src/share/vm/oops/klass.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
child 9756
2be326848943
permissions
-rw-r--r--

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

aoqi@0 1 /*
kbarrett@9099 2 * Copyright (c) 1997, 2018, 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_KLASS_HPP
aoqi@0 26 #define SHARE_VM_OOPS_KLASS_HPP
aoqi@0 27
aoqi@0 28 #include "memory/genOopClosures.hpp"
aoqi@0 29 #include "memory/iterator.hpp"
aoqi@0 30 #include "memory/memRegion.hpp"
aoqi@0 31 #include "memory/specialized_oop_closures.hpp"
aoqi@0 32 #include "oops/klassPS.hpp"
aoqi@0 33 #include "oops/metadata.hpp"
aoqi@0 34 #include "oops/oop.hpp"
fujie@9138 35 #ifdef MIPS
aoqi@0 36 #include "runtime/orderAccess.hpp"
aoqi@7535 37 #endif
aoqi@0 38 #include "trace/traceMacros.hpp"
aoqi@0 39 #include "utilities/accessFlags.hpp"
aoqi@0 40 #include "utilities/macros.hpp"
aoqi@0 41 #if INCLUDE_ALL_GCS
aoqi@0 42 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp"
aoqi@0 43 #include "gc_implementation/g1/g1OopClosures.hpp"
aoqi@0 44 #include "gc_implementation/parNew/parOopClosures.hpp"
aoqi@0 45 #endif // INCLUDE_ALL_GCS
aoqi@0 46
aoqi@0 47 //
aoqi@0 48 // A Klass provides:
aoqi@0 49 // 1: language level class object (method dictionary etc.)
aoqi@0 50 // 2: provide vm dispatch behavior for the object
aoqi@0 51 // Both functions are combined into one C++ class.
aoqi@0 52
aoqi@0 53 // One reason for the oop/klass dichotomy in the implementation is
aoqi@0 54 // that we don't want a C++ vtbl pointer in every object. Thus,
aoqi@0 55 // normal oops don't have any virtual functions. Instead, they
aoqi@0 56 // forward all "virtual" functions to their klass, which does have
aoqi@0 57 // a vtbl and does the C++ dispatch depending on the object's
aoqi@0 58 // actual type. (See oop.inline.hpp for some of the forwarding code.)
aoqi@0 59 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
aoqi@0 60
aoqi@0 61 // Klass layout:
aoqi@0 62 // [C++ vtbl ptr ] (contained in Metadata)
aoqi@0 63 // [layout_helper ]
aoqi@0 64 // [super_check_offset ] for fast subtype checks
aoqi@0 65 // [name ]
aoqi@0 66 // [secondary_super_cache] for fast subtype checks
aoqi@0 67 // [secondary_supers ] array of 2ndary supertypes
aoqi@0 68 // [primary_supers 0]
aoqi@0 69 // [primary_supers 1]
aoqi@0 70 // [primary_supers 2]
aoqi@0 71 // ...
aoqi@0 72 // [primary_supers 7]
aoqi@0 73 // [java_mirror ]
aoqi@0 74 // [super ]
aoqi@0 75 // [subklass ] first subclass
aoqi@0 76 // [next_sibling ] link to chain additional subklasses
aoqi@0 77 // [next_link ]
aoqi@0 78 // [class_loader_data]
aoqi@0 79 // [modifier_flags]
aoqi@0 80 // [access_flags ]
aoqi@0 81 // [last_biased_lock_bulk_revocation_time] (64 bits)
aoqi@0 82 // [prototype_header]
aoqi@0 83 // [biased_lock_revocation_count]
aoqi@0 84 // [_modified_oops]
aoqi@0 85 // [_accumulated_modified_oops]
aoqi@0 86 // [trace_id]
aoqi@0 87
aoqi@0 88
aoqi@0 89 // Forward declarations.
aoqi@0 90 template <class T> class Array;
aoqi@0 91 template <class T> class GrowableArray;
aoqi@0 92 class ClassLoaderData;
aoqi@0 93 class klassVtable;
aoqi@0 94 class ParCompactionManager;
aoqi@0 95 class KlassSizeStats;
aoqi@0 96 class fieldDescriptor;
aoqi@0 97
aoqi@0 98 class Klass : public Metadata {
aoqi@0 99 friend class VMStructs;
aoqi@0 100 protected:
aoqi@0 101 // note: put frequently-used fields together at start of klass structure
aoqi@0 102 // for better cache behavior (may not make much of a difference but sure won't hurt)
aoqi@0 103 enum { _primary_super_limit = 8 };
aoqi@0 104
aoqi@0 105 // The "layout helper" is a combined descriptor of object layout.
aoqi@0 106 // For klasses which are neither instance nor array, the value is zero.
aoqi@0 107 //
aoqi@0 108 // For instances, layout helper is a positive number, the instance size.
aoqi@0 109 // This size is already passed through align_object_size and scaled to bytes.
aoqi@0 110 // The low order bit is set if instances of this class cannot be
aoqi@0 111 // allocated using the fastpath.
aoqi@0 112 //
aoqi@0 113 // For arrays, layout helper is a negative number, containing four
aoqi@0 114 // distinct bytes, as follows:
aoqi@0 115 // MSB:[tag, hsz, ebt, log2(esz)]:LSB
aoqi@0 116 // where:
aoqi@0 117 // tag is 0x80 if the elements are oops, 0xC0 if non-oops
aoqi@0 118 // hsz is array header size in bytes (i.e., offset of first element)
aoqi@0 119 // ebt is the BasicType of the elements
aoqi@0 120 // esz is the element size in bytes
aoqi@0 121 // This packed word is arranged so as to be quickly unpacked by the
aoqi@0 122 // various fast paths that use the various subfields.
aoqi@0 123 //
aoqi@0 124 // The esz bits can be used directly by a SLL instruction, without masking.
aoqi@0 125 //
aoqi@0 126 // Note that the array-kind tag looks like 0x00 for instance klasses,
aoqi@0 127 // since their length in bytes is always less than 24Mb.
aoqi@0 128 //
aoqi@0 129 // Final note: This comes first, immediately after C++ vtable,
aoqi@0 130 // because it is frequently queried.
aoqi@0 131 jint _layout_helper;
aoqi@0 132
aoqi@0 133 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
aoqi@0 134 // and _primary_supers all help make fast subtype checks. See big discussion
aoqi@0 135 // in doc/server_compiler/checktype.txt
aoqi@0 136 //
aoqi@0 137 // Where to look to observe a supertype (it is &_secondary_super_cache for
aoqi@0 138 // secondary supers, else is &_primary_supers[depth()].
aoqi@0 139 juint _super_check_offset;
aoqi@0 140
aoqi@0 141 // Class name. Instance classes: java/lang/String, etc. Array classes: [I,
aoqi@0 142 // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
aoqi@0 143 Symbol* _name;
aoqi@0 144
aoqi@0 145 // Cache of last observed secondary supertype
aoqi@0 146 Klass* _secondary_super_cache;
aoqi@0 147 // Array of all secondary supertypes
aoqi@0 148 Array<Klass*>* _secondary_supers;
aoqi@0 149 // Ordered list of all primary supertypes
aoqi@0 150 Klass* _primary_supers[_primary_super_limit];
aoqi@0 151 // java/lang/Class instance mirroring this class
aoqi@0 152 oop _java_mirror;
aoqi@0 153 // Superclass
aoqi@0 154 Klass* _super;
aoqi@0 155 // First subclass (NULL if none); _subklass->next_sibling() is next one
aoqi@0 156 Klass* _subklass;
aoqi@0 157 // Sibling link (or NULL); links all subklasses of a klass
aoqi@0 158 Klass* _next_sibling;
aoqi@0 159
aoqi@0 160 // All klasses loaded by a class loader are chained through these links
aoqi@0 161 Klass* _next_link;
aoqi@0 162
aoqi@0 163 // The VM's representation of the ClassLoader used to load this class.
aoqi@0 164 // Provide access the corresponding instance java.lang.ClassLoader.
aoqi@0 165 ClassLoaderData* _class_loader_data;
aoqi@0 166
aoqi@0 167 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
aoqi@0 168 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
aoqi@0 169
aoqi@0 170 // Biased locking implementation and statistics
aoqi@0 171 // (the 64-bit chunk goes first, to avoid some fragmentation)
aoqi@0 172 jlong _last_biased_lock_bulk_revocation_time;
aoqi@0 173 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
aoqi@0 174 jint _biased_lock_revocation_count;
aoqi@0 175
aoqi@0 176 TRACE_DEFINE_KLASS_TRACE_ID;
aoqi@0 177
aoqi@0 178 // Remembered sets support for the oops in the klasses.
aoqi@0 179 jbyte _modified_oops; // Card Table Equivalent (YC/CMS support)
aoqi@0 180 jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
aoqi@0 181
iklam@7089 182 private:
iklam@7089 183 // This is an index into FileMapHeader::_classpath_entry_table[], to
iklam@7089 184 // associate this class with the JAR file where it's loaded from during
iklam@7089 185 // dump time. If a class is not loaded from the shared archive, this field is
iklam@7089 186 // -1.
iklam@7089 187 jshort _shared_class_path_index;
iklam@7089 188
iklam@7089 189 friend class SharedClassUtil;
iklam@7089 190 protected:
iklam@7089 191
aoqi@0 192 // Constructor
aoqi@0 193 Klass();
aoqi@0 194
aoqi@0 195 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
aoqi@0 196
aoqi@0 197 public:
dbuck@8716 198 enum DefaultsLookupMode { find_defaults, skip_defaults };
dbuck@8716 199 enum OverpassLookupMode { find_overpass, skip_overpass };
dbuck@8716 200 enum StaticLookupMode { find_static, skip_static };
dbuck@8716 201 enum PrivateLookupMode { find_private, skip_private };
aoqi@0 202
aoqi@0 203 bool is_klass() const volatile { return true; }
aoqi@0 204
aoqi@0 205 // super
aoqi@0 206 Klass* super() const { return _super; }
aoqi@0 207 void set_super(Klass* k) { _super = k; }
aoqi@0 208
aoqi@0 209 // initializes _super link, _primary_supers & _secondary_supers arrays
aoqi@0 210 void initialize_supers(Klass* k, TRAPS);
aoqi@0 211 void initialize_supers_impl1(Klass* k);
aoqi@0 212 void initialize_supers_impl2(Klass* k);
aoqi@0 213
aoqi@0 214 // klass-specific helper for initializing _secondary_supers
aoqi@0 215 virtual GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots);
aoqi@0 216
aoqi@0 217 // java_super is the Java-level super type as specified by Class.getSuperClass.
aoqi@0 218 virtual Klass* java_super() const { return NULL; }
aoqi@0 219
aoqi@0 220 juint super_check_offset() const { return _super_check_offset; }
aoqi@0 221 void set_super_check_offset(juint o) { _super_check_offset = o; }
aoqi@0 222
aoqi@0 223 Klass* secondary_super_cache() const { return _secondary_super_cache; }
aoqi@0 224 void set_secondary_super_cache(Klass* k) { _secondary_super_cache = k; }
aoqi@0 225
aoqi@0 226 Array<Klass*>* secondary_supers() const { return _secondary_supers; }
aoqi@0 227 void set_secondary_supers(Array<Klass*>* k) { _secondary_supers = k; }
aoqi@0 228
aoqi@0 229 // Return the element of the _super chain of the given depth.
aoqi@0 230 // If there is no such element, return either NULL or this.
aoqi@0 231 Klass* primary_super_of_depth(juint i) const {
aoqi@0 232 assert(i < primary_super_limit(), "oob");
aoqi@0 233 Klass* super = _primary_supers[i];
aoqi@0 234 assert(super == NULL || super->super_depth() == i, "correct display");
aoqi@0 235 return super;
aoqi@0 236 }
aoqi@0 237
aoqi@0 238 // Can this klass be a primary super? False for interfaces and arrays of
aoqi@0 239 // interfaces. False also for arrays or classes with long super chains.
aoqi@0 240 bool can_be_primary_super() const {
aoqi@0 241 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
aoqi@0 242 return super_check_offset() != secondary_offset;
aoqi@0 243 }
aoqi@0 244 virtual bool can_be_primary_super_slow() const;
aoqi@0 245
aoqi@0 246 // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit].
aoqi@0 247 juint super_depth() const {
aoqi@0 248 if (!can_be_primary_super()) {
aoqi@0 249 return primary_super_limit();
aoqi@0 250 } else {
aoqi@0 251 juint d = (super_check_offset() - in_bytes(primary_supers_offset())) / sizeof(Klass*);
aoqi@0 252 assert(d < primary_super_limit(), "oob");
aoqi@0 253 assert(_primary_supers[d] == this, "proper init");
aoqi@0 254 return d;
aoqi@0 255 }
aoqi@0 256 }
aoqi@0 257
aoqi@0 258 // store an oop into a field of a Klass
aoqi@0 259 void klass_oop_store(oop* p, oop v);
aoqi@0 260 void klass_oop_store(volatile oop* p, oop v);
aoqi@0 261
aoqi@0 262 // java mirror
aoqi@0 263 oop java_mirror() const { return _java_mirror; }
aoqi@0 264 void set_java_mirror(oop m) { klass_oop_store(&_java_mirror, m); }
aoqi@0 265
aoqi@0 266 // modifier flags
aoqi@0 267 jint modifier_flags() const { return _modifier_flags; }
aoqi@0 268 void set_modifier_flags(jint flags) { _modifier_flags = flags; }
aoqi@0 269
aoqi@0 270 // size helper
aoqi@0 271 int layout_helper() const { return _layout_helper; }
aoqi@0 272 void set_layout_helper(int lh) { _layout_helper = lh; }
aoqi@0 273
aoqi@0 274 // Note: for instances layout_helper() may include padding.
aoqi@0 275 // Use InstanceKlass::contains_field_offset to classify field offsets.
aoqi@0 276
aoqi@0 277 // sub/superklass links
aoqi@0 278 InstanceKlass* superklass() const;
aoqi@0 279 Klass* subklass() const;
aoqi@0 280 Klass* next_sibling() const;
aoqi@0 281 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
aoqi@0 282
aoqi@0 283 void set_next_link(Klass* k) { _next_link = k; }
aoqi@0 284 Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
aoqi@0 285
aoqi@0 286 // class loader data
aoqi@0 287 ClassLoaderData* class_loader_data() const { return _class_loader_data; }
aoqi@0 288 void set_class_loader_data(ClassLoaderData* loader_data) { _class_loader_data = loader_data; }
aoqi@0 289
aoqi@0 290 // The Klasses are not placed in the Heap, so the Card Table or
aoqi@0 291 // the Mod Union Table can't be used to mark when klasses have modified oops.
aoqi@0 292 // The CT and MUT bits saves this information for the individual Klasses.
aoqi@8019 293 void record_modified_oops() {
aoqi@8019 294 _modified_oops = 1;
jingtian@9465 295 #if defined MIPS && !defined ZERO
aoqi@8019 296 if (UseSyncLevel >= 2000) OrderAccess::fence();
aoqi@8019 297 #endif
fujie@135 298 }
aoqi@8019 299 void clear_modified_oops() {
aoqi@8019 300 _modified_oops = 0;
jingtian@9465 301 #if defined MIPS && !defined ZERO
aoqi@8019 302 if (UseSyncLevel >= 2000) OrderAccess::fence();
aoqi@8019 303 #endif
fujie@135 304 }
aoqi@0 305 bool has_modified_oops() { return _modified_oops == 1; }
aoqi@0 306
aoqi@0 307 void accumulate_modified_oops() { if (has_modified_oops()) _accumulated_modified_oops = 1; }
aoqi@0 308 void clear_accumulated_modified_oops() { _accumulated_modified_oops = 0; }
aoqi@0 309 bool has_accumulated_modified_oops() { return _accumulated_modified_oops == 1; }
aoqi@0 310
iklam@7089 311 int shared_classpath_index() const {
iklam@7089 312 return _shared_class_path_index;
iklam@7089 313 };
iklam@7089 314
iklam@7089 315 void set_shared_classpath_index(int index) {
iklam@7089 316 _shared_class_path_index = index;
iklam@7089 317 };
iklam@7089 318
iklam@7089 319
aoqi@0 320 protected: // internal accessors
aoqi@0 321 Klass* subklass_oop() const { return _subklass; }
aoqi@0 322 Klass* next_sibling_oop() const { return _next_sibling; }
aoqi@0 323 void set_subklass(Klass* s);
aoqi@0 324 void set_next_sibling(Klass* s);
aoqi@0 325
aoqi@0 326 public:
aoqi@0 327
aoqi@0 328 // Compiler support
aoqi@0 329 static ByteSize super_offset() { return in_ByteSize(offset_of(Klass, _super)); }
aoqi@0 330 static ByteSize super_check_offset_offset() { return in_ByteSize(offset_of(Klass, _super_check_offset)); }
aoqi@0 331 static ByteSize primary_supers_offset() { return in_ByteSize(offset_of(Klass, _primary_supers)); }
aoqi@0 332 static ByteSize secondary_super_cache_offset() { return in_ByteSize(offset_of(Klass, _secondary_super_cache)); }
aoqi@0 333 static ByteSize secondary_supers_offset() { return in_ByteSize(offset_of(Klass, _secondary_supers)); }
aoqi@0 334 static ByteSize java_mirror_offset() { return in_ByteSize(offset_of(Klass, _java_mirror)); }
aoqi@0 335 static ByteSize modifier_flags_offset() { return in_ByteSize(offset_of(Klass, _modifier_flags)); }
aoqi@0 336 static ByteSize layout_helper_offset() { return in_ByteSize(offset_of(Klass, _layout_helper)); }
aoqi@0 337 static ByteSize access_flags_offset() { return in_ByteSize(offset_of(Klass, _access_flags)); }
aoqi@0 338
aoqi@0 339 // Unpacking layout_helper:
aoqi@0 340 enum {
aoqi@0 341 _lh_neutral_value = 0, // neutral non-array non-instance value
aoqi@0 342 _lh_instance_slow_path_bit = 0x01,
aoqi@0 343 _lh_log2_element_size_shift = BitsPerByte*0,
aoqi@0 344 _lh_log2_element_size_mask = BitsPerLong-1,
aoqi@0 345 _lh_element_type_shift = BitsPerByte*1,
aoqi@0 346 _lh_element_type_mask = right_n_bits(BitsPerByte), // shifted mask
aoqi@0 347 _lh_header_size_shift = BitsPerByte*2,
aoqi@0 348 _lh_header_size_mask = right_n_bits(BitsPerByte), // shifted mask
aoqi@0 349 _lh_array_tag_bits = 2,
aoqi@0 350 _lh_array_tag_shift = BitsPerInt - _lh_array_tag_bits,
aoqi@0 351 _lh_array_tag_type_value = ~0x00, // 0xC0000000 >> 30
aoqi@0 352 _lh_array_tag_obj_value = ~0x01 // 0x80000000 >> 30
aoqi@0 353 };
aoqi@0 354
aoqi@0 355 static int layout_helper_size_in_bytes(jint lh) {
aoqi@0 356 assert(lh > (jint)_lh_neutral_value, "must be instance");
aoqi@0 357 return (int) lh & ~_lh_instance_slow_path_bit;
aoqi@0 358 }
aoqi@0 359 static bool layout_helper_needs_slow_path(jint lh) {
aoqi@0 360 assert(lh > (jint)_lh_neutral_value, "must be instance");
aoqi@0 361 return (lh & _lh_instance_slow_path_bit) != 0;
aoqi@0 362 }
aoqi@0 363 static bool layout_helper_is_instance(jint lh) {
aoqi@0 364 return (jint)lh > (jint)_lh_neutral_value;
aoqi@0 365 }
aoqi@0 366 static bool layout_helper_is_array(jint lh) {
aoqi@0 367 return (jint)lh < (jint)_lh_neutral_value;
aoqi@0 368 }
aoqi@0 369 static bool layout_helper_is_typeArray(jint lh) {
aoqi@0 370 // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
aoqi@0 371 return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
aoqi@0 372 }
aoqi@0 373 static bool layout_helper_is_objArray(jint lh) {
aoqi@0 374 // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
aoqi@0 375 return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);
aoqi@0 376 }
aoqi@0 377 static int layout_helper_header_size(jint lh) {
aoqi@0 378 assert(lh < (jint)_lh_neutral_value, "must be array");
aoqi@0 379 int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
aoqi@0 380 assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
aoqi@0 381 return hsize;
aoqi@0 382 }
aoqi@0 383 static BasicType layout_helper_element_type(jint lh) {
aoqi@0 384 assert(lh < (jint)_lh_neutral_value, "must be array");
aoqi@0 385 int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
aoqi@0 386 assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity");
aoqi@0 387 return (BasicType) btvalue;
aoqi@0 388 }
kevinw@8368 389
kevinw@8368 390 // Want a pattern to quickly diff against layout header in register
kevinw@8368 391 // find something less clever!
kevinw@8368 392 static int layout_helper_boolean_diffbit() {
kevinw@8368 393 jint zlh = array_layout_helper(T_BOOLEAN);
kevinw@8368 394 jint blh = array_layout_helper(T_BYTE);
kevinw@8368 395 assert(zlh != blh, "array layout helpers must differ");
kevinw@8368 396 int diffbit = 1;
kevinw@8368 397 while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
kevinw@8368 398 diffbit <<= 1;
kevinw@8368 399 assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
kevinw@8368 400 }
kevinw@8368 401 return diffbit;
kevinw@8368 402 }
kevinw@8368 403
aoqi@0 404 static int layout_helper_log2_element_size(jint lh) {
aoqi@0 405 assert(lh < (jint)_lh_neutral_value, "must be array");
aoqi@0 406 int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
aoqi@0 407 assert(l2esz <= LogBitsPerLong,
aoqi@0 408 err_msg("sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh));
aoqi@0 409 return l2esz;
aoqi@0 410 }
aoqi@0 411 static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
aoqi@0 412 return (tag << _lh_array_tag_shift)
aoqi@0 413 | (hsize << _lh_header_size_shift)
aoqi@0 414 | ((int)etype << _lh_element_type_shift)
aoqi@0 415 | (log2_esize << _lh_log2_element_size_shift);
aoqi@0 416 }
aoqi@0 417 static jint instance_layout_helper(jint size, bool slow_path_flag) {
aoqi@0 418 return (size << LogHeapWordSize)
aoqi@0 419 | (slow_path_flag ? _lh_instance_slow_path_bit : 0);
aoqi@0 420 }
aoqi@0 421 static int layout_helper_to_size_helper(jint lh) {
aoqi@0 422 assert(lh > (jint)_lh_neutral_value, "must be instance");
aoqi@0 423 // Note that the following expression discards _lh_instance_slow_path_bit.
aoqi@0 424 return lh >> LogHeapWordSize;
aoqi@0 425 }
aoqi@0 426 // Out-of-line version computes everything based on the etype:
aoqi@0 427 static jint array_layout_helper(BasicType etype);
aoqi@0 428
aoqi@0 429 // What is the maximum number of primary superclasses any klass can have?
aoqi@0 430 #ifdef PRODUCT
aoqi@0 431 static juint primary_super_limit() { return _primary_super_limit; }
aoqi@0 432 #else
aoqi@0 433 static juint primary_super_limit() {
aoqi@0 434 assert(FastSuperclassLimit <= _primary_super_limit, "parameter oob");
aoqi@0 435 return FastSuperclassLimit;
aoqi@0 436 }
aoqi@0 437 #endif
aoqi@0 438
aoqi@0 439 // vtables
aoqi@0 440 virtual klassVtable* vtable() const { return NULL; }
aoqi@0 441 virtual int vtable_length() const { return 0; }
aoqi@0 442
aoqi@0 443 // subclass check
aoqi@0 444 bool is_subclass_of(const Klass* k) const;
aoqi@0 445 // subtype check: true if is_subclass_of, or if k is interface and receiver implements it
aoqi@0 446 bool is_subtype_of(Klass* k) const {
aoqi@0 447 juint off = k->super_check_offset();
aoqi@0 448 Klass* sup = *(Klass**)( (address)this + off );
aoqi@0 449 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
aoqi@0 450 if (sup == k) {
aoqi@0 451 return true;
aoqi@0 452 } else if (off != secondary_offset) {
aoqi@0 453 return false;
aoqi@0 454 } else {
aoqi@0 455 return search_secondary_supers(k);
aoqi@0 456 }
aoqi@0 457 }
aoqi@0 458 bool search_secondary_supers(Klass* k) const;
aoqi@0 459
aoqi@0 460 // Find LCA in class hierarchy
aoqi@0 461 Klass *LCA( Klass *k );
aoqi@0 462
aoqi@0 463 // Check whether reflection/jni/jvm code is allowed to instantiate this class;
aoqi@0 464 // if not, throw either an Error or an Exception.
aoqi@0 465 virtual void check_valid_for_instantiation(bool throwError, TRAPS);
aoqi@0 466
aoqi@0 467 // array copying
aoqi@0 468 virtual void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
aoqi@0 469
aoqi@0 470 // tells if the class should be initialized
aoqi@0 471 virtual bool should_be_initialized() const { return false; }
aoqi@0 472 // initializes the klass
aoqi@0 473 virtual void initialize(TRAPS);
aoqi@0 474 // lookup operation for MethodLookupCache
aoqi@0 475 friend class MethodLookupCache;
aoqi@0 476 virtual Klass* find_field(Symbol* name, Symbol* signature, fieldDescriptor* fd) const;
dbuck@8716 477 virtual Method* uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const;
aoqi@0 478 public:
aoqi@0 479 Method* lookup_method(Symbol* name, Symbol* signature) const {
dbuck@8716 480 return uncached_lookup_method(name, signature, find_overpass);
aoqi@0 481 }
aoqi@0 482
aoqi@0 483 // array class with specific rank
aoqi@0 484 Klass* array_klass(int rank, TRAPS) { return array_klass_impl(false, rank, THREAD); }
aoqi@0 485
aoqi@0 486 // array class with this klass as element type
aoqi@0 487 Klass* array_klass(TRAPS) { return array_klass_impl(false, THREAD); }
aoqi@0 488
aoqi@0 489 // These will return NULL instead of allocating on the heap:
aoqi@0 490 // NB: these can block for a mutex, like other functions with TRAPS arg.
aoqi@0 491 Klass* array_klass_or_null(int rank);
aoqi@0 492 Klass* array_klass_or_null();
aoqi@0 493
aoqi@0 494 virtual oop protection_domain() const = 0;
aoqi@0 495
aoqi@0 496 oop class_loader() const;
aoqi@0 497
aoqi@0 498 virtual oop klass_holder() const { return class_loader(); }
aoqi@0 499
aoqi@0 500 protected:
aoqi@0 501 virtual Klass* array_klass_impl(bool or_null, int rank, TRAPS);
aoqi@0 502 virtual Klass* array_klass_impl(bool or_null, TRAPS);
aoqi@0 503
aoqi@0 504 public:
aoqi@0 505 // CDS support - remove and restore oops from metadata. Oops are not shared.
aoqi@0 506 virtual void remove_unshareable_info();
iklam@7089 507 virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
aoqi@0 508
aoqi@0 509 protected:
aoqi@0 510 // computes the subtype relationship
aoqi@0 511 virtual bool compute_is_subtype_of(Klass* k);
aoqi@0 512 public:
aoqi@0 513 // subclass accessor (here for convenience; undefined for non-klass objects)
aoqi@0 514 virtual bool is_leaf_class() const { fatal("not a class"); return false; }
aoqi@0 515 public:
aoqi@0 516 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP
aoqi@0 517 // These functions describe behavior for the oop not the KLASS.
aoqi@0 518
aoqi@0 519 // actual oop size of obj in memory
aoqi@0 520 virtual int oop_size(oop obj) const = 0;
aoqi@0 521
aoqi@0 522 // Size of klass in word size.
aoqi@0 523 virtual int size() const = 0;
aoqi@0 524 #if INCLUDE_SERVICES
aoqi@0 525 virtual void collect_statistics(KlassSizeStats *sz) const;
aoqi@0 526 #endif
aoqi@0 527
aoqi@0 528 // Returns the Java name for a class (Resource allocated)
aoqi@0 529 // For arrays, this returns the name of the element with a leading '['.
aoqi@0 530 // For classes, this returns the name with the package separators
aoqi@0 531 // turned into '.'s.
aoqi@0 532 const char* external_name() const;
aoqi@0 533 // Returns the name for a class (Resource allocated) as the class
aoqi@0 534 // would appear in a signature.
aoqi@0 535 // For arrays, this returns the name of the element with a leading '['.
aoqi@0 536 // For classes, this returns the name with a leading 'L' and a trailing ';'
aoqi@0 537 // and the package separators as '/'.
aoqi@0 538 virtual const char* signature_name() const;
aoqi@0 539
aoqi@0 540 // garbage collection support
aoqi@0 541 virtual void oop_follow_contents(oop obj) = 0;
aoqi@0 542 virtual int oop_adjust_pointers(oop obj) = 0;
aoqi@0 543
aoqi@0 544 // Parallel Scavenge and Parallel Old
aoqi@0 545 PARALLEL_GC_DECLS_PV
aoqi@0 546
aoqi@0 547 // type testing operations
aoqi@0 548 protected:
aoqi@0 549 virtual bool oop_is_instance_slow() const { return false; }
aoqi@0 550 virtual bool oop_is_array_slow() const { return false; }
aoqi@0 551 virtual bool oop_is_objArray_slow() const { return false; }
aoqi@0 552 virtual bool oop_is_typeArray_slow() const { return false; }
aoqi@0 553 public:
stefank@6976 554 virtual bool oop_is_instanceClassLoader() const { return false; }
aoqi@0 555 virtual bool oop_is_instanceMirror() const { return false; }
aoqi@0 556 virtual bool oop_is_instanceRef() const { return false; }
aoqi@0 557
aoqi@0 558 // Fast non-virtual versions
aoqi@0 559 #ifndef ASSERT
aoqi@0 560 #define assert_same_query(xval, xcheck) xval
aoqi@0 561 #else
aoqi@0 562 private:
aoqi@0 563 static bool assert_same_query(bool xval, bool xslow) {
aoqi@0 564 assert(xval == xslow, "slow and fast queries agree");
aoqi@0 565 return xval;
aoqi@0 566 }
aoqi@0 567 public:
aoqi@0 568 #endif
aoqi@0 569 inline bool oop_is_instance() const { return assert_same_query(
aoqi@0 570 layout_helper_is_instance(layout_helper()),
aoqi@0 571 oop_is_instance_slow()); }
aoqi@0 572 inline bool oop_is_array() const { return assert_same_query(
aoqi@0 573 layout_helper_is_array(layout_helper()),
aoqi@0 574 oop_is_array_slow()); }
aoqi@0 575 inline bool oop_is_objArray() const { return assert_same_query(
aoqi@0 576 layout_helper_is_objArray(layout_helper()),
aoqi@0 577 oop_is_objArray_slow()); }
aoqi@0 578 inline bool oop_is_typeArray() const { return assert_same_query(
aoqi@0 579 layout_helper_is_typeArray(layout_helper()),
aoqi@0 580 oop_is_typeArray_slow()); }
aoqi@0 581 #undef assert_same_query
aoqi@0 582
aoqi@0 583 // Access flags
aoqi@0 584 AccessFlags access_flags() const { return _access_flags; }
aoqi@0 585 void set_access_flags(AccessFlags flags) { _access_flags = flags; }
aoqi@0 586
aoqi@0 587 bool is_public() const { return _access_flags.is_public(); }
aoqi@0 588 bool is_final() const { return _access_flags.is_final(); }
aoqi@0 589 bool is_interface() const { return _access_flags.is_interface(); }
aoqi@0 590 bool is_abstract() const { return _access_flags.is_abstract(); }
aoqi@0 591 bool is_super() const { return _access_flags.is_super(); }
aoqi@0 592 bool is_synthetic() const { return _access_flags.is_synthetic(); }
aoqi@0 593 void set_is_synthetic() { _access_flags.set_is_synthetic(); }
aoqi@0 594 bool has_finalizer() const { return _access_flags.has_finalizer(); }
aoqi@0 595 bool has_final_method() const { return _access_flags.has_final_method(); }
aoqi@0 596 void set_has_finalizer() { _access_flags.set_has_finalizer(); }
aoqi@0 597 void set_has_final_method() { _access_flags.set_has_final_method(); }
kbarrett@9099 598 bool is_cloneable() const;
kbarrett@9099 599 void set_is_cloneable();
aoqi@0 600 bool has_vanilla_constructor() const { return _access_flags.has_vanilla_constructor(); }
aoqi@0 601 void set_has_vanilla_constructor() { _access_flags.set_has_vanilla_constructor(); }
aoqi@0 602 bool has_miranda_methods () const { return access_flags().has_miranda_methods(); }
aoqi@0 603 void set_has_miranda_methods() { _access_flags.set_has_miranda_methods(); }
aoqi@0 604
aoqi@0 605 // Biased locking support
aoqi@0 606 // Note: the prototype header is always set up to be at least the
aoqi@0 607 // prototype markOop. If biased locking is enabled it may further be
aoqi@0 608 // biasable and have an epoch.
aoqi@0 609 markOop prototype_header() const { return _prototype_header; }
aoqi@0 610 // NOTE: once instances of this klass are floating around in the
aoqi@0 611 // system, this header must only be updated at a safepoint.
aoqi@0 612 // NOTE 2: currently we only ever set the prototype header to the
aoqi@0 613 // biasable prototype for instanceKlasses. There is no technical
aoqi@0 614 // reason why it could not be done for arrayKlasses aside from
aoqi@0 615 // wanting to reduce the initial scope of this optimization. There
aoqi@0 616 // are potential problems in setting the bias pattern for
aoqi@0 617 // JVM-internal oops.
aoqi@0 618 inline void set_prototype_header(markOop header);
aoqi@0 619 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
aoqi@0 620
aoqi@0 621 int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
aoqi@0 622 // Atomically increments biased_lock_revocation_count and returns updated value
aoqi@0 623 int atomic_incr_biased_lock_revocation_count();
aoqi@0 624 void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
aoqi@0 625 jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
aoqi@0 626 void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
aoqi@0 627
aoqi@0 628 TRACE_DEFINE_KLASS_METHODS;
aoqi@0 629
aoqi@0 630 // garbage collection support
aoqi@0 631 virtual void oops_do(OopClosure* cl);
aoqi@0 632
aoqi@0 633 // Iff the class loader (or mirror for anonymous classes) is alive the
aoqi@0 634 // Klass is considered alive.
aoqi@0 635 // The is_alive closure passed in depends on the Garbage Collector used.
aoqi@0 636 bool is_loader_alive(BoolObjectClosure* is_alive);
aoqi@0 637
stefank@6992 638 static void clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses = true);
stefank@6992 639 static void clean_subklass_tree(BoolObjectClosure* is_alive) {
stefank@6992 640 clean_weak_klass_links(is_alive, false /* clean_alive_klasses */);
aoqi@0 641 }
aoqi@0 642
aoqi@0 643 // iterators
aoqi@0 644 virtual int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) = 0;
aoqi@0 645 virtual int oop_oop_iterate_v(oop obj, ExtendedOopClosure* blk) {
aoqi@0 646 return oop_oop_iterate(obj, blk);
aoqi@0 647 }
aoqi@0 648
aoqi@0 649 #if INCLUDE_ALL_GCS
aoqi@0 650 // In case we don't have a specialized backward scanner use forward
aoqi@0 651 // iteration.
aoqi@0 652 virtual int oop_oop_iterate_backwards_v(oop obj, ExtendedOopClosure* blk) {
aoqi@0 653 return oop_oop_iterate_v(obj, blk);
aoqi@0 654 }
aoqi@0 655 #endif // INCLUDE_ALL_GCS
aoqi@0 656
aoqi@0 657 // Iterates "blk" over all the oops in "obj" (of type "this") within "mr".
aoqi@0 658 // (I don't see why the _m should be required, but without it the Solaris
aoqi@0 659 // C++ gives warning messages about overridings of the "oop_oop_iterate"
aoqi@0 660 // defined above "hiding" this virtual function. (DLD, 6/20/00)) */
aoqi@0 661 virtual int oop_oop_iterate_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) = 0;
aoqi@0 662 virtual int oop_oop_iterate_v_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) {
aoqi@0 663 return oop_oop_iterate_m(obj, blk, mr);
aoqi@0 664 }
aoqi@0 665
aoqi@0 666 // Versions of the above iterators specialized to particular subtypes
aoqi@0 667 // of OopClosure, to avoid closure virtual calls.
aoqi@0 668 #define Klass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
aoqi@0 669 virtual int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk) { \
aoqi@0 670 /* Default implementation reverts to general version. */ \
aoqi@0 671 return oop_oop_iterate(obj, blk); \
aoqi@0 672 } \
aoqi@0 673 \
aoqi@0 674 /* Iterates "blk" over all the oops in "obj" (of type "this") within "mr". \
aoqi@0 675 (I don't see why the _m should be required, but without it the Solaris \
aoqi@0 676 C++ gives warning messages about overridings of the "oop_oop_iterate" \
aoqi@0 677 defined above "hiding" this virtual function. (DLD, 6/20/00)) */ \
aoqi@0 678 virtual int oop_oop_iterate##nv_suffix##_m(oop obj, \
aoqi@0 679 OopClosureType* blk, \
aoqi@0 680 MemRegion mr) { \
aoqi@0 681 return oop_oop_iterate_m(obj, blk, mr); \
aoqi@0 682 }
aoqi@0 683
aoqi@0 684 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_DECL)
aoqi@0 685 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_DECL)
aoqi@0 686
aoqi@0 687 #if INCLUDE_ALL_GCS
aoqi@0 688 #define Klass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix) \
aoqi@0 689 virtual int oop_oop_iterate_backwards##nv_suffix(oop obj, \
aoqi@0 690 OopClosureType* blk) { \
aoqi@0 691 /* Default implementation reverts to general version. */ \
aoqi@0 692 return oop_oop_iterate_backwards_v(obj, blk); \
aoqi@0 693 }
aoqi@0 694
aoqi@0 695 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL)
aoqi@0 696 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL)
aoqi@0 697 #endif // INCLUDE_ALL_GCS
aoqi@0 698
aoqi@0 699 virtual void array_klasses_do(void f(Klass* k)) {}
aoqi@0 700
aoqi@0 701 // Return self, except for abstract classes with exactly 1
aoqi@0 702 // implementor. Then return the 1 concrete implementation.
aoqi@0 703 Klass *up_cast_abstract();
aoqi@0 704
aoqi@0 705 // klass name
aoqi@0 706 Symbol* name() const { return _name; }
aoqi@0 707 void set_name(Symbol* n);
aoqi@0 708
aoqi@0 709 public:
aoqi@0 710 // jvm support
aoqi@0 711 virtual jint compute_modifier_flags(TRAPS) const;
aoqi@0 712
aoqi@0 713 // JVMTI support
aoqi@0 714 virtual jint jvmti_class_status() const;
aoqi@0 715
aoqi@0 716 // Printing
aoqi@0 717 virtual void print_on(outputStream* st) const;
aoqi@0 718
aoqi@0 719 virtual void oop_print_value_on(oop obj, outputStream* st);
aoqi@0 720 virtual void oop_print_on (oop obj, outputStream* st);
aoqi@0 721
aoqi@0 722 virtual const char* internal_name() const = 0;
aoqi@0 723
aoqi@0 724 // Verification
aoqi@0 725 virtual void verify_on(outputStream* st);
aoqi@0 726 void verify() { verify_on(tty); }
aoqi@0 727
aoqi@0 728 #ifndef PRODUCT
aoqi@0 729 bool verify_vtable_index(int index);
aoqi@0 730 bool verify_itable_index(int index);
aoqi@0 731 #endif
aoqi@0 732
aoqi@0 733 virtual void oop_verify_on(oop obj, outputStream* st);
aoqi@0 734
aoqi@0 735 static bool is_null(narrowKlass obj);
aoqi@0 736 static bool is_null(Klass* obj);
aoqi@0 737
aoqi@0 738 // klass encoding for klass pointer in objects.
aoqi@0 739 static narrowKlass encode_klass_not_null(Klass* v);
aoqi@0 740 static narrowKlass encode_klass(Klass* v);
aoqi@0 741
aoqi@0 742 static Klass* decode_klass_not_null(narrowKlass v);
aoqi@0 743 static Klass* decode_klass(narrowKlass v);
aoqi@0 744
aoqi@0 745 private:
aoqi@0 746 // barriers used by klass_oop_store
aoqi@0 747 void klass_update_barrier_set(oop v);
stefank@6992 748 void klass_update_barrier_set_pre(oop* p, oop v);
aoqi@0 749 };
aoqi@0 750
aoqi@0 751 #endif // SHARE_VM_OOPS_KLASS_HPP

mercurial