< prev index next >

src/hotspot/share/runtime/jniHandles.cpp

Print this page

        

@@ -45,10 +45,11 @@
   if (obj == NULL) {
     return NULL;                // ignore null handles
   } else {
     Thread* thread = Thread::current();
     assert(Universe::heap()->is_in_reserved(obj), "sanity check");
+    assert(!current_thread_in_native(), "must not be in native");
     return thread->active_handles()->allocate_handle(obj);
   }
 }
 
 

@@ -57,10 +58,12 @@
 jobject JNIHandles::make_local(Thread* thread, oop obj) {
   if (obj == NULL) {
     return NULL;                // ignore null handles
   } else {
     assert(Universe::heap()->is_in_reserved(obj), "sanity check");
+    assert(thread->is_Java_thread(), "not a Java thread");
+    assert(!current_thread_in_native(), "must not be in native");
     return thread->active_handles()->allocate_handle(obj);
   }
 }
 
 

@@ -68,17 +71,19 @@
   if (obj == NULL) {
     return NULL;                // ignore null handles
   } else {
     JavaThread* thread = JavaThread::thread_from_jni_environment(env);
     assert(Universe::heap()->is_in_reserved(obj), "sanity check");
+    assert(!current_thread_in_native(), "must not be in native");
     return thread->active_handles()->allocate_handle(obj);
   }
 }
 
 
 jobject JNIHandles::make_global(Handle obj) {
   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
+  assert(!current_thread_in_native(), "must not be in native");
   jobject res = NULL;
   if (!obj.is_null()) {
     // ignore null handles
     MutexLocker ml(JNIGlobalHandle_lock);
     assert(Universe::heap()->is_in_reserved(obj()), "sanity check");

@@ -91,10 +96,11 @@
 }
 
 
 jobject JNIHandles::make_weak_global(Handle obj) {
   assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
+  assert(!current_thread_in_native(), "must not be in native");
   jobject res = NULL;
   if (!obj.is_null()) {
     // ignore null handles
     {
       MutexLocker ml(JNIGlobalHandle_lock);

@@ -263,10 +269,17 @@
 
   oops_do(&verify_handle);
   weak_oops_do(&verify_handle);
 }
 
+// This method is implemented here to avoid circular includes between
+// jniHandles.hpp and thread.hpp.
+bool JNIHandles::current_thread_in_native() {
+  Thread* thread = Thread::current();
+  return (thread->is_Java_thread() &&
+          JavaThread::current()->thread_state() == _thread_in_native);
+}
 
 
 void jni_handles_init() {
   JNIHandles::initialize();
 }
< prev index next >