changeset 49665:4062c2c5f7d7

8200195: serviceability/jvmti/FieldAccessWatch/FieldAccessWatch.java crashes with "assert(thread->thread_state() == _thread_in_native) failed: coming from wrong thread state" Reviewed-by: sspitsyn, cjplummer
author amenkov
date Tue, 10 Apr 2018 15:33:11 -0700
parents 00805b129186
children 0d8ed8b2ac4f
files test/hotspot/jtreg/serviceability/jvmti/FieldAccessWatch/libFieldAccessWatch.c
diffstat 1 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/jtreg/serviceability/jvmti/FieldAccessWatch/libFieldAccessWatch.c	Tue Apr 10 11:43:40 2018 -0700
+++ b/test/hotspot/jtreg/serviceability/jvmti/FieldAccessWatch/libFieldAccessWatch.c	Tue Apr 10 15:33:11 2018 -0700
@@ -35,7 +35,6 @@
 static jvmtiEnv *jvmti = NULL;
 
 // valid while a test is executed
-static JNIEnv *javaEnv = NULL;
 static jobject testResultObject = NULL;
 static jclass testResultClass = NULL;
 
@@ -46,7 +45,8 @@
 
 
 // logs the notification and updates currentTestResult
-static void handleNotification(jmethodID method,
+static void handleNotification(JNIEnv *jni_env,
+    jmethodID method,
     jfieldID field,
     jclass field_klass,
     int modified,
@@ -92,21 +92,21 @@
         csig, mname, mgensig, modified ? "modified" : "accessed", name, (int)location);
 
     // set TestResult
-    if (javaEnv != NULL && testResultObject != NULL && testResultClass != NULL) {
+    if (testResultObject != NULL && testResultClass != NULL) {
         jfieldID fieldID;
         // field names in TestResult are "<field_name>_access"/"<field_name>_modify"
         char *fieldName = (char *)malloc(strlen(name) + 16);
         strcpy(fieldName, name);
         strcat(fieldName, modified ? "_modify" : "_access");
 
-        fieldID = (*javaEnv)->GetFieldID(javaEnv, testResultClass, fieldName, "Z");
+        fieldID = (*jni_env)->GetFieldID(jni_env, testResultClass, fieldName, "Z");
         if (fieldID != NULL) {
-            (*javaEnv)->SetBooleanField(javaEnv, testResultObject, fieldID, JNI_TRUE);
+            (*jni_env)->SetBooleanField(jni_env, testResultObject, fieldID, JNI_TRUE);
         } else {
             // the field is not interesting for the test
         }
         // clear any possible exception
-        (*javaEnv)->ExceptionClear(javaEnv);
+        (*jni_env)->ExceptionClear(jni_env);
 
         free(fieldName);
     }
@@ -179,7 +179,7 @@
             jobject object,
             jfieldID field)
 {
-    handleNotification(method, field, field_klass, 0, location);
+    handleNotification(jni_env, method, field, field_klass, 0, location);
 }
 
 
@@ -195,7 +195,7 @@
             char signature_type,
             jvalue new_value)
 {
-    handleNotification(method, field, field_klass, 1, location);
+    handleNotification(jni_env, method, field, field_klass, 1, location);
 
     if (signature_type == 'L') {
         jobject newObject = new_value.l;
@@ -282,9 +282,8 @@
 JNIEXPORT jboolean JNICALL
 Java_FieldAccessWatch_startTest(JNIEnv *env, jclass thisClass, jobject testResults)
 {
-    javaEnv = env;
-    testResultObject = (*javaEnv)->NewGlobalRef(javaEnv, testResults);
-    testResultClass = (jclass)(*javaEnv)->NewGlobalRef(javaEnv, (*javaEnv)->GetObjectClass(javaEnv, testResultObject));
+    testResultObject = (*env)->NewGlobalRef(env, testResults);
+    testResultClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, testResultObject));
 
     return JNI_TRUE;
 }