8139892: Allow G1CollectorPolicy to specify if reference processing should be enabled
authorehelin
Mon, 19 Oct 2015 16:33:12 +0200
changeset 34310 32e3c906b613
parent 34309 7c25f5fb2b03
child 34311 586e90e84d60
8139892: Allow G1CollectorPolicy to specify if reference processing should be enabled Reviewed-by: mgerdin, kbarrett, tbenson
hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp
hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp
hotspot/src/share/vm/gc/g1/g1CollectorPolicy.hpp
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Thu Nov 26 01:59:34 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Mon Oct 19 16:33:12 2015 +0200
@@ -3826,7 +3826,11 @@
       // reference processing currently works in G1.
 
       // Enable discovery in the STW reference processor
-      ref_processor_stw()->enable_discovery();
+      if (g1_policy()->should_process_references()) {
+        ref_processor_stw()->enable_discovery();
+      } else {
+        ref_processor_stw()->disable_discovery();
+      }
 
       {
         // We want to temporarily turn off discovery by the
@@ -4973,6 +4977,17 @@
   }
 };
 
+void G1CollectedHeap::process_weak_jni_handles() {
+  double ref_proc_start = os::elapsedTime();
+
+  G1STWIsAliveClosure is_alive(this);
+  G1KeepAliveClosure keep_alive(this);
+  JNIHandles::weak_oops_do(&is_alive, &keep_alive);
+
+  double ref_proc_time = os::elapsedTime() - ref_proc_start;
+  g1_policy()->phase_times()->record_ref_proc_time(ref_proc_time * 1000.0);
+}
+
 // Weak Reference processing during an evacuation pause (part 1).
 void G1CollectedHeap::process_discovered_references(G1ParScanThreadStateSet* per_thread_states) {
   double ref_proc_start = os::elapsedTime();
@@ -5157,7 +5172,12 @@
   // as we may have to copy some 'reachable' referent
   // objects (and their reachable sub-graphs) that were
   // not copied during the pause.
-  process_discovered_references(per_thread_states);
+  if (g1_policy()->should_process_references()) {
+    process_discovered_references(per_thread_states);
+  } else {
+    ref_processor_stw()->verify_no_references_recorded();
+    process_weak_jni_handles();
+  }
 
   if (G1StringDedup::is_enabled()) {
     double fixup_start = os::elapsedTime();
@@ -5188,7 +5208,11 @@
   // will log these updates (and dirty their associated
   // cards). We need these updates logged to update any
   // RSets.
-  enqueue_discovered_references(per_thread_states);
+  if (g1_policy()->should_process_references()) {
+    enqueue_discovered_references(per_thread_states);
+  } else {
+    g1_policy()->phase_times()->record_ref_enq_time(0);
+  }
 }
 
 void G1CollectedHeap::post_evacuate_collection_set(EvacuationInfo& evacuation_info, G1ParScanThreadStateSet* per_thread_states) {
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Thu Nov 26 01:59:34 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Mon Oct 19 16:33:12 2015 +0200
@@ -292,6 +292,8 @@
 
   void trace_heap(GCWhen::Type when, const GCTracer* tracer);
 
+  void process_weak_jni_handles();
+
   // These are macros so that, if the assert fires, we get the correct
   // line number, file, etc.
 
--- a/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.hpp	Thu Nov 26 01:59:34 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.hpp	Mon Oct 19 16:33:12 2015 +0200
@@ -783,6 +783,10 @@
     return _young_gen_sizer->adaptive_young_list_length();
   }
 
+  virtual bool should_process_references() const {
+    return true;
+  }
+
 private:
   //
   // Survivor regions policy.