Skip to content

Commit 119684d

Browse files
committed
[GR-23085] JNA crashes Espresso when running NetBeans and Intellij IDEA.
PullRequest: graal/9753
2 parents 5df1a4e + 149095d commit 119684d

File tree

8 files changed

+207
-181
lines changed

8 files changed

+207
-181
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Requires = language:nfi
22

3-
Args = -H:MaxRuntimeCompileMethods=5000 \
3+
Args = -H:MaxRuntimeCompileMethods=7000 \
44
-H:ReflectionConfigurationFiles=${.}/reflectconfig.json \
55
-H:+TruffleCheckBlockListMethods \
66
--features=com.oracle.truffle.espresso.FinalizationFeature

espresso/mx.espresso/suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
"use_jdk_headers": True,
174174
"buildDependencies": [
175175
"truffle:TRUFFLE_NFI_NATIVE",
176+
"com.oracle.truffle.espresso.mokapot",
176177
],
177178
"os_arch": {
178179
"windows": {

espresso/src/com.oracle.truffle.espresso.mokapot/include/mokapot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ typedef uint64_t julong;
7171
* ----------+----------------+---------------------+----------------+
7272
* reserved0 | NULL | LibEspressoIsolate* | context handle |
7373
* reserved1 | MOKA_RISTRETTO | MOKA_LATTE | MOKA_AMERICANO |
74-
* reserved2 | NULL | JavaVM* (americano) | NULL |
74+
* reserved2 | NULL | JavaVM* (americano) | JavaVM* (latte)|
7575
*/
7676

7777
#define VM_METHOD_LIST(V) \

espresso/src/com.oracle.truffle.espresso.mokapot/src/mokapot.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ JNIEXPORT MokapotEnv* JNICALL initializeMokapotContext(JNIEnv* env, void* (*fetc
7171
java_vm_functions->reserved1 = MOKA_RISTRETTO;
7272
java_vm_functions->reserved2 = NULL;
7373

74+
// Store the MokapotEnv* in the JNIEnv*.
75+
struct JNINativeInterface_* tmp = (struct JNINativeInterface_*) *env;
76+
tmp->reserved1 = (void*) moka_env;
77+
7478
#define INIT__(name) \
7579
functions->name = fetch_by_name(#name, (void*)&name);
7680
VM_METHOD_LIST(INIT__)
@@ -1891,6 +1895,8 @@ _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm_ptr, void **pen
18911895
vmInterface->AttachCurrentThreadAsDaemon = AttachCurrentThreadAsDaemon;
18921896

18931897
*vm = vmInterface;
1898+
// MOKA_LATTE and MOKA_AMERICANO JavaVM structs point to each other via reserved2.
1899+
((struct JNIInvokeInterface_ *) espressoJavaVM->functions)->reserved2 = (void*) vm;
18941900

18951901
add_java_vm(vm);
18961902
*vm_ptr = vm;

espresso/src/com.oracle.truffle.espresso.native/include/nespresso.h

Lines changed: 143 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
#include <jni.h>
2727
#include <trufflenfi.h>
2828

29-
JNIEXPORT void* JNICALL dupClosureRef(TruffleEnv *truffle_env, void* closure);
29+
struct Varargs {
30+
const struct VarargsInterface* functions;
31+
};
3032

31-
JNIEXPORT JNIEnv* JNICALL initializeNativeContext(TruffleEnv *truffle_env, void* (*fetch_by_name)(const char *));
33+
JNIEXPORT JNIEnv* JNICALL initializeNativeContext(void* (*fetch_by_name)(const char *));
3234

33-
JNIEXPORT void JNICALL disposeNativeContext(TruffleEnv* truffle_env, JNIEnv* env);
35+
JNIEXPORT void JNICALL disposeNativeContext(JNIEnv* env, void (*release_closure)(void *));
3436

3537
// varargs support
3638
JNIEXPORT jboolean JNICALL pop_boolean(struct Varargs* varargs);
@@ -50,6 +52,144 @@ JNIEXPORT void * JNICALL reallocateMemory(void *ptr, size_t new_size);
5052
JNIEXPORT void JNICALL ctypeInit(void);
5153
JNIEXPORT jlong JNICALL get_SIZE_MAX();
5254

55+
#define JNI_FUNCTION_LIST(V) \
56+
V(GetVersion) \
57+
V(DefineClass) \
58+
V(FindClass) \
59+
V(FromReflectedMethod) \
60+
V(FromReflectedField) \
61+
V(ToReflectedMethod) \
62+
V(GetSuperclass) \
63+
V(IsAssignableFrom) \
64+
V(ToReflectedField) \
65+
V(Throw) \
66+
V(ThrowNew) \
67+
V(ExceptionOccurred) \
68+
V(ExceptionDescribe) \
69+
V(ExceptionClear) \
70+
V(FatalError) \
71+
V(PushLocalFrame) \
72+
V(PopLocalFrame) \
73+
V(DeleteLocalRef) \
74+
V(NewLocalRef) \
75+
V(EnsureLocalCapacity) \
76+
V(AllocObject) \
77+
V(GetObjectClass) \
78+
V(IsInstanceOf) \
79+
V(GetMethodID) \
80+
V(GetFieldID) \
81+
V(GetObjectField) \
82+
V(GetBooleanField) \
83+
V(GetByteField) \
84+
V(GetCharField) \
85+
V(GetShortField) \
86+
V(GetIntField) \
87+
V(GetLongField) \
88+
V(GetFloatField) \
89+
V(GetDoubleField) \
90+
V(SetObjectField) \
91+
V(SetBooleanField) \
92+
V(SetByteField) \
93+
V(SetCharField) \
94+
V(SetShortField) \
95+
V(SetIntField) \
96+
V(SetLongField) \
97+
V(SetFloatField) \
98+
V(SetDoubleField) \
99+
V(GetStaticMethodID) \
100+
V(GetStaticFieldID) \
101+
V(GetStaticObjectField) \
102+
V(GetStaticBooleanField) \
103+
V(GetStaticByteField) \
104+
V(GetStaticCharField) \
105+
V(GetStaticShortField) \
106+
V(GetStaticIntField) \
107+
V(GetStaticLongField) \
108+
V(GetStaticFloatField) \
109+
V(GetStaticDoubleField) \
110+
V(SetStaticObjectField) \
111+
V(SetStaticBooleanField) \
112+
V(SetStaticByteField) \
113+
V(SetStaticCharField) \
114+
V(SetStaticShortField) \
115+
V(SetStaticIntField) \
116+
V(SetStaticLongField) \
117+
V(SetStaticFloatField) \
118+
V(SetStaticDoubleField) \
119+
V(NewString) \
120+
V(GetStringLength) \
121+
V(GetStringChars) \
122+
V(ReleaseStringChars) \
123+
V(NewStringUTF) \
124+
V(GetStringUTFLength) \
125+
V(GetStringUTFChars) \
126+
V(ReleaseStringUTFChars) \
127+
V(GetArrayLength) \
128+
V(NewObjectArray) \
129+
V(GetObjectArrayElement) \
130+
V(SetObjectArrayElement) \
131+
V(NewBooleanArray) \
132+
V(NewByteArray) \
133+
V(NewCharArray) \
134+
V(NewShortArray) \
135+
V(NewIntArray) \
136+
V(NewLongArray) \
137+
V(NewFloatArray) \
138+
V(NewDoubleArray) \
139+
V(GetBooleanArrayElements) \
140+
V(GetByteArrayElements) \
141+
V(GetCharArrayElements) \
142+
V(GetShortArrayElements) \
143+
V(GetIntArrayElements) \
144+
V(GetLongArrayElements) \
145+
V(GetFloatArrayElements) \
146+
V(GetDoubleArrayElements) \
147+
V(ReleaseBooleanArrayElements) \
148+
V(ReleaseByteArrayElements) \
149+
V(ReleaseCharArrayElements) \
150+
V(ReleaseShortArrayElements) \
151+
V(ReleaseIntArrayElements) \
152+
V(ReleaseLongArrayElements) \
153+
V(ReleaseFloatArrayElements) \
154+
V(ReleaseDoubleArrayElements) \
155+
V(GetBooleanArrayRegion) \
156+
V(GetByteArrayRegion) \
157+
V(GetCharArrayRegion) \
158+
V(GetShortArrayRegion) \
159+
V(GetIntArrayRegion) \
160+
V(GetLongArrayRegion) \
161+
V(GetFloatArrayRegion) \
162+
V(GetDoubleArrayRegion) \
163+
V(SetBooleanArrayRegion) \
164+
V(SetByteArrayRegion) \
165+
V(SetCharArrayRegion) \
166+
V(SetShortArrayRegion) \
167+
V(SetIntArrayRegion) \
168+
V(SetLongArrayRegion) \
169+
V(SetFloatArrayRegion) \
170+
V(SetDoubleArrayRegion) \
171+
V(UnregisterNatives) \
172+
V(MonitorEnter) \
173+
V(MonitorExit) \
174+
V(GetStringRegion) \
175+
V(GetStringUTFRegion) \
176+
V(GetPrimitiveArrayCritical) \
177+
V(ReleasePrimitiveArrayCritical) \
178+
V(GetStringCritical) \
179+
V(ReleaseStringCritical) \
180+
V(ExceptionCheck) \
181+
V(GetDirectBufferAddress) \
182+
V(GetDirectBufferCapacity) \
183+
V(GetObjectRefType) \
184+
V(IsSameObject) \
185+
V(NewGlobalRef) \
186+
V(DeleteGlobalRef) \
187+
V(NewWeakGlobalRef) \
188+
V(DeleteWeakGlobalRef) \
189+
V(NewDirectByteBuffer) \
190+
V(GetModule)
191+
192+
53193
#endif // _NESPRESSO_H
54194

55195

0 commit comments

Comments
 (0)