8228340: JVMCI deleteGlobalHandle doesn't delete the handle
authorkbarrett
Thu, 18 Jul 2019 09:15:26 -0700
changeset 57492 0fb5cc208e71
parent 57491 6236826e44c3
child 57493 b95ebdbf68ca
8228340: JVMCI deleteGlobalHandle doesn't delete the handle Summary: Add missing call to OopStorage::release() when deleting global handles in JVMCI to prevent handles leak. Reviewed-by: kvn, dlong
src/hotspot/share/jvmci/jvmci.cpp
src/hotspot/share/jvmci/jvmci.hpp
src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
--- a/src/hotspot/share/jvmci/jvmci.cpp	Tue Jul 02 10:28:20 2019 +0200
+++ b/src/hotspot/share/jvmci/jvmci.cpp	Thu Jul 18 09:15:26 2019 -0700
@@ -93,6 +93,14 @@
   return res;
 }
 
+void JVMCI::destroy_global(jobject handle) {
+  // Assert before nulling out, for better debugging.
+  assert(is_global_handle(handle), "precondition");
+  oop* oop_ptr = reinterpret_cast<oop*>(handle);
+  NativeAccess<>::oop_store(oop_ptr, (oop)NULL);
+  object_handles()->release(oop_ptr);
+}
+
 bool JVMCI::is_global_handle(jobject handle) {
   const oop* ptr = reinterpret_cast<oop*>(handle);
   return object_handles()->allocation_status(ptr) == OopStorage::ALLOCATED_ENTRY;
--- a/src/hotspot/share/jvmci/jvmci.hpp	Tue Jul 02 10:28:20 2019 +0200
+++ b/src/hotspot/share/jvmci/jvmci.hpp	Thu Jul 18 09:15:26 2019 -0700
@@ -92,6 +92,7 @@
   static void initialize_compiler(TRAPS);
 
   static jobject make_global(const Handle& obj);
+  static void destroy_global(jobject handle);
   static bool is_global_handle(jobject handle);
 
   static jmetadata allocate_handle(const methodHandle& handle);
--- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Tue Jul 02 10:28:20 2019 +0200
+++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Thu Jul 18 09:15:26 2019 -0700
@@ -2181,8 +2181,7 @@
 C2V_VMENTRY(void, deleteGlobalHandle, (JNIEnv* env, jobject, jlong h))
   jobject handle = (jobject)(address)h;
   if (handle != NULL) {
-    assert(JVMCI::is_global_handle(handle), "Invalid delete of global JNI handle");
-    *((oop*)handle) = NULL; // Mark the handle as deleted, allocate will reuse it
+    JVMCI::destroy_global(handle);
   }
 }