RFR: 8365937: post_method_exit might incorrectly set was_popped_by_exception and value in the middle of stack unwinding [v3]

Leonid Mesnik lmesnik at openjdk.org
Fri Aug 29 06:56:45 UTC 2025


On Fri, 29 Aug 2025 06:03:30 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> I am not sure what to check here. 
>> The 'exception_exit' can be true here. It means that it has been thrown in this thread and not caught yet. But this method is called after exception thrown.
>
> But we are only in this method because the Java method has completed normally so there cannot be a pending exception at this point. ???

There is might be exception if current method has been called after exception has been thrown. It is quite rare case, but I've seem when add `assert(!exception_exit, "")`. It might happens if exception thrown  and there were other upcals  in the same thread before exception has been caught. I think I've seen it during classloading or some method bootstrapping.

The test `TestMethodExitWithPendingException`  simulates the same issue by calling method in the MethodExit event call back.
For method `upCall` the `exception_exit` would be true, because the method is called while exception is pending. However, the method `upCall` exits normally and is not unwinded. So this method `post_method_exit` is called.

Here is the example of such stack in the on of the tests were assertion has been hit. The VM tries to load classes when exception is throwing.

V  [libjvm.so+0x1415d6c]  JvmtiExport::post_method_exit(JavaThread*, Method*, frame)+0x29c  (jvmtiExport.cpp:1847)
V  [libjvm.so+0x1066b86]  InterpreterRuntime::post_method_exit(JavaThread*)+0xe6  (interpreterRuntime.cpp:1278)
j  java.lang.Object.<init>()V+0 java.base at 26-internal
j  java.lang.Throwable.<init>(Ljava/lang/String;)V+1 java.base at 26-internal
j  java.lang.Error.<init>(Ljava/lang/String;)V+2 java.base at 26-internal
j  java.lang.LinkageError.<init>(Ljava/lang/String;)V+2 java.base at 26-internal
j  java.lang.NoClassDefFoundError.<init>(Ljava/lang/String;)V+2 java.base at 26-internal
v  ~StubRoutines::Stub Generator call_stub_stub 0x00007f81b7c876fd
V  [libjvm.so+0x1089117]  JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*)+0x4f7  (javaCalls.cpp:415)
V  [libjvm.so+0x108ab3f]  JavaCalls::call_special(JavaValue*, Klass*, Symbol*, Symbol*, JavaCallArguments*, JavaThread*)+0x18f  (javaCalls.cpp:323)
V  [libjvm.so+0x108b3c6]  JavaCalls::construct_new_instance(InstanceKlass*, Symbol*, JavaCallArguments*, JavaThread*)+0x116  (javaCalls.cpp:289)
V  [libjvm.so+0xd74f4b]  Exceptions::new_exception(JavaThread*, Symbol*, Symbol*, JavaCallArguments*, Handle)+0x1db  (exceptions.cpp:320)
V  [libjvm.so+0xd7517f]  Exceptions::new_exception(JavaThread*, Symbol*, Symbol*, JavaCallArguments*, Handle, Handle)+0x2f  (exceptions.cpp:341)
V  [libjvm.so+0xd7609f]  Exceptions::new_exception(JavaThread*, Symbol*, char const*, Handle, Handle, Exceptions::ExceptionMsgToUtf8Mode)+0x3bf  (exceptions.cpp:424)
V  [libjvm.so+0xd7b9a0]  Exceptions::_throw_msg_cause(JavaThread*, char const*, int, Symbol*, char const*, Handle)+0x60  (exceptions.cpp:208)
V  [libjvm.so+0x1ad397b]  handle_resolution_exception(Symbol*, bool, JavaThread*)+0x22b  (systemDictionary.cpp:313)
V  [libjvm.so+0x1adef82]  SystemDictionary::resolve_with_circularity_detection(Symbol*, Symbol*, Handle, bool, JavaThread*)+0x282  (systemDictionary.cpp:487)
V  [libjvm.so+0xa9baf2]  ClassFileParser::post_process_parsed_stream(ClassFileStream const*, ConstantPool*, JavaThread*)+0x402  (systemDictionary.hpp:118)
V  [libjvm.so+0xaa3142]  ClassFileParser::ClassFileParser(ClassFileStream*, Symbol*, ClassLoaderData*, ClassLoadInfo const*, ClassFileParser::Publicity, JavaThread*)+0x192  (classFileParser.cpp:5425)
V  [libjvm.so+0x146d4f5]  KlassFactory::create_from_stream(ClassFileStream*, Symbol*, ClassLoaderData*, ClassLoadInfo const&, JavaThread*)+0x195  (klassFactory.cpp:202)
V  [libjvm.so+0x1add90c]  SystemDictionary::resolve_class_from_stream(ClassFileStream*, Symbol*, Handle, ClassLoadInfo const&, JavaThread*)+0xfc  (systemDictionary.cpp:869)
V  [libjvm.so+0x1262042]  jvm_define_class_common(char const*, _jobject*, signed char const*, int, _jobject*, char const*, JavaThread*)+0x322  (jvm.cpp:886)
V  [libjvm.so+0x12622f5]  JVM_DefineClassWithSource+0xa5  (jvm.cpp:1053)
C  [libjava.so+0xe659]  Java_java_lang_ClassLoader_defineClass1+0x1a9  (ClassLoader.c:139)
j  java.lang.ClassLoader.defineClass1(Ljava/lang/ClassLoader;Ljava/lang/String;[BIILjava/security/ProtectionDomain;Ljava/lang/String;)Ljava/lang/Class;+0 java.base at 26-internal
j  java.lang.ClassLoader.defineClass(Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;+27 java.base at 26-internal
j  java.security.SecureClassLoader.defineClass(Ljava/lang/String;[BIILjava/security/CodeSource;)Ljava/lang/Class;+12 java.base at 26-internal
j  java.net.URLClassLoader.defineClass(Ljava/lang/String;Ljdk/internal/loader/Resource;)Ljava/lang/Class;+220 java.base at 26-internal
j  java.net.URLClassLoader.findClass(Ljava/lang/String;)Ljava/lang/Class;+30 java.base at 26-internal
j  java.lang.ClassLoader.loadClass(Ljava/lang/String;Z)Ljava/lang/Class;+69 java.base at 26-internal
j  java.lang.ClassLoader.loadClass(Ljava/lang/String;)Ljava/lang/Class;+3 java.base at 26-internal
v  ~StubRoutines::Stub Generator call_stub_stub 0x00007f81b7c876fd
V  [libjvm.so+0x1089117]  JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*)+0x4f7  (javaCalls.cpp:415)
V  [libjvm.so+0x1089873]  JavaCalls::call_virtual(JavaValue*, Klass*, Symbol*, Symbol*, JavaCallArguments*, JavaThread*)+0x313  (javaCalls.cpp:323)
V  [libjvm.so+0x1089fba]  JavaCalls::call_virtual(JavaValue*, Handle, Klass*, Symbol*, Symbol*, Handle, JavaThread*)+0xca  (javaCalls.cpp:192)
V  [libjvm.so+0x1adfa90]  SystemDictionary::load_instance_class_impl(Symbol*, Handle, JavaThread*)+0x1e0  (systemDictionary.cpp:1269)
V  [libjvm.so+0x1addb3c]  SystemDictionary::load_instance_class(Symbol*, Handle, JavaThread*)+0x1c  (systemDictionary.cpp:1300)
V  [libjvm.so+0x1ade768]  SystemDictionary::resolve_instance_class_or_null(Symbol*, Handle, JavaThread*)+0xa48  (systemDictionary.cpp:694)
V  [libjvm.so+0x1adec82]  SystemDictionary::resolve_or_fail(Symbol*, Handle, bool, JavaThread*)+0x22  (systemDictionary.cpp:332)
V  [libjvm.so+0xb9d6a5]  ConstantPool::klass_at_impl(constantPoolHandle const&, int, JavaThread*)+0x185  (constantPool.cpp:665)
V  [libjvm.so+0x106df52]  InterpreterRuntime::_new(JavaThread*, ConstantPool*, int)+0xb2  (constantPool.hpp:423)
j  TestClassResolutionFail.test1()V+0

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26886#discussion_r2309321623


More information about the hotspot-dev mailing list