8228340: JVMCI deleteGlobalHandle doesn't delete the handle

Add missing call to OopStorage::release() when deleting global handles in JVMCI to prevent handles leak.

Reviewed-by: kvn, dlong
This commit is contained in:
Kim Barrett 2019-07-18 09:15:26 -07:00
parent 0fa1047733
commit 4d471e7845
3 changed files with 10 additions and 2 deletions

View File

@ -93,6 +93,14 @@ jobject JVMCI::make_global(const Handle& obj) {
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;

View File

@ -92,6 +92,7 @@ class JVMCI : public AllStatic {
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);

View File

@ -2181,8 +2181,7 @@ C2V_VMENTRY_NULL(jobject, getObject, (JNIEnv* env, jobject, jobject x, long disp
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);
}
}