RFR: 8364360: Defining hidden class with no room in constant pool crashes the VM [v2]
Coleen Phillimore
coleenp at openjdk.org
Mon Oct 27 12:45:14 UTC 2025
On Mon, 27 Oct 2025 04:17:27 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> Coleen Phillimore has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Test enhancement and comment.
>
> src/hotspot/share/classfile/classFileParser.cpp line 5528:
>
>> 5526: cp_size++;
>> 5527: // Check for overflow. cp_size is a u2.
>> 5528: precond(sizeof(cp_size) == sizeof(u2));
>
> Why do you need to assert this given `u2 cp_size = ...` is the declaration?
In case somebody changes it to int. There used to be talk about doing this so then the overflow check might have to be different.
> test/hotspot/jtreg/runtime/ClassFile/HiddenClassesTest.java line 44:
>
>> 42: var cw = new ClassWriter(0);
>> 43: cw.visit(V17, ACC_PUBLIC, "Hidden", null, "java/lang/Object", null);
>> 44: for (int i = 0; i < 65530; i++) {
>
> Why 65530? An empty class definition already has 12 CP entries when compiled by javac.
This is a magic number. 65536-5 gets CFE: class too large, 65536-7 doesn't get an CFE. Only 65536-6 caused the overflow. This is asm so asm may only be adding 6 entries. I kept the test as ASM rather than using ClassFile API because it might be good to backport this.
> test/hotspot/jtreg/runtime/ClassFile/HiddenClassesTest.java line 50:
>
>> 48: MethodHandles.lookup().defineHiddenClass(cw.toByteArray(), false);
>> 49: throw new RuntimeException("Test Failed: ClassFormatError expected.");
>> 50: } catch (ClassFormatError cfe) {
>
> It would be prudent to check that you get the expected CFE.
okay.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27964#discussion_r2465450393
PR Review Comment: https://git.openjdk.org/jdk/pull/27964#discussion_r2465501998
PR Review Comment: https://git.openjdk.org/jdk/pull/27964#discussion_r2465481673
More information about the hotspot-runtime-dev
mailing list