< prev index next >

src/hotspot/share/runtime/jniHandles.cpp

Print this page




  30 #include "runtime/jniHandles.hpp"
  31 #include "runtime/mutexLocker.hpp"
  32 #include "runtime/thread.inline.hpp"
  33 #include "trace/traceMacros.hpp"
  34 #include "utilities/align.hpp"
  35 #if INCLUDE_ALL_GCS
  36 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  37 #endif
  38 
  39 JNIHandleBlock* JNIHandles::_global_handles       = NULL;
  40 JNIHandleBlock* JNIHandles::_weak_global_handles  = NULL;
  41 oop             JNIHandles::_deleted_handle       = NULL;
  42 
  43 
  44 jobject JNIHandles::make_local(oop obj) {
  45   if (obj == NULL) {
  46     return NULL;                // ignore null handles
  47   } else {
  48     Thread* thread = Thread::current();
  49     assert(Universe::heap()->is_in_reserved(obj), "sanity check");

  50     return thread->active_handles()->allocate_handle(obj);
  51   }
  52 }
  53 
  54 
  55 // optimized versions
  56 
  57 jobject JNIHandles::make_local(Thread* thread, oop obj) {
  58   if (obj == NULL) {
  59     return NULL;                // ignore null handles
  60   } else {
  61     assert(Universe::heap()->is_in_reserved(obj), "sanity check");


  62     return thread->active_handles()->allocate_handle(obj);
  63   }
  64 }
  65 
  66 
  67 jobject JNIHandles::make_local(JNIEnv* env, oop obj) {
  68   if (obj == NULL) {
  69     return NULL;                // ignore null handles
  70   } else {
  71     JavaThread* thread = JavaThread::thread_from_jni_environment(env);
  72     assert(Universe::heap()->is_in_reserved(obj), "sanity check");

  73     return thread->active_handles()->allocate_handle(obj);
  74   }
  75 }
  76 
  77 
  78 jobject JNIHandles::make_global(Handle obj) {
  79   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");

  80   jobject res = NULL;
  81   if (!obj.is_null()) {
  82     // ignore null handles
  83     MutexLocker ml(JNIGlobalHandle_lock);
  84     assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
  85     res = _global_handles->allocate_handle(obj());
  86   } else {
  87     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
  88   }
  89 
  90   return res;
  91 }
  92 
  93 
  94 jobject JNIHandles::make_weak_global(Handle obj) {
  95   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");

  96   jobject res = NULL;
  97   if (!obj.is_null()) {
  98     // ignore null handles
  99     {
 100       MutexLocker ml(JNIGlobalHandle_lock);
 101       assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
 102       res = _weak_global_handles->allocate_handle(obj());
 103     }
 104     // Add weak tag.
 105     assert(is_aligned(res, weak_tag_alignment), "invariant");
 106     char* tptr = reinterpret_cast<char*>(res) + weak_tag_value;
 107     res = reinterpret_cast<jobject>(tptr);
 108   } else {
 109     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
 110   }
 111   return res;
 112 }
 113 
 114 template<bool external_guard>
 115 oop JNIHandles::resolve_jweak(jweak handle) {




  30 #include "runtime/jniHandles.hpp"
  31 #include "runtime/mutexLocker.hpp"
  32 #include "runtime/thread.inline.hpp"
  33 #include "trace/traceMacros.hpp"
  34 #include "utilities/align.hpp"
  35 #if INCLUDE_ALL_GCS
  36 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  37 #endif
  38 
  39 JNIHandleBlock* JNIHandles::_global_handles       = NULL;
  40 JNIHandleBlock* JNIHandles::_weak_global_handles  = NULL;
  41 oop             JNIHandles::_deleted_handle       = NULL;
  42 
  43 
  44 jobject JNIHandles::make_local(oop obj) {
  45   if (obj == NULL) {
  46     return NULL;                // ignore null handles
  47   } else {
  48     Thread* thread = Thread::current();
  49     assert(Universe::heap()->is_in_reserved(obj), "sanity check");
  50     assert(JavaThread::current()->thread_state() != _thread_in_native, "must not be in native");
  51     return thread->active_handles()->allocate_handle(obj);
  52   }
  53 }
  54 
  55 
  56 // optimized versions
  57 
  58 jobject JNIHandles::make_local(Thread* thread, oop obj) {
  59   if (obj == NULL) {
  60     return NULL;                // ignore null handles
  61   } else {
  62     assert(Universe::heap()->is_in_reserved(obj), "sanity check");
  63     assert(thread->is_Java_thread(), "not a Java thread");
  64     assert(((JavaThread *)thread)->thread_state() != _thread_in_native, "must not be in native");
  65     return thread->active_handles()->allocate_handle(obj);
  66   }
  67 }
  68 
  69 
  70 jobject JNIHandles::make_local(JNIEnv* env, oop obj) {
  71   if (obj == NULL) {
  72     return NULL;                // ignore null handles
  73   } else {
  74     JavaThread* thread = JavaThread::thread_from_jni_environment(env);
  75     assert(Universe::heap()->is_in_reserved(obj), "sanity check");
  76     assert(thread->thread_state() != _thread_in_native, "must not be in native");
  77     return thread->active_handles()->allocate_handle(obj);
  78   }
  79 }
  80 
  81 
  82 jobject JNIHandles::make_global(Handle obj) {
  83   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
  84   assert(JavaThread::current()->thread_state() != _thread_in_native, "must not be in native");
  85   jobject res = NULL;
  86   if (!obj.is_null()) {
  87     // ignore null handles
  88     MutexLocker ml(JNIGlobalHandle_lock);
  89     assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
  90     res = _global_handles->allocate_handle(obj());
  91   } else {
  92     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
  93   }
  94 
  95   return res;
  96 }
  97 
  98 
  99 jobject JNIHandles::make_weak_global(Handle obj) {
 100   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
 101   assert(JavaThread::current()->thread_state() != _thread_in_native, "must not be in native");
 102   jobject res = NULL;
 103   if (!obj.is_null()) {
 104     // ignore null handles
 105     {
 106       MutexLocker ml(JNIGlobalHandle_lock);
 107       assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
 108       res = _weak_global_handles->allocate_handle(obj());
 109     }
 110     // Add weak tag.
 111     assert(is_aligned(res, weak_tag_alignment), "invariant");
 112     char* tptr = reinterpret_cast<char*>(res) + weak_tag_value;
 113     res = reinterpret_cast<jobject>(tptr);
 114   } else {
 115     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
 116   }
 117   return res;
 118 }
 119 
 120 template<bool external_guard>
 121 oop JNIHandles::resolve_jweak(jweak handle) {


< prev index next >