src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.cpp
changeset 54103 8b61a38be0c5
parent 54058 be40860e8227
child 54338 7a34a3270270
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.cpp	Wed Mar 13 17:32:17 2019 +0100
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.cpp	Wed Mar 13 13:33:50 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2018, Red Hat, Inc. All rights reserved.
+ * Copyright (c) 2015, 2019, Red Hat, Inc. All rights reserved.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
@@ -41,6 +41,25 @@
 #include "runtime/thread.hpp"
 #include "services/management.hpp"
 
+struct PhaseMap {
+  WeakProcessorPhases::Phase            _weak_processor_phase;
+  ShenandoahPhaseTimings::GCParPhases   _shenandoah_phase;
+};
+
+static const struct PhaseMap phase_mapping[] = {
+#if INCLUDE_JVMTI
+  {WeakProcessorPhases::jvmti,       ShenandoahPhaseTimings::JVMTIWeakRoots},
+#endif
+#if INCLUDE_JFR
+  {WeakProcessorPhases::jfr,         ShenandoahPhaseTimings::JFRWeakRoots},
+#endif
+  {WeakProcessorPhases::jni,         ShenandoahPhaseTimings::JNIWeakRoots},
+  {WeakProcessorPhases::stringtable, ShenandoahPhaseTimings::StringTableRoots},
+  {WeakProcessorPhases::vm,          ShenandoahPhaseTimings::VMWeakRoots}
+};
+
+STATIC_ASSERT(sizeof(phase_mapping) / sizeof(PhaseMap) == WeakProcessorPhases::phase_count);
+
 ShenandoahRootProcessor::ShenandoahRootProcessor(ShenandoahHeap* heap, uint n_workers,
                                                  ShenandoahPhaseTimings::Phase phase) :
   _process_strong_tasks(new SubTasksDone(SHENANDOAH_RP_PS_NumElements)),
@@ -48,8 +67,9 @@
   _par_state_string(StringTable::weak_storage()),
   _phase(phase),
   _coderoots_all_iterator(ShenandoahCodeRoots::iterator()),
-  _weak_processor_task(n_workers)
-{
+  _weak_processor_timings(n_workers),
+  _weak_processor_task(&_weak_processor_timings, n_workers),
+  _processed_weak_roots(false) {
   heap->phase_timings()->record_workers_start(_phase);
 
   if (ShenandoahStringDedup::is_enabled()) {
@@ -63,9 +83,32 @@
     StringDedup::gc_epilogue();
   }
 
+  ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
+
+  if (_processed_weak_roots) {
+    assert(_weak_processor_timings.max_threads() == n_workers(), "Must match");
+    for (uint index = 0; index < WeakProcessorPhases::phase_count; index ++) {
+      weak_processor_timing_to_shenandoah_timing(phase_mapping[index]._weak_processor_phase,
+                                                 phase_mapping[index]._shenandoah_phase,
+                                                 worker_times);
+    }
+  }
+
   ShenandoahHeap::heap()->phase_timings()->record_workers_end(_phase);
 }
 
+void ShenandoahRootProcessor::weak_processor_timing_to_shenandoah_timing(const WeakProcessorPhases::Phase wpp,
+                                                                         const ShenandoahPhaseTimings::GCParPhases spp,
+                                                                         ShenandoahWorkerTimings* worker_times) const {
+  if (WeakProcessorPhases::is_serial(wpp)) {
+    worker_times->record_time_secs(spp, 0, _weak_processor_timings.phase_time_sec(wpp));
+  } else {
+    for (uint index = 0; index < _weak_processor_timings.max_threads(); index ++) {
+      worker_times->record_time_secs(spp, index, _weak_processor_timings.worker_time_sec(index, wpp));
+    }
+  }
+}
+
 void ShenandoahRootProcessor::process_all_roots_slow(OopClosure* oops) {
   CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong);
   CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);
@@ -193,9 +236,9 @@
     SystemDictionary::oops_do(strong_roots);
   }
   if (jni_weak_roots != NULL) {
-      ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::JNIWeakRoots, worker_id);
-      AlwaysTrueClosure always_true;
-      _weak_processor_task.work<AlwaysTrueClosure, OopClosure>(worker_id, &always_true, jni_weak_roots);
+    AlwaysTrueClosure always_true;
+    _weak_processor_task.work<AlwaysTrueClosure, OopClosure>(worker_id, &always_true, jni_weak_roots);
+    _processed_weak_roots = true;
   }
 
   if (ShenandoahStringDedup::is_enabled() && weak_roots != NULL) {