annotate src/share/vm/oops/oop.hpp @ 7745:6dc8db7164d2

Added tag jdk9-b49 for changeset 360cd1fc42f1
author katleman
date Thu, 05 Feb 2015 11:43:29 -0800
parents cd6b3f1a94ff
children 6a5be7f00868
rev   line source
duke@0 1 /*
minqi@5895 2 * Copyright (c) 1997, 2014, 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_HPP
stefank@1879 26 #define SHARE_VM_OOPS_OOP_HPP
stefank@1879 27
stefank@1879 28 #include "memory/iterator.hpp"
stefank@1879 29 #include "memory/memRegion.hpp"
stefank@1879 30 #include "memory/specialized_oop_closures.hpp"
coleenp@3602 31 #include "oops/metadata.hpp"
jprovino@4107 32 #include "utilities/macros.hpp"
stefank@1879 33 #include "utilities/top.hpp"
stefank@1879 34
duke@0 35 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
duke@0 36 // the format of Java objects so the fields can be accessed from C++.
duke@0 37 // oopDesc is abstract.
duke@0 38 // (see oopHierarchy for complete oop class hierarchy)
duke@0 39 //
duke@0 40 // no virtual functions allowed
duke@0 41
duke@0 42 // store into oop with store check
stefank@1879 43 template <class T> void oop_store(T* p, oop v);
stefank@1879 44 template <class T> void oop_store(volatile T* p, oop v);
duke@0 45
duke@0 46 extern bool always_do_update_barrier;
duke@0 47
duke@0 48 // Forward declarations.
duke@0 49 class OopClosure;
duke@0 50 class ScanClosure;
duke@0 51 class FastScanClosure;
duke@0 52 class FilteringClosure;
duke@0 53 class BarrierSet;
duke@0 54 class CMSIsAliveClosure;
duke@0 55
duke@0 56 class PSPromotionManager;
duke@0 57 class ParCompactionManager;
duke@0 58
duke@0 59 class oopDesc {
duke@0 60 friend class VMStructs;
duke@0 61 private:
duke@0 62 volatile markOop _mark;
coleenp@113 63 union _metadata {
coleenp@3602 64 Klass* _klass;
hseigel@5093 65 narrowKlass _compressed_klass;
coleenp@113 66 } _metadata;
duke@0 67
duke@0 68 // Fast access to barrier set. Must be initialized.
duke@0 69 static BarrierSet* _bs;
duke@0 70
duke@0 71 public:
duke@0 72 markOop mark() const { return _mark; }
duke@0 73 markOop* mark_addr() const { return (markOop*) &_mark; }
duke@0 74
duke@0 75 void set_mark(volatile markOop m) { _mark = m; }
duke@0 76
duke@0 77 void release_set_mark(markOop m);
duke@0 78 markOop cas_set_mark(markOop new_mark, markOop old_mark);
duke@0 79
duke@0 80 // Used only to re-initialize the mark word (e.g., of promoted
duke@0 81 // objects during a GC) -- requires a valid klass pointer
duke@0 82 void init_mark();
duke@0 83
coleenp@3602 84 Klass* klass() const;
coleenp@3602 85 Klass* klass_or_null() const volatile;
coleenp@3602 86 Klass** klass_addr();
hseigel@5093 87 narrowKlass* compressed_klass_addr();
duke@0 88
coleenp@3602 89 void set_klass(Klass* k);
coleenp@167 90
coleenp@167 91 // For klass field compression
coleenp@167 92 int klass_gap() const;
coleenp@167 93 void set_klass_gap(int z);
duke@0 94 // For when the klass pointer is being used as a linked list "next" field.
duke@0 95 void set_klass_to_list_ptr(oop k);
coleenp@3602 96 oop list_ptr_from_klass();
duke@0 97
coleenp@113 98 // size of object header, aligned to platform wordSize
coleenp@113 99 static int header_size() { return sizeof(oopDesc)/HeapWordSize; }
duke@0 100
duke@0 101 // Returns whether this is an instance of k or an instance of a subclass of k
coleenp@3602 102 bool is_a(Klass* k) const;
duke@0 103
duke@0 104 // Returns the actual oop size of the object
duke@0 105 int size();
duke@0 106
duke@0 107 // Sometimes (for complicated concurrency-related reasons), it is useful
duke@0 108 // to be able to figure out the size of an object knowing its klass.
duke@0 109 int size_given_klass(Klass* klass);
duke@0 110
duke@0 111 // type test operations (inlined in oop.inline.h)
stefank@6046 112 bool is_instance() const;
stefank@6046 113 bool is_instanceMirror() const;
stefank@6046 114 bool is_instanceClassLoader() const;
stefank@6046 115 bool is_instanceRef() const;
stefank@6046 116 bool is_array() const;
stefank@6046 117 bool is_objArray() const;
stefank@6046 118 bool is_typeArray() const;
duke@0 119
duke@0 120 private:
duke@0 121 // field addresses in oop
duke@0 122 void* field_base(int offset) const;
duke@0 123
duke@0 124 jbyte* byte_field_addr(int offset) const;
duke@0 125 jchar* char_field_addr(int offset) const;
duke@0 126 jboolean* bool_field_addr(int offset) const;
duke@0 127 jint* int_field_addr(int offset) const;
duke@0 128 jshort* short_field_addr(int offset) const;
duke@0 129 jlong* long_field_addr(int offset) const;
duke@0 130 jfloat* float_field_addr(int offset) const;
duke@0 131 jdouble* double_field_addr(int offset) const;
coleenp@3602 132 Metadata** metadata_field_addr(int offset) const;
duke@0 133
duke@0 134 public:
coleenp@113 135 // Need this as public for garbage collection.
coleenp@113 136 template <class T> T* obj_field_addr(int offset) const;
duke@0 137
coleenp@3602 138 // Needed for javaClasses
coleenp@3602 139 address* address_field_addr(int offset) const;
coleenp@3602 140
coleenp@113 141 static bool is_null(oop obj);
coleenp@113 142 static bool is_null(narrowOop obj);
coleenp@3602 143 static bool is_null(Klass* obj);
coleenp@113 144
coleenp@113 145 // Decode an oop pointer from a narrowOop if compressed.
coleenp@113 146 // These are overloaded for oop and narrowOop as are the other functions
coleenp@113 147 // below so that they can be called in template functions.
coleenp@113 148 static oop decode_heap_oop_not_null(oop v);
coleenp@113 149 static oop decode_heap_oop_not_null(narrowOop v);
coleenp@113 150 static oop decode_heap_oop(oop v);
coleenp@113 151 static oop decode_heap_oop(narrowOop v);
coleenp@113 152
coleenp@113 153 // Encode an oop pointer to a narrow oop. The or_null versions accept
coleenp@113 154 // null oop pointer, others do not in order to eliminate the
coleenp@113 155 // null checking branches.
coleenp@113 156 static narrowOop encode_heap_oop_not_null(oop v);
coleenp@113 157 static narrowOop encode_heap_oop(oop v);
coleenp@113 158
coleenp@113 159 // Load an oop out of the Java heap
coleenp@113 160 static narrowOop load_heap_oop(narrowOop* p);
coleenp@113 161 static oop load_heap_oop(oop* p);
coleenp@113 162
coleenp@113 163 // Load an oop out of Java heap and decode it to an uncompressed oop.
coleenp@113 164 static oop load_decode_heap_oop_not_null(narrowOop* p);
coleenp@113 165 static oop load_decode_heap_oop_not_null(oop* p);
coleenp@113 166 static oop load_decode_heap_oop(narrowOop* p);
coleenp@113 167 static oop load_decode_heap_oop(oop* p);
coleenp@113 168
coleenp@113 169 // Store an oop into the heap.
coleenp@113 170 static void store_heap_oop(narrowOop* p, narrowOop v);
coleenp@113 171 static void store_heap_oop(oop* p, oop v);
coleenp@113 172
coleenp@113 173 // Encode oop if UseCompressedOops and store into the heap.
coleenp@113 174 static void encode_store_heap_oop_not_null(narrowOop* p, oop v);
coleenp@113 175 static void encode_store_heap_oop_not_null(oop* p, oop v);
coleenp@113 176 static void encode_store_heap_oop(narrowOop* p, oop v);
coleenp@113 177 static void encode_store_heap_oop(oop* p, oop v);
coleenp@113 178
coleenp@113 179 static void release_store_heap_oop(volatile narrowOop* p, narrowOop v);
coleenp@113 180 static void release_store_heap_oop(volatile oop* p, oop v);
coleenp@113 181
coleenp@113 182 static void release_encode_store_heap_oop_not_null(volatile narrowOop* p, oop v);
coleenp@113 183 static void release_encode_store_heap_oop_not_null(volatile oop* p, oop v);
coleenp@113 184 static void release_encode_store_heap_oop(volatile narrowOop* p, oop v);
coleenp@113 185 static void release_encode_store_heap_oop(volatile oop* p, oop v);
coleenp@113 186
coleenp@113 187 static oop atomic_exchange_oop(oop exchange_value, volatile HeapWord *dest);
coleenp@113 188 static oop atomic_compare_exchange_oop(oop exchange_value,
coleenp@113 189 volatile HeapWord *dest,
coleenp@3602 190 oop compare_value,
coleenp@3602 191 bool prebarrier = false);
coleenp@3602 192
coleenp@113 193 // Access to fields in a instanceOop through these methods.
duke@0 194 oop obj_field(int offset) const;
twisti@2696 195 volatile oop obj_field_volatile(int offset) const;
duke@0 196 void obj_field_put(int offset, oop value);
twisti@2696 197 void obj_field_put_raw(int offset, oop value);
twisti@2696 198 void obj_field_put_volatile(int offset, oop value);
duke@0 199
coleenp@3602 200 Metadata* metadata_field(int offset) const;
coleenp@3602 201 void metadata_field_put(int offset, Metadata* value);
coleenp@3602 202
duke@0 203 jbyte byte_field(int offset) const;
duke@0 204 void byte_field_put(int offset, jbyte contents);
duke@0 205
duke@0 206 jchar char_field(int offset) const;
duke@0 207 void char_field_put(int offset, jchar contents);
duke@0 208
duke@0 209 jboolean bool_field(int offset) const;
duke@0 210 void bool_field_put(int offset, jboolean contents);
duke@0 211
duke@0 212 jint int_field(int offset) const;
duke@0 213 void int_field_put(int offset, jint contents);
duke@0 214
duke@0 215 jshort short_field(int offset) const;
duke@0 216 void short_field_put(int offset, jshort contents);
duke@0 217
duke@0 218 jlong long_field(int offset) const;
duke@0 219 void long_field_put(int offset, jlong contents);
duke@0 220
duke@0 221 jfloat float_field(int offset) const;
duke@0 222 void float_field_put(int offset, jfloat contents);
duke@0 223
duke@0 224 jdouble double_field(int offset) const;
duke@0 225 void double_field_put(int offset, jdouble contents);
duke@0 226
coleenp@113 227 address address_field(int offset) const;
coleenp@113 228 void address_field_put(int offset, address contents);
coleenp@113 229
duke@0 230 oop obj_field_acquire(int offset) const;
duke@0 231 void release_obj_field_put(int offset, oop value);
duke@0 232
duke@0 233 jbyte byte_field_acquire(int offset) const;
duke@0 234 void release_byte_field_put(int offset, jbyte contents);
duke@0 235
duke@0 236 jchar char_field_acquire(int offset) const;
duke@0 237 void release_char_field_put(int offset, jchar contents);
duke@0 238
duke@0 239 jboolean bool_field_acquire(int offset) const;
duke@0 240 void release_bool_field_put(int offset, jboolean contents);
duke@0 241
duke@0 242 jint int_field_acquire(int offset) const;
duke@0 243 void release_int_field_put(int offset, jint contents);
duke@0 244
duke@0 245 jshort short_field_acquire(int offset) const;
duke@0 246 void release_short_field_put(int offset, jshort contents);
duke@0 247
duke@0 248 jlong long_field_acquire(int offset) const;
duke@0 249 void release_long_field_put(int offset, jlong contents);
duke@0 250
duke@0 251 jfloat float_field_acquire(int offset) const;
duke@0 252 void release_float_field_put(int offset, jfloat contents);
duke@0 253
duke@0 254 jdouble double_field_acquire(int offset) const;
duke@0 255 void release_double_field_put(int offset, jdouble contents);
duke@0 256
jrose@710 257 address address_field_acquire(int offset) const;
jrose@710 258 void release_address_field_put(int offset, address contents);
jrose@710 259
duke@0 260 // printing functions for VM debugging
duke@0 261 void print_on(outputStream* st) const; // First level print
duke@0 262 void print_value_on(outputStream* st) const; // Second level print.
duke@0 263 void print_address_on(outputStream* st) const; // Address printing
duke@0 264
duke@0 265 // printing on default output stream
duke@0 266 void print();
duke@0 267 void print_value();
duke@0 268 void print_address();
duke@0 269
duke@0 270 // return the print strings
duke@0 271 char* print_string();
duke@0 272 char* print_value_string();
duke@0 273
duke@0 274 // verification operations
duke@0 275 void verify_on(outputStream* st);
duke@0 276 void verify();
duke@0 277
duke@0 278 // locking operations
duke@0 279 bool is_locked() const;
duke@0 280 bool is_unlocked() const;
duke@0 281 bool has_bias_pattern() const;
duke@0 282
duke@0 283 // asserts
duke@0 284 bool is_oop(bool ignore_mark_word = false) const;
duke@0 285 bool is_oop_or_null(bool ignore_mark_word = false) const;
duke@0 286 #ifndef PRODUCT
duke@0 287 bool is_unlocked_oop() const;
duke@0 288 #endif
duke@0 289
duke@0 290 // garbage collection
duke@0 291 bool is_gc_marked() const;
duke@0 292 // Apply "MarkSweep::mark_and_push" to (the address of) every non-NULL
duke@0 293 // reference field in "this".
coleenp@113 294 void follow_contents(void);
duke@0 295
jprovino@4107 296 #if INCLUDE_ALL_GCS
duke@0 297 // Parallel Scavenge
duke@0 298 void push_contents(PSPromotionManager* pm);
duke@0 299
duke@0 300 // Parallel Old
duke@0 301 void update_contents(ParCompactionManager* cm);
duke@0 302
duke@0 303 void follow_contents(ParCompactionManager* cm);
jprovino@4107 304 #endif // INCLUDE_ALL_GCS
duke@0 305
jrose@989 306 bool is_scavengable() const;
duke@0 307
duke@0 308 // Forward pointer operations for scavenge
duke@0 309 bool is_forwarded() const;
duke@0 310
duke@0 311 void forward_to(oop p);
duke@0 312 bool cas_forward_to(oop p, markOop compare);
duke@0 313
jprovino@4107 314 #if INCLUDE_ALL_GCS
duke@0 315 // Like "forward_to", but inserts the forwarding pointer atomically.
duke@0 316 // Exactly one thread succeeds in inserting the forwarding pointer, and
duke@0 317 // this call returns "NULL" for that thread; any other thread has the
duke@0 318 // value of the forwarding pointer returned and does not modify "this".
duke@0 319 oop forward_to_atomic(oop p);
jprovino@4107 320 #endif // INCLUDE_ALL_GCS
duke@0 321
duke@0 322 oop forwardee() const;
duke@0 323
duke@0 324 // Age of object during scavenge
jwilhelm@3694 325 uint age() const;
duke@0 326 void incr_age();
duke@0 327
duke@0 328 // Adjust all pointers in this object to point at it's forwarded location and
duke@0 329 // return the size of this oop. This is used by the MarkSweep collector.
duke@0 330 int adjust_pointers();
duke@0 331
duke@0 332 // mark-sweep support
duke@0 333 void follow_body(int begin, int end);
duke@0 334
duke@0 335 // Fast access to barrier set
duke@0 336 static BarrierSet* bs() { return _bs; }
duke@0 337 static void set_bs(BarrierSet* bs) { _bs = bs; }
duke@0 338
duke@0 339 // iterators, returns size of object
ysr@342 340 #define OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
duke@0 341 int oop_iterate(OopClosureType* blk); \
duke@0 342 int oop_iterate(OopClosureType* blk, MemRegion mr); // Only in mr.
duke@0 343
duke@0 344 ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_ITERATE_DECL)
ysr@342 345 ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_ITERATE_DECL)
ysr@342 346
jprovino@4107 347 #if INCLUDE_ALL_GCS
ysr@342 348
ysr@342 349 #define OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix) \
ysr@342 350 int oop_iterate_backwards(OopClosureType* blk);
ysr@342 351
ysr@342 352 ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_ITERATE_BACKWARDS_DECL)
ysr@342 353 ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_ITERATE_BACKWARDS_DECL)
ysr@342 354 #endif
duke@0 355
coleenp@3602 356 int oop_iterate_no_header(OopClosure* bk);
coleenp@3602 357 int oop_iterate_no_header(OopClosure* bk, MemRegion mr);
duke@0 358
duke@0 359 // identity hash; returns the identity hash key (computes it if necessary)
duke@0 360 // NOTE with the introduction of UseBiasedLocking that identity_hash() might reach a
duke@0 361 // safepoint if called on a biased object. Calling code must be aware of that.
duke@0 362 intptr_t identity_hash();
duke@0 363 intptr_t slow_identity_hash();
duke@0 364
coleenp@3602 365 // Alternate hashing code if string table is rehashed
minqi@5895 366 unsigned int new_hash(juint seed);
coleenp@3602 367
duke@0 368 // marks are forwarded to stack when object is locked
duke@0 369 bool has_displaced_mark() const;
duke@0 370 markOop displaced_mark() const;
duke@0 371 void set_displaced_mark(markOop m);
duke@0 372
duke@0 373 // for code generation
duke@0 374 static int mark_offset_in_bytes() { return offset_of(oopDesc, _mark); }
coleenp@113 375 static int klass_offset_in_bytes() { return offset_of(oopDesc, _metadata._klass); }
coleenp@113 376 static int klass_gap_offset_in_bytes();
duke@0 377 };
stefank@1879 378
stefank@1879 379 #endif // SHARE_VM_OOPS_OOP_HPP