@@ -165,14 +165,19 @@ Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) {
165165 MACOS_AARCH64_ONLY (ThreadWXEnable __wx (WXWrite, thread)); \
166166 ThreadInVMfromNative __tiv (thread); \
167167 HandleMarkCleaner __hm (thread); \
168- JavaThread* THREAD = thread; \
168+ JavaThread* THREAD = thread; \
169169 debug_only (VMNativeEntryWrapper __vew;)
170170
171171// Native method block that transitions current thread to '_thread_in_vm'.
172- #define C2V_BLOCK (result_type, name, signature ) \
173- JVMCI_VM_ENTRY_MARK; \
174- ResourceMark rm; \
175- JVMCIENV_FROM_JNI (JVMCI::compilation_tick(thread), env);
172+ // Note: CompilerThreadCanCallJava must precede JVMCIENV_FROM_JNI so that
173+ // the translation of an uncaught exception in the JVMCIEnv does not make
174+ // a Java call when __is_hotspot == false.
175+ #define C2V_BLOCK (result_type, name, signature ) \
176+ JVMCI_VM_ENTRY_MARK; \
177+ ResourceMark rm; \
178+ bool __is_hotspot = env == thread->jni_environment (); \
179+ CompilerThreadCanCallJava ccj (thread, __is_hotspot); \
180+ JVMCIENV_FROM_JNI (JVMCI::compilation_tick(thread), env); \
176181
177182static JavaThread* get_current_thread (bool allow_null=true ) {
178183 Thread* thread = Thread::current_or_null_safe ();
@@ -188,7 +193,7 @@ static JavaThread* get_current_thread(bool allow_null=true) {
188193#define C2V_VMENTRY (result_type, name, signature ) \
189194 JNIEXPORT result_type JNICALL c2v_ ## name signature { \
190195 JavaThread* thread = get_current_thread (); \
191- if (thread == nullptr ) { \
196+ if (thread == nullptr ) { \
192197 env->ThrowNew (JNIJVMCI::InternalError::clazz (), \
193198 err_msg (" Cannot call into HotSpot from JVMCI shared library without attaching current thread" )); \
194199 return ; \
@@ -199,7 +204,7 @@ static JavaThread* get_current_thread(bool allow_null=true) {
199204#define C2V_VMENTRY_ (result_type, name, signature, result ) \
200205 JNIEXPORT result_type JNICALL c2v_ ## name signature { \
201206 JavaThread* thread = get_current_thread (); \
202- if (thread == nullptr ) { \
207+ if (thread == nullptr ) { \
203208 env->ThrowNew (JNIJVMCI::InternalError::clazz (), \
204209 err_msg (" Cannot call into HotSpot from JVMCI shared library without attaching current thread" )); \
205210 return result; \
@@ -221,15 +226,15 @@ static JavaThread* get_current_thread(bool allow_null=true) {
221226#define JNI_THROW (caller, name, msg ) do { \
222227 jint __throw_res = env->ThrowNew (JNIJVMCI::name::clazz (), msg); \
223228 if (__throw_res != JNI_OK) { \
224- tty-> print_cr (" Throwing " #name " in " caller " returned %d" , __throw_res); \
229+ JVMCI_event_1 (" Throwing " #name " in " caller " returned %d" , __throw_res); \
225230 } \
226231 return ; \
227232 } while (0 );
228233
229234#define JNI_THROW_ (caller, name, msg, result ) do { \
230235 jint __throw_res = env->ThrowNew (JNIJVMCI::name::clazz (), msg); \
231236 if (__throw_res != JNI_OK) { \
232- tty-> print_cr (" Throwing " #name " in " caller " returned %d" , __throw_res); \
237+ JVMCI_event_1 (" Throwing " #name " in " caller " returned %d" , __throw_res); \
233238 } \
234239 return result; \
235240 } while (0 )
@@ -579,6 +584,7 @@ C2V_VMENTRY_0(jboolean, shouldInlineMethod,(JNIEnv* env, jobject, ARGUMENT_PAIR(
579584C2V_END
580585
581586C2V_VMENTRY_NULL (jobject, lookupType, (JNIEnv* env, jobject, jstring jname, ARGUMENT_PAIR(accessing_klass), jint accessing_klass_loader, jboolean resolve))
587+ CompilerThreadCanCallJava canCallJava(thread, resolve); // Resolution requires Java calls
582588 JVMCIObject name = JVMCIENV->wrap (jname);
583589 const char * str = JVMCIENV->as_utf8_string (name);
584590 TempNewSymbol class_name = SymbolTable::new_symbol(str);
@@ -592,7 +598,7 @@ C2V_VMENTRY_NULL(jobject, lookupType, (JNIEnv* env, jobject, jstring jname, ARGU
592598 if (val != nullptr ) {
593599 if (strstr (val, " <trace>" ) != nullptr ) {
594600 tty->print_cr (" CompilerToVM.lookupType: %s" , str);
595- } else if (strstr (val, str ) != nullptr ) {
601+ } else if (strstr (str, val ) != nullptr ) {
596602 THROW_MSG_0 (vmSymbols::java_lang_Exception (),
597603 err_msg (" lookupTypeException: %s" , str));
598604 }
@@ -938,6 +944,17 @@ C2V_VMENTRY_NULL(jobject, resolveFieldInPool, (JNIEnv* env, jobject, ARGUMENT_PA
938944 Bytecodes::Code code = (Bytecodes::Code)(((int ) opcode) & 0xFF );
939945 fieldDescriptor fd;
940946 methodHandle mh (THREAD, UNPACK_PAIR(Method, method));
947+
948+ Bytecodes::Code bc = (Bytecodes::Code) (((int ) opcode) & 0xFF );
949+ int holder_index = cp->klass_ref_index_at (index, bc);
950+ if (!cp->tag_at (holder_index).is_klass() && !THREAD->can_call_java()) {
951+ // If the holder is not resolved in the constant pool and the current
952+ // thread cannot call Java, return null. This avoids a Java call
953+ // in LinkInfo to load the holder.
954+ Symbol* klass_name = cp->klass_ref_at_noresolve (index, bc);
955+ return nullptr ;
956+ }
957+
941958 LinkInfo link_info (cp, index, mh, code, CHECK_NULL);
942959 LinkResolver::resolve_field (fd, link_info, Bytecodes::java_code(code), false, CHECK_NULL);
943960 JVMCIPrimitiveArray info = JVMCIENV->wrap (info_handle);
@@ -2726,6 +2743,7 @@ C2V_VMENTRY_0(jlong, translate, (JNIEnv* env, jobject, jobject obj_handle, jbool
27262743 return 0L ;
27272744 }
27282745 PEER_JVMCIENV_FROM_THREAD (THREAD, !JVMCIENV->is_hotspot ());
2746+ CompilerThreadCanCallJava canCallJava (thread, PEER_JVMCIENV->is_hotspot ());
27292747 PEER_JVMCIENV->check_init (JVMCI_CHECK_0);
27302748
27312749 JVMCIEnv* thisEnv = JVMCIENV;
@@ -2945,18 +2963,21 @@ static jbyteArray get_encoded_annotation_data(InstanceKlass* holder, AnnotationA
29452963
29462964C2V_VMENTRY_NULL (jbyteArray, getEncodedClassAnnotationData, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass),
29472965 jobject filter, jint filter_length, jlong filter_klass_pointers))
2966+ CompilerThreadCanCallJava canCallJava(thread, true ); // Requires Java support
29482967 InstanceKlass* holder = InstanceKlass::cast(UNPACK_PAIR(Klass, klass));
29492968 return get_encoded_annotation_data(holder, holder->class_annotations (), true, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
29502969C2V_END
29512970
29522971C2V_VMENTRY_NULL (jbyteArray, getEncodedExecutableAnnotationData, (JNIEnv* env, jobject, ARGUMENT_PAIR(method),
29532972 jobject filter, jint filter_length, jlong filter_klass_pointers))
2973+ CompilerThreadCanCallJava canCallJava(thread, true ); // Requires Java support
29542974 methodHandle method (THREAD, UNPACK_PAIR(Method, method));
29552975 return get_encoded_annotation_data(method->method_holder (), method->annotations(), false, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
29562976C2V_END
29572977
29582978C2V_VMENTRY_NULL (jbyteArray, getEncodedFieldAnnotationData, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index,
29592979 jobject filter, jint filter_length, jlong filter_klass_pointers))
2980+ CompilerThreadCanCallJava canCallJava(thread, true ); // Requires Java support
29602981 InstanceKlass* holder = check_field(InstanceKlass::cast(UNPACK_PAIR(Klass, klass)), index, JVMCIENV);
29612982 fieldDescriptor fd (holder, index);
29622983 return get_encoded_annotation_data(holder, fd.annotations(), false , filter_length, filter_klass_pointers, THREAD, JVMCIENV);
@@ -3013,6 +3034,7 @@ C2V_VMENTRY_0(jboolean, addFailedSpeculation, (JNIEnv* env, jobject, jlong faile
30133034C2V_END
30143035
30153036C2V_VMENTRY (void , callSystemExit, (JNIEnv* env, jobject, jint status))
3037+ CompilerThreadCanCallJava canCallJava(thread, true );
30163038 JavaValue result (T_VOID);
30173039 JavaCallArguments jargs (1 );
30183040 jargs.push_int(status);
0 commit comments