8202230: Provide accessors for JNIHandles storage objects
authorkbarrett
Fri, 27 Apr 2018 03:57:00 -0400
changeset 49909 f276b348ec14
parent 49908 22eb3e22f245
child 49910 c822dd1a3b66
8202230: Provide accessors for JNIHandles storage objects Summary: Add JNIHandles::[weak_]global_handles(). Reviewed-by: coleenp, tschatzl
src/hotspot/share/runtime/jniHandles.cpp
src/hotspot/share/runtime/jniHandles.hpp
--- a/src/hotspot/share/runtime/jniHandles.cpp	Fri Apr 27 07:59:29 2018 +0200
+++ b/src/hotspot/share/runtime/jniHandles.cpp	Fri Apr 27 03:57:00 2018 -0400
@@ -39,6 +39,16 @@
 OopStorage* JNIHandles::_global_handles = NULL;
 OopStorage* JNIHandles::_weak_global_handles = NULL;
 
+OopStorage* JNIHandles::global_handles() {
+  assert(_global_handles != NULL, "Uninitialized JNI global handles");
+  return _global_handles;
+}
+
+OopStorage* JNIHandles::weak_global_handles() {
+  assert(_weak_global_handles != NULL, "Uninitialized JNI weak global handles");
+  return _weak_global_handles;
+}
+
 
 jobject JNIHandles::make_local(oop obj) {
   if (obj == NULL) {
@@ -96,7 +106,7 @@
   if (!obj.is_null()) {
     // ignore null handles
     assert(oopDesc::is_oop(obj()), "not an oop");
-    oop* ptr = _global_handles->allocate();
+    oop* ptr = global_handles()->allocate();
     // Return NULL on allocation failure.
     if (ptr != NULL) {
       assert(*ptr == NULL, "invariant");
@@ -120,7 +130,7 @@
   if (!obj.is_null()) {
     // ignore null handles
     assert(oopDesc::is_oop(obj()), "not an oop");
-    oop* ptr = _weak_global_handles->allocate();
+    oop* ptr = weak_global_handles()->allocate();
     // Return NULL on allocation failure.
     if (ptr != NULL) {
       assert(*ptr == NULL, "invariant");
@@ -167,7 +177,7 @@
     assert(!is_jweak(handle), "wrong method for detroying jweak");
     oop* oop_ptr = jobject_ptr(handle);
     RootAccess<IN_CONCURRENT_ROOT>::oop_store(oop_ptr, (oop)NULL);
-    _global_handles->release(oop_ptr);
+    global_handles()->release(oop_ptr);
   }
 }
 
@@ -177,23 +187,23 @@
     assert(is_jweak(handle), "JNI handle not jweak");
     oop* oop_ptr = jweak_ptr(handle);
     RootAccess<ON_PHANTOM_OOP_REF>::oop_store(oop_ptr, (oop)NULL);
-    _weak_global_handles->release(oop_ptr);
+    weak_global_handles()->release(oop_ptr);
   }
 }
 
 
 void JNIHandles::oops_do(OopClosure* f) {
-  _global_handles->oops_do(f);
+  global_handles()->oops_do(f);
 }
 
 
 void JNIHandles::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f) {
-  _weak_global_handles->weak_oops_do(is_alive, f);
+  weak_global_handles()->weak_oops_do(is_alive, f);
 }
 
 
 void JNIHandles::weak_oops_do(OopClosure* f) {
-  _weak_global_handles->weak_oops_do(f);
+  weak_global_handles()->weak_oops_do(f);
 }
 
 
@@ -216,11 +226,11 @@
   assert(handle != NULL, "precondition");
   jobjectRefType result = JNIInvalidRefType;
   if (is_jweak(handle)) {
-    if (is_storage_handle(_weak_global_handles, jweak_ptr(handle))) {
+    if (is_storage_handle(weak_global_handles(), jweak_ptr(handle))) {
       result = JNIWeakGlobalRefType;
     }
   } else {
-    switch (_global_handles->allocation_status(jobject_ptr(handle))) {
+    switch (global_handles()->allocation_status(jobject_ptr(handle))) {
     case OopStorage::ALLOCATED_ENTRY:
       result = JNIGlobalRefType;
       break;
@@ -277,33 +287,31 @@
 
 bool JNIHandles::is_global_handle(jobject handle) {
   assert(handle != NULL, "precondition");
-  return !is_jweak(handle) && is_storage_handle(_global_handles, jobject_ptr(handle));
+  return !is_jweak(handle) && is_storage_handle(global_handles(), jobject_ptr(handle));
 }
 
 
 bool JNIHandles::is_weak_global_handle(jobject handle) {
   assert(handle != NULL, "precondition");
-  return is_jweak(handle) && is_storage_handle(_weak_global_handles, jweak_ptr(handle));
+  return is_jweak(handle) && is_storage_handle(weak_global_handles(), jweak_ptr(handle));
 }
 
 size_t JNIHandles::global_handle_memory_usage() {
-  return _global_handles->total_memory_usage();
+  return global_handles()->total_memory_usage();
 }
 
 size_t JNIHandles::weak_global_handle_memory_usage() {
-  return _weak_global_handles->total_memory_usage();
+  return weak_global_handles()->total_memory_usage();
 }
 
 
 // We assume this is called at a safepoint: no lock is needed.
 void JNIHandles::print_on(outputStream* st) {
   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
-  assert(_global_handles != NULL && _weak_global_handles != NULL,
-         "JNIHandles not initialized");
 
   st->print_cr("JNI global refs: " SIZE_FORMAT ", weak refs: " SIZE_FORMAT,
-               _global_handles->allocation_count(),
-               _weak_global_handles->allocation_count());
+               global_handles()->allocation_count(),
+               weak_global_handles()->allocation_count());
   st->cr();
   st->flush();
 }
--- a/src/hotspot/share/runtime/jniHandles.hpp	Fri Apr 27 07:59:29 2018 +0200
+++ b/src/hotspot/share/runtime/jniHandles.hpp	Fri Apr 27 03:57:00 2018 -0400
@@ -115,6 +115,9 @@
   static void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f);
   // Traversal of weak global handles.
   static void weak_oops_do(OopClosure* f);
+
+  static OopStorage* global_handles();
+  static OopStorage* weak_global_handles();
 };