Thu, 13 Mar 2008 14:17:48 -0700
Merge
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // Implementation of all inlined member functions defined in oop.hpp |
duke@435 | 26 | // We need a separate file to avoid circular references |
duke@435 | 27 | |
duke@435 | 28 | |
duke@435 | 29 | inline void oopDesc::release_set_mark(markOop m) { |
duke@435 | 30 | OrderAccess::release_store_ptr(&_mark, m); |
duke@435 | 31 | } |
duke@435 | 32 | |
duke@435 | 33 | inline markOop oopDesc::cas_set_mark(markOop new_mark, markOop old_mark) { |
duke@435 | 34 | return (markOop) Atomic::cmpxchg_ptr(new_mark, &_mark, old_mark); |
duke@435 | 35 | } |
duke@435 | 36 | |
duke@435 | 37 | inline void oopDesc::set_klass(klassOop k) { |
duke@435 | 38 | // since klasses are promoted no store check is needed |
duke@435 | 39 | assert(Universe::is_bootstrapping() || k != NULL, "must be a real klassOop"); |
duke@435 | 40 | assert(Universe::is_bootstrapping() || k->is_klass(), "not a klassOop"); |
duke@435 | 41 | oop_store_without_check((oop*) &_klass, (oop) k); |
duke@435 | 42 | } |
duke@435 | 43 | |
duke@435 | 44 | inline void oopDesc::set_klass_to_list_ptr(oop k) { |
duke@435 | 45 | // This is only to be used during GC, for from-space objects, so no |
duke@435 | 46 | // barrier is needed. |
duke@435 | 47 | _klass = (klassOop)k; |
duke@435 | 48 | } |
duke@435 | 49 | |
duke@435 | 50 | inline void oopDesc::init_mark() { set_mark(markOopDesc::prototype_for_object(this)); } |
duke@435 | 51 | inline Klass* oopDesc::blueprint() const { return klass()->klass_part(); } |
duke@435 | 52 | |
duke@435 | 53 | inline bool oopDesc::is_a(klassOop k) const { return blueprint()->is_subtype_of(k); } |
duke@435 | 54 | |
duke@435 | 55 | inline bool oopDesc::is_instance() const { return blueprint()->oop_is_instance(); } |
duke@435 | 56 | inline bool oopDesc::is_instanceRef() const { return blueprint()->oop_is_instanceRef(); } |
duke@435 | 57 | inline bool oopDesc::is_array() const { return blueprint()->oop_is_array(); } |
duke@435 | 58 | inline bool oopDesc::is_objArray() const { return blueprint()->oop_is_objArray(); } |
duke@435 | 59 | inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); } |
duke@435 | 60 | inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); } |
duke@435 | 61 | inline bool oopDesc::is_symbol() const { return blueprint()->oop_is_symbol(); } |
duke@435 | 62 | inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); } |
duke@435 | 63 | inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); } |
duke@435 | 64 | inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); } |
duke@435 | 65 | inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); } |
duke@435 | 66 | inline bool oopDesc::is_methodData() const { return blueprint()->oop_is_methodData(); } |
duke@435 | 67 | inline bool oopDesc::is_constantPool() const { return blueprint()->oop_is_constantPool(); } |
duke@435 | 68 | inline bool oopDesc::is_constantPoolCache() const { return blueprint()->oop_is_constantPoolCache(); } |
duke@435 | 69 | inline bool oopDesc::is_compiledICHolder() const { return blueprint()->oop_is_compiledICHolder(); } |
duke@435 | 70 | |
duke@435 | 71 | inline void* oopDesc::field_base(int offset) const { return (void*)&((char*)this)[offset]; } |
duke@435 | 72 | |
duke@435 | 73 | inline oop* oopDesc::obj_field_addr(int offset) const { return (oop*) field_base(offset); } |
duke@435 | 74 | inline jbyte* oopDesc::byte_field_addr(int offset) const { return (jbyte*) field_base(offset); } |
duke@435 | 75 | inline jchar* oopDesc::char_field_addr(int offset) const { return (jchar*) field_base(offset); } |
duke@435 | 76 | inline jboolean* oopDesc::bool_field_addr(int offset) const { return (jboolean*)field_base(offset); } |
duke@435 | 77 | inline jint* oopDesc::int_field_addr(int offset) const { return (jint*) field_base(offset); } |
duke@435 | 78 | inline jshort* oopDesc::short_field_addr(int offset) const { return (jshort*) field_base(offset); } |
duke@435 | 79 | inline jlong* oopDesc::long_field_addr(int offset) const { return (jlong*) field_base(offset); } |
duke@435 | 80 | inline jfloat* oopDesc::float_field_addr(int offset) const { return (jfloat*) field_base(offset); } |
duke@435 | 81 | inline jdouble* oopDesc::double_field_addr(int offset) const { return (jdouble*) field_base(offset); } |
duke@435 | 82 | |
duke@435 | 83 | inline oop oopDesc::obj_field(int offset) const { return *obj_field_addr(offset); } |
duke@435 | 84 | inline void oopDesc::obj_field_put(int offset, oop value) { oop_store(obj_field_addr(offset), value); } |
duke@435 | 85 | |
duke@435 | 86 | inline jbyte oopDesc::byte_field(int offset) const { return (jbyte) *byte_field_addr(offset); } |
duke@435 | 87 | inline void oopDesc::byte_field_put(int offset, jbyte contents) { *byte_field_addr(offset) = (jint) contents; } |
duke@435 | 88 | |
duke@435 | 89 | inline jboolean oopDesc::bool_field(int offset) const { return (jboolean) *bool_field_addr(offset); } |
duke@435 | 90 | inline void oopDesc::bool_field_put(int offset, jboolean contents) { *bool_field_addr(offset) = (jint) contents; } |
duke@435 | 91 | |
duke@435 | 92 | inline jchar oopDesc::char_field(int offset) const { return (jchar) *char_field_addr(offset); } |
duke@435 | 93 | inline void oopDesc::char_field_put(int offset, jchar contents) { *char_field_addr(offset) = (jint) contents; } |
duke@435 | 94 | |
duke@435 | 95 | inline jint oopDesc::int_field(int offset) const { return *int_field_addr(offset); } |
duke@435 | 96 | inline void oopDesc::int_field_put(int offset, jint contents) { *int_field_addr(offset) = contents; } |
duke@435 | 97 | |
duke@435 | 98 | inline jshort oopDesc::short_field(int offset) const { return (jshort) *short_field_addr(offset); } |
duke@435 | 99 | inline void oopDesc::short_field_put(int offset, jshort contents) { *short_field_addr(offset) = (jint) contents;} |
duke@435 | 100 | |
duke@435 | 101 | inline jlong oopDesc::long_field(int offset) const { return *long_field_addr(offset); } |
duke@435 | 102 | inline void oopDesc::long_field_put(int offset, jlong contents) { *long_field_addr(offset) = contents; } |
duke@435 | 103 | |
duke@435 | 104 | inline jfloat oopDesc::float_field(int offset) const { return *float_field_addr(offset); } |
duke@435 | 105 | inline void oopDesc::float_field_put(int offset, jfloat contents) { *float_field_addr(offset) = contents; } |
duke@435 | 106 | |
duke@435 | 107 | inline jdouble oopDesc::double_field(int offset) const { return *double_field_addr(offset); } |
duke@435 | 108 | inline void oopDesc::double_field_put(int offset, jdouble contents) { *double_field_addr(offset) = contents; } |
duke@435 | 109 | |
duke@435 | 110 | inline oop oopDesc::obj_field_acquire(int offset) const { return (oop)OrderAccess::load_ptr_acquire(obj_field_addr(offset)); } |
duke@435 | 111 | inline void oopDesc::release_obj_field_put(int offset, oop value) { oop_store((volatile oop*)obj_field_addr(offset), value); } |
duke@435 | 112 | |
duke@435 | 113 | inline jbyte oopDesc::byte_field_acquire(int offset) const { return OrderAccess::load_acquire(byte_field_addr(offset)); } |
duke@435 | 114 | inline void oopDesc::release_byte_field_put(int offset, jbyte contents) { OrderAccess::release_store(byte_field_addr(offset), contents); } |
duke@435 | 115 | |
duke@435 | 116 | inline jboolean oopDesc::bool_field_acquire(int offset) const { return OrderAccess::load_acquire(bool_field_addr(offset)); } |
duke@435 | 117 | inline void oopDesc::release_bool_field_put(int offset, jboolean contents) { OrderAccess::release_store(bool_field_addr(offset), contents); } |
duke@435 | 118 | |
duke@435 | 119 | inline jchar oopDesc::char_field_acquire(int offset) const { return OrderAccess::load_acquire(char_field_addr(offset)); } |
duke@435 | 120 | inline void oopDesc::release_char_field_put(int offset, jchar contents) { OrderAccess::release_store(char_field_addr(offset), contents); } |
duke@435 | 121 | |
duke@435 | 122 | inline jint oopDesc::int_field_acquire(int offset) const { return OrderAccess::load_acquire(int_field_addr(offset)); } |
duke@435 | 123 | inline void oopDesc::release_int_field_put(int offset, jint contents) { OrderAccess::release_store(int_field_addr(offset), contents); } |
duke@435 | 124 | |
duke@435 | 125 | inline jshort oopDesc::short_field_acquire(int offset) const { return (jshort)OrderAccess::load_acquire(short_field_addr(offset)); } |
duke@435 | 126 | inline void oopDesc::release_short_field_put(int offset, jshort contents) { OrderAccess::release_store(short_field_addr(offset), contents); } |
duke@435 | 127 | |
duke@435 | 128 | inline jlong oopDesc::long_field_acquire(int offset) const { return OrderAccess::load_acquire(long_field_addr(offset)); } |
duke@435 | 129 | inline void oopDesc::release_long_field_put(int offset, jlong contents) { OrderAccess::release_store(long_field_addr(offset), contents); } |
duke@435 | 130 | |
duke@435 | 131 | inline jfloat oopDesc::float_field_acquire(int offset) const { return OrderAccess::load_acquire(float_field_addr(offset)); } |
duke@435 | 132 | inline void oopDesc::release_float_field_put(int offset, jfloat contents) { OrderAccess::release_store(float_field_addr(offset), contents); } |
duke@435 | 133 | |
duke@435 | 134 | inline jdouble oopDesc::double_field_acquire(int offset) const { return OrderAccess::load_acquire(double_field_addr(offset)); } |
duke@435 | 135 | inline void oopDesc::release_double_field_put(int offset, jdouble contents) { OrderAccess::release_store(double_field_addr(offset), contents); } |
duke@435 | 136 | |
duke@435 | 137 | |
duke@435 | 138 | inline int oopDesc::size_given_klass(Klass* klass) { |
duke@435 | 139 | int lh = klass->layout_helper(); |
duke@435 | 140 | int s = lh >> LogHeapWordSize; // deliver size scaled by wordSize |
duke@435 | 141 | |
duke@435 | 142 | // lh is now a value computed at class initialization that may hint |
duke@435 | 143 | // at the size. For instances, this is positive and equal to the |
duke@435 | 144 | // size. For arrays, this is negative and provides log2 of the |
duke@435 | 145 | // array element size. For other oops, it is zero and thus requires |
duke@435 | 146 | // a virtual call. |
duke@435 | 147 | // |
duke@435 | 148 | // We go to all this trouble because the size computation is at the |
duke@435 | 149 | // heart of phase 2 of mark-compaction, and called for every object, |
duke@435 | 150 | // alive or dead. So the speed here is equal in importance to the |
duke@435 | 151 | // speed of allocation. |
duke@435 | 152 | |
duke@435 | 153 | if (lh <= Klass::_lh_neutral_value) { |
duke@435 | 154 | // The most common case is instances; fall through if so. |
duke@435 | 155 | if (lh < Klass::_lh_neutral_value) { |
duke@435 | 156 | // Second most common case is arrays. We have to fetch the |
duke@435 | 157 | // length of the array, shift (multiply) it appropriately, |
duke@435 | 158 | // up to wordSize, add the header, and align to object size. |
duke@435 | 159 | size_t size_in_bytes; |
duke@435 | 160 | #ifdef _M_IA64 |
duke@435 | 161 | // The Windows Itanium Aug 2002 SDK hoists this load above |
duke@435 | 162 | // the check for s < 0. An oop at the end of the heap will |
duke@435 | 163 | // cause an access violation if this load is performed on a non |
duke@435 | 164 | // array oop. Making the reference volatile prohibits this. |
duke@435 | 165 | // (%%% please explain by what magic the length is actually fetched!) |
duke@435 | 166 | volatile int *array_length; |
duke@435 | 167 | array_length = (volatile int *)( (intptr_t)this + |
duke@435 | 168 | arrayOopDesc::length_offset_in_bytes() ); |
duke@435 | 169 | assert(array_length > 0, "Integer arithmetic problem somewhere"); |
duke@435 | 170 | // Put into size_t to avoid overflow. |
duke@435 | 171 | size_in_bytes = (size_t) array_length; |
duke@435 | 172 | size_in_bytes = size_in_bytes << Klass::layout_helper_log2_element_size(lh); |
duke@435 | 173 | #else |
duke@435 | 174 | size_t array_length = (size_t) ((arrayOop)this)->length(); |
duke@435 | 175 | size_in_bytes = array_length << Klass::layout_helper_log2_element_size(lh); |
duke@435 | 176 | #endif |
duke@435 | 177 | size_in_bytes += Klass::layout_helper_header_size(lh); |
duke@435 | 178 | |
duke@435 | 179 | // This code could be simplified, but by keeping array_header_in_bytes |
duke@435 | 180 | // in units of bytes and doing it this way we can round up just once, |
duke@435 | 181 | // skipping the intermediate round to HeapWordSize. Cast the result |
duke@435 | 182 | // of round_to to size_t to guarantee unsigned division == right shift. |
duke@435 | 183 | s = (int)((size_t)round_to(size_in_bytes, MinObjAlignmentInBytes) / |
duke@435 | 184 | HeapWordSize); |
duke@435 | 185 | |
duke@435 | 186 | // UseParNewGC can change the length field of an "old copy" of an object |
duke@435 | 187 | // array in the young gen so it indicates the stealable portion of |
duke@435 | 188 | // an already copied array. This will cause the first disjunct below |
duke@435 | 189 | // to fail if the sizes are computed across such a concurrent change. |
duke@435 | 190 | // UseParNewGC also runs with promotion labs (which look like int |
duke@435 | 191 | // filler arrays) which are subject to changing their declared size |
duke@435 | 192 | // when finally retiring a PLAB; this also can cause the first disjunct |
duke@435 | 193 | // to fail for another worker thread that is concurrently walking the block |
duke@435 | 194 | // offset table. Both these invariant failures are benign for their |
duke@435 | 195 | // current uses; we relax the assertion checking to cover these two cases below: |
duke@435 | 196 | // is_objArray() && is_forwarded() // covers first scenario above |
duke@435 | 197 | // || is_typeArray() // covers second scenario above |
duke@435 | 198 | // If and when UseParallelGC uses the same obj array oop stealing/chunking |
duke@435 | 199 | // technique, or when G1 is integrated (and currently uses this array chunking |
duke@435 | 200 | // technique) we will need to suitably modify the assertion. |
duke@435 | 201 | assert((s == klass->oop_size(this)) || |
duke@435 | 202 | (((UseParNewGC || UseParallelGC) && |
duke@435 | 203 | Universe::heap()->is_gc_active()) && |
duke@435 | 204 | (is_typeArray() || |
duke@435 | 205 | (is_objArray() && is_forwarded()))), |
duke@435 | 206 | "wrong array object size"); |
duke@435 | 207 | } else { |
duke@435 | 208 | // Must be zero, so bite the bullet and take the virtual call. |
duke@435 | 209 | s = klass->oop_size(this); |
duke@435 | 210 | } |
duke@435 | 211 | } |
duke@435 | 212 | |
duke@435 | 213 | assert(s % MinObjAlignment == 0, "alignment check"); |
duke@435 | 214 | assert(s > 0, "Bad size calculated"); |
duke@435 | 215 | return s; |
duke@435 | 216 | } |
duke@435 | 217 | |
duke@435 | 218 | |
duke@435 | 219 | inline int oopDesc::size() { |
duke@435 | 220 | return size_given_klass(blueprint()); |
duke@435 | 221 | } |
duke@435 | 222 | |
duke@435 | 223 | inline bool oopDesc::is_parsable() { |
duke@435 | 224 | return blueprint()->oop_is_parsable(this); |
duke@435 | 225 | } |
duke@435 | 226 | |
duke@435 | 227 | |
duke@435 | 228 | inline void update_barrier_set(oop *p, oop v) { |
duke@435 | 229 | assert(oopDesc::bs() != NULL, "Uninitialized bs in oop!"); |
duke@435 | 230 | oopDesc::bs()->write_ref_field(p, v); |
duke@435 | 231 | } |
duke@435 | 232 | |
duke@435 | 233 | |
duke@435 | 234 | inline void oop_store(oop* p, oop v) { |
duke@435 | 235 | if (always_do_update_barrier) { |
duke@435 | 236 | oop_store((volatile oop*)p, v); |
duke@435 | 237 | } else { |
duke@435 | 238 | *p = v; |
duke@435 | 239 | update_barrier_set(p, v); |
duke@435 | 240 | } |
duke@435 | 241 | } |
duke@435 | 242 | |
duke@435 | 243 | inline void oop_store(volatile oop* p, oop v) { |
duke@435 | 244 | // Used by release_obj_field_put, so use release_store_ptr. |
duke@435 | 245 | OrderAccess::release_store_ptr(p, v); |
duke@435 | 246 | update_barrier_set((oop *)p, v); |
duke@435 | 247 | } |
duke@435 | 248 | |
duke@435 | 249 | inline void oop_store_without_check(oop* p, oop v) { |
duke@435 | 250 | // XXX YSR FIX ME!!! |
duke@435 | 251 | if (always_do_update_barrier) { |
duke@435 | 252 | oop_store(p, v); |
duke@435 | 253 | } else { |
duke@435 | 254 | assert(!Universe::heap()->barrier_set()->write_ref_needs_barrier(p, v), |
duke@435 | 255 | "oop store without store check failed"); |
duke@435 | 256 | *p = v; |
duke@435 | 257 | } |
duke@435 | 258 | } |
duke@435 | 259 | |
duke@435 | 260 | // When it absolutely has to get there. |
duke@435 | 261 | inline void oop_store_without_check(volatile oop* p, oop v) { |
duke@435 | 262 | // XXX YSR FIX ME!!! |
duke@435 | 263 | if (always_do_update_barrier) { |
duke@435 | 264 | oop_store(p, v); |
duke@435 | 265 | } else { |
duke@435 | 266 | assert(!Universe::heap()->barrier_set()-> |
duke@435 | 267 | write_ref_needs_barrier((oop *)p, v), |
duke@435 | 268 | "oop store without store check failed"); |
duke@435 | 269 | OrderAccess::release_store_ptr(p, v); |
duke@435 | 270 | } |
duke@435 | 271 | } |
duke@435 | 272 | |
duke@435 | 273 | |
duke@435 | 274 | // Used only for markSweep, scavenging |
duke@435 | 275 | inline bool oopDesc::is_gc_marked() const { |
duke@435 | 276 | return mark()->is_marked(); |
duke@435 | 277 | } |
duke@435 | 278 | |
duke@435 | 279 | inline bool oopDesc::is_locked() const { |
duke@435 | 280 | return mark()->is_locked(); |
duke@435 | 281 | } |
duke@435 | 282 | |
duke@435 | 283 | inline bool oopDesc::is_unlocked() const { |
duke@435 | 284 | return mark()->is_unlocked(); |
duke@435 | 285 | } |
duke@435 | 286 | |
duke@435 | 287 | inline bool oopDesc::has_bias_pattern() const { |
duke@435 | 288 | return mark()->has_bias_pattern(); |
duke@435 | 289 | } |
duke@435 | 290 | |
duke@435 | 291 | inline bool check_obj_alignment(oop obj) { |
duke@435 | 292 | return (intptr_t)obj % MinObjAlignmentInBytes == 0; |
duke@435 | 293 | } |
duke@435 | 294 | |
duke@435 | 295 | |
duke@435 | 296 | // used only for asserts |
duke@435 | 297 | inline bool oopDesc::is_oop(bool ignore_mark_word) const { |
duke@435 | 298 | oop obj = (oop) this; |
duke@435 | 299 | if (!check_obj_alignment(obj)) return false; |
duke@435 | 300 | if (!Universe::heap()->is_in_reserved(obj)) return false; |
duke@435 | 301 | // obj is aligned and accessible in heap |
duke@435 | 302 | // try to find metaclass cycle safely without seg faulting on bad input |
duke@435 | 303 | // we should reach klassKlassObj by following klass link at most 3 times |
duke@435 | 304 | for (int i = 0; i < 3; i++) { |
duke@435 | 305 | obj = obj->klass(); |
duke@435 | 306 | // klass should be aligned and in permspace |
duke@435 | 307 | if (!check_obj_alignment(obj)) return false; |
duke@435 | 308 | if (!Universe::heap()->is_in_permanent(obj)) return false; |
duke@435 | 309 | } |
duke@435 | 310 | if (obj != Universe::klassKlassObj()) { |
duke@435 | 311 | // During a dump, the _klassKlassObj moved to a shared space. |
duke@435 | 312 | if (DumpSharedSpaces && Universe::klassKlassObj()->is_shared()) { |
duke@435 | 313 | return true; |
duke@435 | 314 | } |
duke@435 | 315 | return false; |
duke@435 | 316 | } |
duke@435 | 317 | |
duke@435 | 318 | // Header verification: the mark is typically non-NULL. If we're |
duke@435 | 319 | // at a safepoint, it must not be null. |
duke@435 | 320 | // Outside of a safepoint, the header could be changing (for example, |
duke@435 | 321 | // another thread could be inflating a lock on this object). |
duke@435 | 322 | if (ignore_mark_word) { |
duke@435 | 323 | return true; |
duke@435 | 324 | } |
duke@435 | 325 | if (mark() != NULL) { |
duke@435 | 326 | return true; |
duke@435 | 327 | } |
duke@435 | 328 | return !SafepointSynchronize::is_at_safepoint(); |
duke@435 | 329 | } |
duke@435 | 330 | |
duke@435 | 331 | |
duke@435 | 332 | // used only for asserts |
duke@435 | 333 | inline bool oopDesc::is_oop_or_null(bool ignore_mark_word) const { |
duke@435 | 334 | return this == NULL ? true : is_oop(ignore_mark_word); |
duke@435 | 335 | } |
duke@435 | 336 | |
duke@435 | 337 | #ifndef PRODUCT |
duke@435 | 338 | // used only for asserts |
duke@435 | 339 | inline bool oopDesc::is_unlocked_oop() const { |
duke@435 | 340 | if (!Universe::heap()->is_in_reserved(this)) return false; |
duke@435 | 341 | return mark()->is_unlocked(); |
duke@435 | 342 | } |
duke@435 | 343 | |
duke@435 | 344 | |
duke@435 | 345 | #endif // PRODUCT |
duke@435 | 346 | |
duke@435 | 347 | inline void oopDesc::follow_header() { |
duke@435 | 348 | MarkSweep::mark_and_push((oop*)&_klass); |
duke@435 | 349 | } |
duke@435 | 350 | |
duke@435 | 351 | inline void oopDesc::follow_contents() { |
duke@435 | 352 | assert (is_gc_marked(), "should be marked"); |
duke@435 | 353 | blueprint()->oop_follow_contents(this); |
duke@435 | 354 | } |
duke@435 | 355 | |
duke@435 | 356 | |
duke@435 | 357 | // Used by scavengers |
duke@435 | 358 | |
duke@435 | 359 | inline bool oopDesc::is_forwarded() const { |
duke@435 | 360 | // The extra heap check is needed since the obj might be locked, in which case the |
duke@435 | 361 | // mark would point to a stack location and have the sentinel bit cleared |
duke@435 | 362 | return mark()->is_marked(); |
duke@435 | 363 | } |
duke@435 | 364 | |
duke@435 | 365 | |
duke@435 | 366 | // Used by scavengers |
duke@435 | 367 | inline void oopDesc::forward_to(oop p) { |
duke@435 | 368 | assert(Universe::heap()->is_in_reserved(p), |
duke@435 | 369 | "forwarding to something not in heap"); |
duke@435 | 370 | markOop m = markOopDesc::encode_pointer_as_mark(p); |
duke@435 | 371 | assert(m->decode_pointer() == p, "encoding must be reversable"); |
duke@435 | 372 | set_mark(m); |
duke@435 | 373 | } |
duke@435 | 374 | |
duke@435 | 375 | // Used by parallel scavengers |
duke@435 | 376 | inline bool oopDesc::cas_forward_to(oop p, markOop compare) { |
duke@435 | 377 | assert(Universe::heap()->is_in_reserved(p), |
duke@435 | 378 | "forwarding to something not in heap"); |
duke@435 | 379 | markOop m = markOopDesc::encode_pointer_as_mark(p); |
duke@435 | 380 | assert(m->decode_pointer() == p, "encoding must be reversable"); |
duke@435 | 381 | return cas_set_mark(m, compare) == compare; |
duke@435 | 382 | } |
duke@435 | 383 | |
duke@435 | 384 | // Note that the forwardee is not the same thing as the displaced_mark. |
duke@435 | 385 | // The forwardee is used when copying during scavenge and mark-sweep. |
duke@435 | 386 | // It does need to clear the low two locking- and GC-related bits. |
duke@435 | 387 | inline oop oopDesc::forwardee() const { return (oop) mark()->decode_pointer(); } |
duke@435 | 388 | |
duke@435 | 389 | |
duke@435 | 390 | inline bool oopDesc::has_displaced_mark() const { |
duke@435 | 391 | return mark()->has_displaced_mark_helper(); |
duke@435 | 392 | } |
duke@435 | 393 | |
duke@435 | 394 | inline markOop oopDesc::displaced_mark() const { |
duke@435 | 395 | return mark()->displaced_mark_helper(); |
duke@435 | 396 | } |
duke@435 | 397 | |
duke@435 | 398 | inline void oopDesc::set_displaced_mark(markOop m) { |
duke@435 | 399 | mark()->set_displaced_mark_helper(m); |
duke@435 | 400 | } |
duke@435 | 401 | |
duke@435 | 402 | // The following method needs to be MT safe. |
duke@435 | 403 | inline int oopDesc::age() const { |
duke@435 | 404 | assert(!is_forwarded(), "Attempt to read age from forwarded mark"); |
duke@435 | 405 | if (has_displaced_mark()) { |
duke@435 | 406 | return displaced_mark()->age(); |
duke@435 | 407 | } else { |
duke@435 | 408 | return mark()->age(); |
duke@435 | 409 | } |
duke@435 | 410 | } |
duke@435 | 411 | |
duke@435 | 412 | inline void oopDesc::incr_age() { |
duke@435 | 413 | assert(!is_forwarded(), "Attempt to increment age of forwarded mark"); |
duke@435 | 414 | if (has_displaced_mark()) { |
duke@435 | 415 | set_displaced_mark(displaced_mark()->incr_age()); |
duke@435 | 416 | } else { |
duke@435 | 417 | set_mark(mark()->incr_age()); |
duke@435 | 418 | } |
duke@435 | 419 | } |
duke@435 | 420 | |
duke@435 | 421 | |
duke@435 | 422 | inline intptr_t oopDesc::identity_hash() { |
duke@435 | 423 | // Fast case; if the object is unlocked and the hash value is set, no locking is needed |
duke@435 | 424 | // Note: The mark must be read into local variable to avoid concurrent updates. |
duke@435 | 425 | markOop mrk = mark(); |
duke@435 | 426 | if (mrk->is_unlocked() && !mrk->has_no_hash()) { |
duke@435 | 427 | return mrk->hash(); |
duke@435 | 428 | } else if (mrk->is_marked()) { |
duke@435 | 429 | return mrk->hash(); |
duke@435 | 430 | } else { |
duke@435 | 431 | return slow_identity_hash(); |
duke@435 | 432 | } |
duke@435 | 433 | } |
duke@435 | 434 | |
duke@435 | 435 | |
duke@435 | 436 | inline void oopDesc::oop_iterate_header(OopClosure* blk) { |
duke@435 | 437 | blk->do_oop((oop*)&_klass); |
duke@435 | 438 | } |
duke@435 | 439 | |
duke@435 | 440 | |
duke@435 | 441 | inline void oopDesc::oop_iterate_header(OopClosure* blk, MemRegion mr) { |
duke@435 | 442 | if (mr.contains(&_klass)) blk->do_oop((oop*)&_klass); |
duke@435 | 443 | } |
duke@435 | 444 | |
duke@435 | 445 | |
duke@435 | 446 | inline int oopDesc::adjust_pointers() { |
duke@435 | 447 | debug_only(int check_size = size()); |
duke@435 | 448 | int s = blueprint()->oop_adjust_pointers(this); |
duke@435 | 449 | assert(s == check_size, "should be the same"); |
duke@435 | 450 | return s; |
duke@435 | 451 | } |
duke@435 | 452 | |
duke@435 | 453 | inline void oopDesc::adjust_header() { |
duke@435 | 454 | MarkSweep::adjust_pointer((oop*)&_klass); |
duke@435 | 455 | } |
duke@435 | 456 | |
duke@435 | 457 | #define OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ |
duke@435 | 458 | \ |
duke@435 | 459 | inline int oopDesc::oop_iterate(OopClosureType* blk) { \ |
duke@435 | 460 | SpecializationStats::record_call(); \ |
duke@435 | 461 | return blueprint()->oop_oop_iterate##nv_suffix(this, blk); \ |
duke@435 | 462 | } \ |
duke@435 | 463 | \ |
duke@435 | 464 | inline int oopDesc::oop_iterate(OopClosureType* blk, MemRegion mr) { \ |
duke@435 | 465 | SpecializationStats::record_call(); \ |
duke@435 | 466 | return blueprint()->oop_oop_iterate##nv_suffix##_m(this, blk, mr); \ |
duke@435 | 467 | } |
duke@435 | 468 | |
duke@435 | 469 | ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_ITERATE_DEFN) |
duke@435 | 470 | ALL_OOP_OOP_ITERATE_CLOSURES_3(OOP_ITERATE_DEFN) |
duke@435 | 471 | |
duke@435 | 472 | |
duke@435 | 473 | inline bool oopDesc::is_shared() const { |
duke@435 | 474 | return CompactingPermGenGen::is_shared(this); |
duke@435 | 475 | } |
duke@435 | 476 | |
duke@435 | 477 | inline bool oopDesc::is_shared_readonly() const { |
duke@435 | 478 | return CompactingPermGenGen::is_shared_readonly(this); |
duke@435 | 479 | } |
duke@435 | 480 | |
duke@435 | 481 | inline bool oopDesc::is_shared_readwrite() const { |
duke@435 | 482 | return CompactingPermGenGen::is_shared_readwrite(this); |
duke@435 | 483 | } |