Skip to content

Commit 63e4303

Browse files
author
Alex Menkov
committed
8278519: serviceability/jvmti/FieldAccessWatch/FieldAccessWatch.java failed "assert(handle != __null) failed: JNI handle should not be null"
Reviewed-by: cjplummer, sspitsyn
1 parent 6f0e8da commit 63e4303

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

test/hotspot/jtreg/serviceability/jvmti/FieldAccessWatch/FieldAccessWatch.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -57,7 +57,7 @@ public static void main(String[] args) throws Exception {
5757
throw ex;
5858
}
5959

60-
if (!initWatchers(MyList.class, MyList.class.getDeclaredField("items"))) {
60+
if (!initWatchers(MyList.class, MyList.class.getDeclaredField("items"), Thread.currentThread())) {
6161
throw new RuntimeException("Watchers initializations error");
6262
}
6363

@@ -131,7 +131,7 @@ private static void test(String descr, TestAction action) throws Exception {
131131
log(descr + ": OK");
132132
}
133133

134-
private static native boolean initWatchers(Class cls, Field field);
134+
private static native boolean initWatchers(Class cls, Field field, Thread testThread);
135135
private static native boolean startTest(TestResult results);
136136
private static native void stopTest();
137137

test/hotspot/jtreg/serviceability/jvmti/FieldAccessWatch/libFieldAccessWatch.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -37,6 +37,7 @@ static jvmtiEnv *jvmti = NULL;
3737
// valid while a test is executed
3838
static jobject testResultObject = NULL;
3939
static jclass testResultClass = NULL;
40+
static jthread testThread = NULL;
4041

4142

4243
static void reportError(const char *msg, int err) {
@@ -46,6 +47,7 @@ static void reportError(const char *msg, int err) {
4647

4748
// logs the notification and updates currentTestResult
4849
static void handleNotification(JNIEnv *jni_env,
50+
jthread thread,
4951
jmethodID method,
5052
jfieldID field,
5153
jclass field_klass,
@@ -64,6 +66,10 @@ static void handleNotification(JNIEnv *jni_env,
6466
return;
6567
}
6668

69+
if (!(*jni_env)->IsSameObject(jni_env, thread, testThread)) {
70+
return; // skip events from unexpected threads
71+
}
72+
6773
err = (*jvmti)->GetFieldName(jvmti, field_klass, field, &name, NULL, NULL);
6874
if (err != JVMTI_ERROR_NONE) {
6975
reportError("GetFieldName failed", err);
@@ -179,7 +185,7 @@ onFieldAccess(jvmtiEnv *jvmti_env,
179185
jobject object,
180186
jfieldID field)
181187
{
182-
handleNotification(jni_env, method, field, field_klass, 0, location);
188+
handleNotification(jni_env, thread, method, field, field_klass, 0, location);
183189
}
184190

185191

@@ -195,7 +201,7 @@ onFieldModification(jvmtiEnv *jvmti_env,
195201
char signature_type,
196202
jvalue new_value)
197203
{
198-
handleNotification(jni_env, method, field, field_klass, 1, location);
204+
handleNotification(jni_env, thread, method, field, field_klass, 1, location);
199205

200206
if (signature_type == 'L') {
201207
jobject newObject = new_value.l;
@@ -251,7 +257,7 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
251257

252258

253259
JNIEXPORT jboolean JNICALL
254-
Java_FieldAccessWatch_initWatchers(JNIEnv *env, jclass thisClass, jclass cls, jobject field)
260+
Java_FieldAccessWatch_initWatchers(JNIEnv *env, jclass thisClass, jclass cls, jobject field, jthread thread)
255261
{
256262
jfieldID fieldId;
257263
jvmtiError err;
@@ -275,6 +281,8 @@ Java_FieldAccessWatch_initWatchers(JNIEnv *env, jclass thisClass, jclass cls, jo
275281
return JNI_FALSE;
276282
}
277283

284+
testThread = (jthread)(*env)->NewGlobalRef(env, thread);
285+
278286
return JNI_TRUE;
279287
}
280288

0 commit comments

Comments
 (0)