16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #include "precompiled.hpp" 25 #include "gc/shared/gcId.hpp" 26 #include "gc/shared/gcLocker.hpp" 27 #include "gc/shared/isGCActiveMark.hpp" 28 #include "gc/shared/vmGCOperations.hpp" 29 #include "gc/z/zCollectedHeap.hpp" 30 #include "gc/z/zDriver.hpp" 31 #include "gc/z/zHeap.inline.hpp" 32 #include "gc/z/zMessagePort.inline.hpp" 33 #include "gc/z/zServiceability.hpp" 34 #include "gc/z/zStat.hpp" 35 #include "logging/log.hpp" 36 #include "runtime/vm_operations.hpp" 37 #include "runtime/vmThread.hpp" 38 39 static const ZStatPhaseCycle ZPhaseCycle("Garbage Collection Cycle"); 40 static const ZStatPhasePause ZPhasePauseMarkStart("Pause Mark Start"); 41 static const ZStatPhaseConcurrent ZPhaseConcurrentMark("Concurrent Mark"); 42 static const ZStatPhaseConcurrent ZPhaseConcurrentMarkContinue("Concurrent Mark Continue"); 43 static const ZStatPhasePause ZPhasePauseMarkEnd("Pause Mark End"); 44 static const ZStatPhaseConcurrent ZPhaseConcurrentProcessNonStrongReferences("Concurrent Process Non-Strong References"); 45 static const ZStatPhaseConcurrent ZPhaseConcurrentResetRelocationSet("Concurrent Reset Relocation Set"); 46 static const ZStatPhaseConcurrent ZPhaseConcurrentDestroyDetachedPages("Concurrent Destroy Detached Pages"); 47 static const ZStatPhaseConcurrent ZPhaseConcurrentSelectRelocationSet("Concurrent Select Relocation Set"); 48 static const ZStatPhaseConcurrent ZPhaseConcurrentPrepareRelocationSet("Concurrent Prepare Relocation Set"); 49 static const ZStatPhasePause ZPhasePauseRelocateStart("Pause Relocate Start"); 50 static const ZStatPhaseConcurrent ZPhaseConcurrentRelocated("Concurrent Relocate"); 51 static const ZStatCriticalPhase ZCriticalPhaseGCLockerStall("GC Locker Stall", false /* verbose */); 52 static const ZStatSampler ZSamplerJavaThreads("System", "Java Threads", ZStatUnitThreads); 53 54 class ZOperationClosure : public StackObj { 55 public: 56 virtual const char* name() const = 0; 57 58 virtual bool needs_inactive_gc_locker() const { 59 // An inactive GC locker is needed in operations where we change the good 60 // mask or move objects. Changing the good mask will invalidate all oops, 61 // which makes it conceptually the same thing as moving all objects. 62 return false; 63 } 64 65 virtual bool do_operation() = 0; 66 }; 193 194 ZHeap::heap()->mark_start(); 195 return true; 196 } 197 }; 198 199 class ZMarkEndClosure : public ZOperationClosure { 200 public: 201 virtual const char* name() const { 202 return "ZMarkEnd"; 203 } 204 205 virtual bool do_operation() { 206 ZStatTimer timer(ZPhasePauseMarkEnd); 207 ZServiceabilityMarkEndTracer tracer; 208 209 return ZHeap::heap()->mark_end(); 210 } 211 }; 212 213 class ZRelocateStartClosure : public ZOperationClosure { 214 public: 215 virtual const char* name() const { 216 return "ZRelocateStart"; 217 } 218 219 virtual bool needs_inactive_gc_locker() const { 220 return true; 221 } 222 223 virtual bool do_operation() { 224 ZStatTimer timer(ZPhasePauseRelocateStart); 225 ZServiceabilityRelocateStartTracer tracer; 226 227 ZHeap::heap()->relocate_start(); 228 return true; 229 } 230 }; 231 232 ZDriver::ZDriver() : 350 } 351 352 // Phase 4: Concurrent Process Non-Strong References 353 { 354 ZStatTimer timer(ZPhaseConcurrentProcessNonStrongReferences); 355 ZHeap::heap()->process_non_strong_references(); 356 } 357 358 // Phase 5: Concurrent Reset Relocation Set 359 { 360 ZStatTimer timer(ZPhaseConcurrentResetRelocationSet); 361 ZHeap::heap()->reset_relocation_set(); 362 } 363 364 // Phase 6: Concurrent Destroy Detached Pages 365 { 366 ZStatTimer timer(ZPhaseConcurrentDestroyDetachedPages); 367 ZHeap::heap()->destroy_detached_pages(); 368 } 369 370 // Phase 7: Concurrent Select Relocation Set 371 { 372 ZStatTimer timer(ZPhaseConcurrentSelectRelocationSet); 373 ZHeap::heap()->select_relocation_set(); 374 } 375 376 // Phase 8: Concurrent Prepare Relocation Set 377 { 378 ZStatTimer timer(ZPhaseConcurrentPrepareRelocationSet); 379 ZHeap::heap()->prepare_relocation_set(); 380 } 381 382 // Phase 9: Pause Relocate Start 383 { 384 ZRelocateStartClosure cl; 385 vm_operation(&cl); 386 } 387 388 // Phase 10: Concurrent Relocate 389 { 390 ZStatTimer timer(ZPhaseConcurrentRelocated); 391 ZHeap::heap()->relocate(); 392 } 393 } 394 395 void ZDriver::end_gc_cycle() { 396 // Notify GC cycle completed 397 _gc_cycle_port.ack(); 398 399 // Check for out of memory condition 400 ZHeap::heap()->check_out_of_memory(); 401 } 402 403 void ZDriver::run_service() { 404 // Main loop 405 while (!should_terminate()) { 406 const GCCause::Cause cause = start_gc_cycle(); 407 if (cause != GCCause::_no_gc) { 408 run_gc_cycle(cause); | 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #include "precompiled.hpp" 25 #include "gc/shared/gcId.hpp" 26 #include "gc/shared/gcLocker.hpp" 27 #include "gc/shared/isGCActiveMark.hpp" 28 #include "gc/shared/vmGCOperations.hpp" 29 #include "gc/z/zCollectedHeap.hpp" 30 #include "gc/z/zDriver.hpp" 31 #include "gc/z/zHeap.inline.hpp" 32 #include "gc/z/zMessagePort.inline.hpp" 33 #include "gc/z/zServiceability.hpp" 34 #include "gc/z/zStat.hpp" 35 #include "logging/log.hpp" 36 #include "memory/universe.hpp" 37 #include "runtime/vm_operations.hpp" 38 #include "runtime/vmThread.hpp" 39 40 static const ZStatPhaseCycle ZPhaseCycle("Garbage Collection Cycle"); 41 static const ZStatPhasePause ZPhasePauseMarkStart("Pause Mark Start"); 42 static const ZStatPhaseConcurrent ZPhaseConcurrentMark("Concurrent Mark"); 43 static const ZStatPhaseConcurrent ZPhaseConcurrentMarkContinue("Concurrent Mark Continue"); 44 static const ZStatPhasePause ZPhasePauseMarkEnd("Pause Mark End"); 45 static const ZStatPhaseConcurrent ZPhaseConcurrentProcessNonStrongReferences("Concurrent Process Non-Strong References"); 46 static const ZStatPhaseConcurrent ZPhaseConcurrentResetRelocationSet("Concurrent Reset Relocation Set"); 47 static const ZStatPhaseConcurrent ZPhaseConcurrentDestroyDetachedPages("Concurrent Destroy Detached Pages"); 48 static const ZStatPhasePause ZPhasePauseVerify("Pause Verify"); 49 static const ZStatPhaseConcurrent ZPhaseConcurrentSelectRelocationSet("Concurrent Select Relocation Set"); 50 static const ZStatPhaseConcurrent ZPhaseConcurrentPrepareRelocationSet("Concurrent Prepare Relocation Set"); 51 static const ZStatPhasePause ZPhasePauseRelocateStart("Pause Relocate Start"); 52 static const ZStatPhaseConcurrent ZPhaseConcurrentRelocated("Concurrent Relocate"); 53 static const ZStatCriticalPhase ZCriticalPhaseGCLockerStall("GC Locker Stall", false /* verbose */); 54 static const ZStatSampler ZSamplerJavaThreads("System", "Java Threads", ZStatUnitThreads); 55 56 class ZOperationClosure : public StackObj { 57 public: 58 virtual const char* name() const = 0; 59 60 virtual bool needs_inactive_gc_locker() const { 61 // An inactive GC locker is needed in operations where we change the good 62 // mask or move objects. Changing the good mask will invalidate all oops, 63 // which makes it conceptually the same thing as moving all objects. 64 return false; 65 } 66 67 virtual bool do_operation() = 0; 68 }; 195 196 ZHeap::heap()->mark_start(); 197 return true; 198 } 199 }; 200 201 class ZMarkEndClosure : public ZOperationClosure { 202 public: 203 virtual const char* name() const { 204 return "ZMarkEnd"; 205 } 206 207 virtual bool do_operation() { 208 ZStatTimer timer(ZPhasePauseMarkEnd); 209 ZServiceabilityMarkEndTracer tracer; 210 211 return ZHeap::heap()->mark_end(); 212 } 213 }; 214 215 class ZVerifyClosure : public ZOperationClosure { 216 public: 217 virtual const char* name() const { 218 return "ZVerify"; 219 } 220 221 virtual bool do_operation() { 222 ZStatTimer timer(ZPhasePauseVerify); 223 Universe::verify(); 224 return true; 225 } 226 }; 227 228 class ZRelocateStartClosure : public ZOperationClosure { 229 public: 230 virtual const char* name() const { 231 return "ZRelocateStart"; 232 } 233 234 virtual bool needs_inactive_gc_locker() const { 235 return true; 236 } 237 238 virtual bool do_operation() { 239 ZStatTimer timer(ZPhasePauseRelocateStart); 240 ZServiceabilityRelocateStartTracer tracer; 241 242 ZHeap::heap()->relocate_start(); 243 return true; 244 } 245 }; 246 247 ZDriver::ZDriver() : 365 } 366 367 // Phase 4: Concurrent Process Non-Strong References 368 { 369 ZStatTimer timer(ZPhaseConcurrentProcessNonStrongReferences); 370 ZHeap::heap()->process_non_strong_references(); 371 } 372 373 // Phase 5: Concurrent Reset Relocation Set 374 { 375 ZStatTimer timer(ZPhaseConcurrentResetRelocationSet); 376 ZHeap::heap()->reset_relocation_set(); 377 } 378 379 // Phase 6: Concurrent Destroy Detached Pages 380 { 381 ZStatTimer timer(ZPhaseConcurrentDestroyDetachedPages); 382 ZHeap::heap()->destroy_detached_pages(); 383 } 384 385 // Phase 7: Pause Verify 386 if (VerifyBeforeGC || VerifyDuringGC || VerifyAfterGC) { 387 ZVerifyClosure cl; 388 vm_operation(&cl); 389 } 390 391 // Phase 8: Concurrent Select Relocation Set 392 { 393 ZStatTimer timer(ZPhaseConcurrentSelectRelocationSet); 394 ZHeap::heap()->select_relocation_set(); 395 } 396 397 // Phase 9: Concurrent Prepare Relocation Set 398 { 399 ZStatTimer timer(ZPhaseConcurrentPrepareRelocationSet); 400 ZHeap::heap()->prepare_relocation_set(); 401 } 402 403 // Phase 10: Pause Relocate Start 404 { 405 ZRelocateStartClosure cl; 406 vm_operation(&cl); 407 } 408 409 // Phase 11: Concurrent Relocate 410 { 411 ZStatTimer timer(ZPhaseConcurrentRelocated); 412 ZHeap::heap()->relocate(); 413 } 414 } 415 416 void ZDriver::end_gc_cycle() { 417 // Notify GC cycle completed 418 _gc_cycle_port.ack(); 419 420 // Check for out of memory condition 421 ZHeap::heap()->check_out_of_memory(); 422 } 423 424 void ZDriver::run_service() { 425 // Main loop 426 while (!should_terminate()) { 427 const GCCause::Cause cause = start_gc_cycle(); 428 if (cause != GCCause::_no_gc) { 429 run_gc_cycle(cause); |