< prev index next >

src/share/vm/runtime/jniHandles.cpp

Print this page
rev 12906 : [mq]: gc_interface


  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "logging/log.hpp"
  28 #include "memory/iterator.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "prims/jvmtiExport.hpp"

  31 #include "runtime/jniHandles.hpp"
  32 #include "runtime/mutexLocker.hpp"
  33 #include "runtime/thread.inline.hpp"
  34 #if INCLUDE_ALL_GCS
  35 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  36 #endif
  37 
  38 JNIHandleBlock* JNIHandles::_global_handles       = NULL;
  39 JNIHandleBlock* JNIHandles::_weak_global_handles  = NULL;
  40 oop             JNIHandles::_deleted_handle       = NULL;
  41 








  42 
  43 jobject JNIHandles::make_local(oop obj) {
  44   if (obj == NULL) {
  45     return NULL;                // ignore null handles
  46   } else {
  47     Thread* thread = Thread::current();
  48     assert(Universe::heap()->is_in_reserved(obj), "sanity check");
  49     return thread->active_handles()->allocate_handle(obj);
  50   }
  51 }
  52 
  53 
  54 // optimized versions
  55 
  56 jobject JNIHandles::make_local(Thread* thread, oop obj) {
  57   if (obj == NULL) {
  58     return NULL;                // ignore null handles
  59   } else {
  60     assert(Universe::heap()->is_in_reserved(obj), "sanity check");
  61     return thread->active_handles()->allocate_handle(obj);
  62   }
  63 }
  64 
  65 
  66 jobject JNIHandles::make_local(JNIEnv* env, oop obj) {
  67   if (obj == NULL) {
  68     return NULL;                // ignore null handles
  69   } else {
  70     JavaThread* thread = JavaThread::thread_from_jni_environment(env);
  71     assert(Universe::heap()->is_in_reserved(obj), "sanity check");
  72     return thread->active_handles()->allocate_handle(obj);
  73   }


  93 jobject JNIHandles::make_weak_global(Handle obj) {
  94   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
  95   jobject res = NULL;
  96   if (!obj.is_null()) {
  97     // ignore null handles
  98     {
  99       MutexLocker ml(JNIGlobalHandle_lock);
 100       assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
 101       res = _weak_global_handles->allocate_handle(obj());
 102     }
 103     // Add weak tag.
 104     assert(is_ptr_aligned(res, weak_tag_alignment), "invariant");
 105     char* tptr = reinterpret_cast<char*>(res) + weak_tag_value;
 106     res = reinterpret_cast<jobject>(tptr);
 107   } else {
 108     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
 109   }
 110   return res;
 111 }
 112 
 113 template<bool external_guard>
 114 oop JNIHandles::resolve_jweak(jweak handle) {
 115   assert(is_jweak(handle), "precondition");
 116   oop result = jweak_ref(handle);
 117   result = guard_value<external_guard>(result);
 118 #if INCLUDE_ALL_GCS
 119   if (result != NULL && UseG1GC) {
 120     G1SATBCardTableModRefBS::enqueue(result);
 121   }
 122 #endif // INCLUDE_ALL_GCS
 123   return result;
 124 }
 125 
 126 template oop JNIHandles::resolve_jweak<true>(jweak);
 127 template oop JNIHandles::resolve_jweak<false>(jweak);
 128 
 129 void JNIHandles::destroy_global(jobject handle) {
 130   if (handle != NULL) {
 131     assert(is_global_handle(handle), "Invalid delete of global JNI handle");
 132     jobject_ref(handle) = deleted_handle();
 133   }
 134 }
 135 
 136 
 137 void JNIHandles::destroy_weak_global(jobject handle) {
 138   if (handle != NULL) {
 139     jweak_ref(handle) = deleted_handle();
 140   }
 141 }
 142 
 143 
 144 void JNIHandles::oops_do(OopClosure* f) {
 145   f->do_oop(&_deleted_handle);
 146   _global_handles->oops_do(f);
 147 }
 148 
 149 
 150 void JNIHandles::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f) {
 151   _weak_global_handles->weak_oops_do(is_alive, f);
 152 }
 153 
 154 
 155 void JNIHandles::weak_oops_do(OopClosure* f) {
 156   AlwaysTrueClosure always_true;
 157   weak_oops_do(&always_true, f);
 158 }
 159 




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "logging/log.hpp"
  28 #include "memory/iterator.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "prims/jvmtiExport.hpp"
  31 #include "runtime/access.inline.hpp"
  32 #include "runtime/jniHandles.hpp"
  33 #include "runtime/mutexLocker.hpp"
  34 #include "runtime/thread.inline.hpp"



  35 
  36 JNIHandleBlock* JNIHandles::_global_handles       = NULL;
  37 JNIHandleBlock* JNIHandles::_weak_global_handles  = NULL;
  38 oop             JNIHandles::_deleted_handle       = NULL;
  39 
  40 oop JNIHandles::resolve_handle(jobject handle) {
  41   oop* addr = oop_addr(handle);
  42   if (is_jweak(handle)) {
  43     return RootAccess<GC_ACCESS_ON_PHANTOM>::oop_load(addr);
  44   } else {
  45     return RootAccess<GC_ACCESS_ON_STRONG>::oop_load(addr);
  46   }
  47 }
  48 
  49 jobject JNIHandles::make_local(oop obj) {
  50   if (obj == NULL) {
  51     return NULL;                // ignore null handles
  52   } else {
  53     Thread* thread = Thread::current();
  54     assert(Universe::heap()->is_in_reserved(obj), "sanity check");
  55     return thread->active_handles()->allocate_handle(obj);
  56   }
  57 }
  58 

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


  98 jobject JNIHandles::make_weak_global(Handle obj) {
  99   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
 100   jobject res = NULL;
 101   if (!obj.is_null()) {
 102     // ignore null handles
 103     {
 104       MutexLocker ml(JNIGlobalHandle_lock);
 105       assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
 106       res = _weak_global_handles->allocate_handle(obj());
 107     }
 108     // Add weak tag.
 109     assert(is_ptr_aligned(res, weak_tag_alignment), "invariant");
 110     char* tptr = reinterpret_cast<char*>(res) + weak_tag_value;
 111     res = reinterpret_cast<jobject>(tptr);
 112   } else {
 113     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
 114   }
 115   return res;
 116 }
 117 
















 118 void JNIHandles::destroy_global(jobject handle) {
 119   if (handle != NULL) {
 120     assert(is_global_handle(handle), "Invalid delete of global JNI handle");
 121     *oop_addr(handle) = deleted_handle();
 122   }
 123 }
 124 
 125 
 126 void JNIHandles::destroy_weak_global(jobject handle) {
 127   if (handle != NULL) {
 128     *oop_addr(handle) = deleted_handle();
 129   }
 130 }
 131 
 132 
 133 void JNIHandles::oops_do(OopClosure* f) {
 134   f->do_oop(&_deleted_handle);
 135   _global_handles->oops_do(f);
 136 }
 137 
 138 
 139 void JNIHandles::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f) {
 140   _weak_global_handles->weak_oops_do(is_alive, f);
 141 }
 142 
 143 
 144 void JNIHandles::weak_oops_do(OopClosure* f) {
 145   AlwaysTrueClosure always_true;
 146   weak_oops_do(&always_true, f);
 147 }
 148 


< prev index next >