changeset 4527:e99b6a69b81d

8009232: Improve stats gathering code for reference processor Reviewed-by: jwilhelm, brutisso
author ehelin
date Mon, 18 Mar 2013 12:29:19 +0100
parents f3338eb19a6a
children c49a43256225 76451677d919
files src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp src/share/vm/gc_implementation/shared/gcTrace.cpp src/share/vm/gc_implementation/shared/gcTrace.hpp src/share/vm/gc_implementation/shared/gcTraceSend.cpp src/share/vm/memory/referenceProcessor.cpp src/share/vm/memory/referenceProcessor.hpp src/share/vm/memory/referenceProcessorStats.hpp src/share/vm/trace/trace.xml
diffstat 9 files changed, 70 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp	Thu Mar 14 11:00:38 2013 -0700
+++ b/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp	Mon Mar 18 12:29:19 2013 +0100
@@ -2407,18 +2407,19 @@
   {
     GCTraceTime tm_r("reference processing", print_phases(), true, &_gc_timer);
 
+    ReferenceProcessorStats stats;
     if (ref_processor()->processing_is_mt()) {
       RefProcTaskExecutor task_executor;
-      ref_processor()->process_discovered_references(
+      stats = ref_processor()->process_discovered_references(
         is_alive_closure(), &mark_and_push_closure, &follow_stack_closure,
         &task_executor, &_gc_timer);
     } else {
-      ref_processor()->process_discovered_references(
+      stats = ref_processor()->process_discovered_references(
         is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, NULL,
         &_gc_timer);
     }
 
-    gc_tracer->report_gc_reference_processing(ref_processor()->collect_statistics());
+    gc_tracer->report_gc_reference_stats(stats);
   }
 
   GCTraceTime tm_c("class unloading", print_phases(), true, &_gc_timer);
--- a/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp	Thu Mar 14 11:00:38 2013 -0700
+++ b/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp	Mon Mar 18 12:29:19 2013 +0100
@@ -449,17 +449,18 @@
       reference_processor()->set_active_mt_degree(active_workers);
       PSKeepAliveClosure keep_alive(promotion_manager);
       PSEvacuateFollowersClosure evac_followers(promotion_manager);
+      ReferenceProcessorStats stats;
       if (reference_processor()->processing_is_mt()) {
         PSRefProcTaskExecutor task_executor;
-        reference_processor()->process_discovered_references(
+        stats = reference_processor()->process_discovered_references(
           &_is_alive_closure, &keep_alive, &evac_followers, &task_executor,
           &_gc_timer);
       } else {
-        reference_processor()->process_discovered_references(
+        stats = reference_processor()->process_discovered_references(
           &_is_alive_closure, &keep_alive, &evac_followers, NULL, &_gc_timer);
       }
 
-      _gc_tracer.report_gc_reference_processing(reference_processor()->collect_statistics());
+      _gc_tracer.report_gc_reference_stats(stats);
 
       // Enqueue reference objects discovered during scavenge.
       if (reference_processor()->processing_is_mt()) {
--- a/src/share/vm/gc_implementation/shared/gcTrace.cpp	Thu Mar 14 11:00:38 2013 -0700
+++ b/src/share/vm/gc_implementation/shared/gcTrace.cpp	Mon Mar 18 12:29:19 2013 +0100
@@ -75,13 +75,13 @@
   _shared_gc_info.set_id(SharedGCInfo::UNSET_GCID);
 }
 
-void GCTracer::report_gc_reference_processing(const ReferenceProcessorStats& rps) const {
+void GCTracer::report_gc_reference_stats(const ReferenceProcessorStats& rps) const {
   assert_set_gc_id();
 
-  send_reference_processing_event(REF_SOFT, rps.soft_count());
-  send_reference_processing_event(REF_WEAK, rps.weak_count());
-  send_reference_processing_event(REF_FINAL, rps.final_count());
-  send_reference_processing_event(REF_PHANTOM, rps.phantom_count());
+  send_reference_stats_event(REF_SOFT, rps.soft_count());
+  send_reference_stats_event(REF_WEAK, rps.weak_count());
+  send_reference_stats_event(REF_FINAL, rps.final_count());
+  send_reference_stats_event(REF_PHANTOM, rps.phantom_count());
 }
 
 void GCTracer::report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary, const PermGenSummary& perm_gen_summary) const {
--- a/src/share/vm/gc_implementation/shared/gcTrace.hpp	Thu Mar 14 11:00:38 2013 -0700
+++ b/src/share/vm/gc_implementation/shared/gcTrace.hpp	Mon Mar 18 12:29:19 2013 +0100
@@ -125,7 +125,7 @@
   void report_gc_start(GCCause::Cause cause, jlong timestamp);
   void report_gc_end(jlong timestamp, TimePartitions* time_partitions);
   void report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary, const PermGenSummary& perm_gen_summary) const;
-  void report_gc_reference_processing(const ReferenceProcessorStats& rp) const;
+  void report_gc_reference_stats(const ReferenceProcessorStats& rp) const;
 
   bool has_reported_gc_start() const;
 
@@ -138,7 +138,7 @@
   void send_garbage_collection_event() const;
   void send_gc_heap_summary_event(GCWhen::Type when, const GCHeapSummary& heap_summary) const;
   void send_perm_gen_summary_event(GCWhen::Type when, const PermGenSummary& perm_gen_summary) const;
-  void send_reference_processing_event(ReferenceType type, size_t count) const;
+  void send_reference_stats_event(ReferenceType type, size_t count) const;
   void send_phase_events(TimePartitions* time_partitions) const;
 };
 
--- a/src/share/vm/gc_implementation/shared/gcTraceSend.cpp	Thu Mar 14 11:00:38 2013 -0700
+++ b/src/share/vm/gc_implementation/shared/gcTraceSend.cpp	Mon Mar 18 12:29:19 2013 +0100
@@ -50,8 +50,8 @@
   }
 }
 
-void GCTracer::send_reference_processing_event(ReferenceType type, size_t count) const {
-  EventGCReferenceProcessing e;
+void GCTracer::send_reference_stats_event(ReferenceType type, size_t count) const {
+  EventGCReferenceStatistics e;
   if (e.should_commit()) {
       e.set_gcId(_shared_gc_info.id());
       e.set_type((u1)type);
--- a/src/share/vm/memory/referenceProcessor.cpp	Thu Mar 14 11:00:38 2013 -0700
+++ b/src/share/vm/memory/referenceProcessor.cpp	Mon Mar 18 12:29:19 2013 +0100
@@ -102,8 +102,7 @@
   _discovered_list_needs_barrier(discovered_list_needs_barrier),
   _bs(NULL),
   _processing_is_mt(mt_processing),
-  _next_id(0),
-  _stats()
+  _next_id(0)
 {
   _span = span;
   _discovery_is_atomic = atomic_discovery;
@@ -191,14 +190,7 @@
   return total;
 }
 
-void ReferenceProcessor::save_discovered_list_stats() {
-  _stats._soft_count = total_count(_discoveredSoftRefs);
-  _stats._weak_count = total_count(_discoveredWeakRefs);
-  _stats._final_count = total_count(_discoveredFinalRefs);
-  _stats._phantom_count = total_count(_discoveredPhantomRefs);
-}
-
-void ReferenceProcessor::process_discovered_references(
+ReferenceProcessorStats ReferenceProcessor::process_discovered_references(
   BoolObjectClosure*           is_alive,
   OopClosure*                  keep_alive,
   VoidClosure*                 complete_gc,
@@ -220,37 +212,44 @@
 
   _soft_ref_timestamp_clock = java_lang_ref_SoftReference::clock();
 
-  save_discovered_list_stats();
+  bool trace_time = PrintGCDetails && PrintReferenceGC;
 
-  bool trace_time = PrintGCDetails && PrintReferenceGC;
   // Soft references
+  size_t soft_count = 0;
   {
     GCTraceTime tt("SoftReference", trace_time, false, gc_timer);
-    process_discovered_reflist(_discoveredSoftRefs, _current_soft_ref_policy, true,
-                               is_alive, keep_alive, complete_gc, task_executor);
+    soft_count =
+      process_discovered_reflist(_discoveredSoftRefs, _current_soft_ref_policy, true,
+                                 is_alive, keep_alive, complete_gc, task_executor);
   }
 
   update_soft_ref_master_clock();
 
   // Weak references
+  size_t weak_count = 0;
   {
     GCTraceTime tt("WeakReference", trace_time, false, gc_timer);
-    process_discovered_reflist(_discoveredWeakRefs, NULL, true,
-                               is_alive, keep_alive, complete_gc, task_executor);
+    weak_count =
+      process_discovered_reflist(_discoveredWeakRefs, NULL, true,
+                                 is_alive, keep_alive, complete_gc, task_executor);
   }
 
   // Final references
+  size_t final_count = 0;
   {
     GCTraceTime tt("FinalReference", trace_time, false, gc_timer);
-    process_discovered_reflist(_discoveredFinalRefs, NULL, false,
-                               is_alive, keep_alive, complete_gc, task_executor);
+    final_count =
+      process_discovered_reflist(_discoveredFinalRefs, NULL, false,
+                                 is_alive, keep_alive, complete_gc, task_executor);
   }
 
   // Phantom references
+  size_t phantom_count = 0;
   {
     GCTraceTime tt("PhantomReference", trace_time, false, gc_timer);
-    process_discovered_reflist(_discoveredPhantomRefs, NULL, false,
-                               is_alive, keep_alive, complete_gc, task_executor);
+    phantom_count =
+      process_discovered_reflist(_discoveredPhantomRefs, NULL, false,
+                                 is_alive, keep_alive, complete_gc, task_executor);
   }
 
   // Weak global JNI references. It would make more sense (semantically) to
@@ -265,6 +264,8 @@
     }
     process_phaseJNI(is_alive, keep_alive, complete_gc);
   }
+
+  return ReferenceProcessorStats(soft_count, weak_count, final_count, phantom_count);
 }
 
 #ifndef PRODUCT
@@ -900,7 +901,7 @@
   balance_queues(_discoveredPhantomRefs);
 }
 
-void
+size_t
 ReferenceProcessor::process_discovered_reflist(
   DiscoveredList               refs_lists[],
   ReferencePolicy*             policy,
@@ -923,8 +924,11 @@
       must_balance) {
     balance_queues(refs_lists);
   }
+
+  size_t total_list_count = total_count(refs_lists);
+
   if (PrintReferenceGC && PrintGCDetails) {
-    gclog_or_tty->print(", %u refs", total_count(refs_lists));
+    gclog_or_tty->print(", %u refs", total_list_count);
   }
 
   // Phase 1 (soft refs only):
@@ -969,6 +973,8 @@
                      is_alive, keep_alive, complete_gc);
     }
   }
+
+  return total_list_count;
 }
 
 void ReferenceProcessor::clean_up_discovered_references() {
--- a/src/share/vm/memory/referenceProcessor.hpp	Thu Mar 14 11:00:38 2013 -0700
+++ b/src/share/vm/memory/referenceProcessor.hpp	Mon Mar 18 12:29:19 2013 +0100
@@ -210,10 +210,7 @@
 class ReferenceProcessor : public CHeapObj<mtGC> {
 
  private:
-  ReferenceProcessorStats _stats;
-
   size_t total_count(DiscoveredList lists[]);
-  void save_discovered_list_stats();
 
  protected:
   // Compatibility with pre-4965777 JDK's
@@ -293,13 +290,13 @@
   }
 
   // Process references with a certain reachability level.
-  void process_discovered_reflist(DiscoveredList               refs_lists[],
-                                  ReferencePolicy*             policy,
-                                  bool                         clear_referent,
-                                  BoolObjectClosure*           is_alive,
-                                  OopClosure*                  keep_alive,
-                                  VoidClosure*                 complete_gc,
-                                  AbstractRefProcTaskExecutor* task_executor);
+  size_t process_discovered_reflist(DiscoveredList               refs_lists[],
+                                    ReferencePolicy*             policy,
+                                    bool                         clear_referent,
+                                    BoolObjectClosure*           is_alive,
+                                    OopClosure*                  keep_alive,
+                                    VoidClosure*                 complete_gc,
+                                    AbstractRefProcTaskExecutor* task_executor);
 
   void process_phaseJNI(BoolObjectClosure* is_alive,
                         OopClosure*        keep_alive,
@@ -384,12 +381,6 @@
 
   void enqueue_discovered_reflists(HeapWord* pending_list_addr, AbstractRefProcTaskExecutor* task_executor);
 
-  // Returns statistics from the last time the reference where processed via
-  // an invocation of process_discovered_references.
-  const ReferenceProcessorStats& collect_statistics() const {
-    return _stats;
-  }
-
  protected:
   // Set the 'discovered' field of the given reference to
   // the given value - emitting barriers depending upon
@@ -447,8 +438,7 @@
     _num_q(0),
     _max_num_q(0),
     _processing_is_mt(false),
-    _next_id(0),
-    _stats()
+    _next_id(0)
   { }
 
   // Default parameters give you a vanilla reference processor.
@@ -520,11 +510,12 @@
   bool discover_reference(oop obj, ReferenceType rt);
 
   // Process references found during GC (called by the garbage collector)
-  void process_discovered_references(BoolObjectClosure*           is_alive,
-                                     OopClosure*                  keep_alive,
-                                     VoidClosure*                 complete_gc,
-                                     AbstractRefProcTaskExecutor* task_executor,
-                                     GCTimer *gc_timer);
+  ReferenceProcessorStats
+  process_discovered_references(BoolObjectClosure*           is_alive,
+                                OopClosure*                  keep_alive,
+                                VoidClosure*                 complete_gc,
+                                AbstractRefProcTaskExecutor* task_executor,
+                                GCTimer *gc_timer);
 
   // Enqueue references at end of GC (called by the garbage collector)
   bool enqueue_discovered_references(AbstractRefProcTaskExecutor* task_executor = NULL);
--- a/src/share/vm/memory/referenceProcessorStats.hpp	Thu Mar 14 11:00:38 2013 -0700
+++ b/src/share/vm/memory/referenceProcessorStats.hpp	Mon Mar 18 12:29:19 2013 +0100
@@ -32,9 +32,6 @@
 // ReferenceProcessorStats contains statistics about how many references that
 // have been traversed when processing references during garbage collection.
 class ReferenceProcessorStats {
-  friend class ReferenceProcessor;
-
- private:
   size_t _soft_count;
   size_t _weak_count;
   size_t _final_count;
@@ -47,6 +44,16 @@
     _final_count(0),
     _phantom_count(0) {}
 
+  ReferenceProcessorStats(size_t soft_count,
+                          size_t weak_count,
+                          size_t final_count,
+                          size_t phantom_count) :
+    _soft_count(soft_count),
+    _weak_count(weak_count),
+    _final_count(final_count),
+    _phantom_count(phantom_count)
+  {}
+
   size_t soft_count() const {
     return _soft_count;
   }
--- a/src/share/vm/trace/trace.xml	Thu Mar 14 11:00:38 2013 -0700
+++ b/src/share/vm/trace/trace.xml	Mon Mar 18 12:29:19 2013 +0100
@@ -183,7 +183,7 @@
       <value type="G1YCTYPE" field="type" label="Type" />
     </event>
 
-    <event id="GCReferenceProcessing" path="vm/gc/reference/statistics"
+    <event id="GCReferenceStatistics" path="vm/gc/reference/statistics"
            label="GC Reference Processing" is_instant="true"
            description="Total count of processed references during GC">
       <value type="ULONG" field="gcId" label="GC ID" relation="GC_ID"/>