src/share/vm/oops/klass.hpp

Wed, 11 Jan 2012 17:34:02 -0500

author
phh
date
Wed, 11 Jan 2012 17:34:02 -0500
changeset 3427
94ec88ca68e2
parent 2658
c7f3d0b4570f
child 3428
4f3ce9284781
permissions
-rw-r--r--

7115199: Add event tracing hooks and Java Flight Recorder infrastructure
Summary: Added a nop tracing infrastructure, JFR makefile changes and other infrastructure used only by JFR.
Reviewed-by: acorn, sspitsyn
Contributed-by: markus.gronlund@oracle.com

duke@435 1 /*
never@2658 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_OOPS_KLASS_HPP
stefank@2314 26 #define SHARE_VM_OOPS_KLASS_HPP
stefank@2314 27
stefank@2314 28 #include "memory/genOopClosures.hpp"
stefank@2314 29 #include "memory/iterator.hpp"
stefank@2314 30 #include "memory/memRegion.hpp"
stefank@2314 31 #include "memory/specialized_oop_closures.hpp"
stefank@2314 32 #include "oops/klassOop.hpp"
stefank@2314 33 #include "oops/klassPS.hpp"
stefank@2314 34 #include "oops/oop.hpp"
stefank@2314 35 #include "runtime/orderAccess.hpp"
phh@3427 36 #include "trace/traceMacros.hpp"
stefank@2314 37 #include "utilities/accessFlags.hpp"
stefank@2314 38 #ifndef SERIALGC
stefank@2314 39 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp"
stefank@2314 40 #include "gc_implementation/g1/g1OopClosures.hpp"
stefank@2314 41 #include "gc_implementation/parNew/parOopClosures.hpp"
stefank@2314 42 #endif
stefank@2314 43
duke@435 44 // A Klass is the part of the klassOop that provides:
duke@435 45 // 1: language level class object (method dictionary etc.)
duke@435 46 // 2: provide vm dispatch behavior for the object
duke@435 47 // Both functions are combined into one C++ class. The toplevel class "Klass"
duke@435 48 // implements purpose 1 whereas all subclasses provide extra virtual functions
duke@435 49 // for purpose 2.
duke@435 50
duke@435 51 // One reason for the oop/klass dichotomy in the implementation is
duke@435 52 // that we don't want a C++ vtbl pointer in every object. Thus,
duke@435 53 // normal oops don't have any virtual functions. Instead, they
duke@435 54 // forward all "virtual" functions to their klass, which does have
duke@435 55 // a vtbl and does the C++ dispatch depending on the object's
duke@435 56 // actual type. (See oop.inline.hpp for some of the forwarding code.)
duke@435 57 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
duke@435 58
duke@435 59 // Klass layout:
duke@435 60 // [header ] klassOop
duke@435 61 // [klass pointer ] klassOop
duke@435 62 // [C++ vtbl ptr ] (contained in Klass_vtbl)
duke@435 63 // [layout_helper ]
duke@435 64 // [super_check_offset ] for fast subtype checks
duke@435 65 // [secondary_super_cache] for fast subtype checks
duke@435 66 // [secondary_supers ] array of 2ndary supertypes
duke@435 67 // [primary_supers 0]
duke@435 68 // [primary_supers 1]
duke@435 69 // [primary_supers 2]
duke@435 70 // ...
duke@435 71 // [primary_supers 7]
duke@435 72 // [java_mirror ]
duke@435 73 // [super ]
duke@435 74 // [name ]
duke@435 75 // [first subklass]
duke@435 76 // [next_sibling ] link to chain additional subklasses
duke@435 77 // [modifier_flags]
duke@435 78 // [access_flags ]
duke@435 79 // [verify_count ] - not in product
duke@435 80 // [alloc_count ]
duke@435 81 // [last_biased_lock_bulk_revocation_time] (64 bits)
duke@435 82 // [prototype_header]
duke@435 83 // [biased_lock_revocation_count]
phh@3427 84 // [trace_id]
duke@435 85
duke@435 86
duke@435 87 // Forward declarations.
duke@435 88 class klassVtable;
duke@435 89 class KlassHandle;
duke@435 90 class OrderAccess;
duke@435 91
duke@435 92 // Holder (or cage) for the C++ vtable of each kind of Klass.
duke@435 93 // We want to tightly constrain the location of the C++ vtable in the overall layout.
duke@435 94 class Klass_vtbl {
duke@435 95 protected:
duke@435 96 // The following virtual exists only to force creation of a C++ vtable,
duke@435 97 // so that this class truly is the location of the vtable of all Klasses.
duke@435 98 virtual void unused_initial_virtual() { }
duke@435 99
duke@435 100 public:
duke@435 101 // The following virtual makes Klass_vtbl play a second role as a
duke@435 102 // factory protocol for subclasses of Klass ("sub-Klasses").
duke@435 103 // Here's how it works....
duke@435 104 //
duke@435 105 // This VM uses metaobjects as factories for their instances.
duke@435 106 //
duke@435 107 // In order to initialize the C++ vtable of a new instance, its
duke@435 108 // metaobject is forced to use the C++ placed new operator to
duke@435 109 // allocate the instance. In a typical C++-based system, each
duke@435 110 // sub-class would have its own factory routine which
duke@435 111 // directly uses the placed new operator on the desired class,
duke@435 112 // and then calls the appropriate chain of C++ constructors.
duke@435 113 //
duke@435 114 // However, this system uses shared code to performs the first
duke@435 115 // allocation and initialization steps for all sub-Klasses.
duke@435 116 // (See base_create_klass() and base_create_array_klass().)
duke@435 117 // This does not factor neatly into a hierarchy of C++ constructors.
duke@435 118 // Each caller of these shared "base_create" routines knows
duke@435 119 // exactly which sub-Klass it is creating, but the shared routine
duke@435 120 // does not, even though it must perform the actual allocation.
duke@435 121 //
duke@435 122 // Therefore, the caller of the shared "base_create" must wrap
duke@435 123 // the specific placed new call in a virtual function which
duke@435 124 // performs the actual allocation and vtable set-up. That
duke@435 125 // virtual function is here, Klass_vtbl::allocate_permanent.
duke@435 126 //
duke@435 127 // The arguments to Universe::allocate_permanent() are passed
duke@435 128 // straight through the placed new operator, which in turn
duke@435 129 // obtains them directly from this virtual call.
duke@435 130 //
duke@435 131 // This virtual is called on a temporary "example instance" of the
duke@435 132 // sub-Klass being instantiated, a C++ auto variable. The "real"
duke@435 133 // instance created by this virtual is on the VM heap, where it is
duke@435 134 // equipped with a klassOopDesc header.
duke@435 135 //
duke@435 136 // It is merely an accident of implementation that we use "example
duke@435 137 // instances", but that is why the virtual function which implements
duke@435 138 // each sub-Klass factory happens to be defined by the same sub-Klass
duke@435 139 // for which it creates instances.
duke@435 140 //
duke@435 141 // The vtbl_value() call (see below) is used to strip away the
duke@435 142 // accidental Klass-ness from an "example instance" and present it as
duke@435 143 // a factory. Think of each factory object as a mere container of the
duke@435 144 // C++ vtable for the desired sub-Klass. Since C++ does not allow
duke@435 145 // direct references to vtables, the factory must also be delegated
duke@435 146 // the task of allocating the instance, but the essential point is
duke@435 147 // that the factory knows how to initialize the C++ vtable with the
duke@435 148 // right pointer value. All other common initializations are handled
duke@435 149 // by the shared "base_create" subroutines.
duke@435 150 //
duke@435 151 virtual void* allocate_permanent(KlassHandle& klass, int size, TRAPS) const = 0;
duke@435 152 void post_new_init_klass(KlassHandle& klass, klassOop obj, int size) const;
duke@435 153
duke@435 154 // Every subclass on which vtbl_value is called must include this macro.
duke@435 155 // Delay the installation of the klassKlass pointer until after the
duke@435 156 // the vtable for a new klass has been installed (after the call to new()).
ysr@777 157 #define DEFINE_ALLOCATE_PERMANENT(thisKlass) \
duke@435 158 void* allocate_permanent(KlassHandle& klass_klass, int size, TRAPS) const { \
ysr@777 159 void* result = new(klass_klass, size, THREAD) thisKlass(); \
ysr@777 160 if (HAS_PENDING_EXCEPTION) return NULL; \
ysr@777 161 klassOop new_klass = ((Klass*) result)->as_klassOop(); \
ysr@777 162 OrderAccess::storestore(); \
ysr@777 163 post_new_init_klass(klass_klass, new_klass, size); \
ysr@777 164 return result; \
duke@435 165 }
duke@435 166
duke@435 167 bool null_vtbl() { return *(intptr_t*)this == 0; }
duke@435 168
duke@435 169 protected:
duke@435 170 void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
duke@435 171 };
duke@435 172
duke@435 173
duke@435 174 class Klass : public Klass_vtbl {
duke@435 175 friend class VMStructs;
duke@435 176 protected:
duke@435 177 // note: put frequently-used fields together at start of klass structure
duke@435 178 // for better cache behavior (may not make much of a difference but sure won't hurt)
duke@435 179 enum { _primary_super_limit = 8 };
duke@435 180
duke@435 181 // The "layout helper" is a combined descriptor of object layout.
duke@435 182 // For klasses which are neither instance nor array, the value is zero.
duke@435 183 //
duke@435 184 // For instances, layout helper is a positive number, the instance size.
duke@435 185 // This size is already passed through align_object_size and scaled to bytes.
duke@435 186 // The low order bit is set if instances of this class cannot be
duke@435 187 // allocated using the fastpath.
duke@435 188 //
duke@435 189 // For arrays, layout helper is a negative number, containing four
duke@435 190 // distinct bytes, as follows:
duke@435 191 // MSB:[tag, hsz, ebt, log2(esz)]:LSB
duke@435 192 // where:
duke@435 193 // tag is 0x80 if the elements are oops, 0xC0 if non-oops
duke@435 194 // hsz is array header size in bytes (i.e., offset of first element)
duke@435 195 // ebt is the BasicType of the elements
duke@435 196 // esz is the element size in bytes
duke@435 197 // This packed word is arranged so as to be quickly unpacked by the
duke@435 198 // various fast paths that use the various subfields.
duke@435 199 //
duke@435 200 // The esz bits can be used directly by a SLL instruction, without masking.
duke@435 201 //
duke@435 202 // Note that the array-kind tag looks like 0x00 for instance klasses,
duke@435 203 // since their length in bytes is always less than 24Mb.
duke@435 204 //
duke@435 205 // Final note: This comes first, immediately after Klass_vtbl,
duke@435 206 // because it is frequently queried.
duke@435 207 jint _layout_helper;
duke@435 208
duke@435 209 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
duke@435 210 // and _primary_supers all help make fast subtype checks. See big discussion
duke@435 211 // in doc/server_compiler/checktype.txt
duke@435 212 //
duke@435 213 // Where to look to observe a supertype (it is &_secondary_super_cache for
duke@435 214 // secondary supers, else is &_primary_supers[depth()].
duke@435 215 juint _super_check_offset;
duke@435 216
coleenp@2497 217 // Class name. Instance classes: java/lang/String, etc. Array classes: [I,
coleenp@2497 218 // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
coleenp@2497 219 Symbol* _name;
coleenp@2497 220
duke@435 221 public:
duke@435 222 oop* oop_block_beg() const { return adr_secondary_super_cache(); }
duke@435 223 oop* oop_block_end() const { return adr_next_sibling() + 1; }
duke@435 224
duke@435 225 protected:
duke@435 226 //
duke@435 227 // The oop block. All oop fields must be declared here and only oop fields
duke@435 228 // may be declared here. In addition, the first and last fields in this block
duke@435 229 // must remain first and last, unless oop_block_beg() and/or oop_block_end()
duke@435 230 // are updated. Grouping the oop fields in a single block simplifies oop
duke@435 231 // iteration.
duke@435 232 //
duke@435 233
duke@435 234 // Cache of last observed secondary supertype
duke@435 235 klassOop _secondary_super_cache;
duke@435 236 // Array of all secondary supertypes
duke@435 237 objArrayOop _secondary_supers;
duke@435 238 // Ordered list of all primary supertypes
duke@435 239 klassOop _primary_supers[_primary_super_limit];
duke@435 240 // java/lang/Class instance mirroring this class
duke@435 241 oop _java_mirror;
duke@435 242 // Superclass
duke@435 243 klassOop _super;
duke@435 244 // First subclass (NULL if none); _subklass->next_sibling() is next one
duke@435 245 klassOop _subklass;
duke@435 246 // Sibling link (or NULL); links all subklasses of a klass
duke@435 247 klassOop _next_sibling;
duke@435 248
duke@435 249 //
duke@435 250 // End of the oop block.
duke@435 251 //
duke@435 252
duke@435 253 jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
duke@435 254 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
duke@435 255
duke@435 256 #ifndef PRODUCT
duke@435 257 int _verify_count; // to avoid redundant verifies
duke@435 258 #endif
duke@435 259
duke@435 260 juint _alloc_count; // allocation profiling support - update klass_size_in_bytes() if moved/deleted
duke@435 261
duke@435 262 // Biased locking implementation and statistics
duke@435 263 // (the 64-bit chunk goes first, to avoid some fragmentation)
duke@435 264 jlong _last_biased_lock_bulk_revocation_time;
duke@435 265 markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
duke@435 266 jint _biased_lock_revocation_count;
duke@435 267
phh@3427 268 #ifdef TRACE_DEFINE_KLASS_TRACE_ID
phh@3427 269 TRACE_DEFINE_KLASS_TRACE_ID;
phh@3427 270 #endif
duke@435 271 public:
duke@435 272
duke@435 273 // returns the enclosing klassOop
duke@435 274 klassOop as_klassOop() const {
duke@435 275 // see klassOop.hpp for layout.
duke@435 276 return (klassOop) (((char*) this) - sizeof(klassOopDesc));
duke@435 277 }
duke@435 278
duke@435 279 public:
duke@435 280 // Allocation
duke@435 281 const Klass_vtbl& vtbl_value() const { return *this; } // used only on "example instances"
duke@435 282 static KlassHandle base_create_klass(KlassHandle& klass, int size, const Klass_vtbl& vtbl, TRAPS);
duke@435 283 static klassOop base_create_klass_oop(KlassHandle& klass, int size, const Klass_vtbl& vtbl, TRAPS);
duke@435 284
duke@435 285 // super
duke@435 286 klassOop super() const { return _super; }
duke@435 287 void set_super(klassOop k) { oop_store_without_check((oop*) &_super, (oop) k); }
duke@435 288
duke@435 289 // initializes _super link, _primary_supers & _secondary_supers arrays
duke@435 290 void initialize_supers(klassOop k, TRAPS);
duke@435 291 void initialize_supers_impl1(klassOop k);
duke@435 292 void initialize_supers_impl2(klassOop k);
duke@435 293
duke@435 294 // klass-specific helper for initializing _secondary_supers
duke@435 295 virtual objArrayOop compute_secondary_supers(int num_extra_slots, TRAPS);
duke@435 296
duke@435 297 // java_super is the Java-level super type as specified by Class.getSuperClass.
duke@435 298 virtual klassOop java_super() const { return NULL; }
duke@435 299
duke@435 300 juint super_check_offset() const { return _super_check_offset; }
duke@435 301 void set_super_check_offset(juint o) { _super_check_offset = o; }
duke@435 302
duke@435 303 klassOop secondary_super_cache() const { return _secondary_super_cache; }
duke@435 304 void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
duke@435 305
duke@435 306 objArrayOop secondary_supers() const { return _secondary_supers; }
duke@435 307 void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
duke@435 308
duke@435 309 // Return the element of the _super chain of the given depth.
duke@435 310 // If there is no such element, return either NULL or this.
duke@435 311 klassOop primary_super_of_depth(juint i) const {
duke@435 312 assert(i < primary_super_limit(), "oob");
duke@435 313 klassOop super = _primary_supers[i];
duke@435 314 assert(super == NULL || super->klass_part()->super_depth() == i, "correct display");
duke@435 315 return super;
duke@435 316 }
duke@435 317
duke@435 318 // Can this klass be a primary super? False for interfaces and arrays of
duke@435 319 // interfaces. False also for arrays or classes with long super chains.
duke@435 320 bool can_be_primary_super() const {
duke@435 321 const juint secondary_offset = secondary_super_cache_offset_in_bytes() + sizeof(oopDesc);
duke@435 322 return super_check_offset() != secondary_offset;
duke@435 323 }
duke@435 324 virtual bool can_be_primary_super_slow() const;
duke@435 325
duke@435 326 // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit].
duke@435 327 juint super_depth() const {
duke@435 328 if (!can_be_primary_super()) {
duke@435 329 return primary_super_limit();
duke@435 330 } else {
duke@435 331 juint d = (super_check_offset() - (primary_supers_offset_in_bytes() + sizeof(oopDesc))) / sizeof(klassOop);
duke@435 332 assert(d < primary_super_limit(), "oob");
duke@435 333 assert(_primary_supers[d] == as_klassOop(), "proper init");
duke@435 334 return d;
duke@435 335 }
duke@435 336 }
duke@435 337
duke@435 338 // java mirror
duke@435 339 oop java_mirror() const { return _java_mirror; }
duke@435 340 void set_java_mirror(oop m) { oop_store((oop*) &_java_mirror, m); }
duke@435 341
duke@435 342 // modifier flags
duke@435 343 jint modifier_flags() const { return _modifier_flags; }
duke@435 344 void set_modifier_flags(jint flags) { _modifier_flags = flags; }
duke@435 345
duke@435 346 // size helper
duke@435 347 int layout_helper() const { return _layout_helper; }
duke@435 348 void set_layout_helper(int lh) { _layout_helper = lh; }
duke@435 349
duke@435 350 // Note: for instances layout_helper() may include padding.
duke@435 351 // Use instanceKlass::contains_field_offset to classify field offsets.
duke@435 352
duke@435 353 // sub/superklass links
duke@435 354 instanceKlass* superklass() const;
duke@435 355 Klass* subklass() const;
duke@435 356 Klass* next_sibling() const;
duke@435 357 void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
duke@435 358 void remove_from_sibling_list(); // remove receiver from sibling list
duke@435 359 protected: // internal accessors
duke@435 360 klassOop subklass_oop() const { return _subklass; }
duke@435 361 klassOop next_sibling_oop() const { return _next_sibling; }
duke@435 362 void set_subklass(klassOop s);
duke@435 363 void set_next_sibling(klassOop s);
duke@435 364
duke@435 365 oop* adr_super() const { return (oop*)&_super; }
duke@435 366 oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
duke@435 367 oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
duke@435 368 oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
duke@435 369 oop* adr_java_mirror() const { return (oop*)&_java_mirror; }
duke@435 370 oop* adr_subklass() const { return (oop*)&_subklass; }
duke@435 371 oop* adr_next_sibling() const { return (oop*)&_next_sibling; }
duke@435 372
duke@435 373 public:
duke@435 374 // Allocation profiling support
duke@435 375 juint alloc_count() const { return _alloc_count; }
duke@435 376 void set_alloc_count(juint n) { _alloc_count = n; }
duke@435 377 virtual juint alloc_size() const = 0;
duke@435 378 virtual void set_alloc_size(juint n) = 0;
duke@435 379
duke@435 380 // Compiler support
duke@435 381 static int super_offset_in_bytes() { return offset_of(Klass, _super); }
duke@435 382 static int super_check_offset_offset_in_bytes() { return offset_of(Klass, _super_check_offset); }
duke@435 383 static int primary_supers_offset_in_bytes(){ return offset_of(Klass, _primary_supers); }
duke@435 384 static int secondary_super_cache_offset_in_bytes() { return offset_of(Klass, _secondary_super_cache); }
duke@435 385 static int secondary_supers_offset_in_bytes() { return offset_of(Klass, _secondary_supers); }
duke@435 386 static int java_mirror_offset_in_bytes() { return offset_of(Klass, _java_mirror); }
duke@435 387 static int modifier_flags_offset_in_bytes(){ return offset_of(Klass, _modifier_flags); }
duke@435 388 static int layout_helper_offset_in_bytes() { return offset_of(Klass, _layout_helper); }
duke@435 389 static int access_flags_offset_in_bytes() { return offset_of(Klass, _access_flags); }
duke@435 390
duke@435 391 // Unpacking layout_helper:
duke@435 392 enum {
duke@435 393 _lh_neutral_value = 0, // neutral non-array non-instance value
duke@435 394 _lh_instance_slow_path_bit = 0x01,
duke@435 395 _lh_log2_element_size_shift = BitsPerByte*0,
duke@435 396 _lh_log2_element_size_mask = BitsPerLong-1,
duke@435 397 _lh_element_type_shift = BitsPerByte*1,
duke@435 398 _lh_element_type_mask = right_n_bits(BitsPerByte), // shifted mask
duke@435 399 _lh_header_size_shift = BitsPerByte*2,
duke@435 400 _lh_header_size_mask = right_n_bits(BitsPerByte), // shifted mask
duke@435 401 _lh_array_tag_bits = 2,
duke@435 402 _lh_array_tag_shift = BitsPerInt - _lh_array_tag_bits,
duke@435 403 _lh_array_tag_type_value = ~0x00, // 0xC0000000 >> 30
duke@435 404 _lh_array_tag_obj_value = ~0x01 // 0x80000000 >> 30
duke@435 405 };
duke@435 406
duke@435 407 static int layout_helper_size_in_bytes(jint lh) {
duke@435 408 assert(lh > (jint)_lh_neutral_value, "must be instance");
duke@435 409 return (int) lh & ~_lh_instance_slow_path_bit;
duke@435 410 }
duke@435 411 static bool layout_helper_needs_slow_path(jint lh) {
duke@435 412 assert(lh > (jint)_lh_neutral_value, "must be instance");
duke@435 413 return (lh & _lh_instance_slow_path_bit) != 0;
duke@435 414 }
duke@435 415 static bool layout_helper_is_instance(jint lh) {
duke@435 416 return (jint)lh > (jint)_lh_neutral_value;
duke@435 417 }
duke@435 418 static bool layout_helper_is_javaArray(jint lh) {
duke@435 419 return (jint)lh < (jint)_lh_neutral_value;
duke@435 420 }
duke@435 421 static bool layout_helper_is_typeArray(jint lh) {
duke@435 422 // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
duke@435 423 return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
duke@435 424 }
duke@435 425 static bool layout_helper_is_objArray(jint lh) {
duke@435 426 // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
duke@435 427 return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);
duke@435 428 }
duke@435 429 static int layout_helper_header_size(jint lh) {
duke@435 430 assert(lh < (jint)_lh_neutral_value, "must be array");
duke@435 431 int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
duke@435 432 assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
duke@435 433 return hsize;
duke@435 434 }
duke@435 435 static BasicType layout_helper_element_type(jint lh) {
duke@435 436 assert(lh < (jint)_lh_neutral_value, "must be array");
duke@435 437 int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
duke@435 438 assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity");
duke@435 439 return (BasicType) btvalue;
duke@435 440 }
duke@435 441 static int layout_helper_log2_element_size(jint lh) {
duke@435 442 assert(lh < (jint)_lh_neutral_value, "must be array");
duke@435 443 int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
duke@435 444 assert(l2esz <= LogBitsPerLong, "sanity");
duke@435 445 return l2esz;
duke@435 446 }
duke@435 447 static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
duke@435 448 return (tag << _lh_array_tag_shift)
duke@435 449 | (hsize << _lh_header_size_shift)
duke@435 450 | ((int)etype << _lh_element_type_shift)
duke@435 451 | (log2_esize << _lh_log2_element_size_shift);
duke@435 452 }
duke@435 453 static jint instance_layout_helper(jint size, bool slow_path_flag) {
duke@435 454 return (size << LogHeapWordSize)
duke@435 455 | (slow_path_flag ? _lh_instance_slow_path_bit : 0);
duke@435 456 }
duke@435 457 static int layout_helper_to_size_helper(jint lh) {
duke@435 458 assert(lh > (jint)_lh_neutral_value, "must be instance");
duke@435 459 // Note that the following expression discards _lh_instance_slow_path_bit.
duke@435 460 return lh >> LogHeapWordSize;
duke@435 461 }
duke@435 462 // Out-of-line version computes everything based on the etype:
duke@435 463 static jint array_layout_helper(BasicType etype);
duke@435 464
duke@435 465 // What is the maximum number of primary superclasses any klass can have?
duke@435 466 #ifdef PRODUCT
duke@435 467 static juint primary_super_limit() { return _primary_super_limit; }
duke@435 468 #else
duke@435 469 static juint primary_super_limit() {
duke@435 470 assert(FastSuperclassLimit <= _primary_super_limit, "parameter oob");
duke@435 471 return FastSuperclassLimit;
duke@435 472 }
duke@435 473 #endif
duke@435 474
duke@435 475 // vtables
duke@435 476 virtual klassVtable* vtable() const { return NULL; }
duke@435 477
duke@435 478 static int klass_size_in_bytes() { return offset_of(Klass, _alloc_count) + sizeof(juint); } // all "visible" fields
duke@435 479
duke@435 480 // subclass check
duke@435 481 bool is_subclass_of(klassOop k) const;
duke@435 482 // subtype check: true if is_subclass_of, or if k is interface and receiver implements it
duke@435 483 bool is_subtype_of(klassOop k) const {
duke@435 484 juint off = k->klass_part()->super_check_offset();
duke@435 485 klassOop sup = *(klassOop*)( (address)as_klassOop() + off );
duke@435 486 const juint secondary_offset = secondary_super_cache_offset_in_bytes() + sizeof(oopDesc);
duke@435 487 if (sup == k) {
duke@435 488 return true;
duke@435 489 } else if (off != secondary_offset) {
duke@435 490 return false;
duke@435 491 } else {
duke@435 492 return search_secondary_supers(k);
duke@435 493 }
duke@435 494 }
duke@435 495 bool search_secondary_supers(klassOop k) const;
duke@435 496
twisti@1040 497 // Find LCA in class hierarchy
duke@435 498 Klass *LCA( Klass *k );
duke@435 499
duke@435 500 // Check whether reflection/jni/jvm code is allowed to instantiate this class;
duke@435 501 // if not, throw either an Error or an Exception.
duke@435 502 virtual void check_valid_for_instantiation(bool throwError, TRAPS);
duke@435 503
duke@435 504 // Casting
duke@435 505 static Klass* cast(klassOop k) {
duke@435 506 assert(k->is_klass(), "cast to Klass");
duke@435 507 return k->klass_part();
duke@435 508 }
duke@435 509
duke@435 510 // array copying
duke@435 511 virtual void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
duke@435 512
duke@435 513 // tells if the class should be initialized
duke@435 514 virtual bool should_be_initialized() const { return false; }
duke@435 515 // initializes the klass
duke@435 516 virtual void initialize(TRAPS);
duke@435 517 // lookup operation for MethodLookupCache
duke@435 518 friend class MethodLookupCache;
coleenp@2497 519 virtual methodOop uncached_lookup_method(Symbol* name, Symbol* signature) const;
duke@435 520 public:
coleenp@2497 521 methodOop lookup_method(Symbol* name, Symbol* signature) const {
duke@435 522 return uncached_lookup_method(name, signature);
duke@435 523 }
duke@435 524
duke@435 525 // array class with specific rank
duke@435 526 klassOop array_klass(int rank, TRAPS) { return array_klass_impl(false, rank, THREAD); }
duke@435 527
duke@435 528 // array class with this klass as element type
duke@435 529 klassOop array_klass(TRAPS) { return array_klass_impl(false, THREAD); }
duke@435 530
duke@435 531 // These will return NULL instead of allocating on the heap:
duke@435 532 // NB: these can block for a mutex, like other functions with TRAPS arg.
duke@435 533 klassOop array_klass_or_null(int rank);
duke@435 534 klassOop array_klass_or_null();
duke@435 535
duke@435 536 virtual oop protection_domain() { return NULL; }
duke@435 537 virtual oop class_loader() const { return NULL; }
duke@435 538
duke@435 539 protected:
duke@435 540 virtual klassOop array_klass_impl(bool or_null, int rank, TRAPS);
duke@435 541 virtual klassOop array_klass_impl(bool or_null, TRAPS);
duke@435 542
duke@435 543 public:
duke@435 544 virtual void remove_unshareable_info();
coleenp@2497 545 virtual void shared_symbols_iterate(SymbolClosure* closure);
duke@435 546
duke@435 547 protected:
duke@435 548 // computes the subtype relationship
duke@435 549 virtual bool compute_is_subtype_of(klassOop k);
duke@435 550 public:
duke@435 551 // subclass accessor (here for convenience; undefined for non-klass objects)
duke@435 552 virtual bool is_leaf_class() const { fatal("not a class"); return false; }
duke@435 553 public:
duke@435 554 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP
duke@435 555 // These functions describe behavior for the oop not the KLASS.
duke@435 556
duke@435 557 // actual oop size of obj in memory
duke@435 558 virtual int oop_size(oop obj) const = 0;
duke@435 559
duke@435 560 // actual oop size of this klass in memory
duke@435 561 virtual int klass_oop_size() const = 0;
duke@435 562
duke@435 563 // Returns the Java name for a class (Resource allocated)
duke@435 564 // For arrays, this returns the name of the element with a leading '['.
duke@435 565 // For classes, this returns the name with the package separators
duke@435 566 // turned into '.'s.
duke@435 567 const char* external_name() const;
duke@435 568 // Returns the name for a class (Resource allocated) as the class
duke@435 569 // would appear in a signature.
duke@435 570 // For arrays, this returns the name of the element with a leading '['.
duke@435 571 // For classes, this returns the name with a leading 'L' and a trailing ';'
duke@435 572 // and the package separators as '/'.
jrose@1474 573 virtual const char* signature_name() const;
duke@435 574
duke@435 575 // garbage collection support
duke@435 576 virtual void oop_follow_contents(oop obj) = 0;
duke@435 577 virtual int oop_adjust_pointers(oop obj) = 0;
duke@435 578
duke@435 579 // Parallel Scavenge and Parallel Old
duke@435 580 PARALLEL_GC_DECLS_PV
duke@435 581
duke@435 582 public:
duke@435 583 // type testing operations
duke@435 584 virtual bool oop_is_instance_slow() const { return false; }
never@2658 585 virtual bool oop_is_instanceMirror() const { return false; }
duke@435 586 virtual bool oop_is_instanceRef() const { return false; }
duke@435 587 virtual bool oop_is_array() const { return false; }
duke@435 588 virtual bool oop_is_objArray_slow() const { return false; }
duke@435 589 virtual bool oop_is_klass() const { return false; }
duke@435 590 virtual bool oop_is_thread() const { return false; }
duke@435 591 virtual bool oop_is_method() const { return false; }
duke@435 592 virtual bool oop_is_constMethod() const { return false; }
duke@435 593 virtual bool oop_is_methodData() const { return false; }
duke@435 594 virtual bool oop_is_constantPool() const { return false; }
duke@435 595 virtual bool oop_is_constantPoolCache() const { return false; }
duke@435 596 virtual bool oop_is_typeArray_slow() const { return false; }
duke@435 597 virtual bool oop_is_arrayKlass() const { return false; }
duke@435 598 virtual bool oop_is_objArrayKlass() const { return false; }
duke@435 599 virtual bool oop_is_typeArrayKlass() const { return false; }
duke@435 600 virtual bool oop_is_compiledICHolder() const { return false; }
duke@435 601 virtual bool oop_is_instanceKlass() const { return false; }
duke@435 602
duke@435 603 bool oop_is_javaArray_slow() const {
duke@435 604 return oop_is_objArray_slow() || oop_is_typeArray_slow();
duke@435 605 }
duke@435 606
duke@435 607 // Fast non-virtual versions, used by oop.inline.hpp and elsewhere:
duke@435 608 #ifndef ASSERT
duke@435 609 #define assert_same_query(xval, xcheck) xval
duke@435 610 #else
duke@435 611 private:
duke@435 612 static bool assert_same_query(bool xval, bool xslow) {
duke@435 613 assert(xval == xslow, "slow and fast queries agree");
duke@435 614 return xval;
duke@435 615 }
duke@435 616 public:
duke@435 617 #endif
duke@435 618 inline bool oop_is_instance() const { return assert_same_query(
duke@435 619 layout_helper_is_instance(layout_helper()),
duke@435 620 oop_is_instance_slow()); }
duke@435 621 inline bool oop_is_javaArray() const { return assert_same_query(
duke@435 622 layout_helper_is_javaArray(layout_helper()),
duke@435 623 oop_is_javaArray_slow()); }
duke@435 624 inline bool oop_is_objArray() const { return assert_same_query(
duke@435 625 layout_helper_is_objArray(layout_helper()),
duke@435 626 oop_is_objArray_slow()); }
duke@435 627 inline bool oop_is_typeArray() const { return assert_same_query(
duke@435 628 layout_helper_is_typeArray(layout_helper()),
duke@435 629 oop_is_typeArray_slow()); }
duke@435 630 #undef assert_same_query
duke@435 631
duke@435 632 // Unless overridden, oop is parsable if it has a klass pointer.
jmasa@953 633 // Parsability of an object is object specific.
duke@435 634 virtual bool oop_is_parsable(oop obj) const { return true; }
duke@435 635
jmasa@953 636 // Unless overridden, oop is safe for concurrent GC processing
jmasa@953 637 // after its allocation is complete. The exception to
jmasa@953 638 // this is the case where objects are changed after allocation.
jmasa@953 639 // Class redefinition is one of the known exceptions. During
jmasa@953 640 // class redefinition, an allocated class can changed in order
jmasa@953 641 // order to create a merged class (the combiniation of the
jmasa@953 642 // old class definition that has to be perserved and the new class
jmasa@953 643 // definition which is being created.
jmasa@953 644 virtual bool oop_is_conc_safe(oop obj) const { return true; }
jmasa@953 645
duke@435 646 // Access flags
duke@435 647 AccessFlags access_flags() const { return _access_flags; }
duke@435 648 void set_access_flags(AccessFlags flags) { _access_flags = flags; }
duke@435 649
duke@435 650 bool is_public() const { return _access_flags.is_public(); }
duke@435 651 bool is_final() const { return _access_flags.is_final(); }
duke@435 652 bool is_interface() const { return _access_flags.is_interface(); }
duke@435 653 bool is_abstract() const { return _access_flags.is_abstract(); }
duke@435 654 bool is_super() const { return _access_flags.is_super(); }
duke@435 655 bool is_synthetic() const { return _access_flags.is_synthetic(); }
duke@435 656 void set_is_synthetic() { _access_flags.set_is_synthetic(); }
duke@435 657 bool has_finalizer() const { return _access_flags.has_finalizer(); }
duke@435 658 bool has_final_method() const { return _access_flags.has_final_method(); }
duke@435 659 void set_has_finalizer() { _access_flags.set_has_finalizer(); }
duke@435 660 void set_has_final_method() { _access_flags.set_has_final_method(); }
duke@435 661 bool is_cloneable() const { return _access_flags.is_cloneable(); }
duke@435 662 void set_is_cloneable() { _access_flags.set_is_cloneable(); }
duke@435 663 bool has_vanilla_constructor() const { return _access_flags.has_vanilla_constructor(); }
duke@435 664 void set_has_vanilla_constructor() { _access_flags.set_has_vanilla_constructor(); }
duke@435 665 bool has_miranda_methods () const { return access_flags().has_miranda_methods(); }
duke@435 666 void set_has_miranda_methods() { _access_flags.set_has_miranda_methods(); }
duke@435 667
duke@435 668 // Biased locking support
duke@435 669 // Note: the prototype header is always set up to be at least the
duke@435 670 // prototype markOop. If biased locking is enabled it may further be
duke@435 671 // biasable and have an epoch.
duke@435 672 markOop prototype_header() const { return _prototype_header; }
duke@435 673 // NOTE: once instances of this klass are floating around in the
duke@435 674 // system, this header must only be updated at a safepoint.
duke@435 675 // NOTE 2: currently we only ever set the prototype header to the
duke@435 676 // biasable prototype for instanceKlasses. There is no technical
duke@435 677 // reason why it could not be done for arrayKlasses aside from
duke@435 678 // wanting to reduce the initial scope of this optimization. There
duke@435 679 // are potential problems in setting the bias pattern for
duke@435 680 // JVM-internal oops.
duke@435 681 inline void set_prototype_header(markOop header);
duke@435 682 static int prototype_header_offset_in_bytes() { return offset_of(Klass, _prototype_header); }
duke@435 683
duke@435 684 int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
duke@435 685 // Atomically increments biased_lock_revocation_count and returns updated value
duke@435 686 int atomic_incr_biased_lock_revocation_count();
duke@435 687 void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
duke@435 688 jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
duke@435 689 void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
duke@435 690
phh@3427 691 #ifdef TRACE_DEFINE_KLASS_METHODS
phh@3427 692 TRACE_DEFINE_KLASS_METHODS;
phh@3427 693 #endif
duke@435 694
duke@435 695 // garbage collection support
duke@435 696 virtual void follow_weak_klass_links(
duke@435 697 BoolObjectClosure* is_alive, OopClosure* keep_alive);
duke@435 698
duke@435 699 // Prefetch within oop iterators. This is a macro because we
duke@435 700 // can't guarantee that the compiler will inline it. In 64-bit
duke@435 701 // it generally doesn't. Signature is
duke@435 702 //
duke@435 703 // static void prefetch_beyond(oop* const start,
duke@435 704 // oop* const end,
duke@435 705 // const intx foffset,
duke@435 706 // const Prefetch::style pstyle);
duke@435 707 #define prefetch_beyond(start, end, foffset, pstyle) { \
duke@435 708 const intx foffset_ = (foffset); \
duke@435 709 const Prefetch::style pstyle_ = (pstyle); \
duke@435 710 assert(foffset_ > 0, "prefetch beyond, not behind"); \
duke@435 711 if (pstyle_ != Prefetch::do_none) { \
duke@435 712 oop* ref = (start); \
duke@435 713 if (ref < (end)) { \
duke@435 714 switch (pstyle_) { \
duke@435 715 case Prefetch::do_read: \
duke@435 716 Prefetch::read(*ref, foffset_); \
duke@435 717 break; \
duke@435 718 case Prefetch::do_write: \
duke@435 719 Prefetch::write(*ref, foffset_); \
duke@435 720 break; \
duke@435 721 default: \
duke@435 722 ShouldNotReachHere(); \
duke@435 723 break; \
duke@435 724 } \
duke@435 725 } \
duke@435 726 } \
duke@435 727 }
duke@435 728
duke@435 729 // iterators
duke@435 730 virtual int oop_oop_iterate(oop obj, OopClosure* blk) = 0;
duke@435 731 virtual int oop_oop_iterate_v(oop obj, OopClosure* blk) {
duke@435 732 return oop_oop_iterate(obj, blk);
duke@435 733 }
duke@435 734
ysr@777 735 #ifndef SERIALGC
ysr@777 736 // In case we don't have a specialized backward scanner use forward
ysr@777 737 // iteration.
ysr@777 738 virtual int oop_oop_iterate_backwards_v(oop obj, OopClosure* blk) {
ysr@777 739 return oop_oop_iterate_v(obj, blk);
ysr@777 740 }
ysr@777 741 #endif // !SERIALGC
ysr@777 742
duke@435 743 // Iterates "blk" over all the oops in "obj" (of type "this") within "mr".
duke@435 744 // (I don't see why the _m should be required, but without it the Solaris
duke@435 745 // C++ gives warning messages about overridings of the "oop_oop_iterate"
duke@435 746 // defined above "hiding" this virtual function. (DLD, 6/20/00)) */
duke@435 747 virtual int oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) = 0;
duke@435 748 virtual int oop_oop_iterate_v_m(oop obj, OopClosure* blk, MemRegion mr) {
duke@435 749 return oop_oop_iterate_m(obj, blk, mr);
duke@435 750 }
duke@435 751
duke@435 752 // Versions of the above iterators specialized to particular subtypes
duke@435 753 // of OopClosure, to avoid closure virtual calls.
duke@435 754 #define Klass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
duke@435 755 virtual int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk) { \
duke@435 756 /* Default implementation reverts to general version. */ \
duke@435 757 return oop_oop_iterate(obj, blk); \
duke@435 758 } \
duke@435 759 \
duke@435 760 /* Iterates "blk" over all the oops in "obj" (of type "this") within "mr". \
duke@435 761 (I don't see why the _m should be required, but without it the Solaris \
duke@435 762 C++ gives warning messages about overridings of the "oop_oop_iterate" \
duke@435 763 defined above "hiding" this virtual function. (DLD, 6/20/00)) */ \
duke@435 764 virtual int oop_oop_iterate##nv_suffix##_m(oop obj, \
duke@435 765 OopClosureType* blk, \
duke@435 766 MemRegion mr) { \
duke@435 767 return oop_oop_iterate_m(obj, blk, mr); \
duke@435 768 }
duke@435 769
duke@435 770 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_DECL)
ysr@777 771 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_DECL)
ysr@777 772
ysr@777 773 #ifndef SERIALGC
ysr@777 774 #define Klass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix) \
ysr@777 775 virtual int oop_oop_iterate_backwards##nv_suffix(oop obj, \
ysr@777 776 OopClosureType* blk) { \
ysr@777 777 /* Default implementation reverts to general version. */ \
ysr@777 778 return oop_oop_iterate_backwards_v(obj, blk); \
ysr@777 779 }
ysr@777 780
ysr@777 781 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL)
ysr@777 782 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL)
ysr@777 783 #endif // !SERIALGC
duke@435 784
duke@435 785 virtual void array_klasses_do(void f(klassOop k)) {}
duke@435 786 virtual void with_array_klasses_do(void f(klassOop k));
duke@435 787
duke@435 788 // Return self, except for abstract classes with exactly 1
duke@435 789 // implementor. Then return the 1 concrete implementation.
duke@435 790 Klass *up_cast_abstract();
duke@435 791
duke@435 792 // klass name
coleenp@2497 793 Symbol* name() const { return _name; }
coleenp@2497 794 void set_name(Symbol* n);
duke@435 795
duke@435 796 friend class klassKlass;
duke@435 797
duke@435 798 public:
duke@435 799 // jvm support
duke@435 800 virtual jint compute_modifier_flags(TRAPS) const;
duke@435 801
duke@435 802 // JVMTI support
duke@435 803 virtual jint jvmti_class_status() const;
duke@435 804
duke@435 805 // Printing
jrose@1590 806 virtual void oop_print_value_on(oop obj, outputStream* st);
duke@435 807 virtual void oop_print_on (oop obj, outputStream* st);
duke@435 808
duke@435 809 // Verification
duke@435 810 virtual const char* internal_name() const = 0;
duke@435 811 virtual void oop_verify_on(oop obj, outputStream* st);
duke@435 812 virtual void oop_verify_old_oop(oop obj, oop* p, bool allow_dirty);
coleenp@548 813 virtual void oop_verify_old_oop(oop obj, narrowOop* p, bool allow_dirty);
duke@435 814 // tells whether obj is partially constructed (gc during class loading)
duke@435 815 virtual bool oop_partially_loaded(oop obj) const { return false; }
duke@435 816 virtual void oop_set_partially_loaded(oop obj) {};
duke@435 817
duke@435 818 #ifndef PRODUCT
duke@435 819 void verify_vtable_index(int index);
duke@435 820 #endif
duke@435 821 };
stefank@2314 822
never@2658 823
never@2658 824 inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
never@2658 825
never@2658 826
stefank@2314 827 #endif // SHARE_VM_OOPS_KLASS_HPP

mercurial