Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8309757

com/sun/jdi/ReferrersTest.java fails with virtual test thread factory



    • b02



        This test launches a debuggee, which creates 11 instances of its main class, stores them in a static array of the main class, and then the debugger side iterates over all referrers to the main class instaces. Usually this is a pretty quick process and doesn't produce much in the way of output while walking the reference tree of referrers. However, with virtual threads the tree walking and output get unwieldy, and eventually it fails with:

        IOException reading output of child java interpreter:Stream closed
        at jdk.jdi/com.sun.tools.jdi.JDWPException.toJDIException(JDWPException.java:76)
        at jdk.jdi/com.sun.tools.jdi.ThreadReferenceImpl.name(ThreadReferenceImpl.java:197)
        at jdk.jdi/com.sun.tools.jdi.ThreadReferenceImpl.toString(ThreadReferenceImpl.java:637)
        at java.base/java.lang.String.valueOf(String.java:4461)
        at ReferrersTest.showReferrers(ReferrersTest.java:438)
        at ReferrersTest.showReferrers(ReferrersTest.java:466)

        And ReferrersTest.showReferrers() has recursed about 200 levels deep. I'm not sure the order of these errors can be relied on. It looks like while walking the referrers tree, the test eventually stumbled upon a thread that had exited (but its Thread object was still alive), and this resulted in the test aborting. If I catch these exceptions, eventually the test times out while still working on referrers.

        Judging by some of the output, it appears that introducing the TestScaffold class as a referrer to the main debuggee class is the root cause of all these extra referrers.

        The test has a provision to cut off the recursion:

                // We have to stop going up a referrer chain in some cases
                Type rt = objRef.type();
                if (rt instanceof ClassType) {
                    ClassType ct = (ClassType)rt;
                    String name = ct.name();
                    if (name.equals("sun.awt.SoftCache$ValueCell")) {
                    if (name.equals("java.lang.ref.Finalizer")) {
                    if (name.equals("java.lang.ref.SoftReference")) {
                    // oh oh, should really check for a subclass of ClassLoader :-)
                    if (name.indexOf("ClassLoader") >= 0) {
                    // No doubt there are other reasons to stop ...

        Adding TestScaffold to the list makes it so the referrer tree walking output is almost identical to what it is when not using virtual threads. Adding java.lang.reflect.Method instead does a slightly better job.


          Issue Links



                cjplummer Chris Plummer
                cjplummer Chris Plummer
                0 Vote for this issue
                4 Start watching this issue