src/share/vm/prims/jni.cpp

Print this page




2674 
2675     // Make global references for these
2676     bufferClass           = (jclass) env->NewGlobalRef(bufferClass);
2677     directBufferClass     = (jclass) env->NewGlobalRef(directBufferClass);
2678     directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass);
2679 
2680     // Get needed field and method IDs
2681     directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V");
2682     directBufferAddressField    = env->GetFieldID(bufferClass, "address", "J");
2683     bufferCapacityField         = env->GetFieldID(bufferClass, "capacity", "I");
2684 
2685     if ((directByteBufferConstructor == NULL) ||
2686         (directBufferAddressField    == NULL) ||
2687         (bufferCapacityField         == NULL)) {
2688       directBufferSupportInitializeFailed = 1;
2689       return false;
2690     }
2691 
2692     directBufferSupportInitializeEnded = 1;
2693   } else {
2694     ThreadInVMfromNative tivn(thread); // set state as yield_all can call os:sleep
2695     while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) {






2696       os::yield_all();
2697     }
2698   }
2699 
2700   return !directBufferSupportInitializeFailed;
2701 }
2702 
2703 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity)
2704 {
2705   // thread_from_jni_environment() will block if VM is gone.
2706   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
2707 
2708   JNIWrapper("jni_NewDirectByteBuffer");
2709   DTRACE_PROBE3(hotspot_jni, NewDirectByteBuffer__entry, env, address, capacity);
2710 
2711   if (!directBufferSupportInitializeEnded) {
2712     if (!initializeDirectBufferSupport(env, thread)) {
2713       DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, NULL);
2714       return NULL;
2715     }




2674 
2675     // Make global references for these
2676     bufferClass           = (jclass) env->NewGlobalRef(bufferClass);
2677     directBufferClass     = (jclass) env->NewGlobalRef(directBufferClass);
2678     directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass);
2679 
2680     // Get needed field and method IDs
2681     directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V");
2682     directBufferAddressField    = env->GetFieldID(bufferClass, "address", "J");
2683     bufferCapacityField         = env->GetFieldID(bufferClass, "capacity", "I");
2684 
2685     if ((directByteBufferConstructor == NULL) ||
2686         (directBufferAddressField    == NULL) ||
2687         (bufferCapacityField         == NULL)) {
2688       directBufferSupportInitializeFailed = 1;
2689       return false;
2690     }
2691 
2692     directBufferSupportInitializeEnded = 1;
2693   } else {

2694     while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) {
2695       // Set state as yield_all can call os:sleep. On Solaris, yield_all calls 
2696       // os::sleep which requires the VM state transition. On other platforms, it
2697       // is not necessary. The following call to transit the VM state is purposely
2698       // put inside the loop to avoid potential deadlock when multiple threads
2699       // try to call this method. See 6791815 for more details.
2700       ThreadInVMfromNative tivn(thread); 
2701       os::yield_all();
2702     }
2703   }
2704 
2705   return !directBufferSupportInitializeFailed;
2706 }
2707 
2708 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity)
2709 {
2710   // thread_from_jni_environment() will block if VM is gone.
2711   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
2712 
2713   JNIWrapper("jni_NewDirectByteBuffer");
2714   DTRACE_PROBE3(hotspot_jni, NewDirectByteBuffer__entry, env, address, capacity);
2715 
2716   if (!directBufferSupportInitializeEnded) {
2717     if (!initializeDirectBufferSupport(env, thread)) {
2718       DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, NULL);
2719       return NULL;
2720     }