RFR: 8364360: Defining hidden class with no room in constant pool crashes the VM

David Holmes dholmes at openjdk.org
Mon Oct 27 04:29:02 UTC 2025


On Thu, 23 Oct 2025 23:54:10 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

> Check for constant pool index overflow and throw ClassFormatError instead of crashing.
> Tested with tier1-4.

The `guarantee_property` is fine but some nits elsewhere.

Thanks

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?

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.

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.

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

Changes requested by dholmes (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/27964#pullrequestreview-3381751779
PR Review Comment: https://git.openjdk.org/jdk/pull/27964#discussion_r2464387186
PR Review Comment: https://git.openjdk.org/jdk/pull/27964#discussion_r2464392864
PR Review Comment: https://git.openjdk.org/jdk/pull/27964#discussion_r2464389558


More information about the hotspot-runtime-dev mailing list