215 }
216
217 // Only used by oldgen allocation.
218 bool MutableSpace::needs_expand(size_t word_size) const {
219 assert_lock_strong(PSOldGenExpand_lock);
220 // Holding the lock means end is stable. So while top may be advancing
221 // via concurrent allocations, there is no need to order the reads of top
222 // and end here, unlike in cas_allocate.
223 return pointer_delta(end(), top()) < word_size;
224 }
225
226 void MutableSpace::oop_iterate(OopIterateClosure* cl) {
227 HeapWord* obj_addr = bottom();
228 HeapWord* t = top();
229 // Could call objects iterate, but this is easier.
230 while (obj_addr < t) {
231 obj_addr += cast_to_oop(obj_addr)->oop_iterate_size(cl);
232 }
233 }
234
235 void MutableSpace::object_iterate(ObjectClosure* cl) {
236 HeapWord* p = bottom();
237 while (p < top()) {
238 oop obj = cast_to_oop(p);
239 // When promotion-failure occurs during Young GC, eden/from space is not cleared,
240 // so we can encounter objects with "forwarded" markword.
241 // They are essentially dead, so skipping them
242 if (!obj->is_forwarded()) {
243 cl->do_object(obj);
244 }
245 #ifdef ASSERT
246 else {
247 assert(obj->forwardee() != obj, "must not be self-forwarded");
248 }
249 #endif
250 p += obj->size();
251 }
252 }
253
254 void MutableSpace::print_short() const { print_short_on(tty); }
255 void MutableSpace::print_short_on( outputStream* st) const {
256 st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K,
257 (int) ((double) used_in_bytes() * 100 / capacity_in_bytes()));
258 }
259
260 void MutableSpace::print() const { print_on(tty); }
261 void MutableSpace::print_on(outputStream* st) const {
262 MutableSpace::print_short_on(st);
263 st->print_cr(" [" PTR_FORMAT "," PTR_FORMAT "," PTR_FORMAT ")",
264 p2i(bottom()), p2i(top()), p2i(end()));
265 }
266
267 void MutableSpace::verify() {
268 HeapWord* p = bottom();
269 HeapWord* t = top();
270 HeapWord* prev_p = nullptr;
|
215 }
216
217 // Only used by oldgen allocation.
218 bool MutableSpace::needs_expand(size_t word_size) const {
219 assert_lock_strong(PSOldGenExpand_lock);
220 // Holding the lock means end is stable. So while top may be advancing
221 // via concurrent allocations, there is no need to order the reads of top
222 // and end here, unlike in cas_allocate.
223 return pointer_delta(end(), top()) < word_size;
224 }
225
226 void MutableSpace::oop_iterate(OopIterateClosure* cl) {
227 HeapWord* obj_addr = bottom();
228 HeapWord* t = top();
229 // Could call objects iterate, but this is easier.
230 while (obj_addr < t) {
231 obj_addr += cast_to_oop(obj_addr)->oop_iterate_size(cl);
232 }
233 }
234
235 template<bool COMPACT_HEADERS>
236 void MutableSpace::object_iterate_impl(ObjectClosure* cl) {
237 HeapWord* p = bottom();
238 while (p < top()) {
239 oop obj = cast_to_oop(p);
240 // When promotion-failure occurs during Young GC, eden/from space is not cleared,
241 // so we can encounter objects with "forwarded" markword.
242 // They are essentially dead, so skipping them
243 if (!obj->is_forwarded()) {
244 cl->do_object(obj);
245 p += obj->size();
246 } else {
247 assert(obj->forwardee() != obj, "must not be self-forwarded");
248 if (COMPACT_HEADERS) {
249 // It is safe to use the forwardee here. Parallel GC only uses
250 // header-based forwarding during promotion. Full GC doesn't
251 // use the object header for forwarding at all.
252 p += obj->forwardee()->size();
253 } else {
254 p += obj->size();
255 }
256 }
257 }
258 }
259
260 void MutableSpace::object_iterate(ObjectClosure* cl) {
261 if (UseCompactObjectHeaders) {
262 object_iterate_impl<true>(cl);
263 } else {
264 object_iterate_impl<false>(cl);
265 }
266 }
267
268 void MutableSpace::print_short() const { print_short_on(tty); }
269 void MutableSpace::print_short_on( outputStream* st) const {
270 st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K,
271 (int) ((double) used_in_bytes() * 100 / capacity_in_bytes()));
272 }
273
274 void MutableSpace::print() const { print_on(tty); }
275 void MutableSpace::print_on(outputStream* st) const {
276 MutableSpace::print_short_on(st);
277 st->print_cr(" [" PTR_FORMAT "," PTR_FORMAT "," PTR_FORMAT ")",
278 p2i(bottom()), p2i(top()), p2i(end()));
279 }
280
281 void MutableSpace::verify() {
282 HeapWord* p = bottom();
283 HeapWord* t = top();
284 HeapWord* prev_p = nullptr;
|