src/share/vm/oops/klass.hpp

Tue, 12 Dec 2017 10:30:27 +0800

author
aoqi
date
Tue, 12 Dec 2017 10:30:27 +0800
changeset 8019
3fb3ceb7398f
parent 7535
7ae4e26cb1e0
child 8604
04d83ba48607
permissions
-rw-r--r--

#6345 sync is controled by UseSyncLevel instead of Use3A2000
Reviewed-by: fujie

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_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"
aoqi@7535 35 #ifdef MIPS64
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:
aoqi@0 198 enum MethodLookupMode { normal, skip_overpass, skip_defaults };
aoqi@0 199
aoqi@0 200 bool is_klass() const volatile { return true; }
aoqi@0 201
aoqi@0 202 // super
aoqi@0 203 Klass* super() const { return _super; }
aoqi@0 204 void set_super(Klass* k) { _super = k; }
aoqi@0 205
aoqi@0 206 // initializes _super link, _primary_supers & _secondary_supers arrays
aoqi@0 207 void initialize_supers(Klass* k, TRAPS);
aoqi@0 208 void initialize_supers_impl1(Klass* k);
aoqi@0 209 void initialize_supers_impl2(Klass* k);
aoqi@0 210
aoqi@0 211 // klass-specific helper for initializing _secondary_supers
aoqi@0 212 virtual GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots);
aoqi@0 213
aoqi@0 214 // java_super is the Java-level super type as specified by Class.getSuperClass.
aoqi@0 215 virtual Klass* java_super() const { return NULL; }
aoqi@0 216
aoqi@0 217 juint super_check_offset() const { return _super_check_offset; }
aoqi@0 218 void set_super_check_offset(juint o) { _super_check_offset = o; }
aoqi@0 219
aoqi@0 220 Klass* secondary_super_cache() const { return _secondary_super_cache; }
aoqi@0 221 void set_secondary_super_cache(Klass* k) { _secondary_super_cache = k; }
aoqi@0 222
aoqi@0 223 Array<Klass*>* secondary_supers() const { return _secondary_supers; }
aoqi@0 224 void set_secondary_supers(Array<Klass*>* k) { _secondary_supers = k; }
aoqi@0 225
aoqi@0 226 // Return the element of the _super chain of the given depth.
aoqi@0 227 // If there is no such element, return either NULL or this.
aoqi@0 228 Klass* primary_super_of_depth(juint i) const {
aoqi@0 229 assert(i < primary_super_limit(), "oob");
aoqi@0 230 Klass* super = _primary_supers[i];
aoqi@0 231 assert(super == NULL || super->super_depth() == i, "correct display");
aoqi@0 232 return super;
aoqi@0 233 }
aoqi@0 234
aoqi@0 235 // Can this klass be a primary super? False for interfaces and arrays of
aoqi@0 236 // interfaces. False also for arrays or classes with long super chains.
aoqi@0 237 bool can_be_primary_super() const {
aoqi@0 238 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
aoqi@0 239 return super_check_offset() != secondary_offset;
aoqi@0 240 }
aoqi@0 241 virtual bool can_be_primary_super_slow() const;
aoqi@0 242
aoqi@0 243 // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit].
aoqi@0 244 juint super_depth() const {
aoqi@0 245 if (!can_be_primary_super()) {
aoqi@0 246 return primary_super_limit();
aoqi@0 247 } else {
aoqi@0 248 juint d = (super_check_offset() - in_bytes(primary_supers_offset())) / sizeof(Klass*);
aoqi@0 249 assert(d < primary_super_limit(), "oob");
aoqi@0 250 assert(_primary_supers[d] == this, "proper init");
aoqi@0 251 return d;
aoqi@0 252 }
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 // store an oop into a field of a Klass
aoqi@0 256 void klass_oop_store(oop* p, oop v);
aoqi@0 257 void klass_oop_store(volatile oop* p, oop v);
aoqi@0 258
aoqi@0 259 // java mirror
aoqi@0 260 oop java_mirror() const { return _java_mirror; }
aoqi@0 261 void set_java_mirror(oop m) { klass_oop_store(&_java_mirror, m); }
aoqi@0 262
aoqi@0 263 // modifier flags
aoqi@0 264 jint modifier_flags() const { return _modifier_flags; }
aoqi@0 265 void set_modifier_flags(jint flags) { _modifier_flags = flags; }
aoqi@0 266
aoqi@0 267 // size helper
aoqi@0 268 int layout_helper() const { return _layout_helper; }
aoqi@0 269 void set_layout_helper(int lh) { _layout_helper = lh; }
aoqi@0 270
aoqi@0 271 // Note: for instances layout_helper() may include padding.
aoqi@0 272 // Use InstanceKlass::contains_field_offset to classify field offsets.
aoqi@0 273
aoqi@0 274 // sub/superklass links
aoqi@0 275 InstanceKlass* superklass() const;
aoqi@0 276 Klass* subklass() const;
aoqi@0 277 Klass* next_sibling() const;
aoqi@0 278 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
aoqi@0 279
aoqi@0 280 void set_next_link(Klass* k) { _next_link = k; }
aoqi@0 281 Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
aoqi@0 282
aoqi@0 283 // class loader data
aoqi@0 284 ClassLoaderData* class_loader_data() const { return _class_loader_data; }
aoqi@0 285 void set_class_loader_data(ClassLoaderData* loader_data) { _class_loader_data = loader_data; }
aoqi@0 286
aoqi@0 287 // The Klasses are not placed in the Heap, so the Card Table or
aoqi@0 288 // the Mod Union Table can't be used to mark when klasses have modified oops.
aoqi@0 289 // The CT and MUT bits saves this information for the individual Klasses.
aoqi@8019 290 void record_modified_oops() {
aoqi@8019 291 _modified_oops = 1;
fujie@135 292 #ifdef MIPS64
aoqi@8019 293 if (UseSyncLevel >= 2000) OrderAccess::fence();
aoqi@8019 294 #endif
fujie@135 295 }
aoqi@8019 296 void clear_modified_oops() {
aoqi@8019 297 _modified_oops = 0;
fujie@135 298 #ifdef MIPS64
aoqi@8019 299 if (UseSyncLevel >= 2000) OrderAccess::fence();
aoqi@8019 300 #endif
fujie@135 301 }
aoqi@0 302 bool has_modified_oops() { return _modified_oops == 1; }
aoqi@0 303
aoqi@0 304 void accumulate_modified_oops() { if (has_modified_oops()) _accumulated_modified_oops = 1; }
aoqi@0 305 void clear_accumulated_modified_oops() { _accumulated_modified_oops = 0; }
aoqi@0 306 bool has_accumulated_modified_oops() { return _accumulated_modified_oops == 1; }
aoqi@0 307
iklam@7089 308 int shared_classpath_index() const {
iklam@7089 309 return _shared_class_path_index;
iklam@7089 310 };
iklam@7089 311
iklam@7089 312 void set_shared_classpath_index(int index) {
iklam@7089 313 _shared_class_path_index = index;
iklam@7089 314 };
iklam@7089 315
iklam@7089 316
aoqi@0 317 protected: // internal accessors
aoqi@0 318 Klass* subklass_oop() const { return _subklass; }
aoqi@0 319 Klass* next_sibling_oop() const { return _next_sibling; }
aoqi@0 320 void set_subklass(Klass* s);
aoqi@0 321 void set_next_sibling(Klass* s);
aoqi@0 322
aoqi@0 323 public:
aoqi@0 324
aoqi@0 325 // Compiler support
aoqi@0 326 static ByteSize super_offset() { return in_ByteSize(offset_of(Klass, _super)); }
aoqi@0 327 static ByteSize super_check_offset_offset() { return in_ByteSize(offset_of(Klass, _super_check_offset)); }
aoqi@0 328 static ByteSize primary_supers_offset() { return in_ByteSize(offset_of(Klass, _primary_supers)); }
aoqi@0 329 static ByteSize secondary_super_cache_offset() { return in_ByteSize(offset_of(Klass, _secondary_super_cache)); }
aoqi@0 330 static ByteSize secondary_supers_offset() { return in_ByteSize(offset_of(Klass, _secondary_supers)); }
aoqi@0 331 static ByteSize java_mirror_offset() { return in_ByteSize(offset_of(Klass, _java_mirror)); }
aoqi@0 332 static ByteSize modifier_flags_offset() { return in_ByteSize(offset_of(Klass, _modifier_flags)); }
aoqi@0 333 static ByteSize layout_helper_offset() { return in_ByteSize(offset_of(Klass, _layout_helper)); }
aoqi@0 334 static ByteSize access_flags_offset() { return in_ByteSize(offset_of(Klass, _access_flags)); }
aoqi@0 335
aoqi@0 336 // Unpacking layout_helper:
aoqi@0 337 enum {
aoqi@0 338 _lh_neutral_value = 0, // neutral non-array non-instance value
aoqi@0 339 _lh_instance_slow_path_bit = 0x01,
aoqi@0 340 _lh_log2_element_size_shift = BitsPerByte*0,
aoqi@0 341 _lh_log2_element_size_mask = BitsPerLong-1,
aoqi@0 342 _lh_element_type_shift = BitsPerByte*1,
aoqi@0 343 _lh_element_type_mask = right_n_bits(BitsPerByte), // shifted mask
aoqi@0 344 _lh_header_size_shift = BitsPerByte*2,
aoqi@0 345 _lh_header_size_mask = right_n_bits(BitsPerByte), // shifted mask
aoqi@0 346 _lh_array_tag_bits = 2,
aoqi@0 347 _lh_array_tag_shift = BitsPerInt - _lh_array_tag_bits,
aoqi@0 348 _lh_array_tag_type_value = ~0x00, // 0xC0000000 >> 30
aoqi@0 349 _lh_array_tag_obj_value = ~0x01 // 0x80000000 >> 30
aoqi@0 350 };
aoqi@0 351
aoqi@0 352 static int layout_helper_size_in_bytes(jint lh) {
aoqi@0 353 assert(lh > (jint)_lh_neutral_value, "must be instance");
aoqi@0 354 return (int) lh & ~_lh_instance_slow_path_bit;
aoqi@0 355 }
aoqi@0 356 static bool layout_helper_needs_slow_path(jint lh) {
aoqi@0 357 assert(lh > (jint)_lh_neutral_value, "must be instance");
aoqi@0 358 return (lh & _lh_instance_slow_path_bit) != 0;
aoqi@0 359 }
aoqi@0 360 static bool layout_helper_is_instance(jint lh) {
aoqi@0 361 return (jint)lh > (jint)_lh_neutral_value;
aoqi@0 362 }
aoqi@0 363 static bool layout_helper_is_array(jint lh) {
aoqi@0 364 return (jint)lh < (jint)_lh_neutral_value;
aoqi@0 365 }
aoqi@0 366 static bool layout_helper_is_typeArray(jint lh) {
aoqi@0 367 // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
aoqi@0 368 return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
aoqi@0 369 }
aoqi@0 370 static bool layout_helper_is_objArray(jint lh) {
aoqi@0 371 // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
aoqi@0 372 return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);
aoqi@0 373 }
aoqi@0 374 static int layout_helper_header_size(jint lh) {
aoqi@0 375 assert(lh < (jint)_lh_neutral_value, "must be array");
aoqi@0 376 int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
aoqi@0 377 assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
aoqi@0 378 return hsize;
aoqi@0 379 }
aoqi@0 380 static BasicType layout_helper_element_type(jint lh) {
aoqi@0 381 assert(lh < (jint)_lh_neutral_value, "must be array");
aoqi@0 382 int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
aoqi@0 383 assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity");
aoqi@0 384 return (BasicType) btvalue;
aoqi@0 385 }
aoqi@0 386 static int layout_helper_log2_element_size(jint lh) {
aoqi@0 387 assert(lh < (jint)_lh_neutral_value, "must be array");
aoqi@0 388 int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
aoqi@0 389 assert(l2esz <= LogBitsPerLong,
aoqi@0 390 err_msg("sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh));
aoqi@0 391 return l2esz;
aoqi@0 392 }
aoqi@0 393 static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
aoqi@0 394 return (tag << _lh_array_tag_shift)
aoqi@0 395 | (hsize << _lh_header_size_shift)
aoqi@0 396 | ((int)etype << _lh_element_type_shift)
aoqi@0 397 | (log2_esize << _lh_log2_element_size_shift);
aoqi@0 398 }
aoqi@0 399 static jint instance_layout_helper(jint size, bool slow_path_flag) {
aoqi@0 400 return (size << LogHeapWordSize)
aoqi@0 401 | (slow_path_flag ? _lh_instance_slow_path_bit : 0);
aoqi@0 402 }
aoqi@0 403 static int layout_helper_to_size_helper(jint lh) {
aoqi@0 404 assert(lh > (jint)_lh_neutral_value, "must be instance");
aoqi@0 405 // Note that the following expression discards _lh_instance_slow_path_bit.
aoqi@0 406 return lh >> LogHeapWordSize;
aoqi@0 407 }
aoqi@0 408 // Out-of-line version computes everything based on the etype:
aoqi@0 409 static jint array_layout_helper(BasicType etype);
aoqi@0 410
aoqi@0 411 // What is the maximum number of primary superclasses any klass can have?
aoqi@0 412 #ifdef PRODUCT
aoqi@0 413 static juint primary_super_limit() { return _primary_super_limit; }
aoqi@0 414 #else
aoqi@0 415 static juint primary_super_limit() {
aoqi@0 416 assert(FastSuperclassLimit <= _primary_super_limit, "parameter oob");
aoqi@0 417 return FastSuperclassLimit;
aoqi@0 418 }
aoqi@0 419 #endif
aoqi@0 420
aoqi@0 421 // vtables
aoqi@0 422 virtual klassVtable* vtable() const { return NULL; }
aoqi@0 423 virtual int vtable_length() const { return 0; }
aoqi@0 424
aoqi@0 425 // subclass check
aoqi@0 426 bool is_subclass_of(const Klass* k) const;
aoqi@0 427 // subtype check: true if is_subclass_of, or if k is interface and receiver implements it
aoqi@0 428 bool is_subtype_of(Klass* k) const {
aoqi@0 429 juint off = k->super_check_offset();
aoqi@0 430 Klass* sup = *(Klass**)( (address)this + off );
aoqi@0 431 const juint secondary_offset = in_bytes(secondary_super_cache_offset());
aoqi@0 432 if (sup == k) {
aoqi@0 433 return true;
aoqi@0 434 } else if (off != secondary_offset) {
aoqi@0 435 return false;
aoqi@0 436 } else {
aoqi@0 437 return search_secondary_supers(k);
aoqi@0 438 }
aoqi@0 439 }
aoqi@0 440 bool search_secondary_supers(Klass* k) const;
aoqi@0 441
aoqi@0 442 // Find LCA in class hierarchy
aoqi@0 443 Klass *LCA( Klass *k );
aoqi@0 444
aoqi@0 445 // Check whether reflection/jni/jvm code is allowed to instantiate this class;
aoqi@0 446 // if not, throw either an Error or an Exception.
aoqi@0 447 virtual void check_valid_for_instantiation(bool throwError, TRAPS);
aoqi@0 448
aoqi@0 449 // array copying
aoqi@0 450 virtual void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
aoqi@0 451
aoqi@0 452 // tells if the class should be initialized
aoqi@0 453 virtual bool should_be_initialized() const { return false; }
aoqi@0 454 // initializes the klass
aoqi@0 455 virtual void initialize(TRAPS);
aoqi@0 456 // lookup operation for MethodLookupCache
aoqi@0 457 friend class MethodLookupCache;
aoqi@0 458 virtual Klass* find_field(Symbol* name, Symbol* signature, fieldDescriptor* fd) const;
aoqi@0 459 virtual Method* uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const;
aoqi@0 460 public:
aoqi@0 461 Method* lookup_method(Symbol* name, Symbol* signature) const {
aoqi@0 462 return uncached_lookup_method(name, signature, normal);
aoqi@0 463 }
aoqi@0 464
aoqi@0 465 // array class with specific rank
aoqi@0 466 Klass* array_klass(int rank, TRAPS) { return array_klass_impl(false, rank, THREAD); }
aoqi@0 467
aoqi@0 468 // array class with this klass as element type
aoqi@0 469 Klass* array_klass(TRAPS) { return array_klass_impl(false, THREAD); }
aoqi@0 470
aoqi@0 471 // These will return NULL instead of allocating on the heap:
aoqi@0 472 // NB: these can block for a mutex, like other functions with TRAPS arg.
aoqi@0 473 Klass* array_klass_or_null(int rank);
aoqi@0 474 Klass* array_klass_or_null();
aoqi@0 475
aoqi@0 476 virtual oop protection_domain() const = 0;
aoqi@0 477
aoqi@0 478 oop class_loader() const;
aoqi@0 479
aoqi@0 480 virtual oop klass_holder() const { return class_loader(); }
aoqi@0 481
aoqi@0 482 protected:
aoqi@0 483 virtual Klass* array_klass_impl(bool or_null, int rank, TRAPS);
aoqi@0 484 virtual Klass* array_klass_impl(bool or_null, TRAPS);
aoqi@0 485
aoqi@0 486 public:
aoqi@0 487 // CDS support - remove and restore oops from metadata. Oops are not shared.
aoqi@0 488 virtual void remove_unshareable_info();
iklam@7089 489 virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
aoqi@0 490
aoqi@0 491 protected:
aoqi@0 492 // computes the subtype relationship
aoqi@0 493 virtual bool compute_is_subtype_of(Klass* k);
aoqi@0 494 public:
aoqi@0 495 // subclass accessor (here for convenience; undefined for non-klass objects)
aoqi@0 496 virtual bool is_leaf_class() const { fatal("not a class"); return false; }
aoqi@0 497 public:
aoqi@0 498 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP
aoqi@0 499 // These functions describe behavior for the oop not the KLASS.
aoqi@0 500
aoqi@0 501 // actual oop size of obj in memory
aoqi@0 502 virtual int oop_size(oop obj) const = 0;
aoqi@0 503
aoqi@0 504 // Size of klass in word size.
aoqi@0 505 virtual int size() const = 0;
aoqi@0 506 #if INCLUDE_SERVICES
aoqi@0 507 virtual void collect_statistics(KlassSizeStats *sz) const;
aoqi@0 508 #endif
aoqi@0 509
aoqi@0 510 // Returns the Java name for a class (Resource allocated)
aoqi@0 511 // For arrays, this returns the name of the element with a leading '['.
aoqi@0 512 // For classes, this returns the name with the package separators
aoqi@0 513 // turned into '.'s.
aoqi@0 514 const char* external_name() const;
aoqi@0 515 // Returns the name for a class (Resource allocated) as the class
aoqi@0 516 // would appear in a signature.
aoqi@0 517 // For arrays, this returns the name of the element with a leading '['.
aoqi@0 518 // For classes, this returns the name with a leading 'L' and a trailing ';'
aoqi@0 519 // and the package separators as '/'.
aoqi@0 520 virtual const char* signature_name() const;
aoqi@0 521
aoqi@0 522 // garbage collection support
aoqi@0 523 virtual void oop_follow_contents(oop obj) = 0;
aoqi@0 524 virtual int oop_adjust_pointers(oop obj) = 0;
aoqi@0 525
aoqi@0 526 // Parallel Scavenge and Parallel Old
aoqi@0 527 PARALLEL_GC_DECLS_PV
aoqi@0 528
aoqi@0 529 // type testing operations
aoqi@0 530 protected:
aoqi@0 531 virtual bool oop_is_instance_slow() const { return false; }
aoqi@0 532 virtual bool oop_is_array_slow() const { return false; }
aoqi@0 533 virtual bool oop_is_objArray_slow() const { return false; }
aoqi@0 534 virtual bool oop_is_typeArray_slow() const { return false; }
aoqi@0 535 public:
stefank@6976 536 virtual bool oop_is_instanceClassLoader() const { return false; }
aoqi@0 537 virtual bool oop_is_instanceMirror() const { return false; }
aoqi@0 538 virtual bool oop_is_instanceRef() const { return false; }
aoqi@0 539
aoqi@0 540 // Fast non-virtual versions
aoqi@0 541 #ifndef ASSERT
aoqi@0 542 #define assert_same_query(xval, xcheck) xval
aoqi@0 543 #else
aoqi@0 544 private:
aoqi@0 545 static bool assert_same_query(bool xval, bool xslow) {
aoqi@0 546 assert(xval == xslow, "slow and fast queries agree");
aoqi@0 547 return xval;
aoqi@0 548 }
aoqi@0 549 public:
aoqi@0 550 #endif
aoqi@0 551 inline bool oop_is_instance() const { return assert_same_query(
aoqi@0 552 layout_helper_is_instance(layout_helper()),
aoqi@0 553 oop_is_instance_slow()); }
aoqi@0 554 inline bool oop_is_array() const { return assert_same_query(
aoqi@0 555 layout_helper_is_array(layout_helper()),
aoqi@0 556 oop_is_array_slow()); }
aoqi@0 557 inline bool oop_is_objArray() const { return assert_same_query(
aoqi@0 558 layout_helper_is_objArray(layout_helper()),
aoqi@0 559 oop_is_objArray_slow()); }
aoqi@0 560 inline bool oop_is_typeArray() const { return assert_same_query(
aoqi@0 561 layout_helper_is_typeArray(layout_helper()),
aoqi@0 562 oop_is_typeArray_slow()); }
aoqi@0 563 #undef assert_same_query
aoqi@0 564
aoqi@0 565 // Access flags
aoqi@0 566 AccessFlags access_flags() const { return _access_flags; }
aoqi@0 567 void set_access_flags(AccessFlags flags) { _access_flags = flags; }
aoqi@0 568
aoqi@0 569 bool is_public() const { return _access_flags.is_public(); }
aoqi@0 570 bool is_final() const { return _access_flags.is_final(); }
aoqi@0 571 bool is_interface() const { return _access_flags.is_interface(); }
aoqi@0 572 bool is_abstract() const { return _access_flags.is_abstract(); }
aoqi@0 573 bool is_super() const { return _access_flags.is_super(); }
aoqi@0 574 bool is_synthetic() const { return _access_flags.is_synthetic(); }
aoqi@0 575 void set_is_synthetic() { _access_flags.set_is_synthetic(); }
aoqi@0 576 bool has_finalizer() const { return _access_flags.has_finalizer(); }
aoqi@0 577 bool has_final_method() const { return _access_flags.has_final_method(); }
aoqi@0 578 void set_has_finalizer() { _access_flags.set_has_finalizer(); }
aoqi@0 579 void set_has_final_method() { _access_flags.set_has_final_method(); }
aoqi@0 580 bool is_cloneable() const { return _access_flags.is_cloneable(); }
aoqi@0 581 void set_is_cloneable() { _access_flags.set_is_cloneable(); }
aoqi@0 582 bool has_vanilla_constructor() const { return _access_flags.has_vanilla_constructor(); }
aoqi@0 583 void set_has_vanilla_constructor() { _access_flags.set_has_vanilla_constructor(); }
aoqi@0 584 bool has_miranda_methods () const { return access_flags().has_miranda_methods(); }
aoqi@0 585 void set_has_miranda_methods() { _access_flags.set_has_miranda_methods(); }
aoqi@0 586
aoqi@0 587 // Biased locking support
aoqi@0 588 // Note: the prototype header is always set up to be at least the
aoqi@0 589 // prototype markOop. If biased locking is enabled it may further be
aoqi@0 590 // biasable and have an epoch.
aoqi@0 591 markOop prototype_header() const { return _prototype_header; }
aoqi@0 592 // NOTE: once instances of this klass are floating around in the
aoqi@0 593 // system, this header must only be updated at a safepoint.
aoqi@0 594 // NOTE 2: currently we only ever set the prototype header to the
aoqi@0 595 // biasable prototype for instanceKlasses. There is no technical
aoqi@0 596 // reason why it could not be done for arrayKlasses aside from
aoqi@0 597 // wanting to reduce the initial scope of this optimization. There
aoqi@0 598 // are potential problems in setting the bias pattern for
aoqi@0 599 // JVM-internal oops.
aoqi@0 600 inline void set_prototype_header(markOop header);
aoqi@0 601 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
aoqi@0 602
aoqi@0 603 int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
aoqi@0 604 // Atomically increments biased_lock_revocation_count and returns updated value
aoqi@0 605 int atomic_incr_biased_lock_revocation_count();
aoqi@0 606 void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
aoqi@0 607 jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
aoqi@0 608 void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
aoqi@0 609
aoqi@0 610 TRACE_DEFINE_KLASS_METHODS;
aoqi@0 611
aoqi@0 612 // garbage collection support
aoqi@0 613 virtual void oops_do(OopClosure* cl);
aoqi@0 614
aoqi@0 615 // Iff the class loader (or mirror for anonymous classes) is alive the
aoqi@0 616 // Klass is considered alive.
aoqi@0 617 // The is_alive closure passed in depends on the Garbage Collector used.
aoqi@0 618 bool is_loader_alive(BoolObjectClosure* is_alive);
aoqi@0 619
stefank@6992 620 static void clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses = true);
stefank@6992 621 static void clean_subklass_tree(BoolObjectClosure* is_alive) {
stefank@6992 622 clean_weak_klass_links(is_alive, false /* clean_alive_klasses */);
aoqi@0 623 }
aoqi@0 624
aoqi@0 625 // iterators
aoqi@0 626 virtual int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) = 0;
aoqi@0 627 virtual int oop_oop_iterate_v(oop obj, ExtendedOopClosure* blk) {
aoqi@0 628 return oop_oop_iterate(obj, blk);
aoqi@0 629 }
aoqi@0 630
aoqi@0 631 #if INCLUDE_ALL_GCS
aoqi@0 632 // In case we don't have a specialized backward scanner use forward
aoqi@0 633 // iteration.
aoqi@0 634 virtual int oop_oop_iterate_backwards_v(oop obj, ExtendedOopClosure* blk) {
aoqi@0 635 return oop_oop_iterate_v(obj, blk);
aoqi@0 636 }
aoqi@0 637 #endif // INCLUDE_ALL_GCS
aoqi@0 638
aoqi@0 639 // Iterates "blk" over all the oops in "obj" (of type "this") within "mr".
aoqi@0 640 // (I don't see why the _m should be required, but without it the Solaris
aoqi@0 641 // C++ gives warning messages about overridings of the "oop_oop_iterate"
aoqi@0 642 // defined above "hiding" this virtual function. (DLD, 6/20/00)) */
aoqi@0 643 virtual int oop_oop_iterate_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) = 0;
aoqi@0 644 virtual int oop_oop_iterate_v_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) {
aoqi@0 645 return oop_oop_iterate_m(obj, blk, mr);
aoqi@0 646 }
aoqi@0 647
aoqi@0 648 // Versions of the above iterators specialized to particular subtypes
aoqi@0 649 // of OopClosure, to avoid closure virtual calls.
aoqi@0 650 #define Klass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
aoqi@0 651 virtual int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk) { \
aoqi@0 652 /* Default implementation reverts to general version. */ \
aoqi@0 653 return oop_oop_iterate(obj, blk); \
aoqi@0 654 } \
aoqi@0 655 \
aoqi@0 656 /* Iterates "blk" over all the oops in "obj" (of type "this") within "mr". \
aoqi@0 657 (I don't see why the _m should be required, but without it the Solaris \
aoqi@0 658 C++ gives warning messages about overridings of the "oop_oop_iterate" \
aoqi@0 659 defined above "hiding" this virtual function. (DLD, 6/20/00)) */ \
aoqi@0 660 virtual int oop_oop_iterate##nv_suffix##_m(oop obj, \
aoqi@0 661 OopClosureType* blk, \
aoqi@0 662 MemRegion mr) { \
aoqi@0 663 return oop_oop_iterate_m(obj, blk, mr); \
aoqi@0 664 }
aoqi@0 665
aoqi@0 666 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_DECL)
aoqi@0 667 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_DECL)
aoqi@0 668
aoqi@0 669 #if INCLUDE_ALL_GCS
aoqi@0 670 #define Klass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix) \
aoqi@0 671 virtual int oop_oop_iterate_backwards##nv_suffix(oop obj, \
aoqi@0 672 OopClosureType* blk) { \
aoqi@0 673 /* Default implementation reverts to general version. */ \
aoqi@0 674 return oop_oop_iterate_backwards_v(obj, blk); \
aoqi@0 675 }
aoqi@0 676
aoqi@0 677 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL)
aoqi@0 678 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL)
aoqi@0 679 #endif // INCLUDE_ALL_GCS
aoqi@0 680
aoqi@0 681 virtual void array_klasses_do(void f(Klass* k)) {}
aoqi@0 682
aoqi@0 683 // Return self, except for abstract classes with exactly 1
aoqi@0 684 // implementor. Then return the 1 concrete implementation.
aoqi@0 685 Klass *up_cast_abstract();
aoqi@0 686
aoqi@0 687 // klass name
aoqi@0 688 Symbol* name() const { return _name; }
aoqi@0 689 void set_name(Symbol* n);
aoqi@0 690
aoqi@0 691 public:
aoqi@0 692 // jvm support
aoqi@0 693 virtual jint compute_modifier_flags(TRAPS) const;
aoqi@0 694
aoqi@0 695 // JVMTI support
aoqi@0 696 virtual jint jvmti_class_status() const;
aoqi@0 697
aoqi@0 698 // Printing
aoqi@0 699 virtual void print_on(outputStream* st) const;
aoqi@0 700
aoqi@0 701 virtual void oop_print_value_on(oop obj, outputStream* st);
aoqi@0 702 virtual void oop_print_on (oop obj, outputStream* st);
aoqi@0 703
aoqi@0 704 virtual const char* internal_name() const = 0;
aoqi@0 705
aoqi@0 706 // Verification
aoqi@0 707 virtual void verify_on(outputStream* st);
aoqi@0 708 void verify() { verify_on(tty); }
aoqi@0 709
aoqi@0 710 #ifndef PRODUCT
aoqi@0 711 bool verify_vtable_index(int index);
aoqi@0 712 bool verify_itable_index(int index);
aoqi@0 713 #endif
aoqi@0 714
aoqi@0 715 virtual void oop_verify_on(oop obj, outputStream* st);
aoqi@0 716
aoqi@0 717 static bool is_null(narrowKlass obj);
aoqi@0 718 static bool is_null(Klass* obj);
aoqi@0 719
aoqi@0 720 // klass encoding for klass pointer in objects.
aoqi@0 721 static narrowKlass encode_klass_not_null(Klass* v);
aoqi@0 722 static narrowKlass encode_klass(Klass* v);
aoqi@0 723
aoqi@0 724 static Klass* decode_klass_not_null(narrowKlass v);
aoqi@0 725 static Klass* decode_klass(narrowKlass v);
aoqi@0 726
aoqi@0 727 private:
aoqi@0 728 // barriers used by klass_oop_store
aoqi@0 729 void klass_update_barrier_set(oop v);
stefank@6992 730 void klass_update_barrier_set_pre(oop* p, oop v);
aoqi@0 731 };
aoqi@0 732
aoqi@0 733 #endif // SHARE_VM_OOPS_KLASS_HPP

mercurial