< prev index next >

src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp

Print this page

 44 
 45 inline PSPromotionManager* PSPromotionManager::manager_array(uint index) {
 46   assert(_manager_array != NULL, "access of NULL manager_array");
 47   assert(index <= ParallelGCThreads, "out of range manager_array access");
 48   return &_manager_array[index];
 49 }
 50 
 51 inline void PSPromotionManager::push_depth(ScannerTask task) {
 52   claimed_stack_depth()->push(task);
 53 }
 54 
 55 template <class T>
 56 inline void PSPromotionManager::claim_or_forward_depth(T* p) {
 57   assert(should_scavenge(p, true), "revisiting object?");
 58   assert(ParallelScavengeHeap::heap()->is_in(p), "pointer outside heap");
 59   oop obj = RawAccess<IS_NOT_NULL>::oop_load(p);
 60   Prefetch::write(obj->mark_addr(), 0);
 61   push_depth(ScannerTask(p));
 62 }
 63 
 64 inline void PSPromotionManager::promotion_trace_event(oop new_obj, oop old_obj,
 65                                                       size_t obj_size,
 66                                                       uint age, bool tenured,
 67                                                       const PSPromotionLAB* lab) {
 68   // Skip if memory allocation failed
 69   if (new_obj != NULL) {
 70     const ParallelScavengeTracer* gc_tracer = PSScavenge::gc_tracer();
 71 
 72     if (lab != NULL) {
 73       // Promotion of object through newly allocated PLAB
 74       if (gc_tracer->should_report_promotion_in_new_plab_event()) {
 75         size_t obj_bytes = obj_size * HeapWordSize;
 76         size_t lab_size = lab->capacity();
 77         gc_tracer->report_promotion_in_new_plab_event(old_obj->klass(), obj_bytes,
 78                                                       age, tenured, lab_size);
 79       }
 80     } else {
 81       // Promotion of object directly to heap
 82       if (gc_tracer->should_report_promotion_outside_plab_event()) {
 83         size_t obj_bytes = obj_size * HeapWordSize;
 84         gc_tracer->report_promotion_outside_plab_event(old_obj->klass(), obj_bytes,
 85                                                        age, tenured);
 86       }
 87     }
 88   }
 89 }
 90 
 91 class PSPushContentsClosure: public BasicOopIterateClosure {
 92   PSPromotionManager* _pm;
 93  public:
 94   PSPushContentsClosure(PSPromotionManager* pm) : BasicOopIterateClosure(PSScavenge::reference_processor()), _pm(pm) {}
 95 
 96   template <typename T> void do_oop_nv(T* p) {
 97     if (PSScavenge::should_scavenge(p)) {
 98       _pm->claim_or_forward_depth(p);
 99     }
100   }
101 
102   virtual void do_oop(oop* p)       { do_oop_nv(p); }
103   virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
104 };

128     obj->oop_iterate_backwards(&pcc);
129   }
130 }
131 
132 template<bool promote_immediately>
133 inline oop PSPromotionManager::copy_to_survivor_space(oop o) {
134   assert(should_scavenge(&o), "Sanity");
135 
136   // NOTE! We must be very careful with any methods that access the mark
137   // in o. There may be multiple threads racing on it, and it may be forwarded
138   // at any time.
139   markWord m = o->mark();
140   if (!m.is_marked()) {
141     return copy_unmarked_to_survivor_space<promote_immediately>(o, m);
142   } else {
143     // Ensure any loads from the forwardee follow all changes that precede
144     // the release-cmpxchg that performed the forwarding, possibly in some
145     // other thread.
146     OrderAccess::acquire();
147     // Return the already installed forwardee.
148     return cast_to_oop(m.decode_pointer());
149   }
150 }
151 
152 //
153 // This method is pretty bulky. It would be nice to split it up
154 // into smaller submethods, but we need to be careful not to hurt
155 // performance.
156 //
157 template<bool promote_immediately>
158 inline oop PSPromotionManager::copy_unmarked_to_survivor_space(oop o,
159                                                                markWord test_mark) {
160   assert(should_scavenge(&o), "Sanity");
161 
162   oop new_obj = NULL;
163   bool new_obj_is_tenured = false;
164   size_t new_obj_size = o->size();





165 
166   // Find the objects age, MT safe.
167   uint age = (test_mark.has_displaced_mark_helper() /* o->has_displaced_mark() */) ?
168       test_mark.displaced_mark_helper().age() : test_mark.age();
169 
170   if (!promote_immediately) {
171     // Try allocating obj in to-space (unless too old)
172     if (age < PSScavenge::tenuring_threshold()) {
173       new_obj = cast_to_oop(_young_lab.allocate(new_obj_size));
174       if (new_obj == NULL && !_young_gen_is_full) {
175         // Do we allocate directly, or flush and refill?
176         if (new_obj_size > (YoungPLABSize / 2)) {
177           // Allocate this object directly
178           new_obj = cast_to_oop(young_space()->cas_allocate(new_obj_size));
179           promotion_trace_event(new_obj, o, new_obj_size, age, false, NULL);
180         } else {
181           // Flush and fill
182           _young_lab.flush();
183 
184           HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
185           if (lab_base != NULL) {
186             _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
187             // Try the young lab allocation again.
188             new_obj = cast_to_oop(_young_lab.allocate(new_obj_size));
189             promotion_trace_event(new_obj, o, new_obj_size, age, false, &_young_lab);
190           } else {
191             _young_gen_is_full = true;
192           }
193         }
194       }
195     }
196   }
197 
198   // Otherwise try allocating obj tenured
199   if (new_obj == NULL) {
200 #ifndef PRODUCT
201     if (ParallelScavengeHeap::heap()->promotion_should_fail()) {
202       return oop_promotion_failed(o, test_mark);
203     }
204 #endif  // #ifndef PRODUCT
205 
206     new_obj = cast_to_oop(_old_lab.allocate(new_obj_size));
207     new_obj_is_tenured = true;
208 
209     if (new_obj == NULL) {
210       if (!_old_gen_is_full) {
211         // Do we allocate directly, or flush and refill?
212         if (new_obj_size > (OldPLABSize / 2)) {
213           // Allocate this object directly
214           new_obj = cast_to_oop(old_gen()->allocate(new_obj_size));
215           promotion_trace_event(new_obj, o, new_obj_size, age, true, NULL);
216         } else {
217           // Flush and fill
218           _old_lab.flush();
219 
220           HeapWord* lab_base = old_gen()->allocate(OldPLABSize);
221           if(lab_base != NULL) {
222 #ifdef ASSERT
223             // Delay the initialization of the promotion lab (plab).
224             // This exposes uninitialized plabs to card table processing.
225             if (GCWorkerDelayMillis > 0) {
226               os::naked_sleep(GCWorkerDelayMillis);
227             }
228 #endif
229             _old_lab.initialize(MemRegion(lab_base, OldPLABSize));
230             // Try the old lab allocation again.
231             new_obj = cast_to_oop(_old_lab.allocate(new_obj_size));
232             promotion_trace_event(new_obj, o, new_obj_size, age, true, &_old_lab);
233           }
234         }
235       }
236 
237       // This is the promotion failed test, and code handling.
238       // The code belongs here for two reasons. It is slightly
239       // different than the code below, and cannot share the
240       // CAS testing code. Keeping the code here also minimizes
241       // the impact on the common case fast path code.
242 
243       if (new_obj == NULL) {
244         _old_gen_is_full = true;
245         return oop_promotion_failed(o, test_mark);
246       }
247     }
248   }
249 
250   assert(new_obj != NULL, "allocation should have succeeded");
251 
252   // Copy obj

 44 
 45 inline PSPromotionManager* PSPromotionManager::manager_array(uint index) {
 46   assert(_manager_array != NULL, "access of NULL manager_array");
 47   assert(index <= ParallelGCThreads, "out of range manager_array access");
 48   return &_manager_array[index];
 49 }
 50 
 51 inline void PSPromotionManager::push_depth(ScannerTask task) {
 52   claimed_stack_depth()->push(task);
 53 }
 54 
 55 template <class T>
 56 inline void PSPromotionManager::claim_or_forward_depth(T* p) {
 57   assert(should_scavenge(p, true), "revisiting object?");
 58   assert(ParallelScavengeHeap::heap()->is_in(p), "pointer outside heap");
 59   oop obj = RawAccess<IS_NOT_NULL>::oop_load(p);
 60   Prefetch::write(obj->mark_addr(), 0);
 61   push_depth(ScannerTask(p));
 62 }
 63 
 64 inline void PSPromotionManager::promotion_trace_event(oop new_obj, oop old_obj, Klass* klass,
 65                                                       size_t obj_size,
 66                                                       uint age, bool tenured,
 67                                                       const PSPromotionLAB* lab) {
 68   // Skip if memory allocation failed
 69   if (new_obj != NULL) {
 70     const ParallelScavengeTracer* gc_tracer = PSScavenge::gc_tracer();
 71 
 72     if (lab != NULL) {
 73       // Promotion of object through newly allocated PLAB
 74       if (gc_tracer->should_report_promotion_in_new_plab_event()) {
 75         size_t obj_bytes = obj_size * HeapWordSize;
 76         size_t lab_size = lab->capacity();
 77         gc_tracer->report_promotion_in_new_plab_event(klass, obj_bytes,
 78                                                       age, tenured, lab_size);
 79       }
 80     } else {
 81       // Promotion of object directly to heap
 82       if (gc_tracer->should_report_promotion_outside_plab_event()) {
 83         size_t obj_bytes = obj_size * HeapWordSize;
 84         gc_tracer->report_promotion_outside_plab_event(klass, obj_bytes,
 85                                                        age, tenured);
 86       }
 87     }
 88   }
 89 }
 90 
 91 class PSPushContentsClosure: public BasicOopIterateClosure {
 92   PSPromotionManager* _pm;
 93  public:
 94   PSPushContentsClosure(PSPromotionManager* pm) : BasicOopIterateClosure(PSScavenge::reference_processor()), _pm(pm) {}
 95 
 96   template <typename T> void do_oop_nv(T* p) {
 97     if (PSScavenge::should_scavenge(p)) {
 98       _pm->claim_or_forward_depth(p);
 99     }
100   }
101 
102   virtual void do_oop(oop* p)       { do_oop_nv(p); }
103   virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
104 };

128     obj->oop_iterate_backwards(&pcc);
129   }
130 }
131 
132 template<bool promote_immediately>
133 inline oop PSPromotionManager::copy_to_survivor_space(oop o) {
134   assert(should_scavenge(&o), "Sanity");
135 
136   // NOTE! We must be very careful with any methods that access the mark
137   // in o. There may be multiple threads racing on it, and it may be forwarded
138   // at any time.
139   markWord m = o->mark();
140   if (!m.is_marked()) {
141     return copy_unmarked_to_survivor_space<promote_immediately>(o, m);
142   } else {
143     // Ensure any loads from the forwardee follow all changes that precede
144     // the release-cmpxchg that performed the forwarding, possibly in some
145     // other thread.
146     OrderAccess::acquire();
147     // Return the already installed forwardee.
148     return o->forwardee(m);
149   }
150 }
151 
152 //
153 // This method is pretty bulky. It would be nice to split it up
154 // into smaller submethods, but we need to be careful not to hurt
155 // performance.
156 //
157 template<bool promote_immediately>
158 inline oop PSPromotionManager::copy_unmarked_to_survivor_space(oop o,
159                                                                markWord test_mark) {
160   assert(should_scavenge(&o), "Sanity");
161 
162   oop new_obj = NULL;
163   bool new_obj_is_tenured = false;
164 #ifdef _LP64
165   Klass* klass = test_mark.safe_klass();
166 #else
167   Klass* klass = o->klass();
168 #endif
169   size_t new_obj_size = o->size_given_klass(klass);
170 
171   // Find the objects age, MT safe.
172   uint age = (test_mark.has_displaced_mark_helper() /* o->has_displaced_mark() */) ?
173       test_mark.displaced_mark_helper().age() : test_mark.age();
174 
175   if (!promote_immediately) {
176     // Try allocating obj in to-space (unless too old)
177     if (age < PSScavenge::tenuring_threshold()) {
178       new_obj = cast_to_oop(_young_lab.allocate(new_obj_size));
179       if (new_obj == NULL && !_young_gen_is_full) {
180         // Do we allocate directly, or flush and refill?
181         if (new_obj_size > (YoungPLABSize / 2)) {
182           // Allocate this object directly
183           new_obj = cast_to_oop(young_space()->cas_allocate(new_obj_size));
184           promotion_trace_event(new_obj, o, klass, new_obj_size, age, false, NULL);
185         } else {
186           // Flush and fill
187           _young_lab.flush();
188 
189           HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
190           if (lab_base != NULL) {
191             _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
192             // Try the young lab allocation again.
193             new_obj = cast_to_oop(_young_lab.allocate(new_obj_size));
194             promotion_trace_event(new_obj, o, klass, new_obj_size, age, false, &_young_lab);
195           } else {
196             _young_gen_is_full = true;
197           }
198         }
199       }
200     }
201   }
202 
203   // Otherwise try allocating obj tenured
204   if (new_obj == NULL) {
205 #ifndef PRODUCT
206     if (ParallelScavengeHeap::heap()->promotion_should_fail()) {
207       return oop_promotion_failed(o, test_mark);
208     }
209 #endif  // #ifndef PRODUCT
210 
211     new_obj = cast_to_oop(_old_lab.allocate(new_obj_size));
212     new_obj_is_tenured = true;
213 
214     if (new_obj == NULL) {
215       if (!_old_gen_is_full) {
216         // Do we allocate directly, or flush and refill?
217         if (new_obj_size > (OldPLABSize / 2)) {
218           // Allocate this object directly
219           new_obj = cast_to_oop(old_gen()->allocate(new_obj_size));
220           promotion_trace_event(new_obj, o, klass, new_obj_size, age, true, NULL);
221         } else {
222           // Flush and fill
223           _old_lab.flush();
224 
225           HeapWord* lab_base = old_gen()->allocate(OldPLABSize);
226           if(lab_base != NULL) {
227 #ifdef ASSERT
228             // Delay the initialization of the promotion lab (plab).
229             // This exposes uninitialized plabs to card table processing.
230             if (GCWorkerDelayMillis > 0) {
231               os::naked_sleep(GCWorkerDelayMillis);
232             }
233 #endif
234             _old_lab.initialize(MemRegion(lab_base, OldPLABSize));
235             // Try the old lab allocation again.
236             new_obj = cast_to_oop(_old_lab.allocate(new_obj_size));
237             promotion_trace_event(new_obj, o, klass, new_obj_size, age, true, &_old_lab);
238           }
239         }
240       }
241 
242       // This is the promotion failed test, and code handling.
243       // The code belongs here for two reasons. It is slightly
244       // different than the code below, and cannot share the
245       // CAS testing code. Keeping the code here also minimizes
246       // the impact on the common case fast path code.
247 
248       if (new_obj == NULL) {
249         _old_gen_is_full = true;
250         return oop_promotion_failed(o, test_mark);
251       }
252     }
253   }
254 
255   assert(new_obj != NULL, "allocation should have succeeded");
256 
257   // Copy obj
< prev index next >