annotate src/share/vm/oops/oop.inline.hpp @ 122:435e64505015

6693457: Open-source hotspot linux-sparc support Summary: Move os_cpu/linux_sparc from closed to open Reviewed-by: kamg
author phh
date Thu, 24 Apr 2008 15:07:57 -0400
parents ba764ed4b6f2
children b7268662a986
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 // Implementation of all inlined member functions defined in oop.hpp
duke@0 26 // We need a separate file to avoid circular references
duke@0 27
duke@0 28 inline void oopDesc::release_set_mark(markOop m) {
duke@0 29 OrderAccess::release_store_ptr(&_mark, m);
duke@0 30 }
duke@0 31
duke@0 32 inline markOop oopDesc::cas_set_mark(markOop new_mark, markOop old_mark) {
duke@0 33 return (markOop) Atomic::cmpxchg_ptr(new_mark, &_mark, old_mark);
duke@0 34 }
duke@0 35
coleenp@107 36 inline klassOop oopDesc::klass() const {
coleenp@107 37 if (UseCompressedOops) {
coleenp@107 38 return (klassOop)decode_heap_oop_not_null(_metadata._compressed_klass);
coleenp@107 39 // can be NULL in CMS, but isn't supported on CMS yet.
coleenp@107 40 } else {
coleenp@107 41 return _metadata._klass;
coleenp@107 42 }
coleenp@107 43 }
coleenp@107 44
coleenp@107 45 inline int oopDesc::klass_gap_offset_in_bytes() {
coleenp@107 46 assert(UseCompressedOops, "only applicable to compressed headers");
coleenp@107 47 return oopDesc::klass_offset_in_bytes() + sizeof(narrowOop);
coleenp@107 48 }
coleenp@107 49
coleenp@107 50 inline oop* oopDesc::klass_addr() {
coleenp@107 51 // Only used internally and with CMS and will not work with
coleenp@107 52 // UseCompressedOops
coleenp@107 53 assert(!UseCompressedOops, "only supported with uncompressed oops");
coleenp@107 54 return (oop*) &_metadata._klass;
coleenp@107 55 }
coleenp@107 56
coleenp@107 57 inline narrowOop* oopDesc::compressed_klass_addr() {
coleenp@107 58 assert(UseCompressedOops, "only called by compressed oops");
coleenp@107 59 return (narrowOop*) &_metadata._compressed_klass;
coleenp@107 60 }
coleenp@107 61
duke@0 62 inline void oopDesc::set_klass(klassOop k) {
duke@0 63 // since klasses are promoted no store check is needed
duke@0 64 assert(Universe::is_bootstrapping() || k != NULL, "must be a real klassOop");
duke@0 65 assert(Universe::is_bootstrapping() || k->is_klass(), "not a klassOop");
coleenp@107 66 if (UseCompressedOops) {
coleenp@107 67 // zero the gap when the klass is set, by zeroing the pointer sized
coleenp@107 68 // part of the union.
coleenp@107 69 _metadata._klass = NULL;
coleenp@107 70 oop_store_without_check(compressed_klass_addr(), (oop)k);
coleenp@107 71 } else {
coleenp@107 72 oop_store_without_check(klass_addr(), (oop) k);
coleenp@107 73 }
duke@0 74 }
duke@0 75
duke@0 76 inline void oopDesc::set_klass_to_list_ptr(oop k) {
duke@0 77 // This is only to be used during GC, for from-space objects, so no
duke@0 78 // barrier is needed.
coleenp@107 79 if (UseCompressedOops) {
coleenp@107 80 _metadata._compressed_klass = encode_heap_oop_not_null(k);
coleenp@107 81 } else {
coleenp@107 82 _metadata._klass = (klassOop)k;
coleenp@107 83 }
duke@0 84 }
duke@0 85
duke@0 86 inline void oopDesc::init_mark() { set_mark(markOopDesc::prototype_for_object(this)); }
duke@0 87 inline Klass* oopDesc::blueprint() const { return klass()->klass_part(); }
duke@0 88
duke@0 89 inline bool oopDesc::is_a(klassOop k) const { return blueprint()->is_subtype_of(k); }
duke@0 90
duke@0 91 inline bool oopDesc::is_instance() const { return blueprint()->oop_is_instance(); }
duke@0 92 inline bool oopDesc::is_instanceRef() const { return blueprint()->oop_is_instanceRef(); }
duke@0 93 inline bool oopDesc::is_array() const { return blueprint()->oop_is_array(); }
duke@0 94 inline bool oopDesc::is_objArray() const { return blueprint()->oop_is_objArray(); }
duke@0 95 inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
duke@0 96 inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
duke@0 97 inline bool oopDesc::is_symbol() const { return blueprint()->oop_is_symbol(); }
duke@0 98 inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
duke@0 99 inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
duke@0 100 inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
duke@0 101 inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
duke@0 102 inline bool oopDesc::is_methodData() const { return blueprint()->oop_is_methodData(); }
duke@0 103 inline bool oopDesc::is_constantPool() const { return blueprint()->oop_is_constantPool(); }
duke@0 104 inline bool oopDesc::is_constantPoolCache() const { return blueprint()->oop_is_constantPoolCache(); }
duke@0 105 inline bool oopDesc::is_compiledICHolder() const { return blueprint()->oop_is_compiledICHolder(); }
duke@0 106
duke@0 107 inline void* oopDesc::field_base(int offset) const { return (void*)&((char*)this)[offset]; }
duke@0 108
coleenp@107 109 template <class T> inline T* oopDesc::obj_field_addr(int offset) const { return (T*)field_base(offset); }
duke@0 110 inline jbyte* oopDesc::byte_field_addr(int offset) const { return (jbyte*) field_base(offset); }
duke@0 111 inline jchar* oopDesc::char_field_addr(int offset) const { return (jchar*) field_base(offset); }
duke@0 112 inline jboolean* oopDesc::bool_field_addr(int offset) const { return (jboolean*)field_base(offset); }
duke@0 113 inline jint* oopDesc::int_field_addr(int offset) const { return (jint*) field_base(offset); }
duke@0 114 inline jshort* oopDesc::short_field_addr(int offset) const { return (jshort*) field_base(offset); }
duke@0 115 inline jlong* oopDesc::long_field_addr(int offset) const { return (jlong*) field_base(offset); }
duke@0 116 inline jfloat* oopDesc::float_field_addr(int offset) const { return (jfloat*) field_base(offset); }
duke@0 117 inline jdouble* oopDesc::double_field_addr(int offset) const { return (jdouble*) field_base(offset); }
coleenp@107 118 inline address* oopDesc::address_field_addr(int offset) const { return (address*) field_base(offset); }
duke@0 119
coleenp@107 120
coleenp@107 121 // Functions for getting and setting oops within instance objects.
coleenp@107 122 // If the oops are compressed, the type passed to these overloaded functions
coleenp@107 123 // is narrowOop. All functions are overloaded so they can be called by
coleenp@107 124 // template functions without conditionals (the compiler instantiates via
coleenp@107 125 // the right type and inlines the appopriate code).
coleenp@107 126
coleenp@107 127 inline bool oopDesc::is_null(oop obj) { return obj == NULL; }
coleenp@107 128 inline bool oopDesc::is_null(narrowOop obj) { return obj == 0; }
coleenp@107 129
coleenp@107 130 // Algorithm for encoding and decoding oops from 64 bit pointers to 32 bit
coleenp@107 131 // offset from the heap base. Saving the check for null can save instructions
coleenp@107 132 // in inner GC loops so these are separated.
coleenp@107 133
coleenp@107 134 inline narrowOop oopDesc::encode_heap_oop_not_null(oop v) {
coleenp@107 135 assert(!is_null(v), "oop value can never be zero");
coleenp@107 136 address heap_base = Universe::heap_base();
coleenp@107 137 uint64_t result = (uint64_t)(pointer_delta((void*)v, (void*)heap_base, 1) >> LogMinObjAlignmentInBytes);
phh@122 138 assert((result & 0xffffffff00000000ULL) == 0, "narrow oop overflow");
coleenp@107 139 return (narrowOop)result;
coleenp@107 140 }
coleenp@107 141
coleenp@107 142 inline narrowOop oopDesc::encode_heap_oop(oop v) {
coleenp@107 143 return (is_null(v)) ? (narrowOop)0 : encode_heap_oop_not_null(v);
coleenp@107 144 }
coleenp@107 145
coleenp@107 146 inline oop oopDesc::decode_heap_oop_not_null(narrowOop v) {
coleenp@107 147 assert(!is_null(v), "narrow oop value can never be zero");
coleenp@107 148 address heap_base = Universe::heap_base();
coleenp@107 149 return (oop)(void*)((uintptr_t)heap_base + ((uintptr_t)v << LogMinObjAlignmentInBytes));
coleenp@107 150 }
coleenp@107 151
coleenp@107 152 inline oop oopDesc::decode_heap_oop(narrowOop v) {
coleenp@107 153 return is_null(v) ? (oop)NULL : decode_heap_oop_not_null(v);
coleenp@107 154 }
coleenp@107 155
coleenp@107 156 inline oop oopDesc::decode_heap_oop_not_null(oop v) { return v; }
coleenp@107 157 inline oop oopDesc::decode_heap_oop(oop v) { return v; }
coleenp@107 158
coleenp@107 159 // Load an oop out of the Java heap as is without decoding.
coleenp@107 160 // Called by GC to check for null before decoding.
coleenp@107 161 inline oop oopDesc::load_heap_oop(oop* p) { return *p; }
coleenp@107 162 inline narrowOop oopDesc::load_heap_oop(narrowOop* p) { return *p; }
coleenp@107 163
coleenp@107 164 // Load and decode an oop out of the Java heap into a wide oop.
coleenp@107 165 inline oop oopDesc::load_decode_heap_oop_not_null(oop* p) { return *p; }
coleenp@107 166 inline oop oopDesc::load_decode_heap_oop_not_null(narrowOop* p) {
coleenp@107 167 return decode_heap_oop_not_null(*p);
coleenp@107 168 }
coleenp@107 169
coleenp@107 170 // Load and decode an oop out of the heap accepting null
coleenp@107 171 inline oop oopDesc::load_decode_heap_oop(oop* p) { return *p; }
coleenp@107 172 inline oop oopDesc::load_decode_heap_oop(narrowOop* p) {
coleenp@107 173 return decode_heap_oop(*p);
coleenp@107 174 }
coleenp@107 175
coleenp@107 176 // Store already encoded heap oop into the heap.
coleenp@107 177 inline void oopDesc::store_heap_oop(oop* p, oop v) { *p = v; }
coleenp@107 178 inline void oopDesc::store_heap_oop(narrowOop* p, narrowOop v) { *p = v; }
coleenp@107 179
coleenp@107 180 // Encode and store a heap oop.
coleenp@107 181 inline void oopDesc::encode_store_heap_oop_not_null(narrowOop* p, oop v) {
coleenp@107 182 *p = encode_heap_oop_not_null(v);
coleenp@107 183 }
coleenp@107 184 inline void oopDesc::encode_store_heap_oop_not_null(oop* p, oop v) { *p = v; }
coleenp@107 185
coleenp@107 186 // Encode and store a heap oop allowing for null.
coleenp@107 187 inline void oopDesc::encode_store_heap_oop(narrowOop* p, oop v) {
coleenp@107 188 *p = encode_heap_oop(v);
coleenp@107 189 }
coleenp@107 190 inline void oopDesc::encode_store_heap_oop(oop* p, oop v) { *p = v; }
coleenp@107 191
coleenp@107 192 // Store heap oop as is for volatile fields.
coleenp@107 193 inline void oopDesc::release_store_heap_oop(volatile oop* p, oop v) {
coleenp@107 194 OrderAccess::release_store_ptr(p, v);
coleenp@107 195 }
coleenp@107 196 inline void oopDesc::release_store_heap_oop(volatile narrowOop* p,
coleenp@107 197 narrowOop v) {
coleenp@107 198 OrderAccess::release_store(p, v);
coleenp@107 199 }
coleenp@107 200
coleenp@107 201 inline void oopDesc::release_encode_store_heap_oop_not_null(
coleenp@107 202 volatile narrowOop* p, oop v) {
coleenp@107 203 // heap oop is not pointer sized.
coleenp@107 204 OrderAccess::release_store(p, encode_heap_oop_not_null(v));
coleenp@107 205 }
coleenp@107 206
coleenp@107 207 inline void oopDesc::release_encode_store_heap_oop_not_null(
coleenp@107 208 volatile oop* p, oop v) {
coleenp@107 209 OrderAccess::release_store_ptr(p, v);
coleenp@107 210 }
coleenp@107 211
coleenp@107 212 inline void oopDesc::release_encode_store_heap_oop(volatile oop* p,
coleenp@107 213 oop v) {
coleenp@107 214 OrderAccess::release_store_ptr(p, v);
coleenp@107 215 }
coleenp@107 216 inline void oopDesc::release_encode_store_heap_oop(
coleenp@107 217 volatile narrowOop* p, oop v) {
coleenp@107 218 OrderAccess::release_store(p, encode_heap_oop(v));
coleenp@107 219 }
coleenp@107 220
coleenp@107 221
coleenp@107 222 // These functions are only used to exchange oop fields in instances,
coleenp@107 223 // not headers.
coleenp@107 224 inline oop oopDesc::atomic_exchange_oop(oop exchange_value, volatile HeapWord *dest) {
coleenp@107 225 if (UseCompressedOops) {
coleenp@107 226 // encode exchange value from oop to T
coleenp@107 227 narrowOop val = encode_heap_oop(exchange_value);
coleenp@107 228 narrowOop old = (narrowOop)Atomic::xchg(val, (narrowOop*)dest);
coleenp@107 229 // decode old from T to oop
coleenp@107 230 return decode_heap_oop(old);
coleenp@107 231 } else {
coleenp@107 232 return (oop)Atomic::xchg_ptr(exchange_value, (oop*)dest);
coleenp@107 233 }
coleenp@107 234 }
coleenp@107 235
coleenp@107 236 inline oop oopDesc::atomic_compare_exchange_oop(oop exchange_value,
coleenp@107 237 volatile HeapWord *dest,
coleenp@107 238 oop compare_value) {
coleenp@107 239 if (UseCompressedOops) {
coleenp@107 240 // encode exchange and compare value from oop to T
coleenp@107 241 narrowOop val = encode_heap_oop(exchange_value);
coleenp@107 242 narrowOop cmp = encode_heap_oop(compare_value);
coleenp@107 243
coleenp@107 244 narrowOop old = (narrowOop) Atomic::cmpxchg(val, (narrowOop*)dest, cmp);
coleenp@107 245 // decode old from T to oop
coleenp@107 246 return decode_heap_oop(old);
coleenp@107 247 } else {
coleenp@107 248 return (oop)Atomic::cmpxchg_ptr(exchange_value, (oop*)dest, compare_value);
coleenp@107 249 }
coleenp@107 250 }
coleenp@107 251
coleenp@107 252 // In order to put or get a field out of an instance, must first check
coleenp@107 253 // if the field has been compressed and uncompress it.
coleenp@107 254 inline oop oopDesc::obj_field(int offset) const {
coleenp@107 255 return UseCompressedOops ?
coleenp@107 256 load_decode_heap_oop(obj_field_addr<narrowOop>(offset)) :
coleenp@107 257 load_decode_heap_oop(obj_field_addr<oop>(offset));
coleenp@107 258 }
coleenp@107 259 inline void oopDesc::obj_field_put(int offset, oop value) {
coleenp@107 260 UseCompressedOops ? oop_store(obj_field_addr<narrowOop>(offset), value) :
coleenp@107 261 oop_store(obj_field_addr<oop>(offset), value);
coleenp@107 262 }
coleenp@107 263 inline void oopDesc::obj_field_raw_put(int offset, oop value) {
coleenp@107 264 UseCompressedOops ?
coleenp@107 265 encode_store_heap_oop(obj_field_addr<narrowOop>(offset), value) :
coleenp@107 266 encode_store_heap_oop(obj_field_addr<oop>(offset), value);
coleenp@107 267 }
duke@0 268
duke@0 269 inline jbyte oopDesc::byte_field(int offset) const { return (jbyte) *byte_field_addr(offset); }
duke@0 270 inline void oopDesc::byte_field_put(int offset, jbyte contents) { *byte_field_addr(offset) = (jint) contents; }
duke@0 271
duke@0 272 inline jboolean oopDesc::bool_field(int offset) const { return (jboolean) *bool_field_addr(offset); }
duke@0 273 inline void oopDesc::bool_field_put(int offset, jboolean contents) { *bool_field_addr(offset) = (jint) contents; }
duke@0 274
duke@0 275 inline jchar oopDesc::char_field(int offset) const { return (jchar) *char_field_addr(offset); }
duke@0 276 inline void oopDesc::char_field_put(int offset, jchar contents) { *char_field_addr(offset) = (jint) contents; }
duke@0 277
duke@0 278 inline jint oopDesc::int_field(int offset) const { return *int_field_addr(offset); }
duke@0 279 inline void oopDesc::int_field_put(int offset, jint contents) { *int_field_addr(offset) = contents; }
duke@0 280
duke@0 281 inline jshort oopDesc::short_field(int offset) const { return (jshort) *short_field_addr(offset); }
duke@0 282 inline void oopDesc::short_field_put(int offset, jshort contents) { *short_field_addr(offset) = (jint) contents;}
duke@0 283
duke@0 284 inline jlong oopDesc::long_field(int offset) const { return *long_field_addr(offset); }
duke@0 285 inline void oopDesc::long_field_put(int offset, jlong contents) { *long_field_addr(offset) = contents; }
duke@0 286
duke@0 287 inline jfloat oopDesc::float_field(int offset) const { return *float_field_addr(offset); }
duke@0 288 inline void oopDesc::float_field_put(int offset, jfloat contents) { *float_field_addr(offset) = contents; }
duke@0 289
duke@0 290 inline jdouble oopDesc::double_field(int offset) const { return *double_field_addr(offset); }
duke@0 291 inline void oopDesc::double_field_put(int offset, jdouble contents) { *double_field_addr(offset) = contents; }
duke@0 292
coleenp@107 293 inline address oopDesc::address_field(int offset) const { return *address_field_addr(offset); }
coleenp@107 294 inline void oopDesc::address_field_put(int offset, address contents) { *address_field_addr(offset) = contents; }
coleenp@107 295
coleenp@107 296 inline oop oopDesc::obj_field_acquire(int offset) const {
coleenp@107 297 return UseCompressedOops ?
coleenp@107 298 decode_heap_oop((narrowOop)
coleenp@107 299 OrderAccess::load_acquire(obj_field_addr<narrowOop>(offset)))
coleenp@107 300 : decode_heap_oop((oop)
coleenp@107 301 OrderAccess::load_ptr_acquire(obj_field_addr<oop>(offset)));
coleenp@107 302 }
coleenp@107 303 inline void oopDesc::release_obj_field_put(int offset, oop value) {
coleenp@107 304 UseCompressedOops ?
coleenp@107 305 oop_store((volatile narrowOop*)obj_field_addr<narrowOop>(offset), value) :
coleenp@107 306 oop_store((volatile oop*) obj_field_addr<oop>(offset), value);
coleenp@107 307 }
duke@0 308
duke@0 309 inline jbyte oopDesc::byte_field_acquire(int offset) const { return OrderAccess::load_acquire(byte_field_addr(offset)); }
duke@0 310 inline void oopDesc::release_byte_field_put(int offset, jbyte contents) { OrderAccess::release_store(byte_field_addr(offset), contents); }
duke@0 311
duke@0 312 inline jboolean oopDesc::bool_field_acquire(int offset) const { return OrderAccess::load_acquire(bool_field_addr(offset)); }
duke@0 313 inline void oopDesc::release_bool_field_put(int offset, jboolean contents) { OrderAccess::release_store(bool_field_addr(offset), contents); }
duke@0 314
duke@0 315 inline jchar oopDesc::char_field_acquire(int offset) const { return OrderAccess::load_acquire(char_field_addr(offset)); }
duke@0 316 inline void oopDesc::release_char_field_put(int offset, jchar contents) { OrderAccess::release_store(char_field_addr(offset), contents); }
duke@0 317
duke@0 318 inline jint oopDesc::int_field_acquire(int offset) const { return OrderAccess::load_acquire(int_field_addr(offset)); }
duke@0 319 inline void oopDesc::release_int_field_put(int offset, jint contents) { OrderAccess::release_store(int_field_addr(offset), contents); }
duke@0 320
duke@0 321 inline jshort oopDesc::short_field_acquire(int offset) const { return (jshort)OrderAccess::load_acquire(short_field_addr(offset)); }
duke@0 322 inline void oopDesc::release_short_field_put(int offset, jshort contents) { OrderAccess::release_store(short_field_addr(offset), contents); }
duke@0 323
duke@0 324 inline jlong oopDesc::long_field_acquire(int offset) const { return OrderAccess::load_acquire(long_field_addr(offset)); }
duke@0 325 inline void oopDesc::release_long_field_put(int offset, jlong contents) { OrderAccess::release_store(long_field_addr(offset), contents); }
duke@0 326
duke@0 327 inline jfloat oopDesc::float_field_acquire(int offset) const { return OrderAccess::load_acquire(float_field_addr(offset)); }
duke@0 328 inline void oopDesc::release_float_field_put(int offset, jfloat contents) { OrderAccess::release_store(float_field_addr(offset), contents); }
duke@0 329
duke@0 330 inline jdouble oopDesc::double_field_acquire(int offset) const { return OrderAccess::load_acquire(double_field_addr(offset)); }
duke@0 331 inline void oopDesc::release_double_field_put(int offset, jdouble contents) { OrderAccess::release_store(double_field_addr(offset), contents); }
duke@0 332
duke@0 333 inline int oopDesc::size_given_klass(Klass* klass) {
duke@0 334 int lh = klass->layout_helper();
duke@0 335 int s = lh >> LogHeapWordSize; // deliver size scaled by wordSize
duke@0 336
duke@0 337 // lh is now a value computed at class initialization that may hint
duke@0 338 // at the size. For instances, this is positive and equal to the
duke@0 339 // size. For arrays, this is negative and provides log2 of the
duke@0 340 // array element size. For other oops, it is zero and thus requires
duke@0 341 // a virtual call.
duke@0 342 //
duke@0 343 // We go to all this trouble because the size computation is at the
duke@0 344 // heart of phase 2 of mark-compaction, and called for every object,
duke@0 345 // alive or dead. So the speed here is equal in importance to the
duke@0 346 // speed of allocation.
duke@0 347
duke@0 348 if (lh <= Klass::_lh_neutral_value) {
duke@0 349 // The most common case is instances; fall through if so.
duke@0 350 if (lh < Klass::_lh_neutral_value) {
duke@0 351 // Second most common case is arrays. We have to fetch the
duke@0 352 // length of the array, shift (multiply) it appropriately,
duke@0 353 // up to wordSize, add the header, and align to object size.
duke@0 354 size_t size_in_bytes;
duke@0 355 #ifdef _M_IA64
duke@0 356 // The Windows Itanium Aug 2002 SDK hoists this load above
duke@0 357 // the check for s < 0. An oop at the end of the heap will
duke@0 358 // cause an access violation if this load is performed on a non
duke@0 359 // array oop. Making the reference volatile prohibits this.
duke@0 360 // (%%% please explain by what magic the length is actually fetched!)
duke@0 361 volatile int *array_length;
duke@0 362 array_length = (volatile int *)( (intptr_t)this +
duke@0 363 arrayOopDesc::length_offset_in_bytes() );
duke@0 364 assert(array_length > 0, "Integer arithmetic problem somewhere");
duke@0 365 // Put into size_t to avoid overflow.
duke@0 366 size_in_bytes = (size_t) array_length;
duke@0 367 size_in_bytes = size_in_bytes << Klass::layout_helper_log2_element_size(lh);
duke@0 368 #else
duke@0 369 size_t array_length = (size_t) ((arrayOop)this)->length();
duke@0 370 size_in_bytes = array_length << Klass::layout_helper_log2_element_size(lh);
duke@0 371 #endif
duke@0 372 size_in_bytes += Klass::layout_helper_header_size(lh);
duke@0 373
duke@0 374 // This code could be simplified, but by keeping array_header_in_bytes
duke@0 375 // in units of bytes and doing it this way we can round up just once,
duke@0 376 // skipping the intermediate round to HeapWordSize. Cast the result
duke@0 377 // of round_to to size_t to guarantee unsigned division == right shift.
duke@0 378 s = (int)((size_t)round_to(size_in_bytes, MinObjAlignmentInBytes) /
duke@0 379 HeapWordSize);
duke@0 380
duke@0 381 // UseParNewGC can change the length field of an "old copy" of an object
duke@0 382 // array in the young gen so it indicates the stealable portion of
duke@0 383 // an already copied array. This will cause the first disjunct below
duke@0 384 // to fail if the sizes are computed across such a concurrent change.
duke@0 385 // UseParNewGC also runs with promotion labs (which look like int
duke@0 386 // filler arrays) which are subject to changing their declared size
duke@0 387 // when finally retiring a PLAB; this also can cause the first disjunct
duke@0 388 // to fail for another worker thread that is concurrently walking the block
duke@0 389 // offset table. Both these invariant failures are benign for their
duke@0 390 // current uses; we relax the assertion checking to cover these two cases below:
duke@0 391 // is_objArray() && is_forwarded() // covers first scenario above
duke@0 392 // || is_typeArray() // covers second scenario above
duke@0 393 // If and when UseParallelGC uses the same obj array oop stealing/chunking
duke@0 394 // technique, or when G1 is integrated (and currently uses this array chunking
duke@0 395 // technique) we will need to suitably modify the assertion.
duke@0 396 assert((s == klass->oop_size(this)) ||
duke@0 397 (((UseParNewGC || UseParallelGC) &&
coleenp@107 398 Universe::heap()->is_gc_active()) &&
duke@0 399 (is_typeArray() ||
duke@0 400 (is_objArray() && is_forwarded()))),
duke@0 401 "wrong array object size");
duke@0 402 } else {
duke@0 403 // Must be zero, so bite the bullet and take the virtual call.
duke@0 404 s = klass->oop_size(this);
duke@0 405 }
duke@0 406 }
duke@0 407
duke@0 408 assert(s % MinObjAlignment == 0, "alignment check");
duke@0 409 assert(s > 0, "Bad size calculated");
duke@0 410 return s;
duke@0 411 }
duke@0 412
duke@0 413
duke@0 414 inline int oopDesc::size() {
duke@0 415 return size_given_klass(blueprint());
duke@0 416 }
duke@0 417
duke@0 418 inline bool oopDesc::is_parsable() {
duke@0 419 return blueprint()->oop_is_parsable(this);
duke@0 420 }
duke@0 421
coleenp@107 422 inline void update_barrier_set(void* p, oop v) {
duke@0 423 assert(oopDesc::bs() != NULL, "Uninitialized bs in oop!");
duke@0 424 oopDesc::bs()->write_ref_field(p, v);
duke@0 425 }
duke@0 426
coleenp@107 427 template <class T> inline void oop_store(T* p, oop v) {
duke@0 428 if (always_do_update_barrier) {
coleenp@107 429 oop_store((volatile T*)p, v);
duke@0 430 } else {
coleenp@107 431 oopDesc::encode_store_heap_oop(p, v);
duke@0 432 update_barrier_set(p, v);
duke@0 433 }
duke@0 434 }
duke@0 435
coleenp@107 436 template <class T> inline void oop_store(volatile T* p, oop v) {
duke@0 437 // Used by release_obj_field_put, so use release_store_ptr.
coleenp@107 438 oopDesc::release_encode_store_heap_oop(p, v);
coleenp@107 439 update_barrier_set((void*)p, v);
duke@0 440 }
duke@0 441
coleenp@107 442 template <class T> inline void oop_store_without_check(T* p, oop v) {
duke@0 443 // XXX YSR FIX ME!!!
duke@0 444 if (always_do_update_barrier) {
coleenp@107 445 oop_store(p, v);
duke@0 446 } else {
duke@0 447 assert(!Universe::heap()->barrier_set()->write_ref_needs_barrier(p, v),
duke@0 448 "oop store without store check failed");
coleenp@107 449 oopDesc::encode_store_heap_oop(p, v);
duke@0 450 }
duke@0 451 }
duke@0 452
duke@0 453 // When it absolutely has to get there.
coleenp@107 454 template <class T> inline void oop_store_without_check(volatile T* p, oop v) {
duke@0 455 // XXX YSR FIX ME!!!
duke@0 456 if (always_do_update_barrier) {
duke@0 457 oop_store(p, v);
duke@0 458 } else {
coleenp@107 459 assert(!Universe::heap()->barrier_set()->write_ref_needs_barrier((T*)p, v),
duke@0 460 "oop store without store check failed");
coleenp@107 461 oopDesc::release_encode_store_heap_oop(p, v);
duke@0 462 }
duke@0 463 }
duke@0 464
coleenp@107 465 // Should replace *addr = oop assignments where addr type depends on UseCompressedOops
coleenp@107 466 // (without having to remember the function name this calls).
coleenp@107 467 inline void oop_store_raw(HeapWord* addr, oop value) {
coleenp@107 468 if (UseCompressedOops) {
coleenp@107 469 oopDesc::encode_store_heap_oop((narrowOop*)addr, value);
coleenp@107 470 } else {
coleenp@107 471 oopDesc::encode_store_heap_oop((oop*)addr, value);
coleenp@107 472 }
coleenp@107 473 }
duke@0 474
duke@0 475 // Used only for markSweep, scavenging
duke@0 476 inline bool oopDesc::is_gc_marked() const {
duke@0 477 return mark()->is_marked();
duke@0 478 }
duke@0 479
duke@0 480 inline bool oopDesc::is_locked() const {
duke@0 481 return mark()->is_locked();
duke@0 482 }
duke@0 483
duke@0 484 inline bool oopDesc::is_unlocked() const {
duke@0 485 return mark()->is_unlocked();
duke@0 486 }
duke@0 487
duke@0 488 inline bool oopDesc::has_bias_pattern() const {
duke@0 489 return mark()->has_bias_pattern();
duke@0 490 }
duke@0 491
duke@0 492 inline bool check_obj_alignment(oop obj) {
duke@0 493 return (intptr_t)obj % MinObjAlignmentInBytes == 0;
duke@0 494 }
duke@0 495
duke@0 496
duke@0 497 // used only for asserts
duke@0 498 inline bool oopDesc::is_oop(bool ignore_mark_word) const {
duke@0 499 oop obj = (oop) this;
duke@0 500 if (!check_obj_alignment(obj)) return false;
duke@0 501 if (!Universe::heap()->is_in_reserved(obj)) return false;
duke@0 502 // obj is aligned and accessible in heap
duke@0 503 // try to find metaclass cycle safely without seg faulting on bad input
duke@0 504 // we should reach klassKlassObj by following klass link at most 3 times
duke@0 505 for (int i = 0; i < 3; i++) {
duke@0 506 obj = obj->klass();
duke@0 507 // klass should be aligned and in permspace
duke@0 508 if (!check_obj_alignment(obj)) return false;
duke@0 509 if (!Universe::heap()->is_in_permanent(obj)) return false;
duke@0 510 }
duke@0 511 if (obj != Universe::klassKlassObj()) {
duke@0 512 // During a dump, the _klassKlassObj moved to a shared space.
duke@0 513 if (DumpSharedSpaces && Universe::klassKlassObj()->is_shared()) {
duke@0 514 return true;
duke@0 515 }
duke@0 516 return false;
duke@0 517 }
duke@0 518
duke@0 519 // Header verification: the mark is typically non-NULL. If we're
duke@0 520 // at a safepoint, it must not be null.
duke@0 521 // Outside of a safepoint, the header could be changing (for example,
duke@0 522 // another thread could be inflating a lock on this object).
duke@0 523 if (ignore_mark_word) {
duke@0 524 return true;
duke@0 525 }
duke@0 526 if (mark() != NULL) {
duke@0 527 return true;
duke@0 528 }
duke@0 529 return !SafepointSynchronize::is_at_safepoint();
duke@0 530 }
duke@0 531
duke@0 532
duke@0 533 // used only for asserts
duke@0 534 inline bool oopDesc::is_oop_or_null(bool ignore_mark_word) const {
duke@0 535 return this == NULL ? true : is_oop(ignore_mark_word);
duke@0 536 }
duke@0 537
duke@0 538 #ifndef PRODUCT
duke@0 539 // used only for asserts
duke@0 540 inline bool oopDesc::is_unlocked_oop() const {
duke@0 541 if (!Universe::heap()->is_in_reserved(this)) return false;
duke@0 542 return mark()->is_unlocked();
duke@0 543 }
duke@0 544 #endif // PRODUCT
duke@0 545
duke@0 546 inline void oopDesc::follow_header() {
coleenp@107 547 if (UseCompressedOops) {
coleenp@107 548 MarkSweep::mark_and_push(compressed_klass_addr());
coleenp@107 549 } else {
coleenp@107 550 MarkSweep::mark_and_push(klass_addr());
coleenp@107 551 }
duke@0 552 }
duke@0 553
coleenp@107 554 inline void oopDesc::follow_contents(void) {
duke@0 555 assert (is_gc_marked(), "should be marked");
duke@0 556 blueprint()->oop_follow_contents(this);
duke@0 557 }
duke@0 558
duke@0 559
duke@0 560 // Used by scavengers
duke@0 561
duke@0 562 inline bool oopDesc::is_forwarded() const {
duke@0 563 // The extra heap check is needed since the obj might be locked, in which case the
duke@0 564 // mark would point to a stack location and have the sentinel bit cleared
duke@0 565 return mark()->is_marked();
duke@0 566 }
duke@0 567
duke@0 568 // Used by scavengers
duke@0 569 inline void oopDesc::forward_to(oop p) {
duke@0 570 assert(Universe::heap()->is_in_reserved(p),
duke@0 571 "forwarding to something not in heap");
duke@0 572 markOop m = markOopDesc::encode_pointer_as_mark(p);
duke@0 573 assert(m->decode_pointer() == p, "encoding must be reversable");
duke@0 574 set_mark(m);
duke@0 575 }
duke@0 576
duke@0 577 // Used by parallel scavengers
duke@0 578 inline bool oopDesc::cas_forward_to(oop p, markOop compare) {
duke@0 579 assert(Universe::heap()->is_in_reserved(p),
duke@0 580 "forwarding to something not in heap");
duke@0 581 markOop m = markOopDesc::encode_pointer_as_mark(p);
duke@0 582 assert(m->decode_pointer() == p, "encoding must be reversable");
duke@0 583 return cas_set_mark(m, compare) == compare;
duke@0 584 }
duke@0 585
duke@0 586 // Note that the forwardee is not the same thing as the displaced_mark.
duke@0 587 // The forwardee is used when copying during scavenge and mark-sweep.
duke@0 588 // It does need to clear the low two locking- and GC-related bits.
coleenp@107 589 inline oop oopDesc::forwardee() const {
coleenp@107 590 return (oop) mark()->decode_pointer();
coleenp@107 591 }
duke@0 592
duke@0 593 inline bool oopDesc::has_displaced_mark() const {
duke@0 594 return mark()->has_displaced_mark_helper();
duke@0 595 }
duke@0 596
duke@0 597 inline markOop oopDesc::displaced_mark() const {
duke@0 598 return mark()->displaced_mark_helper();
duke@0 599 }
duke@0 600
duke@0 601 inline void oopDesc::set_displaced_mark(markOop m) {
duke@0 602 mark()->set_displaced_mark_helper(m);
duke@0 603 }
duke@0 604
duke@0 605 // The following method needs to be MT safe.
duke@0 606 inline int oopDesc::age() const {
duke@0 607 assert(!is_forwarded(), "Attempt to read age from forwarded mark");
duke@0 608 if (has_displaced_mark()) {
duke@0 609 return displaced_mark()->age();
duke@0 610 } else {
duke@0 611 return mark()->age();
duke@0 612 }
duke@0 613 }
duke@0 614
duke@0 615 inline void oopDesc::incr_age() {
duke@0 616 assert(!is_forwarded(), "Attempt to increment age of forwarded mark");
duke@0 617 if (has_displaced_mark()) {
duke@0 618 set_displaced_mark(displaced_mark()->incr_age());
duke@0 619 } else {
duke@0 620 set_mark(mark()->incr_age());
duke@0 621 }
duke@0 622 }
duke@0 623
duke@0 624
duke@0 625 inline intptr_t oopDesc::identity_hash() {
duke@0 626 // Fast case; if the object is unlocked and the hash value is set, no locking is needed
duke@0 627 // Note: The mark must be read into local variable to avoid concurrent updates.
duke@0 628 markOop mrk = mark();
duke@0 629 if (mrk->is_unlocked() && !mrk->has_no_hash()) {
duke@0 630 return mrk->hash();
duke@0 631 } else if (mrk->is_marked()) {
duke@0 632 return mrk->hash();
duke@0 633 } else {
duke@0 634 return slow_identity_hash();
duke@0 635 }
duke@0 636 }
duke@0 637
duke@0 638 inline void oopDesc::oop_iterate_header(OopClosure* blk) {
coleenp@107 639 if (UseCompressedOops) {
coleenp@107 640 blk->do_oop(compressed_klass_addr());
coleenp@107 641 } else {
coleenp@107 642 blk->do_oop(klass_addr());
coleenp@107 643 }
duke@0 644 }
duke@0 645
duke@0 646 inline void oopDesc::oop_iterate_header(OopClosure* blk, MemRegion mr) {
coleenp@107 647 if (UseCompressedOops) {
coleenp@107 648 if (mr.contains(compressed_klass_addr())) {
coleenp@107 649 blk->do_oop(compressed_klass_addr());
coleenp@107 650 }
coleenp@107 651 } else {
coleenp@107 652 if (mr.contains(klass_addr())) blk->do_oop(klass_addr());
coleenp@107 653 }
duke@0 654 }
duke@0 655
duke@0 656 inline int oopDesc::adjust_pointers() {
duke@0 657 debug_only(int check_size = size());
duke@0 658 int s = blueprint()->oop_adjust_pointers(this);
duke@0 659 assert(s == check_size, "should be the same");
duke@0 660 return s;
duke@0 661 }
duke@0 662
duke@0 663 inline void oopDesc::adjust_header() {
coleenp@107 664 if (UseCompressedOops) {
coleenp@107 665 MarkSweep::adjust_pointer(compressed_klass_addr());
coleenp@107 666 } else {
coleenp@107 667 MarkSweep::adjust_pointer(klass_addr());
coleenp@107 668 }
duke@0 669 }
duke@0 670
duke@0 671 #define OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \
duke@0 672 \
duke@0 673 inline int oopDesc::oop_iterate(OopClosureType* blk) { \
duke@0 674 SpecializationStats::record_call(); \
duke@0 675 return blueprint()->oop_oop_iterate##nv_suffix(this, blk); \
duke@0 676 } \
duke@0 677 \
duke@0 678 inline int oopDesc::oop_iterate(OopClosureType* blk, MemRegion mr) { \
duke@0 679 SpecializationStats::record_call(); \
duke@0 680 return blueprint()->oop_oop_iterate##nv_suffix##_m(this, blk, mr); \
duke@0 681 }
duke@0 682
duke@0 683 ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_ITERATE_DEFN)
duke@0 684 ALL_OOP_OOP_ITERATE_CLOSURES_3(OOP_ITERATE_DEFN)
duke@0 685
duke@0 686
duke@0 687 inline bool oopDesc::is_shared() const {
duke@0 688 return CompactingPermGenGen::is_shared(this);
duke@0 689 }
duke@0 690
duke@0 691 inline bool oopDesc::is_shared_readonly() const {
duke@0 692 return CompactingPermGenGen::is_shared_readonly(this);
duke@0 693 }
duke@0 694
duke@0 695 inline bool oopDesc::is_shared_readwrite() const {
duke@0 696 return CompactingPermGenGen::is_shared_readwrite(this);
duke@0 697 }