LocalVariableTableAttribute
Chen Liang
chen.l.liang at oracle.com
Mon Dec 2 20:09:38 UTC 2024
Hi Mark,
Some attributes do not extend MethodElement: this is notably the case for containers of some Class-File pseudo instructions, such as LocalVariable, LocalVariableType, and CharacterRange. You can check the sealed class hierarchy of PseudoInstruction to discover all of them.
Indeed, it seems you cannot provide LocalVariableTableAttribute to any class file builder; however, you should be able to discover it from a CodeAttribute when you do a code.findAttribute(Attributes.localVariableTable()). It is supposed to be a code-independent representation, as it has no Label references but use raw BCI instead. So LocalVariable is derived from LocalVariableTableAttribute.
The only way to construct a LocalVariableTable is to do CodeBuilder::localVariable() when you build the code, I think. Note that when you have a CodeTransform, the accept(CodeBuilder, CodeElement) may receive a LocalVariable as a CodeElement by default, and you can choose to reuse that local variable, drop it, or call the builder method to create a transformed variable.
Regards, Chen
________________________________
From: classfile-api-dev <classfile-api-dev-retn at openjdk.org> on behalf of Mark Roberts <markro at cs.washington.edu>
Sent: Monday, December 2, 2024 12:53 PM
To: classfile-api-dev <classfile-api-dev at openjdk.org>
Cc: Chen Liang <liangchenblue at gmail.com>
Subject: LocalVariableTableAttribute
First, a more general question about attributes. There are a number of these items that are not directly exposed as a MethodELement or a CodeElement. How and when do these attributes get ‘built’, i.e., copied to the output class?
The LocalVariableTable needs to be modified as part of our instrumentation. I see how to build a LocalVariableTalbeAttribute with the ‘of()’ method, but how do I replace the existing table?
Also, what is the relationship between the LocalVariableTable and the LocalVariable CodeElement? Are they duplicate information? Or perhaps one is derived from the other?
Thank you,
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20241202/78d1154d/attachment.htm>
More information about the classfile-api-dev
mailing list