Skip to content

Commit f48c0f4

Browse files
committed
8336795: [lworld] JNI MonitorEnter doesn't return the right value when it throws an exception
1 parent 0bbfece commit f48c0f4

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/hotspot/share/prims/jni.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2818,7 +2818,7 @@ JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj))
28182818
}
28192819

28202820
Handle obj(thread, JNIHandles::resolve_non_null(jobj));
2821-
ObjectSynchronizer::jni_enter(obj, thread);
2821+
ObjectSynchronizer::jni_enter(obj, CHECK_(JNI_ERR));
28222822
return JNI_OK;
28232823
JNI_END
28242824

test/hotspot/jtreg/runtime/valhalla/inlinetypes/InlineWithJni.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
public value class InlineWithJni {
3636

37+
static int returnValue = 999;
38+
static final int JNI_ERR = -1; // from jni.h
39+
3740
static {
3841
System.loadLibrary("InlineWithJni");
3942
}
@@ -60,6 +63,7 @@ public static void testJniMonitorOps() {
6063
sawIe = true;
6164
}
6265
Asserts.assertTrue(sawIe, "Missing IdentityException");
66+
Asserts.assertEQ(returnValue, JNI_ERR);
6367
try {
6468
new InlineWithJni(0).doJniMonitorExit();
6569
} catch (IllegalMonitorStateException imse) {

test/hotspot/jtreg/runtime/valhalla/inlinetypes/libInlineWithJni.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
JNIEXPORT void JNICALL
2727
Java_runtime_valhalla_inlinetypes_InlineWithJni_doJniMonitorEnter(JNIEnv *env, jobject obj) {
28-
(*env)->MonitorEnter(env, obj);
28+
int ret = (*env)->MonitorEnter(env, obj);
29+
jclass class = (*env)->GetObjectClass(env, obj);
30+
jfieldID fieldId = (*env)->GetStaticFieldID(env, class, "returnValue", "I");
31+
(*env)->SetStaticIntField(env, class, fieldId, ret);
2932
}
3033

3134
JNIEXPORT void JNICALL

0 commit comments

Comments
 (0)