diff src/share/vm/gc_implementation/g1/concurrentMark.cpp @ 453:c96030fff130

6684579: SoftReference processing can be made more efficient Summary: For current soft-ref clearing policies, we can decide at marking time if a soft-reference will definitely not be cleared, postponing the decision of whether it will definitely be cleared to the final reference processing phase. This can be especially beneficial in the case of concurrent collectors where the marking is usually concurrent but reference processing is usually not. Reviewed-by: jmasa
author ysr
date Thu, 20 Nov 2008 16:56:09 -0800
parents 0edda524b58c
children 27a80744a83b
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/g1/concurrentMark.cpp	Thu Nov 20 12:27:41 2008 -0800
+++ b/src/share/vm/gc_implementation/g1/concurrentMark.cpp	Thu Nov 20 16:56:09 2008 -0800
@@ -811,6 +811,7 @@
   ReferenceProcessor* rp = g1h->ref_processor();
   rp->verify_no_references_recorded();
   rp->enable_discovery(); // enable ("weak") refs discovery
+  rp->snap_policy(false); // snapshot the soft ref policy to be used in this cycle
 
   SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
   satb_mq_set.set_process_completed_threshold(G1SATBProcessCompletedThreshold);
@@ -1829,32 +1830,21 @@
 void ConcurrentMark::weakRefsWork(bool clear_all_soft_refs) {
   ResourceMark rm;
   HandleMark   hm;
-  ReferencePolicy* soft_ref_policy;
+  G1CollectedHeap* g1h   = G1CollectedHeap::heap();
+  ReferenceProcessor* rp = g1h->ref_processor();
 
   // Process weak references.
-  if (clear_all_soft_refs) {
-    soft_ref_policy = new AlwaysClearPolicy();
-  } else {
-#ifdef COMPILER2
-    soft_ref_policy = new LRUMaxHeapPolicy();
-#else
-    soft_ref_policy = new LRUCurrentHeapPolicy();
-#endif
-  }
+  rp->snap_policy(clear_all_soft_refs);
   assert(_markStack.isEmpty(), "mark stack should be empty");
 
-  G1CollectedHeap* g1 = G1CollectedHeap::heap();
-  G1CMIsAliveClosure g1IsAliveClosure(g1);
-
-  G1CMKeepAliveClosure g1KeepAliveClosure(g1, this, nextMarkBitMap());
+  G1CMIsAliveClosure   g1IsAliveClosure  (g1h);
+  G1CMKeepAliveClosure g1KeepAliveClosure(g1h, this, nextMarkBitMap());
   G1CMDrainMarkingStackClosure
     g1DrainMarkingStackClosure(nextMarkBitMap(), &_markStack,
                                &g1KeepAliveClosure);
 
   // XXXYYY  Also: copy the parallel ref processing code from CMS.
-  ReferenceProcessor* rp = g1->ref_processor();
-  rp->process_discovered_references(soft_ref_policy,
-                                    &g1IsAliveClosure,
+  rp->process_discovered_references(&g1IsAliveClosure,
                                     &g1KeepAliveClosure,
                                     &g1DrainMarkingStackClosure,
                                     NULL);