下面列出了org.objectweb.asm.Opcodes# LCONST_1 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Determine if the given opcode is a load of a constant (xCONST_y).
*
* @param opcode the opcode
* @return true if the opcode is one of the constant loading ones, false otherwise
*/
public static boolean isXconst(final int opcode) {
switch(opcode) {
case Opcodes.ICONST_0:
case Opcodes.ICONST_1:
case Opcodes.ICONST_2:
case Opcodes.ICONST_3:
case Opcodes.ICONST_4:
case Opcodes.ICONST_5:
case Opcodes.ICONST_M1:
case Opcodes.DCONST_0:
case Opcodes.DCONST_1:
case Opcodes.FCONST_0:
case Opcodes.FCONST_1:
case Opcodes.LCONST_0:
case Opcodes.LCONST_1:
return true;
}
return false;
}
@Override
public boolean isConstant() {
switch (opcode) {
case Opcodes.ACONST_NULL:
case Opcodes.ICONST_0:
case Opcodes.ICONST_1:
case Opcodes.ICONST_2:
case Opcodes.ICONST_3:
case Opcodes.ICONST_4:
case Opcodes.ICONST_5:
case Opcodes.ICONST_M1:
case Opcodes.FCONST_0:
case Opcodes.FCONST_1:
case Opcodes.FCONST_2:
case Opcodes.DCONST_0:
case Opcodes.DCONST_1:
case Opcodes.LCONST_0:
case Opcodes.LCONST_1:
case Opcodes.LDC:
return true;
}
return super.isConstant();
}
public static InsnValue longValue(int opcode) {
switch (opcode) {
case Opcodes.LCONST_0:
return new InsnValue(Type.LONG_TYPE, 0L);
case Opcodes.LCONST_1:
return new InsnValue(Type.LONG_TYPE, 1L);
}
return InsnValue.LONG_VALUE;
}
public static boolean isLongInsn(AbstractInsnNode insn) {
int opcode = insn.getOpcode();
return (opcode == Opcodes.LCONST_0
|| opcode == Opcodes.LCONST_1
|| (insn instanceof LdcInsnNode
&& ((LdcInsnNode) insn).cst instanceof Long));
}
public static long getLongFromInsn(AbstractInsnNode insn) {
int opcode = insn.getOpcode();
if (opcode >= Opcodes.LCONST_0 && opcode <= Opcodes.LCONST_1) {
return opcode - 9;
} else if (insn instanceof LdcInsnNode
&& ((LdcInsnNode) insn).cst instanceof Long) {
return (Long) ((LdcInsnNode) insn).cst;
}
throw new RadonException("Unexpected instruction");
}
private boolean willPush2(AbstractInsnNode ain)
{
return ain.getOpcode() == Opcodes.LCONST_0 || ain.getOpcode() == Opcodes.LCONST_1
|| ain.getOpcode() == Opcodes.DCONST_0 || ain.getOpcode() == Opcodes.DCONST_1
|| (ain.getOpcode() == Opcodes.LDC &&
(((LdcInsnNode)ain).cst instanceof Long || ((LdcInsnNode)ain).cst instanceof Double))
|| ain.getOpcode() == Opcodes.LLOAD || ain.getOpcode() == Opcodes.DLOAD;
}
public static boolean isLong(AbstractInsnNode ain)
{
if (ain == null) return false;
if(ain.getOpcode() == Opcodes.LCONST_0
|| ain.getOpcode() == Opcodes.LCONST_1)
return true;
if(ain instanceof LdcInsnNode)
{
LdcInsnNode ldc = (LdcInsnNode)ain;
if(ldc.cst instanceof Long)
return true;
}
return false;
}
public static long getLongValue(AbstractInsnNode node)
{
if(node.getOpcode() >= Opcodes.LCONST_0
&& node.getOpcode() <= Opcodes.LCONST_1)
return node.getOpcode() - 9;
if(node instanceof LdcInsnNode)
{
LdcInsnNode ldc = (LdcInsnNode)node;
if(ldc.cst instanceof Long)
return (long)ldc.cst;
}
return 0;
}
private void mutatePrimitiveLongReturn() {
if (shouldMutate("primitive long", "x + 1")) {
super.visitInsn(Opcodes.LCONST_1);
super.visitInsn(Opcodes.LADD);
super.visitInsn(Opcodes.LRETURN);
}
}
void translateToByteCode(final Long constant) {
if (constant == 0L) {
super.visitInsn(Opcodes.LCONST_0);
} else if (constant == 1L) {
super.visitInsn(Opcodes.LCONST_1);
} else {
super.visitLdcInsn(constant);
}
}
Number translateToNumber(final int opcode) {
switch (opcode) {
case Opcodes.ICONST_M1:
return Integer.valueOf(-1);
case Opcodes.ICONST_0:
return Integer.valueOf(0);
case Opcodes.ICONST_1:
return Integer.valueOf(1);
case Opcodes.ICONST_2:
return Integer.valueOf(2);
case Opcodes.ICONST_3:
return Integer.valueOf(3);
case Opcodes.ICONST_4:
return Integer.valueOf(4);
case Opcodes.ICONST_5:
return Integer.valueOf(5);
case Opcodes.LCONST_0:
return Long.valueOf(0L);
case Opcodes.LCONST_1:
return Long.valueOf(1L);
case Opcodes.FCONST_0:
return Float.valueOf(0F);
case Opcodes.FCONST_1:
return Float.valueOf(1F);
case Opcodes.FCONST_2:
return Float.valueOf(2F);
case Opcodes.DCONST_0:
return Double.valueOf(0D);
case Opcodes.DCONST_1:
return Double.valueOf(1D);
default:
return null;
}
}
private void translateToByteCode(final Long constant) {
if (constant == 0L) {
super.visitInsn(Opcodes.LCONST_0);
} else if (constant == 1L) {
super.visitInsn(Opcodes.LCONST_1);
} else {
super.visitLdcInsn(constant);
}
}
/**
* Translates the opcode to a number (inline constant) if possible or
* returns <code>null</code> if the opcode cannot be translated.
*
* @param opcode
* that might represent an inline constant.
* @return the value of the inline constant represented by opcode or
* <code>null</code> if the opcode does not represent a
* number/constant.
*/
private Number translateToNumber(final int opcode) {
switch (opcode) {
case Opcodes.ICONST_M1:
return Integer.valueOf(-1);
case Opcodes.ICONST_0:
return Integer.valueOf(0);
case Opcodes.ICONST_1:
return Integer.valueOf(1);
case Opcodes.ICONST_2:
return Integer.valueOf(2);
case Opcodes.ICONST_3:
return Integer.valueOf(3);
case Opcodes.ICONST_4:
return Integer.valueOf(4);
case Opcodes.ICONST_5:
return Integer.valueOf(5);
case Opcodes.LCONST_0:
return Long.valueOf(0L);
case Opcodes.LCONST_1:
return Long.valueOf(1L);
case Opcodes.FCONST_0:
return Float.valueOf(0F);
case Opcodes.FCONST_1:
return Float.valueOf(1F);
case Opcodes.FCONST_2:
return Float.valueOf(2F);
case Opcodes.DCONST_0:
return Double.valueOf(0D);
case Opcodes.DCONST_1:
return Double.valueOf(1D);
default:
return null;
}
}
public InsnValue createConstant(AbstractInsnNode insn) throws AnalyzerException {
switch (insn.getOpcode()) {
case Opcodes.ACONST_NULL:
return InsnValue.NULL_REFERENCE_VALUE;
case Opcodes.ICONST_M1:
case Opcodes.ICONST_0:
case Opcodes.ICONST_1:
case Opcodes.ICONST_2:
case Opcodes.ICONST_3:
case Opcodes.ICONST_4:
case Opcodes.ICONST_5:
case Opcodes.BIPUSH:
case Opcodes.SIPUSH:
return InsnValue.intValue(insn);
case Opcodes.LCONST_0:
case Opcodes.LCONST_1:
return InsnValue.longValue(insn.getOpcode());
case Opcodes.FCONST_0:
case Opcodes.FCONST_1:
case Opcodes.FCONST_2:
return InsnValue.floatValue(insn.getOpcode());
case Opcodes.DCONST_0:
case Opcodes.DCONST_1:
return InsnValue.doubleValue(insn.getOpcode());
case Opcodes.LDC:
Object obj = ((LdcInsnNode) insn).cst;
if (obj instanceof Type) {
return new InsnValue((Type) obj);
} else {
Type t = Type.getType(obj.getClass());
int sort = t.getSort();
// Non-included types:
// Type.ARRAY
// Type.VOID
// Type.METHOD
switch (sort) {
case Type.BOOLEAN:
return InsnValue.intValue((int) obj);
case Type.CHAR:
return InsnValue.charValue((char) obj);
case Type.BYTE:
return InsnValue.byteValue((byte) obj);
case Type.SHORT:
return InsnValue.shortValue((short) obj);
case Type.INT:
return InsnValue.intValue((int) obj);
case Type.FLOAT:
return InsnValue.floatValue((float) obj);
case Type.LONG:
return InsnValue.longValue((long) obj);
case Type.DOUBLE:
return InsnValue.doubleValue((double) obj);
case Type.OBJECT:
return new InsnValue(t, obj);
}
return new InsnValue(t);
}
case Opcodes.NEW:
return new InsnValue(Type.getType(((TypeInsnNode) insn).desc));
case Opcodes.JSR:
// TODO: IDK if this is right.
return InsnValue.REFERENCE_VALUE;
}
return null;
}
/**
* Returns whether a given instruction can be used to push argument of {@code type} on stack.
*/
private /* static */ boolean isPushForType(AbstractInsnNode insn, Type type) {
int opcode = insn.getOpcode();
if (opcode == type.getOpcode(Opcodes.ILOAD)) {
return true;
}
// b/62060793: AsyncAwait rewrites bytecode to convert java methods into state machine with
// support of lambdas. Constant zero values are pushed on stack for all yet uninitialized
// local variables. And SIPUSH instruction is used to advance an internal state of a state
// machine.
switch (type.getSort()) {
case Type.BOOLEAN:
return opcode == Opcodes.ICONST_0 || opcode == Opcodes.ICONST_1;
case Type.BYTE:
case Type.CHAR:
case Type.SHORT:
case Type.INT:
return opcode == Opcodes.SIPUSH
|| opcode == Opcodes.ICONST_0
|| opcode == Opcodes.ICONST_1
|| opcode == Opcodes.ICONST_2
|| opcode == Opcodes.ICONST_3
|| opcode == Opcodes.ICONST_4
|| opcode == Opcodes.ICONST_5
|| opcode == Opcodes.ICONST_M1;
case Type.LONG:
return opcode == Opcodes.LCONST_0 || opcode == Opcodes.LCONST_1;
case Type.FLOAT:
return opcode == Opcodes.FCONST_0
|| opcode == Opcodes.FCONST_1
|| opcode == Opcodes.FCONST_2;
case Type.DOUBLE:
return opcode == Opcodes.DCONST_0 || opcode == Opcodes.DCONST_1;
case Type.OBJECT:
case Type.ARRAY:
return opcode == Opcodes.ACONST_NULL;
default:
// Support for BIPUSH and LDC* opcodes is not implemented as there is no known use case.
return false;
}
}