< prev index next >

src/hotspot/share/runtime/jniHandles.cpp

Print this page




  38 #include "utilities/debug.hpp"
  39 
  40 OopStorage* JNIHandles::global_handles() {
  41   return _global_handles;
  42 }
  43 
  44 OopStorage* JNIHandles::weak_global_handles() {
  45   return _weak_global_handles;
  46 }
  47 
  48 // Serviceability agent support.
  49 OopStorage* JNIHandles::_global_handles = NULL;
  50 OopStorage* JNIHandles::_weak_global_handles = NULL;
  51 
  52 void jni_handles_init() {
  53   JNIHandles::_global_handles = OopStorageSet::create_strong("JNI Global");
  54   JNIHandles::_weak_global_handles = OopStorageSet::create_weak("JNI Weak");
  55 }
  56 
  57 jobject JNIHandles::make_local(oop obj) {
  58   if (obj == NULL) {
  59     return NULL;                // ignore null handles
  60   } else {
  61     Thread* thread = Thread::current();
  62     assert(oopDesc::is_oop(obj), "not an oop");
  63     assert(!current_thread_in_native(), "must not be in native");
  64     return thread->active_handles()->allocate_handle(obj);
  65   }
  66 }
  67 
  68 
  69 // optimized versions
  70 
  71 jobject JNIHandles::make_local(Thread* thread, oop obj) {
  72   if (obj == NULL) {
  73     return NULL;                // ignore null handles
  74   } else {
  75     assert(oopDesc::is_oop(obj), "not an oop");
  76     assert(thread->is_Java_thread(), "not a Java thread");
  77     assert(!current_thread_in_native(), "must not be in native");
  78     return thread->active_handles()->allocate_handle(obj);
  79   }
  80 }
  81 
  82 
  83 jobject JNIHandles::make_local(JNIEnv* env, oop obj) {
  84   if (obj == NULL) {
  85     return NULL;                // ignore null handles
  86   } else {
  87     JavaThread* thread = JavaThread::thread_from_jni_environment(env);
  88     assert(oopDesc::is_oop(obj), "not an oop");
  89     assert(!current_thread_in_native(), "must not be in native");
  90     return thread->active_handles()->allocate_handle(obj);
  91   }
  92 }
  93 
  94 
  95 static void report_handle_allocation_failure(AllocFailType alloc_failmode,
  96                                              const char* handle_kind) {
  97   if (alloc_failmode == AllocFailStrategy::EXIT_OOM) {
  98     // Fake size value, since we don't know the min allocation size here.
  99     vm_exit_out_of_memory(sizeof(oop), OOM_MALLOC_ERROR,
 100                           "Cannot create %s JNI handle", handle_kind);
 101   } else {
 102     assert(alloc_failmode == AllocFailStrategy::RETURN_NULL, "invariant");
 103   }
 104 }
 105 
 106 jobject JNIHandles::make_global(Handle obj, AllocFailType alloc_failmode) {
 107   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
 108   assert(!current_thread_in_native(), "must not be in native");
 109   jobject res = NULL;
 110   if (!obj.is_null()) {
 111     // ignore null handles
 112     assert(oopDesc::is_oop(obj()), "not an oop");
 113     oop* ptr = global_handles()->allocate();




  38 #include "utilities/debug.hpp"
  39 
  40 OopStorage* JNIHandles::global_handles() {
  41   return _global_handles;
  42 }
  43 
  44 OopStorage* JNIHandles::weak_global_handles() {
  45   return _weak_global_handles;
  46 }
  47 
  48 // Serviceability agent support.
  49 OopStorage* JNIHandles::_global_handles = NULL;
  50 OopStorage* JNIHandles::_weak_global_handles = NULL;
  51 
  52 void jni_handles_init() {
  53   JNIHandles::_global_handles = OopStorageSet::create_strong("JNI Global");
  54   JNIHandles::_weak_global_handles = OopStorageSet::create_weak("JNI Weak");
  55 }
  56 
  57 jobject JNIHandles::make_local(oop obj) {
  58   return make_local(Thread::current(), obj);







  59 }
  60 
  61 


  62 jobject JNIHandles::make_local(Thread* thread, oop obj) {
  63   if (obj == NULL) {
  64     return NULL;                // ignore null handles
  65   } else {
  66     assert(oopDesc::is_oop(obj), "not an oop");
  67     assert(thread->is_Java_thread(), "not a Java thread");
  68     assert(!current_thread_in_native(), "must not be in native");
  69     return thread->active_handles()->allocate_handle(obj);
  70   }
  71 }













  72 
  73 static void report_handle_allocation_failure(AllocFailType alloc_failmode,
  74                                              const char* handle_kind) {
  75   if (alloc_failmode == AllocFailStrategy::EXIT_OOM) {
  76     // Fake size value, since we don't know the min allocation size here.
  77     vm_exit_out_of_memory(sizeof(oop), OOM_MALLOC_ERROR,
  78                           "Cannot create %s JNI handle", handle_kind);
  79   } else {
  80     assert(alloc_failmode == AllocFailStrategy::RETURN_NULL, "invariant");
  81   }
  82 }
  83 
  84 jobject JNIHandles::make_global(Handle obj, AllocFailType alloc_failmode) {
  85   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
  86   assert(!current_thread_in_native(), "must not be in native");
  87   jobject res = NULL;
  88   if (!obj.is_null()) {
  89     // ignore null handles
  90     assert(oopDesc::is_oop(obj()), "not an oop");
  91     oop* ptr = global_handles()->allocate();


< prev index next >