5050
5151// Breakpoint support
5252class ShenandoahBreakpointGCScope :public StackObj {
53+ private:
54+ const GCCause::Cause _cause;
5355public:
54- ShenandoahBreakpointGCScope () {
55- ShenandoahBreakpoint::at_before_gc ();
56+ ShenandoahBreakpointGCScope (GCCause::Cause cause) : _cause(cause) {
57+ if (cause == GCCause::_wb_breakpoint) {
58+ ShenandoahBreakpoint::start_gc ();
59+ ShenandoahBreakpoint::at_before_gc ();
60+ }
5661 }
5762
5863~ShenandoahBreakpointGCScope () {
59- ShenandoahBreakpoint::at_after_gc ();
64+ if (_cause == GCCause::_wb_breakpoint) {
65+ ShenandoahBreakpoint::at_after_gc ();
66+ }
6067 }
6168};
6269
6370class ShenandoahBreakpointMarkScope :public StackObj {
71+ private:
72+ const GCCause::Cause _cause;
6473public:
65- ShenandoahBreakpointMarkScope () {
66- ShenandoahBreakpoint::at_after_marking_started ();
74+ ShenandoahBreakpointMarkScope (GCCause::Cause cause) : _cause(cause) {
75+ if (_cause == GCCause::_wb_breakpoint) {
76+ ShenandoahBreakpoint::at_after_marking_started ();
77+ }
6778 }
6879
6980~ShenandoahBreakpointMarkScope () {
70- ShenandoahBreakpoint::at_before_marking_completed ();
81+ if (_cause == GCCause::_wb_breakpoint) {
82+ ShenandoahBreakpoint::at_before_marking_completed ();
83+ }
7184 }
7285};
7386
@@ -86,10 +99,7 @@ void ShenandoahConcurrentGC::cancel() {
8699
87100bool ShenandoahConcurrentGC::collect (GCCause::Cause cause) {
88101 ShenandoahHeap*const heap =ShenandoahHeap::heap ();
89- if (cause == GCCause::_wb_breakpoint) {
90- ShenandoahBreakpoint::start_gc ();
91- }
92- ShenandoahBreakpointGCScope breakpoint_gc_scope;
102+ ShenandoahBreakpointGCScopebreakpoint_gc_scope (cause);
93103
94104// Reset for upcoming marking
95105entry_reset ();
@@ -98,7 +108,7 @@ bool ShenandoahConcurrentGC::collect(GCCause::Cause cause) {
98108vmop_entry_init_mark ();
99109
100110 {
101- ShenandoahBreakpointMarkScope breakpoint_mark_scope;
111+ ShenandoahBreakpointMarkScopebreakpoint_mark_scope (cause) ;
102112// Concurrent mark roots
103113entry_mark_roots ();
104114if (check_cancellation_and_abort (ShenandoahDegenPoint::_degenerated_outside_cycle))return false ;
@@ -657,7 +667,9 @@ void ShenandoahConcurrentGC::op_weak_refs() {
657667assert (heap->is_concurrent_weak_root_in_progress ()," Only during this phase" );
658668// Concurrent weak refs processing
659669 ShenandoahGCWorkerPhaseworker_phase (ShenandoahPhaseTimings::conc_weak_refs);
660- ShenandoahBreakpoint::at_after_reference_processing_started ();
670+ if (heap->gc_cause () == GCCause::_wb_breakpoint) {
671+ ShenandoahBreakpoint::at_after_reference_processing_started ();
672+ }
661673 heap->ref_processor ()->process_references (ShenandoahPhaseTimings::conc_weak_refs, heap->workers (),true /* concurrent*/ );
662674}
663675