상용 JVM 데이터 구조

6989 단어
1. JVM 이 만 든 데이터 구조 (hotspot/src/share/tools/lancher/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 를 찾 습 니 다.Create JavaVM 과 JNIGetDefaultJavaVMInitArgs 초기 화
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 등등 방법
문형
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

좋은 웹페이지 즐겨찾기