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

CDS test HelloUnload.java should not use literal string as ClassLoader name

    XMLWordPrintable

Details

    • b04

    Backports

      Description

        HelloUnload.java tests refcount of the Symbol for ClassLoader::getName().

        https://github.com/openjdk/jdk/blob/f3da7ff66e83a44118c090b7729dce858f0df1b1/test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/HelloUnload.java#L101

        URLClassLoader urlClassLoader =
             new URLClassLoader("HelloClassLoader", urls, null);

        if (doUnload) {
            String loaderName = urlClassLoader.getName();
            int loadedRefcount = wb.getSymbolRefcount(loaderName);
            System.out.println("Refcount of symbol " + loaderName + " is " + loadedRefcount);

            ...

            int unloadedRefcount = wb.getSymbolRefcount(loaderName);
            System.out.println("Refcount of symbol " + loaderName + " is " + unloadedRefcount);

            // refcount of a permanent symbol will not be decremented
            if (loadedRefcount != 65535) {
                ClassUnloadCommon.failIf(unloadedRefcount != (loadedRefcount - 1), "Refcount must be decremented");
            }
        }


        This portion of the test is copied from

        https://github.com/openjdk/jdk/blob/f3da7ff66e83a44118c090b7729dce858f0df1b1/test/hotspot/jtreg/runtime/ClassUnload/UnloadTest.java#L65

        which was introduced in JDK-8210559

        However, HelloUnload is archived, so the Symbol for the literal string "HelloClassLoader" is also archived, which means it will always have a refcount of 65535

        Output:

        class CustomLoadee
        java.net.URLClassLoader@2b193f2d
        Refcount of symbol HelloClassLoader is 65535
        Is CustomLoadee alive? false
        Refcount of symbol HelloClassLoader is 65535

        Attachments

          Issue Links

            Activity

              People

                ccheung Calvin Cheung
                iklam Ioi Lam
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: