@@ -2922,6 +2922,36 @@ class G1YoungGCTraceTime {
29222922 }
29232923};
29242924
2925+ class G1YoungGCVerifierMark : public StackObj {
2926+ G1HeapVerifier::G1VerifyType _type;
2927+
2928+ static G1HeapVerifier::G1VerifyType young_collection_verify_type () {
2929+ G1CollectorState* state = G1CollectedHeap::heap ()->collector_state ();
2930+ if (state->in_concurrent_start_gc ()) {
2931+ return G1HeapVerifier::G1VerifyConcurrentStart;
2932+ } else if (state->in_young_only_phase ()) {
2933+ return G1HeapVerifier::G1VerifyYoungNormal;
2934+ } else {
2935+ return G1HeapVerifier::G1VerifyMixed;
2936+ }
2937+ }
2938+
2939+ public:
2940+ G1YoungGCVerifierMark () : _type(young_collection_verify_type()) {
2941+ G1CollectedHeap::heap ()->verify_before_young_collection (_type);
2942+ }
2943+
2944+ ~G1YoungGCVerifierMark () {
2945+ G1CollectedHeap::heap ()->verify_after_young_collection (_type);
2946+ }
2947+ };
2948+
2949+ class G1YoungGCNotifyPauseMark : public StackObj {
2950+ public:
2951+ G1YoungGCNotifyPauseMark () { G1CollectedHeap::heap ()->policy ()->record_young_gc_pause_start (); }
2952+ ~G1YoungGCNotifyPauseMark () { G1CollectedHeap::heap ()->policy ()->record_young_gc_pause_end (); }
2953+ };
2954+
29252955G1HeapPrinterMark::G1HeapPrinterMark (G1CollectedHeap* g1h) : _g1h(g1h), _heap_transition(g1h) {
29262956 // This summary needs to be printed before incrementing total collections.
29272957 _g1h->rem_set ()->print_periodic_summary_info (" Before GC RS summary" , _g1h->total_collections ());
@@ -3053,8 +3083,8 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus
30533083 // determining collector state.
30543084 G1YoungGCTraceTime tm (gc_cause ());
30553085
3056- // Young GC internal timing
3057- policy ()-> note_gc_start () ;
3086+ // Young GC internal pause timing
3087+ G1YoungGCNotifyPauseMark npm ;
30583088 // JFR
30593089 G1YoungGCJFRTracerMark jtm (_gc_timer_stw, _gc_tracer_stw, gc_cause ());
30603090 // JStat/MXBeans
@@ -3069,15 +3099,14 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus
30693099 // just to do that).
30703100 wait_for_root_region_scanning ();
30713101
3072- G1HeapVerifier::G1VerifyType verify_type = young_collection_verify_type ();
3073- verify_before_young_collection (verify_type);
3102+ G1YoungGCVerifierMark vm;
30743103 {
30753104 // Actual collection work starts and is executed (only) in this scope.
30763105
3077- // The elapsed time induced by the start time below deliberately elides
3078- // the possible verification above.
3079- double sample_start_time_sec = os::elapsedTime ();
3080- policy ()->record_collection_pause_start (sample_start_time_sec );
3106+ // Young GC internal collection timing. The elapsed time recorded in the
3107+ // policy for the collection deliberately elides verification (and some
3108+ // other trivial setup above).
3109+ policy ()->record_young_collection_start ( );
30813110
30823111 calculate_collection_set (jtm.evacuation_info (), target_pause_time_ms);
30833112
@@ -3106,14 +3135,8 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus
31063135 // modifies it to the next state.
31073136 jtm.report_pause_type (collector_state ()->young_gc_pause_type (concurrent_operation_is_full_mark));
31083137
3109- double sample_end_time_sec = os::elapsedTime ();
3110- double pause_time_ms = (sample_end_time_sec - sample_start_time_sec) * MILLIUNITS;
3111- policy ()->record_collection_pause_end (pause_time_ms, concurrent_operation_is_full_mark);
3138+ policy ()->record_young_collection_end (concurrent_operation_is_full_mark);
31123139 }
3113- verify_after_young_collection (verify_type);
3114-
3115- policy ()->print_phases ();
3116-
31173140 TASKQUEUE_STATS_ONLY (print_taskqueue_stats ());
31183141 TASKQUEUE_STATS_ONLY (reset_taskqueue_stats ());
31193142 }
@@ -3780,11 +3803,11 @@ void G1CollectedHeap::evacuate_next_optional_regions(G1ParScanThreadStateSet* pe
37803803}
37813804
37823805void G1CollectedHeap::evacuate_optional_collection_set (G1ParScanThreadStateSet* per_thread_states) {
3783- const double gc_start_time_ms = phase_times ()->cur_collection_start_sec () * 1000.0 ;
3806+ const double collection_start_time_ms = phase_times ()->cur_collection_start_sec () * 1000.0 ;
37843807
37853808 while (!evacuation_failed () && _collection_set.optional_region_length () > 0 ) {
37863809
3787- double time_used_ms = os::elapsedTime () * 1000.0 - gc_start_time_ms ;
3810+ double time_used_ms = os::elapsedTime () * 1000.0 - collection_start_time_ms ;
37883811 double time_left_ms = MaxGCPauseMillis - time_used_ms;
37893812
37903813 if (time_left_ms < 0 ||
0 commit comments