常用的JVM数据结构

1、JVM创建的数据结构(hotspot/src/share/tools/launcher/java.h)
typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args);
typedef jint (JNICALL *GetDefaultJavaVMInitArgs_t)(void *args);

typedef struct {
    CreateJavaVM_t CreateJavaVM;
    GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs;
} InvocationFunctions;

jvm在启动的时候,会dlopen libjvm.so,从而定位符号JNI_CreateJavaVM和JNI_GetDefaultJavaVMInitArgs进行初始化


2、jvm的初始化属性

typedef struct JavaVMOption {
    char *optionString;
    void *extraInfo;
} JavaVMOption;


typedef struct JavaVMInitArgs {
    jint version;


    jint nOptions;
    JavaVMOption *options;
    jboolean ignoreUnrecognized;
} JavaVMInitArgs;


3、zip文件,用于加载jar包中的资源文件

typedef void* jzfile; //zip文件句柄
typedef struct {
  char *name;                   /* entry name */
  jlong time;                   /* modification time */
  jlong size;                   /* size of uncompressed data */
  jlong csize;                  /* size of compressed data (zero if uncompressed) */
  jint crc;                     /* crc of uncompressed data */
  char *comment;                /* optional zip file comment */
  jbyte *extra;                 /* optional extra data */
  jlong pos;                    /* position of LOC header (if negative) or data */
} jzentry;

下面是zip的操作方法

typedef void * * (JNICALL *ZipOpen_t)(const char *name, char **pmsg);
typedef void (JNICALL *ZipClose_t)(jzfile *zip);
typedef jzentry* (JNICALL *FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen);
typedef jboolean (JNICALL *ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf);
typedef jboolean (JNICALL *ReadMappedEntry_t)(jzfile *zip, jzentry *entry, unsigned char **buf, char *namebuf);
typedef jzentry* (JNICALL *GetNextEntry_t)(jzfile *zip, jint n);

初始化方法是动态加载libzip.so的ZIP_Open、Zip_Close、Zip_FindEntry等等方法


4、句柄

class Handle VALUE_OBJ_CLASS_SPEC {
 private:
  oop* _handle;

 protected:
  oop     obj() const                            { return _handle == NULL ? (oop)NULL : *_handle; }
  oop     non_null_obj() const                   { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }

 public:
  // Constructors
  Handle()                                       { _handle = NULL; }
  Handle(oop obj);
#ifndef ASSERT
  Handle(Thread* thread, oop obj);
#else
  // Don't inline body with assert for current thread
  Handle(Thread* thread, oop obj);
#endif // ASSERT

  // General access
  oop     operator () () const                   { return obj(); }
  oop     operator -> () const                   { return non_null_obj(); }
  bool    operator == (oop o) const              { return obj() == o; }
  bool    operator == (const Handle& h) const          { return obj() == h.obj(); }

  // Null checks
  bool    is_null() const                        { return _handle == NULL; }
  bool    not_null() const                       { return _handle != NULL; }

  // Debugging
  void    print()                                { obj()->print(); }

  // Direct interface, use very sparingly.
  // Used by JavaCalls to quickly convert handles and to create handles static data structures.
  // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
  Handle(oop *handle, bool dummy)                { _handle = handle; }

  // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
  // since duplicates is only valid as long as original handle is alive.
  oop* raw_value()                               { return _handle; }
  static oop raw_resolve(oop *handle)            { return handle == NULL ? (oop)NULL : *handle; }
};


//------------------------------------------------------------------------------------------------------------------------
// Base class for Handles containing klassOops. Provides overloading of frequently
// used operators for ease of use and typed access to the Klass part.
class KlassHandle: public Handle {
 protected:
  klassOop    obj() const                        { return (klassOop)Handle::obj(); }
  klassOop    non_null_obj() const               { return (klassOop)Handle::non_null_obj(); }
  Klass*      as_klass() const                   { return non_null_obj()->klass_part(); }

 public:
  // Constructors
  KlassHandle ()                                 : Handle()            {}
  KlassHandle (oop obj) : Handle(obj) {
    assert(SharedSkipVerify || is_null() || obj->is_klass(), "not a klassOop");
  }
  KlassHandle (Klass* kl) : Handle(kl ? kl->as_klassOop() : (klassOop)NULL) {
    assert(SharedSkipVerify || is_null() || obj()->is_klass(), "not a klassOop");
  }

  // Faster versions passing Thread
  KlassHandle (Thread* thread, oop obj) : Handle(thread, obj) {
    assert(SharedSkipVerify || is_null() || obj->is_klass(), "not a klassOop");
  }
  KlassHandle (Thread *thread, Klass* kl)
    : Handle(thread, kl ? kl->as_klassOop() : (klassOop)NULL) {
    assert(is_null() || obj()->is_klass(), "not a klassOop");
  }

  // Direct interface, use very sparingly.
  // Used by SystemDictionaryHandles to create handles on existing WKKs.
  // The obj of such a klass handle may be null, because the handle is formed
  // during system bootstrapping.
  KlassHandle(klassOop *handle, bool dummy) : Handle((oop*)handle, dummy) {
    assert(SharedSkipVerify || is_null() || obj() == NULL || obj()->is_klass(), "not a klassOop");
  }

  // General access
  klassOop    operator () () const               { return obj(); }
  Klass*      operator -> () const               { return as_klass(); }
};

用来对OOP进行包装,在JVM内部直接使用的都是Handle


5、重要的变量

hotspot/src/share/vm/utilities/globalDefinitions.hpp

// Info for oops within a java object.  Defaults are zero so
// things will break badly if incorrectly initialized.
int heapOopSize        = 0; 
int LogBytesPerHeapOop = 0;
int LogBitsPerHeapOop  = 0;
int BytesPerHeapOop    = 0;
int BitsPerHeapOop     = 0;

// Object alignment, in units of HeapWords.
// Defaults are -1 so things will break badly if incorrectly initialized.
int MinObjAlignment            = -1;
int MinObjAlignmentInBytes     = -1;
int MinObjAlignmentInBytesMask = 0;

int LogMinObjAlignment         = -1;
int LogMinObjAlignmentInBytes  = -1;


6、常用的参数

#define THREAD __the_thread__
#define TRAPS  Thread* THREAD

用于便于抛出异常,一般TRAPS作为函数的最后一个参数存在


7、GC分代类型

enum Name {
    ASParNew,
    ASConcurrentMarkSweep,
    DefNew,
    ParNew,
    MarkSweepCompact,
    ConcurrentMarkSweep,
    Other
  };

8、全局性的参数变量定义

详见:hotspot/src/share/vm/runtime/globals.hpp

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值