8231769: Test tools/javac/tree/MakeTypeTest.java fails with -Xcheck:jni
authorcoleenp
Fri, 11 Oct 2019 08:49:42 -0400
changeset 58555 7252d89e3a4e
parent 58554 8c3c39710a08
child 58556 ff8716224f35
8231769: Test tools/javac/tree/MakeTypeTest.java fails with -Xcheck:jni Summary: Delete local jni handles in create_from_platform_dependent_str() after upcall to Java. Reviewed-by: dholmes, hseigel
src/hotspot/share/classfile/javaClasses.cpp
--- a/src/hotspot/share/classfile/javaClasses.cpp	Fri Oct 11 17:49:25 2019 +0800
+++ b/src/hotspot/share/classfile/javaClasses.cpp	Fri Oct 11 08:49:42 2019 -0400
@@ -384,13 +384,17 @@
   }
 
   jstring js = NULL;
-  { JavaThread* thread = (JavaThread*)THREAD;
-    assert(thread->is_Java_thread(), "must be java thread");
+  {
+    assert(THREAD->is_Java_thread(), "must be java thread");
+    JavaThread* thread = (JavaThread*)THREAD;
     HandleMark hm(thread);
     ThreadToNativeFromVM ttn(thread);
     js = (_to_java_string_fn)(thread->jni_environment(), str);
   }
-  return Handle(THREAD, JNIHandles::resolve(js));
+
+  Handle native_platform_string(THREAD, JNIHandles::resolve(js));
+  JNIHandles::destroy_local(js);  // destroy local JNIHandle.
+  return native_platform_string;
 }
 
 // Converts a Java String to a native C string that can be used for