方法参数是前几个局部变量 . 要访问第一个arg,字节码助记符看起来像 aload_0 或 iload_0 或 lload_0 等,具体取决于参数's type. For arguments past the fourth, you' d说 aload 4 等 .
注意,实例方法的第一个参数是对 this 的引用 . 所以第一个参数将是本地#1,你会得到它像 aload_1 等 .
但是你'd generate bytecode with the ASM stuff... do that. It looks like you' d说出类似于 mv.visitVarInsn(ALOAD, 0); 的东西,其中 mv 是你的MethodVisitor . 0 将替换为局部变量索引 .
2 回答
考虑到方法参数类型,您可以执行以下操作:
其中
param
是方法参数编号,access
和desc
是从ClassVisitor.html#visitMethod的相应参数获得的值 .方法参数是前几个局部变量 . 要访问第一个arg,字节码助记符看起来像
aload_0
或iload_0
或lload_0
等,具体取决于参数's type. For arguments past the fourth, you' d说aload 4
等 .注意,实例方法的第一个参数是对
this
的引用 . 所以第一个参数将是本地#1,你会得到它像aload_1
等 .但是你'd generate bytecode with the ASM stuff... do that. It looks like you' d说出类似于
mv.visitVarInsn(ALOAD, 0);
的东西,其中mv
是你的MethodVisitor .0
将替换为局部变量索引 .