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

Coleen Phillimore coleenp at openjdk.org
Tue Oct 28 13:11:44 UTC 2025


On Tue, 28 Oct 2025 12:25:57 GMT, Rémi Forax <forax at openjdk.org> wrote:

>> @liach  I have no idea how to do this, can you help?  Is see symbolTable is internal to ClassWriter and things are added in toByteArray.  I would have to add a method to ClassWriter to get the default size of an empty class.
>> 
>>         // IMPORTANT: this must be the last part of the ClassFile size computation, because the previous
>>         // statements can add attribute names to the constant pool, thereby changing its size!
>>         size += symbolTable.getConstantPoolLength();
>>         int constantPoolCount = symbolTable.getConstantPoolCount();
>>         if (constantPoolCount > 0xFFFF) {
>>             throw new ClassTooLargeException(symbolTable.getClassName(), constantPoolCount);
>>         }
>>  
>> Create an empty class, call new API to get constant pool length, then do the loop to create the overflowing class.
>
> ClassWriter.newUTF8() returns the index in the constant pool so you can use that information
> 
> 
> int maxCPIndex = cw.newUTF8(Integer.toString(-1));
> int maxEntry = 65535 - maxCPIndex - 1;

I think I figured it out.  It's sort of um interesting.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27964#discussion_r2469509255


More information about the hotspot-runtime-dev mailing list