Skip to content

Instantly share code, notes, and snippets.

@mildsunrise
Last active March 30, 2024 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildsunrise/f29ae1349c3dfd0afafa1bdafa204477 to your computer and use it in GitHub Desktop.
Save mildsunrise/f29ae1349c3dfd0afafa1bdafa204477 to your computer and use it in GitHub Desktop.
JNI ABI magic numbers

JNIEnv

(keep in mind that JNI methods get a JNIEnv *, not a direct JNIEnv)

given JNIEnv x, you can write ((void**)x)[N] to access a function pointer, where N is:

     4	GetVersion
     5	DefineClass
     6	FindClass
     7	FromReflectedMethod
     8	FromReflectedField
     9	ToReflectedMethod
    10	GetSuperclass
    11	IsAssignableFrom
    12	ToReflectedField
    13	Throw
    14	ThrowNew
    15	ExceptionOccurred
    16	ExceptionDescribe
    17	ExceptionClear
    18	FatalError
    19	PushLocalFrame
    20	PopLocalFrame
    21	NewGlobalRef
    22	DeleteGlobalRef
    23	DeleteLocalRef
    24	IsSameObject
    25	NewLocalRef
    26	EnsureLocalCapacity
    27	AllocObject
    28	NewObject
    29	NewObjectV
    30	NewObjectA
    31	GetObjectClass
    32	IsInstanceOf
    33	GetMethodID
    34	CallObjectMethod
    35	CallObjectMethodV
    36	CallObjectMethodA
    37	CallBooleanMethod
    38	CallBooleanMethodV
    39	CallBooleanMethodA
    40	CallByteMethod
    41	CallByteMethodV
    42	CallByteMethodA
    43	CallCharMethod
    44	CallCharMethodV
    45	CallCharMethodA
    46	CallShortMethod
    47	CallShortMethodV
    48	CallShortMethodA
    49	CallIntMethod
    50	CallIntMethodV
    51	CallIntMethodA
    52	CallLongMethod
    53	CallLongMethodV
    54	CallLongMethodA
    55	CallFloatMethod
    56	CallFloatMethodV
    57	CallFloatMethodA
    58	CallDoubleMethod
    59	CallDoubleMethodV
    60	CallDoubleMethodA
    61	CallVoidMethod
    62	CallVoidMethodV
    63	CallVoidMethodA
    64	CallNonvirtualObjectMethod
    65	CallNonvirtualObjectMethodV
    66	CallNonvirtualObjectMethodA
    67	CallNonvirtualBooleanMethod
    68	CallNonvirtualBooleanMethodV
    69	CallNonvirtualBooleanMethodA
    70	CallNonvirtualByteMethod
    71	CallNonvirtualByteMethodV
    72	CallNonvirtualByteMethodA
    73	CallNonvirtualCharMethod
    74	CallNonvirtualCharMethodV
    75	CallNonvirtualCharMethodA
    76	CallNonvirtualShortMethod
    77	CallNonvirtualShortMethodV
    78	CallNonvirtualShortMethodA
    79	CallNonvirtualIntMethod
    80	CallNonvirtualIntMethodV
    81	CallNonvirtualIntMethodA
    82	CallNonvirtualLongMethod
    83	CallNonvirtualLongMethodV
    84	CallNonvirtualLongMethodA
    85	CallNonvirtualFloatMethod
    86	CallNonvirtualFloatMethodV
    87	CallNonvirtualFloatMethodA
    88	CallNonvirtualDoubleMethod
    89	CallNonvirtualDoubleMethodV
    90	CallNonvirtualDoubleMethodA
    91	CallNonvirtualVoidMethod
    92	CallNonvirtualVoidMethodV
    93	CallNonvirtualVoidMethodA
    94	GetFieldID
    95	GetObjectField
    96	GetBooleanField
    97	GetByteField
    98	GetCharField
    99	GetShortField
   100	GetIntField
   101	GetLongField
   102	GetFloatField
   103	GetDoubleField
   104	SetObjectField
   105	SetBooleanField
   106	SetByteField
   107	SetCharField
   108	SetShortField
   109	SetIntField
   110	SetLongField
   111	SetFloatField
   112	SetDoubleField
   113	GetStaticMethodID
   114	CallStaticObjectMethod
   115	CallStaticObjectMethodV
   116	CallStaticObjectMethodA
   117	CallStaticBooleanMethod
   118	CallStaticBooleanMethodV
   119	CallStaticBooleanMethodA
   120	CallStaticByteMethod
   121	CallStaticByteMethodV
   122	CallStaticByteMethodA
   123	CallStaticCharMethod
   124	CallStaticCharMethodV
   125	CallStaticCharMethodA
   126	CallStaticShortMethod
   127	CallStaticShortMethodV
   128	CallStaticShortMethodA
   129	CallStaticIntMethod
   130	CallStaticIntMethodV
   131	CallStaticIntMethodA
   132	CallStaticLongMethod
   133	CallStaticLongMethodV
   134	CallStaticLongMethodA
   135	CallStaticFloatMethod
   136	CallStaticFloatMethodV
   137	CallStaticFloatMethodA
   138	CallStaticDoubleMethod
   139	CallStaticDoubleMethodV
   140	CallStaticDoubleMethodA
   141	CallStaticVoidMethod
   142	CallStaticVoidMethodV
   143	CallStaticVoidMethodA
   144	GetStaticFieldID
   145	GetStaticObjectField
   146	GetStaticBooleanField
   147	GetStaticByteField
   148	GetStaticCharField
   149	GetStaticShortField
   150	GetStaticIntField
   151	GetStaticLongField
   152	GetStaticFloatField
   153	GetStaticDoubleField
   154	SetStaticObjectField
   155	SetStaticBooleanField
   156	SetStaticByteField
   157	SetStaticCharField
   158	SetStaticShortField
   159	SetStaticIntField
   160	SetStaticLongField
   161	SetStaticFloatField
   162	SetStaticDoubleField
   163	NewString
   164	GetStringLength
   165	GetStringChars
   166	ReleaseStringChars
   167	NewStringUTF
   168	GetStringUTFLength
   169	GetStringUTFChars
   170	ReleaseStringUTFChars
   171	GetArrayLength
   172	NewObjectArray
   173	GetObjectArrayElement
   174	SetObjectArrayElement
   175	NewBooleanArray
   176	NewByteArray
   177	NewCharArray
   178	NewShortArray
   179	NewIntArray
   180	NewLongArray
   181	NewFloatArray
   182	NewDoubleArray
   183	GetBooleanArrayElements
   184	GetByteArrayElements
   185	GetCharArrayElements
   186	GetShortArrayElements
   187	GetIntArrayElements
   188	GetLongArrayElements
   189	GetFloatArrayElements
   190	GetDoubleArrayElements
   191	ReleaseBooleanArrayElements
   192	ReleaseByteArrayElements
   193	ReleaseCharArrayElements
   194	ReleaseShortArrayElements
   195	ReleaseIntArrayElements
   196	ReleaseLongArrayElements
   197	ReleaseFloatArrayElements
   198	ReleaseDoubleArrayElements
   199	GetBooleanArrayRegion
   200	GetByteArrayRegion
   201	GetCharArrayRegion
   202	GetShortArrayRegion
   203	GetIntArrayRegion
   204	GetLongArrayRegion
   205	GetFloatArrayRegion
   206	GetDoubleArrayRegion
   207	SetBooleanArrayRegion
   208	SetByteArrayRegion
   209	SetCharArrayRegion
   210	SetShortArrayRegion
   211	SetIntArrayRegion
   212	SetLongArrayRegion
   213	SetFloatArrayRegion
   214	SetDoubleArrayRegion
   215	RegisterNatives
   216	UnregisterNatives
   217	MonitorEnter
   218	MonitorExit
   219	GetJavaVM
   220	GetStringRegion
   221	GetStringUTFRegion
   222	GetPrimitiveArrayCritical
   223	ReleasePrimitiveArrayCritical
   224	GetStringCritical
   225	ReleaseStringCritical
   226	NewWeakGlobalRef
   227	DeleteWeakGlobalRef
   228	ExceptionCheck
   229	NewDirectByteBuffer
   230	GetDirectBufferAddress
   231	GetDirectBufferCapacity
   232	GetObjectRefType
   233	GetModule
   234	IsVirtualThread

this should be implementation- and arch-independent. source:

https://github.com/openjdk/jdk/blob/f2e5808b46a3da6920dd56688c877ee0e2795de6/src/java.base/share/native/include/jni.h#L214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment