hotspot/src/share/vm/gc_implementation/parNew/parOopClosures.inline.hpp
changeset 360 21d113ecbf6a
parent 1 489c9b5090e2
child 5547 f4b087cbb361
equal deleted inserted replaced
357:f4edb0d9f109 360:21d113ecbf6a
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    21  * have any questions.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 inline void ParScanWeakRefClosure::do_oop(oop* p)
    25 template <class T> inline void ParScanWeakRefClosure::do_oop_work(T* p) {
    26 {
    26   assert (!oopDesc::is_null(*p), "null weak reference?");
    27   oop obj = *p;
    27   oop obj = oopDesc::load_decode_heap_oop_not_null(p);
    28   assert (obj != NULL, "null weak reference?");
       
    29   // weak references are sometimes scanned twice; must check
    28   // weak references are sometimes scanned twice; must check
    30   // that to-space doesn't already contain this object
    29   // that to-space doesn't already contain this object
    31   if ((HeapWord*)obj < _boundary && !_g->to()->is_in_reserved(obj)) {
    30   if ((HeapWord*)obj < _boundary && !_g->to()->is_in_reserved(obj)) {
    32     // we need to ensure that it is copied (see comment in
    31     // we need to ensure that it is copied (see comment in
    33     // ParScanClosure::do_oop_work).
    32     // ParScanClosure::do_oop_work).
    34     klassOop objK = obj->klass();
    33     klassOop objK = obj->klass();
    35     markOop m = obj->mark();
    34     markOop m = obj->mark();
       
    35     oop new_obj;
    36     if (m->is_marked()) { // Contains forwarding pointer.
    36     if (m->is_marked()) { // Contains forwarding pointer.
    37       *p = ParNewGeneration::real_forwardee(obj);
    37       new_obj = ParNewGeneration::real_forwardee(obj);
    38     } else {
    38     } else {
    39       size_t obj_sz = obj->size_given_klass(objK->klass_part());
    39       size_t obj_sz = obj->size_given_klass(objK->klass_part());
    40       *p = ((ParNewGeneration*)_g)->copy_to_survivor_space(_par_scan_state,
    40       new_obj = ((ParNewGeneration*)_g)->copy_to_survivor_space(_par_scan_state,
    41                                                            obj, obj_sz, m);
    41                                                                 obj, obj_sz, m);
    42     }
    42     }
       
    43     oopDesc::encode_store_heap_oop_not_null(p, new_obj);
    43   }
    44   }
    44 }
    45 }
    45 
    46 
    46 inline void ParScanWeakRefClosure::do_oop_nv(oop* p)
    47 inline void ParScanWeakRefClosure::do_oop_nv(oop* p)       { ParScanWeakRefClosure::do_oop_work(p); }
    47 {
    48 inline void ParScanWeakRefClosure::do_oop_nv(narrowOop* p) { ParScanWeakRefClosure::do_oop_work(p); }
    48   ParScanWeakRefClosure::do_oop(p);
       
    49 }
       
    50 
    49 
    51 inline void ParScanClosure::par_do_barrier(oop* p) {
    50 template <class T> inline void ParScanClosure::par_do_barrier(T* p) {
    52   assert(generation()->is_in_reserved(p), "expected ref in generation");
    51   assert(generation()->is_in_reserved(p), "expected ref in generation");
    53   oop obj = *p;
    52   assert(!oopDesc::is_null(*p), "expected non-null object");
    54   assert(obj != NULL, "expected non-null object");
    53   oop obj = oopDesc::load_decode_heap_oop_not_null(p);
    55   // If p points to a younger generation, mark the card.
    54   // If p points to a younger generation, mark the card.
    56   if ((HeapWord*)obj < gen_boundary()) {
    55   if ((HeapWord*)obj < gen_boundary()) {
    57     rs()->write_ref_field_gc_par(p, obj);
    56     rs()->write_ref_field_gc_par(p, obj);
    58   }
    57   }
    59 }
    58 }
    60 
    59 
    61 inline void ParScanClosure::do_oop_work(oop* p,
    60 template <class T>
       
    61 inline void ParScanClosure::do_oop_work(T* p,
    62                                         bool gc_barrier,
    62                                         bool gc_barrier,
    63                                         bool root_scan) {
    63                                         bool root_scan) {
    64   oop obj = *p;
       
    65   assert((!Universe::heap()->is_in_reserved(p) ||
    64   assert((!Universe::heap()->is_in_reserved(p) ||
    66           generation()->is_in_reserved(p))
    65           generation()->is_in_reserved(p))
    67          && (generation()->level() == 0 || gc_barrier),
    66          && (generation()->level() == 0 || gc_barrier),
    68          "The gen must be right, and we must be doing the barrier "
    67          "The gen must be right, and we must be doing the barrier "
    69          "in older generations.");
    68          "in older generations.");
    70   if (obj != NULL) {
    69   T heap_oop = oopDesc::load_heap_oop(p);
       
    70   if (!oopDesc::is_null(heap_oop)) {
       
    71     oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
    71     if ((HeapWord*)obj < _boundary) {
    72     if ((HeapWord*)obj < _boundary) {
    72       assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?");
    73       assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?");
    73       // OK, we need to ensure that it is copied.
    74       // OK, we need to ensure that it is copied.
    74       // We read the klass and mark in this order, so that we can reliably
    75       // We read the klass and mark in this order, so that we can reliably
    75       // get the size of the object: if the mark we read is not a
    76       // get the size of the object: if the mark we read is not a
    76       // forwarding pointer, then the klass is valid: the klass is only
    77       // forwarding pointer, then the klass is valid: the klass is only
    77       // overwritten with an overflow next pointer after the object is
    78       // overwritten with an overflow next pointer after the object is
    78       // forwarded.
    79       // forwarded.
    79       klassOop objK = obj->klass();
    80       klassOop objK = obj->klass();
    80       markOop m = obj->mark();
    81       markOop m = obj->mark();
       
    82       oop new_obj;
    81       if (m->is_marked()) { // Contains forwarding pointer.
    83       if (m->is_marked()) { // Contains forwarding pointer.
    82         *p = ParNewGeneration::real_forwardee(obj);
    84         new_obj = ParNewGeneration::real_forwardee(obj);
       
    85         oopDesc::encode_store_heap_oop_not_null(p, new_obj);
    83       } else {
    86       } else {
    84         size_t obj_sz = obj->size_given_klass(objK->klass_part());
    87         size_t obj_sz = obj->size_given_klass(objK->klass_part());
    85         *p = _g->copy_to_survivor_space(_par_scan_state, obj, obj_sz, m);
    88         new_obj = _g->copy_to_survivor_space(_par_scan_state, obj, obj_sz, m);
       
    89         oopDesc::encode_store_heap_oop_not_null(p, new_obj);
    86         if (root_scan) {
    90         if (root_scan) {
    87           // This may have pushed an object.  If we have a root
    91           // This may have pushed an object.  If we have a root
    88           // category with a lot of roots, can't let the queue get too
    92           // category with a lot of roots, can't let the queue get too
    89           // full:
    93           // full:
    90           (void)_par_scan_state->trim_queues(10 * ParallelGCThreads);
    94           (void)_par_scan_state->trim_queues(10 * ParallelGCThreads);
    95         par_do_barrier(p);
    99         par_do_barrier(p);
    96       }
   100       }
    97     }
   101     }
    98   }
   102   }
    99 }
   103 }
       
   104 
       
   105 inline void ParScanWithBarrierClosure::do_oop_nv(oop* p)       { ParScanClosure::do_oop_work(p, true, false); }
       
   106 inline void ParScanWithBarrierClosure::do_oop_nv(narrowOop* p) { ParScanClosure::do_oop_work(p, true, false); }
       
   107 
       
   108 inline void ParScanWithoutBarrierClosure::do_oop_nv(oop* p)       { ParScanClosure::do_oop_work(p, false, false); }
       
   109 inline void ParScanWithoutBarrierClosure::do_oop_nv(narrowOop* p) { ParScanClosure::do_oop_work(p, false, false); }