Checking for 'Stack size mismatch'
-
liangchenblue at gmail.com
Sat Mar 9 21:10:38 UTC 2024
What are you trying to do? So you are writing a class and there's a stack
size error, but you don't know which method builder this stack size error
is from?
On Sat, Mar 9, 2024 at 2:04 PM Øystein Myhre Andersen <o.myhre at gmail.com>
wrote:
> You said: as this error can only be detected at run time.
> That is wrong. It occurs when building stack-map.
>
> On Sat, Mar 9, 2024 at 7:38 PM - <liangchenblue at gmail.com> wrote:
>
>> 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/e6e6b392/attachment.htm>
More information about the classfile-api-dev
mailing list