// OBJECT hierarchy// This hierarchy is a representation hierarchy, i.e. if A is a superclass// of B, A's representation is a prefix of B's representation.typedefclassoopDesc* oop;typedefclassinstanceOopDesc* instanceOop;typedefclassarrayOopDesc* arrayOop;typedefclassobjArrayOopDesc* objArrayOop;typedefclasstypeArrayOopDesc* typeArrayOop;
typedef juint narrowOop;// Offset instead of address for an oop within a java object// If compressed klass pointers then use narrowKlass.typedef juint narrowKlass;
而juint则在globalDefinitions.hpp定义为u4
metadata hierarchy
// The metadata hierarchy is separate from the oop hierarchy// class MetaspaceObjclassConstMethod;classConstantPoolCache;classMethodData;// class MetadataclassMethod;classConstantPool;// class CHeapObjclassCompiledICHolder;
klass hierarchy
// The klass hierarchy is separate from the oop hierarchy.classKlass;classInstanceKlass;classInstanceMirrorKlass;classInstanceClassLoaderKlass;classInstanceRefKlass;classArrayKlass;classObjArrayKlass;classTypeArrayKlass;
// 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 {
allocated,// allocated (but not yet linked)
loaded,// loaded and inserted in class hierarchy (but not linked yet)
linked,// successfully linked/verified (but not initialized yet)
being_initialized,// currently running class initializer
fully_initialized,// initialized (successfull final state)
initialization_error // error happened during initialization};
// Describes where oops are located in instances of this klass.
class OopMapBlock {
public:voidincrement_count(int diff){ _count += diff;}intoffset_span()const{return _count * heapOopSize;}intend_offset()const{returnoffset()+offset_span();}
bool is_contiguous(int another_offset)const{return another_offset ==end_offset();}// sizeof(OopMapBlock) in words.staticconstintsize_in_words(){returnalign_up((int)sizeof(OopMapBlock), wordSize)>>
LogBytesPerWord;}staticintcompare_offset(const OopMapBlock* a,const OopMapBlock* b){return a->offset()- b->offset();}
private:int _offset;//PUBLIC
uint _count;//PUBLIC};
// An InstanceKlass is the VM level representation of a Java class.// It contains all information needed for at class at execution runtime.// InstanceKlass embedded field layout (after declared fields):// [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 unsafe_anonymous_host klass] only exist for an unsafe anonymous class (JSR 292 enabled)// [EMBEDDED fingerprint ] only if should_store_fingerprint()==true// forward declaration for class -- see below for definition
class InstanceKlass: public Klass {
friend class VMStructs;
friend class JVMCIVMStructs;
friend class ClassFileParser;
friend class CompileReplay;
public:staticconst KlassID ID = InstanceKlassID;
protected:InstanceKlass(const ClassFileParser& parser,unsigned kind, KlassID id = ID);
public:InstanceKlass(){assert(DumpSharedSpaces || UseSharedSpaces,"only for CDS");}
private:static InstanceKlass*allocate_instance_klass(const ClassFileParser& parser, TRAPS);
protected:
Annotations* _annotations;//PUBLIC Annotations for this class// Package this class is defined in
PackageEntry* _package_entry;// Array classes holding elements of this class.
ObjArrayKlass*volatile _array_klasses;//PUBLIC
ConstantPool* _constants;//PUBLIC Constant pool for this class.
Array<jushort>* _inner_classes;//PUBLIC
Array<jushort>* _nest_members;//PUBLIC class info index for the class that is a nest member// Resolved nest-host klass: either true nest-host or self if we are not// nested, or an error occurred resolving or validating the nominated// nest-host. Can also be set directly by JDK API's that establish nest// relationships.// By always being set it makes nest-member access checks simpler.
InstanceKlass* _nest_host;
Array<jushort>* _permitted_subclasses;//PUBLIC class info index for the class that is a permitted subclass
Array<RecordComponent*>* _record_components;//PUBLIC The contents of the Record attribute.// 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 stringconstchar* _source_debug_extension;// Number of heapOopSize words used by non-static fields in this klass// (including inherited fields but after header_size()).int _nonstatic_field_size;//PUBLICint _static_field_size;//PUBLIC number words used by static fields (oop and non-oop) in this klassint _nonstatic_oop_map_size;//PUBLIC size in words of nonstatic oop map blocksint _itable_len;// length of Java itable (in words)// The NestHost attribute. The class info index for the class// that is the nest-host of this class. This data has not been validated.
u2 _nest_host_index;//PUBLIC
u2 _this_class_index;//PUBLIC constant pool entry
u2 _static_oop_field_count;//PUBLIC number of static oop fields in this klass
u2 _java_fields_count;// The number of declared Java fieldsvolatile u2 _idnum_allocated_count;// JNI/JVMTI: increments with the addition of methods, old ids don't change
bool _is_marked_dependent;//PUBLIC used for marking during flushing and deoptimization// Class states are defined as ClassState (see above).// Place the _init_state here to utilize the unused 2-byte after// _idnum_allocated_count.
u1 _init_state;// state of class// This can be used to quickly discriminate among the four kinds of// InstanceKlass. This should be an enum (?)staticconstunsigned _kind_other =0;// concrete InstanceKlassstaticconstunsigned _kind_reference =1;// InstanceRefKlassstaticconstunsigned _kind_class_loader =2;// InstanceClassLoaderKlassstaticconstunsigned _kind_mirror =3;// InstanceMirrorKlass
u1 _reference_type;// reference type
u1 _kind;// kind of InstanceKlass
u2 shared_loader_type_bits()const{return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class;}
u2 _misc_flags;// There is more space in access_flags for more flags.
Thread* _init_thread;// Pointer to current thread doing initialization (to handle recursive initialization)
OopMapCache*volatile _oop_map_cache;//PUBLIC OopMapCache for all methods in the klass (allocated lazily)
JNIid* _jni_ids;//PUBLIC First JNI identifier for static fields in this class
jmethodID*volatile _methods_jmethod_ids;// jmethodIDs corresponding to method_idnum, or NULL if none
nmethodBucket*volatile _dep_context;// packed DependencyContext structure
uint64_t volatile _dep_context_last_cleaned;
nmethod* _osr_nmethods_head;//PUBLIC Head of list of on-stack replacement nmethods for this class
Array<Method*>* _methods;//PUBLIC Method array.
Array<Method*>* _default_methods;//PUBLIC Default Method Array, concrete methods inherited from interfaces// Interfaces (InstanceKlass*s) this class declares locally to implement.
Array<InstanceKlass*>* _local_interfaces;//只被赋值一次// Interfaces (InstanceKlass*s) this class implements transitively.
Array<InstanceKlass*>* _transitive_interfaces;//只被赋值一次
Array<int>* _method_ordering;//PUBLIC Int array containing the original order of method in the class file (for JVMTI).// Int array containing the vtable_indices for default_methods// offset matches _default_methods offset
Array<int>* _default_vtable_indices;//PUBLLIC// 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]// ...
Array<u2>* _fields;// 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 Klass* that's not itself: one implementor.// Itself: more than one implementors.// embedded unsafe_anonymous_host klass follows here// The embedded host klass only exists in an unsafe 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 unsafe anonymous class. A non-anonymous class// or an anonymous class loaded through normal classloading does not// have this embedded field.//
friend class SystemDictionary;static bool _disable_method_binary_search;
public:// The UNREGISTERED class loader type
bool is_shared_unregistered_class()const{return(_misc_flags &shared_loader_type_bits())==0;}voidclear_shared_class_loader_type(){
_misc_flags &=~shared_loader_type_bits();}voidset_shared_class_loader_type(s2 loader_type);voidassign_class_loader_type();// methods
Method*method_with_idnum(int idnum);
Method*method_with_orig_idnum(int idnum);
Method*method_with_orig_idnum(int idnum,int version);// method orderingvoidcopy_method_ordering(const intArray* m, TRAPS);// default method vtable_indices
Array<int>*create_new_default_vtable_indices(int len, TRAPS);
private:
friend class fieldDescriptor;
FieldInfo*field(int index)const{return FieldInfo::from_field_array(_fields, index);}
public:int field_offset (int index)const{returnfield(index)->offset();}intfield_access_flags(int index)const{returnfield(index)->access_flags();}
Symbol* field_name (int index)const{returnfield(index)->name(constants());}
Symbol* field_signature (int index)const{returnfield(index)->signature(constants());}// Number of Java declared fieldsintjava_fields_count()const{return(int)_java_fields_count;}
Array<u2>*fields()const{return _fields;}voidset_fields(Array<u2>* f, u2 java_fields_count){guarantee(_fields ==NULL|| f ==NULL,"Just checking");
_fields = f;
_java_fields_count = java_fields_count;}// dynamic nest member supportvoidset_nest_host(InstanceKlass* host, TRAPS);
bool is_record()const{return _record_components !=NULL;}
private:// Called to verify that k is a member of this nest - does not look at k's nest-host
bool has_nest_member(InstanceKlass* k, TRAPS)const;
public:// Used to construct informative IllegalAccessError messages at a higher level,// if there was an issue resolving or validating the nest host.// Returns NULL if there was no error.constchar*nest_host_error(TRAPS);// Returns nest-host class, resolving and validating it if needed.// Returns NULL if resolution is not possible from the calling context.
InstanceKlass*nest_host(TRAPS);// Check if this klass is a nestmate of k - resolves this nest-host and k's
bool has_nestmate_access_to(InstanceKlass* k, TRAPS);// Called to verify that k is a permitted subclass of this class
bool has_as_permitted_subclass(const InstanceKlass* k)const;// method override check
bool is_override(const methodHandle& super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS);// package
PackageEntry*package()const{return _package_entry;}
ModuleEntry*module()const;
bool in_unnamed_package()const{return(_package_entry ==NULL);}voidset_package(ClassLoaderData* loader_data, PackageEntry* pkg_entry, TRAPS);// If the package for the InstanceKlass is in the boot loader's package entry// table then sets the classpath_index field so that// get_system_package() will know to return a non-null value for the// package's location. And, so that the package will be added to the list of// packages returned by get_system_packages().// For packages whose classes are loaded from the boot loader class path, the// classpath_index indicates which entry on the boot loader class path.voidset_classpath_index(s2 path_index, TRAPS);
bool is_same_class_package(const Klass* class2)const;
bool is_same_class_package(oop other_class_loader,const Symbol* other_class_name)const;// find an enclosing class
InstanceKlass*compute_enclosing_class(bool* inner_is_member, TRAPS)const;// Find InnerClasses attribute and return outer_class_info_index & inner_name_index.
bool find_inner_classes_attr(int* ooff,int* noff, TRAPS)const;
private:// Check prohibited package ("java/" only loadable by boot or platform loaders)staticvoidcheck_prohibited_package(Symbol* class_name,
ClassLoaderData* loader_data,
TRAPS);
public:// initialization state
bool is_loaded()const{return _init_state >= loaded;}
bool is_linked()const{return _init_state >= linked;}
bool is_initialized()const{return _init_state == fully_initialized;}
bool is_not_initialized()const{return _init_state < being_initialized;}
bool is_being_initialized()const{return _init_state == being_initialized;}
bool is_in_error_state()const{return _init_state == initialization_error;}
bool is_reentrant_initialization(Thread *thread){return thread == _init_thread;}
ClassState init_state(){return(ClassState)_init_state;}// is this a sealed class
bool is_sealed()const;// initialization (virtuals from Klass)
bool should_be_initialized()const;// means that initialize should be calledvoidinitialize(TRAPS);voidlink_class(TRAPS);
bool link_class_or_fail(TRAPS);// returns false on failurevoidrewrite_class(TRAPS);voidlink_methods(TRAPS);
Method*class_initializer()const;// set the class to initialized if no static initializer is presentvoideager_initialize(Thread *thread);// reference type
ReferenceType reference_type()const{return(ReferenceType)_reference_type;}voidset_reference_type(ReferenceType t){assert(t ==(u1)t,"overflow");
_reference_type =(u1)t;}static ByteSize reference_type_offset(){returnin_ByteSize(offset_of(InstanceKlass, _reference_type));}// find local field, returns true if found
bool find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd)const;// find field in direct superinterfaces, returns the interface in which the field is defined
Klass*find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd)const;// find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined
Klass*find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd)const;// find instance or static fields according to JVM spec 5.4.3.2, returns the klass in which the field is defined
Klass*find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd)const;// find a non-static or static field given its offset within the class.
bool contains_field_offset(int offset);
bool find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd)const;
bool find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd)const;
private:inlinestaticintquick_search(const Array<Method*>* methods,const Symbol* name);
public:staticvoiddisable_method_binary_search(){
_disable_method_binary_search = true;}// find a local method (returns NULL if not found)
Method*find_method(const Symbol* name,const Symbol* signature)const;static Method*find_method(const Array<Method*>* methods,const Symbol* name,const Symbol* signature);// find a local method, but skip static methods
Method*find_instance_method(const Symbol* name,const Symbol* signature,
PrivateLookupMode private_mode)const;static Method*find_instance_method(const Array<Method*>* methods,const Symbol* name,const Symbol* signature,
PrivateLookupMode private_mode);// find a local method (returns NULL if not found)
Method*find_local_method(const Symbol* name,const Symbol* signature,
OverpassLookupMode overpass_mode,
StaticLookupMode static_mode,
PrivateLookupMode private_mode)const;// find a local method from given methods array (returns NULL if not found)static Method*find_local_method(const Array<Method*>* methods,const Symbol* name,const Symbol* signature,
OverpassLookupMode overpass_mode,
StaticLookupMode static_mode,
PrivateLookupMode private_mode);// find a local method index in methods or default_methods (returns -1 if not found)staticintfind_method_index(const Array<Method*>* methods,const Symbol* name,const Symbol* signature,
OverpassLookupMode overpass_mode,
StaticLookupMode static_mode,
PrivateLookupMode private_mode);// lookup operation (returns NULL if not found)
Method*uncached_lookup_method(const Symbol* name,const Symbol* signature,
OverpassLookupMode overpass_mode,
PrivateLookupMode private_mode = find_private)const;// lookup a method in all the interfaces that this class implements// (returns NULL if not found)
Method*lookup_method_in_all_interfaces(Symbol* name, Symbol* signature, DefaultsLookupMode defaults_mode)const;// lookup a method in local defaults then in all interfaces// (returns NULL if not found)
Method*lookup_method_in_ordered_interfaces(Symbol* name, Symbol* signature)const;// Find method indices by name. If a method with the specified name is// found the index to the first method is returned, and 'end' is filled in// with the index of first non-name-matching method. If no method is found// -1 is returned.intfind_method_by_name(const Symbol* name,int* end)const;staticintfind_method_by_name(const Array<Method*>* methods,const Symbol* name,int* end);// protection domain
oop protection_domain()const;// signers
objArrayOop signers()const;// host class
InstanceKlass*unsafe_anonymous_host()const{
InstanceKlass** hk =adr_unsafe_anonymous_host();if(hk ==NULL){assert(!is_unsafe_anonymous(),"Unsafe anonymous classes have host klasses");returnNULL;}else{assert(*hk !=NULL,"host klass should always be set if the address is not null");assert(is_unsafe_anonymous(),"Only unsafe anonymous classes have host klasses");return*hk;}}voidset_unsafe_anonymous_host(const InstanceKlass* host){assert(is_unsafe_anonymous(),"not unsafe anonymous");const InstanceKlass** addr =(const InstanceKlass **)adr_unsafe_anonymous_host();assert(addr !=NULL,"no reversed space");if(addr !=NULL){*addr = host;}}// source debug extensionconstchar*source_debug_extension()const{return _source_debug_extension;}voidset_source_debug_extension(constchar* array,int length);// nonstatic oop-map blocksstaticintnonstatic_oop_map_size(unsignedint oop_map_count){return oop_map_count * OopMapBlock::size_in_words();}unsignedintnonstatic_oop_map_count()const{return _nonstatic_oop_map_size / OopMapBlock::size_in_words();}// 对于非JVMTI的情况总是NULL
InstanceKlass*previous_versions()const{returnNULL;}
InstanceKlass*get_klass_version(int version){returnNULL;}
bool supers_have_passed_fingerprint_checks();static bool should_store_fingerprint(bool is_hidden_or_anonymous);
bool should_store_fingerprint()const{returnshould_store_fingerprint(is_hidden()||is_unsafe_anonymous());}
bool has_stored_fingerprint()const;
uint64_t get_stored_fingerprint()const;voidstore_fingerprint(uint64_t fingerprint);
private:voidset_kind(unsigned kind){ _kind =(u1)kind;}
bool is_kind(unsigned desired)const{return _kind ==(u1)desired;}
public:// Other is anything that is not one of the more specialized kinds of InstanceKlass.
bool is_other_instance_klass()const{returnis_kind(_kind_other);}
bool is_reference_instance_klass()const{returnis_kind(_kind_reference);}
bool is_mirror_instance_klass()const{returnis_kind(_kind_mirror);}
bool is_class_loader_instance_klass()const{returnis_kind(_kind_class_loader);}staticvoidpurge_previous_versions(InstanceKlass* ik){return;};static bool has_previous_versions_and_reset(){return false;}voidset_cached_class_file(JvmtiCachedClassFileData *data){assert(data ==NULL,"unexpected call with JVMTI disabled");}
JvmtiCachedClassFileData *get_cached_class_file(){return(JvmtiCachedClassFileData *)NULL;}// for adding methods, ConstMethod::UNSET_IDNUM means no more ids availableinline u2 next_method_idnum();voidset_initial_method_idnum(u2 value){ _idnum_allocated_count = value;}
u2 enclosing_method_data(int offset)const;
u2 enclosing_method_class_index()const{returnenclosing_method_data(enclosing_method_class_index_offset);}
u2 enclosing_method_method_index(){returnenclosing_method_data(enclosing_method_method_index_offset);}voidset_enclosing_method_indices(u2 class_index,
u2 method_index);// jmethodID support
jmethodID get_jmethod_id(const methodHandle& method_h);
jmethodID get_jmethod_id_fetch_or_update(size_t idnum,
jmethodID new_id, jmethodID* new_jmeths,
jmethodID* to_dealloc_id_p,
jmethodID** to_dealloc_jmeths_p);staticvoidget_jmethod_id_length_value(jmethodID* cache, size_t idnum,
size_t *length_p, jmethodID* id_p);voidensure_space_for_methodids(int start_offset =0);
jmethodID jmethod_id_or_null(Method* method);
instanceOop allocate_instance(TRAPS);// allocationstatic instanceOop allocate_instance(oop cls, TRAPS);// additional member function to return a handle
instanceHandle allocate_instance_handle(TRAPS);
objArrayOop allocate_objArray(int n,int length, TRAPS);// Helper functionstatic instanceOop register_finalizer(instanceOop i, TRAPS);// Check whether reflection/jni/jvm code is allowed to instantiate this class;// if not, throw either an Error or an Exception.
virtual voidcheck_valid_for_instantiation(bool throwError, TRAPS);voidcall_class_initializer(TRAPS);// initializationvoidset_initialization_state_and_notify(ClassState state, TRAPS);voidmask_for(const methodHandle& method,int bci, InterpreterOopMap* entry);
JNIid*jni_id_for(int offset);// maintenance of deoptimization dependenciesinline DependencyContext dependencies();intmark_dependent_nmethods(KlassDepChange& changes);voidadd_dependent_nmethod(nmethod* nm);voidremove_dependent_nmethod(nmethod* nm);voidclean_dependency_context();// On-stack replacement supportvoidadd_osr_nmethod(nmethod* n);
bool remove_osr_nmethod(nmethod* n);intmark_osr_nmethods(const Method* m);
nmethod*lookup_osr_nmethod(const Method* m,int bci,int level, bool match_level)const;// support for stub routinesstatic ByteSize init_state_offset(){returnin_ByteSize(offset_of(InstanceKlass, _init_state));}JFR_ONLY(DEFINE_KLASS_TRACE_ID_OFFSET;)static ByteSize init_thread_offset(){returnin_ByteSize(offset_of(InstanceKlass, _init_thread));}// subclass/subinterface checks
bool implements_interface(Klass* k)const;
bool is_same_or_direct_interface(Klass* k)const;// Access to the implementor of an interface.
Klass*implementor()const;voidset_implementor(Klass* k);intnof_implementors()const;voidadd_implementor(Klass* k);// k is a new class that implements this interfacevoidinit_implementor();// initialize// link this class into the implementors list of every interface it implementsvoidprocess_interfaces(Thread *thread);// virtual operations from Klass
GrowableArray<Klass*>*compute_secondary_supers(int num_extra_slots,
Array<InstanceKlass*>* transitive_interfaces);
bool can_be_primary_super_slow()const;intoop_size(oop obj)const{returnsize_helper();}// slow because it's a virtual call and used for verifying the layout_helper.// Using the layout_helper bits, we can call is_instance_klass without a virtual call.DEBUG_ONLY(bool is_instance_klass_slow()const{return true;})// Iteratorsvoiddo_local_static_fields(FieldClosure* cl);voiddo_nonstatic_fields(FieldClosure* cl);// including inherited fieldsvoiddo_local_static_fields(voidf(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS);voidmethods_do(voidf(Method* method));voidarray_klasses_do(voidf(Klass* k));voidarray_klasses_do(voidf(Klass* k, TRAPS), TRAPS);static InstanceKlass*cast(Klass* k){return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));}staticconst InstanceKlass*cast(const Klass* k){assert(k !=NULL,"k should not be null");assert(k->is_instance_klass(),"cast to InstanceKlass");return static_cast<const InstanceKlass*>(k);}
virtual InstanceKlass*java_super()const{return(super()==NULL)?NULL:cast(super());}// Sizing (in words)staticintheader_size(){returnsizeof(InstanceKlass)/wordSize;}staticintsize(int vtable_length,int itable_length,int nonstatic_oop_map_size,
bool is_interface, bool is_unsafe_anonymous, bool has_stored_fingerprint){returnalign_metadata_size(header_size()+
vtable_length +
itable_length +
nonstatic_oop_map_size +(is_interface ?(int)sizeof(Klass*)/wordSize :0)+(is_unsafe_anonymous ?(int)sizeof(Klass*)/wordSize :0)+(has_stored_fingerprint ?(int)sizeof(uint64_t*)/wordSize :0));}intsize()const{returnsize(vtable_length(),itable_length(),nonstatic_oop_map_size(),is_interface(),is_unsafe_anonymous(),has_stored_fingerprint());}
intptr_t*start_of_itable()const{return(intptr_t*)start_of_vtable()+vtable_length();}
intptr_t*end_of_itable()const{returnstart_of_itable()+itable_length();}intitable_offset_in_words()const{returnstart_of_itable()-(intptr_t*)this;}
oop static_field_base_raw(){returnjava_mirror();}
OopMapBlock*start_of_nonstatic_oop_maps()const{return(OopMapBlock*)(start_of_itable()+itable_length());}
Klass**end_of_nonstatic_oop_maps()const{return(Klass**)(start_of_nonstatic_oop_maps()+nonstatic_oop_map_count());}
Klass*volatile*adr_implementor()const{if(is_interface()){return(Klass*volatile*)end_of_nonstatic_oop_maps();}else{returnNULL;}};
InstanceKlass**adr_unsafe_anonymous_host()const{if(is_unsafe_anonymous()){
InstanceKlass** adr_impl =(InstanceKlass**)adr_implementor();if(adr_impl !=NULL){return adr_impl +1;}else{return(InstanceKlass **)end_of_nonstatic_oop_maps();}}else{returnNULL;}}
address adr_fingerprint()const{if(has_stored_fingerprint()){
InstanceKlass** adr_host =adr_unsafe_anonymous_host();if(adr_host !=NULL){return(address)(adr_host +1);}
Klass*volatile* adr_impl =adr_implementor();if(adr_impl !=NULL){return(address)(adr_impl +1);}return(address)end_of_nonstatic_oop_maps();}else{returnNULL;}}// Use this to return the size of an instance in heap words:intsize_helper()const{returnlayout_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// - the class is java/lang/Class, which cannot be allocated directly
bool can_be_fastpath_allocated()const{return!layout_helper_needs_slow_path(layout_helper());}// Java itable
klassItable itable()const;// return klassItable wrapper
Method*method_at_itable(Klass* holder,int index, TRAPS);voidclean_weak_instanceklass_links();
private:voidclean_implementors_list();voidclean_method_data();
public:// Explicit metaspace deallocation of fields// For RedefineClasses and class file parsing errors, we need to deallocate// instanceKlasses and the metadata they point to.voiddeallocate_contents(ClassLoaderData* loader_data);staticvoiddeallocate_methods(ClassLoaderData* loader_data,
Array<Method*>* methods);voidstaticdeallocate_interfaces(ClassLoaderData* loader_data,const Klass* super_klass,
Array<InstanceKlass*>* local_interfaces,
Array<InstanceKlass*>* transitive_interfaces);voidstaticdeallocate_record_components(ClassLoaderData* loader_data,
Array<RecordComponent*>* record_component);// callbacks for actions during class unloadingstaticvoidunload_class(InstanceKlass* ik);
virtual voidrelease_C_heap_structures();// Namingconstchar*signature_name()const;// Oop fields (and metadata) iterators//// The InstanceKlass iterators also visits the Object's klass.// Forward iteration
public:// Iterate over all oop fields in the oop maps.
template <typename T, class OopClosureType>inlinevoidoop_oop_iterate_oop_maps(oop obj, OopClosureType* closure);// Iterate over all oop fields and metadata.
template <typename T, class OopClosureType>inlinevoidoop_oop_iterate(oop obj, OopClosureType* closure);// Iterate over all oop fields in one oop map.
template <typename T, class OopClosureType>inlinevoidoop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure);// Reverse iteration// Iterate over all oop fields and metadata.
template <typename T, class OopClosureType>inlinevoidoop_oop_iterate_reverse(oop obj, OopClosureType* closure);
private:// Iterate over all oop fields in the oop maps.
template <typename T, class OopClosureType>inlinevoidoop_oop_iterate_oop_maps_reverse(oop obj, OopClosureType* closure);// Iterate over all oop fields in one oop map.
template <typename T, class OopClosureType>inlinevoidoop_oop_iterate_oop_map_reverse(OopMapBlock* map, oop obj, OopClosureType* closure);// Bounded range iteration
public:// Iterate over all oop fields in the oop maps.
template <typename T, class OopClosureType>inlinevoidoop_oop_iterate_oop_maps_bounded(oop obj, OopClosureType* closure, MemRegion mr);// Iterate over all oop fields and metadata.
template <typename T, class OopClosureType>inlinevoidoop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr);
private:// Iterate over all oop fields in one oop map.
template <typename T, class OopClosureType>inlinevoidoop_oop_iterate_oop_map_bounded(OopMapBlock* map, oop obj, OopClosureType* closure, MemRegion mr);
public:
u2 idnum_allocated_count()const{return _idnum_allocated_count;}
private:// initialization statevoidset_init_state(ClassState state);voidset_init_thread(Thread *thread){ _init_thread = thread;}// 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.
bool idnum_can_increment()const{returnhas_been_redefined();}inline jmethodID*methods_jmethod_ids_acquire()const;inlinevoidrelease_set_methods_jmethod_ids(jmethodID* jmeths);// Lock during initialization
public:// Lock for (1) initialization; (2) access to the ConstantPool of this class.// Must be one per class and it has to be a VM internal object so java code// cannot lock it (like the mirror).// It has to be an object not a Mutex because it's held through java calls.
oop init_lock()const;
private:voidfence_and_clear_init_lock();
bool link_class_impl (TRAPS);
bool verify_code (TRAPS);void initialize_impl (TRAPS);void initialize_super_interfaces (TRAPS);void eager_initialize_impl ();/* jni_id_for_impl for jfieldID only */
JNIid* jni_id_for_impl (int offset);// Returns the array class for the n'th dimension
Klass*array_klass_impl(bool or_null,int n, TRAPS);// Returns the array class with this class as element type
Klass*array_klass_impl(bool or_null, TRAPS);// find a local method (returns NULL if not found)
Method*find_method_impl(const Symbol* name,const Symbol* signature,
OverpassLookupMode overpass_mode,
StaticLookupMode static_mode,
PrivateLookupMode private_mode)const;static Method*find_method_impl(const Array<Method*>* methods,const Symbol* name,const Symbol* signature,
OverpassLookupMode overpass_mode,
StaticLookupMode static_mode,
PrivateLookupMode private_mode);// Free CHeap allocated fields.voidrelease_C_heap_structures_internal();
public:// CDS support - remove and restore oops from metadata. Oops are not shared.
virtual voidremove_unshareable_info();
virtual voidremove_java_mirror();voidrestore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);// jvm support
jint compute_modifier_flags(TRAPS)const;
public:// JVMTI support
jint jvmti_class_status()const;
virtual voidmetaspace_pointers_do(MetaspaceClosure* iter);
public:// Printing#ifndef PRODUCTvoidprint_on(outputStream* st)const;#endifvoidprint_value_on(outputStream* st)const;voidoop_print_value_on(oop obj, outputStream* st);#ifndef PRODUCTvoid oop_print_on (oop obj, outputStream* st);voidprint_dependent_nmethods(bool verbose = false);
bool is_dependent_nmethod(nmethod* nm);
bool verify_itable_index(int index);#endifconstchar*internal_name()const;// Verificationvoidverify_on(outputStream* st);voidoop_verify_on(oop obj, outputStream* st);// Loggingvoidprint_class_load_logging(ClassLoaderData* loader_data,constchar* module_name,const ClassFileStream* cfs)const;};// for adding methods// UNSET_IDNUM return means no more ids availableinline u2 InstanceKlass::next_method_idnum(){if(_idnum_allocated_count == ConstMethod::MAX_IDNUM){return ConstMethod::UNSET_IDNUM;// no more ids available}else{return _idnum_allocated_count++;}}
enum{
_misc_rewritten =1<<0,// methods rewritten.
_misc_has_nonstatic_fields =1<<1,// for sizing with UseCompressedOops
_misc_should_verify_class =1<<2,// allow caching of preverification
_misc_is_unsafe_anonymous =1<<3,// has embedded _unsafe_anonymous_host field
_misc_is_contended =1<<4,// marked with contended annotation
_misc_has_nonstatic_concrete_methods =1<<5,// class/superclass/implemented interfaces has non-static, concrete methods
_misc_declares_nonstatic_concrete_methods =1<<6,// directly declares non-static, concrete methods
_misc_has_been_redefined =1<<7,// class has been redefined
_misc_has_passed_fingerprint_check =1<<8,// when this class was loaded, the fingerprint computed from its// code source was found to be matching the value recorded by AOT.
_misc_is_scratch_class =1<<9,// class is the redefined scratch class
_misc_is_shared_boot_class =1<<10,// defining class loader is boot class loader
_misc_is_shared_platform_class =1<<11,// defining class loader is platform class loader
_misc_is_shared_app_class =1<<12,// defining class loader is app class loader
_misc_has_resolved_methods =1<<13,// resolved methods table entries added for this class
_misc_is_being_redefined =1<<14,// used for locking redefinition
_misc_has_contended_annotations =1<<15// has @Contended annotation};
所以下面众多方法就是通过_misc_flags来读写
mask
读方法
写方法
说明
_misc_rewritten
is_rewritten()
set_rewritten()
_misc_has_nonstatic_fields
has_nonstatic_fields()
set_has_nonstatic_fields(bool b)
_misc_should_verify_class
should_verify_class
set_should_verify_class
_misc_is_unsafe_anonymous
is_unsafe_anonymous()
set_is_unsafe_anonymous(bool value)
_misc_is_contended
is_contended()
set_is_contended(bool value)
_misc_has_nonstatic_concrete_methods
has_nonstatic_concrete_methods()
set_has_nonstatic_concrete_methods(bool b)
_misc_declares_nonstatic_concrete_methods
declares_nonstatic_concrete_methods()
set_declares_nonstatic_concrete_methods(bool b)
_misc_has_been_redefined
has_been_redefined()
set_has_been_redefined()
_misc_has_passed_fingerprint_check
has_passed_fingerprint_check()
set_has_passed_fingerprint_check(bool b)
_misc_is_scratch_class
is_scratch_class()
set_is_scratch_class()
_misc_is_shared_boot_class
is_shared_boot_class()
-
_misc_is_shared_platform_class
is_shared_platform_class()
-
_misc_is_shared_app_clas
is_shared_app_clas()
-
_misc_has_resolved_methods
has_resolved_methods()
set_has_resolved_methods()
_misc_is_being_redefined
is_being_redefined()
set_is_being_redefined(bool value)
JVMTI
_misc_has_contended_annotations
has_contended_annotations()
set_has_contended_annotations(bool value)
_constants
_constants是一个重要属性,很多操作都是委托给_constants的同名方法,包括以下这些
bool on_stack() const The constant pool is on stack if any of the methods are executing or referenced by handles.