src/share/vm/oops/oop.hpp

Tue, 02 Apr 2019 19:01:15 +0800

author
jingtian
date
Tue, 02 Apr 2019 19:01:15 +0800
changeset 9465
1556c6d89036
parent 9138
b56ab8e56604
permissions
-rw-r--r--

#8565 UseSyncLevel is not declared in zero/mips
Reviewed-by: aoqi

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

mercurial