On Tue, 4 Jun 2024 21:16:08 GMT, Serguei Spitsyn <sspit...@openjdk.org> wrote:

>> The empty method is removed. So test failing with '-Xcomp /C2' and exception 
>> happens after try block.
>> 
>> The log shows:
>> reply[2]: main[1] 
>> Sending command: cont
>> reply[0]: > 
>> reply[1]: Exception occurred: java.lang.NullPointerException (to be caught 
>> at: nsk.jdb.kill.kill001.MyThread.run(), line=165 
>> bci=107)"thread=MyThread-1", nsk.jdb.kill.kill001.MyThread.run(), line=164 
>> bci=100
>> reply[2]: 164                methodForException();
>> reply[3]: 
>> reply[4]: MyThread-1[1] 
>> Sending command: cont
>> reply[0]: > 
>> reply[1]: Exception occurred: nsk.jdb.kill.kill001.MyException (uncaught)
>> reply[2]: Exception occurred: nsk.jdb.kill.kill001.MyException 
>> (uncaught)"thread=MyThread-4", nsk.jdb.kill.kill001.MyThread.run(), line=178 
>> bci=187
>> reply[3]: 178            kill001a.log.display(ThreadFinished);
>> reply[4]: 
>> reply[5]: MyThread-4[1] 
>> Sending command: cont
>> reply[0]: > 
>> reply[1]: Exception occurred: com.sun.jdi.IncompatibleThreadStateException 
>> (uncaught)
>> reply[2]: Exception occurred: com.sun.jdi.IncompatibleThreadStateException 
>> (uncaught)"thread=MyThread-3", nsk.share.Log.display(), line=327 bci=9
>> reply[3]: 327                doPrint(message.toString());
>> reply[4]: 
>> reply[5]: MyThread-3[1] 
>> Sending command: cont
>> reply[0]: > Thread MyThread-1 caught expected async exception: 
>> java.lang.NullPointerException: kill001a's Exception
>> reply[1]: Thread finished: MyThread-1
>> reply[2]: 
>> reply[3]: Exception occurred: java.lang.ThreadDeath (uncaught)
>> reply[4]: Exception occurred: java.lang.ThreadDeath 
>> (uncaught)"thread=MyThread-0", nsk.share.Log.doPrint(), line=495 bci=1
>> reply[5]: 495            PrintStream stream = findOutStream();
>> reply[6]: 
>> reply[7]: MyThread-0[1] 
>> Sending command: cont
>> reply[0]: > 
>> reply[1]: Exception occurred: java.lang.SecurityException (uncaught)
>> reply[2]: Exception occurred: java.lang.SecurityException 
>> (uncaught)"thread=MyThread-2", nsk.share.Log.doPrint(), line=495 bci=1
>> reply[3]: 495            PrintStream stream = findOutStream();
>
> Empty method could work but the JIT compiler can optimize it out with 
> inlining.
> But the loop is not needed. Something like this could work:
> 
>    static public int trash;
>     void methodForException() {
>         trash = 10;
>     }
> 
> But I'm not sure if the static variable needs to be used outside of this 
> method. I'm afraid, that Escape Analysis (EA) can spoil this. I wonder if 
> `Thread.yield()`, Thread.sleep(), or something alike can be used here instead 
> of `methodForException()`.

I'm afraid it could be just inlined into try block. The public static variables 
might be read globally and should be optimized. However, really safer is jut to 
 use them explicitly.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19547#discussion_r1626732823

Reply via email to