< prev index next >

src/hotspot/share/runtime/jniHandles.cpp

Print this page
rev 49487 : imported patch accessorize

@@ -24,21 +24,19 @@
 
 #include "precompiled.hpp"
 #include "gc/shared/oopStorage.inline.hpp"
 #include "logging/log.hpp"
 #include "memory/iterator.hpp"
+#include "oops/access.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "runtime/handles.inline.hpp"
 #include "runtime/jniHandles.inline.hpp"
 #include "runtime/mutexLocker.hpp"
 #include "runtime/thread.inline.hpp"
 #include "trace/traceMacros.hpp"
 #include "utilities/align.hpp"
 #include "utilities/debug.hpp"
-#if INCLUDE_ALL_GCS
-#include "gc/g1/g1BarrierSet.hpp"
-#endif
 
 OopStorage* JNIHandles::_global_handles = NULL;
 OopStorage* JNIHandles::_weak_global_handles = NULL;
 
 

@@ -99,11 +97,12 @@
     // ignore null handles
     assert(oopDesc::is_oop(obj()), "not an oop");
     oop* ptr = _global_handles->allocate();
     // Return NULL on allocation failure.
     if (ptr != NULL) {
-      *ptr = obj();
+      assert(*ptr == NULL, "invariant");
+      RootAccess<IN_CONCURRENT_ROOT>::oop_store(ptr, obj());
       res = reinterpret_cast<jobject>(ptr);
     } else {
       report_handle_allocation_failure(alloc_failmode, "global");
     }
   } else {

@@ -122,11 +121,12 @@
     // ignore null handles
     assert(oopDesc::is_oop(obj()), "not an oop");
     oop* ptr = _weak_global_handles->allocate();
     // Return NULL on allocation failure.
     if (ptr != NULL) {
-      *ptr = obj();
+      assert(*ptr == NULL, "invariant");
+      RootAccess<ON_PHANTOM_OOP_REF>::oop_store(ptr, obj());
       char* tptr = reinterpret_cast<char*>(ptr) + weak_tag_value;
       res = reinterpret_cast<jobject>(tptr);
     } else {
       report_handle_allocation_failure(alloc_failmode, "weak global");
     }

@@ -149,39 +149,37 @@
 }
 
 oop JNIHandles::resolve_jweak(jweak handle) {
   assert(handle != NULL, "precondition");
   assert(is_jweak(handle), "precondition");
-  oop result = jweak_ref(handle);
-#if INCLUDE_ALL_GCS
-  if (result != NULL && UseG1GC) {
-    G1BarrierSet::enqueue(result);
-  }
-#endif // INCLUDE_ALL_GCS
-  return result;
+  return RootAccess<ON_PHANTOM_OOP_REF>::oop_load(jweak_ptr(handle));
 }
 
 bool JNIHandles::is_global_weak_cleared(jweak handle) {
   assert(handle != NULL, "precondition");
   assert(is_jweak(handle), "not a weak handle");
-  return jweak_ref(handle) == NULL;
+  oop* oop_ptr = jweak_ptr(handle);
+  oop value = RootAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(oop_ptr);
+  return value == NULL;
 }
 
 void JNIHandles::destroy_global(jobject handle) {
   if (handle != NULL) {
     assert(!is_jweak(handle), "wrong method for detroying jweak");
-    jobject_ref(handle) = NULL;
-    _global_handles->release(&jobject_ref(handle));
+    oop* oop_ptr = jobject_ptr(handle);
+    RootAccess<IN_CONCURRENT_ROOT>::oop_store(oop_ptr, (oop)NULL);
+    _global_handles->release(oop_ptr);
   }
 }
 
 
 void JNIHandles::destroy_weak_global(jobject handle) {
   if (handle != NULL) {
     assert(is_jweak(handle), "JNI handle not jweak");
-    jweak_ref(handle) = NULL;
-    _weak_global_handles->release(&jweak_ref(handle));
+    oop* oop_ptr = jweak_ptr(handle);
+    RootAccess<ON_PHANTOM_OOP_REF>::oop_store(oop_ptr, (oop)NULL);
+    _weak_global_handles->release(oop_ptr);
   }
 }
 
 
 void JNIHandles::oops_do(OopClosure* f) {

@@ -216,15 +214,15 @@
 
 jobjectRefType JNIHandles::handle_type(Thread* thread, jobject handle) {
   assert(handle != NULL, "precondition");
   jobjectRefType result = JNIInvalidRefType;
   if (is_jweak(handle)) {
-    if (is_storage_handle(_weak_global_handles, &jweak_ref(handle))) {
+    if (is_storage_handle(_weak_global_handles, jweak_ptr(handle))) {
       result = JNIWeakGlobalRefType;
     }
   } else {
-    switch (_global_handles->allocation_status(&jobject_ref(handle))) {
+    switch (_global_handles->allocation_status(jobject_ptr(handle))) {
     case OopStorage::ALLOCATED_ENTRY:
       result = JNIGlobalRefType;
       break;
 
     case OopStorage::UNALLOCATED_ENTRY:

@@ -277,17 +275,17 @@
 }
 
 
 bool JNIHandles::is_global_handle(jobject handle) {
   assert(handle != NULL, "precondition");
-  return !is_jweak(handle) && is_storage_handle(_global_handles, &jobject_ref(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_ref(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();
 }

@@ -349,10 +347,12 @@
 #ifdef ASSERT
 void JNIHandleBlock::zap() {
   // Zap block values
   _top = 0;
   for (int index = 0; index < block_size_in_oops; index++) {
+    // NOT using Access here; just bare clobbering to NULL, since the
+    // block no longer contains valid oops.
     _handles[index] = NULL;
   }
 }
 #endif // ASSERT
 

@@ -504,19 +504,19 @@
   }
 
   // Try last block
   if (_last->_top < block_size_in_oops) {
     oop* handle = &(_last->_handles)[_last->_top++];
-    *handle = obj;
+    RootAccess<AS_DEST_NOT_INITIALIZED>::oop_store(handle, obj);
     return (jobject) handle;
   }
 
   // Try free list
   if (_free_list != NULL) {
     oop* handle = _free_list;
     _free_list = (oop*) *_free_list;
-    *handle = obj;
+    RootAccess<AS_DEST_NOT_INITIALIZED>::oop_store(handle, obj);
     return (jobject) handle;
   }
   // Check if unused block follow last
   if (_last->_next != NULL) {
     // update last and retry
< prev index next >