36
37 #include "gc/shenandoah/shenandoahAllocTracker.hpp"
38 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
39 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
40 #include "gc/shenandoah/shenandoahCollectionSet.hpp"
41 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
42 #include "gc/shenandoah/shenandoahConcurrentMark.inline.hpp"
43 #include "gc/shenandoah/shenandoahConcurrentRoots.hpp"
44 #include "gc/shenandoah/shenandoahControlThread.hpp"
45 #include "gc/shenandoah/shenandoahFreeSet.hpp"
46 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
47 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
48 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
49 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
50 #include "gc/shenandoah/shenandoahMarkCompact.hpp"
51 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
52 #include "gc/shenandoah/shenandoahMemoryPool.hpp"
53 #include "gc/shenandoah/shenandoahMetrics.hpp"
54 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
55 #include "gc/shenandoah/shenandoahNormalMode.hpp"
56 #include "gc/shenandoah/shenandoahOopClosures.inline.hpp"
57 #include "gc/shenandoah/shenandoahPacer.inline.hpp"
58 #include "gc/shenandoah/shenandoahParallelCleaning.inline.hpp"
59 #include "gc/shenandoah/shenandoahPassiveMode.hpp"
60 #include "gc/shenandoah/shenandoahRootProcessor.inline.hpp"
61 #include "gc/shenandoah/shenandoahStringDedup.hpp"
62 #include "gc/shenandoah/shenandoahTaskqueue.hpp"
63 #include "gc/shenandoah/shenandoahTraversalMode.hpp"
64 #include "gc/shenandoah/shenandoahUtils.hpp"
65 #include "gc/shenandoah/shenandoahVerifier.hpp"
66 #include "gc/shenandoah/shenandoahCodeRoots.hpp"
67 #include "gc/shenandoah/shenandoahVMOperations.hpp"
68 #include "gc/shenandoah/shenandoahWorkGroup.hpp"
69 #include "gc/shenandoah/shenandoahWorkerPolicy.hpp"
70 #if INCLUDE_JFR
71 #include "gc/shenandoah/shenandoahJfrSupport.hpp"
72 #endif
73
74 #include "memory/metaspace.hpp"
75 #include "oops/compressedOops.inline.hpp"
1259 }
1260 }
1261 }
1262 public:
1263 ObjectIterateScanRootClosure(MarkBitMap* bitmap, Stack<oop,mtGC>* oop_stack) :
1264 _bitmap(bitmap), _oop_stack(oop_stack) {}
1265 void do_oop(oop* p) { do_oop_work(p); }
1266 void do_oop(narrowOop* p) { do_oop_work(p); }
1267 };
1268
1269 /*
1270 * This is public API, used in preparation of object_iterate().
1271 * Since we don't do linear scan of heap in object_iterate() (see comment below), we don't
1272 * need to make the heap parsable. For Shenandoah-internal linear heap scans that we can
1273 * control, we call SH::make_tlabs_parsable().
1274 */
1275 void ShenandoahHeap::ensure_parsability(bool retire_tlabs) {
1276 // No-op.
1277 }
1278
1279 /*
1280 * Iterates objects in the heap. This is public API, used for, e.g., heap dumping.
1281 *
1282 * We cannot safely iterate objects by doing a linear scan at random points in time. Linear
1283 * scanning needs to deal with dead objects, which may have dead Klass* pointers (e.g.
1284 * calling oopDesc::size() would crash) or dangling reference fields (crashes) etc. Linear
1285 * scanning therefore depends on having a valid marking bitmap to support it. However, we only
1286 * have a valid marking bitmap after successful marking. In particular, we *don't* have a valid
1287 * marking bitmap during marking, after aborted marking or during/after cleanup (when we just
1288 * wiped the bitmap in preparation for next marking).
1289 *
1290 * For all those reasons, we implement object iteration as a single marking traversal, reporting
1291 * objects as we mark+traverse through the heap, starting from GC roots. JVMTI IterateThroughHeap
1292 * is allowed to report dead objects, but is not required to do so.
1293 */
1294 void ShenandoahHeap::object_iterate(ObjectClosure* cl) {
1295 assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1296 if (!_aux_bitmap_region_special && !os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
1297 log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
1298 return;
1299 }
1300
1301 // Reset bitmap
1302 _aux_bit_map.clear();
1303
1304 Stack<oop,mtGC> oop_stack;
1305
1306 // First, we process GC roots according to current GC cycle. This populates the work stack with initial objects.
1307 ShenandoahHeapIterationRootScanner rp;
1308 ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack);
1309
1310 // When concurrent root is in progress, weak roots may contain dead oops, they should not be used
1311 // for root scanning.
1312 if (is_concurrent_root_in_progress()) {
1313 rp.strong_roots_do(&oops);
1314 } else {
1315 rp.roots_do(&oops);
1316 }
1317
1318 // Work through the oop stack to traverse heap.
1319 while (! oop_stack.is_empty()) {
1320 oop obj = oop_stack.pop();
1321 assert(oopDesc::is_oop(obj), "must be a valid oop");
1322 cl->do_object(obj);
1323 obj->oop_iterate(&oops);
1324 }
1325
1326 assert(oop_stack.is_empty(), "should be empty");
1327
1328 if (!_aux_bitmap_region_special && !os::uncommit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size())) {
1329 log_warning(gc)("Could not uncommit native memory for auxiliary marking bitmap for heap iteration");
1330 }
1331 }
1332
1333 // Keep alive an object that was loaded with AS_NO_KEEPALIVE.
1334 void ShenandoahHeap::keep_alive(oop obj) {
1335 if (is_concurrent_mark_in_progress()) {
1336 ShenandoahBarrierSet::barrier_set()->enqueue(obj);
1337 }
1338 }
1339
1340 void ShenandoahHeap::heap_region_iterate(ShenandoahHeapRegionClosure* blk) const {
1341 for (size_t i = 0; i < num_regions(); i++) {
1342 ShenandoahHeapRegion* current = get_region(i);
1343 blk->heap_region_do(current);
1344 }
1345 }
1346
1347 class ShenandoahParallelHeapRegionTask : public AbstractGangTask {
1348 private:
1349 ShenandoahHeap* const _heap;
1350 ShenandoahHeapRegionClosure* const _blk;
|
36
37 #include "gc/shenandoah/shenandoahAllocTracker.hpp"
38 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
39 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
40 #include "gc/shenandoah/shenandoahCollectionSet.hpp"
41 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
42 #include "gc/shenandoah/shenandoahConcurrentMark.inline.hpp"
43 #include "gc/shenandoah/shenandoahConcurrentRoots.hpp"
44 #include "gc/shenandoah/shenandoahControlThread.hpp"
45 #include "gc/shenandoah/shenandoahFreeSet.hpp"
46 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
47 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
48 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
49 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
50 #include "gc/shenandoah/shenandoahMarkCompact.hpp"
51 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
52 #include "gc/shenandoah/shenandoahMemoryPool.hpp"
53 #include "gc/shenandoah/shenandoahMetrics.hpp"
54 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
55 #include "gc/shenandoah/shenandoahNormalMode.hpp"
56 #include "gc/shenandoah/shenandoahObjectMarker.hpp"
57 #include "gc/shenandoah/shenandoahOopClosures.inline.hpp"
58 #include "gc/shenandoah/shenandoahPacer.inline.hpp"
59 #include "gc/shenandoah/shenandoahParallelCleaning.inline.hpp"
60 #include "gc/shenandoah/shenandoahPassiveMode.hpp"
61 #include "gc/shenandoah/shenandoahRootProcessor.inline.hpp"
62 #include "gc/shenandoah/shenandoahStringDedup.hpp"
63 #include "gc/shenandoah/shenandoahTaskqueue.hpp"
64 #include "gc/shenandoah/shenandoahTraversalMode.hpp"
65 #include "gc/shenandoah/shenandoahUtils.hpp"
66 #include "gc/shenandoah/shenandoahVerifier.hpp"
67 #include "gc/shenandoah/shenandoahCodeRoots.hpp"
68 #include "gc/shenandoah/shenandoahVMOperations.hpp"
69 #include "gc/shenandoah/shenandoahWorkGroup.hpp"
70 #include "gc/shenandoah/shenandoahWorkerPolicy.hpp"
71 #if INCLUDE_JFR
72 #include "gc/shenandoah/shenandoahJfrSupport.hpp"
73 #endif
74
75 #include "memory/metaspace.hpp"
76 #include "oops/compressedOops.inline.hpp"
1260 }
1261 }
1262 }
1263 public:
1264 ObjectIterateScanRootClosure(MarkBitMap* bitmap, Stack<oop,mtGC>* oop_stack) :
1265 _bitmap(bitmap), _oop_stack(oop_stack) {}
1266 void do_oop(oop* p) { do_oop_work(p); }
1267 void do_oop(narrowOop* p) { do_oop_work(p); }
1268 };
1269
1270 /*
1271 * This is public API, used in preparation of object_iterate().
1272 * Since we don't do linear scan of heap in object_iterate() (see comment below), we don't
1273 * need to make the heap parsable. For Shenandoah-internal linear heap scans that we can
1274 * control, we call SH::make_tlabs_parsable().
1275 */
1276 void ShenandoahHeap::ensure_parsability(bool retire_tlabs) {
1277 // No-op.
1278 }
1279
1280 ObjectMarker* ShenandoahHeap::object_marker() {
1281 return new ShenandoahObjectMarker(this, &_aux_bit_map);
1282 }
1283
1284 bool ShenandoahHeap::commit_aux_bitmap() {
1285 if (!_aux_bitmap_region_special && !os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
1286 log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
1287 return false;
1288 }
1289 return true;
1290 }
1291
1292 void ShenandoahHeap::uncommit_aux_bit_map() {
1293 if (!_aux_bitmap_region_special && !os::uncommit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size())) {
1294 log_warning(gc)("Could not uncommit native memory for auxiliary marking bitmap for heap iteration");
1295 }
1296 }
1297
1298 /*
1299 * Iterates objects in the heap. This is public API, used for, e.g., heap dumping.
1300 *
1301 * We cannot safely iterate objects by doing a linear scan at random points in time. Linear
1302 * scanning needs to deal with dead objects, which may have dead Klass* pointers (e.g.
1303 * calling oopDesc::size() would crash) or dangling reference fields (crashes) etc. Linear
1304 * scanning therefore depends on having a valid marking bitmap to support it. However, we only
1305 * have a valid marking bitmap after successful marking. In particular, we *don't* have a valid
1306 * marking bitmap during marking, after aborted marking or during/after cleanup (when we just
1307 * wiped the bitmap in preparation for next marking).
1308 *
1309 * For all those reasons, we implement object iteration as a single marking traversal, reporting
1310 * objects as we mark+traverse through the heap, starting from GC roots. JVMTI IterateThroughHeap
1311 * is allowed to report dead objects, but is not required to do so.
1312 */
1313 void ShenandoahHeap::object_iterate(ObjectClosure* cl) {
1314 assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1315 if (!commit_aux_bitmap()) return;
1316
1317 // Reset bitmap
1318 _aux_bit_map.clear();
1319
1320 Stack<oop,mtGC> oop_stack;
1321
1322 // First, we process GC roots according to current GC cycle. This populates the work stack with initial objects.
1323 ShenandoahHeapIterationRootScanner rp;
1324 ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack);
1325
1326 // When concurrent root is in progress, weak roots may contain dead oops, they should not be used
1327 // for root scanning.
1328 if (is_concurrent_root_in_progress()) {
1329 rp.strong_roots_do(&oops);
1330 } else {
1331 rp.roots_do(&oops);
1332 }
1333
1334 // Work through the oop stack to traverse heap.
1335 while (! oop_stack.is_empty()) {
1336 oop obj = oop_stack.pop();
1337 assert(oopDesc::is_oop(obj), "must be a valid oop");
1338 cl->do_object(obj);
1339 obj->oop_iterate(&oops);
1340 }
1341
1342 assert(oop_stack.is_empty(), "should be empty");
1343
1344 uncommit_aux_bit_map();
1345 }
1346
1347 // Keep alive an object that was loaded with AS_NO_KEEPALIVE.
1348 void ShenandoahHeap::keep_alive(oop obj) {
1349 if (is_concurrent_mark_in_progress()) {
1350 ShenandoahBarrierSet::barrier_set()->enqueue(obj);
1351 }
1352 }
1353
1354 void ShenandoahHeap::heap_region_iterate(ShenandoahHeapRegionClosure* blk) const {
1355 for (size_t i = 0; i < num_regions(); i++) {
1356 ShenandoahHeapRegion* current = get_region(i);
1357 blk->heap_region_do(current);
1358 }
1359 }
1360
1361 class ShenandoahParallelHeapRegionTask : public AbstractGangTask {
1362 private:
1363 ShenandoahHeap* const _heap;
1364 ShenandoahHeapRegionClosure* const _blk;
|