问题描述
我在应用程序中第一次使用ASM创建Java类文件.这是我正在编写的编译器的后端.
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.
我阅读了ASM文档的相关部分,并对堆栈映射框架有疑问. ASM表示,如果使用适当的标志初始化类编写器,它可以自动计算那些帧.我的问题是,这是否意味着我将永远不必亲自对访问者的方法调用visitLocalVariable()方法?我不确定该方法的作用.该文档确实说过,如果帧是自动计算的,我不需要调用visitFrame()方法,但是在visitLocalVariable()方法中它是静默的.
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.
推荐答案
visitLocalVariable()
描述或定义了存储在debug 信息. com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.13"rel =" nofollow> LocalVariableTable
和 LocalVariableTypeTable
属性.它们不是正常操作所必需的,并且不同于StackMapTable
中存储的信息.
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
.
换句话说,除非要提供调试信息,否则无论是否自动计算堆栈映射帧,都无需调用visitLocalVariable()
.
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.
请注意这些属性中存储的信息的区别. LocalVariable[Type]Table
存储本地变量的名称和[通用]类型以及它们与源级别语言有关的范围. StackMapTable
存储有关字节码验证程序的JVM类型系统的局部变量和操作数堆栈条目的类型信息.
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.
这篇关于ASM字节码工程库中MethodVisitor类的visitLocalVariable()方法有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!