JDK-8288651 : CDS test HelloUnload.java should not use literal string as ClassLoader name
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 20
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-06-17
  • Updated: 2022-10-04
  • Resolved: 2022-06-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17 JDK 20
17.0.6-oracleFixed 20 b04Fixed
Related Reports
Relates :  
Relates :  
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
Comments
Fix request [17u] I backport this for parity with 17.0.6-oracle. No risk, only a test change. Clean backport. SAP nightly testing passed.
29-09-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/744 Date: 2022-09-27 16:38:14 +0000
27-09-2022

Changeset: e322e77e Author: Calvin Cheung <ccheung@openjdk.org> Date: 2022-06-27 21:16:02 +0000 URL: https://git.openjdk.org/jdk/commit/e322e77e9535fc3f37b409a1c805e9f6b728377a
27-06-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/9297 Date: 2022-06-27 17:32:24 +0000
27-06-2022

Suggested fix: URLClassLoader urlClassLoader = new URLClassLoader("HelloClassLoader" + System.currentTimeMillis(), urls, null); New output: /jdk2/tmp/jtreg/work/scratch/hello_custom.jar file:/jdk2/tmp/jtreg/work/scratch/hello_custom.jar class CustomLoadee java.net.URLClassLoader@4b1210ee Refcount of symbol HelloClassLoader1655453780386 is 2 Is CustomLoadee alive? false Refcount of symbol HelloClassLoader1655453780386 is 1
17-06-2022