What does the visitLocalVariable() method of the MethodVisitor class in the ASM bytecode engineering library do?

心已入冬 提交于 2021-02-09 05:38:23

问题


I am using ASM (for the first time) in an application to create Java class files. This is for the backend of a compiler I am writing.

I read the relevant parts of the ASM documentation and have a question about stack map frames. ASM says it can automatically compute those frames if the class writer is initialized with the appropriate flags. My question is, does that mean I will not ever have to call the visitLocalVariable() method on the method visitors myself? I am not sure what that method does. The documentation does say that I do not need to call the visitFrame() method if frames are computed automatically, but it is silent on the visitLocalVariable() method.


回答1:


visitLocalVariable() describes or defines the debug information as stored in the LocalVariableTable and LocalVariableTypeTable attributes of a Code attribute. They are not required for normal operation and distinct from the information stored in a StackMapTable.

In other words, unless you want to provide debug information, you never need to call visitLocalVariable(), regardless of whether stack map frames are automatically computed or not.


Note the differences of the information stored within these attributes. LocalVariable[Type]Table stores names and [generic] types of local variables and their scope regarding the source level language. StackMapTable stores type information for local variables and operand stack entries regarding the JVM type system for the byte code verifier.



来源:https://stackoverflow.com/questions/28633731/what-does-the-visitlocalvariable-method-of-the-methodvisitor-class-in-the-asm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!