src/share/vm/oops/klass.hpp

Fri, 27 Feb 2009 13:27:09 -0800

author
twisti
date
Fri, 27 Feb 2009 13:27:09 -0800
changeset 1040
98cb887364d3
parent 953
0af8b0718fc9
child 1063
7bb995fbd3c0
permissions
-rw-r--r--

6810672: Comment typos
Summary: I have collected some typos I have found while looking at the code.
Reviewed-by: kvn, never

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

mercurial