src/hotspot/share/gc/g1/g1GCPhaseTimes.cpp
changeset 50438 66d0ded78cce
parent 50113 caf115bb98ad
child 51332 c25572739e7c
--- a/src/hotspot/share/gc/g1/g1GCPhaseTimes.cpp	Wed Jun 06 13:58:57 2018 -0700
+++ b/src/hotspot/share/gc/g1/g1GCPhaseTimes.cpp	Thu Jun 07 09:02:03 2018 +0200
@@ -468,15 +468,24 @@
   _pss(pss),
   _start(Ticks::now()),
   _total_time(total_time),
-  _trim_time(trim_time) {
+  _trim_time(trim_time),
+  _stopped(false) {
 
   assert(_pss->trim_ticks().value() == 0, "Possibly remaining trim ticks left over from previous use");
 }
 
 G1EvacPhaseWithTrimTimeTracker::~G1EvacPhaseWithTrimTimeTracker() {
+  if (!_stopped) {
+    stop();
+  }
+}
+
+void G1EvacPhaseWithTrimTimeTracker::stop() {
+  assert(!_stopped, "Should only be called once");
   _total_time += (Ticks::now() - _start) - _pss->trim_ticks();
   _trim_time += _pss->trim_ticks();
   _pss->reset_trim_ticks();
+  _stopped = true;
 }
 
 G1GCParPhaseTimesTracker::G1GCParPhaseTimesTracker(G1GCPhaseTimes* phase_times, G1GCPhaseTimes::GCParPhases phase, uint worker_id) :
@@ -504,6 +513,8 @@
 
 G1EvacPhaseTimesTracker::~G1EvacPhaseTimesTracker() {
   if (_phase_times != NULL) {
+    // Explicitly stop the trim tracker since it's not yet destructed.
+    _trim_tracker.stop();
     // Exclude trim time by increasing the start time.
     _start_time += _trim_time;
     _phase_times->record_or_add_objcopy_time_secs(_worker_id, _trim_time.seconds());