我尝试将 asm 用于 BCI,并且我有一个要求我应该注入“if 条件”,所以我尝试使用类似下面的东西
Below is the code snippet..if i comment the jump instruction things work fine..with jump instruction i see verifyerror
@Override
protected void onMethodEnter() {
try{
visitor.visitVarInsn(ALOAD, 0);
visitor.visitFieldInsn(GETFIELD, "com/vish/MyWrapper", "isCached", "Z");
Label jump = new Label();
visitor.visitJumpInsn(IFEQ,jump);
visitor.visitMethodInsn(Opcodes.INVOKESTATIC, MyConstants.TO_HELPER_CLASS, "sayHello","(Z)V");
visitor.visitVarInsn(ALOAD, 0);
visitor.visitInsn(ICONST_1);
visitFieldInsn(PUTFIELD, "com/vish/MyWrapper", "isCached", "Z");
visitor.visitLabel(jump);
visitor.visitVarInsn(ALOAD, 0);
visitor.visitFieldInsn(GETFIELD, "com/vish/MyWrapper", "isCached", "Z");
visitor.visitMethodInsn(Opcodes.INVOKESTATIC, MyConstants.TO_HELPER_CLASS, "sayHello",
"()V");
}catch(Exception e){
e.printStackTrace();
}
}
但是当我尝试运行时,出现以下异常
java.lang.VerifyError: JVMVRFY036 stack underflow; class=com/vish/MyWrapper, method=service()V, pc=10
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:72)
at java.lang.J9VMInternals.verify(J9VMInternals.java:70)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:134)
如果我评论跳转指令一切正常。
我做了一些阅读并了解到由于使用 JumpInstructions 可能会弄乱堆栈映射帧,并且还阅读了使用 COMPUTE_FRAMES 选项以及 SKIP_FRAMES 将导致堆栈映射帧的自动计算
“public static final int COMPUTE_FRAMES 标志,用于从头开始自动计算方法的堆栈映射帧。如果设置了此标志,则调用 MethodVisitor.visitFrame(int, int, java.lang.Object[], int, java. “
任何人都可以阐明我在做什么错……在跳转指令的情况下我还需要计算堆栈映射帧吗?如果是这种情况,我可以在某处获得如何计算堆栈映射帧的样本吗?
谢谢