/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_OOPS_INSTANCEKLASS_HPP
#define SHARE_VM_OOPS_INSTANCEKLASS_HPP
#include "memory/referenceType.hpp"
#include "oops/constMethodOop.hpp"
#include "oops/constantPoolOop.hpp"
#include "oops/fieldInfo.hpp"
#include "oops/instanceOop.hpp"
#include "oops/klassOop.hpp"
#include "oops/klassVtable.hpp"
#include "oops/objArrayOop.hpp"
#include "runtime/atomic.hpp"
#include "runtime/handles.hpp"
#include "utilities/accessFlags.hpp"
#include "utilities/bitMap.inline.hpp"
#include "trace/traceMacros.hpp"
// An instanceKlass is the VM level representation of a Java class.
// It contains all information needed for at class at execution runtime.
// instanceKlass layout:
// [header ] klassOop
// [klass pointer ] klassOop
// [C++ vtbl pointer ] Klass
// [subtype cache ] Klass
// [instance size ] Klass
// [java mirror ] Klass
// [super ] Klass
// [access_flags ] Klass
// [name ] Klass
// [first subklass ] Klass
// [next sibling ] Klass
// [array klasses ]
// [methods ]
// [local interfaces ]
// [transitive interfaces ]
// [fields ]
// [constants ]
// [class loader ]
// [protection domain ]
// [signers ]
// [source file name ]
// [inner classes ]
// [static field size ]
// [nonstatic field size ]
// [static oop fields size ]
// [nonstatic oop maps size ]
// [has finalize method ]
// [deoptimization mark bit ]
// [initialization state ]
// [initializing thread ]
// [Java vtable length ]
// [oop map cache (stack maps) ]
// [EMBEDDED Java vtable ] size in words = vtable_len
// [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
// The embedded nonstatic oop-map blocks are short pairs (offset, length)
// indicating where oops are located in instances of this klass.
// [EMBEDDED implementor of the interface] only exist for interface
// [EMBEDDED host klass ] only exist for an anonymous class (JSR 292 enabled)
// forward declaration for class -- see below for definition
class SuperTypeClosure;
class JNIid;
class jniIdMapBase;
class BreakpointInfo;
class fieldDescriptor;
class DepChange;
class nmethodBucket;
class PreviousVersionNode;
class JvmtiCachedClassFieldMap;
// This is used in iterators below.
public:
};
#ifndef PRODUCT
// Print fields.
// If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
public:
};
#endif // !PRODUCT
// ValueObjs embedded in klass. Describes where oops are located in instances of
// this klass.
public:
// Byte offset of the first oop mapped by this block.
// Number of oops in this block.
// sizeof(OopMapBlock) in HeapWords.
static const int size_in_words() {
}
private:
int _offset;
};
friend class VMStructs;
public:
// See "The Java Virtual Machine Specification" section 2.16.2-5 for a detailed description
// of the class loading & initialization procedure, and the use of the states.
enum ClassState {
unparsable_by_gc = 0, // object is not yet parsable by gc. Value of _init_state at object allocation.
};
public:
private:
static volatile int _total_instanceKlass_count;
protected:
//
// The oop block. See comment in klass.hpp before making changes.
//
// Array classes holding elements of this class.
// Method array.
// Int array containing the original order of method in the class file (for
// JVMTI).
// Interface (klassOops) this class declares locally to implement.
// Interface (klassOops) this class implements transitively.
// Instance and static variable information, starts with 6-tuples of shorts
// [access, name index, sig index, initval index, low_offset, high_offset]
// for all fields, followed by the generic signature data at the end of
// the array. Only fields with generic signature attributes have the generic
// signature data set in the array. The fields array looks like following:
//
// f1: [access, name index, sig index, initial value index, low_offset, high_offset]
// f2: [access, name index, sig index, initial value index, low_offset, high_offset]
// ...
// fn: [access, name index, sig index, initial value index, low_offset, high_offset]
// [generic signature index]
// [generic signature index]
// ...
// Constant pool for this class.
// Class loader used to load this class, NULL if VM loader used.
// Protection domain.
// Class signers.
// The InnerClasses attribute and EnclosingMethod attribute. The
// _inner_classes is an array of shorts. If the class has InnerClasses
// attribute, then the _inner_classes array begins with 4-tuples of shorts
// [inner_class_info_index, outer_class_info_index,
// inner_name_index, inner_class_access_flags] for the InnerClasses
// attribute. If the EnclosingMethod attribute exists, it occupies the
// last two shorts [class_index, method_index] of the array. If only
// the InnerClasses attribute exists, the _inner_classes array length is
// number_of_inner_classes * 4. If the class has both InnerClasses
// and EnclosingMethod attributes the _inner_classes array length is
// number_of_inner_classes * 4 + enclosing_method_attribute_size.
// Annotations for this class, or null if none.
// Annotation objects (byte arrays) for fields, or null if no annotations.
// Indices correspond to entries (not indices) in fields array.
// Annotation objects (byte arrays) for methods, or null if no annotations.
// Index is the idnum, which is initially the same as the methods array index.
// Annotation objects (byte arrays) for methods' parameters, or null if no
// such annotations.
// Index is the idnum, which is initially the same as the methods array index.
// Annotation objects (byte arrays) for methods' default values, or null if no
// such annotations.
// Index is the idnum, which is initially the same as the methods array index.
//
// End of the oop block.
//
// Name of source file containing this klass, NULL if not specified.
// the source debug extension for this klass, NULL if not specified.
// Specified as UTF-8 string without terminating zero byte in the classfile,
// it is stored in the instanceklass as a NULL-terminated UTF-8 string
char* _source_debug_extension;
// Generic signature, or null if none.
// Array name derived from this class which needs unreferencing
// if this class is unloaded.
// Number of heapOopSize words used by non-static fields in this klass
// (including inherited fields but after header_size()).
enum {
};
Thread* _init_thread; // Pointer to current thread doing initialization (to handle recusive initialization)
OopMapCache* volatile _oop_map_cache; // OopMapCache for all methods in the klass (allocated lazily)
int* _methods_cached_itable_indices; // itable_index cache for JNI invoke corresponding to methods idnum, or NULL
// Array of interesting part(s) of the previous version(s) of this
// instanceKlass. See PreviousVersionWalker below.
// JVMTI fields can be moved to their own structure - see 6315920
unsigned char * _cached_class_file_bytes; // JVMTI: cached class file, before retransformable agent modified it in CFLH
volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change
// Class states are defined as ClassState (see above).
// Place the _init_state here to utilize the unused 2-byte after
// _idnum_allocated_count.
// embedded Java vtable follows here
// embedded Java itables follows here
// embedded static fields follows here
// embedded nonstatic oop-map blocks follows here
// embedded implementor of this interface follows here
// The embedded implementor only exists if the current klass is an
// iterface. The possible values of the implementor fall into following
// three cases:
// NULL: no implementor.
// A klassOop that's not itself: one implementor.
// Itsef: more than one implementors.
// embedded host klass follows here
// The embedded host klass only exists in an anonymous class for
// dynamic language support (JSR 292 enabled). The host class grants
// its access privileges to this class also. The host class is either
// named, or a previously loaded anonymous class. A non-anonymous class
// or an anonymous class loaded through normal classloading does not
// have this embedded field.
//
friend class instanceKlassKlass;
friend class SystemDictionary;
public:
bool has_nonstatic_fields() const {
return (_misc_flags & _misc_has_nonstatic_fields) != 0;
}
void set_has_nonstatic_fields(bool b) {
if (b) {
} else {
}
}
// field sizes
// Java vtable
// Java itable
// array klasses
// methods
// method ordering
void set_method_ordering(typeArrayOop m) { oop_store_without_check((oop*) &_method_ordering, (oop) m); }
// interfaces
void set_local_interfaces(objArrayOop a) { oop_store_without_check((oop*) &_local_interfaces, (oop) a); }
void set_transitive_interfaces(objArrayOop a) { oop_store_without_check((oop*) &_transitive_interfaces, (oop) a); }
private:
friend class fieldDescriptor;
public:
// Number of Java declared fields
}
// inner classes
void set_inner_classes(typeArrayOop f) { oop_store_without_check((oop*) &_inner_classes, (oop) f); }
enum InnerClassAttributeOffset {
// From http://mirror.eng/products/jdk/1.1/docs/guide/innerclasses/spec/innerclasses.doc10.html#18814
};
};
// method override check
bool is_override(methodHandle super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS);
// package
static bool is_same_class_package(oop class_loader1, Symbol* class_name1, oop class_loader2, Symbol* class_name2);
// find an enclosing class (defined where original code was, in jvm.cpp!)
}
bool* inner_is_member, TRAPS);
// tell if two classes have the same enclosing class (at package level)
}
// initialization state
// defineClass specified verification
bool should_verify_class() const {
return (_misc_flags & _misc_should_verify_class) != 0;
}
if (value) {
} else {
}
}
// marking
// initialization (virtuals from Klass)
bool should_be_initialized() const; // means that initialize should be called
void initialize(TRAPS);
void link_class(TRAPS);
void unlink_class();
void rewrite_class(TRAPS);
void relocate_and_link_methods(TRAPS);
// set the class to initialized if no static initializer is present
// reference type
_reference_type = (u1)t;
}
static ByteSize reference_type_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(instanceKlass, _reference_type)); }
// find local field, returns true if found
// find field in direct superinterfaces, returns the interface in which the field is defined
// find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined
// find instance or static fields according to JVM spec 5.4.3.2, returns the klass in which the field is defined
// find a non-static or static field given its offset within the class.
}
// find a local method (returns NULL if not found)
// lookup operation (returns NULL if not found)
// lookup a method in all the interfaces that this class implements
// (returns NULL if not found)
// constant pool
// class loader
// protection domain
// host class
return NULL;
} else {
return *hk;
}
}
}
bool is_anonymous() const {
return (_misc_flags & _misc_is_anonymous) != 0;
}
if (value) {
} else {
}
}
// signers
// source file name
void set_source_file_name(Symbol* n);
// minor and major version numbers of class file
// source debug extension
// symbol unloading support (refcount already added)
void set_array_name(Symbol* name) { assert(_array_name == NULL, "name already created"); _array_name = name; }
// nonstatic oop-map blocks
}
unsigned int nonstatic_oop_map_count() const {
}
}
// RedefineClasses() support for previous versions:
int emcp_method_count);
// If the _previous_versions array is non-NULL, then this klass
// has been redefined at least once even if we aren't currently
// tracking a previous version.
bool has_previous_version() const;
void init_previous_versions() {
}
return _previous_versions;
}
// JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation
// JVMTI: Support for caching of field indices, types, and offsets
}
return _jvmti_cached_class_field_map;
}
// for adding methods, constMethodOopDesc::UNSET_IDNUM means no more ids available
inline u2 next_method_idnum();
// generics support
}
}
// jmethodID support
// cached itable index support
// annotations support
void set_class_annotations(typeArrayOop md) { oop_store_without_check((oop*)&_class_annotations, (oop)md); }
void set_methods_parameter_annotations(objArrayOop md) { set_annotations(md, &_methods_parameter_annotations); }
void set_methods_default_annotations(objArrayOop md) { set_annotations(md, &_methods_default_annotations); }
// allocation
// additional member function to return a handle
instanceHandle allocate_instance_handle(TRAPS) { return instanceHandle(THREAD, allocate_instance(THREAD)); }
// Helper function
// Check whether reflection/jni/jvm code is allowed to instantiate this class;
// if not, throw either an Error or an Exception.
// initialization
void call_class_initializer(TRAPS);
// OopMapCache support
// JNI identifier support (for static fields - for jni performance)
// maintenance of deoptimization dependencies
// On-stack replacement support
void add_osr_nmethod(nmethod* n);
void remove_osr_nmethod(nmethod* n);
// Breakpoint support (see methods on methodOop for details)
// support for stub routines
static ByteSize init_state_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(instanceKlass, _init_state)); }
static ByteSize init_thread_offset() { return in_ByteSize(sizeof(klassOopDesc) + offset_of(instanceKlass, _init_thread)); }
// subclass/subinterface checks
bool implements_interface(klassOop k) const;
// Access to the implementor of an interface.
{
if (k == NULL) {
return NULL;
} else {
return *k;
}
}
}
int nof_implementors() const {
klassOop k = implementor();
if (k == NULL) {
return 0;
} else if (k != this->as_klassOop()) {
return 1;
} else {
return 2;
}
}
void init_implementor(); // initialize
// link this class into the implementors list of every interface it implements
// virtual operations from Klass
bool compute_is_subtype_of(klassOop k);
bool can_be_primary_super_slow() const;
bool oop_is_instance_slow() const { return true; }
// Iterators
void array_klasses_do(void f(klassOop k));
void with_array_klasses_do(void f(klassOop k));
// Casting from klassOop
return (instanceKlass*) kp;
}
// Sizing (in words)
static int header_size() { return align_object_offset(oopDesc::header_size() + sizeof(instanceKlass)/HeapWordSize); }
int object_size() const
{
((is_interface() || is_anonymous()) ?
}
static int vtable_length_offset() { return oopDesc::header_size() + offset_of(instanceKlass, _vtable_len) / HeapWordSize; }
intptr_t* start_of_itable() const { return start_of_vtable() + align_object_offset(vtable_length()); }
}
if (is_interface()) {
return (oop*)(start_of_nonstatic_oop_maps() +
} else {
return NULL;
}
};
if (is_anonymous()) {
return adr_impl + 1;
} else {
return (oop*)(start_of_nonstatic_oop_maps() +
}
} else {
return NULL;
}
}
// Allocation profiling support
// Use this to return the size of an instance in heap words:
int size_helper() const {
return layout_helper_to_size_helper(layout_helper());
}
// This bit is initialized in classFileParser.cpp.
// It is false under any of the following conditions:
// - the class is abstract (including any interface)
// - the class has a finalizer (if !RegisterFinalizersAtInit)
// - the class size is larger than FastAllocateSizeLimit
bool can_be_fastpath_allocated() const {
return !layout_helper_needs_slow_path(layout_helper());
}
// Garbage collection
// Value of _init_state must be zero (unparsable_by_gc) when klass field is set.
void follow_weak_klass_links(
void release_C_heap_structures();
// Parallel Scavenge and Parallel Old
// Naming
const char* signature_name() const;
// Iterators
}
}
#ifndef SERIALGC
#endif // !SERIALGC
private:
// initialization state
#ifdef ASSERT
#else
#endif
// The RedefineClasses() API can cause new method idnums to be needed
// which will cause the caches to grow. Safety requires different
// cache management logic if the caches can grow instead of just
// going from NULL to non-NULL.
int* methods_cached_itable_indices_acquire() const
void set_annotations(objArrayOop md, objArrayOop* md_p) { oop_store_without_check((oop*)md_p, (oop)md); }
// Offsets for memory management
oop* adr_methods_cached_itable_indices() const { return (oop*)&this->_methods_cached_itable_indices;}
oop* adr_methods_parameter_annotations() const { return (oop*)&this->_methods_parameter_annotations;}
// Static methods that are used to implement member methods where an exposed this pointer
// is needed due to possible GCs
static void set_initialization_state_and_notify_impl (instanceKlassHandle this_oop, ClassState state, TRAPS);
static void do_local_static_fields_impl (instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS);
/* jni_id_for_impl for jfieldID only */
// Returns the array class for the n'th dimension
// Returns the array class with this class as element type
public:
// sharing support
virtual void remove_unshareable_info();
// jvm support
public:
// JVMTI support
jint jvmti_class_status() const;
public:
// Printing
#ifndef PRODUCT
void print_dependent_nmethods(bool verbose = false);
#endif
// Verification
const char* internal_name() const;
};
#ifndef PRODUCT
if (DebugVtables) {
}
#endif
}
return NULL;
}
}
// for adding methods
// UNSET_IDNUM return means no more ids available
} else {
return _idnum_allocated_count++;
}
}
/* JNIid class for jfieldIDs only */
friend class VMStructs;
private:
int _offset;
#ifdef ASSERT
bool _is_static_field_id;
#endif
public:
// Accessors
// Constructor
// Identifier lookup
}
// Garbage collection support
void oops_do(OopClosure* f);
// Debugging
#ifdef ASSERT
#endif
};
// If breakpoints are more numerous than just JVMTI breakpoints,
// consider compressing this data structure.
// It is currently a simple linked list defined in methodOop.hpp.
class BreakpointInfo;
// A collection point for interesting information about the previous
// version(s) of an instanceKlass. This class uses weak references to
// the information so that the information may be collected as needed
// by the system. If the information is shared, then a regular
// reference must be used because a weak reference would be seen as
// collectible. A GrowableArray of PreviousVersionNodes is attached
// to the instanceKlass as needed. See PreviousVersionWalker below.
private:
// A shared ConstantPool is never collected so we'll always have
// a reference to it so we can update items in the cache. We'll
// have a weak reference to a non-shared ConstantPool until all
// of the methods (EMCP or obsolete) have been collected; the
// non-shared ConstantPool becomes collectible at that point.
// If the previous version of the instanceKlass doesn't have any
// EMCP methods, then _prev_EMCP_methods will be NULL. If all the
// EMCP methods have been collected, then _prev_EMCP_methods can
// have a length of zero.
public:
return _prev_constant_pool;
}
return _prev_EMCP_methods;
}
};
// A Handle-ized version of PreviousVersionNode.
private:
// If the previous version of the instanceKlass doesn't have any
// EMCP methods, then _prev_EMCP_methods will be NULL. Since the
// methods cannot be collected while we hold a handle,
// _prev_EMCP_methods should never have a length of zero.
public:
return _prev_constant_pool_handle;
}
return _prev_EMCP_method_handles;
}
};
// Helper object for walking previous versions. This helper cleans up
// the Handles that it allocates when the helper object is destroyed.
// The PreviousVersionInfo object returned by next_previous_version()
// is only valid until a subsequent call to next_previous_version() or
// the helper object is destroyed.
private:
int _current_index;
// Fields for cleaning up when we are done walking the previous versions:
// A HandleMark for the PreviousVersionInfo handles:
// It would be nice to have a ResourceMark field in this helper also,
// but the ResourceMark code says to be careful to delete handles held
// in GrowableArrays _before_ deleting the GrowableArray. Since we
// can't guarantee the order in which the fields are destroyed, we
// have to let the creator of the PreviousVersionWalker object do
// the right thing. Also, adding a ResourceMark here causes an
// include loop.
// A pointer to the current info object so we can handle the deletes.
public:
// Return the interesting information for the next previous version
// of the klass. Returns NULL if there are no more previous versions.
};
//
// nmethodBucket is used to record dependent nmethods for
// deoptimization. nmethod dependencies are actually <klass, method>
// pairs but we really only care about the klass part for purposes of
// finding nmethods which might need to be deoptimized. Instead of
// recording the method, a count of how many times a particular nmethod
// was recorded is kept. This ensures that any recording errors are
// noticed since an nmethod should be removed as many times are it's
// added.
//
friend class VMStructs;
private:
int _count;
public:
_count = 1;
}
};
// An iterator that's used to access the inner classes indices in the
// instanceKlass::_inner_classes array.
private:
int _length;
int _idx;
public:
_inner_classes = k->inner_classes();
if (k->inner_classes() != NULL) {
// The inner class array's length should be the multiple of
// inner_class_next_offset if it only contains the InnerClasses
// attribute data, or it should be
// n*inner_class_next_offset+enclosing_method_attribute_size
// if it also contains the EnclosingMethod data.
_length % instanceKlass::inner_class_next_offset == instanceKlass::enclosing_method_attribute_size),
"just checking");
// Remove the enclosing_method portion if exists.
if (_length % instanceKlass::inner_class_next_offset == instanceKlass::enclosing_method_attribute_size) {
}
} else {
_length = 0;
}
_idx = 0;
}
int length() const {
return _length;
}
void next() {
}
bool done() const {
}
return _inner_classes->ushort_at(
}
}
return _inner_classes->ushort_at(
}
}
return _inner_classes->ushort_at(
}
}
return _inner_classes->ushort_at(
}
};
#endif // SHARE_VM_OOPS_INSTANCEKLASS_HPP