1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)oop.pcgc.inline.hpp  1.16 07/05/29 09:44:24 JVM"
   3 #endif
   4 /*
   5  * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 inline void oopDesc::update_contents(ParCompactionManager* cm) {
  29   // The klass field must be updated before anything else
  30   // can be done.
  31   DEBUG_ONLY(klassOopDesc* original_klass = klass());
  32 
  33   // Can the option to update and/or copy be moved up in the
  34   // call chain to avoid calling into here?
  35  
  36   if (PSParallelCompact::should_update_klass(klass())) {
  37     update_header();
  38     assert(klass()->is_klass(), "Not updated correctly");
  39   } else {
  40     assert(klass()->is_klass(), "Not updated");
  41   }
  42 
  43   Klass* new_klass = blueprint();
  44   if (!new_klass->oop_is_typeArray()) {
  45     // It might contain oops beyond the header, so take the virtual call.
  46     new_klass->oop_update_pointers(cm, this);
  47   }
  48   // Else skip it.  The typeArrayKlass in the header never needs scavenging.
  49 }
  50 
  51 inline void oopDesc::update_contents(ParCompactionManager* cm,
  52                                      HeapWord* begin_limit,
  53                                      HeapWord* end_limit) {
  54   // The klass field must be updated before anything else
  55   // can be done.
  56   debug_only(klassOopDesc* original_klass = klass());
  57 
  58   update_contents(cm, klass(), begin_limit, end_limit);
  59 }
  60 
  61 inline void oopDesc::update_contents(ParCompactionManager* cm,
  62                                      klassOop old_klass,
  63                                      HeapWord* begin_limit,
  64                                      HeapWord* end_limit) {
  65 
  66   klassOop updated_klass = 
  67     PSParallelCompact::summary_data().calc_new_klass(old_klass);
  68 
  69   // Needs to be boundary aware for the 64 bit case
  70   // update_header();
  71   // The klass has moved.  Is the location of the klass
  72   // within the limits?
  73   if ((((HeapWord*)&_metadata._klass) >= begin_limit) &&
  74       (((HeapWord*)&_metadata._klass) < end_limit)) {
  75     set_klass(updated_klass);
  76   }
  77 
  78   Klass* klass = updated_klass->klass_part();
  79   if (!klass->oop_is_typeArray()) {
  80     // It might contain oops beyond the header, so take the virtual call.
  81     klass->oop_update_pointers(cm, this, begin_limit, end_limit);
  82   }
  83   // Else skip it.  The typeArrayKlass in the header never needs scavenging.
  84 }
  85 
  86 inline void oopDesc::follow_contents(ParCompactionManager* cm) {
  87   assert (PSParallelCompact::mark_bitmap()->is_marked(this), 
  88     "should be marked");
  89   blueprint()->oop_follow_contents(cm, this);
  90 }
  91 
  92 // Used by parallel old GC.
  93 
  94 inline void oopDesc::follow_header(ParCompactionManager* cm) {
  95   if (UseCompressedOops) {
  96     PSParallelCompact::mark_and_push(cm, compressed_klass_addr());
  97   } else {
  98     PSParallelCompact::mark_and_push(cm, klass_addr());
  99   }
 100 }
 101 
 102 inline oop oopDesc::forward_to_atomic(oop p) {
 103   assert(ParNewGeneration::is_legal_forward_ptr(p),
 104          "illegal forwarding pointer value.");
 105   markOop oldMark = mark();
 106   markOop forwardPtrMark = markOopDesc::encode_pointer_as_mark(p);
 107   markOop curMark;
 108 
 109   assert(forwardPtrMark->decode_pointer() == p, "encoding must be reversable");
 110   assert(sizeof(markOop) == sizeof(intptr_t), "CAS below requires this.");
 111 
 112   while (!is_forwarded()) {
 113     curMark = (markOop)Atomic::cmpxchg_ptr(forwardPtrMark, &_mark, oldMark);
 114     if (curMark == oldMark) {
 115       assert(is_forwarded(), "the CAS should have succeeded.");
 116       return NULL;
 117     }
 118     oldMark = curMark;
 119   }
 120   return forwardee();
 121 }
 122 
 123 inline void oopDesc::update_header() {
 124   if (UseCompressedOops) {
 125     PSParallelCompact::adjust_pointer(compressed_klass_addr());
 126   } else {
 127     PSParallelCompact::adjust_pointer(klass_addr());
 128   }
 129 }
 130 
 131 inline void oopDesc::update_header(HeapWord* beg_addr, HeapWord* end_addr) {
 132   if (UseCompressedOops) {
 133     PSParallelCompact::adjust_pointer(compressed_klass_addr(),
 134                                       beg_addr, end_addr);
 135   } else {
 136     PSParallelCompact::adjust_pointer(klass_addr(), beg_addr, end_addr);
 137   }
 138 }