src/share/vm/oops/klass.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6830
54bc75c144b0
parent 135
5b3263131a49
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial