Checking for 'Stack size mismatch'

- liangchenblue at gmail.com
Sat Mar 9 18:38:01 UTC 2024


Hi Øystein,
ClassFile API does not always ensure the created bytecode is valid, and
allowing creation of code with invalid stack size is a feature instead of a
bug. A stack size mismatch problem, in essence, is closer to the error
which a user forgot to call a builder method. And putting this check
earlier doesn't really help, as this error can only be detected at run
time. You can always use ClassFile.verify to verify your generated class
files.

In addition, CodeBuilder supports chaining; if we add the size checking in
each item of the chain, it will introduce a performance penalty.

Chen

On Sat, Mar 9, 2024 at 8:42 AM Øystein Myhre Andersen <o.myhre at gmail.com>
wrote:

> Checking for 'Stack size mismatch' is currently done in 'java.base/jdk.internal.classfile.impl.StackMapGenerator'.
> It would have been nice if this was tested earlier by Codebuilder when the instructions was created.
>
> For example, by keeping track of the stack size curing code building.
>
> It is good programming practice to catch errors as early as possible.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20240309/0b94aa76/attachment.htm>


More information about the classfile-api-dev mailing list