openjdk javac_openjdk platform binary

(144) 2024-05-27 20:01:03

JNI有两种基本数据类型基本数据类型和引用数据类型

基本数据类型

openjdk javac_openjdk platform binary (https://mushiming.com/)  第1张

在jnt.h中可以找到

//如果没在jni_md.中定义好的话
#ifndef JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H
//就使用下面的定义
typedef unsigned char   jboolean;
typedef unsigned short  jchar;
typedef short           jshort;
typedef float           jfloat;
typedef double          jdouble;

typedef jint            jsize;

找到jnt_md.h中的数据定义

openjdk javac_openjdk platform binary (https://mushiming.com/)  第2张

 在jnt_md.h中找到如上定义,根据环境选择数据类型,根据X86架构找到jni_x86.h文件

#ifndef _JAVASOFT_JNI_MD_H_
#define _JAVASOFT_JNI_MD_H_

#if defined(SOLARIS) || defined(LINUX) || defined(_ALLBSD_SOURCE)


// Note: please do not change these without also changing jni_md.h in the JDK
// repository
#ifndef __has_attribute
  #define __has_attribute(x) 0
#endif
#if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility)
  #define JNIEXPORT     __attribute__((visibility("default")))
  #define JNIIMPORT     __attribute__((visibility("default")))
#else
  #define JNIEXPORT
  #define JNIIMPORT
#endif

  #define JNICALL
  typedef int jint;   
#if defined(_LP64)
  typedef long jlong;
#else
  typedef long long jlong;
#endif

#else
  #define JNIEXPORT __declspec(dllexport)
  #define JNIIMPORT __declspec(dllimport)
  #define JNICALL __stdcall

  typedef int jint;
  typedef __int64 jlong;
#endif

typedef signed char jbyte;

#endif /* !_JAVASOFT_JNI_MD_H_ */

引用数据类型

openjdk javac_openjdk platform binary (https://mushiming.com/)  第3张

方法签名时用到的公共体类型

typedef union jvalue {
    jboolean z;
    jbyte    b;
    jchar    c;
    jshort   s;
    jint     i;
    jlong    j;
    jfloat   f;
    jdouble  d;
    jobject  l;
} jvalue;

属性ID和方法ID的定义

struct _jfieldID;
typedef struct _jfieldID *jfieldID;

struct _jmethodID;
typedef struct _jmethodID *jmethodID;

四种不同引用类型的定义

/* Return values from jobjectRefType */
typedef enum _jobjectType {
     JNIInvalidRefType    = 0,
     JNILocalRefType      = 1,
     JNIGlobalRefType     = 2,
     JNIWeakGlobalRefType = 3
} jobjectRefType;

分别为JNIInvalidRefType(无效引用)、JNILocalRefType(本地引用)、JNIWeakGlobalRefType(弱全局引用)和JNIGlobalRefType(全局引用)的枚举类型

JNI错误类型的定义

/*
 * jboolean constants
 */

#define JNI_FALSE 0
#define JNI_TRUE 1

/*
 * possible return values for JNI functions.
 */

#define JNI_OK           0                 /* success */
#define JNI_ERR          (-1)              /* unknown error */
#define JNI_EDETACHED    (-2)              /* thread detached from the VM */
#define JNI_EVERSION     (-3)              /* JNI version error */
#define JNI_ENOMEM       (-4)              /* not enough memory */
#define JNI_EEXIST       (-5)              /* VM already created */
#define JNI_EINVAL       (-6)              /* invalid arguments */

/*
 * used in ReleaseScalarArrayElements
 */

#define JNI_COMMIT 1
#define JNI_ABORT 2

THE END

发表回复