List of usage examples for org.objectweb.asm Opcodes BIPUSH
int BIPUSH
To view the source code for org.objectweb.asm Opcodes BIPUSH.
Click Source Link
From source file:org.formulacompiler.compiler.internal.bytecode.ArrayAccessorForFullDataCompiler.java
License:Open Source License
@Override protected void compileBody() throws CompilerException { final GeneratorAdapter mv = mv(); final DataType eltDataType = this.arrayNode.getDataType(); final ExpressionCompiler eltCompiler = expressionCompiler(eltDataType); final Type eltType = eltCompiler.type(); final String initName = methodName() + "$init"; final String initDesc = "Z"; // private boolean xy$init; final FieldVisitor fv = cw().visitField(Opcodes.ACC_PRIVATE, initName, initDesc, null, null); fv.visitEnd();/*from w ww.j a v a 2 s . co m*/ // if (!this.xy$init) { final Label skipInit = mv.newLabel(); mv.loadThis(); mv.visitFieldInsn(Opcodes.GETFIELD, section().classInternalName(), initName, initDesc); mv.visitJumpInsn(Opcodes.IFNE, skipInit); // this.xy$init = true; mv.loadThis(); mv.push(true); mv.visitFieldInsn(Opcodes.PUTFIELD, section().classInternalName(), initName, initDesc); // this.xy = { ?, c1, c2, ... } mv.loadThis(); section().getArrayAccessorForConstDataOnly(this.arrayNode).compileCall(mv); int i = 0; for (ExpressionNode elt : this.arrayNode.arguments()) { if (!(elt instanceof ExpressionNodeForConstantValue)) { mv.visitInsn(Opcodes.DUP); mv.visitIntInsn(Opcodes.BIPUSH, i); eltCompiler.compile(elt); mv.arrayStore(eltType); } i++; } // return this.xy; mv.visitInsn(Opcodes.ARETURN); // } else // return this.xy; mv.mark(skipInit); mv.loadThis(); section().getArrayAccessorForConstDataOnly(this.arrayNode).compileCall(mv); mv.visitInsn(Opcodes.ARETURN); if (section().hasReset()) { final GeneratorAdapter reset = section().resetter(); // this.xy$init = false; reset.loadThis(); reset.push(false); reset.visitFieldInsn(Opcodes.PUTFIELD, section().classInternalName(), initName, initDesc); } }
From source file:org.friz.bytecode.insn.InsnNodeUtility.java
License:Open Source License
/** * Creates a numeric push instruction./* w ww . j a v a 2 s. c o m*/ * @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.jacoco.core.internal.analysis.MethodAnalyzerTest.java
License:Open Source License
private void createTableSwitch() { method.visitLineNumber(1001, new Label()); method.visitVarInsn(Opcodes.ILOAD, 1); Label l1 = new Label(); Label l2 = new Label(); Label l3 = new Label(); method.visitTableSwitchInsn(1, 3, l3, new Label[] { l1, l2, l1 }); method.visitLabel(l1);//from ww w .j a v a 2 s. co m method.visitLineNumber(1002, l1); method.visitIntInsn(Opcodes.BIPUSH, 11); method.visitVarInsn(Opcodes.ISTORE, 2); method.visitLineNumber(1003, new Label()); Label l5 = new Label(); method.visitJumpInsn(Opcodes.GOTO, l5); method.visitLabel(l2); method.visitLineNumber(1004, l2); method.visitIntInsn(Opcodes.BIPUSH, 22); method.visitVarInsn(Opcodes.ISTORE, 2); method.visitLineNumber(1005, new Label()); method.visitJumpInsn(Opcodes.GOTO, l5); method.visitLabel(l3); method.visitLineNumber(1006, l3); method.visitInsn(Opcodes.ICONST_0); method.visitVarInsn(Opcodes.ISTORE, 2); method.visitLabel(l5); method.visitLineNumber(1007, l5); method.visitVarInsn(Opcodes.ILOAD, 2); method.visitInsn(Opcodes.IRETURN); }
From source file:org.jacoco.core.internal.instr.DuplicateFrameEliminatorTest.java
License:Open Source License
@Test public void testIntInsn() { testInstructionBetweenFrames(new IntInsnNode(Opcodes.BIPUSH, 123)); }
From source file:org.jacoco.core.internal.instr.FrameTracker.java
License:Open Source License
@Override public void visitIntInsn(final int opcode, final int operand) { switch (opcode) { case Opcodes.BIPUSH: case Opcodes.SIPUSH: push(Opcodes.INTEGER);//from w w w . j a v a2 s. com break; case Opcodes.NEWARRAY: pop(1); switch (operand) { case Opcodes.T_BOOLEAN: push("[Z"); break; case Opcodes.T_CHAR: push("[C"); break; case Opcodes.T_FLOAT: push("[F"); break; case Opcodes.T_DOUBLE: push("[D"); break; case Opcodes.T_BYTE: push("[B"); break; case Opcodes.T_SHORT: push("[S"); break; case Opcodes.T_INT: push("[I"); break; case Opcodes.T_LONG: push("[J"); break; default: throw new IllegalArgumentException(); } break; default: throw new IllegalArgumentException(); } mv.visitIntInsn(opcode, operand); }
From source file:org.jacoco.core.runtime.OfflineInstrumentationAccessGeneratorTest.java
License:Open Source License
@Test public void testRuntimeClassName() throws Exception { generator = new OfflineInstrumentationAccessGenerator(); MethodRecorder actual = new MethodRecorder(); generator.generateDataAccessor(987654321, "foo/Bar", 17, actual.getVisitor()); MethodRecorder expected = new MethodRecorder(); expected.getVisitor().visitLdcInsn(Long.valueOf(987654321)); expected.getVisitor().visitLdcInsn("foo/Bar"); expected.getVisitor().visitIntInsn(Opcodes.BIPUSH, 17); String rtname = JaCoCo.RUNTIMEPACKAGE.replace('.', '/') + "/Offline"; expected.getVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, rtname, "getProbes", "(JLjava/lang/String;I)[Z"); assertEquals(expected, actual);/*www .j a va2 s . c om*/ }
From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java
License:Open Source License
/** * Generates the instruction to push the given value on the stack. * * @param value the value to be pushed on the stack. *///from ww w .ja v a 2 s. com public void push(final int value) { if (value >= -1 && value <= 5) { visitInsn(Opcodes.ICONST_0 + value); } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { visitIntInsn(Opcodes.BIPUSH, value); } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { visitIntInsn(Opcodes.SIPUSH, value); } else { visitLdcInsn(new Integer(value)); } }
From source file:org.kantega.notsoserial.CreateBytesIT.java
License:Apache License
private byte[] createTransletBytes() { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "com/example/InvokingTranslet", null, Type.getType(AbstractTranslet.class).getInternalName(), new String[] { Type.getType(Serializable.class).getInternalName() }); MethodVisitor init = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); init.visitCode();//from w ww . j av a 2 s. com init.visitVarInsn(Opcodes.ALOAD, 0); init.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getType(AbstractTranslet.class).getInternalName(), "<init>", "()V"); init.visitVarInsn(Opcodes.ALOAD, 0); init.visitIntInsn(Opcodes.BIPUSH, 101); init.visitFieldInsn(Opcodes.PUTFIELD, Type.getType(AbstractTranslet.class).getInternalName(), "transletVersion", "I"); init.visitInsn(Opcodes.RETURN); init.visitMaxs(2, 2); init.visitEnd(); MethodVisitor transformMethod = cw.visitMethod(Opcodes.ACC_PUBLIC, "transform", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(DOM.class), Type.getType(DTMAxisIterator.class) }), null, new String[] { Type.getType(TransletException.class).getInternalName() }); transformMethod.visitCode(); transformMethod.visitInsn(Opcodes.RETURN); transformMethod.visitEnd(); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn("HMM.."); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); mv.visitLdcInsn("pwned"); mv.visitLdcInsn("true"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"); mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(2, 0); mv.visitEnd(); cw.visitEnd(); return cw.toByteArray(); }
From source file:org.lambdamatic.analyzer.ast.LambdaExpressionReader.java
License:Open Source License
/** * Reads the given {@link IntInsnNode} instruction and adds the associated {@link Expression} to * the given {@link Stack}./* w w w . j av a2s . com*/ * * @param intInsnNode the instruction to read * @param expressionStack the expression stack to put on or pop from. * @param localVariables the local variables */ private static void readIntInstruction(final IntInsnNode intInsnNode, final Stack<Expression> expressionStack, final LocalVariables localVariables) { switch (intInsnNode.getOpcode()) { case Opcodes.BIPUSH: // expressionStack.add(LiteralFactory.getLiteral(intInsnNode.operand, // expressionStack.peek())); final Expression literal = new NumberLiteral(intInsnNode.operand); LOGGER.trace("Stacking literal {}", literal); expressionStack.add(literal); break; default: LOGGER.warn("IntInsnNode with OpCode {} was ignored.", intInsnNode.getOpcode()); } }
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:/*w w w . java 2s . c om*/ 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); }