Crash with -Djava.lang.Continuation.trace

Ron Pressler ron.pressler at oracle.com
Mon Jun 29 22:29:37 UTC 2020


Yeah, that’s right. The code is there for some internal debugging and will
be removed. When we use it, we comment out whatever printlns give us 
trouble; If you’d like to play with it, do the same.

— Ron


On 29 June 2020 at 23:14:02, Johannes Kuhn (info at j-kuhn.de) wrote:

I just tried out the Loom EA build on windows, and found  
-Djava.lang.Continuation.trace, which I did enable to better understand  
the inner workings.  

Unfortunately, this lead to a crash of the VM with the following code:  

    public class LoomBug {  

        BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(1);  

        public static void main(String[] args) throws  
InterruptedException {  
            var hello = new LoomBug();  
            var c =  
Thread.builder().virtual().name("consumer").task(hello::consumer).start();  
            var p =  
Thread.builder().virtual().name("producer").task(hello::producer).start();  
            p.join();  
            c.join();  
        }  

        public void producer() {  
            try {  
                for (int i = 0; i < 10; i++) {  
                    System.out.println("Producing " + i);  
                    queue.put(i);  
                    System.out.println("Produced " + i);  
                }  
                queue.put(-1);  
            } catch (InterruptedException e) {  
                Thread.currentThread().interrupt();  
            }  
        }  

        public void consumer() {  
            while (true) {  
                try {  
                    int val = queue.take();  
                    if (val < 0) {  
                        break;  
                    }  
                    System.out.println("Consuming " + val);  
                } catch (InterruptedException e) {  
                    Thread.currentThread().interrupt();  
                    break;  
                }  
            }  
        }  
    }  

And this output:  

Exception in thread "ForkJoinPool-1-worker-5"  
java.lang.IllegalStateException: Not in scope VirtualThreads  
    at java.base/java.lang.Continuation.yield(Continuation.java:428)  
    at java.base/java.lang.VirtualThread.tryPark(VirtualThread.java:470)  
    at java.base/java.lang.VirtualThread.park(VirtualThread.java:418)  
    at java.base/java.lang.System$2.parkVirtualThread(System.java:2322)  

++++++++++++++++++++++++++++++  
    at  
java.base/jdk.internal.misc.VirtualThreads.park(VirtualThreads.java:56)  
    at  
java.base/java.util.concurrent.locks.LockSupport.park(LockSupport.java:220)  
    at  
java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:714)  
    at  
java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:937)  
    at  
java.base/java.util.concurrent.locks.ReentrantLock$Sync.lock(ReentrantLock.java:153)  
    at  
java.base/java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:322)  
    at java.base/java.io.PrintStream.writeln(PrintStream.java:828)  
    at java.base/java.io.PrintStream.println(PrintStream.java:1163)  
    at java.base/java.lang.Continuation.run(Continuation.java:305)  
    at  
java.base/java.lang.VirtualThread.runContinuation(VirtualThread.java:211)  
    at  
java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1429)  
    at  
java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)  
    at  
java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1018)  

++++++++++++++++++++++++++++++  
    at  
java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1667)  
    at  
java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1600)  
    at  
java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:189)  
ENTERING 4fc4b48f [19]  
java.lang.VirtualThread$1 at 47fb4b70 scope: VirtualThreads yielding on  
scope VirtualThreads. child: null  
java.lang.VirtualThread$1 at 4fc4b48f scope: VirtualThreads yielding on  
scope VirtualThreads. child: null  
#  
[thread 18516 also had an error]  
# A fatal error has been detected by the Java Runtime Environment:  
#  
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffea7468191,  
pid=6244, tid=9080  
#  
# JRE version: OpenJDK Runtime Environment (16.0+2) (build 16-loom+2-14)  
# Java VM: OpenJDK 64-Bit Server VM (16-loom+2-14, mixed mode, sharing,  
tiered, compressed oops, g1 gc, windows-amd64)  
# Problematic frame:  
# V  [jvm.dll+0x218191]  
#  
# No core dump will be written. Minidumps are not enabled by default on  
client versions of Windows  
#  
# An error report file with more information is saved as:  
# C:\Users\Johannes\eclipse-workspace\loom-test\hs_err_pid6244.log  
#  
# If you would like to submit a bug report, please visit:  
#   https://bugreport.java.com/bugreport/crash.jsp  
#  

The ++++++++++++++++++++++++++++++ lines are on stdout, the rest on stderr.  

I think writing to System.err involves locks, which are not safe to use  
during transition between virtual threads and carrier.  
Let me know if you need additional information.  

- Johannes  



More information about the loom-dev mailing list