List of usage examples for org.objectweb.asm Opcodes ICONST_4
int ICONST_4
To view the source code for org.objectweb.asm Opcodes ICONST_4.
Click Source Link
From source file:org.friz.bytecode.insn.InsnNodeUtility.java
License:Open Source License
/** * Creates a numeric push instruction./*from www. j a v a 2 s . c om*/ * @param num The number to push. * @return The instruction node. */ public static AbstractInsnNode createNumericPushInsn(Number num) { long value = num.longValue(); if (value == -1) { return new InsnNode(Opcodes.ICONST_M1); } else if (value == 0) { return new InsnNode(Opcodes.ICONST_0); } else if (value == 1) { return new InsnNode(Opcodes.ICONST_1); } else if (value == 2) { return new InsnNode(Opcodes.ICONST_2); } else if (value == 3) { return new InsnNode(Opcodes.ICONST_3); } else if (value == 4) { return new InsnNode(Opcodes.ICONST_4); } else if (value == 5) { return new InsnNode(Opcodes.ICONST_5); } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { return new IntInsnNode(Opcodes.BIPUSH, (int) value); } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { return new IntInsnNode(Opcodes.SIPUSH, (int) value); } else if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) { return new LdcInsnNode((int) value); } else { return new LdcInsnNode(/*(long)*/ value); } }
From source file:org.friz.bytecode.insn.InsnNodeUtility.java
License:Open Source License
/** * Reads the value of a numeric push instruction (which can be an * {@code ICONST_*} instruction, an {@code BIPUSH} instruction, an * {@code SIPUSH} instruction or a {@code LDC_*} instruction. * @param push The instruction node./*from w w w . j ava 2 s . co m*/ * @return The numeric value. */ public static long getNumericPushValue(AbstractInsnNode push) { if (push instanceof InsnNode) { switch (push.getOpcode()) { case Opcodes.ICONST_M1: return -1; case Opcodes.ICONST_0: return 0; case Opcodes.ICONST_1: return 1; case Opcodes.ICONST_2: return 2; case Opcodes.ICONST_3: return 3; case Opcodes.ICONST_4: return 4; case Opcodes.ICONST_5: return 5; default: throw new AssertionError(); } } else if (push instanceof IntInsnNode) { return ((IntInsnNode) push).operand; } else { return ((Number) ((LdcInsnNode) push).cst).longValue(); } }
From source file:org.glassfish.pfl.tf.spi.Util.java
License:Open Source License
public void emitIntConstant(MethodVisitor mv, int val) { info(2, "Emitting constant " + val); if (val <= 5) { switch (val) { case 0:/*from www. ja v a 2s .com*/ mv.visitInsn(Opcodes.ICONST_0); break; case 1: mv.visitInsn(Opcodes.ICONST_1); break; case 2: mv.visitInsn(Opcodes.ICONST_2); break; case 3: mv.visitInsn(Opcodes.ICONST_3); break; case 4: mv.visitInsn(Opcodes.ICONST_4); break; case 5: mv.visitInsn(Opcodes.ICONST_5); break; } } else { mv.visitLdcInsn(val); } }
From source file:org.jacoco.core.internal.instr.FrameTracker.java
License:Open Source License
@Override public void visitInsn(final int opcode) { final Object t1, t2, t3, t4; switch (opcode) { case Opcodes.NOP: case Opcodes.RETURN: break;/* ww w . j a v a 2 s . co m*/ case Opcodes.ARETURN: case Opcodes.ATHROW: case Opcodes.FRETURN: case Opcodes.IRETURN: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: case Opcodes.POP: pop(1); break; case Opcodes.DRETURN: case Opcodes.LRETURN: case Opcodes.POP2: pop(2); break; case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.FASTORE: case Opcodes.IASTORE: case Opcodes.SASTORE: pop(3); break; case Opcodes.LASTORE: case Opcodes.DASTORE: pop(4); break; 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: push(Opcodes.INTEGER); break; case Opcodes.ARRAYLENGTH: case Opcodes.F2I: case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: case Opcodes.INEG: pop(1); push(Opcodes.INTEGER); break; case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.D2I: case Opcodes.FCMPG: case Opcodes.FCMPL: case Opcodes.IADD: case Opcodes.IALOAD: case Opcodes.IAND: case Opcodes.IDIV: case Opcodes.IMUL: case Opcodes.IOR: case Opcodes.IREM: case Opcodes.ISHL: case Opcodes.ISHR: case Opcodes.ISUB: case Opcodes.IUSHR: case Opcodes.IXOR: case Opcodes.L2I: case Opcodes.SALOAD: pop(2); push(Opcodes.INTEGER); break; case Opcodes.DCMPG: case Opcodes.DCMPL: case Opcodes.LCMP: pop(4); push(Opcodes.INTEGER); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: push(Opcodes.FLOAT); break; case Opcodes.FNEG: case Opcodes.I2F: pop(1); push(Opcodes.FLOAT); break; case Opcodes.D2F: case Opcodes.FADD: case Opcodes.FALOAD: case Opcodes.FDIV: case Opcodes.FMUL: case Opcodes.FREM: case Opcodes.FSUB: case Opcodes.L2F: pop(2); push(Opcodes.FLOAT); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.F2L: case Opcodes.I2L: pop(1); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.D2L: case Opcodes.LALOAD: case Opcodes.LNEG: pop(2); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.LSHL: case Opcodes.LSHR: case Opcodes.LUSHR: pop(3); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.LADD: case Opcodes.LAND: case Opcodes.LDIV: case Opcodes.LMUL: case Opcodes.LOR: case Opcodes.LREM: case Opcodes.LSUB: case Opcodes.LXOR: pop(4); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.F2D: case Opcodes.I2D: pop(1); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.DALOAD: case Opcodes.DNEG: case Opcodes.L2D: pop(2); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.DADD: case Opcodes.DDIV: case Opcodes.DMUL: case Opcodes.DREM: case Opcodes.DSUB: pop(4); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.ACONST_NULL: push(Opcodes.NULL); break; case Opcodes.AALOAD: pop(1); t1 = pop(); push(Type.getType(((String) t1).substring(1))); break; case Opcodes.DUP: t1 = pop(); push(t1); push(t1); break; case Opcodes.DUP_X1: t1 = pop(); t2 = pop(); push(t1); push(t2); push(t1); break; case Opcodes.DUP_X2: t1 = pop(); t2 = pop(); t3 = pop(); push(t1); push(t3); push(t2); push(t1); break; case Opcodes.DUP2: t1 = pop(); t2 = pop(); push(t2); push(t1); push(t2); push(t1); break; case Opcodes.DUP2_X1: t1 = pop(); t2 = pop(); t3 = pop(); push(t2); push(t1); push(t3); push(t2); push(t1); break; case Opcodes.DUP2_X2: t1 = pop(); t2 = pop(); t3 = pop(); t4 = pop(); push(t2); push(t1); push(t4); push(t3); push(t2); push(t1); break; case Opcodes.SWAP: t1 = pop(); t2 = pop(); push(t1); push(t2); break; default: throw new IllegalArgumentException(); } mv.visitInsn(opcode); }
From source file:org.jooby.internal.apitool.BytecodeRouteParser.java
License:Apache License
private Object paramValue(final ClassLoader loader, final ClassNode owner, final MethodNode method, final AbstractInsnNode n) { if (n instanceof LdcInsnNode) { Object cst = ((LdcInsnNode) n).cst; if (cst instanceof Type) { boolean typePresent = new Insn<>(method, n).next().filter(is(MethodInsnNode.class)).findFirst() .map(MethodInsnNode.class::cast).filter(mutantToSomething().or(getOrCreateKotlinClass())) .isPresent();/*w ww .j a va 2 s.co m*/ if (typePresent) { return null; } return loadType(loader, ((Type) cst).getClassName()); } return cst; } else if (n instanceof InsnNode) { InsnNode insn = (InsnNode) n; switch (insn.getOpcode()) { case Opcodes.ICONST_0: return 0; case Opcodes.ICONST_1: return 1; case Opcodes.ICONST_2: return 2; case Opcodes.ICONST_3: return 3; case Opcodes.ICONST_4: return 4; case Opcodes.ICONST_5: return 5; case Opcodes.LCONST_0: return 0L; case Opcodes.LCONST_1: return 1L; case Opcodes.FCONST_0: return 0f; case Opcodes.FCONST_1: return 1f; case Opcodes.FCONST_2: return 2f; case Opcodes.DCONST_0: return 0d; case Opcodes.DCONST_1: return 1d; case Opcodes.ICONST_M1: return -1; case Opcodes.ACONST_NULL: return null; } } else if (n instanceof IntInsnNode) { IntInsnNode intinsn = (IntInsnNode) n; return intinsn.operand; } else if (n instanceof FieldInsnNode) { // toEnum FieldInsnNode finsn = (FieldInsnNode) n; if (finsn.getOpcode() == GETSTATIC) { java.lang.reflect.Type possibleEnum = loadType(loader, finsn.owner); if (MoreTypes.getRawType(possibleEnum).isEnum()) { return finsn.name; } } } return n; }
From source file:org.lambdamatic.analyzer.ast.LambdaExpressionReader.java
License:Open Source License
/** * Reads the current {@link InsnNode} instruction and returns a {@link Statement} or {@code null} * if the instruction is not a full statement (in that case, the instruction is stored in the * given Expression {@link Stack})./*from w w w . j av a2s . co m*/ * * @param insnNode the instruction to read * @param expressionStack the expression stack to put on or pop from. * @param localVariables the local variables * @return a {@link List} of {@link Statement} or empty list if no {@link Statement} was created * after reading the current instruction. * @see <a href="https://en.wikipedia.org/wiki/Java_bytecode_instruction_listings">Java bytcode * instruction listings on Wikipedia</a> */ private List<Statement> readInstruction(final InsnCursor insnCursor, final Stack<Expression> expressionStack, final List<CapturedArgument> capturedArguments, final LocalVariables localVariables) { final List<Statement> statements = new ArrayList<>(); final AbstractInsnNode insnNode = insnCursor.getCurrent(); switch (insnNode.getOpcode()) { // return a reference from a method case Opcodes.ARETURN: // return an integer from a method case Opcodes.IRETURN: statements.add(new ReturnStatement(expressionStack.pop())); break; // return void from method case Opcodes.RETURN: // wrap all pending expressions into ExpressionStatements while (!expressionStack.isEmpty()) { final Expression pendingExpression = expressionStack.pop(); statements.add(new ExpressionStatement(pendingExpression)); } break; // push a null reference onto the stack case Opcodes.ACONST_NULL: expressionStack.add(new NullLiteral()); break; // load the int value 0 onto the stack case Opcodes.ICONST_0: // applies for byte, short, int and boolean expressionStack.add(new NumberLiteral(0)); break; // load the int value 1 onto the stack case Opcodes.ICONST_1: // applies for byte, short, int and boolean expressionStack.add(new NumberLiteral(1)); break; // load the int value 2 onto the stack case Opcodes.ICONST_2: expressionStack.add(new NumberLiteral(2)); break; // load the int value 3 onto the stack case Opcodes.ICONST_3: expressionStack.add(new NumberLiteral(3)); break; // load the int value 4 onto the stack case Opcodes.ICONST_4: expressionStack.add(new NumberLiteral(4)); break; // load the int value 5 onto the stack case Opcodes.ICONST_5: expressionStack.add(new NumberLiteral(5)); break; // push the long 0 onto the stack case Opcodes.LCONST_0: expressionStack.add(new NumberLiteral(0L)); break; // push the long 1 onto the stack case Opcodes.LCONST_1: expressionStack.add(new NumberLiteral(1L)); break; // push the 0.0f onto the stack case Opcodes.FCONST_0: expressionStack.add(new NumberLiteral(0f)); break; // push the 1.0f onto the stack case Opcodes.FCONST_1: expressionStack.add(new NumberLiteral(1f)); break; // push the 2.0f onto the stack case Opcodes.FCONST_2: expressionStack.add(new NumberLiteral(2f)); break; // push the constant 0.0 onto the stack case Opcodes.DCONST_0: expressionStack.add(new NumberLiteral(0d)); break; // push the constant 1.0 onto the stack case Opcodes.DCONST_1: expressionStack.add(new NumberLiteral(1d)); break; // compare two longs values case Opcodes.LCMP: // compare two doubles case Opcodes.DCMPL: // compare two doubles case Opcodes.DCMPG: // compare two floats case Opcodes.FCMPL: // compare two floats case Opcodes.FCMPG: statements.addAll( readJumpInstruction(insnCursor.next(), expressionStack, capturedArguments, localVariables)); break; // add 2 ints case Opcodes.IADD: expressionStack.add(readOperation(Operator.ADD, expressionStack)); break; // int subtract case Opcodes.ISUB: expressionStack.add(readOperation(Operator.SUBTRACT, expressionStack)); break; // multiply 2 integers case Opcodes.IMUL: expressionStack.add(readOperation(Operator.MULTIPLY, expressionStack)); break; // divide 2 integers case Opcodes.IDIV: expressionStack.add(readOperation(Operator.DIVIDE, expressionStack)); break; // negate int case Opcodes.INEG: expressionStack.add(inverseInteger(expressionStack)); break; // discard the top value on the stack case Opcodes.POP: statements.add(new ExpressionStatement(expressionStack.pop())); break; // duplicate the value on top of the stack case Opcodes.DUP: expressionStack.push(expressionStack.peek()); break; // insert a copy of the top value into the stack two values from the top. case Opcodes.DUP_X1: expressionStack.add(expressionStack.size() - 2, expressionStack.peek()); break; // store into a reference in an array case Opcodes.AASTORE: readArrayStoreInstruction(insnNode, expressionStack); break; // converts Float to Double -> ignored. case Opcodes.F2D: break; default: throw new AnalyzeException( "Bytecode instruction with OpCode '" + insnNode.getOpcode() + "' is not supported."); } return statements; }
From source file:org.mbte.groovypp.compiler.asm.LdcImproverMethodAdapter.java
License:Apache License
public void visitLdcInsn(Object cst) { if (cst instanceof Integer) { Integer value = (Integer) cst; switch (value) { case -1://ww w.j a va 2 s . c o m super.visitInsn(Opcodes.ICONST_M1); break; case 0: super.visitInsn(Opcodes.ICONST_0); break; case 1: super.visitInsn(Opcodes.ICONST_1); break; case 2: super.visitInsn(Opcodes.ICONST_2); break; case 3: super.visitInsn(Opcodes.ICONST_3); break; case 4: super.visitInsn(Opcodes.ICONST_4); break; case 5: super.visitInsn(Opcodes.ICONST_5); break; default: if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { super.visitIntInsn(Opcodes.BIPUSH, value); } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { super.visitIntInsn(Opcodes.SIPUSH, value); } else { super.visitLdcInsn(Integer.valueOf(value)); } } } else if (cst instanceof BigDecimal) { super.visitTypeInsn(NEW, "java/math/BigDecimal"); super.visitInsn(DUP); super.visitLdcInsn(cst.toString()); super.visitMethodInsn(INVOKESPECIAL, "java/math/BigDecimal", "<init>", "(Ljava/lang/String;)V"); } else if (cst instanceof BigInteger) { super.visitTypeInsn(NEW, "java/math/BigInteger"); super.visitInsn(DUP); super.visitLdcInsn(cst.toString()); super.visitMethodInsn(INVOKESPECIAL, "java/math/BigInteger", "<init>", "(Ljava/lang/String;)V"); } else if (cst instanceof Double) { Double aDouble = (Double) cst; if (aDouble == 1.0d) super.visitInsn(DCONST_1); else super.visitLdcInsn(cst); } else if (cst instanceof Long) { Long aLong = (Long) cst; if (aLong == 0L) super.visitInsn(LCONST_0); else if (aLong == 1L) super.visitInsn(LCONST_1); else super.visitLdcInsn(cst); } else if (cst instanceof Float) { Float aFloat = (Float) cst; if (aFloat == 1.0f) super.visitInsn(FCONST_1); else if (aFloat == 2.0f) super.visitInsn(FCONST_2); else super.visitLdcInsn(cst); } else if (cst == null) { super.visitInsn(ACONST_NULL); } else super.visitLdcInsn(cst); }
From source file:org.mbte.groovypp.compiler.bytecode.BytecodeExpr.java
License:Apache License
public void pushConstant(int value, MethodVisitor mv) { switch (value) { case 0:/*from w ww. j a v a2 s.co m*/ mv.visitInsn(Opcodes.ICONST_0); break; case 1: mv.visitInsn(Opcodes.ICONST_1); break; case 2: mv.visitInsn(Opcodes.ICONST_2); break; case 3: mv.visitInsn(Opcodes.ICONST_3); break; case 4: mv.visitInsn(Opcodes.ICONST_4); break; case 5: mv.visitInsn(Opcodes.ICONST_5); break; default: if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { mv.visitIntInsn(Opcodes.BIPUSH, value); } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { mv.visitIntInsn(Opcodes.SIPUSH, value); } else { mv.visitLdcInsn(Integer.valueOf(value)); } } }
From source file:org.sonar.java.bytecode.se.BytecodeEGWalkerExecuteTest.java
License:Open Source License
@Test public void test_iconst() throws Exception { ProgramState programState = execute(new Instruction(Opcodes.ICONST_0)); assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.ZERO, BooleanConstraint.FALSE, ObjectConstraint.NOT_NULL } }); programState = execute(new Instruction(Opcodes.ICONST_1)); assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.NON_ZERO, BooleanConstraint.TRUE, ObjectConstraint.NOT_NULL } }); int[] opCodesConst = new int[] { Opcodes.ICONST_M1, Opcodes.ICONST_2, Opcodes.ICONST_3, Opcodes.ICONST_4, Opcodes.ICONST_5 };// ww w . ja v a 2s . c o m for (int opcode : opCodesConst) { programState = execute(new Instruction(opcode)); assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.NON_ZERO, ObjectConstraint.NOT_NULL } }); } }
From source file:org.spongepowered.despector.emitter.bytecode.instruction.BytecodeIntConstantEmitter.java
License:Open Source License
@Override public void emit(BytecodeEmitterContext ctx, IntConstant arg, TypeSignature type) { MethodVisitor mv = ctx.getMethodVisitor(); int val = arg.getConstant(); if (val == -1) { mv.visitInsn(Opcodes.ICONST_M1); } else if (val == 0) { mv.visitInsn(Opcodes.ICONST_0);// w ww. j av a 2 s. c o m } else if (val == 1) { mv.visitInsn(Opcodes.ICONST_1); } else if (val == 2) { mv.visitInsn(Opcodes.ICONST_2); } else if (val == 3) { mv.visitInsn(Opcodes.ICONST_3); } else if (val == 4) { mv.visitInsn(Opcodes.ICONST_4); } else if (val == 5) { mv.visitInsn(Opcodes.ICONST_5); } else if (val <= Byte.MAX_VALUE && val >= Byte.MIN_VALUE) { mv.visitIntInsn(Opcodes.BIPUSH, val); } else if (val <= Short.MAX_VALUE && val >= Short.MIN_VALUE) { mv.visitIntInsn(Opcodes.SIPUSH, val); } else { mv.visitLdcInsn(val); } ctx.updateStack(1); }