RFR: 8357910: LoaderConstraintsTest.java fails when run with TEST_THREAD_FACTORY=Virtual

David Holmes dholmes at openjdk.org
Thu May 29 07:23:53 UTC 2025


On Wed, 28 May 2025 14:42:10 GMT, Patricio Chilano Mateo <pchilanomate at openjdk.org> wrote:

> Please review this small test fix. When running LoaderConstraintsTest with `TEST_THREAD_FACTORY=Virtual` we load class `java.lang.Class` earlier than expected which causes the test to fail because of a missing loader constraint logging output. I added the full details of the issue in the JBS comments. 
> 
> The fix changes the constraint we look for to be on class `java.lang.String` between classloader `ClassUnloadCommonClassLoader` and the bootstrap classloader. This allows the test to be more robust and not depend on some hidden behavior. In fact, the only line that is currently needed for the test to pass for the platform thread case is the call to `ClassUnloadCommon.newClassLoader()`, which seems a bit obscure. Also as explained in JBS, the defining loader of `test.Empty` is currently the builtin system classloader, not `ClassUnloadCommonClassLoader` as the test would suggest.
> 
> Thanks,
> Patricio

test/hotspot/jtreg/runtime/logging/LoaderConstraintsTest.java line 53:

> 51:             ClassLoader cl = ClassUnloadCommon.newClassLoader();
> 52:             Class<?> c = cl.loadClass("test.Empty");
> 53:             // Causes class test.Emtpy to be linked, which triggers the

Suggestion:

            // Causes class test.Empty to be linked, which triggers the

test/hotspot/jtreg/runtime/logging/LoaderConstraintsTest.java line 66:

> 64:         Collections.addAll(argsList, args);
> 65:         Collections.addAll(argsList, "-Xmn8m");
> 66:         Collections.addAll(argsList, "-Xbootclasspath/a:.");

Without use of `WhiteBox`, you don't need this. And this is probably what caused the class to be loaded by the boot-loader instead of the custom loader as expected. But the use of WB is needed by `ClassUnloadCommon` and these instructions are present to ensure it works - as added by JDK-8289184.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25496#discussion_r2113360652
PR Review Comment: https://git.openjdk.org/jdk/pull/25496#discussion_r2113363958


More information about the hotspot-runtime-dev mailing list