annotate src/share/vm/oops/oop.inline.hpp @ 7850:1d0974d906a5

Merge
author enevill
date Tue, 03 May 2016 11:05:40 +0100
parents 0d63f295c3c2 32b682649973
children
rev   line source
duke@0 1 /*
kevinw@7827 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. 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 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #ifndef SHARE_VM_OOPS_OOP_INLINE_HPP
stefank@1879 26 #define SHARE_VM_OOPS_OOP_INLINE_HPP
stefank@1879 27
stefank@1879 28 #include "gc_implementation/shared/ageTable.hpp"
stefank@1879 29 #include "gc_implementation/shared/markSweep.inline.hpp"
stefank@1879 30 #include "gc_interface/collectedHeap.inline.hpp"
stefank@1879 31 #include "memory/barrierSet.inline.hpp"
stefank@1879 32 #include "memory/cardTableModRefBS.hpp"
stefank@1879 33 #include "memory/genCollectedHeap.hpp"
stefank@1879 34 #include "memory/generation.hpp"
stefank@1879 35 #include "memory/specialized_oop_closures.hpp"
stefank@1879 36 #include "oops/arrayKlass.hpp"
stefank@1879 37 #include "oops/arrayOop.hpp"
hseigel@5093 38 #include "oops/klass.inline.hpp"
stefank@1879 39 #include "oops/markOop.inline.hpp"
stefank@1879 40 #include "oops/oop.hpp"
goetz@6316 41 #include "runtime/atomic.inline.hpp"
goetz@6316 42 #include "runtime/orderAccess.inline.hpp"
stefank@1879 43 #include "runtime/os.hpp"
jprovino@4107 44 #include "utilities/macros.hpp"
stefank@1879 45 #ifdef TARGET_ARCH_x86
stefank@1879 46 # include "bytes_x86.hpp"
stefank@1879 47 #endif
stefank@1879 48 #ifdef TARGET_ARCH_sparc
stefank@1879 49 # include "bytes_sparc.hpp"
stefank@1879 50 #endif
stefank@1879 51 #ifdef TARGET_ARCH_zero
stefank@1879 52 # include "bytes_zero.hpp"
stefank@1879 53 #endif
bobv@2073 54 #ifdef TARGET_ARCH_arm
bobv@2073 55 # include "bytes_arm.hpp"
bobv@2073 56 #endif
bobv@2073 57 #ifdef TARGET_ARCH_ppc
bobv@2073 58 # include "bytes_ppc.hpp"
bobv@2073 59 #endif
enevill@7673 60 #ifdef TARGET_ARCH_aarch32
enevill@7673 61 # include "bytes_aarch32.hpp"
enevill@7673 62 #endif
stefank@1879 63
duke@0 64 // Implementation of all inlined member functions defined in oop.hpp
duke@0 65 // We need a separate file to avoid circular references
duke@0 66
duke@0 67 inline void oopDesc::release_set_mark(markOop m) {
duke@0 68 OrderAccess::release_store_ptr(&_mark, m);
duke@0 69 }
duke@0 70
duke@0 71 inline markOop oopDesc::cas_set_mark(markOop new_mark, markOop old_mark) {
duke@0 72 return (markOop) Atomic::cmpxchg_ptr(new_mark, &_mark, old_mark);
duke@0 73 }
duke@0 74
coleenp@3602 75 inline Klass* oopDesc::klass() const {
ehelin@5259 76 if (UseCompressedClassPointers) {
hseigel@5093 77 return Klass::decode_klass_not_null(_metadata._compressed_klass);
coleenp@167 78 } else {
coleenp@167 79 return _metadata._klass;
coleenp@167 80 }
coleenp@167 81 }
coleenp@167 82
coleenp@3602 83 inline Klass* oopDesc::klass_or_null() const volatile {
coleenp@167 84 // can be NULL in CMS
ehelin@5259 85 if (UseCompressedClassPointers) {
hseigel@5093 86 return Klass::decode_klass(_metadata._compressed_klass);
coleenp@113 87 } else {
coleenp@113 88 return _metadata._klass;
coleenp@113 89 }
coleenp@113 90 }
coleenp@113 91
coleenp@113 92 inline int oopDesc::klass_gap_offset_in_bytes() {
ehelin@5259 93 assert(UseCompressedClassPointers, "only applicable to compressed klass pointers");
hseigel@5093 94 return oopDesc::klass_offset_in_bytes() + sizeof(narrowKlass);
coleenp@113 95 }
coleenp@113 96
coleenp@3602 97 inline Klass** oopDesc::klass_addr() {
coleenp@113 98 // Only used internally and with CMS and will not work with
coleenp@113 99 // UseCompressedOops
ehelin@5259 100 assert(!UseCompressedClassPointers, "only supported with uncompressed klass pointers");
coleenp@3602 101 return (Klass**) &_metadata._klass;
coleenp@113 102 }
coleenp@113 103
hseigel@5093 104 inline narrowKlass* oopDesc::compressed_klass_addr() {
ehelin@5259 105 assert(UseCompressedClassPointers, "only called by compressed klass pointers");
hseigel@5093 106 return &_metadata._compressed_klass;
coleenp@113 107 }
coleenp@113 108
coleenp@3602 109 inline void oopDesc::set_klass(Klass* k) {
duke@0 110 // since klasses are promoted no store check is needed
coleenp@3602 111 assert(Universe::is_bootstrapping() || k != NULL, "must be a real Klass*");
coleenp@3602 112 assert(Universe::is_bootstrapping() || k->is_klass(), "not a Klass*");
ehelin@5259 113 if (UseCompressedClassPointers) {
hseigel@5093 114 *compressed_klass_addr() = Klass::encode_klass_not_null(k);
coleenp@113 115 } else {
coleenp@3602 116 *klass_addr() = k;
coleenp@113 117 }
duke@0 118 }
duke@0 119
coleenp@167 120 inline int oopDesc::klass_gap() const {
coleenp@167 121 return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
coleenp@167 122 }
coleenp@167 123
coleenp@167 124 inline void oopDesc::set_klass_gap(int v) {
ehelin@5259 125 if (UseCompressedClassPointers) {
coleenp@167 126 *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes()) = v;
coleenp@167 127 }
coleenp@167 128 }
coleenp@167 129
duke@0 130 inline void oopDesc::set_klass_to_list_ptr(oop k) {
duke@0 131 // This is only to be used during GC, for from-space objects, so no
duke@0 132 // barrier is needed.
ehelin@5259 133 if (UseCompressedClassPointers) {
hseigel@5093 134 _metadata._compressed_klass = (narrowKlass)encode_heap_oop(k); // may be null (parnew overflow handling)
coleenp@113 135 } else {
coleenp@3602 136 _metadata._klass = (Klass*)(address)k;
coleenp@3602 137 }
coleenp@3602 138 }
coleenp@3602 139
coleenp@3602 140 inline oop oopDesc::list_ptr_from_klass() {
coleenp@3602 141 // This is only to be used during GC, for from-space objects.
ehelin@5259 142 if (UseCompressedClassPointers) {
hseigel@5093 143 return decode_heap_oop((narrowOop)_metadata._compressed_klass);
coleenp@3602 144 } else {
coleenp@3602 145 // Special case for GC
coleenp@3602 146 return (oop)(address)_metadata._klass;
coleenp@113 147 }
duke@0 148 }
duke@0 149
duke@0 150 inline void oopDesc::init_mark() { set_mark(markOopDesc::prototype_for_object(this)); }
duke@0 151
coleenp@3602 152 inline bool oopDesc::is_a(Klass* k) const { return klass()->is_subtype_of(k); }
duke@0 153
stefank@6449 154 inline bool oopDesc::is_instance() const { return klass()->oop_is_instance(); }
stefank@6449 155 inline bool oopDesc::is_instanceClassLoader() const { return klass()->oop_is_instanceClassLoader(); }
stefank@6449 156 inline bool oopDesc::is_instanceMirror() const { return klass()->oop_is_instanceMirror(); }
stefank@6449 157 inline bool oopDesc::is_instanceRef() const { return klass()->oop_is_instanceRef(); }
stefank@6449 158 inline bool oopDesc::is_array() const { return klass()->oop_is_array(); }
stefank@6449 159 inline bool oopDesc::is_objArray() const { return klass()->oop_is_objArray(); }
stefank@6449 160 inline bool oopDesc::is_typeArray() const { return klass()->oop_is_typeArray(); }
duke@0 161
duke@0 162 inline void* oopDesc::field_base(int offset) const { return (void*)&((char*)this)[offset]; }
duke@0 163
coleenp@113 164 template <class T> inline T* oopDesc::obj_field_addr(int offset) const { return (T*)field_base(offset); }
coleenp@3602 165 inline Metadata** oopDesc::metadata_field_addr(int offset) const { return (Metadata**)field_base(offset); }
duke@0 166 inline jbyte* oopDesc::byte_field_addr(int offset) const { return (jbyte*) field_base(offset); }
duke@0 167 inline jchar* oopDesc::char_field_addr(int offset) const { return (jchar*) field_base(offset); }
duke@0 168 inline jboolean* oopDesc::bool_field_addr(int offset) const { return (jboolean*)field_base(offset); }
duke@0 169 inline jint* oopDesc::int_field_addr(int offset) const { return (jint*) field_base(offset); }
duke@0 170 inline jshort* oopDesc::short_field_addr(int offset) const { return (jshort*) field_base(offset); }
duke@0 171 inline jlong* oopDesc::long_field_addr(int offset) const { return (jlong*) field_base(offset); }
duke@0 172 inline jfloat* oopDesc::float_field_addr(int offset) const { return (jfloat*) field_base(offset); }
duke@0 173 inline jdouble* oopDesc::double_field_addr(int offset) const { return (jdouble*) field_base(offset); }
coleenp@113 174 inline address* oopDesc::address_field_addr(int offset) const { return (address*) field_base(offset); }
duke@0 175
coleenp@113 176
coleenp@113 177 // Functions for getting and setting oops within instance objects.
coleenp@113 178 // If the oops are compressed, the type passed to these overloaded functions
coleenp@113 179 // is narrowOop. All functions are overloaded so they can be called by
coleenp@113 180 // template functions without conditionals (the compiler instantiates via
coleenp@113 181 // the right type and inlines the appopriate code).
coleenp@113 182
coleenp@113 183 inline bool oopDesc::is_null(oop obj) { return obj == NULL; }
coleenp@113 184 inline bool oopDesc::is_null(narrowOop obj) { return obj == 0; }
coleenp@113 185
coleenp@113 186 // Algorithm for encoding and decoding oops from 64 bit pointers to 32 bit
coleenp@113 187 // offset from the heap base. Saving the check for null can save instructions
coleenp@113 188 // in inner GC loops so these are separated.
coleenp@113 189
kvn@1491 190 inline bool check_obj_alignment(oop obj) {
hseigel@5349 191 return cast_from_oop<intptr_t>(obj) % MinObjAlignmentInBytes == 0;
kvn@1491 192 }
kvn@1491 193
coleenp@113 194 inline narrowOop oopDesc::encode_heap_oop_not_null(oop v) {
coleenp@113 195 assert(!is_null(v), "oop value can never be zero");
kvn@1491 196 assert(check_obj_alignment(v), "Address not aligned");
ysr@845 197 assert(Universe::heap()->is_in_reserved(v), "Address not in heap");
kvn@642 198 address base = Universe::narrow_oop_base();
kvn@642 199 int shift = Universe::narrow_oop_shift();
kvn@642 200 uint64_t pd = (uint64_t)(pointer_delta((void*)v, (void*)base, 1));
coleenp@135 201 assert(OopEncodingHeapMax > pd, "change encoding max if new encoding");
kvn@642 202 uint64_t result = pd >> shift;
coleenp@135 203 assert((result & CONST64(0xffffffff00000000)) == 0, "narrow oop overflow");
ysr@845 204 assert(decode_heap_oop(result) == v, "reversibility");
coleenp@113 205 return (narrowOop)result;
coleenp@113 206 }
coleenp@113 207
coleenp@113 208 inline narrowOop oopDesc::encode_heap_oop(oop v) {
coleenp@113 209 return (is_null(v)) ? (narrowOop)0 : encode_heap_oop_not_null(v);
coleenp@113 210 }
coleenp@113 211
coleenp@113 212 inline oop oopDesc::decode_heap_oop_not_null(narrowOop v) {
coleenp@113 213 assert(!is_null(v), "narrow oop value can never be zero");
kvn@642 214 address base = Universe::narrow_oop_base();
kvn@642 215 int shift = Universe::narrow_oop_shift();
kvn@1491 216 oop result = (oop)(void*)((uintptr_t)base + ((uintptr_t)v << shift));
drchase@6245 217 assert(check_obj_alignment(result), err_msg("address not aligned: " INTPTR_FORMAT, p2i((void*) result)));
kvn@1491 218 return result;
coleenp@113 219 }
coleenp@113 220
coleenp@113 221 inline oop oopDesc::decode_heap_oop(narrowOop v) {
coleenp@113 222 return is_null(v) ? (oop)NULL : decode_heap_oop_not_null(v);
coleenp@113 223 }
coleenp@113 224
coleenp@113 225 inline oop oopDesc::decode_heap_oop_not_null(oop v) { return v; }
coleenp@113 226 inline oop oopDesc::decode_heap_oop(oop v) { return v; }
coleenp@113 227
coleenp@113 228 // Load an oop out of the Java heap as is without decoding.
coleenp@113 229 // Called by GC to check for null before decoding.
coleenp@113 230 inline oop oopDesc::load_heap_oop(oop* p) { return *p; }
coleenp@113 231 inline narrowOop oopDesc::load_heap_oop(narrowOop* p) { return *p; }
coleenp@113 232
coleenp@113 233 // Load and decode an oop out of the Java heap into a wide oop.
coleenp@113 234 inline oop oopDesc::load_decode_heap_oop_not_null(oop* p) { return *p; }
coleenp@113 235 inline oop oopDesc::load_decode_heap_oop_not_null(narrowOop* p) {
coleenp@113 236 return decode_heap_oop_not_null(*p);
coleenp@113 237 }
coleenp@113 238
coleenp@113 239 // Load and decode an oop out of the heap accepting null
coleenp@113 240 inline oop oopDesc::load_decode_heap_oop(oop* p) { return *p; }
coleenp@113 241 inline oop oopDesc::load_decode_heap_oop(narrowOop* p) {
coleenp@113 242 return decode_heap_oop(*p);
coleenp@113 243 }
coleenp@113 244
coleenp@113 245 // Store already encoded heap oop into the heap.
coleenp@113 246 inline void oopDesc::store_heap_oop(oop* p, oop v) { *p = v; }
coleenp@113 247 inline void oopDesc::store_heap_oop(narrowOop* p, narrowOop v) { *p = v; }
coleenp@113 248
coleenp@113 249 // Encode and store a heap oop.
coleenp@113 250 inline void oopDesc::encode_store_heap_oop_not_null(narrowOop* p, oop v) {
coleenp@113 251 *p = encode_heap_oop_not_null(v);
coleenp@113 252 }
coleenp@113 253 inline void oopDesc::encode_store_heap_oop_not_null(oop* p, oop v) { *p = v; }
coleenp@113 254
coleenp@113 255 // Encode and store a heap oop allowing for null.
coleenp@113 256 inline void oopDesc::encode_store_heap_oop(narrowOop* p, oop v) {
coleenp@113 257 *p = encode_heap_oop(v);
coleenp@113 258 }
coleenp@113 259 inline void oopDesc::encode_store_heap_oop(oop* p, oop v) { *p = v; }
coleenp@113 260
coleenp@113 261 // Store heap oop as is for volatile fields.
coleenp@113 262 inline void oopDesc::release_store_heap_oop(volatile oop* p, oop v) {
coleenp@113 263 OrderAccess::release_store_ptr(p, v);
coleenp@113 264 }
coleenp@113 265 inline void oopDesc::release_store_heap_oop(volatile narrowOop* p,
coleenp@113 266 narrowOop v) {
coleenp@113 267 OrderAccess::release_store(p, v);
coleenp@113 268 }
coleenp@113 269
coleenp@113 270 inline void oopDesc::release_encode_store_heap_oop_not_null(
coleenp@113 271 volatile narrowOop* p, oop v) {
coleenp@113 272 // heap oop is not pointer sized.
coleenp@113 273 OrderAccess::release_store(p, encode_heap_oop_not_null(v));
coleenp@113 274 }
coleenp@113 275
coleenp@113 276 inline void oopDesc::release_encode_store_heap_oop_not_null(
coleenp@113 277 volatile oop* p, oop v) {
coleenp@113 278 OrderAccess::release_store_ptr(p, v);
coleenp@113 279 }
coleenp@113 280
coleenp@113 281 inline void oopDesc::release_encode_store_heap_oop(volatile oop* p,
coleenp@113 282 oop v) {
coleenp@113 283 OrderAccess::release_store_ptr(p, v);
coleenp@113 284 }
coleenp@113 285 inline void oopDesc::release_encode_store_heap_oop(
coleenp@113 286 volatile narrowOop* p, oop v) {
coleenp@113 287 OrderAccess::release_store(p, encode_heap_oop(v));
coleenp@113 288 }
coleenp@113 289
coleenp@113 290
coleenp@113 291 // These functions are only used to exchange oop fields in instances,
coleenp@113 292 // not headers.
coleenp@113 293 inline oop oopDesc::atomic_exchange_oop(oop exchange_value, volatile HeapWord *dest) {
coleenp@113 294 if (UseCompressedOops) {
coleenp@113 295 // encode exchange value from oop to T
coleenp@113 296 narrowOop val = encode_heap_oop(exchange_value);
coleenp@113 297 narrowOop old = (narrowOop)Atomic::xchg(val, (narrowOop*)dest);
coleenp@113 298 // decode old from T to oop
coleenp@113 299 return decode_heap_oop(old);
coleenp@113 300 } else {
coleenp@113 301 return (oop)Atomic::xchg_ptr(exchange_value, (oop*)dest);
coleenp@113 302 }
coleenp@113 303 }
coleenp@113 304
coleenp@113 305 // In order to put or get a field out of an instance, must first check
coleenp@113 306 // if the field has been compressed and uncompress it.
coleenp@113 307 inline oop oopDesc::obj_field(int offset) const {
coleenp@113 308 return UseCompressedOops ?
coleenp@113 309 load_decode_heap_oop(obj_field_addr<narrowOop>(offset)) :
coleenp@113 310 load_decode_heap_oop(obj_field_addr<oop>(offset));
coleenp@113 311 }
twisti@2696 312 inline volatile oop oopDesc::obj_field_volatile(int offset) const {
twisti@2696 313 volatile oop value = obj_field(offset);
twisti@2696 314 OrderAccess::acquire();
twisti@2696 315 return value;
twisti@2696 316 }
coleenp@113 317 inline void oopDesc::obj_field_put(int offset, oop value) {
coleenp@113 318 UseCompressedOops ? oop_store(obj_field_addr<narrowOop>(offset), value) :
coleenp@113 319 oop_store(obj_field_addr<oop>(offset), value);
coleenp@113 320 }
coleenp@3602 321
coleenp@3602 322 inline Metadata* oopDesc::metadata_field(int offset) const {
coleenp@3602 323 return *metadata_field_addr(offset);
coleenp@3602 324 }
coleenp@3602 325
coleenp@3602 326 inline void oopDesc::metadata_field_put(int offset, Metadata* value) {
coleenp@3602 327 *metadata_field_addr(offset) = value;
coleenp@3602 328 }
coleenp@3602 329
twisti@2696 330 inline void oopDesc::obj_field_put_raw(int offset, oop value) {
coleenp@113 331 UseCompressedOops ?
coleenp@113 332 encode_store_heap_oop(obj_field_addr<narrowOop>(offset), value) :
coleenp@113 333 encode_store_heap_oop(obj_field_addr<oop>(offset), value);
coleenp@113 334 }
twisti@2696 335 inline void oopDesc::obj_field_put_volatile(int offset, oop value) {
twisti@2696 336 OrderAccess::release();
twisti@2696 337 obj_field_put(offset, value);
twisti@2696 338 OrderAccess::fence();
twisti@2696 339 }
duke@0 340
duke@0 341 inline jbyte oopDesc::byte_field(int offset) const { return (jbyte) *byte_field_addr(offset); }
duke@0 342 inline void oopDesc::byte_field_put(int offset, jbyte contents) { *byte_field_addr(offset) = (jint) contents; }
duke@0 343
duke@0 344 inline jboolean oopDesc::bool_field(int offset) const { return (jboolean) *bool_field_addr(offset); }
kevinw@7827 345 inline void oopDesc::bool_field_put(int offset, jboolean contents) { *bool_field_addr(offset) = (( (jint) contents) & 1); }
duke@0 346
duke@0 347 inline jchar oopDesc::char_field(int offset) const { return (jchar) *char_field_addr(offset); }
duke@0 348 inline void oopDesc::char_field_put(int offset, jchar contents) { *char_field_addr(offset) = (jint) contents; }
duke@0 349
duke@0 350 inline jint oopDesc::int_field(int offset) const { return *int_field_addr(offset); }
duke@0 351 inline void oopDesc::int_field_put(int offset, jint contents) { *int_field_addr(offset) = contents; }
duke@0 352
duke@0 353 inline jshort oopDesc::short_field(int offset) const { return (jshort) *short_field_addr(offset); }
duke@0 354 inline void oopDesc::short_field_put(int offset, jshort contents) { *short_field_addr(offset) = (jint) contents;}
duke@0 355
duke@0 356 inline jlong oopDesc::long_field(int offset) const { return *long_field_addr(offset); }
duke@0 357 inline void oopDesc::long_field_put(int offset, jlong contents) { *long_field_addr(offset) = contents; }
duke@0 358
duke@0 359 inline jfloat oopDesc::float_field(int offset) const { return *float_field_addr(offset); }
duke@0 360 inline void oopDesc::float_field_put(int offset, jfloat contents) { *float_field_addr(offset) = contents; }
duke@0 361
duke@0 362 inline jdouble oopDesc::double_field(int offset) const { return *double_field_addr(offset); }
duke@0 363 inline void oopDesc::double_field_put(int offset, jdouble contents) { *double_field_addr(offset) = contents; }
duke@0 364
coleenp@113 365 inline address oopDesc::address_field(int offset) const { return *address_field_addr(offset); }
coleenp@113 366 inline void oopDesc::address_field_put(int offset, address contents) { *address_field_addr(offset) = contents; }
coleenp@113 367
coleenp@113 368 inline oop oopDesc::obj_field_acquire(int offset) const {
coleenp@113 369 return UseCompressedOops ?
coleenp@113 370 decode_heap_oop((narrowOop)
coleenp@113 371 OrderAccess::load_acquire(obj_field_addr<narrowOop>(offset)))
coleenp@113 372 : decode_heap_oop((oop)
coleenp@113 373 OrderAccess::load_ptr_acquire(obj_field_addr<oop>(offset)));
coleenp@113 374 }
coleenp@113 375 inline void oopDesc::release_obj_field_put(int offset, oop value) {
coleenp@113 376 UseCompressedOops ?
coleenp@113 377 oop_store((volatile narrowOop*)obj_field_addr<narrowOop>(offset), value) :
coleenp@113 378 oop_store((volatile oop*) obj_field_addr<oop>(offset), value);
coleenp@113 379 }
duke@0 380
duke@0 381 inline jbyte oopDesc::byte_field_acquire(int offset) const { return OrderAccess::load_acquire(byte_field_addr(offset)); }
duke@0 382 inline void oopDesc::release_byte_field_put(int offset, jbyte contents) { OrderAccess::release_store(byte_field_addr(offset), contents); }
duke@0 383
duke@0 384 inline jboolean oopDesc::bool_field_acquire(int offset) const { return OrderAccess::load_acquire(bool_field_addr(offset)); }
kevinw@7827 385 inline void oopDesc::release_bool_field_put(int offset, jboolean contents) { OrderAccess::release_store(bool_field_addr(offset), (contents & 1)); }
duke@0 386
duke@0 387 inline jchar oopDesc::char_field_acquire(int offset) const { return OrderAccess::load_acquire(char_field_addr(offset)); }
duke@0 388 inline void oopDesc::release_char_field_put(int offset, jchar contents) { OrderAccess::release_store(char_field_addr(offset), contents); }
duke@0 389
duke@0 390 inline jint oopDesc::int_field_acquire(int offset) const { return OrderAccess::load_acquire(int_field_addr(offset)); }
duke@0 391 inline void oopDesc::release_int_field_put(int offset, jint contents) { OrderAccess::release_store(int_field_addr(offset), contents); }
duke@0 392
duke@0 393 inline jshort oopDesc::short_field_acquire(int offset) const { return (jshort)OrderAccess::load_acquire(short_field_addr(offset)); }
duke@0 394 inline void oopDesc::release_short_field_put(int offset, jshort contents) { OrderAccess::release_store(short_field_addr(offset), contents); }
duke@0 395
duke@0 396 inline jlong oopDesc::long_field_acquire(int offset) const { return OrderAccess::load_acquire(long_field_addr(offset)); }
duke@0 397 inline void oopDesc::release_long_field_put(int offset, jlong contents) { OrderAccess::release_store(long_field_addr(offset), contents); }
duke@0 398
duke@0 399 inline jfloat oopDesc::float_field_acquire(int offset) const { return OrderAccess::load_acquire(float_field_addr(offset)); }
duke@0 400 inline void oopDesc::release_float_field_put(int offset, jfloat contents) { OrderAccess::release_store(float_field_addr(offset), contents); }
duke@0 401
duke@0 402 inline jdouble oopDesc::double_field_acquire(int offset) const { return OrderAccess::load_acquire(double_field_addr(offset)); }
duke@0 403 inline void oopDesc::release_double_field_put(int offset, jdouble contents) { OrderAccess::release_store(double_field_addr(offset), contents); }
duke@0 404
jrose@710 405 inline address oopDesc::address_field_acquire(int offset) const { return (address) OrderAccess::load_ptr_acquire(address_field_addr(offset)); }
jrose@710 406 inline void oopDesc::release_address_field_put(int offset, address contents) { OrderAccess::release_store_ptr(address_field_addr(offset), contents); }
jrose@710 407
duke@0 408 inline int oopDesc::size_given_klass(Klass* klass) {
duke@0 409 int lh = klass->layout_helper();
never@2223 410 int s;
duke@0 411
duke@0 412 // lh is now a value computed at class initialization that may hint
duke@0 413 // at the size. For instances, this is positive and equal to the
duke@0 414 // size. For arrays, this is negative and provides log2 of the
duke@0 415 // array element size. For other oops, it is zero and thus requires
duke@0 416 // a virtual call.
duke@0 417 //
duke@0 418 // We go to all this trouble because the size computation is at the
duke@0 419 // heart of phase 2 of mark-compaction, and called for every object,
duke@0 420 // alive or dead. So the speed here is equal in importance to the
duke@0 421 // speed of allocation.
duke@0 422
never@2223 423 if (lh > Klass::_lh_neutral_value) {
never@2223 424 if (!Klass::layout_helper_needs_slow_path(lh)) {
never@2223 425 s = lh >> LogHeapWordSize; // deliver size scaled by wordSize
never@2223 426 } else {
never@2223 427 s = klass->oop_size(this);
never@2223 428 }
never@2223 429 } else if (lh <= Klass::_lh_neutral_value) {
duke@0 430 // The most common case is instances; fall through if so.
duke@0 431 if (lh < Klass::_lh_neutral_value) {
duke@0 432 // Second most common case is arrays. We have to fetch the
duke@0 433 // length of the array, shift (multiply) it appropriately,
duke@0 434 // up to wordSize, add the header, and align to object size.
duke@0 435 size_t size_in_bytes;
duke@0 436 #ifdef _M_IA64
duke@0 437 // The Windows Itanium Aug 2002 SDK hoists this load above
duke@0 438 // the check for s < 0. An oop at the end of the heap will
duke@0 439 // cause an access violation if this load is performed on a non
duke@0 440 // array oop. Making the reference volatile prohibits this.
duke@0 441 // (%%% please explain by what magic the length is actually fetched!)
duke@0 442 volatile int *array_length;
duke@0 443 array_length = (volatile int *)( (intptr_t)this +
duke@0 444 arrayOopDesc::length_offset_in_bytes() );
duke@0 445 assert(array_length > 0, "Integer arithmetic problem somewhere");
duke@0 446 // Put into size_t to avoid overflow.
duke@0 447 size_in_bytes = (size_t) array_length;
duke@0 448 size_in_bytes = size_in_bytes << Klass::layout_helper_log2_element_size(lh);
duke@0 449 #else
duke@0 450 size_t array_length = (size_t) ((arrayOop)this)->length();
duke@0 451 size_in_bytes = array_length << Klass::layout_helper_log2_element_size(lh);
duke@0 452 #endif
duke@0 453 size_in_bytes += Klass::layout_helper_header_size(lh);
duke@0 454
duke@0 455 // This code could be simplified, but by keeping array_header_in_bytes
duke@0 456 // in units of bytes and doing it this way we can round up just once,
duke@0 457 // skipping the intermediate round to HeapWordSize. Cast the result
duke@0 458 // of round_to to size_t to guarantee unsigned division == right shift.
duke@0 459 s = (int)((size_t)round_to(size_in_bytes, MinObjAlignmentInBytes) /
duke@0 460 HeapWordSize);
duke@0 461
ysr@342 462 // UseParNewGC, UseParallelGC and UseG1GC can change the length field
ysr@342 463 // of an "old copy" of an object array in the young gen so it indicates
ysr@342 464 // the grey portion of an already copied array. This will cause the first
ysr@342 465 // disjunct below to fail if the two comparands are computed across such
ysr@342 466 // a concurrent change.
duke@0 467 // UseParNewGC also runs with promotion labs (which look like int
duke@0 468 // filler arrays) which are subject to changing their declared size
duke@0 469 // when finally retiring a PLAB; this also can cause the first disjunct
duke@0 470 // to fail for another worker thread that is concurrently walking the block
duke@0 471 // offset table. Both these invariant failures are benign for their
duke@0 472 // current uses; we relax the assertion checking to cover these two cases below:
duke@0 473 // is_objArray() && is_forwarded() // covers first scenario above
duke@0 474 // || is_typeArray() // covers second scenario above
duke@0 475 // If and when UseParallelGC uses the same obj array oop stealing/chunking
ysr@342 476 // technique, we will need to suitably modify the assertion.
duke@0 477 assert((s == klass->oop_size(this)) ||
ysr@342 478 (Universe::heap()->is_gc_active() &&
ysr@342 479 ((is_typeArray() && UseParNewGC) ||
ysr@342 480 (is_objArray() && is_forwarded() && (UseParNewGC || UseParallelGC || UseG1GC)))),
duke@0 481 "wrong array object size");
duke@0 482 } else {
duke@0 483 // Must be zero, so bite the bullet and take the virtual call.
duke@0 484 s = klass->oop_size(this);
duke@0 485 }
duke@0 486 }
duke@0 487
duke@0 488 assert(s % MinObjAlignment == 0, "alignment check");
duke@0 489 assert(s > 0, "Bad size calculated");
duke@0 490 return s;
duke@0 491 }
duke@0 492
duke@0 493
duke@0 494 inline int oopDesc::size() {
coleenp@3602 495 return size_given_klass(klass());
jmasa@518 496 }
jmasa@518 497
goetz@6058 498 inline void update_barrier_set(void* p, oop v, bool release = false) {
duke@0 499 assert(oopDesc::bs() != NULL, "Uninitialized bs in oop!");
goetz@6058 500 oopDesc::bs()->write_ref_field(p, v, release);
duke@0 501 }
duke@0 502
ysr@845 503 template <class T> inline void update_barrier_set_pre(T* p, oop v) {
ysr@342 504 oopDesc::bs()->write_ref_field_pre(p, v);
ysr@342 505 }
ysr@342 506
coleenp@113 507 template <class T> inline void oop_store(T* p, oop v) {
duke@0 508 if (always_do_update_barrier) {
coleenp@113 509 oop_store((volatile T*)p, v);
duke@0 510 } else {
ysr@342 511 update_barrier_set_pre(p, v);
coleenp@113 512 oopDesc::encode_store_heap_oop(p, v);
goetz@6058 513 // always_do_update_barrier == false =>
goetz@6058 514 // Either we are at a safepoint (in GC) or CMS is not used. In both
goetz@6058 515 // cases it's unnecessary to mark the card as dirty with release sematics.
goetz@6058 516 update_barrier_set((void*)p, v, false /* release */); // cast away type
duke@0 517 }
duke@0 518 }
duke@0 519
coleenp@113 520 template <class T> inline void oop_store(volatile T* p, oop v) {
ysr@845 521 update_barrier_set_pre((T*)p, v); // cast away volatile
duke@0 522 // Used by release_obj_field_put, so use release_store_ptr.
coleenp@113 523 oopDesc::release_encode_store_heap_oop(p, v);
goetz@6058 524 // When using CMS we must mark the card corresponding to p as dirty
goetz@6058 525 // with release sematics to prevent that CMS sees the dirty card but
goetz@6058 526 // not the new value v at p due to reordering of the two
goetz@6058 527 // stores. Note that CMS has a concurrent precleaning phase, where
goetz@6058 528 // it reads the card table while the Java threads are running.
goetz@6058 529 update_barrier_set((void*)p, v, true /* release */); // cast away type
duke@0 530 }
duke@0 531
coleenp@113 532 // Should replace *addr = oop assignments where addr type depends on UseCompressedOops
coleenp@113 533 // (without having to remember the function name this calls).
coleenp@113 534 inline void oop_store_raw(HeapWord* addr, oop value) {
coleenp@113 535 if (UseCompressedOops) {
coleenp@113 536 oopDesc::encode_store_heap_oop((narrowOop*)addr, value);
coleenp@113 537 } else {
coleenp@113 538 oopDesc::encode_store_heap_oop((oop*)addr, value);
coleenp@113 539 }
coleenp@113 540 }
duke@0 541
coleenp@3602 542 inline oop oopDesc::atomic_compare_exchange_oop(oop exchange_value,
coleenp@3602 543 volatile HeapWord *dest,
coleenp@3602 544 oop compare_value,
coleenp@3602 545 bool prebarrier) {
coleenp@3602 546 if (UseCompressedOops) {
coleenp@3602 547 if (prebarrier) {
coleenp@3602 548 update_barrier_set_pre((narrowOop*)dest, exchange_value);
coleenp@3602 549 }
coleenp@3602 550 // encode exchange and compare value from oop to T
coleenp@3602 551 narrowOop val = encode_heap_oop(exchange_value);
coleenp@3602 552 narrowOop cmp = encode_heap_oop(compare_value);
coleenp@3602 553
coleenp@3602 554 narrowOop old = (narrowOop) Atomic::cmpxchg(val, (narrowOop*)dest, cmp);
coleenp@3602 555 // decode old from T to oop
coleenp@3602 556 return decode_heap_oop(old);
coleenp@3602 557 } else {
coleenp@3602 558 if (prebarrier) {
coleenp@3602 559 update_barrier_set_pre((oop*)dest, exchange_value);
coleenp@3602 560 }
coleenp@3602 561 return (oop)Atomic::cmpxchg_ptr(exchange_value, (oop*)dest, compare_value);
coleenp@3602 562 }
coleenp@3602 563 }
coleenp@3602 564
duke@0 565 // Used only for markSweep, scavenging
duke@0 566 inline bool oopDesc::is_gc_marked() const {
duke@0 567 return mark()->is_marked();
duke@0 568 }
duke@0 569
duke@0 570 inline bool oopDesc::is_locked() const {
duke@0 571 return mark()->is_locked();
duke@0 572 }
duke@0 573
duke@0 574 inline bool oopDesc::is_unlocked() const {
duke@0 575 return mark()->is_unlocked();
duke@0 576 }
duke@0 577
duke@0 578 inline bool oopDesc::has_bias_pattern() const {
duke@0 579 return mark()->has_bias_pattern();
duke@0 580 }
duke@0 581
duke@0 582
duke@0 583 // used only for asserts
duke@0 584 inline bool oopDesc::is_oop(bool ignore_mark_word) const {
duke@0 585 oop obj = (oop) this;
duke@0 586 if (!check_obj_alignment(obj)) return false;
duke@0 587 if (!Universe::heap()->is_in_reserved(obj)) return false;
duke@0 588 // obj is aligned and accessible in heap
coleenp@3602 589 if (Universe::heap()->is_in_reserved(obj->klass_or_null())) return false;
duke@0 590
duke@0 591 // Header verification: the mark is typically non-NULL. If we're
duke@0 592 // at a safepoint, it must not be null.
duke@0 593 // Outside of a safepoint, the header could be changing (for example,
duke@0 594 // another thread could be inflating a lock on this object).
duke@0 595 if (ignore_mark_word) {
duke@0 596 return true;
duke@0 597 }
duke@0 598 if (mark() != NULL) {
duke@0 599 return true;
duke@0 600 }
duke@0 601 return !SafepointSynchronize::is_at_safepoint();
duke@0 602 }
duke@0 603
duke@0 604
duke@0 605 // used only for asserts
duke@0 606 inline bool oopDesc::is_oop_or_null(bool ignore_mark_word) const {
duke@0 607 return this == NULL ? true : is_oop(ignore_mark_word);
duke@0 608 }
duke@0 609
duke@0 610 #ifndef PRODUCT
duke@0 611 // used only for asserts
duke@0 612 inline bool oopDesc::is_unlocked_oop() const {
duke@0 613 if (!Universe::heap()->is_in_reserved(this)) return false;
duke@0 614 return mark()->is_unlocked();
duke@0 615 }
duke@0 616 #endif // PRODUCT
duke@0 617
coleenp@113 618 inline void oopDesc::follow_contents(void) {
duke@0 619 assert (is_gc_marked(), "should be marked");
coleenp@3602 620 klass()->oop_follow_contents(this);
duke@0 621 }
duke@0 622
duke@0 623 // Used by scavengers
duke@0 624
duke@0 625 inline bool oopDesc::is_forwarded() const {
duke@0 626 // The extra heap check is needed since the obj might be locked, in which case the
duke@0 627 // mark would point to a stack location and have the sentinel bit cleared
duke@0 628 return mark()->is_marked();
duke@0 629 }
duke@0 630
duke@0 631 // Used by scavengers
duke@0 632 inline void oopDesc::forward_to(oop p) {
kvn@1491 633 assert(check_obj_alignment(p),
kvn@1491 634 "forwarding to something not aligned");
duke@0 635 assert(Universe::heap()->is_in_reserved(p),
duke@0 636 "forwarding to something not in heap");
duke@0 637 markOop m = markOopDesc::encode_pointer_as_mark(p);
duke@0 638 assert(m->decode_pointer() == p, "encoding must be reversable");
duke@0 639 set_mark(m);
duke@0 640 }
duke@0 641
duke@0 642 // Used by parallel scavengers
duke@0 643 inline bool oopDesc::cas_forward_to(oop p, markOop compare) {
kvn@1491 644 assert(check_obj_alignment(p),
kvn@1491 645 "forwarding to something not aligned");
duke@0 646 assert(Universe::heap()->is_in_reserved(p),
duke@0 647 "forwarding to something not in heap");
duke@0 648 markOop m = markOopDesc::encode_pointer_as_mark(p);
duke@0 649 assert(m->decode_pointer() == p, "encoding must be reversable");
duke@0 650 return cas_set_mark(m, compare) == compare;
duke@0 651 }
duke@0 652
duke@0 653 // Note that the forwardee is not the same thing as the displaced_mark.
duke@0 654 // The forwardee is used when copying during scavenge and mark-sweep.
duke@0 655 // It does need to clear the low two locking- and GC-related bits.
coleenp@113 656 inline oop oopDesc::forwardee() const {
coleenp@113 657 return (oop) mark()->decode_pointer();
coleenp@113 658 }
duke@0 659
duke@0 660 inline bool oopDesc::has_displaced_mark() const {
duke@0 661 return mark()->has_displaced_mark_helper();
duke@0 662 }
duke@0 663
duke@0 664 inline markOop oopDesc::displaced_mark() const {
duke@0 665 return mark()->displaced_mark_helper();
duke@0 666 }
duke@0 667
duke@0 668 inline void oopDesc::set_displaced_mark(markOop m) {
duke@0 669 mark()->set_displaced_mark_helper(m);
duke@0 670 }
duke@0 671
duke@0 672 // The following method needs to be MT safe.
jwilhelm@3694 673 inline uint oopDesc::age() const {
duke@0 674 assert(!is_forwarded(), "Attempt to read age from forwarded mark");
duke@0 675 if (has_displaced_mark()) {
duke@0 676 return displaced_mark()->age();
duke@0 677 } else {
duke@0 678 return mark()->age();
duke@0 679 }
duke@0 680 }
duke@0 681
duke@0 682 inline void oopDesc::incr_age() {
duke@0 683 assert(!is_forwarded(), "Attempt to increment age of forwarded mark");
duke@0 684 if (has_displaced_mark()) {
duke@0 685 set_displaced_mark(displaced_mark()->incr_age());
duke@0 686 } else {
duke@0 687 set_mark(mark()->incr_age());
duke@0 688 }
duke@0 689 }
duke@0 690
duke@0 691
duke@0 692 inline intptr_t oopDesc::identity_hash() {
duke@0 693 // Fast case; if the object is unlocked and the hash value is set, no locking is needed
duke@0 694 // Note: The mark must be read into local variable to avoid concurrent updates.
duke@0 695 markOop mrk = mark();
duke@0 696 if (mrk->is_unlocked() && !mrk->has_no_hash()) {
duke@0 697 return mrk->hash();
duke@0 698 } else if (mrk->is_marked()) {
duke@0 699 return mrk->hash();
duke@0 700 } else {
duke@0 701 return slow_identity_hash();
duke@0 702 }
duke@0 703 }
duke@0 704
duke@0 705 inline int oopDesc::adjust_pointers() {
duke@0 706 debug_only(int check_size = size());
coleenp@3602 707 int s = klass()->oop_adjust_pointers(this);
duke@0 708 assert(s == check_size, "should be the same");
duke@0 709 return s;
duke@0 710 }
duke@0 711
duke@0 712 #define OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \
duke@0 713 \
duke@0 714 inline int oopDesc::oop_iterate(OopClosureType* blk) { \
duke@0 715 SpecializationStats::record_call(); \
coleenp@3602 716 return klass()->oop_oop_iterate##nv_suffix(this, blk); \
duke@0 717 } \
duke@0 718 \
duke@0 719 inline int oopDesc::oop_iterate(OopClosureType* blk, MemRegion mr) { \
duke@0 720 SpecializationStats::record_call(); \
coleenp@3602 721 return klass()->oop_oop_iterate##nv_suffix##_m(this, blk, mr); \
coleenp@3602 722 }
coleenp@3602 723
coleenp@3602 724
coleenp@3602 725 inline int oopDesc::oop_iterate_no_header(OopClosure* blk) {
coleenp@3602 726 // The NoHeaderExtendedOopClosure wraps the OopClosure and proxies all
coleenp@3602 727 // the do_oop calls, but turns off all other features in ExtendedOopClosure.
coleenp@3602 728 NoHeaderExtendedOopClosure cl(blk);
coleenp@3602 729 return oop_iterate(&cl);
coleenp@3602 730 }
coleenp@3602 731
coleenp@3602 732 inline int oopDesc::oop_iterate_no_header(OopClosure* blk, MemRegion mr) {
coleenp@3602 733 NoHeaderExtendedOopClosure cl(blk);
coleenp@3602 734 return oop_iterate(&cl, mr);
duke@0 735 }
duke@0 736
duke@0 737 ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_ITERATE_DEFN)
ysr@342 738 ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_ITERATE_DEFN)
duke@0 739
jprovino@4107 740 #if INCLUDE_ALL_GCS
ysr@342 741 #define OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \
ysr@342 742 \
ysr@342 743 inline int oopDesc::oop_iterate_backwards(OopClosureType* blk) { \
ysr@342 744 SpecializationStats::record_call(); \
coleenp@3602 745 return klass()->oop_oop_iterate_backwards##nv_suffix(this, blk); \
ysr@342 746 }
ysr@342 747
ysr@342 748 ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_ITERATE_BACKWARDS_DEFN)
ysr@342 749 ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_ITERATE_BACKWARDS_DEFN)
jprovino@4107 750 #endif // INCLUDE_ALL_GCS
duke@0 751
stefank@1879 752 #endif // SHARE_VM_OOPS_OOP_INLINE_HPP