< prev index next >

src/hotspot/share/prims/jni.cpp

Print this page

2698 
2699 //
2700 // Monitor functions
2701 //
2702 
2703 DT_RETURN_MARK_DECL(MonitorEnter, jint
2704                     , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref));
2705 
2706 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj))
2707  HOTSPOT_JNI_MONITORENTER_ENTRY(env, jobj);
2708   jint ret = JNI_ERR;
2709   DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret);
2710 
2711   // If the object is null, we can't do anything with it
2712   if (jobj == NULL) {
2713     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
2714   }
2715 
2716   Handle obj(thread, JNIHandles::resolve_non_null(jobj));
2717   ObjectSynchronizer::jni_enter(obj, thread);




2718   ret = JNI_OK;
2719   return ret;
2720 JNI_END
2721 
2722 DT_RETURN_MARK_DECL(MonitorExit, jint
2723                     , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref));
2724 
2725 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj))
2726  HOTSPOT_JNI_MONITOREXIT_ENTRY(env, jobj);
2727   jint ret = JNI_ERR;
2728   DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret);
2729 
2730   // Don't do anything with a null object
2731   if (jobj == NULL) {
2732     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
2733   }
2734 
2735   Handle obj(THREAD, JNIHandles::resolve_non_null(jobj));
2736   ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR));
2737 


2738   ret = JNI_OK;
2739   return ret;
2740 JNI_END
2741 
2742 //
2743 // Extensions
2744 //
2745 
2746 DT_VOID_RETURN_MARK_DECL(GetStringRegion
2747                          , HOTSPOT_JNI_GETSTRINGREGION_RETURN());
2748 
2749 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf))
2750  HOTSPOT_JNI_GETSTRINGREGION_ENTRY(env, string, start, len, buf);
2751   DT_VOID_RETURN_MARK(GetStringRegion);
2752   oop s = JNIHandles::resolve_non_null(string);
2753   typeArrayOop s_value = java_lang_String::value(s);
2754   int s_len = java_lang_String::length(s, s_value);
2755   if (start < 0 || len < 0 || start > s_len - len) {
2756     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
2757   } else {

3116 JNI_LEAF(jint, jni_GetVersion(JNIEnv *env))
3117   HOTSPOT_JNI_GETVERSION_ENTRY(env);
3118   HOTSPOT_JNI_GETVERSION_RETURN(CurrentVersion);
3119   return CurrentVersion;
3120 JNI_END
3121 
3122 extern struct JavaVM_ main_vm;
3123 
3124 JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm))
3125   HOTSPOT_JNI_GETJAVAVM_ENTRY(env, (void **) vm);
3126   *vm  = (JavaVM *)(&main_vm);
3127   HOTSPOT_JNI_GETJAVAVM_RETURN(JNI_OK);
3128   return JNI_OK;
3129 JNI_END
3130 
3131 
3132 JNI_ENTRY(jobject, jni_GetModule(JNIEnv* env, jclass clazz))
3133   return Modules::get_module(clazz, THREAD);
3134 JNI_END
3135 





3136 
3137 // Structure containing all jni functions
3138 struct JNINativeInterface_ jni_NativeInterface = {
3139     NULL,
3140     NULL,
3141     NULL,
3142 
3143     NULL,
3144 
3145     jni_GetVersion,
3146 
3147     jni_DefineClass,
3148     jni_FindClass,
3149 
3150     jni_FromReflectedMethod,
3151     jni_FromReflectedField,
3152 
3153     jni_ToReflectedMethod,
3154 
3155     jni_GetSuperclass,

3400     jni_ReleasePrimitiveArrayCritical,
3401 
3402     jni_GetStringCritical,
3403     jni_ReleaseStringCritical,
3404 
3405     jni_NewWeakGlobalRef,
3406     jni_DeleteWeakGlobalRef,
3407 
3408     jni_ExceptionCheck,
3409 
3410     jni_NewDirectByteBuffer,
3411     jni_GetDirectBufferAddress,
3412     jni_GetDirectBufferCapacity,
3413 
3414     // New 1_6 features
3415 
3416     jni_GetObjectRefType,
3417 
3418     // Module features
3419 
3420     jni_GetModule




3421 };
3422 
3423 
3424 // For jvmti use to modify jni function table.
3425 // Java threads in native contiues to run until it is transitioned
3426 // to VM at safepoint. Before the transition or before it is blocked
3427 // for safepoint it may access jni function table. VM could crash if
3428 // any java thread access the jni function table in the middle of memcpy.
3429 // To avoid this each function pointers are copied automically.
3430 void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) {
3431   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
3432   intptr_t *a = (intptr_t *) jni_functions();
3433   intptr_t *b = (intptr_t *) new_jni_NativeInterface;
3434   for (uint i=0; i <  sizeof(struct JNINativeInterface_)/sizeof(void *); i++) {
3435     Atomic::store(a++, *b++);
3436   }
3437 }
3438 
3439 void quicken_jni_functions() {
3440   // Replace Get<Primitive>Field with fast versions

2698 
2699 //
2700 // Monitor functions
2701 //
2702 
2703 DT_RETURN_MARK_DECL(MonitorEnter, jint
2704                     , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref));
2705 
2706 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj))
2707  HOTSPOT_JNI_MONITORENTER_ENTRY(env, jobj);
2708   jint ret = JNI_ERR;
2709   DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret);
2710 
2711   // If the object is null, we can't do anything with it
2712   if (jobj == NULL) {
2713     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
2714   }
2715 
2716   Handle obj(thread, JNIHandles::resolve_non_null(jobj));
2717   ObjectSynchronizer::jni_enter(obj, thread);
2718   if (!Continuation::pin(thread)) {
2719     ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR));
2720     THROW_(vmSymbols::java_lang_IllegalMonitorStateException(), JNI_ERR);
2721   }
2722   ret = JNI_OK;
2723   return ret;
2724 JNI_END
2725 
2726 DT_RETURN_MARK_DECL(MonitorExit, jint
2727                     , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref));
2728 
2729 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj))
2730  HOTSPOT_JNI_MONITOREXIT_ENTRY(env, jobj);
2731   jint ret = JNI_ERR;
2732   DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret);
2733 
2734   // Don't do anything with a null object
2735   if (jobj == NULL) {
2736     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
2737   }
2738 
2739   Handle obj(THREAD, JNIHandles::resolve_non_null(jobj));
2740   ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR));
2741   if (!Continuation::unpin(thread)) {
2742     THROW_(vmSymbols::java_lang_IllegalMonitorStateException(), JNI_ERR);
2743   }
2744   ret = JNI_OK;
2745   return ret;
2746 JNI_END
2747 
2748 //
2749 // Extensions
2750 //
2751 
2752 DT_VOID_RETURN_MARK_DECL(GetStringRegion
2753                          , HOTSPOT_JNI_GETSTRINGREGION_RETURN());
2754 
2755 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf))
2756  HOTSPOT_JNI_GETSTRINGREGION_ENTRY(env, string, start, len, buf);
2757   DT_VOID_RETURN_MARK(GetStringRegion);
2758   oop s = JNIHandles::resolve_non_null(string);
2759   typeArrayOop s_value = java_lang_String::value(s);
2760   int s_len = java_lang_String::length(s, s_value);
2761   if (start < 0 || len < 0 || start > s_len - len) {
2762     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
2763   } else {

3122 JNI_LEAF(jint, jni_GetVersion(JNIEnv *env))
3123   HOTSPOT_JNI_GETVERSION_ENTRY(env);
3124   HOTSPOT_JNI_GETVERSION_RETURN(CurrentVersion);
3125   return CurrentVersion;
3126 JNI_END
3127 
3128 extern struct JavaVM_ main_vm;
3129 
3130 JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm))
3131   HOTSPOT_JNI_GETJAVAVM_ENTRY(env, (void **) vm);
3132   *vm  = (JavaVM *)(&main_vm);
3133   HOTSPOT_JNI_GETJAVAVM_RETURN(JNI_OK);
3134   return JNI_OK;
3135 JNI_END
3136 
3137 
3138 JNI_ENTRY(jobject, jni_GetModule(JNIEnv* env, jclass clazz))
3139   return Modules::get_module(clazz, THREAD);
3140 JNI_END
3141 
3142 JNI_ENTRY(jboolean, jni_IsVirtualThread(JNIEnv* env, jobject obj))
3143   oop thread_obj = JNIHandles::resolve_external_guard(obj);
3144   return java_lang_VirtualThread::is_instance(thread_obj) ? JNI_TRUE : JNI_FALSE;
3145 JNI_END
3146 
3147 
3148 // Structure containing all jni functions
3149 struct JNINativeInterface_ jni_NativeInterface = {
3150     NULL,
3151     NULL,
3152     NULL,
3153 
3154     NULL,
3155 
3156     jni_GetVersion,
3157 
3158     jni_DefineClass,
3159     jni_FindClass,
3160 
3161     jni_FromReflectedMethod,
3162     jni_FromReflectedField,
3163 
3164     jni_ToReflectedMethod,
3165 
3166     jni_GetSuperclass,

3411     jni_ReleasePrimitiveArrayCritical,
3412 
3413     jni_GetStringCritical,
3414     jni_ReleaseStringCritical,
3415 
3416     jni_NewWeakGlobalRef,
3417     jni_DeleteWeakGlobalRef,
3418 
3419     jni_ExceptionCheck,
3420 
3421     jni_NewDirectByteBuffer,
3422     jni_GetDirectBufferAddress,
3423     jni_GetDirectBufferCapacity,
3424 
3425     // New 1_6 features
3426 
3427     jni_GetObjectRefType,
3428 
3429     // Module features
3430 
3431     jni_GetModule,
3432 
3433     // Loom
3434 
3435     jni_IsVirtualThread
3436 };
3437 
3438 
3439 // For jvmti use to modify jni function table.
3440 // Java threads in native contiues to run until it is transitioned
3441 // to VM at safepoint. Before the transition or before it is blocked
3442 // for safepoint it may access jni function table. VM could crash if
3443 // any java thread access the jni function table in the middle of memcpy.
3444 // To avoid this each function pointers are copied automically.
3445 void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) {
3446   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
3447   intptr_t *a = (intptr_t *) jni_functions();
3448   intptr_t *b = (intptr_t *) new_jni_NativeInterface;
3449   for (uint i=0; i <  sizeof(struct JNINativeInterface_)/sizeof(void *); i++) {
3450     Atomic::store(a++, *b++);
3451   }
3452 }
3453 
3454 void quicken_jni_functions() {
3455   // Replace Get<Primitive>Field with fast versions
< prev index next >