< prev index next >

src/hotspot/share/prims/jni.cpp

Print this page

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




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


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

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





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

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




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

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

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

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