OpenJDK源码阅读-Oop&Klass

2023-11-18

oop-klass

当C,C++和Delphi等程序被编译成二进制程序后,原来所定义的高级数据结构都不复存在了,当windows/linux等操作系统(宿主机)加载这些二进制程序时,是不会加载这些语言中所定义的高级数据结构的,宿主机压根就不知道原来定了那些数据结构,哪些类,所有的数据结构都被转换为对特定内存段的偏移地址.例如C中的Struct结构体,被编译后不复存在,汇编和机器语言中没有与之对应的数据结构的概念,CPU更不知道何为结构体.C++和Delphi中的类概念被编译后也不复存在,所谓的类最终变成内存首地址.而JVM虚拟机在加载字节码程序时,会记录字节码中所定义的所有类型的原始信息(元数据),JVM知道程序中包含了哪些类,以及每个类中所关联的字段,方法,父类等信息.这是JVM虚拟机与操作系统最大的区别所在

oop:ordinary object pointer,用来描述对象实例信息,一般保存在HEAP
klass:用来描述java类,是虚拟机内部java类型结构的对等体,一般保存在PERM
根据最新的oopsHierarchy.hpp里的说明,整个继承树分为以下三个

OBJECT hierarchy

继承关系代码如下

// 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.

typedef class oopDesc*                    oop;
typedef class   instanceOopDesc*            instanceOop;
typedef class   arrayOopDesc*               arrayOop;
typedef class     objArrayOopDesc*            objArrayOop;
typedef class     typeArrayOopDesc*           typeArrayOop;
  • oopDesc
    这个类定义在oop.hpp中,方法有很对,属性却很少,如下所示

class oopDesc {
  friend class VMStructs;
  friend class JVMCIVMStructs;
 private:
  volatile markWord _mark;
  union _metadata {
    Klass*      _klass;
    narrowKlass _compressed_klass;
  } _metadata;
......
}

_mark属性主要使用标记对象的各种状态,例如锁,分代,线程状态等等.而_metadata可以看出来指向Klass,至于里面的方法很多.上面的narrowKlass是用于指针压缩,相关定义在oopsHierarchy.hpp如下

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 MetaspaceObj
class   ConstMethod;
class   ConstantPoolCache;
class   MethodData;
//      class Metadata
class   Method;
class   ConstantPool;
//      class CHeapObj
class   CompiledICHolder;

klass hierarchy

// The klass hierarchy is separate from the oop hierarchy.
class Klass;
class   InstanceKlass;
class     InstanceMirrorKlass;
class     InstanceClassLoaderKlass;
class     InstanceRefKlass;
class   ArrayKlass;
class     ObjArrayKlass;
class     TypeArrayKlass;

oop

classDiagram

oopDesc -markWord _mark -union _metadata instanceOopDesc +header_size() : int +base_offset_in_bytes() : int arrayOopDesc typeArrayOopDesc objArrayOopDesc

description

这里面各类的作用如下

class 源码位置 description
typeArrayOopDesc typeArrayOop.hpp 用于基本类型的数组

klass

classDiagram

为了方便起见,下面的方法里省略了各种print*

MetaspaceObj +is_valid(MetaspaceObj* p) : bool +is_shared(Metaspaceobj* p) : bool +is_shared() : bool +set_shared_metaspace_range(void* base,void* top) : void +shared_metaspace_base() +shared_metaspace_top() +type_name(Type type) +array_type(size_t elem_size) : Type +is_read_only_by_default() : bool Annotations Array ConstMethod Metadata +identity_hash() : int +is_metadate() : bool +is_klass() : bool +is_method() : bool +is_methodData() : bool +is_constantPool() : bool +is_methodCounters() : bool +size() : int +type() : Type +internal_name() +metaspace_pointers_do(iter) +on_stack() +set_on_stack(bool value) +mark_on_stack(Metadata* m) : void ConstantPoolCache RecordComponent Symbol MethodCounters ConstantPool Klass +jint _layout_helper #KlassID _id #int _vtable_len +juint _super_check_offset #Symbol* _name +Klass* _secondary_super_cache +Array<Klass*>* _secondary_supers #Klass* _primary_supers[_primary_super_limit] #OopHandle _java_mirror +Klass* _super #Klass* _subklass #Klass* _next_sibling +Klass* _next_link +ClassLoaderDate* _class_loader_data +jint _modifier_flags #AccessFlags _access_flags #jlong _last_biased_lock_bulk_revocation_time #markWord _prototype_header #jint _biased_lock_revocation_count +jshort _shared_class_path_index +id() : int +is_klass() : bool +initialize_supers(Klass* k,Array<InstanceKlass*>* interfaces) +compute_secondary_supers(int Array<InstanceKlass*>* interfaces) +java_super() : InstanceKlass +primary_super_of_depth(jint i) : Klass +can_be_primary_super() : bool +can_be_primary_super_slow() : bool +super_depth() : juint +java_mirror() : oop +java_mirror_no_keepalive() : oop +set_java_mirror(Handle m) +archived_java_mirror_raw() : oop +archived_java_mirror_raw_narrow() : narrowOOp +set_archived_java_mirror_raw(oop m) : void +replace_java_mirror(oop mirror) : viod +clear_java_mirror_handle() : void +subklass(bool log) : Klass +next_sibling(bool log) : Klass +superklass() : InstanceKlass +append_to_sibling_list() : void +module() : ModuleEntry +package() : PackageEntry Method MethodData ArrayKlass InstanceKlass InstanceClassLoaderKlass InstanceMirrorKlass InstanceRefKlass

description

这里面各类的作用如下

class 源码位置 description
MetaspaceObj allocation.hpp 从名字上看出任何存放在Metaspace的数据都是一个MetaspaceObj
Metadata metadata.hpp 用于存放和Class相关的元数据
Klass klass.cpp 对应java中的class
InstanceKlass instanceKlass.hpp jvm用来存放java class信息
InstanceRefKlass instanceRefKlass.hpp 用于处理Reference相关一些非强引用类型

InstanceKlass

// 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:
   void increment_count(int diff) { _count += diff; }
  int offset_span() const { return _count * heapOopSize; }
  int end_offset() const {
    return offset() + offset_span();
  }
  bool is_contiguous(int another_offset) const {
    return another_offset == end_offset();
  }
  // sizeof(OopMapBlock) in words.
  static const int size_in_words() {
    return align_up((int)sizeof(OopMapBlock), wordSize) >>
      LogBytesPerWord;
  }
  static int compare_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:
  static const 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 string
  const char*     _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;//PUBLIC
  int             _static_field_size;    //PUBLIC number words used by static fields (oop and non-oop) in this klass

  int             _nonstatic_oop_map_size;//PUBLIC size in words of nonstatic oop map blocks
  int             _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 fields

  volatile 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 (?)
  static const unsigned _kind_other        = 0; // concrete InstanceKlass
  static const unsigned _kind_reference    = 1; // InstanceRefKlass
  static const unsigned _kind_class_loader = 2; // InstanceClassLoaderKlass
  static const unsigned _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;
  }

  void clear_shared_class_loader_type() {
    _misc_flags &= ~shared_loader_type_bits();
  }

  void set_shared_class_loader_type(s2 loader_type);
  void assign_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 ordering
  void copy_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 { return field(index)->offset(); }
  int     field_access_flags(int index) const { return field(index)->access_flags(); }
  Symbol* field_name        (int index) const { return field(index)->name(constants()); }
  Symbol* field_signature   (int index) const { return field(index)->signature(constants()); }

  // Number of Java declared fields
  int java_fields_count() const           { return (int)_java_fields_count; }

  Array<u2>* fields() const            { return _fields; }
  void set_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 support
  void set_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.
  const char* 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); }
  void set_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.
  void set_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)
  static void check_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 called
  void initialize(TRAPS);
  void link_class(TRAPS);
  bool link_class_or_fail(TRAPS); // returns false on failure
  void rewrite_class(TRAPS);
  void link_methods(TRAPS);
  Method* class_initializer() const;

  // set the class to initialized if no static initializer is present
  void eager_initialize(Thread *thread);

  // reference type
  ReferenceType reference_type() const     { return (ReferenceType)_reference_type; }
  void set_reference_type(ReferenceType t) {
    assert(t == (u1)t, "overflow");
    _reference_type = (u1)t;
  }


  static ByteSize reference_type_offset() { return in_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:
  inline static int quick_search(const Array<Method*>* methods, const Symbol* name);

 public:
  static void disable_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)
  static int find_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.
  int find_method_by_name(const Symbol* name, int* end) const;
  static int find_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");
      return NULL;
    } 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;
    }
  }
  void set_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 extension
  const char* source_debug_extension() const { return _source_debug_extension; }
  void set_source_debug_extension(const char* array, int length);
  // nonstatic oop-map blocks
  static int nonstatic_oop_map_size(unsigned int oop_map_count) {
    return oop_map_count * OopMapBlock::size_in_words();
  }
  unsigned int nonstatic_oop_map_count() const {
    return _nonstatic_oop_map_size / OopMapBlock::size_in_words();
  }
// 对于非JVMTI的情况总是NULL
  InstanceKlass* previous_versions() const { return NULL; }
  InstanceKlass* get_klass_version(int version) {   return NULL;  }
  
  bool supers_have_passed_fingerprint_checks();

  static bool should_store_fingerprint(bool is_hidden_or_anonymous);
  bool should_store_fingerprint() const { return should_store_fingerprint(is_hidden() || is_unsafe_anonymous()); }
  bool has_stored_fingerprint() const;
  uint64_t get_stored_fingerprint() const;
  void store_fingerprint(uint64_t fingerprint);
 
private:
  void set_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        { return is_kind(_kind_other); }
  bool is_reference_instance_klass() const    { return is_kind(_kind_reference); }
  bool is_mirror_instance_klass() const       { return is_kind(_kind_mirror); }
  bool is_class_loader_instance_klass() const { return is_kind(_kind_class_loader); }

  static void purge_previous_versions(InstanceKlass* ik) { return; };
  static bool has_previous_versions_and_reset() { return false; }

  void set_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 available
  inline u2 next_method_idnum();
  void set_initial_method_idnum(u2 value)             { _idnum_allocated_count = value; }

  u2 enclosing_method_data(int offset) const;
  u2 enclosing_method_class_index() const {
    return enclosing_method_data(enclosing_method_class_index_offset);
  }
  u2 enclosing_method_method_index() {
    return enclosing_method_data(enclosing_method_method_index_offset);
  }
  void set_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);
  static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
                size_t *length_p, jmethodID* id_p);
  void ensure_space_for_methodids(int start_offset = 0);
  jmethodID jmethod_id_or_null(Method* method);
    
  instanceOop allocate_instance(TRAPS);// allocation
  static 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 function
  static 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 void check_valid_for_instantiation(bool throwError, TRAPS);
  
  void call_class_initializer(TRAPS);// initialization
  void set_initialization_state_and_notify(ClassState state, TRAPS);

  void mask_for(const methodHandle& method, int bci, InterpreterOopMap* entry);

  JNIid* jni_id_for(int offset);

  // maintenance of deoptimization dependencies
  inline DependencyContext dependencies();
  int  mark_dependent_nmethods(KlassDepChange& changes);
  void add_dependent_nmethod(nmethod* nm);
  void remove_dependent_nmethod(nmethod* nm);
  void clean_dependency_context();

  // On-stack replacement support
  void add_osr_nmethod(nmethod* n);
  bool remove_osr_nmethod(nmethod* n);
  int mark_osr_nmethods(const Method* m);
  nmethod* lookup_osr_nmethod(const Method* m, int bci, int level, bool match_level) const;

  // support for stub routines
  static ByteSize init_state_offset()  { return in_ByteSize(offset_of(InstanceKlass, _init_state)); }
  JFR_ONLY(DEFINE_KLASS_TRACE_ID_OFFSET;)
  static ByteSize init_thread_offset() { return in_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;
  void set_implementor(Klass* k);
  int  nof_implementors() const;
  void add_implementor(Klass* k);  // k is a new class that implements this interface
  void init_implementor();           // initialize
  // link this class into the implementors list of every interface it implements
  void process_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;
  int oop_size(oop obj)  const             { return size_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; })
  // Iterators
  void do_local_static_fields(FieldClosure* cl);
  void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  void do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS);

  void methods_do(void f(Method* method));
  void array_klasses_do(void f(Klass* k));
  void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);

  static InstanceKlass* cast(Klass* k) {
    return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
  }

  static const 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)
  static int header_size()            { return sizeof(InstanceKlass)/wordSize; }
  static int size(int vtable_length, int itable_length,
                  int nonstatic_oop_map_size,
                  bool is_interface, bool is_unsafe_anonymous, bool has_stored_fingerprint) {
    return align_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));
  }
  int size() const{
	   return size(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 { return start_of_itable() + itable_length(); }

  int  itable_offset_in_words() const { return start_of_itable() - (intptr_t*)this; }

  oop static_field_base_raw() { return java_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 {
      return NULL;
    }
  };

  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 {
      return NULL;
    }
  }

  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 {
      return NULL;
    }
  }
  // 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
  //  - 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);
  void clean_weak_instanceklass_links();
 private:
  void clean_implementors_list();
  void clean_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.
  void deallocate_contents(ClassLoaderData* loader_data);
  static void deallocate_methods(ClassLoaderData* loader_data,
                                 Array<Method*>* methods);
  void static deallocate_interfaces(ClassLoaderData* loader_data,
                                    const Klass* super_klass,
                                    Array<InstanceKlass*>* local_interfaces,
                                    Array<InstanceKlass*>* transitive_interfaces);
  void static deallocate_record_components(ClassLoaderData* loader_data,
                                           Array<RecordComponent*>* record_component);
  // callbacks for actions during class unloading
  static void unload_class(InstanceKlass* ik);
  virtual void release_C_heap_structures();
  // Naming
  const char* 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>
  inline void oop_oop_iterate_oop_maps(oop obj, OopClosureType* closure);
  // Iterate over all oop fields and metadata.
  template <typename T, class OopClosureType>
  inline void oop_oop_iterate(oop obj, OopClosureType* closure);
  // Iterate over all oop fields in one oop map.
  template <typename T, class OopClosureType>
  inline void oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure);
  // Reverse iteration
  // Iterate over all oop fields and metadata.
  template <typename T, class OopClosureType>
  inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure);
 private:
  // Iterate over all oop fields in the oop maps.
  template <typename T, class OopClosureType>
  inline void oop_oop_iterate_oop_maps_reverse(oop obj, OopClosureType* closure);
  // Iterate over all oop fields in one oop map.
  template <typename T, class OopClosureType>
  inline void oop_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>
  inline void oop_oop_iterate_oop_maps_bounded(oop obj, OopClosureType* closure, MemRegion mr);
  // Iterate over all oop fields and metadata.
  template <typename T, class OopClosureType>
  inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr);
 private:
  // Iterate over all oop fields in one oop map.
  template <typename T, class OopClosureType>
  inline void oop_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 state
  void set_init_state(ClassState state);
  void set_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      { return has_been_redefined(); }
  inline jmethodID* methods_jmethod_ids_acquire() const;
  inline void release_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:
  void fence_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.
  void release_C_heap_structures_internal();
public:
  // CDS support - remove and restore oops from metadata. Oops are not shared.
  virtual void remove_unshareable_info();
  virtual void remove_java_mirror();
  void restore_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 void metaspace_pointers_do(MetaspaceClosure* iter);
 public:
  // Printing
#ifndef PRODUCT
  void print_on(outputStream* st) const;
#endif
  void print_value_on(outputStream* st) const;

  void oop_print_value_on(oop obj, outputStream* st);

#ifndef PRODUCT
  void oop_print_on      (oop obj, outputStream* st);

  void print_dependent_nmethods(bool verbose = false);
  bool is_dependent_nmethod(nmethod* nm);
  bool verify_itable_index(int index);
#endif
  const char* internal_name() const;
  // Verification
  void verify_on(outputStream* st);

  void oop_verify_on(oop obj, outputStream* st);
  // Logging
  void print_class_load_logging(ClassLoaderData* loader_data,
                                const char* module_name,
                                const ClassFileStream* cfs) const;
};
// for adding methods
// UNSET_IDNUM return means no more ids available
inline 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++;
  }
}

_misc_flags

InstanceKlass里有个位图字段,一个顶十六个,那就是 _misc_flags,它的16位的含义可以参见下面的枚举

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.
  • void set_generic_signature_index(u2 sig_index)
  • u2 generic_signature_index() const
  • Symbol* generic_signature() const
  • void set_major_version(u2 major_version)
  • u2 major_version() const
  • void set_minor_version(u2 minor_version)
  • u2 minor_version() const
  • Symbol* source_file_name() const
  • u2 source_file_name_index() const
  • void set_source_file_name_index(u2 sourcefile_index)

_annotations

类似的,有些方法委托给了_annotations同名方法,需要注意的是由于_annotations可能为NULL,所以需要先检查了再调用

  • AnnotationArray* class_annotations() const
  • Array<AnnotationArray*>* fields_annotations() const
  • AnnotationArray* class_type_annotations() const
  • Array<AnnotationArray*>* fields_type_annotations() const
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

OpenJDK源码阅读-Oop&Klass 的相关文章

  • 如何使用 SLF4J 和 Log4j2 记录 FATAL(或任何自定义日志级别)

    我有那些具体的要求 需要能够登录FATAL level 需要使用SLF4J 需要使用Log4j2 现在 这是我的执行 final Logger logger LoggerFactory getLogger HelloWorld class
  • Java Swing:清除JList而不触发监听器

    我的情况如下 我有一个 JList 只要在列表中进行选择 它就会触发搜索 使用 ListSelectionListener 我正在尝试使用以下命令重置列表上的选择list clearSelection 这样做的问题是使用clearSelec
  • 以编程方式将 PEM 证书导入 Java KeyStore

    我有一个由两个文件 crt 和 key 组成的客户端证书 我希望将其导入到 java KeyStore 中 然后在 SSLContext 中使用 以通过 Apache 的 HTTPClient 发送 HTTP 请求 但是 我似乎找不到一种以
  • JUnit Eclipse 显示 System.out.print() 的

    我正在使用 JUnit 3 和 Eclipse 3 4 当我运行 JUnit 测试用例时 一切正常并且测试完美完成 唯一的事情是我想查看我正在运行的类的输出 所有类都具有一些输出值的基本 System out print 因此 当我运行测试
  • java“void”和“非void”构造函数

    我用 java 编写了这个简单的类 只是为了测试它的一些功能 public class class1 public static Integer value 0 public class1 da public int da class1 v
  • 如何正确配置Tomcat SSLHostConfig?

    我正在按照本教程在 tomcat 中启用 ssl https medium com raupach how to install lets encrypt with tomcat 3db8a469e3d2 https medium com
  • 如何模拟一个方面

    我目前正在使用aspectj 开发一些监控工具 因为这个工具应该是技术独立的 尽可能 所以我没有使用 Spring 进行注入 但我希望我的方面能够经过单元测试 方面示例 Aspect public class ClassLoadAspect
  • 独占锁定ConcurrentHashMap

    我知道不可能锁定 ConcurrentHashMap 进行独占访问 但是 我找不到原因 是因为构成CHM的 Segment 没有被api公开吗 据推测 如果是的话 客户端代码可以执行 交接 锁定 Cheers 我知道不可能锁定 Concur
  • 会话 bean 中的 EntityManager 异常处理

    我有一个托管无状态会话 bean 其中注入了 EntityManager em 我想做的是拥有一个具有唯一列的数据库表 然后我运行一些尝试插入实体的算法 但是 如果实体存在 它将更新它或跳过它 我想要这样的东西 try em persist
  • JSP 标签+ scriptlet。如何启用脚本?

    我有一个使用标签模板的页面 我的 web xml 非常基本 我只是想在页面中运行一些代码 不 我对标签或其他替代品不感兴趣 我想使用不好的做法 scriptlet 哈哈 到目前为止 我收到了 HTTP ERROR 500 错误 Script
  • 如何在将数据发送到 Firebase 数据库之前对其进行加密?

    我正在使用 Firebase 实时数据库制作聊天应用程序 我知道 Firebase 非常安全 只要您的规则正确 但我自己可以阅读使用我的应用程序的人的所有聊天记录 我想阻止这种情况 为此我需要一种解密和加密方法 我尝试使用凯撒解密 但失败了
  • .class 与 .java

    class 文件和 java 文件有什么区别 我正在尝试让我的小程序工作 但目前我只能在 Eclipse 中运行它 还不能嵌入 HTML 谢谢 编辑 那么如何使用 JVM 进行编译呢 class 文件是编译后的 java 文件 java 都
  • 使用外部硬盘写入和存储 mysql 数据库

    我已经设置了 mysql 数据库在我的 Mac 上使用 java 和 eclipse 运行 它运行得很好 但现在我将生成大约 43 亿行数据 这将占用大约 64GB 的数据 我存储了大量的密钥和加密值 我有一个 1TB 外部我想用作存储位置
  • @TestPropertySource 不适用于 Spring 1.2.6 中使用 AnnotationConfigContextLoader 的 JUnit 测试

    似乎我在 Spring 4 1 17 中使用 Spring Boot 1 2 6 RELEASE 所做的任何事情都不起作用 我只想访问应用程序属性并在必要时通过测试覆盖它们 无需使用 hack 手动注入 PropertySource 这不行
  • RMI 服务器:rmiregistry 或 LocateRegistry.createRegistry

    对于服务器端的RMI 我们需要启动吗rmiregistry程序 或者只是调用LocateRegistry createRegistry 如果两者都可以的话 各有什么优点和缺点 他们是同一件事 rmiregistry是一个单独的程序 您可以从
  • Android 中的字符串加密

    我正在使用代码进行加密和加密 它没有给出字符串结果 字节数组未转换为字符串 我几乎尝试了所有方法将字节数组转换为字符 但没有给出结果 public class EncryptionTest extends Activity EditText
  • Java SE + Spring Data + Hibernate

    我正在尝试使用 Spring Data Hibernate 启动 Java SE 应用程序 并且到目前为止已经完成了以下操作 配置文件 Configuration PropertySource classpath hibernate pro
  • Java的hashCode可以为不同的字符串产生相同的值吗?

    使用java的哈希码函数是否可以为不同的字符串提供相同的哈希码 或者如果可能的话 其可能性的 是多少 Java 哈希码是 32 位 它散列的可能字符串的数量是无限的 所以是的 会发生冲突 百分比是没有意义的 项目 字符串 的数量是无限的 而
  • 使用 Android 的 Mobile Vision API 扫描二维码

    我跟着这个tutorial http code tutsplus com tutorials reading qr codes using the mobile vision api cms 24680关于如何构建可以扫描二维码的 Andr
  • Java 9 中紧凑字符串和压缩字符串的区别

    有什么优点紧凑的字符串 http openjdk java net jeps 254JDK9 中的压缩字符串 压缩字符串 Java 6 和紧凑字符串 Java 9 都有相同的动机 字符串通常实际上是 Latin 1 因此浪费了一半的空间 和

随机推荐

  • AppStore 提审时的“出口合规证明”处理

    对于加密的管理 Apple不比之前严格了 一般选 否 也能通故审核 每次提交审核的时候都会让确认是否使用了Apple以的加密算法 在窗口提示了我们可以看到 可以在Xcdoe的info plist文件中增加App Uses Non Exemp
  • 众多Android 开源项目推荐,给力工作给力学习

    FBReaderJ FBReaderJ用于Android平台的电子书阅读器 它支持多种电子书籍格式包括 oeb ePub和fb2 此外还支持直接读取zip tar和gzip等压缩文档 项目地址 http www fbreader org F
  • jFinal框架下controller接参

    一 表单参数 1 前端 contentType x www form urlencoded 2 apipost接口测试 3 controller接参 1 注解 getPara获取参数 2 注解 默认参数 若方法的参数名为注解名 则jFina
  • Python 基础知识

    进阶选手 Python 进阶知识 Aimin20210819的博客 关注VXG AIMIN2020 更多 目录 1 Python 是怎么理解 2 Python数据类型 四种数据类型
  • 在Firefox浏览器中导入Burp Suite证书

    在日常的渗透中 经常就是在浏览器用bp来抓包 在配置完浏览器的代理的时候就会涉及CA证书问题 在设置完代理后 再访问百度时 就会出现如下图的问题 第一步 导出证书 打开burp suite 找到 代理 Proxy 在选择 选项 Option
  • 指针加法:c = (int *) ((char *) c + 1)与 c=c+1 的区别

    示例代码 include
  • Qt通过QSttings类读取*.ini配置文件

    目录 ini文件 什么是ini文件 格式 需要的参数 需要了解的API 单例 单线程实例 多线程实例 设计一个读取ini文件的类 AppSettings类 ini文件 什么是ini文件 INI Initialization File 是微软
  • DTO和POJO实体类之间值映射

    package cn test util import java lang reflect Method import java util List public class AutoMapper public static
  • Git:Git中的远程操作和标签管理--分布式版本控制系统

    文章目录 理解分布式版本控制系统 克隆仓库 远程推送 拉取远程仓库 配置Git 标签管理 本篇主要总结关于Git中远程操作的相关事项 理解分布式版本控制系统 在进行远程操作前 首先要理解什么是分布式版本控制系统 理解这个问题时要思考这样的问
  • 从均值方差到有效前沿

    这篇文章的主要目的是介绍有效前沿这个理论工具和分析框架 我们由均值方差分析展开 逐步推演到有效前沿 然后 我们又说到有效前沿在投资或者量化中的应用场景 最后我们也总结了有效前沿的一些问题 尤其是敏感性问题 在教程中 特意加入了一些实验代码
  • 学习日记——物联网云平台组件(云消息的后续处理)

    百度云物联网组件图 设备通过MQTT等协议将数据上报到百度云平台 百度云通过主题来将设备分发给其他设备 并且可以通过规则引擎来将数据发送给时序数据库对象存储等等其他云服务 来实现我们想要的各种功能 规则引擎 一 规则引擎简介 使用规则引擎功
  • [qiankun]实战问题汇总

    qiankun 实战问题汇总 ERROR SyntaxError Cannot use import statement outside a module 问题分析 解决方案 子应用命名问题 问题分析 解决方案 jsonpFunction
  • 你的Siri收集了你的个人数据?联邦学习介绍

    MIT Technology Review Apple Siri 这是 MIT Technology Review 12月11日的 Newsletter 的部分摘录 大概意思是 iPhone 上的 Siri 在听到我们个人说 Hey Sir
  • 集群分布式quartz的需要的表

    集群分布式quartz的需要的表 集群分布式quartz一共需要的11张表 select from QRTZ FIRED TRIGGERS select from QRTZ PAUSED TRIGGER GRPS select from Q
  • NDK错(二)

    提示 No version of NDK matched the requested version 21 0 6113669 Versions available locally 22 1 7171670 23 0 7421159 方案一
  • 用执行计划看SQL的索引命中情况

    SQL Server查询超时 用执行计划看SQL的索引命中情况 从SQL Server查询语句 查询超时 需要优化 以下只优化方案之一 仅供参考 选中某段SQL后按CTRL L 查看执行计划 找出哪些表用了全局查询 选中某表按ALT F1
  • 数据结构(2)时间复杂度——渐进时间复杂度、渐进上界、渐进下界

    目录 2 1 概述 2 2 时间复杂度的计算 2 2 1 渐进复杂度 2 2 2 渐进上界 2 2 3 渐进下届 2 2 4 复杂度排序 2 2 5 举几个例子 2 1 概述 算法的基本定义 求解问题的一系列计算或者操作 衡量算法性能的指标
  • cuda求矩阵每一行最大值

    2 完成一个尺寸512 512的二维数组的每一行最大值的并行程序实现数据类型设置为float 需要完成4个版本 1 不使用共享内存 只使用全局内存 采用具有分支发散的并行归约 include cuda runtime h include d
  • Spring Cloud OAuth2 搭建授权服务器 + 客户端 + 令牌中继

    SpringBoot 版本2 1 4 RELEASE Spring Cloud版本Greenwich RELEASE 说明 token采用redis存储 用户信息采用数据库存储 oauth2官网整合springboot的例子 含服务端配置和
  • OpenJDK源码阅读-Oop&Klass

    文章目录 oop klass OBJECT hierarchy metadata hierarchy klass hierarchy oop classDiagram description klass classDiagram descr