简体   繁体   中英

Bytecode instrumentation generating java verifier error

I am using ASM in order to do bytecode instrumentation for Java programs. What I'm doing is simple - When instrumenting a method, if the instruction is a PUTFIELD, simply do a DUP_X1 right before the instruction, then visit the PUTFIELD and inject a function call with an argument that includes the DUP'ed stack entry.

                public void visitFieldInsn(
                                int opcode,
                                String owner,  // owner of this field...
                                String name,
                                String desc) {

                    boolean did_dup = false;

                    if(opcode == Opcodes.PUTFIELD) {
                        if(!owner.equals("java/lang/System")) {
                            if (desc.startsWith("L")) {
                                mv.visitInsn(Opcodes.DUP_X1);                                       
                                did_dup = true;
                            }
                        }

                    } 

                    mv.visitFieldInsn(opcode, owner, name, desc);

                    if (did_dup) {
                        mv.visitVarInsn(Opcodes.ALOAD, 0);
                        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "com/amir/ASide", "updateG", "(Ljava/lang/Object;Ljava/lang/Object;)V");
                    }

                 }

The code looks like this BEFORE and AFTER instrumentation, respectively :

public void setA(ClassA classa)
{
    refA = classa;
    eyeColor = classa.eyeColor;
}


public void setA(ClassA classa)
{
    ASide.updateG(refA = classa, this);
    ASide.updateG(eyeColor = classa.eyeColor, this);
}

But when I run the instrumented code, I get :

java.lang.VerifyError: Expecting to find object/array on stack

Can you offer has any help on this?

There is some holes in your instrumentation. For instance, it doesn't check if you are inside static method, so this variable is present.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM