Commit 99aef57d authored by forax's avatar forax
Browse files

add support of BytecodeMapping for getField/putField/invoke*

parent 8e333487
......@@ -1450,9 +1450,11 @@ public class ClassReader {
String iname = readUTF8(cpIndex, c);
String idesc = readUTF8(cpIndex + 2, c);
if (opcode < Opcodes.INVOKEVIRTUAL) {
mv.visitFieldInsn(opcode, iowner, iname, idesc);
mv.visitFieldInsn(opcode, iowner, iname, idesc,
codeMappingSignature);
} else {
mv.visitMethodInsn(opcode, iowner, iname, idesc, itf);
mv.visitMethodInsn(opcode, iowner, iname, idesc,
codeMappingSignature, itf);
}
if (opcode == Opcodes.INVOKEINTERFACE) {
u += 5;
......@@ -1475,7 +1477,8 @@ public class ClassReader {
cpIndex = items[readUnsignedShort(cpIndex + 2)];
String iname = readUTF8(cpIndex, c);
String idesc = readUTF8(cpIndex + 2, c);
mv.visitInvokeDynamicInsn(iname, idesc, bsm, bsmArgs);
mv.visitInvokeDynamicInsn(iname, idesc, codeMappingSignature,
bsm, bsmArgs);
u += 5;
break;
}
......
......@@ -476,6 +476,38 @@ public abstract class MethodVisitor {
}
}
/**
* Visits a field instruction. A field instruction is an instruction that
* loads or stores the value of a field of an object.
*
* @param opcode
* the opcode of the type instruction to be visited. This opcode
* is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
* @param owner
* the internal name of the field's owner class (see
* {@link Type#getInternalName() getInternalName}).
* @param name
* the field's name.
* @param desc
* the field's descriptor (see {@link Type Type}).
* @param signature
* the unerased signature if the opcode is specializable,
* null otherwise
*/
public void visitFieldInsn(int opcode, String owner, String name,
String desc, String signature) {
if (api < Opcodes.ASM6) {
if (signature != null) {
throw new IllegalArgumentException("BytecodeMapping require ASM 6");
}
visitFieldInsn(opcode, owner, name, desc);
return;
}
if (mv != null) {
mv.visitFieldInsn(opcode, owner, name, desc, signature);
}
}
/**
* Visits a field instruction. A field instruction is an instruction that
* loads or stores the value of a field of an object.
......@@ -491,8 +523,13 @@ public abstract class MethodVisitor {
* @param desc
* the field's descriptor (see {@link Type Type}).
*/
@Deprecated
public void visitFieldInsn(int opcode, String owner, String name,
String desc) {
if (api >= Opcodes.ASM6) {
visitFieldInsn(opcode,owner, name, desc, null);
return;
}
if (mv != null) {
mv.visitFieldInsn(opcode, owner, name, desc);
}
......@@ -513,17 +550,23 @@ public abstract class MethodVisitor {
* the method's name.
* @param desc
* the method's descriptor (see {@link Type Type}).
* @param signature
* the unerased signature if the opcode is specializable,
* null otherwise
* @param itf
* if the method's owner class is an interface.
*/
@Deprecated
public void visitMethodInsn(int opcode, String owner, String name,
String desc) {
if (api >= Opcodes.ASM5) {
boolean itf = opcode == Opcodes.INVOKEINTERFACE;
String desc, String signature, boolean itf) {
if (api < Opcodes.ASM6) {
if (signature != null) {
throw new IllegalArgumentException("BytecodeMapping require ASM 6");
}
visitMethodInsn(opcode, owner, name, desc, itf);
return;
}
if (mv != null) {
mv.visitMethodInsn(opcode, owner, name, desc);
mv.visitMethodInsn(opcode, owner, name, desc, signature, itf);
}
}
......@@ -545,8 +588,13 @@ public abstract class MethodVisitor {
* @param itf
* if the method's owner class is an interface.
*/
@Deprecated
public void visitMethodInsn(int opcode, String owner, String name,
String desc, boolean itf) {
if (api >= Opcodes.ASM6) {
visitMethodInsn(opcode,owner, name, desc, null, itf);
return;
}
if (api < Opcodes.ASM5) {
if (itf != (opcode == Opcodes.INVOKEINTERFACE)) {
throw new IllegalArgumentException(
......@@ -559,6 +607,35 @@ public abstract class MethodVisitor {
mv.visitMethodInsn(opcode, owner, name, desc, itf);
}
}
/**
* Visits a method instruction. A method instruction is an instruction that
* invokes a method.
*
* @param opcode
* the opcode of the type instruction to be visited. This opcode
* is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
* INVOKEINTERFACE.
* @param owner
* the internal name of the method's owner class (see
* {@link Type#getInternalName() getInternalName}).
* @param name
* the method's name.
* @param desc
* the method's descriptor (see {@link Type Type}).
*/
@Deprecated
public void visitMethodInsn(int opcode, String owner, String name,
String desc) {
if (api >= Opcodes.ASM5) {
boolean itf = opcode == Opcodes.INVOKEINTERFACE;
visitMethodInsn(opcode, owner, name, desc, itf);
return;
}
if (mv != null) {
mv.visitMethodInsn(opcode, owner, name, desc);
}
}
/**
* Visits an invokedynamic instruction.
......@@ -567,6 +644,9 @@ public abstract class MethodVisitor {
* the method's name.
* @param desc
* the method's descriptor (see {@link Type Type}).
* @param signature
* the unerased signature if the opcode is specializable,
* null otherwise
* @param bsm
* the bootstrap method.
* @param bsmArgs
......@@ -576,8 +656,43 @@ public abstract class MethodVisitor {
* value. This method is allowed to modify the content of the
* array so a caller should expect that this array may change.
*/
public void visitInvokeDynamicInsn(String name, String desc, String signature,
Handle bsm, Object... bsmArgs) {
if (api < Opcodes.ASM6) {
if (signature != null) {
throw new IllegalArgumentException("BytecodeMapping require ASM 6");
}
visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
return;
}
if (mv != null) {
mv.visitInvokeDynamicInsn(name, desc, signature, bsm, bsmArgs);
}
}
/**
* Visits an invokedynamic instruction.
*
* @param name
* the method's name.
* @param desc
* the method's descriptor (see {@link Type Type}).
* @param bsm
* the bootstrap method.
* @param bsmArgs
* the bootstrap method constant arguments. Each argument must be
* an {@link Integer}, {@link Float}, {@link Long},
* {@link Double}, {@link String}, {@link Type} or {@link Handle}
* value. This method is allowed to modify the content of the
* array so a caller should expect that this array may change.
*/
@Deprecated
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
Object... bsmArgs) {
if (api >= Opcodes.ASM6) {
visitInvokeDynamicInsn(name, desc, null, bsm, bsmArgs);
return;
}
if (mv != null) {
mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
}
......
......@@ -870,7 +870,8 @@ final class MethodWriter extends MethodVisitor {
@Override
public void visitFieldInsn(final int opcode, final String owner,
final String name, final String desc) {
final String name, final String desc,
final String signature) {
lastCodeOffset = code.length;
Item i = cw.newFieldItem(owner, name, desc);
// Label currentBlock = this.currentBlock;
......@@ -905,11 +906,16 @@ final class MethodWriter extends MethodVisitor {
}
// adds the instruction to the bytecode of the method
code.put12(opcode, i.index);
// adds a BytecodeMapping if necessary
if (signature != null) {
addBytecodeMapping(lastCodeOffset, signature);
}
}
@Override
public void visitMethodInsn(final int opcode, final String owner,
final String name, final String desc, final boolean itf) {
final String name, final String desc, final String signature,
final boolean itf) {
lastCodeOffset = code.length;
Item i = cw.newMethodItem(owner, name, desc, itf);
int argSize = i.intVal;
......@@ -957,11 +963,15 @@ final class MethodWriter extends MethodVisitor {
} else {
code.put12(opcode, i.index);
}
// adds a BytecodeMapping if necessary
if (signature != null) {
addBytecodeMapping(lastCodeOffset, signature);
}
}
@Override
public void visitInvokeDynamicInsn(final String name, final String desc,
final Handle bsm, final Object... bsmArgs) {
final String signature, final Handle bsm, final Object... bsmArgs) {
lastCodeOffset = code.length;
Item i = cw.newInvokeDynamicItem(name, desc, bsm, bsmArgs);
int argSize = i.intVal;
......@@ -998,6 +1008,10 @@ final class MethodWriter extends MethodVisitor {
// adds the instruction to the bytecode of the method
code.put12(Opcodes.INVOKEDYNAMIC, i.index);
code.putShort(0);
// adds a BytecodeMapping if necessary
if (signature != null) {
addBytecodeMapping(lastCodeOffset, signature);
}
}
@Override
......
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