Commit 3769b3f0 authored by Dheeraj Yadav's avatar Dheeraj Yadav
Browse files

Add a bytecode offset field into AbstractInsnNode.

A new method is created in the MethodVisitor and MethodNode classes which sets the byteCodeOffset of the last instruction visited by that visitor. This method is called by the the ClassReader.readCode() method.
parent 72225c99
Pipeline #9000 passed with stage
in 10 minutes and 23 seconds
......@@ -91,6 +91,9 @@ public abstract class AbstractInsnNode {
/** The opcode of this instruction. */
protected int opcode;
/** The byteCodeOffset of this instruction. */
private int bytecodeOffset;
/**
* The runtime visible type annotations of this instruction. This field is only used for real
* instructions (i.e. not for labels, frames, or line number nodes). This list is a list of {@link
......@@ -126,6 +129,7 @@ public abstract class AbstractInsnNode {
protected AbstractInsnNode(final int opcode) {
this.opcode = opcode;
this.index = -1;
this.bytecodeOffset = -1;
}
/**
......@@ -262,4 +266,22 @@ public abstract class AbstractInsnNode {
}
return this;
}
/**
* Sets the byte code offset of the Instruction.
*
* @param offset . This is the offset of the instruction.
*/
public void setBytecodeOffset(final int offset) {
this.bytecodeOffset = offset;
}
/**
* Returns the bytecode offset of the instruction.
*
* @return offset.
*/
public int getBytecodeOffset() {
return this.bytecodeOffset;
}
}
......@@ -771,4 +771,11 @@ public class MethodNode extends MethodVisitor {
}
methodVisitor.visitEnd();
}
@Override
public void setByteCodeOffset(final int offset) {
if (this.instructions.size() > 0) {
this.instructions.getLast().setBytecodeOffset(offset);
}
}
}
......@@ -2066,6 +2066,9 @@ public class ClassReader {
// Visit the instruction at this bytecode offset.
int opcode = classBuffer[currentOffset] & 0xFF;
int prevOffset = currentOffset;
switch (opcode) {
case Opcodes.NOP:
case Opcodes.ACONST_NULL:
......@@ -2461,6 +2464,8 @@ public class ClassReader {
throw new AssertionError();
}
methodVisitor.setByteCodeOffset(prevOffset - bytecodeStartOffset);
// Visit the runtime visible instruction annotations, if any.
while (visibleTypeAnnotationOffsets != null
&& currentVisibleTypeAnnotationIndex < visibleTypeAnnotationOffsets.length
......
......@@ -783,4 +783,15 @@ public abstract class MethodVisitor {
mv.visitEnd();
}
}
/**
* Sets the byte code offset of last instruction visited by Method Visitor.
*
* @param offset . This is the offset of last instruction visited by Method Visitor.
*/
public void setByteCodeOffset(final int offset) {
if (mv != null) {
mv.setByteCodeOffset(offset);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment