1.1 --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Thu Sep 22 07:18:51 2011 -0400 1.2 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Thu Sep 22 10:57:37 2011 -0700 1.3 @@ -155,6 +155,19 @@ 1.4 : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */) { } 1.5 }; 1.6 1.7 +// The G1 STW is alive closure. 1.8 +// An instance is embedded into the G1CH and used as the 1.9 +// (optional) _is_alive_non_header closure in the STW 1.10 +// reference processor. It is also extensively used during 1.11 +// refence processing during STW evacuation pauses. 1.12 +class G1STWIsAliveClosure: public BoolObjectClosure { 1.13 + G1CollectedHeap* _g1; 1.14 +public: 1.15 + G1STWIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) {} 1.16 + void do_object(oop p) { assert(false, "Do not call."); } 1.17 + bool do_object_b(oop p); 1.18 +}; 1.19 + 1.20 class SurvivorGCAllocRegion : public G1AllocRegion { 1.21 protected: 1.22 virtual HeapRegion* allocate_new_region(size_t word_size, bool force); 1.23 @@ -174,6 +187,7 @@ 1.24 }; 1.25 1.26 class RefineCardTableEntryClosure; 1.27 + 1.28 class G1CollectedHeap : public SharedHeap { 1.29 friend class VM_G1CollectForAllocation; 1.30 friend class VM_GenCollectForPermanentAllocation; 1.31 @@ -573,6 +587,14 @@ 1.32 // allocated block, or else "NULL". 1.33 HeapWord* expand_and_allocate(size_t word_size); 1.34 1.35 + // Process any reference objects discovered during 1.36 + // an incremental evacuation pause. 1.37 + void process_discovered_references(); 1.38 + 1.39 + // Enqueue any remaining discovered references 1.40 + // after processing. 1.41 + void enqueue_discovered_references(); 1.42 + 1.43 public: 1.44 1.45 G1MonitoringSupport* g1mm() { return _g1mm; } 1.46 @@ -826,14 +848,83 @@ 1.47 bool should_mark_root); 1.48 void handle_evacuation_failure_common(oop obj, markOop m); 1.49 1.50 + // ("Weak") Reference processing support. 1.51 + // 1.52 + // G1 has 2 instances of the referece processor class. One 1.53 + // (_ref_processor_cm) handles reference object discovery 1.54 + // and subsequent processing during concurrent marking cycles. 1.55 + // 1.56 + // The other (_ref_processor_stw) handles reference object 1.57 + // discovery and processing during full GCs and incremental 1.58 + // evacuation pauses. 1.59 + // 1.60 + // During an incremental pause, reference discovery will be 1.61 + // temporarily disabled for _ref_processor_cm and will be 1.62 + // enabled for _ref_processor_stw. At the end of the evacuation 1.63 + // pause references discovered by _ref_processor_stw will be 1.64 + // processed and discovery will be disabled. The previous 1.65 + // setting for reference object discovery for _ref_processor_cm 1.66 + // will be re-instated. 1.67 + // 1.68 + // At the start of marking: 1.69 + // * Discovery by the CM ref processor is verified to be inactive 1.70 + // and it's discovered lists are empty. 1.71 + // * Discovery by the CM ref processor is then enabled. 1.72 + // 1.73 + // At the end of marking: 1.74 + // * Any references on the CM ref processor's discovered 1.75 + // lists are processed (possibly MT). 1.76 + // 1.77 + // At the start of full GC we: 1.78 + // * Disable discovery by the CM ref processor and 1.79 + // empty CM ref processor's discovered lists 1.80 + // (without processing any entries). 1.81 + // * Verify that the STW ref processor is inactive and it's 1.82 + // discovered lists are empty. 1.83 + // * Temporarily set STW ref processor discovery as single threaded. 1.84 + // * Temporarily clear the STW ref processor's _is_alive_non_header 1.85 + // field. 1.86 + // * Finally enable discovery by the STW ref processor. 1.87 + // 1.88 + // The STW ref processor is used to record any discovered 1.89 + // references during the full GC. 1.90 + // 1.91 + // At the end of a full GC we: 1.92 + // * Enqueue any reference objects discovered by the STW ref processor 1.93 + // that have non-live referents. This has the side-effect of 1.94 + // making the STW ref processor inactive by disabling discovery. 1.95 + // * Verify that the CM ref processor is still inactive 1.96 + // and no references have been placed on it's discovered 1.97 + // lists (also checked as a precondition during initial marking). 1.98 + 1.99 + // The (stw) reference processor... 1.100 + ReferenceProcessor* _ref_processor_stw; 1.101 + 1.102 + // During reference object discovery, the _is_alive_non_header 1.103 + // closure (if non-null) is applied to the referent object to 1.104 + // determine whether the referent is live. If so then the 1.105 + // reference object does not need to be 'discovered' and can 1.106 + // be treated as a regular oop. This has the benefit of reducing 1.107 + // the number of 'discovered' reference objects that need to 1.108 + // be processed. 1.109 + // 1.110 + // Instance of the is_alive closure for embedding into the 1.111 + // STW reference processor as the _is_alive_non_header field. 1.112 + // Supplying a value for the _is_alive_non_header field is 1.113 + // optional but doing so prevents unnecessary additions to 1.114 + // the discovered lists during reference discovery. 1.115 + G1STWIsAliveClosure _is_alive_closure_stw; 1.116 + 1.117 + // The (concurrent marking) reference processor... 1.118 + ReferenceProcessor* _ref_processor_cm; 1.119 + 1.120 // Instance of the concurrent mark is_alive closure for embedding 1.121 - // into the reference processor as the is_alive_non_header. This 1.122 - // prevents unnecessary additions to the discovered lists during 1.123 - // concurrent discovery. 1.124 - G1CMIsAliveClosure _is_alive_closure; 1.125 - 1.126 - // ("Weak") Reference processing support 1.127 - ReferenceProcessor* _ref_processor; 1.128 + // into the Concurrent Marking reference processor as the 1.129 + // _is_alive_non_header field. Supplying a value for the 1.130 + // _is_alive_non_header field is optional but doing so prevents 1.131 + // unnecessary additions to the discovered lists during reference 1.132 + // discovery. 1.133 + G1CMIsAliveClosure _is_alive_closure_cm; 1.134 1.135 enum G1H_process_strong_roots_tasks { 1.136 G1H_PS_mark_stack_oops_do, 1.137 @@ -874,6 +965,7 @@ 1.138 // specified by the policy object. 1.139 jint initialize(); 1.140 1.141 + // Initialize weak reference processing. 1.142 virtual void ref_processing_init(); 1.143 1.144 void set_par_threads(int t) { 1.145 @@ -925,8 +1017,13 @@ 1.146 // The shared block offset table array. 1.147 G1BlockOffsetSharedArray* bot_shared() const { return _bot_shared; } 1.148 1.149 - // Reference Processing accessor 1.150 - ReferenceProcessor* ref_processor() { return _ref_processor; } 1.151 + // Reference Processing accessors 1.152 + 1.153 + // The STW reference processor.... 1.154 + ReferenceProcessor* ref_processor_stw() const { return _ref_processor_stw; } 1.155 + 1.156 + // The Concurent Marking reference processor... 1.157 + ReferenceProcessor* ref_processor_cm() const { return _ref_processor_cm; } 1.158 1.159 virtual size_t capacity() const; 1.160 virtual size_t used() const;