Note that there are some explanatory texts on larger screens.

plurals
  1. POReloading a local variable in ASM
    primarykey
    data
    text
    <p>I am trying to retrieve the name of a class implementing a Java interface and then using this name as a key in a data structure to retrieve some code metrics about the class. Here is what I have done:</p> <pre><code>public void visitMethodInsn(int opcode, String owner, String name, String desc) { int methodOwner = _lvs.newLocal(Type.getType("Ljava/lang/String;")); if (opcode == Opcodes.INVOKEINTERFACE) { // some code to pop the operand stack and // get to the object whose method is being called // retrieving the name of the class int callingObj = _lvs.newLocal(Type.getType(Object.class)); this.visitVarInsn(Opcodes.ASTORE, callingObj); this.visitVarInsn(Opcodes.ALOAD, callingObj); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;"); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); this.visitVarInsn(Opcodes.ASTORE, methodOwner); this.visitVarInsn(Opcodes.ALOAD, callingObj); /// (1) /// some code using the methodOwner .... /// something like the following /// this.visitVarInsn(Opcodes.ALOAD, methodOwner); /// code to reconstruct the operand stack /// for the method to be invoked } super.visitMethodInsn(opcode, owner, name, desc); if (opcode == Opcodes.INVOKEINTERFACE) { /// (2) /// some more code using the methodOwner ..... /// /// this.visitVarInsn(Opcodes.ALOAD, methodOwner); } } </code></pre> <p>If I comment out code snippets in block (2) from the code above, it works. However when I try to access "methodOwner" in block (2), I receive the following verification error indicating that the string object is gone missing. I can't understand why.</p> <pre><code> org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 813: Expected an object reference, but found . </code></pre> <p>Since calling <strong>"super.visitMethodInsn(opcode, owner, name, desc);"</strong> pops the object whose interface method is called, I can't get a reference to it again. I tried keeping a second copy of the object in another variable but same problem occurs.</p> <p>I wonder if you have any clue on what is wrong here and if you can give me some advice.</p> <p>thanks very much for your help</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload