< prev index next >

src/hotspot/share/oops/oop.inline.hpp

Print this page




  93   if (UseCompressedClassPointers) {
  94     return CompressedKlassPointers::decode_not_null(_metadata._compressed_klass);
  95   } else {
  96     return _metadata._klass;
  97   }
  98 }
  99 
 100 Klass* oopDesc::klass_or_null() const volatile {
 101   if (UseCompressedClassPointers) {
 102     return CompressedKlassPointers::decode(_metadata._compressed_klass);
 103   } else {
 104     return _metadata._klass;
 105   }
 106 }
 107 
 108 Klass* oopDesc::klass_or_null_acquire() const volatile {
 109   if (UseCompressedClassPointers) {
 110     // Workaround for non-const load_acquire parameter.
 111     const volatile narrowKlass* addr = &_metadata._compressed_klass;
 112     volatile narrowKlass* xaddr = const_cast<volatile narrowKlass*>(addr);
 113     return CompressedKlassPointers::decode(OrderAccess::load_acquire(xaddr));
 114   } else {
 115     return OrderAccess::load_acquire(&_metadata._klass);
 116   }
 117 }
 118 
 119 Klass** oopDesc::klass_addr(HeapWord* mem) {
 120   // Only used internally and with CMS and will not work with
 121   // UseCompressedOops
 122   assert(!UseCompressedClassPointers, "only supported with uncompressed klass pointers");
 123   ByteSize offset = byte_offset_of(oopDesc, _metadata._klass);
 124   return (Klass**) (((char*)mem) + in_bytes(offset));
 125 }
 126 
 127 narrowKlass* oopDesc::compressed_klass_addr(HeapWord* mem) {
 128   assert(UseCompressedClassPointers, "only called by compressed klass pointers");
 129   ByteSize offset = byte_offset_of(oopDesc, _metadata._compressed_klass);
 130   return (narrowKlass*) (((char*)mem) + in_bytes(offset));
 131 }
 132 
 133 Klass** oopDesc::klass_addr() {
 134   return klass_addr((HeapWord*)this);
 135 }


 139 }
 140 
 141 #define CHECK_SET_KLASS(k)                                                \
 142   do {                                                                    \
 143     assert(Universe::is_bootstrapping() || k != NULL, "NULL Klass");      \
 144     assert(Universe::is_bootstrapping() || k->is_klass(), "not a Klass"); \
 145   } while (0)
 146 
 147 void oopDesc::set_klass(Klass* k) {
 148   CHECK_SET_KLASS(k);
 149   if (UseCompressedClassPointers) {
 150     *compressed_klass_addr() = CompressedKlassPointers::encode_not_null(k);
 151   } else {
 152     *klass_addr() = k;
 153   }
 154 }
 155 
 156 void oopDesc::release_set_klass(HeapWord* mem, Klass* klass) {
 157   CHECK_SET_KLASS(klass);
 158   if (UseCompressedClassPointers) {
 159     OrderAccess::release_store(compressed_klass_addr(mem),
 160                                CompressedKlassPointers::encode_not_null(klass));
 161   } else {
 162     OrderAccess::release_store(klass_addr(mem), klass);
 163   }
 164 }
 165 
 166 #undef CHECK_SET_KLASS
 167 
 168 int oopDesc::klass_gap() const {
 169   return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
 170 }
 171 
 172 void oopDesc::set_klass_gap(HeapWord* mem, int v) {
 173   if (UseCompressedClassPointers) {
 174     *(int*)(((char*)mem) + klass_gap_offset_in_bytes()) = v;
 175   }
 176 }
 177 
 178 void oopDesc::set_klass_gap(int v) {
 179   set_klass_gap((HeapWord*)this, v);
 180 }
 181 
 182 bool oopDesc::is_a(Klass* k) const {


 339   assert(m.decode_pointer() == p, "encoding must be reversable");
 340   markWord old_mark = cas_set_mark_raw(m, compare, order);
 341   if (old_mark == compare) {
 342     return NULL;
 343   } else {
 344     return (oop)old_mark.decode_pointer();
 345   }
 346 }
 347 
 348 // Note that the forwardee is not the same thing as the displaced_mark.
 349 // The forwardee is used when copying during scavenge and mark-sweep.
 350 // It does need to clear the low two locking- and GC-related bits.
 351 oop oopDesc::forwardee() const {
 352   return (oop) mark_raw().decode_pointer();
 353 }
 354 
 355 // Note that the forwardee is not the same thing as the displaced_mark.
 356 // The forwardee is used when copying during scavenge and mark-sweep.
 357 // It does need to clear the low two locking- and GC-related bits.
 358 oop oopDesc::forwardee_acquire() const {
 359   return (oop) OrderAccess::load_acquire(&_mark).decode_pointer();
 360 }
 361 
 362 // The following method needs to be MT safe.
 363 uint oopDesc::age() const {
 364   assert(!is_forwarded(), "Attempt to read age from forwarded mark");
 365   if (has_displaced_mark_raw()) {
 366     return displaced_mark_raw().age();
 367   } else {
 368     return mark_raw().age();
 369   }
 370 }
 371 
 372 void oopDesc::incr_age() {
 373   assert(!is_forwarded(), "Attempt to increment age of forwarded mark");
 374   if (has_displaced_mark_raw()) {
 375     set_displaced_mark_raw(displaced_mark_raw().incr_age());
 376   } else {
 377     set_mark_raw(mark_raw().incr_age());
 378   }
 379 }




  93   if (UseCompressedClassPointers) {
  94     return CompressedKlassPointers::decode_not_null(_metadata._compressed_klass);
  95   } else {
  96     return _metadata._klass;
  97   }
  98 }
  99 
 100 Klass* oopDesc::klass_or_null() const volatile {
 101   if (UseCompressedClassPointers) {
 102     return CompressedKlassPointers::decode(_metadata._compressed_klass);
 103   } else {
 104     return _metadata._klass;
 105   }
 106 }
 107 
 108 Klass* oopDesc::klass_or_null_acquire() const volatile {
 109   if (UseCompressedClassPointers) {
 110     // Workaround for non-const load_acquire parameter.
 111     const volatile narrowKlass* addr = &_metadata._compressed_klass;
 112     volatile narrowKlass* xaddr = const_cast<volatile narrowKlass*>(addr);
 113     return CompressedKlassPointers::decode(Atomic::load_acquire(xaddr));
 114   } else {
 115     return Atomic::load_acquire(&_metadata._klass);
 116   }
 117 }
 118 
 119 Klass** oopDesc::klass_addr(HeapWord* mem) {
 120   // Only used internally and with CMS and will not work with
 121   // UseCompressedOops
 122   assert(!UseCompressedClassPointers, "only supported with uncompressed klass pointers");
 123   ByteSize offset = byte_offset_of(oopDesc, _metadata._klass);
 124   return (Klass**) (((char*)mem) + in_bytes(offset));
 125 }
 126 
 127 narrowKlass* oopDesc::compressed_klass_addr(HeapWord* mem) {
 128   assert(UseCompressedClassPointers, "only called by compressed klass pointers");
 129   ByteSize offset = byte_offset_of(oopDesc, _metadata._compressed_klass);
 130   return (narrowKlass*) (((char*)mem) + in_bytes(offset));
 131 }
 132 
 133 Klass** oopDesc::klass_addr() {
 134   return klass_addr((HeapWord*)this);
 135 }


 139 }
 140 
 141 #define CHECK_SET_KLASS(k)                                                \
 142   do {                                                                    \
 143     assert(Universe::is_bootstrapping() || k != NULL, "NULL Klass");      \
 144     assert(Universe::is_bootstrapping() || k->is_klass(), "not a Klass"); \
 145   } while (0)
 146 
 147 void oopDesc::set_klass(Klass* k) {
 148   CHECK_SET_KLASS(k);
 149   if (UseCompressedClassPointers) {
 150     *compressed_klass_addr() = CompressedKlassPointers::encode_not_null(k);
 151   } else {
 152     *klass_addr() = k;
 153   }
 154 }
 155 
 156 void oopDesc::release_set_klass(HeapWord* mem, Klass* klass) {
 157   CHECK_SET_KLASS(klass);
 158   if (UseCompressedClassPointers) {
 159     Atomic::release_store(compressed_klass_addr(mem),
 160                           CompressedKlassPointers::encode_not_null(klass));
 161   } else {
 162     Atomic::release_store(klass_addr(mem), klass);
 163   }
 164 }
 165 
 166 #undef CHECK_SET_KLASS
 167 
 168 int oopDesc::klass_gap() const {
 169   return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
 170 }
 171 
 172 void oopDesc::set_klass_gap(HeapWord* mem, int v) {
 173   if (UseCompressedClassPointers) {
 174     *(int*)(((char*)mem) + klass_gap_offset_in_bytes()) = v;
 175   }
 176 }
 177 
 178 void oopDesc::set_klass_gap(int v) {
 179   set_klass_gap((HeapWord*)this, v);
 180 }
 181 
 182 bool oopDesc::is_a(Klass* k) const {


 339   assert(m.decode_pointer() == p, "encoding must be reversable");
 340   markWord old_mark = cas_set_mark_raw(m, compare, order);
 341   if (old_mark == compare) {
 342     return NULL;
 343   } else {
 344     return (oop)old_mark.decode_pointer();
 345   }
 346 }
 347 
 348 // Note that the forwardee is not the same thing as the displaced_mark.
 349 // The forwardee is used when copying during scavenge and mark-sweep.
 350 // It does need to clear the low two locking- and GC-related bits.
 351 oop oopDesc::forwardee() const {
 352   return (oop) mark_raw().decode_pointer();
 353 }
 354 
 355 // Note that the forwardee is not the same thing as the displaced_mark.
 356 // The forwardee is used when copying during scavenge and mark-sweep.
 357 // It does need to clear the low two locking- and GC-related bits.
 358 oop oopDesc::forwardee_acquire() const {
 359   return (oop) Atomic::load_acquire(&_mark).decode_pointer();
 360 }
 361 
 362 // The following method needs to be MT safe.
 363 uint oopDesc::age() const {
 364   assert(!is_forwarded(), "Attempt to read age from forwarded mark");
 365   if (has_displaced_mark_raw()) {
 366     return displaced_mark_raw().age();
 367   } else {
 368     return mark_raw().age();
 369   }
 370 }
 371 
 372 void oopDesc::incr_age() {
 373   assert(!is_forwarded(), "Attempt to increment age of forwarded mark");
 374   if (has_displaced_mark_raw()) {
 375     set_displaced_mark_raw(displaced_mark_raw().incr_age());
 376   } else {
 377     set_mark_raw(mark_raw().incr_age());
 378   }
 379 }


< prev index next >