< prev index next >

src/hotspot/share/runtime/jniHandles.cpp

Print this page
rev 50745 : imported patch remove_in_concurrent_root


  92   if (alloc_failmode == AllocFailStrategy::EXIT_OOM) {
  93     // Fake size value, since we don't know the min allocation size here.
  94     vm_exit_out_of_memory(sizeof(oop), OOM_MALLOC_ERROR,
  95                           "Cannot create %s JNI handle", handle_kind);
  96   } else {
  97     assert(alloc_failmode == AllocFailStrategy::RETURN_NULL, "invariant");
  98   }
  99 }
 100 
 101 jobject JNIHandles::make_global(Handle obj, AllocFailType alloc_failmode) {
 102   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
 103   assert(!current_thread_in_native(), "must not be in native");
 104   jobject res = NULL;
 105   if (!obj.is_null()) {
 106     // ignore null handles
 107     assert(oopDesc::is_oop(obj()), "not an oop");
 108     oop* ptr = global_handles()->allocate();
 109     // Return NULL on allocation failure.
 110     if (ptr != NULL) {
 111       assert(*ptr == NULL, "invariant");
 112       NativeAccess<IN_CONCURRENT_ROOT>::oop_store(ptr, obj());
 113       res = reinterpret_cast<jobject>(ptr);
 114     } else {
 115       report_handle_allocation_failure(alloc_failmode, "global");
 116     }
 117   } else {
 118     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
 119   }
 120 
 121   return res;
 122 }
 123 
 124 
 125 jobject JNIHandles::make_weak_global(Handle obj, AllocFailType alloc_failmode) {
 126   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
 127   assert(!current_thread_in_native(), "must not be in native");
 128   jobject res = NULL;
 129   if (!obj.is_null()) {
 130     // ignore null handles
 131     assert(oopDesc::is_oop(obj()), "not an oop");
 132     oop* ptr = weak_global_handles()->allocate();


 158 }
 159 
 160 oop JNIHandles::resolve_jweak(jweak handle) {
 161   assert(handle != NULL, "precondition");
 162   assert(is_jweak(handle), "precondition");
 163   return NativeAccess<ON_PHANTOM_OOP_REF>::oop_load(jweak_ptr(handle));
 164 }
 165 
 166 bool JNIHandles::is_global_weak_cleared(jweak handle) {
 167   assert(handle != NULL, "precondition");
 168   assert(is_jweak(handle), "not a weak handle");
 169   oop* oop_ptr = jweak_ptr(handle);
 170   oop value = NativeAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(oop_ptr);
 171   return value == NULL;
 172 }
 173 
 174 void JNIHandles::destroy_global(jobject handle) {
 175   if (handle != NULL) {
 176     assert(!is_jweak(handle), "wrong method for detroying jweak");
 177     oop* oop_ptr = jobject_ptr(handle);
 178     NativeAccess<IN_CONCURRENT_ROOT>::oop_store(oop_ptr, (oop)NULL);
 179     global_handles()->release(oop_ptr);
 180   }
 181 }
 182 
 183 
 184 void JNIHandles::destroy_weak_global(jobject handle) {
 185   if (handle != NULL) {
 186     assert(is_jweak(handle), "JNI handle not jweak");
 187     oop* oop_ptr = jweak_ptr(handle);
 188     NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(oop_ptr, (oop)NULL);
 189     weak_global_handles()->release(oop_ptr);
 190   }
 191 }
 192 
 193 
 194 void JNIHandles::oops_do(OopClosure* f) {
 195   global_handles()->oops_do(f);
 196 }
 197 
 198 




  92   if (alloc_failmode == AllocFailStrategy::EXIT_OOM) {
  93     // Fake size value, since we don't know the min allocation size here.
  94     vm_exit_out_of_memory(sizeof(oop), OOM_MALLOC_ERROR,
  95                           "Cannot create %s JNI handle", handle_kind);
  96   } else {
  97     assert(alloc_failmode == AllocFailStrategy::RETURN_NULL, "invariant");
  98   }
  99 }
 100 
 101 jobject JNIHandles::make_global(Handle obj, AllocFailType alloc_failmode) {
 102   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
 103   assert(!current_thread_in_native(), "must not be in native");
 104   jobject res = NULL;
 105   if (!obj.is_null()) {
 106     // ignore null handles
 107     assert(oopDesc::is_oop(obj()), "not an oop");
 108     oop* ptr = global_handles()->allocate();
 109     // Return NULL on allocation failure.
 110     if (ptr != NULL) {
 111       assert(*ptr == NULL, "invariant");
 112       NativeAccess<>::oop_store(ptr, obj());
 113       res = reinterpret_cast<jobject>(ptr);
 114     } else {
 115       report_handle_allocation_failure(alloc_failmode, "global");
 116     }
 117   } else {
 118     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
 119   }
 120 
 121   return res;
 122 }
 123 
 124 
 125 jobject JNIHandles::make_weak_global(Handle obj, AllocFailType alloc_failmode) {
 126   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
 127   assert(!current_thread_in_native(), "must not be in native");
 128   jobject res = NULL;
 129   if (!obj.is_null()) {
 130     // ignore null handles
 131     assert(oopDesc::is_oop(obj()), "not an oop");
 132     oop* ptr = weak_global_handles()->allocate();


 158 }
 159 
 160 oop JNIHandles::resolve_jweak(jweak handle) {
 161   assert(handle != NULL, "precondition");
 162   assert(is_jweak(handle), "precondition");
 163   return NativeAccess<ON_PHANTOM_OOP_REF>::oop_load(jweak_ptr(handle));
 164 }
 165 
 166 bool JNIHandles::is_global_weak_cleared(jweak handle) {
 167   assert(handle != NULL, "precondition");
 168   assert(is_jweak(handle), "not a weak handle");
 169   oop* oop_ptr = jweak_ptr(handle);
 170   oop value = NativeAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(oop_ptr);
 171   return value == NULL;
 172 }
 173 
 174 void JNIHandles::destroy_global(jobject handle) {
 175   if (handle != NULL) {
 176     assert(!is_jweak(handle), "wrong method for detroying jweak");
 177     oop* oop_ptr = jobject_ptr(handle);
 178     NativeAccess<>::oop_store(oop_ptr, (oop)NULL);
 179     global_handles()->release(oop_ptr);
 180   }
 181 }
 182 
 183 
 184 void JNIHandles::destroy_weak_global(jobject handle) {
 185   if (handle != NULL) {
 186     assert(is_jweak(handle), "JNI handle not jweak");
 187     oop* oop_ptr = jweak_ptr(handle);
 188     NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(oop_ptr, (oop)NULL);
 189     weak_global_handles()->release(oop_ptr);
 190   }
 191 }
 192 
 193 
 194 void JNIHandles::oops_do(OopClosure* f) {
 195   global_handles()->oops_do(f);
 196 }
 197 
 198 


< prev index next >