duke@435: /* xdono@1014: * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // A Klass is the part of the klassOop that provides: duke@435: // 1: language level class object (method dictionary etc.) duke@435: // 2: provide vm dispatch behavior for the object duke@435: // Both functions are combined into one C++ class. The toplevel class "Klass" duke@435: // implements purpose 1 whereas all subclasses provide extra virtual functions duke@435: // for purpose 2. duke@435: duke@435: // One reason for the oop/klass dichotomy in the implementation is duke@435: // that we don't want a C++ vtbl pointer in every object. Thus, duke@435: // normal oops don't have any virtual functions. Instead, they duke@435: // forward all "virtual" functions to their klass, which does have duke@435: // a vtbl and does the C++ dispatch depending on the object's duke@435: // actual type. (See oop.inline.hpp for some of the forwarding code.) duke@435: // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"! duke@435: duke@435: // Klass layout: duke@435: // [header ] klassOop duke@435: // [klass pointer ] klassOop duke@435: // [C++ vtbl ptr ] (contained in Klass_vtbl) duke@435: // [layout_helper ] duke@435: // [super_check_offset ] for fast subtype checks duke@435: // [secondary_super_cache] for fast subtype checks duke@435: // [secondary_supers ] array of 2ndary supertypes duke@435: // [primary_supers 0] duke@435: // [primary_supers 1] duke@435: // [primary_supers 2] duke@435: // ... duke@435: // [primary_supers 7] duke@435: // [java_mirror ] duke@435: // [super ] duke@435: // [name ] duke@435: // [first subklass] duke@435: // [next_sibling ] link to chain additional subklasses duke@435: // [modifier_flags] duke@435: // [access_flags ] duke@435: // [verify_count ] - not in product duke@435: // [alloc_count ] duke@435: // [last_biased_lock_bulk_revocation_time] (64 bits) duke@435: // [prototype_header] duke@435: // [biased_lock_revocation_count] duke@435: duke@435: duke@435: // Forward declarations. duke@435: class klassVtable; duke@435: class KlassHandle; duke@435: class OrderAccess; duke@435: duke@435: // Holder (or cage) for the C++ vtable of each kind of Klass. duke@435: // We want to tightly constrain the location of the C++ vtable in the overall layout. duke@435: class Klass_vtbl { duke@435: protected: duke@435: // The following virtual exists only to force creation of a C++ vtable, duke@435: // so that this class truly is the location of the vtable of all Klasses. duke@435: virtual void unused_initial_virtual() { } duke@435: duke@435: public: duke@435: // The following virtual makes Klass_vtbl play a second role as a duke@435: // factory protocol for subclasses of Klass ("sub-Klasses"). duke@435: // Here's how it works.... duke@435: // duke@435: // This VM uses metaobjects as factories for their instances. duke@435: // duke@435: // In order to initialize the C++ vtable of a new instance, its duke@435: // metaobject is forced to use the C++ placed new operator to duke@435: // allocate the instance. In a typical C++-based system, each duke@435: // sub-class would have its own factory routine which duke@435: // directly uses the placed new operator on the desired class, duke@435: // and then calls the appropriate chain of C++ constructors. duke@435: // duke@435: // However, this system uses shared code to performs the first duke@435: // allocation and initialization steps for all sub-Klasses. duke@435: // (See base_create_klass() and base_create_array_klass().) duke@435: // This does not factor neatly into a hierarchy of C++ constructors. duke@435: // Each caller of these shared "base_create" routines knows duke@435: // exactly which sub-Klass it is creating, but the shared routine duke@435: // does not, even though it must perform the actual allocation. duke@435: // duke@435: // Therefore, the caller of the shared "base_create" must wrap duke@435: // the specific placed new call in a virtual function which duke@435: // performs the actual allocation and vtable set-up. That duke@435: // virtual function is here, Klass_vtbl::allocate_permanent. duke@435: // duke@435: // The arguments to Universe::allocate_permanent() are passed duke@435: // straight through the placed new operator, which in turn duke@435: // obtains them directly from this virtual call. duke@435: // duke@435: // This virtual is called on a temporary "example instance" of the duke@435: // sub-Klass being instantiated, a C++ auto variable. The "real" duke@435: // instance created by this virtual is on the VM heap, where it is duke@435: // equipped with a klassOopDesc header. duke@435: // duke@435: // It is merely an accident of implementation that we use "example duke@435: // instances", but that is why the virtual function which implements duke@435: // each sub-Klass factory happens to be defined by the same sub-Klass duke@435: // for which it creates instances. duke@435: // duke@435: // The vtbl_value() call (see below) is used to strip away the duke@435: // accidental Klass-ness from an "example instance" and present it as duke@435: // a factory. Think of each factory object as a mere container of the duke@435: // C++ vtable for the desired sub-Klass. Since C++ does not allow duke@435: // direct references to vtables, the factory must also be delegated duke@435: // the task of allocating the instance, but the essential point is duke@435: // that the factory knows how to initialize the C++ vtable with the duke@435: // right pointer value. All other common initializations are handled duke@435: // by the shared "base_create" subroutines. duke@435: // duke@435: virtual void* allocate_permanent(KlassHandle& klass, int size, TRAPS) const = 0; duke@435: void post_new_init_klass(KlassHandle& klass, klassOop obj, int size) const; duke@435: duke@435: // Every subclass on which vtbl_value is called must include this macro. duke@435: // Delay the installation of the klassKlass pointer until after the duke@435: // the vtable for a new klass has been installed (after the call to new()). ysr@777: #define DEFINE_ALLOCATE_PERMANENT(thisKlass) \ duke@435: void* allocate_permanent(KlassHandle& klass_klass, int size, TRAPS) const { \ ysr@777: void* result = new(klass_klass, size, THREAD) thisKlass(); \ ysr@777: if (HAS_PENDING_EXCEPTION) return NULL; \ ysr@777: klassOop new_klass = ((Klass*) result)->as_klassOop(); \ ysr@777: OrderAccess::storestore(); \ ysr@777: post_new_init_klass(klass_klass, new_klass, size); \ ysr@777: return result; \ duke@435: } duke@435: duke@435: bool null_vtbl() { return *(intptr_t*)this == 0; } duke@435: duke@435: protected: duke@435: void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS); duke@435: }; duke@435: duke@435: duke@435: class Klass : public Klass_vtbl { duke@435: friend class VMStructs; duke@435: protected: duke@435: // note: put frequently-used fields together at start of klass structure duke@435: // for better cache behavior (may not make much of a difference but sure won't hurt) duke@435: enum { _primary_super_limit = 8 }; duke@435: duke@435: // The "layout helper" is a combined descriptor of object layout. duke@435: // For klasses which are neither instance nor array, the value is zero. duke@435: // duke@435: // For instances, layout helper is a positive number, the instance size. duke@435: // This size is already passed through align_object_size and scaled to bytes. duke@435: // The low order bit is set if instances of this class cannot be duke@435: // allocated using the fastpath. duke@435: // duke@435: // For arrays, layout helper is a negative number, containing four duke@435: // distinct bytes, as follows: duke@435: // MSB:[tag, hsz, ebt, log2(esz)]:LSB duke@435: // where: duke@435: // tag is 0x80 if the elements are oops, 0xC0 if non-oops duke@435: // hsz is array header size in bytes (i.e., offset of first element) duke@435: // ebt is the BasicType of the elements duke@435: // esz is the element size in bytes duke@435: // This packed word is arranged so as to be quickly unpacked by the duke@435: // various fast paths that use the various subfields. duke@435: // duke@435: // The esz bits can be used directly by a SLL instruction, without masking. duke@435: // duke@435: // Note that the array-kind tag looks like 0x00 for instance klasses, duke@435: // since their length in bytes is always less than 24Mb. duke@435: // duke@435: // Final note: This comes first, immediately after Klass_vtbl, duke@435: // because it is frequently queried. duke@435: jint _layout_helper; duke@435: duke@435: // The fields _super_check_offset, _secondary_super_cache, _secondary_supers duke@435: // and _primary_supers all help make fast subtype checks. See big discussion duke@435: // in doc/server_compiler/checktype.txt duke@435: // duke@435: // Where to look to observe a supertype (it is &_secondary_super_cache for duke@435: // secondary supers, else is &_primary_supers[depth()]. duke@435: juint _super_check_offset; duke@435: duke@435: public: duke@435: oop* oop_block_beg() const { return adr_secondary_super_cache(); } duke@435: oop* oop_block_end() const { return adr_next_sibling() + 1; } duke@435: duke@435: protected: duke@435: // duke@435: // The oop block. All oop fields must be declared here and only oop fields duke@435: // may be declared here. In addition, the first and last fields in this block duke@435: // must remain first and last, unless oop_block_beg() and/or oop_block_end() duke@435: // are updated. Grouping the oop fields in a single block simplifies oop duke@435: // iteration. duke@435: // duke@435: duke@435: // Cache of last observed secondary supertype duke@435: klassOop _secondary_super_cache; duke@435: // Array of all secondary supertypes duke@435: objArrayOop _secondary_supers; duke@435: // Ordered list of all primary supertypes duke@435: klassOop _primary_supers[_primary_super_limit]; duke@435: // java/lang/Class instance mirroring this class duke@435: oop _java_mirror; duke@435: // Superclass duke@435: klassOop _super; duke@435: // Class name. Instance classes: java/lang/String, etc. Array classes: [I, duke@435: // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes. duke@435: symbolOop _name; duke@435: // First subclass (NULL if none); _subklass->next_sibling() is next one duke@435: klassOop _subklass; duke@435: // Sibling link (or NULL); links all subklasses of a klass duke@435: klassOop _next_sibling; duke@435: duke@435: // duke@435: // End of the oop block. duke@435: // duke@435: duke@435: jint _modifier_flags; // Processed access flags, for use by Class.getModifiers. duke@435: AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here. duke@435: duke@435: #ifndef PRODUCT duke@435: int _verify_count; // to avoid redundant verifies duke@435: #endif duke@435: duke@435: juint _alloc_count; // allocation profiling support - update klass_size_in_bytes() if moved/deleted duke@435: duke@435: // Biased locking implementation and statistics duke@435: // (the 64-bit chunk goes first, to avoid some fragmentation) duke@435: jlong _last_biased_lock_bulk_revocation_time; duke@435: markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type duke@435: jint _biased_lock_revocation_count; duke@435: duke@435: public: duke@435: duke@435: // returns the enclosing klassOop duke@435: klassOop as_klassOop() const { duke@435: // see klassOop.hpp for layout. duke@435: return (klassOop) (((char*) this) - sizeof(klassOopDesc)); duke@435: } duke@435: duke@435: public: duke@435: // Allocation duke@435: const Klass_vtbl& vtbl_value() const { return *this; } // used only on "example instances" duke@435: static KlassHandle base_create_klass(KlassHandle& klass, int size, const Klass_vtbl& vtbl, TRAPS); duke@435: static klassOop base_create_klass_oop(KlassHandle& klass, int size, const Klass_vtbl& vtbl, TRAPS); duke@435: duke@435: // super duke@435: klassOop super() const { return _super; } duke@435: void set_super(klassOop k) { oop_store_without_check((oop*) &_super, (oop) k); } duke@435: duke@435: // initializes _super link, _primary_supers & _secondary_supers arrays duke@435: void initialize_supers(klassOop k, TRAPS); duke@435: void initialize_supers_impl1(klassOop k); duke@435: void initialize_supers_impl2(klassOop k); duke@435: duke@435: // klass-specific helper for initializing _secondary_supers duke@435: virtual objArrayOop compute_secondary_supers(int num_extra_slots, TRAPS); duke@435: duke@435: // java_super is the Java-level super type as specified by Class.getSuperClass. duke@435: virtual klassOop java_super() const { return NULL; } duke@435: duke@435: juint super_check_offset() const { return _super_check_offset; } duke@435: void set_super_check_offset(juint o) { _super_check_offset = o; } duke@435: duke@435: klassOop secondary_super_cache() const { return _secondary_super_cache; } duke@435: void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); } duke@435: duke@435: objArrayOop secondary_supers() const { return _secondary_supers; } duke@435: void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); } duke@435: duke@435: // Return the element of the _super chain of the given depth. duke@435: // If there is no such element, return either NULL or this. duke@435: klassOop primary_super_of_depth(juint i) const { duke@435: assert(i < primary_super_limit(), "oob"); duke@435: klassOop super = _primary_supers[i]; duke@435: assert(super == NULL || super->klass_part()->super_depth() == i, "correct display"); duke@435: return super; duke@435: } duke@435: duke@435: // Can this klass be a primary super? False for interfaces and arrays of duke@435: // interfaces. False also for arrays or classes with long super chains. duke@435: bool can_be_primary_super() const { duke@435: const juint secondary_offset = secondary_super_cache_offset_in_bytes() + sizeof(oopDesc); duke@435: return super_check_offset() != secondary_offset; duke@435: } duke@435: virtual bool can_be_primary_super_slow() const; duke@435: duke@435: // Returns number of primary supers; may be a number in the inclusive range [0, primary_super_limit]. duke@435: juint super_depth() const { duke@435: if (!can_be_primary_super()) { duke@435: return primary_super_limit(); duke@435: } else { duke@435: juint d = (super_check_offset() - (primary_supers_offset_in_bytes() + sizeof(oopDesc))) / sizeof(klassOop); duke@435: assert(d < primary_super_limit(), "oob"); duke@435: assert(_primary_supers[d] == as_klassOop(), "proper init"); duke@435: return d; duke@435: } duke@435: } duke@435: duke@435: // java mirror duke@435: oop java_mirror() const { return _java_mirror; } duke@435: void set_java_mirror(oop m) { oop_store((oop*) &_java_mirror, m); } duke@435: duke@435: // modifier flags duke@435: jint modifier_flags() const { return _modifier_flags; } duke@435: void set_modifier_flags(jint flags) { _modifier_flags = flags; } duke@435: duke@435: // size helper duke@435: int layout_helper() const { return _layout_helper; } duke@435: void set_layout_helper(int lh) { _layout_helper = lh; } duke@435: duke@435: // Note: for instances layout_helper() may include padding. duke@435: // Use instanceKlass::contains_field_offset to classify field offsets. duke@435: duke@435: // sub/superklass links duke@435: instanceKlass* superklass() const; duke@435: Klass* subklass() const; duke@435: Klass* next_sibling() const; duke@435: void append_to_sibling_list(); // add newly created receiver to superklass' subklass list duke@435: void remove_from_sibling_list(); // remove receiver from sibling list duke@435: protected: // internal accessors duke@435: klassOop subklass_oop() const { return _subklass; } duke@435: klassOop next_sibling_oop() const { return _next_sibling; } duke@435: void set_subklass(klassOop s); duke@435: void set_next_sibling(klassOop s); duke@435: duke@435: oop* adr_super() const { return (oop*)&_super; } duke@435: oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; } duke@435: oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; } duke@435: oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; } duke@435: oop* adr_java_mirror() const { return (oop*)&_java_mirror; } duke@435: oop* adr_name() const { return (oop*)&_name; } duke@435: oop* adr_subklass() const { return (oop*)&_subklass; } duke@435: oop* adr_next_sibling() const { return (oop*)&_next_sibling; } duke@435: duke@435: public: duke@435: // Allocation profiling support duke@435: juint alloc_count() const { return _alloc_count; } duke@435: void set_alloc_count(juint n) { _alloc_count = n; } duke@435: virtual juint alloc_size() const = 0; duke@435: virtual void set_alloc_size(juint n) = 0; duke@435: duke@435: // Compiler support duke@435: static int super_offset_in_bytes() { return offset_of(Klass, _super); } duke@435: static int super_check_offset_offset_in_bytes() { return offset_of(Klass, _super_check_offset); } duke@435: static int primary_supers_offset_in_bytes(){ return offset_of(Klass, _primary_supers); } duke@435: static int secondary_super_cache_offset_in_bytes() { return offset_of(Klass, _secondary_super_cache); } duke@435: static int secondary_supers_offset_in_bytes() { return offset_of(Klass, _secondary_supers); } duke@435: static int java_mirror_offset_in_bytes() { return offset_of(Klass, _java_mirror); } duke@435: static int modifier_flags_offset_in_bytes(){ return offset_of(Klass, _modifier_flags); } duke@435: static int layout_helper_offset_in_bytes() { return offset_of(Klass, _layout_helper); } duke@435: static int access_flags_offset_in_bytes() { return offset_of(Klass, _access_flags); } duke@435: duke@435: // Unpacking layout_helper: duke@435: enum { duke@435: _lh_neutral_value = 0, // neutral non-array non-instance value duke@435: _lh_instance_slow_path_bit = 0x01, duke@435: _lh_log2_element_size_shift = BitsPerByte*0, duke@435: _lh_log2_element_size_mask = BitsPerLong-1, duke@435: _lh_element_type_shift = BitsPerByte*1, duke@435: _lh_element_type_mask = right_n_bits(BitsPerByte), // shifted mask duke@435: _lh_header_size_shift = BitsPerByte*2, duke@435: _lh_header_size_mask = right_n_bits(BitsPerByte), // shifted mask duke@435: _lh_array_tag_bits = 2, duke@435: _lh_array_tag_shift = BitsPerInt - _lh_array_tag_bits, duke@435: _lh_array_tag_type_value = ~0x00, // 0xC0000000 >> 30 duke@435: _lh_array_tag_obj_value = ~0x01 // 0x80000000 >> 30 duke@435: }; duke@435: duke@435: static int layout_helper_size_in_bytes(jint lh) { duke@435: assert(lh > (jint)_lh_neutral_value, "must be instance"); duke@435: return (int) lh & ~_lh_instance_slow_path_bit; duke@435: } duke@435: static bool layout_helper_needs_slow_path(jint lh) { duke@435: assert(lh > (jint)_lh_neutral_value, "must be instance"); duke@435: return (lh & _lh_instance_slow_path_bit) != 0; duke@435: } duke@435: static bool layout_helper_is_instance(jint lh) { duke@435: return (jint)lh > (jint)_lh_neutral_value; duke@435: } duke@435: static bool layout_helper_is_javaArray(jint lh) { duke@435: return (jint)lh < (jint)_lh_neutral_value; duke@435: } duke@435: static bool layout_helper_is_typeArray(jint lh) { duke@435: // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift); duke@435: return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift); duke@435: } duke@435: static bool layout_helper_is_objArray(jint lh) { duke@435: // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift); duke@435: return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift); duke@435: } duke@435: static int layout_helper_header_size(jint lh) { duke@435: assert(lh < (jint)_lh_neutral_value, "must be array"); duke@435: int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask; duke@435: assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity"); duke@435: return hsize; duke@435: } duke@435: static BasicType layout_helper_element_type(jint lh) { duke@435: assert(lh < (jint)_lh_neutral_value, "must be array"); duke@435: int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask; duke@435: assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity"); duke@435: return (BasicType) btvalue; duke@435: } duke@435: static int layout_helper_log2_element_size(jint lh) { duke@435: assert(lh < (jint)_lh_neutral_value, "must be array"); duke@435: int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask; duke@435: assert(l2esz <= LogBitsPerLong, "sanity"); duke@435: return l2esz; duke@435: } duke@435: static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) { duke@435: return (tag << _lh_array_tag_shift) duke@435: | (hsize << _lh_header_size_shift) duke@435: | ((int)etype << _lh_element_type_shift) duke@435: | (log2_esize << _lh_log2_element_size_shift); duke@435: } duke@435: static jint instance_layout_helper(jint size, bool slow_path_flag) { duke@435: return (size << LogHeapWordSize) duke@435: | (slow_path_flag ? _lh_instance_slow_path_bit : 0); duke@435: } duke@435: static int layout_helper_to_size_helper(jint lh) { duke@435: assert(lh > (jint)_lh_neutral_value, "must be instance"); duke@435: // Note that the following expression discards _lh_instance_slow_path_bit. duke@435: return lh >> LogHeapWordSize; duke@435: } duke@435: // Out-of-line version computes everything based on the etype: duke@435: static jint array_layout_helper(BasicType etype); duke@435: duke@435: // What is the maximum number of primary superclasses any klass can have? duke@435: #ifdef PRODUCT duke@435: static juint primary_super_limit() { return _primary_super_limit; } duke@435: #else duke@435: static juint primary_super_limit() { duke@435: assert(FastSuperclassLimit <= _primary_super_limit, "parameter oob"); duke@435: return FastSuperclassLimit; duke@435: } duke@435: #endif duke@435: duke@435: // vtables duke@435: virtual klassVtable* vtable() const { return NULL; } duke@435: duke@435: static int klass_size_in_bytes() { return offset_of(Klass, _alloc_count) + sizeof(juint); } // all "visible" fields duke@435: duke@435: // subclass check duke@435: bool is_subclass_of(klassOop k) const; duke@435: // subtype check: true if is_subclass_of, or if k is interface and receiver implements it duke@435: bool is_subtype_of(klassOop k) const { duke@435: juint off = k->klass_part()->super_check_offset(); duke@435: klassOop sup = *(klassOop*)( (address)as_klassOop() + off ); duke@435: const juint secondary_offset = secondary_super_cache_offset_in_bytes() + sizeof(oopDesc); duke@435: if (sup == k) { duke@435: return true; duke@435: } else if (off != secondary_offset) { duke@435: return false; duke@435: } else { duke@435: return search_secondary_supers(k); duke@435: } duke@435: } duke@435: bool search_secondary_supers(klassOop k) const; duke@435: twisti@1040: // Find LCA in class hierarchy duke@435: Klass *LCA( Klass *k ); duke@435: duke@435: // Check whether reflection/jni/jvm code is allowed to instantiate this class; duke@435: // if not, throw either an Error or an Exception. duke@435: virtual void check_valid_for_instantiation(bool throwError, TRAPS); duke@435: duke@435: // Casting duke@435: static Klass* cast(klassOop k) { duke@435: assert(k->is_klass(), "cast to Klass"); duke@435: return k->klass_part(); duke@435: } duke@435: duke@435: // array copying duke@435: virtual void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS); duke@435: duke@435: // tells if the class should be initialized duke@435: virtual bool should_be_initialized() const { return false; } duke@435: // initializes the klass duke@435: virtual void initialize(TRAPS); duke@435: // lookup operation for MethodLookupCache duke@435: friend class MethodLookupCache; duke@435: virtual methodOop uncached_lookup_method(symbolOop name, symbolOop signature) const; duke@435: public: duke@435: methodOop lookup_method(symbolOop name, symbolOop signature) const { duke@435: return uncached_lookup_method(name, signature); duke@435: } duke@435: duke@435: // array class with specific rank duke@435: klassOop array_klass(int rank, TRAPS) { return array_klass_impl(false, rank, THREAD); } duke@435: duke@435: // array class with this klass as element type duke@435: klassOop array_klass(TRAPS) { return array_klass_impl(false, THREAD); } duke@435: duke@435: // These will return NULL instead of allocating on the heap: duke@435: // NB: these can block for a mutex, like other functions with TRAPS arg. duke@435: klassOop array_klass_or_null(int rank); duke@435: klassOop array_klass_or_null(); duke@435: duke@435: virtual oop protection_domain() { return NULL; } duke@435: virtual oop class_loader() const { return NULL; } duke@435: duke@435: protected: duke@435: virtual klassOop array_klass_impl(bool or_null, int rank, TRAPS); duke@435: virtual klassOop array_klass_impl(bool or_null, TRAPS); duke@435: duke@435: public: duke@435: virtual void remove_unshareable_info(); duke@435: duke@435: protected: duke@435: // computes the subtype relationship duke@435: virtual bool compute_is_subtype_of(klassOop k); duke@435: public: duke@435: // subclass accessor (here for convenience; undefined for non-klass objects) duke@435: virtual bool is_leaf_class() const { fatal("not a class"); return false; } duke@435: public: duke@435: // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP duke@435: // These functions describe behavior for the oop not the KLASS. duke@435: duke@435: // actual oop size of obj in memory duke@435: virtual int oop_size(oop obj) const = 0; duke@435: duke@435: // actual oop size of this klass in memory duke@435: virtual int klass_oop_size() const = 0; duke@435: duke@435: // Returns the Java name for a class (Resource allocated) duke@435: // For arrays, this returns the name of the element with a leading '['. duke@435: // For classes, this returns the name with the package separators duke@435: // turned into '.'s. duke@435: const char* external_name() const; duke@435: // Returns the name for a class (Resource allocated) as the class duke@435: // would appear in a signature. duke@435: // For arrays, this returns the name of the element with a leading '['. duke@435: // For classes, this returns the name with a leading 'L' and a trailing ';' duke@435: // and the package separators as '/'. jrose@1474: virtual const char* signature_name() const; duke@435: duke@435: // garbage collection support duke@435: virtual void oop_follow_contents(oop obj) = 0; duke@435: virtual int oop_adjust_pointers(oop obj) = 0; duke@435: duke@435: // Parallel Scavenge and Parallel Old duke@435: PARALLEL_GC_DECLS_PV duke@435: duke@435: public: duke@435: // type testing operations duke@435: virtual bool oop_is_instance_slow() const { return false; } duke@435: virtual bool oop_is_instanceRef() const { return false; } duke@435: virtual bool oop_is_array() const { return false; } duke@435: virtual bool oop_is_objArray_slow() const { return false; } duke@435: virtual bool oop_is_symbol() const { return false; } duke@435: virtual bool oop_is_klass() const { return false; } duke@435: virtual bool oop_is_thread() const { return false; } duke@435: virtual bool oop_is_method() const { return false; } duke@435: virtual bool oop_is_constMethod() const { return false; } duke@435: virtual bool oop_is_methodData() const { return false; } duke@435: virtual bool oop_is_constantPool() const { return false; } duke@435: virtual bool oop_is_constantPoolCache() const { return false; } duke@435: virtual bool oop_is_typeArray_slow() const { return false; } duke@435: virtual bool oop_is_arrayKlass() const { return false; } duke@435: virtual bool oop_is_objArrayKlass() const { return false; } duke@435: virtual bool oop_is_typeArrayKlass() const { return false; } duke@435: virtual bool oop_is_compiledICHolder() const { return false; } duke@435: virtual bool oop_is_instanceKlass() const { return false; } duke@435: duke@435: bool oop_is_javaArray_slow() const { duke@435: return oop_is_objArray_slow() || oop_is_typeArray_slow(); duke@435: } duke@435: duke@435: // Fast non-virtual versions, used by oop.inline.hpp and elsewhere: duke@435: #ifndef ASSERT duke@435: #define assert_same_query(xval, xcheck) xval duke@435: #else duke@435: private: duke@435: static bool assert_same_query(bool xval, bool xslow) { duke@435: assert(xval == xslow, "slow and fast queries agree"); duke@435: return xval; duke@435: } duke@435: public: duke@435: #endif duke@435: inline bool oop_is_instance() const { return assert_same_query( duke@435: layout_helper_is_instance(layout_helper()), duke@435: oop_is_instance_slow()); } duke@435: inline bool oop_is_javaArray() const { return assert_same_query( duke@435: layout_helper_is_javaArray(layout_helper()), duke@435: oop_is_javaArray_slow()); } duke@435: inline bool oop_is_objArray() const { return assert_same_query( duke@435: layout_helper_is_objArray(layout_helper()), duke@435: oop_is_objArray_slow()); } duke@435: inline bool oop_is_typeArray() const { return assert_same_query( duke@435: layout_helper_is_typeArray(layout_helper()), duke@435: oop_is_typeArray_slow()); } duke@435: #undef assert_same_query duke@435: duke@435: // Unless overridden, oop is parsable if it has a klass pointer. jmasa@953: // Parsability of an object is object specific. duke@435: virtual bool oop_is_parsable(oop obj) const { return true; } duke@435: jmasa@953: // Unless overridden, oop is safe for concurrent GC processing jmasa@953: // after its allocation is complete. The exception to jmasa@953: // this is the case where objects are changed after allocation. jmasa@953: // Class redefinition is one of the known exceptions. During jmasa@953: // class redefinition, an allocated class can changed in order jmasa@953: // order to create a merged class (the combiniation of the jmasa@953: // old class definition that has to be perserved and the new class jmasa@953: // definition which is being created. jmasa@953: virtual bool oop_is_conc_safe(oop obj) const { return true; } jmasa@953: duke@435: // Access flags duke@435: AccessFlags access_flags() const { return _access_flags; } duke@435: void set_access_flags(AccessFlags flags) { _access_flags = flags; } duke@435: duke@435: bool is_public() const { return _access_flags.is_public(); } duke@435: bool is_final() const { return _access_flags.is_final(); } duke@435: bool is_interface() const { return _access_flags.is_interface(); } duke@435: bool is_abstract() const { return _access_flags.is_abstract(); } duke@435: bool is_super() const { return _access_flags.is_super(); } duke@435: bool is_synthetic() const { return _access_flags.is_synthetic(); } duke@435: void set_is_synthetic() { _access_flags.set_is_synthetic(); } duke@435: bool has_finalizer() const { return _access_flags.has_finalizer(); } duke@435: bool has_final_method() const { return _access_flags.has_final_method(); } duke@435: void set_has_finalizer() { _access_flags.set_has_finalizer(); } duke@435: void set_has_final_method() { _access_flags.set_has_final_method(); } duke@435: bool is_cloneable() const { return _access_flags.is_cloneable(); } duke@435: void set_is_cloneable() { _access_flags.set_is_cloneable(); } duke@435: bool has_vanilla_constructor() const { return _access_flags.has_vanilla_constructor(); } duke@435: void set_has_vanilla_constructor() { _access_flags.set_has_vanilla_constructor(); } duke@435: bool has_miranda_methods () const { return access_flags().has_miranda_methods(); } duke@435: void set_has_miranda_methods() { _access_flags.set_has_miranda_methods(); } duke@435: duke@435: // Biased locking support duke@435: // Note: the prototype header is always set up to be at least the duke@435: // prototype markOop. If biased locking is enabled it may further be duke@435: // biasable and have an epoch. duke@435: markOop prototype_header() const { return _prototype_header; } duke@435: // NOTE: once instances of this klass are floating around in the duke@435: // system, this header must only be updated at a safepoint. duke@435: // NOTE 2: currently we only ever set the prototype header to the duke@435: // biasable prototype for instanceKlasses. There is no technical duke@435: // reason why it could not be done for arrayKlasses aside from duke@435: // wanting to reduce the initial scope of this optimization. There duke@435: // are potential problems in setting the bias pattern for duke@435: // JVM-internal oops. duke@435: inline void set_prototype_header(markOop header); duke@435: static int prototype_header_offset_in_bytes() { return offset_of(Klass, _prototype_header); } duke@435: duke@435: int biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; } duke@435: // Atomically increments biased_lock_revocation_count and returns updated value duke@435: int atomic_incr_biased_lock_revocation_count(); duke@435: void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; } duke@435: jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; } duke@435: void set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; } duke@435: duke@435: duke@435: // garbage collection support duke@435: virtual void follow_weak_klass_links( duke@435: BoolObjectClosure* is_alive, OopClosure* keep_alive); duke@435: duke@435: // Prefetch within oop iterators. This is a macro because we duke@435: // can't guarantee that the compiler will inline it. In 64-bit duke@435: // it generally doesn't. Signature is duke@435: // duke@435: // static void prefetch_beyond(oop* const start, duke@435: // oop* const end, duke@435: // const intx foffset, duke@435: // const Prefetch::style pstyle); duke@435: #define prefetch_beyond(start, end, foffset, pstyle) { \ duke@435: const intx foffset_ = (foffset); \ duke@435: const Prefetch::style pstyle_ = (pstyle); \ duke@435: assert(foffset_ > 0, "prefetch beyond, not behind"); \ duke@435: if (pstyle_ != Prefetch::do_none) { \ duke@435: oop* ref = (start); \ duke@435: if (ref < (end)) { \ duke@435: switch (pstyle_) { \ duke@435: case Prefetch::do_read: \ duke@435: Prefetch::read(*ref, foffset_); \ duke@435: break; \ duke@435: case Prefetch::do_write: \ duke@435: Prefetch::write(*ref, foffset_); \ duke@435: break; \ duke@435: default: \ duke@435: ShouldNotReachHere(); \ duke@435: break; \ duke@435: } \ duke@435: } \ duke@435: } \ duke@435: } duke@435: duke@435: // iterators duke@435: virtual int oop_oop_iterate(oop obj, OopClosure* blk) = 0; duke@435: virtual int oop_oop_iterate_v(oop obj, OopClosure* blk) { duke@435: return oop_oop_iterate(obj, blk); duke@435: } duke@435: ysr@777: #ifndef SERIALGC ysr@777: // In case we don't have a specialized backward scanner use forward ysr@777: // iteration. ysr@777: virtual int oop_oop_iterate_backwards_v(oop obj, OopClosure* blk) { ysr@777: return oop_oop_iterate_v(obj, blk); ysr@777: } ysr@777: #endif // !SERIALGC ysr@777: duke@435: // Iterates "blk" over all the oops in "obj" (of type "this") within "mr". duke@435: // (I don't see why the _m should be required, but without it the Solaris duke@435: // C++ gives warning messages about overridings of the "oop_oop_iterate" duke@435: // defined above "hiding" this virtual function. (DLD, 6/20/00)) */ duke@435: virtual int oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) = 0; duke@435: virtual int oop_oop_iterate_v_m(oop obj, OopClosure* blk, MemRegion mr) { duke@435: return oop_oop_iterate_m(obj, blk, mr); duke@435: } duke@435: duke@435: // Versions of the above iterators specialized to particular subtypes duke@435: // of OopClosure, to avoid closure virtual calls. duke@435: #define Klass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \ duke@435: virtual int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk) { \ duke@435: /* Default implementation reverts to general version. */ \ duke@435: return oop_oop_iterate(obj, blk); \ duke@435: } \ duke@435: \ duke@435: /* Iterates "blk" over all the oops in "obj" (of type "this") within "mr". \ duke@435: (I don't see why the _m should be required, but without it the Solaris \ duke@435: C++ gives warning messages about overridings of the "oop_oop_iterate" \ duke@435: defined above "hiding" this virtual function. (DLD, 6/20/00)) */ \ duke@435: virtual int oop_oop_iterate##nv_suffix##_m(oop obj, \ duke@435: OopClosureType* blk, \ duke@435: MemRegion mr) { \ duke@435: return oop_oop_iterate_m(obj, blk, mr); \ duke@435: } duke@435: duke@435: SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_DECL) ysr@777: SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_DECL) ysr@777: ysr@777: #ifndef SERIALGC ysr@777: #define Klass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix) \ ysr@777: virtual int oop_oop_iterate_backwards##nv_suffix(oop obj, \ ysr@777: OopClosureType* blk) { \ ysr@777: /* Default implementation reverts to general version. */ \ ysr@777: return oop_oop_iterate_backwards_v(obj, blk); \ ysr@777: } ysr@777: ysr@777: SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL) ysr@777: SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL) ysr@777: #endif // !SERIALGC duke@435: duke@435: virtual void array_klasses_do(void f(klassOop k)) {} duke@435: virtual void with_array_klasses_do(void f(klassOop k)); duke@435: duke@435: // Return self, except for abstract classes with exactly 1 duke@435: // implementor. Then return the 1 concrete implementation. duke@435: Klass *up_cast_abstract(); duke@435: duke@435: // klass name duke@435: symbolOop name() const { return _name; } duke@435: void set_name(symbolOop n) { oop_store_without_check((oop*) &_name, (oop) n); } duke@435: duke@435: friend class klassKlass; duke@435: duke@435: public: duke@435: // jvm support duke@435: virtual jint compute_modifier_flags(TRAPS) const; duke@435: duke@435: public: duke@435: // JVMTI support duke@435: virtual jint jvmti_class_status() const; duke@435: duke@435: public: duke@435: // Printing jrose@1590: virtual void oop_print_value_on(oop obj, outputStream* st); jrose@1590: #ifndef PRODUCT duke@435: virtual void oop_print_on (oop obj, outputStream* st); jrose@1590: #endif //PRODUCT duke@435: duke@435: // Verification duke@435: virtual const char* internal_name() const = 0; duke@435: virtual void oop_verify_on(oop obj, outputStream* st); duke@435: virtual void oop_verify_old_oop(oop obj, oop* p, bool allow_dirty); coleenp@548: virtual void oop_verify_old_oop(oop obj, narrowOop* p, bool allow_dirty); duke@435: // tells whether obj is partially constructed (gc during class loading) duke@435: virtual bool oop_partially_loaded(oop obj) const { return false; } duke@435: virtual void oop_set_partially_loaded(oop obj) {}; duke@435: duke@435: #ifndef PRODUCT duke@435: void verify_vtable_index(int index); duke@435: #endif duke@435: };