RFR: 8341275: Explicit counter support for Code attribute building

Shaojin Wen swen at openjdk.org
Sun Apr 27 03:31:49 UTC 2025


On Sun, 27 Apr 2025 02:04:30 GMT, Chen Liang <liach at openjdk.org> wrote:

> Internal explicit counter support for Code max_stack and max_locals has been already added in #24807. Since that example works well, we may consider opening this functionality up to general users under strict restrictions.
> 
> This is an advanced API; thus, I chose a more complex name `withExplicitStackAndLocals` that discourages accidental use, and indicates the exact order of stack and locals arguments. For integrity, the argument checks are unconditional. And this is also barred behind `DROP_STACK_MAPS` advanced option.
> 
> I have enhanced the tests with a `CodeBuilderType` utility to test all types of code builders; it is already effective at increasing coverage in some of our existing tests that only cover DirectCodeBuilder, and simplify other tests. It is particularly helpful for my new `BuilderExplicitMaxsTest`.

test/jdk/jdk/classfile/BuilderExplicitMaxsTest.java line 67:

> 65:     void testValidArgs(ClassFile.StackMapsOption stackMapsOption, CodeBuilderType builderType) {
> 66:         var cc = ClassFile.of(stackMapsOption);
> 67:         var bytes = cc.build(ClassDesc.of("Foo"), builderType.asClassHandler("foo", MTD_void, 0, cob -> cob

var bytes = cc.build(
                        ClassDesc.of("Foo"), 
                        builderType.asClassHandler(
                                "foo", 
                                MTD_void, 
                                0, 
                                cob -> cob.return_()
                                          .withExplicitStackAndLocals(2, 3)));

This might be more readable.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24903#discussion_r2061984210


More information about the core-libs-dev mailing list