1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/oops/oop.inline.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,747 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_OOPS_OOP_INLINE_HPP 1.29 +#define SHARE_VM_OOPS_OOP_INLINE_HPP 1.30 + 1.31 +#include "gc_implementation/shared/ageTable.hpp" 1.32 +#include "gc_implementation/shared/markSweep.inline.hpp" 1.33 +#include "gc_interface/collectedHeap.inline.hpp" 1.34 +#include "memory/barrierSet.inline.hpp" 1.35 +#include "memory/cardTableModRefBS.hpp" 1.36 +#include "memory/genCollectedHeap.hpp" 1.37 +#include "memory/generation.hpp" 1.38 +#include "memory/specialized_oop_closures.hpp" 1.39 +#include "oops/arrayKlass.hpp" 1.40 +#include "oops/arrayOop.hpp" 1.41 +#include "oops/klass.inline.hpp" 1.42 +#include "oops/markOop.inline.hpp" 1.43 +#include "oops/oop.hpp" 1.44 +#include "runtime/atomic.hpp" 1.45 +#include "runtime/os.hpp" 1.46 +#include "utilities/macros.hpp" 1.47 +#ifdef TARGET_ARCH_x86 1.48 +# include "bytes_x86.hpp" 1.49 +#endif 1.50 +#ifdef TARGET_ARCH_sparc 1.51 +# include "bytes_sparc.hpp" 1.52 +#endif 1.53 +#ifdef TARGET_ARCH_zero 1.54 +# include "bytes_zero.hpp" 1.55 +#endif 1.56 +#ifdef TARGET_ARCH_arm 1.57 +# include "bytes_arm.hpp" 1.58 +#endif 1.59 +#ifdef TARGET_ARCH_ppc 1.60 +# include "bytes_ppc.hpp" 1.61 +#endif 1.62 + 1.63 +// Implementation of all inlined member functions defined in oop.hpp 1.64 +// We need a separate file to avoid circular references 1.65 + 1.66 +inline void oopDesc::release_set_mark(markOop m) { 1.67 + OrderAccess::release_store_ptr(&_mark, m); 1.68 +} 1.69 + 1.70 +inline markOop oopDesc::cas_set_mark(markOop new_mark, markOop old_mark) { 1.71 + return (markOop) Atomic::cmpxchg_ptr(new_mark, &_mark, old_mark); 1.72 +} 1.73 + 1.74 +inline Klass* oopDesc::klass() const { 1.75 + if (UseCompressedClassPointers) { 1.76 + return Klass::decode_klass_not_null(_metadata._compressed_klass); 1.77 + } else { 1.78 + return _metadata._klass; 1.79 + } 1.80 +} 1.81 + 1.82 +inline Klass* oopDesc::klass_or_null() const volatile { 1.83 + // can be NULL in CMS 1.84 + if (UseCompressedClassPointers) { 1.85 + return Klass::decode_klass(_metadata._compressed_klass); 1.86 + } else { 1.87 + return _metadata._klass; 1.88 + } 1.89 +} 1.90 + 1.91 +inline int oopDesc::klass_gap_offset_in_bytes() { 1.92 + assert(UseCompressedClassPointers, "only applicable to compressed klass pointers"); 1.93 + return oopDesc::klass_offset_in_bytes() + sizeof(narrowKlass); 1.94 +} 1.95 + 1.96 +inline Klass** oopDesc::klass_addr() { 1.97 + // Only used internally and with CMS and will not work with 1.98 + // UseCompressedOops 1.99 + assert(!UseCompressedClassPointers, "only supported with uncompressed klass pointers"); 1.100 + return (Klass**) &_metadata._klass; 1.101 +} 1.102 + 1.103 +inline narrowKlass* oopDesc::compressed_klass_addr() { 1.104 + assert(UseCompressedClassPointers, "only called by compressed klass pointers"); 1.105 + return &_metadata._compressed_klass; 1.106 +} 1.107 + 1.108 +inline void oopDesc::set_klass(Klass* k) { 1.109 + // since klasses are promoted no store check is needed 1.110 + assert(Universe::is_bootstrapping() || k != NULL, "must be a real Klass*"); 1.111 + assert(Universe::is_bootstrapping() || k->is_klass(), "not a Klass*"); 1.112 + if (UseCompressedClassPointers) { 1.113 + *compressed_klass_addr() = Klass::encode_klass_not_null(k); 1.114 + } else { 1.115 + *klass_addr() = k; 1.116 + } 1.117 +} 1.118 + 1.119 +inline int oopDesc::klass_gap() const { 1.120 + return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes()); 1.121 +} 1.122 + 1.123 +inline void oopDesc::set_klass_gap(int v) { 1.124 + if (UseCompressedClassPointers) { 1.125 + *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes()) = v; 1.126 + } 1.127 +} 1.128 + 1.129 +inline void oopDesc::set_klass_to_list_ptr(oop k) { 1.130 + // This is only to be used during GC, for from-space objects, so no 1.131 + // barrier is needed. 1.132 + if (UseCompressedClassPointers) { 1.133 + _metadata._compressed_klass = (narrowKlass)encode_heap_oop(k); // may be null (parnew overflow handling) 1.134 + } else { 1.135 + _metadata._klass = (Klass*)(address)k; 1.136 + } 1.137 +} 1.138 + 1.139 +inline oop oopDesc::list_ptr_from_klass() { 1.140 + // This is only to be used during GC, for from-space objects. 1.141 + if (UseCompressedClassPointers) { 1.142 + return decode_heap_oop((narrowOop)_metadata._compressed_klass); 1.143 + } else { 1.144 + // Special case for GC 1.145 + return (oop)(address)_metadata._klass; 1.146 + } 1.147 +} 1.148 + 1.149 +inline void oopDesc::init_mark() { set_mark(markOopDesc::prototype_for_object(this)); } 1.150 + 1.151 +inline bool oopDesc::is_a(Klass* k) const { return klass()->is_subtype_of(k); } 1.152 + 1.153 +inline bool oopDesc::is_instance() const { return klass()->oop_is_instance(); } 1.154 +inline bool oopDesc::is_instanceMirror() const { return klass()->oop_is_instanceMirror(); } 1.155 +inline bool oopDesc::is_instanceRef() const { return klass()->oop_is_instanceRef(); } 1.156 +inline bool oopDesc::is_array() const { return klass()->oop_is_array(); } 1.157 +inline bool oopDesc::is_objArray() const { return klass()->oop_is_objArray(); } 1.158 +inline bool oopDesc::is_typeArray() const { return klass()->oop_is_typeArray(); } 1.159 + 1.160 +inline void* oopDesc::field_base(int offset) const { return (void*)&((char*)this)[offset]; } 1.161 + 1.162 +template <class T> inline T* oopDesc::obj_field_addr(int offset) const { return (T*)field_base(offset); } 1.163 +inline Metadata** oopDesc::metadata_field_addr(int offset) const { return (Metadata**)field_base(offset); } 1.164 +inline jbyte* oopDesc::byte_field_addr(int offset) const { return (jbyte*) field_base(offset); } 1.165 +inline jchar* oopDesc::char_field_addr(int offset) const { return (jchar*) field_base(offset); } 1.166 +inline jboolean* oopDesc::bool_field_addr(int offset) const { return (jboolean*)field_base(offset); } 1.167 +inline jint* oopDesc::int_field_addr(int offset) const { return (jint*) field_base(offset); } 1.168 +inline jshort* oopDesc::short_field_addr(int offset) const { return (jshort*) field_base(offset); } 1.169 +inline jlong* oopDesc::long_field_addr(int offset) const { return (jlong*) field_base(offset); } 1.170 +inline jfloat* oopDesc::float_field_addr(int offset) const { return (jfloat*) field_base(offset); } 1.171 +inline jdouble* oopDesc::double_field_addr(int offset) const { return (jdouble*) field_base(offset); } 1.172 +inline address* oopDesc::address_field_addr(int offset) const { return (address*) field_base(offset); } 1.173 + 1.174 + 1.175 +// Functions for getting and setting oops within instance objects. 1.176 +// If the oops are compressed, the type passed to these overloaded functions 1.177 +// is narrowOop. All functions are overloaded so they can be called by 1.178 +// template functions without conditionals (the compiler instantiates via 1.179 +// the right type and inlines the appopriate code). 1.180 + 1.181 +inline bool oopDesc::is_null(oop obj) { return obj == NULL; } 1.182 +inline bool oopDesc::is_null(narrowOop obj) { return obj == 0; } 1.183 + 1.184 +// Algorithm for encoding and decoding oops from 64 bit pointers to 32 bit 1.185 +// offset from the heap base. Saving the check for null can save instructions 1.186 +// in inner GC loops so these are separated. 1.187 + 1.188 +inline bool check_obj_alignment(oop obj) { 1.189 + return cast_from_oop<intptr_t>(obj) % MinObjAlignmentInBytes == 0; 1.190 +} 1.191 + 1.192 +inline narrowOop oopDesc::encode_heap_oop_not_null(oop v) { 1.193 + assert(!is_null(v), "oop value can never be zero"); 1.194 + assert(check_obj_alignment(v), "Address not aligned"); 1.195 + assert(Universe::heap()->is_in_reserved(v), "Address not in heap"); 1.196 + address base = Universe::narrow_oop_base(); 1.197 + int shift = Universe::narrow_oop_shift(); 1.198 + uint64_t pd = (uint64_t)(pointer_delta((void*)v, (void*)base, 1)); 1.199 + assert(OopEncodingHeapMax > pd, "change encoding max if new encoding"); 1.200 + uint64_t result = pd >> shift; 1.201 + assert((result & CONST64(0xffffffff00000000)) == 0, "narrow oop overflow"); 1.202 + assert(decode_heap_oop(result) == v, "reversibility"); 1.203 + return (narrowOop)result; 1.204 +} 1.205 + 1.206 +inline narrowOop oopDesc::encode_heap_oop(oop v) { 1.207 + return (is_null(v)) ? (narrowOop)0 : encode_heap_oop_not_null(v); 1.208 +} 1.209 + 1.210 +inline oop oopDesc::decode_heap_oop_not_null(narrowOop v) { 1.211 + assert(!is_null(v), "narrow oop value can never be zero"); 1.212 + address base = Universe::narrow_oop_base(); 1.213 + int shift = Universe::narrow_oop_shift(); 1.214 + oop result = (oop)(void*)((uintptr_t)base + ((uintptr_t)v << shift)); 1.215 + assert(check_obj_alignment(result), err_msg("address not aligned: " INTPTR_FORMAT, p2i((void*) result))); 1.216 + return result; 1.217 +} 1.218 + 1.219 +inline oop oopDesc::decode_heap_oop(narrowOop v) { 1.220 + return is_null(v) ? (oop)NULL : decode_heap_oop_not_null(v); 1.221 +} 1.222 + 1.223 +inline oop oopDesc::decode_heap_oop_not_null(oop v) { return v; } 1.224 +inline oop oopDesc::decode_heap_oop(oop v) { return v; } 1.225 + 1.226 +// Load an oop out of the Java heap as is without decoding. 1.227 +// Called by GC to check for null before decoding. 1.228 +inline oop oopDesc::load_heap_oop(oop* p) { return *p; } 1.229 +inline narrowOop oopDesc::load_heap_oop(narrowOop* p) { return *p; } 1.230 + 1.231 +// Load and decode an oop out of the Java heap into a wide oop. 1.232 +inline oop oopDesc::load_decode_heap_oop_not_null(oop* p) { return *p; } 1.233 +inline oop oopDesc::load_decode_heap_oop_not_null(narrowOop* p) { 1.234 + return decode_heap_oop_not_null(*p); 1.235 +} 1.236 + 1.237 +// Load and decode an oop out of the heap accepting null 1.238 +inline oop oopDesc::load_decode_heap_oop(oop* p) { return *p; } 1.239 +inline oop oopDesc::load_decode_heap_oop(narrowOop* p) { 1.240 + return decode_heap_oop(*p); 1.241 +} 1.242 + 1.243 +// Store already encoded heap oop into the heap. 1.244 +inline void oopDesc::store_heap_oop(oop* p, oop v) { *p = v; } 1.245 +inline void oopDesc::store_heap_oop(narrowOop* p, narrowOop v) { *p = v; } 1.246 + 1.247 +// Encode and store a heap oop. 1.248 +inline void oopDesc::encode_store_heap_oop_not_null(narrowOop* p, oop v) { 1.249 + *p = encode_heap_oop_not_null(v); 1.250 +} 1.251 +inline void oopDesc::encode_store_heap_oop_not_null(oop* p, oop v) { *p = v; } 1.252 + 1.253 +// Encode and store a heap oop allowing for null. 1.254 +inline void oopDesc::encode_store_heap_oop(narrowOop* p, oop v) { 1.255 + *p = encode_heap_oop(v); 1.256 +} 1.257 +inline void oopDesc::encode_store_heap_oop(oop* p, oop v) { *p = v; } 1.258 + 1.259 +// Store heap oop as is for volatile fields. 1.260 +inline void oopDesc::release_store_heap_oop(volatile oop* p, oop v) { 1.261 + OrderAccess::release_store_ptr(p, v); 1.262 +} 1.263 +inline void oopDesc::release_store_heap_oop(volatile narrowOop* p, 1.264 + narrowOop v) { 1.265 + OrderAccess::release_store(p, v); 1.266 +} 1.267 + 1.268 +inline void oopDesc::release_encode_store_heap_oop_not_null( 1.269 + volatile narrowOop* p, oop v) { 1.270 + // heap oop is not pointer sized. 1.271 + OrderAccess::release_store(p, encode_heap_oop_not_null(v)); 1.272 +} 1.273 + 1.274 +inline void oopDesc::release_encode_store_heap_oop_not_null( 1.275 + volatile oop* p, oop v) { 1.276 + OrderAccess::release_store_ptr(p, v); 1.277 +} 1.278 + 1.279 +inline void oopDesc::release_encode_store_heap_oop(volatile oop* p, 1.280 + oop v) { 1.281 + OrderAccess::release_store_ptr(p, v); 1.282 +} 1.283 +inline void oopDesc::release_encode_store_heap_oop( 1.284 + volatile narrowOop* p, oop v) { 1.285 + OrderAccess::release_store(p, encode_heap_oop(v)); 1.286 +} 1.287 + 1.288 + 1.289 +// These functions are only used to exchange oop fields in instances, 1.290 +// not headers. 1.291 +inline oop oopDesc::atomic_exchange_oop(oop exchange_value, volatile HeapWord *dest) { 1.292 + if (UseCompressedOops) { 1.293 + // encode exchange value from oop to T 1.294 + narrowOop val = encode_heap_oop(exchange_value); 1.295 + narrowOop old = (narrowOop)Atomic::xchg(val, (narrowOop*)dest); 1.296 + // decode old from T to oop 1.297 + return decode_heap_oop(old); 1.298 + } else { 1.299 + return (oop)Atomic::xchg_ptr(exchange_value, (oop*)dest); 1.300 + } 1.301 +} 1.302 + 1.303 +// In order to put or get a field out of an instance, must first check 1.304 +// if the field has been compressed and uncompress it. 1.305 +inline oop oopDesc::obj_field(int offset) const { 1.306 + return UseCompressedOops ? 1.307 + load_decode_heap_oop(obj_field_addr<narrowOop>(offset)) : 1.308 + load_decode_heap_oop(obj_field_addr<oop>(offset)); 1.309 +} 1.310 +inline volatile oop oopDesc::obj_field_volatile(int offset) const { 1.311 + volatile oop value = obj_field(offset); 1.312 + OrderAccess::acquire(); 1.313 + return value; 1.314 +} 1.315 +inline void oopDesc::obj_field_put(int offset, oop value) { 1.316 + UseCompressedOops ? oop_store(obj_field_addr<narrowOop>(offset), value) : 1.317 + oop_store(obj_field_addr<oop>(offset), value); 1.318 +} 1.319 + 1.320 +inline Metadata* oopDesc::metadata_field(int offset) const { 1.321 + return *metadata_field_addr(offset); 1.322 +} 1.323 + 1.324 +inline void oopDesc::metadata_field_put(int offset, Metadata* value) { 1.325 + *metadata_field_addr(offset) = value; 1.326 +} 1.327 + 1.328 +inline void oopDesc::obj_field_put_raw(int offset, oop value) { 1.329 + UseCompressedOops ? 1.330 + encode_store_heap_oop(obj_field_addr<narrowOop>(offset), value) : 1.331 + encode_store_heap_oop(obj_field_addr<oop>(offset), value); 1.332 +} 1.333 +inline void oopDesc::obj_field_put_volatile(int offset, oop value) { 1.334 + OrderAccess::release(); 1.335 + obj_field_put(offset, value); 1.336 + OrderAccess::fence(); 1.337 +} 1.338 + 1.339 +inline jbyte oopDesc::byte_field(int offset) const { return (jbyte) *byte_field_addr(offset); } 1.340 +inline void oopDesc::byte_field_put(int offset, jbyte contents) { *byte_field_addr(offset) = (jint) contents; } 1.341 + 1.342 +inline jboolean oopDesc::bool_field(int offset) const { return (jboolean) *bool_field_addr(offset); } 1.343 +inline void oopDesc::bool_field_put(int offset, jboolean contents) { *bool_field_addr(offset) = (jint) contents; } 1.344 + 1.345 +inline jchar oopDesc::char_field(int offset) const { return (jchar) *char_field_addr(offset); } 1.346 +inline void oopDesc::char_field_put(int offset, jchar contents) { *char_field_addr(offset) = (jint) contents; } 1.347 + 1.348 +inline jint oopDesc::int_field(int offset) const { return *int_field_addr(offset); } 1.349 +inline void oopDesc::int_field_put(int offset, jint contents) { *int_field_addr(offset) = contents; } 1.350 + 1.351 +inline jshort oopDesc::short_field(int offset) const { return (jshort) *short_field_addr(offset); } 1.352 +inline void oopDesc::short_field_put(int offset, jshort contents) { *short_field_addr(offset) = (jint) contents;} 1.353 + 1.354 +inline jlong oopDesc::long_field(int offset) const { return *long_field_addr(offset); } 1.355 +inline void oopDesc::long_field_put(int offset, jlong contents) { *long_field_addr(offset) = contents; } 1.356 + 1.357 +inline jfloat oopDesc::float_field(int offset) const { return *float_field_addr(offset); } 1.358 +inline void oopDesc::float_field_put(int offset, jfloat contents) { *float_field_addr(offset) = contents; } 1.359 + 1.360 +inline jdouble oopDesc::double_field(int offset) const { return *double_field_addr(offset); } 1.361 +inline void oopDesc::double_field_put(int offset, jdouble contents) { *double_field_addr(offset) = contents; } 1.362 + 1.363 +inline address oopDesc::address_field(int offset) const { return *address_field_addr(offset); } 1.364 +inline void oopDesc::address_field_put(int offset, address contents) { *address_field_addr(offset) = contents; } 1.365 + 1.366 +inline oop oopDesc::obj_field_acquire(int offset) const { 1.367 + return UseCompressedOops ? 1.368 + decode_heap_oop((narrowOop) 1.369 + OrderAccess::load_acquire(obj_field_addr<narrowOop>(offset))) 1.370 + : decode_heap_oop((oop) 1.371 + OrderAccess::load_ptr_acquire(obj_field_addr<oop>(offset))); 1.372 +} 1.373 +inline void oopDesc::release_obj_field_put(int offset, oop value) { 1.374 + UseCompressedOops ? 1.375 + oop_store((volatile narrowOop*)obj_field_addr<narrowOop>(offset), value) : 1.376 + oop_store((volatile oop*) obj_field_addr<oop>(offset), value); 1.377 +} 1.378 + 1.379 +inline jbyte oopDesc::byte_field_acquire(int offset) const { return OrderAccess::load_acquire(byte_field_addr(offset)); } 1.380 +inline void oopDesc::release_byte_field_put(int offset, jbyte contents) { OrderAccess::release_store(byte_field_addr(offset), contents); } 1.381 + 1.382 +inline jboolean oopDesc::bool_field_acquire(int offset) const { return OrderAccess::load_acquire(bool_field_addr(offset)); } 1.383 +inline void oopDesc::release_bool_field_put(int offset, jboolean contents) { OrderAccess::release_store(bool_field_addr(offset), contents); } 1.384 + 1.385 +inline jchar oopDesc::char_field_acquire(int offset) const { return OrderAccess::load_acquire(char_field_addr(offset)); } 1.386 +inline void oopDesc::release_char_field_put(int offset, jchar contents) { OrderAccess::release_store(char_field_addr(offset), contents); } 1.387 + 1.388 +inline jint oopDesc::int_field_acquire(int offset) const { return OrderAccess::load_acquire(int_field_addr(offset)); } 1.389 +inline void oopDesc::release_int_field_put(int offset, jint contents) { OrderAccess::release_store(int_field_addr(offset), contents); } 1.390 + 1.391 +inline jshort oopDesc::short_field_acquire(int offset) const { return (jshort)OrderAccess::load_acquire(short_field_addr(offset)); } 1.392 +inline void oopDesc::release_short_field_put(int offset, jshort contents) { OrderAccess::release_store(short_field_addr(offset), contents); } 1.393 + 1.394 +inline jlong oopDesc::long_field_acquire(int offset) const { return OrderAccess::load_acquire(long_field_addr(offset)); } 1.395 +inline void oopDesc::release_long_field_put(int offset, jlong contents) { OrderAccess::release_store(long_field_addr(offset), contents); } 1.396 + 1.397 +inline jfloat oopDesc::float_field_acquire(int offset) const { return OrderAccess::load_acquire(float_field_addr(offset)); } 1.398 +inline void oopDesc::release_float_field_put(int offset, jfloat contents) { OrderAccess::release_store(float_field_addr(offset), contents); } 1.399 + 1.400 +inline jdouble oopDesc::double_field_acquire(int offset) const { return OrderAccess::load_acquire(double_field_addr(offset)); } 1.401 +inline void oopDesc::release_double_field_put(int offset, jdouble contents) { OrderAccess::release_store(double_field_addr(offset), contents); } 1.402 + 1.403 +inline address oopDesc::address_field_acquire(int offset) const { return (address) OrderAccess::load_ptr_acquire(address_field_addr(offset)); } 1.404 +inline void oopDesc::release_address_field_put(int offset, address contents) { OrderAccess::release_store_ptr(address_field_addr(offset), contents); } 1.405 + 1.406 +inline int oopDesc::size_given_klass(Klass* klass) { 1.407 + int lh = klass->layout_helper(); 1.408 + int s; 1.409 + 1.410 + // lh is now a value computed at class initialization that may hint 1.411 + // at the size. For instances, this is positive and equal to the 1.412 + // size. For arrays, this is negative and provides log2 of the 1.413 + // array element size. For other oops, it is zero and thus requires 1.414 + // a virtual call. 1.415 + // 1.416 + // We go to all this trouble because the size computation is at the 1.417 + // heart of phase 2 of mark-compaction, and called for every object, 1.418 + // alive or dead. So the speed here is equal in importance to the 1.419 + // speed of allocation. 1.420 + 1.421 + if (lh > Klass::_lh_neutral_value) { 1.422 + if (!Klass::layout_helper_needs_slow_path(lh)) { 1.423 + s = lh >> LogHeapWordSize; // deliver size scaled by wordSize 1.424 + } else { 1.425 + s = klass->oop_size(this); 1.426 + } 1.427 + } else if (lh <= Klass::_lh_neutral_value) { 1.428 + // The most common case is instances; fall through if so. 1.429 + if (lh < Klass::_lh_neutral_value) { 1.430 + // Second most common case is arrays. We have to fetch the 1.431 + // length of the array, shift (multiply) it appropriately, 1.432 + // up to wordSize, add the header, and align to object size. 1.433 + size_t size_in_bytes; 1.434 +#ifdef _M_IA64 1.435 + // The Windows Itanium Aug 2002 SDK hoists this load above 1.436 + // the check for s < 0. An oop at the end of the heap will 1.437 + // cause an access violation if this load is performed on a non 1.438 + // array oop. Making the reference volatile prohibits this. 1.439 + // (%%% please explain by what magic the length is actually fetched!) 1.440 + volatile int *array_length; 1.441 + array_length = (volatile int *)( (intptr_t)this + 1.442 + arrayOopDesc::length_offset_in_bytes() ); 1.443 + assert(array_length > 0, "Integer arithmetic problem somewhere"); 1.444 + // Put into size_t to avoid overflow. 1.445 + size_in_bytes = (size_t) array_length; 1.446 + size_in_bytes = size_in_bytes << Klass::layout_helper_log2_element_size(lh); 1.447 +#else 1.448 + size_t array_length = (size_t) ((arrayOop)this)->length(); 1.449 + size_in_bytes = array_length << Klass::layout_helper_log2_element_size(lh); 1.450 +#endif 1.451 + size_in_bytes += Klass::layout_helper_header_size(lh); 1.452 + 1.453 + // This code could be simplified, but by keeping array_header_in_bytes 1.454 + // in units of bytes and doing it this way we can round up just once, 1.455 + // skipping the intermediate round to HeapWordSize. Cast the result 1.456 + // of round_to to size_t to guarantee unsigned division == right shift. 1.457 + s = (int)((size_t)round_to(size_in_bytes, MinObjAlignmentInBytes) / 1.458 + HeapWordSize); 1.459 + 1.460 + // UseParNewGC, UseParallelGC and UseG1GC can change the length field 1.461 + // of an "old copy" of an object array in the young gen so it indicates 1.462 + // the grey portion of an already copied array. This will cause the first 1.463 + // disjunct below to fail if the two comparands are computed across such 1.464 + // a concurrent change. 1.465 + // UseParNewGC also runs with promotion labs (which look like int 1.466 + // filler arrays) which are subject to changing their declared size 1.467 + // when finally retiring a PLAB; this also can cause the first disjunct 1.468 + // to fail for another worker thread that is concurrently walking the block 1.469 + // offset table. Both these invariant failures are benign for their 1.470 + // current uses; we relax the assertion checking to cover these two cases below: 1.471 + // is_objArray() && is_forwarded() // covers first scenario above 1.472 + // || is_typeArray() // covers second scenario above 1.473 + // If and when UseParallelGC uses the same obj array oop stealing/chunking 1.474 + // technique, we will need to suitably modify the assertion. 1.475 + assert((s == klass->oop_size(this)) || 1.476 + (Universe::heap()->is_gc_active() && 1.477 + ((is_typeArray() && UseParNewGC) || 1.478 + (is_objArray() && is_forwarded() && (UseParNewGC || UseParallelGC || UseG1GC)))), 1.479 + "wrong array object size"); 1.480 + } else { 1.481 + // Must be zero, so bite the bullet and take the virtual call. 1.482 + s = klass->oop_size(this); 1.483 + } 1.484 + } 1.485 + 1.486 + assert(s % MinObjAlignment == 0, "alignment check"); 1.487 + assert(s > 0, "Bad size calculated"); 1.488 + return s; 1.489 +} 1.490 + 1.491 + 1.492 +inline int oopDesc::size() { 1.493 + return size_given_klass(klass()); 1.494 +} 1.495 + 1.496 +inline void update_barrier_set(void* p, oop v, bool release = false) { 1.497 + assert(oopDesc::bs() != NULL, "Uninitialized bs in oop!"); 1.498 + oopDesc::bs()->write_ref_field(p, v, release); 1.499 +} 1.500 + 1.501 +template <class T> inline void update_barrier_set_pre(T* p, oop v) { 1.502 + oopDesc::bs()->write_ref_field_pre(p, v); 1.503 +} 1.504 + 1.505 +template <class T> inline void oop_store(T* p, oop v) { 1.506 + if (always_do_update_barrier) { 1.507 + oop_store((volatile T*)p, v); 1.508 + } else { 1.509 + update_barrier_set_pre(p, v); 1.510 + oopDesc::encode_store_heap_oop(p, v); 1.511 + // always_do_update_barrier == false => 1.512 + // Either we are at a safepoint (in GC) or CMS is not used. In both 1.513 + // cases it's unnecessary to mark the card as dirty with release sematics. 1.514 + update_barrier_set((void*)p, v, false /* release */); // cast away type 1.515 + } 1.516 +} 1.517 + 1.518 +template <class T> inline void oop_store(volatile T* p, oop v) { 1.519 + update_barrier_set_pre((T*)p, v); // cast away volatile 1.520 + // Used by release_obj_field_put, so use release_store_ptr. 1.521 + oopDesc::release_encode_store_heap_oop(p, v); 1.522 + // When using CMS we must mark the card corresponding to p as dirty 1.523 + // with release sematics to prevent that CMS sees the dirty card but 1.524 + // not the new value v at p due to reordering of the two 1.525 + // stores. Note that CMS has a concurrent precleaning phase, where 1.526 + // it reads the card table while the Java threads are running. 1.527 + update_barrier_set((void*)p, v, true /* release */); // cast away type 1.528 +} 1.529 + 1.530 +// Should replace *addr = oop assignments where addr type depends on UseCompressedOops 1.531 +// (without having to remember the function name this calls). 1.532 +inline void oop_store_raw(HeapWord* addr, oop value) { 1.533 + if (UseCompressedOops) { 1.534 + oopDesc::encode_store_heap_oop((narrowOop*)addr, value); 1.535 + } else { 1.536 + oopDesc::encode_store_heap_oop((oop*)addr, value); 1.537 + } 1.538 +} 1.539 + 1.540 +inline oop oopDesc::atomic_compare_exchange_oop(oop exchange_value, 1.541 + volatile HeapWord *dest, 1.542 + oop compare_value, 1.543 + bool prebarrier) { 1.544 + if (UseCompressedOops) { 1.545 + if (prebarrier) { 1.546 + update_barrier_set_pre((narrowOop*)dest, exchange_value); 1.547 + } 1.548 + // encode exchange and compare value from oop to T 1.549 + narrowOop val = encode_heap_oop(exchange_value); 1.550 + narrowOop cmp = encode_heap_oop(compare_value); 1.551 + 1.552 + narrowOop old = (narrowOop) Atomic::cmpxchg(val, (narrowOop*)dest, cmp); 1.553 + // decode old from T to oop 1.554 + return decode_heap_oop(old); 1.555 + } else { 1.556 + if (prebarrier) { 1.557 + update_barrier_set_pre((oop*)dest, exchange_value); 1.558 + } 1.559 + return (oop)Atomic::cmpxchg_ptr(exchange_value, (oop*)dest, compare_value); 1.560 + } 1.561 +} 1.562 + 1.563 +// Used only for markSweep, scavenging 1.564 +inline bool oopDesc::is_gc_marked() const { 1.565 + return mark()->is_marked(); 1.566 +} 1.567 + 1.568 +inline bool oopDesc::is_locked() const { 1.569 + return mark()->is_locked(); 1.570 +} 1.571 + 1.572 +inline bool oopDesc::is_unlocked() const { 1.573 + return mark()->is_unlocked(); 1.574 +} 1.575 + 1.576 +inline bool oopDesc::has_bias_pattern() const { 1.577 + return mark()->has_bias_pattern(); 1.578 +} 1.579 + 1.580 + 1.581 +// used only for asserts 1.582 +inline bool oopDesc::is_oop(bool ignore_mark_word) const { 1.583 + oop obj = (oop) this; 1.584 + if (!check_obj_alignment(obj)) return false; 1.585 + if (!Universe::heap()->is_in_reserved(obj)) return false; 1.586 + // obj is aligned and accessible in heap 1.587 + if (Universe::heap()->is_in_reserved(obj->klass_or_null())) return false; 1.588 + 1.589 + // Header verification: the mark is typically non-NULL. If we're 1.590 + // at a safepoint, it must not be null. 1.591 + // Outside of a safepoint, the header could be changing (for example, 1.592 + // another thread could be inflating a lock on this object). 1.593 + if (ignore_mark_word) { 1.594 + return true; 1.595 + } 1.596 + if (mark() != NULL) { 1.597 + return true; 1.598 + } 1.599 + return !SafepointSynchronize::is_at_safepoint(); 1.600 +} 1.601 + 1.602 + 1.603 +// used only for asserts 1.604 +inline bool oopDesc::is_oop_or_null(bool ignore_mark_word) const { 1.605 + return this == NULL ? true : is_oop(ignore_mark_word); 1.606 +} 1.607 + 1.608 +#ifndef PRODUCT 1.609 +// used only for asserts 1.610 +inline bool oopDesc::is_unlocked_oop() const { 1.611 + if (!Universe::heap()->is_in_reserved(this)) return false; 1.612 + return mark()->is_unlocked(); 1.613 +} 1.614 +#endif // PRODUCT 1.615 + 1.616 +inline void oopDesc::follow_contents(void) { 1.617 + assert (is_gc_marked(), "should be marked"); 1.618 + klass()->oop_follow_contents(this); 1.619 +} 1.620 + 1.621 +// Used by scavengers 1.622 + 1.623 +inline bool oopDesc::is_forwarded() const { 1.624 + // The extra heap check is needed since the obj might be locked, in which case the 1.625 + // mark would point to a stack location and have the sentinel bit cleared 1.626 + return mark()->is_marked(); 1.627 +} 1.628 + 1.629 +// Used by scavengers 1.630 +inline void oopDesc::forward_to(oop p) { 1.631 + assert(check_obj_alignment(p), 1.632 + "forwarding to something not aligned"); 1.633 + assert(Universe::heap()->is_in_reserved(p), 1.634 + "forwarding to something not in heap"); 1.635 + markOop m = markOopDesc::encode_pointer_as_mark(p); 1.636 + assert(m->decode_pointer() == p, "encoding must be reversable"); 1.637 + set_mark(m); 1.638 +} 1.639 + 1.640 +// Used by parallel scavengers 1.641 +inline bool oopDesc::cas_forward_to(oop p, markOop compare) { 1.642 + assert(check_obj_alignment(p), 1.643 + "forwarding to something not aligned"); 1.644 + assert(Universe::heap()->is_in_reserved(p), 1.645 + "forwarding to something not in heap"); 1.646 + markOop m = markOopDesc::encode_pointer_as_mark(p); 1.647 + assert(m->decode_pointer() == p, "encoding must be reversable"); 1.648 + return cas_set_mark(m, compare) == compare; 1.649 +} 1.650 + 1.651 +// Note that the forwardee is not the same thing as the displaced_mark. 1.652 +// The forwardee is used when copying during scavenge and mark-sweep. 1.653 +// It does need to clear the low two locking- and GC-related bits. 1.654 +inline oop oopDesc::forwardee() const { 1.655 + return (oop) mark()->decode_pointer(); 1.656 +} 1.657 + 1.658 +inline bool oopDesc::has_displaced_mark() const { 1.659 + return mark()->has_displaced_mark_helper(); 1.660 +} 1.661 + 1.662 +inline markOop oopDesc::displaced_mark() const { 1.663 + return mark()->displaced_mark_helper(); 1.664 +} 1.665 + 1.666 +inline void oopDesc::set_displaced_mark(markOop m) { 1.667 + mark()->set_displaced_mark_helper(m); 1.668 +} 1.669 + 1.670 +// The following method needs to be MT safe. 1.671 +inline uint oopDesc::age() const { 1.672 + assert(!is_forwarded(), "Attempt to read age from forwarded mark"); 1.673 + if (has_displaced_mark()) { 1.674 + return displaced_mark()->age(); 1.675 + } else { 1.676 + return mark()->age(); 1.677 + } 1.678 +} 1.679 + 1.680 +inline void oopDesc::incr_age() { 1.681 + assert(!is_forwarded(), "Attempt to increment age of forwarded mark"); 1.682 + if (has_displaced_mark()) { 1.683 + set_displaced_mark(displaced_mark()->incr_age()); 1.684 + } else { 1.685 + set_mark(mark()->incr_age()); 1.686 + } 1.687 +} 1.688 + 1.689 + 1.690 +inline intptr_t oopDesc::identity_hash() { 1.691 + // Fast case; if the object is unlocked and the hash value is set, no locking is needed 1.692 + // Note: The mark must be read into local variable to avoid concurrent updates. 1.693 + markOop mrk = mark(); 1.694 + if (mrk->is_unlocked() && !mrk->has_no_hash()) { 1.695 + return mrk->hash(); 1.696 + } else if (mrk->is_marked()) { 1.697 + return mrk->hash(); 1.698 + } else { 1.699 + return slow_identity_hash(); 1.700 + } 1.701 +} 1.702 + 1.703 +inline int oopDesc::adjust_pointers() { 1.704 + debug_only(int check_size = size()); 1.705 + int s = klass()->oop_adjust_pointers(this); 1.706 + assert(s == check_size, "should be the same"); 1.707 + return s; 1.708 +} 1.709 + 1.710 +#define OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ 1.711 + \ 1.712 +inline int oopDesc::oop_iterate(OopClosureType* blk) { \ 1.713 + SpecializationStats::record_call(); \ 1.714 + return klass()->oop_oop_iterate##nv_suffix(this, blk); \ 1.715 +} \ 1.716 + \ 1.717 +inline int oopDesc::oop_iterate(OopClosureType* blk, MemRegion mr) { \ 1.718 + SpecializationStats::record_call(); \ 1.719 + return klass()->oop_oop_iterate##nv_suffix##_m(this, blk, mr); \ 1.720 +} 1.721 + 1.722 + 1.723 +inline int oopDesc::oop_iterate_no_header(OopClosure* blk) { 1.724 + // The NoHeaderExtendedOopClosure wraps the OopClosure and proxies all 1.725 + // the do_oop calls, but turns off all other features in ExtendedOopClosure. 1.726 + NoHeaderExtendedOopClosure cl(blk); 1.727 + return oop_iterate(&cl); 1.728 +} 1.729 + 1.730 +inline int oopDesc::oop_iterate_no_header(OopClosure* blk, MemRegion mr) { 1.731 + NoHeaderExtendedOopClosure cl(blk); 1.732 + return oop_iterate(&cl, mr); 1.733 +} 1.734 + 1.735 +ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_ITERATE_DEFN) 1.736 +ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_ITERATE_DEFN) 1.737 + 1.738 +#if INCLUDE_ALL_GCS 1.739 +#define OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \ 1.740 + \ 1.741 +inline int oopDesc::oop_iterate_backwards(OopClosureType* blk) { \ 1.742 + SpecializationStats::record_call(); \ 1.743 + return klass()->oop_oop_iterate_backwards##nv_suffix(this, blk); \ 1.744 +} 1.745 + 1.746 +ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_ITERATE_BACKWARDS_DEFN) 1.747 +ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_ITERATE_BACKWARDS_DEFN) 1.748 +#endif // INCLUDE_ALL_GCS 1.749 + 1.750 +#endif // SHARE_VM_OOPS_OOP_INLINE_HPP