src/share/vm/prims/jni.cpp

Print this page




3319       directBufferSupportInitializeFailed = 1;
3320       return false;
3321     }
3322     bufferCapacityField         = env->GetFieldID(bufferClass, "capacity", "I");
3323     if (env->ExceptionCheck()) {
3324       env->ExceptionClear();
3325       directBufferSupportInitializeFailed = 1;
3326       return false;
3327     }
3328 
3329     if ((directByteBufferConstructor == NULL) ||
3330         (directBufferAddressField    == NULL) ||
3331         (bufferCapacityField         == NULL)) {
3332       directBufferSupportInitializeFailed = 1;
3333       return false;
3334     }
3335 
3336     directBufferSupportInitializeEnded = 1;
3337   } else {
3338     while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) {
3339       // Set state as yield_all can call os:sleep. On Solaris, yield_all calls
3340       // os::sleep which requires the VM state transition. On other platforms, it
3341       // is not necessary. The following call to change the VM state is purposely
3342       // put inside the loop to avoid potential deadlock when multiple threads
3343       // try to call this method. See 6791815 for more details.
3344       ThreadInVMfromNative tivn(thread);
3345       os::yield_all();
3346     }
3347   }
3348 
3349   return !directBufferSupportInitializeFailed;
3350 }
3351 
3352 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity)
3353 {
3354   // thread_from_jni_environment() will block if VM is gone.
3355   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
3356 
3357   JNIWrapper("jni_NewDirectByteBuffer");
3358  HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY(env, address, capacity);
3359 
3360   if (!directBufferSupportInitializeEnded) {
3361     if (!initializeDirectBufferSupport(env, thread)) {
3362       HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(NULL);
3363       return NULL;
3364     }
3365   }




3319       directBufferSupportInitializeFailed = 1;
3320       return false;
3321     }
3322     bufferCapacityField         = env->GetFieldID(bufferClass, "capacity", "I");
3323     if (env->ExceptionCheck()) {
3324       env->ExceptionClear();
3325       directBufferSupportInitializeFailed = 1;
3326       return false;
3327     }
3328 
3329     if ((directByteBufferConstructor == NULL) ||
3330         (directBufferAddressField    == NULL) ||
3331         (bufferCapacityField         == NULL)) {
3332       directBufferSupportInitializeFailed = 1;
3333       return false;
3334     }
3335 
3336     directBufferSupportInitializeEnded = 1;
3337   } else {
3338     while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) {
3339       os::yield();






3340     }
3341   }
3342 
3343   return !directBufferSupportInitializeFailed;
3344 }
3345 
3346 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity)
3347 {
3348   // thread_from_jni_environment() will block if VM is gone.
3349   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
3350 
3351   JNIWrapper("jni_NewDirectByteBuffer");
3352  HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY(env, address, capacity);
3353 
3354   if (!directBufferSupportInitializeEnded) {
3355     if (!initializeDirectBufferSupport(env, thread)) {
3356       HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(NULL);
3357       return NULL;
3358     }
3359   }