1262 * have a valid marking bitmap after successful marking. In particular, we *don't* have a valid
1263 * marking bitmap during marking, after aborted marking or during/after cleanup (when we just
1264 * wiped the bitmap in preparation for next marking).
1265 *
1266 * For all those reasons, we implement object iteration as a single marking traversal, reporting
1267 * objects as we mark+traverse through the heap, starting from GC roots. JVMTI IterateThroughHeap
1268 * is allowed to report dead objects, but is not required to do so.
1269 */
1270 void ShenandoahHeap::object_iterate(ObjectClosure* cl) {
1271 assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1272 if (!_aux_bitmap_region_special && !os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
1273 log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
1274 return;
1275 }
1276
1277 // Reset bitmap
1278 _aux_bit_map.clear();
1279
1280 Stack<oop,mtGC> oop_stack;
1281
1282 // First, we process all GC roots. This populates the work stack with initial objects.
1283 ShenandoahAllRootScanner rp(1, ShenandoahPhaseTimings::_num_phases);
1284 ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack);
1285
1286 if (unload_classes()) {
1287 rp.strong_roots_do_unchecked(&oops);
1288 } else {
1289 rp.roots_do_unchecked(&oops);
1290 }
1291
1292 // Work through the oop stack to traverse heap.
1293 while (! oop_stack.is_empty()) {
1294 oop obj = oop_stack.pop();
1295 assert(oopDesc::is_oop(obj), "must be a valid oop");
1296 cl->do_object(obj);
1297 obj->oop_iterate(&oops);
1298 }
1299
1300 assert(oop_stack.is_empty(), "should be empty");
1301
1302 if (!_aux_bitmap_region_special && !os::uncommit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size())) {
1303 log_warning(gc)("Could not uncommit native memory for auxiliary marking bitmap for heap iteration");
1304 }
1305 }
1306
1307 void ShenandoahHeap::safe_object_iterate(ObjectClosure* cl) {
1308 assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1309 object_iterate(cl);
|
1262 * have a valid marking bitmap after successful marking. In particular, we *don't* have a valid
1263 * marking bitmap during marking, after aborted marking or during/after cleanup (when we just
1264 * wiped the bitmap in preparation for next marking).
1265 *
1266 * For all those reasons, we implement object iteration as a single marking traversal, reporting
1267 * objects as we mark+traverse through the heap, starting from GC roots. JVMTI IterateThroughHeap
1268 * is allowed to report dead objects, but is not required to do so.
1269 */
1270 void ShenandoahHeap::object_iterate(ObjectClosure* cl) {
1271 assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1272 if (!_aux_bitmap_region_special && !os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
1273 log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
1274 return;
1275 }
1276
1277 // Reset bitmap
1278 _aux_bit_map.clear();
1279
1280 Stack<oop,mtGC> oop_stack;
1281
1282 // First, we process GC roots according to current GC cycle. This populates the work stack with initial objects.
1283 ShenandoahHeapIterationRootScanner rp;
1284 ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack);
1285
1286 if (unload_classes()) {
1287 rp.strong_roots_do(&oops);
1288 } else {
1289 rp.roots_do(&oops);
1290 }
1291
1292 // Work through the oop stack to traverse heap.
1293 while (! oop_stack.is_empty()) {
1294 oop obj = oop_stack.pop();
1295 assert(oopDesc::is_oop(obj), "must be a valid oop");
1296 cl->do_object(obj);
1297 obj->oop_iterate(&oops);
1298 }
1299
1300 assert(oop_stack.is_empty(), "should be empty");
1301
1302 if (!_aux_bitmap_region_special && !os::uncommit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size())) {
1303 log_warning(gc)("Could not uncommit native memory for auxiliary marking bitmap for heap iteration");
1304 }
1305 }
1306
1307 void ShenandoahHeap::safe_object_iterate(ObjectClosure* cl) {
1308 assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1309 object_iterate(cl);
|