< prev index next >

src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.inline.hpp

Print this page
rev 8068 : imported patch parallelscavenge_cleanup


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
  27 

  28 #include "gc_implementation/parallelScavenge/psOldGen.hpp"
  29 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
  30 #include "gc_implementation/parallelScavenge/psPromotionLAB.inline.hpp"
  31 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
  32 #include "oops/oop.inline.hpp"
  33 
  34 inline PSPromotionManager* PSPromotionManager::manager_array(int index) {
  35   assert(_manager_array != NULL, "access of NULL manager_array");
  36   assert(index >= 0 && index <= (int)ParallelGCThreads, "out of range manager_array access");
  37   return &_manager_array[index];
  38 }
  39 
  40 template <class T>
  41 inline void PSPromotionManager::claim_or_forward_internal_depth(T* p) {
  42   if (p != NULL) { // XXX: error if p != NULL here
  43     oop o = oopDesc::load_decode_heap_oop_not_null(p);
  44     if (o->is_forwarded()) {
  45       o = o->forwardee();
  46       // Card mark
  47       if (PSScavenge::is_obj_in_young(o)) {
  48         PSScavenge::card_table()->inline_write_ref_field_gc(p, o);
  49       }
  50       oopDesc::encode_store_heap_oop_not_null(p, o);
  51     } else {
  52       push_depth(p);
  53     }
  54   }
  55 }
  56 
  57 template <class T>
  58 inline void PSPromotionManager::claim_or_forward_depth(T* p) {
  59   assert(should_scavenge(p, true), "revisiting object?");
  60   assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap,
  61          "Sanity");
  62   assert(Universe::heap()->is_in(p), "pointer outside heap");
  63 
  64   claim_or_forward_internal_depth(p);
  65 }
  66 
  67 inline void PSPromotionManager::promotion_trace_event(oop new_obj, oop old_obj,
  68                                                       size_t obj_size,
  69                                                       uint age, bool tenured,
  70                                                       const PSPromotionLAB* lab) {
  71   // Skip if memory allocation failed
  72   if (new_obj != NULL) {
  73     const ParallelScavengeTracer* gc_tracer = PSScavenge::gc_tracer();
  74 
  75     if (lab != NULL) {
  76       // Promotion of object through newly allocated PLAB
  77       if (gc_tracer->should_report_promotion_in_new_plab_event()) {
  78         size_t obj_bytes = obj_size * HeapWordSize;
  79         size_t lab_size = lab->capacity();
  80         gc_tracer->report_promotion_in_new_plab_event(old_obj->klass(), obj_bytes,
  81                                                       age, tenured, lab_size);
  82       }


 133             // Flush and fill
 134             _young_lab.flush();
 135 
 136             HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
 137             if (lab_base != NULL) {
 138               _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
 139               // Try the young lab allocation again.
 140               new_obj = (oop) _young_lab.allocate(new_obj_size);
 141               promotion_trace_event(new_obj, o, new_obj_size, age, false, &_young_lab);
 142             } else {
 143               _young_gen_is_full = true;
 144             }
 145           }
 146         }
 147       }
 148     }
 149 
 150     // Otherwise try allocating obj tenured
 151     if (new_obj == NULL) {
 152 #ifndef PRODUCT
 153       if (Universe::heap()->promotion_should_fail()) {
 154         return oop_promotion_failed(o, test_mark);
 155       }
 156 #endif  // #ifndef PRODUCT
 157 
 158       new_obj = (oop) _old_lab.allocate(new_obj_size);
 159       new_obj_is_tenured = true;
 160 
 161       if (new_obj == NULL) {
 162         if (!_old_gen_is_full) {
 163           // Do we allocate directly, or flush and refill?
 164           if (new_obj_size > (OldPLABSize / 2)) {
 165             // Allocate this object directly
 166             new_obj = (oop)old_gen()->cas_allocate(new_obj_size);
 167             promotion_trace_event(new_obj, o, new_obj_size, age, true, NULL);
 168           } else {
 169             // Flush and fill
 170             _old_lab.flush();
 171 
 172             HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize);
 173             if(lab_base != NULL) {


 279   oop new_obj = o->is_forwarded()
 280         ? o->forwardee()
 281         : copy_to_survivor_space<promote_immediately>(o);
 282 
 283 #ifndef PRODUCT
 284   // This code must come after the CAS test, or it will print incorrect
 285   // information.
 286   if (TraceScavenge &&  o->is_forwarded()) {
 287     gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}",
 288        "forwarding",
 289        new_obj->klass()->internal_name(), p2i((void *)o), p2i((void *)new_obj), new_obj->size());
 290   }
 291 #endif
 292 
 293   oopDesc::encode_store_heap_oop_not_null(p, new_obj);
 294 
 295   // We cannot mark without test, as some code passes us pointers
 296   // that are outside the heap. These pointers are either from roots
 297   // or from metadata.
 298   if ((!PSScavenge::is_obj_in_young((HeapWord*)p)) &&
 299       Universe::heap()->is_in_reserved(p)) {
 300     if (PSScavenge::is_obj_in_young(new_obj)) {
 301       PSScavenge::card_table()->inline_write_ref_field_gc(p, new_obj);
 302     }
 303   }
 304 }
 305 
 306 inline void PSPromotionManager::process_popped_location_depth(StarTask p) {
 307   if (is_oop_masked(p)) {
 308     assert(PSChunkLargeArrays, "invariant");
 309     oop const old = unmask_chunked_array_oop(p);
 310     process_array_chunk(old);
 311   } else {
 312     if (p.is_narrow()) {
 313       assert(UseCompressedOops, "Error");
 314       copy_and_push_safe_barrier<narrowOop, /*promote_immediately=*/false>(p);
 315     } else {
 316       copy_and_push_safe_barrier<oop, /*promote_immediately=*/false>(p);
 317     }
 318   }
 319 }


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
  27 
  28 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  29 #include "gc_implementation/parallelScavenge/psOldGen.hpp"
  30 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
  31 #include "gc_implementation/parallelScavenge/psPromotionLAB.inline.hpp"
  32 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
  33 #include "oops/oop.inline.hpp"
  34 
  35 inline PSPromotionManager* PSPromotionManager::manager_array(int index) {
  36   assert(_manager_array != NULL, "access of NULL manager_array");
  37   assert(index >= 0 && index <= (int)ParallelGCThreads, "out of range manager_array access");
  38   return &_manager_array[index];
  39 }
  40 
  41 template <class T>
  42 inline void PSPromotionManager::claim_or_forward_internal_depth(T* p) {
  43   if (p != NULL) { // XXX: error if p != NULL here
  44     oop o = oopDesc::load_decode_heap_oop_not_null(p);
  45     if (o->is_forwarded()) {
  46       o = o->forwardee();
  47       // Card mark
  48       if (PSScavenge::is_obj_in_young(o)) {
  49         PSScavenge::card_table()->inline_write_ref_field_gc(p, o);
  50       }
  51       oopDesc::encode_store_heap_oop_not_null(p, o);
  52     } else {
  53       push_depth(p);
  54     }
  55   }
  56 }
  57 
  58 template <class T>
  59 inline void PSPromotionManager::claim_or_forward_depth(T* p) {
  60   assert(should_scavenge(p, true), "revisiting object?");
  61   assert(ParallelScavengeHeap::heap()->is_in(p), "pointer outside heap");


  62 
  63   claim_or_forward_internal_depth(p);
  64 }
  65 
  66 inline void PSPromotionManager::promotion_trace_event(oop new_obj, oop old_obj,
  67                                                       size_t obj_size,
  68                                                       uint age, bool tenured,
  69                                                       const PSPromotionLAB* lab) {
  70   // Skip if memory allocation failed
  71   if (new_obj != NULL) {
  72     const ParallelScavengeTracer* gc_tracer = PSScavenge::gc_tracer();
  73 
  74     if (lab != NULL) {
  75       // Promotion of object through newly allocated PLAB
  76       if (gc_tracer->should_report_promotion_in_new_plab_event()) {
  77         size_t obj_bytes = obj_size * HeapWordSize;
  78         size_t lab_size = lab->capacity();
  79         gc_tracer->report_promotion_in_new_plab_event(old_obj->klass(), obj_bytes,
  80                                                       age, tenured, lab_size);
  81       }


 132             // Flush and fill
 133             _young_lab.flush();
 134 
 135             HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
 136             if (lab_base != NULL) {
 137               _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
 138               // Try the young lab allocation again.
 139               new_obj = (oop) _young_lab.allocate(new_obj_size);
 140               promotion_trace_event(new_obj, o, new_obj_size, age, false, &_young_lab);
 141             } else {
 142               _young_gen_is_full = true;
 143             }
 144           }
 145         }
 146       }
 147     }
 148 
 149     // Otherwise try allocating obj tenured
 150     if (new_obj == NULL) {
 151 #ifndef PRODUCT
 152       if (ParallelScavengeHeap::heap()->promotion_should_fail()) {
 153         return oop_promotion_failed(o, test_mark);
 154       }
 155 #endif  // #ifndef PRODUCT
 156 
 157       new_obj = (oop) _old_lab.allocate(new_obj_size);
 158       new_obj_is_tenured = true;
 159 
 160       if (new_obj == NULL) {
 161         if (!_old_gen_is_full) {
 162           // Do we allocate directly, or flush and refill?
 163           if (new_obj_size > (OldPLABSize / 2)) {
 164             // Allocate this object directly
 165             new_obj = (oop)old_gen()->cas_allocate(new_obj_size);
 166             promotion_trace_event(new_obj, o, new_obj_size, age, true, NULL);
 167           } else {
 168             // Flush and fill
 169             _old_lab.flush();
 170 
 171             HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize);
 172             if(lab_base != NULL) {


 278   oop new_obj = o->is_forwarded()
 279         ? o->forwardee()
 280         : copy_to_survivor_space<promote_immediately>(o);
 281 
 282 #ifndef PRODUCT
 283   // This code must come after the CAS test, or it will print incorrect
 284   // information.
 285   if (TraceScavenge &&  o->is_forwarded()) {
 286     gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}",
 287        "forwarding",
 288        new_obj->klass()->internal_name(), p2i((void *)o), p2i((void *)new_obj), new_obj->size());
 289   }
 290 #endif
 291 
 292   oopDesc::encode_store_heap_oop_not_null(p, new_obj);
 293 
 294   // We cannot mark without test, as some code passes us pointers
 295   // that are outside the heap. These pointers are either from roots
 296   // or from metadata.
 297   if ((!PSScavenge::is_obj_in_young((HeapWord*)p)) &&
 298       ParallelScavengeHeap::heap()->is_in_reserved(p)) {
 299     if (PSScavenge::is_obj_in_young(new_obj)) {
 300       PSScavenge::card_table()->inline_write_ref_field_gc(p, new_obj);
 301     }
 302   }
 303 }
 304 
 305 inline void PSPromotionManager::process_popped_location_depth(StarTask p) {
 306   if (is_oop_masked(p)) {
 307     assert(PSChunkLargeArrays, "invariant");
 308     oop const old = unmask_chunked_array_oop(p);
 309     process_array_chunk(old);
 310   } else {
 311     if (p.is_narrow()) {
 312       assert(UseCompressedOops, "Error");
 313       copy_and_push_safe_barrier<narrowOop, /*promote_immediately=*/false>(p);
 314     } else {
 315       copy_and_push_safe_barrier<oop, /*promote_immediately=*/false>(p);
 316     }
 317   }
 318 }
< prev index next >