src/share/vm/gc_implementation/g1/g1ParScanThreadState.hpp

Print this page
rev 6626 : imported patch 8035400-move-g1parscanthreadstate-into-own-files
rev 6627 : imported patch 8035400-2-bengt-fixes
rev 6628 : imported patch 8035401-fix-visibility-of-g1parscanthreadstate
rev 6629 : imported patch 8035401-3-fix-constructor
rev 6630 : imported patch 8035401-2-another-inline-try


  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP
  27 
  28 #include "gc_implementation/g1/dirtyCardQueue.hpp"
  29 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
  30 #include "gc_implementation/g1/g1CollectedHeap.hpp"
  31 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
  32 #include "gc_implementation/g1/g1OopClosures.hpp"
  33 #include "gc_implementation/g1/g1RemSet.hpp"
  34 #include "gc_implementation/shared/ageTable.hpp"
  35 #include "memory/allocation.hpp"
  36 #include "oops/oop.hpp"
  37 
  38 class HeapRegion;
  39 class outputStream;
  40 
  41 class G1ParScanThreadState : public StackObj {
  42 protected:
  43   G1CollectedHeap* _g1h;
  44   RefToScanQueue*  _refs;
  45   DirtyCardQueue   _dcq;
  46   G1SATBCardTableModRefBS* _ct_bs;
  47   G1RemSet* _g1_rem;
  48 
  49   G1ParGCAllocBuffer  _surviving_alloc_buffer;
  50   G1ParGCAllocBuffer  _tenured_alloc_buffer;
  51   G1ParGCAllocBuffer* _alloc_buffers[GCAllocPurposeCount];
  52   ageTable            _age_table;
  53 
  54   G1ParScanClosure    _scanner;
  55 
  56   size_t           _alloc_buffer_waste;
  57   size_t           _undo_waste;
  58 
  59   OopsInHeapRegionClosure*      _evac_failure_cl;
  60 
  61   int  _hash_seed;
  62   uint _queue_num;


  81 
  82   void   add_to_undo_waste(size_t waste)         { _undo_waste += waste; }
  83 
  84   DirtyCardQueue& dirty_card_queue()             { return _dcq;  }
  85   G1SATBCardTableModRefBS* ctbs()                { return _ct_bs; }
  86 
  87   template <class T> inline void immediate_rs_update(HeapRegion* from, T* p, int tid);
  88 
  89   template <class T> void deferred_rs_update(HeapRegion* from, T* p, int tid) {
  90     // If the new value of the field points to the same region or
  91     // is the to-space, we don't need to include it in the Rset updates.
  92     if (!from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && !from->is_survivor()) {
  93       size_t card_index = ctbs()->index_for(p);
  94       // If the card hasn't been added to the buffer, do it.
  95       if (ctbs()->mark_card_deferred(card_index)) {
  96         dirty_card_queue().enqueue((jbyte*)ctbs()->byte_for_index(card_index));
  97       }
  98     }
  99   }
 100 
 101 public:
 102   G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num, ReferenceProcessor* rp);
 103   ~G1ParScanThreadState() {
 104     retire_alloc_buffers();
 105     FREE_C_HEAP_ARRAY(size_t, _surviving_young_words_base, mtGC);
 106   }
 107 
 108   RefToScanQueue*   refs()            { return _refs;             }
 109   ageTable*         age_table()       { return &_age_table;       }
 110 
 111   G1ParGCAllocBuffer* alloc_buffer(GCAllocPurpose purpose) {
 112     return _alloc_buffers[purpose];
 113   }
 114 
 115   size_t alloc_buffer_waste() const              { return _alloc_buffer_waste; }
 116   size_t undo_waste() const                      { return _undo_waste; }
 117 
 118 #ifdef ASSERT


 119   bool verify_ref(narrowOop* ref) const;
 120   bool verify_ref(oop* ref) const;
 121   bool verify_task(StarTask ref) const;
 122 #endif // ASSERT
 123 
 124   template <class T> void push_on_queue(T* ref) {
 125     assert(verify_ref(ref), "sanity");
 126     refs()->push(ref);
 127   }
 128 
 129   template <class T> inline void update_rs(HeapRegion* from, T* p, int tid);
 130 
 131   HeapWord* allocate_slow(GCAllocPurpose purpose, size_t word_sz) {
 132     HeapWord* obj = NULL;
 133     size_t gclab_word_size = _g1h->desired_plab_sz(purpose);
 134     if (word_sz * 100 < gclab_word_size * ParallelGCBufferWastePct) {
 135       G1ParGCAllocBuffer* alloc_buf = alloc_buffer(purpose);
 136       add_to_alloc_buffer_waste(alloc_buf->words_remaining());
 137       alloc_buf->retire(false /* end_of_gc */, false /* retain */);
 138 
 139       HeapWord* buf = _g1h->par_allocate_during_gc(purpose, gclab_word_size);
 140       if (buf == NULL) return NULL; // Let caller handle allocation failure.
 141       // Otherwise.
 142       alloc_buf->set_word_size(gclab_word_size);
 143       alloc_buf->set_buf(buf);
 144 
 145       obj = alloc_buf->allocate(word_sz);
 146       assert(obj != NULL, "buffer was definitely big enough...");
 147     } else {
 148       obj = _g1h->par_allocate_during_gc(purpose, word_sz);
 149     }
 150     return obj;
 151   }
 152 
 153   HeapWord* allocate(GCAllocPurpose purpose, size_t word_sz) {
 154     HeapWord* obj = alloc_buffer(purpose)->allocate(word_sz);
 155     if (obj != NULL) return obj;
 156     return allocate_slow(purpose, word_sz);
 157   }
 158 
 159   void undo_allocation(GCAllocPurpose purpose, HeapWord* obj, size_t word_sz) {
 160     if (alloc_buffer(purpose)->contains(obj)) {
 161       assert(alloc_buffer(purpose)->contains(obj + word_sz - 1),
 162              "should contain whole object");
 163       alloc_buffer(purpose)->undo_allocation(obj, word_sz);
 164     } else {
 165       CollectedHeap::fill_with_object(obj, word_sz);
 166       add_to_undo_waste(word_sz);
 167     }
 168   }
 169 
 170   void set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_cl) {
 171     _evac_failure_cl = evac_failure_cl;
 172   }
 173   OopsInHeapRegionClosure* evac_failure_closure() {
 174     return _evac_failure_cl;
 175   }
 176 
 177   int* hash_seed() { return &_hash_seed; }
 178   uint queue_num() { return _queue_num; }
 179 
 180   size_t term_attempts() const  { return _term_attempts; }
 181   void note_term_attempt() { _term_attempts++; }
 182 
 183   void start_strong_roots() {
 184     _start_strong_roots = os::elapsedTime();
 185   }
 186   void end_strong_roots() {
 187     _strong_roots_time += (os::elapsedTime() - _start_strong_roots);
 188   }
 189   double strong_roots_time() const { return _strong_roots_time; }
 190 
 191   void start_term_time() {
 192     note_term_attempt();
 193     _start_term = os::elapsedTime();
 194   }
 195   void end_term_time() {
 196     _term_time += (os::elapsedTime() - _start_term);
 197   }
 198   double term_time() const { return _term_time; }
 199 
 200   double elapsed_time() const {
 201     return os::elapsedTime() - _start;
 202   }
 203 
 204   static void
 205     print_termination_stats_hdr(outputStream* const st = gclog_or_tty);
 206   void
 207     print_termination_stats(int i, outputStream* const st = gclog_or_tty) const;
 208 
 209   size_t* surviving_young_words() {
 210     // We add on to hide entry 0 which accumulates surviving words for
 211     // age -1 regions (i.e. non-young ones)
 212     return _surviving_young_words;
 213   }
 214 
 215  private:
 216   void retire_alloc_buffers() {
 217     for (int ap = 0; ap < GCAllocPurposeCount; ++ap) {
 218       size_t waste = _alloc_buffers[ap]->words_remaining();
 219       add_to_alloc_buffer_waste(waste);
 220       _alloc_buffers[ap]->flush_stats_and_retire(_g1h->stats_for_purpose((GCAllocPurpose)ap),
 221                                                  true /* end_of_gc */,
 222                                                  false /* retain */);
 223     }
 224   }
 225 
 226   #define G1_PARTIAL_ARRAY_MASK 0x2
 227 
 228   inline bool has_partial_array_mask(oop* ref) const {
 229     return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK;
 230   }
 231 
 232   // We never encode partial array oops as narrowOop*, so return false immediately.
 233   // This allows the compiler to create optimized code when popping references from
 234   // the work queue.
 235   inline bool has_partial_array_mask(narrowOop* ref) const {
 236     assert(((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) != G1_PARTIAL_ARRAY_MASK, "Partial array oop reference encoded as narrowOop*");
 237     return false;
 238   }
 239 
 240   // Only implement set_partial_array_mask() for regular oops, not for narrowOops.
 241   // We always encode partial arrays as regular oop, to allow the
 242   // specialization for has_partial_array_mask() for narrowOops above.
 243   // This means that unintentional use of this method with narrowOops are caught
 244   // by the compiler.
 245   inline oop* set_partial_array_mask(oop obj) const {
 246     assert(((uintptr_t)(void *)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!");
 247     return (oop*) ((uintptr_t)(void *)obj | G1_PARTIAL_ARRAY_MASK);
 248   }
 249 
 250   inline oop clear_partial_array_mask(oop* ref) const {
 251     return cast_to_oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK);
 252   }
 253 
 254   inline void do_oop_partial_array(oop* p);
 255 
 256   // This method is applied to the fields of the objects that have just been copied.
 257   template <class T> void do_oop_evac(T* p, HeapRegion* from) {
 258     assert(!oopDesc::is_null(oopDesc::load_decode_heap_oop(p)),
 259            "Reference should not be NULL here as such are never pushed to the task queue.");
 260     oop obj = oopDesc::load_decode_heap_oop_not_null(p);
 261 
 262     // Although we never intentionally push references outside of the collection
 263     // set, due to (benign) races in the claim mechanism during RSet scanning more
 264     // than one thread might claim the same card. So the same card may be
 265     // processed multiple times. So redo this check.
 266     if (_g1h->in_cset_fast_test(obj)) {
 267       oop forwardee;
 268       if (obj->is_forwarded()) {
 269         forwardee = obj->forwardee();
 270       } else {
 271         forwardee = copy_to_survivor_space(obj);
 272       }
 273       assert(forwardee != NULL, "forwardee should not be NULL");
 274       oopDesc::encode_store_heap_oop(p, forwardee);
 275     }
 276 
 277     assert(obj != NULL, "Must be");
 278     update_rs(from, p, queue_num());
 279   }
 280 public:
 281 
 282   oop copy_to_survivor_space(oop const obj);
 283 
 284   template <class T> inline void deal_with_reference(T* ref_to_scan);
 285 
 286   inline void deal_with_reference(StarTask ref);



 287 
 288 public:
 289   void trim_queue();


 290 };
 291 
 292 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP


  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP
  27 
  28 #include "gc_implementation/g1/dirtyCardQueue.hpp"
  29 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
  30 #include "gc_implementation/g1/g1CollectedHeap.hpp"
  31 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
  32 #include "gc_implementation/g1/g1OopClosures.hpp"
  33 #include "gc_implementation/g1/g1RemSet.hpp"
  34 #include "gc_implementation/shared/ageTable.hpp"
  35 #include "memory/allocation.hpp"
  36 #include "oops/oop.hpp"
  37 
  38 class HeapRegion;
  39 class outputStream;
  40 
  41 class G1ParScanThreadState : public StackObj {
  42  private:
  43   G1CollectedHeap* _g1h;
  44   RefToScanQueue*  _refs;
  45   DirtyCardQueue   _dcq;
  46   G1SATBCardTableModRefBS* _ct_bs;
  47   G1RemSet* _g1_rem;
  48 
  49   G1ParGCAllocBuffer  _surviving_alloc_buffer;
  50   G1ParGCAllocBuffer  _tenured_alloc_buffer;
  51   G1ParGCAllocBuffer* _alloc_buffers[GCAllocPurposeCount];
  52   ageTable            _age_table;
  53 
  54   G1ParScanClosure    _scanner;
  55 
  56   size_t           _alloc_buffer_waste;
  57   size_t           _undo_waste;
  58 
  59   OopsInHeapRegionClosure*      _evac_failure_cl;
  60 
  61   int  _hash_seed;
  62   uint _queue_num;


  81 
  82   void   add_to_undo_waste(size_t waste)         { _undo_waste += waste; }
  83 
  84   DirtyCardQueue& dirty_card_queue()             { return _dcq;  }
  85   G1SATBCardTableModRefBS* ctbs()                { return _ct_bs; }
  86 
  87   template <class T> inline void immediate_rs_update(HeapRegion* from, T* p, int tid);
  88 
  89   template <class T> void deferred_rs_update(HeapRegion* from, T* p, int tid) {
  90     // If the new value of the field points to the same region or
  91     // is the to-space, we don't need to include it in the Rset updates.
  92     if (!from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && !from->is_survivor()) {
  93       size_t card_index = ctbs()->index_for(p);
  94       // If the card hasn't been added to the buffer, do it.
  95       if (ctbs()->mark_card_deferred(card_index)) {
  96         dirty_card_queue().enqueue((jbyte*)ctbs()->byte_for_index(card_index));
  97       }
  98     }
  99   }
 100 
 101  public:
 102   G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num, ReferenceProcessor* rp);
 103   ~G1ParScanThreadState();



 104 

 105   ageTable*         age_table()       { return &_age_table;       }
 106 
 107   G1ParGCAllocBuffer* alloc_buffer(GCAllocPurpose purpose) {
 108     return _alloc_buffers[purpose];
 109   }
 110 
 111   size_t alloc_buffer_waste() const              { return _alloc_buffer_waste; }
 112   size_t undo_waste() const                      { return _undo_waste; }
 113 
 114 #ifdef ASSERT
 115   bool queue_is_empty() const { return _refs->is_empty(); }
 116 
 117   bool verify_ref(narrowOop* ref) const;
 118   bool verify_ref(oop* ref) const;
 119   bool verify_task(StarTask ref) const;
 120 #endif // ASSERT
 121 
 122   template <class T> void push_on_queue(T* ref) {
 123     assert(verify_ref(ref), "sanity");
 124     _refs->push(ref);
 125   }
 126 
 127   template <class T> inline void update_rs(HeapRegion* from, T* p, int tid);
 128 
 129  private:
 130 
 131   inline HeapWord* allocate(GCAllocPurpose purpose, size_t word_sz);
 132   inline HeapWord* allocate_slow(GCAllocPurpose purpose, size_t word_sz);
 133   inline void undo_allocation(GCAllocPurpose purpose, HeapWord* obj, size_t word_sz);
 134 
 135  public:































 136 
 137   void set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_cl) {
 138     _evac_failure_cl = evac_failure_cl;
 139   }
 140 
 141   OopsInHeapRegionClosure* evac_failure_closure() { return _evac_failure_cl; }

 142 
 143   int* hash_seed() { return &_hash_seed; }
 144   uint queue_num() { return _queue_num; }
 145 
 146   size_t term_attempts() const  { return _term_attempts; }
 147   void note_term_attempt() { _term_attempts++; }
 148 
 149   void start_strong_roots() {
 150     _start_strong_roots = os::elapsedTime();
 151   }
 152   void end_strong_roots() {
 153     _strong_roots_time += (os::elapsedTime() - _start_strong_roots);
 154   }
 155   double strong_roots_time() const { return _strong_roots_time; }
 156 
 157   void start_term_time() {
 158     note_term_attempt();
 159     _start_term = os::elapsedTime();
 160   }
 161   void end_term_time() {
 162     _term_time += (os::elapsedTime() - _start_term);
 163   }
 164   double term_time() const { return _term_time; }
 165 
 166   double elapsed_time() const {
 167     return os::elapsedTime() - _start;
 168   }
 169 
 170   static void print_termination_stats_hdr(outputStream* const st = gclog_or_tty);
 171   void print_termination_stats(int i, outputStream* const st = gclog_or_tty) const;


 172 
 173   size_t* surviving_young_words() {
 174     // We add on to hide entry 0 which accumulates surviving words for
 175     // age -1 regions (i.e. non-young ones)
 176     return _surviving_young_words;
 177   }
 178 
 179  private:
 180   void retire_alloc_buffers();








 181 
 182   #define G1_PARTIAL_ARRAY_MASK 0x2
 183 
 184   inline bool has_partial_array_mask(oop* ref) const {
 185     return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK;
 186   }
 187 
 188   // We never encode partial array oops as narrowOop*, so return false immediately.
 189   // This allows the compiler to create optimized code when popping references from
 190   // the work queue.
 191   inline bool has_partial_array_mask(narrowOop* ref) const {
 192     assert(((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) != G1_PARTIAL_ARRAY_MASK, "Partial array oop reference encoded as narrowOop*");
 193     return false;
 194   }
 195 
 196   // Only implement set_partial_array_mask() for regular oops, not for narrowOops.
 197   // We always encode partial arrays as regular oop, to allow the
 198   // specialization for has_partial_array_mask() for narrowOops above.
 199   // This means that unintentional use of this method with narrowOops are caught
 200   // by the compiler.
 201   inline oop* set_partial_array_mask(oop obj) const {
 202     assert(((uintptr_t)(void *)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!");
 203     return (oop*) ((uintptr_t)(void *)obj | G1_PARTIAL_ARRAY_MASK);
 204   }
 205 
 206   inline oop clear_partial_array_mask(oop* ref) const {
 207     return cast_to_oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK);
 208   }
 209 
 210   inline void do_oop_partial_array(oop* p);
 211 
 212   // This method is applied to the fields of the objects that have just been copied.
 213   template <class T> inline void do_oop_evac(T* p, HeapRegion* from);

























 214 
 215   template <class T> inline void deal_with_reference(T* ref_to_scan);
 216 
 217   inline void dispatch_reference(StarTask ref);
 218  public:
 219 
 220   oop copy_to_survivor_space(oop const obj);
 221 

 222   void trim_queue();
 223 
 224   inline void steal_and_trim_queue(RefToScanQueueSet *task_queues);
 225 };
 226 
 227 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP