On Tue, 7 Oct 2025 09:59:51 GMT, Alan Bateman <[email protected]> wrote:
>> Xueming Shen has refreshed the contents of this pull request, and previous
>> commits have been removed. The incremental views will show differences
>> compared to the previous content of the PR. The pull request contains one
>> new commit since the last revision:
>>
>> 8365588: defineClass that accepts a ByteBuffer does not work as expected
>
> test/jdk/java/lang/ClassLoader/defineClass/DefineClassDirectByteBuffer.java
> line 32:
>
>> 30: * @build DefineClassDirectByteBuffer
>> 31: * @run junit/othervm --add-opens java.base/java.lang=ALL-UNNAMED
>> -Dmode=Direct DefineClassDirectByteBuffer
>> 32: * @run junit/othervm --add-opens java.base/java.lang=ALL-UNNAMED
>> -Dmode=Heap DefineClassDirectByteBuffer
>
> I think it would be better to use a ParameterizedTest and a method source
> that give you a good selection of buffers (direct, view of a memory segment,
> heap, read-only, ...). No need to open java.lang as the class loader in the
> test can use super.defineClass to invoke the protected method in the super
> class.
--add-opens java.base/java.lang=ALL-UNNAMED is for the reflective access to
"defineClass" of the platform classloader. any better alternative to test the
platform classloader's defineClass behavior other than the reflect api?
Method m = ClassLoader.class.getDeclaredMethod(
"defineClass", String.class, ByteBuffer.class,
ProtectionDomain.class
);
m.setAccessible(true);
Class<?> clazz = (Class<?>) m.invoke(builtin, null, bb, null);
The dup @run lines are the workaround to test the platform classloader's
defineClass on the same target test class class twice, one for the direct bb,
one for the heap bb (with 2 separate vm runs). Otherwise the test fails with
"java.lang.LinkageError: loader 'platform' attempted duplicate class definition
for Greeting."
Does ParameterizedTest support vm/platform classloader isolation for each
parameterized test run against the same test with different parameters?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27569#discussion_r2411698488