List of usage examples for org.objectweb.asm Opcodes ICONST_0
int ICONST_0
To view the source code for org.objectweb.asm Opcodes ICONST_0.
Click Source Link
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:// w w w . jav a 2 s . c om 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.gradle.model.internal.manage.schema.extract.ManagedProxyClassGenerator.java
License:Apache License
private void writeConfigureMethod(ClassVisitor visitor, Type generatedType, ModelProperty<?> property, boolean writable) { if (!writable && property.getSchema() instanceof CompositeSchema) { // Adds a void $propName(Closure<?> cl) method that delegates to model state MethodVisitor methodVisitor = declareMethod(visitor, property.getName(), Type.getMethodDescriptor(Type.VOID_TYPE, CLOSURE_TYPE), null); putNodeStateFieldValueOnStack(methodVisitor, generatedType); putConstantOnStack(methodVisitor, property.getName()); putFirstMethodArgumentOnStack(methodVisitor); methodVisitor.visitMethodInsn(INVOKEINTERFACE, MODEL_ELEMENT_STATE_TYPE_INTERNAL_NAME, "apply", STATE_APPLY_METHOD_DESCRIPTOR, true); finishVisitingMethod(methodVisitor); return;//w w w. jav a2 s . c om } if (!writable && property.getSchema() instanceof UnmanagedImplStructSchema) { UnmanagedImplStructSchema<?> structSchema = (UnmanagedImplStructSchema<?>) property.getSchema(); if (!structSchema.isAnnotated()) { return; } // Adds a void $propName(Closure<?> cl) method that executes the closure MethodVisitor methodVisitor = declareMethod(visitor, property.getName(), Type.getMethodDescriptor(Type.VOID_TYPE, CLOSURE_TYPE), null); putThisOnStack(methodVisitor); methodVisitor.visitMethodInsn(INVOKEVIRTUAL, generatedType.getInternalName(), property.getGetter().getName(), Type.getMethodDescriptor(Type.getType(property.getType().getConcreteClass())), false); putFirstMethodArgumentOnStack(methodVisitor); methodVisitor.visitMethodInsn(INVOKESTATIC, Type.getInternalName(ClosureBackedAction.class), "execute", Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE, CLOSURE_TYPE), false); finishVisitingMethod(methodVisitor); return; } // Adds a void $propName(Closure<?> cl) method that throws MME, to avoid attempts to convert closure to something else MethodVisitor methodVisitor = declareMethod(visitor, property.getName(), Type.getMethodDescriptor(Type.VOID_TYPE, CLOSURE_TYPE), null); putThisOnStack(methodVisitor); putConstantOnStack(methodVisitor, property.getName()); methodVisitor.visitInsn(Opcodes.ICONST_1); methodVisitor.visitTypeInsn(Opcodes.ANEWARRAY, OBJECT_TYPE.getInternalName()); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_0); putFirstMethodArgumentOnStack(methodVisitor); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitMethodInsn(INVOKEVIRTUAL, generatedType.getInternalName(), "methodMissing", METHOD_MISSING_METHOD_DESCRIPTOR, false); finishVisitingMethod(methodVisitor); }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
private void handleNumberOperator(ASTNode node, Operator op, Type type) throws ASTVisitorException { if (op.equals(Operator.PLUS)) { // FIXME: IADD or DADD, etc. // use type.getOpcode(Opcodes.IADD) to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IADD))); } else if (op.equals(Operator.MINUS)) { // FIXME: ISUB or DSUB, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.ISUB))); } else if (op.equals(Operator.MULTIPLY)) { // FIXME: IMUL or DMUL, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IMUL))); } else if (op.equals(Operator.DIVISION)) { // FIXME: IDIV or DDIV, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IDIV))); } else if (op.isRelational()) { if (type.equals(Type.DOUBLE_TYPE)) { mn.instructions.add(new InsnNode(Opcodes.DCMPG)); JumpInsnNode jmp = null;/*from ww w . j a v a 2s.c o m*/ switch (op) { case EQUAL: jmp = new JumpInsnNode(Opcodes.IFEQ, null); mn.instructions.add(jmp); break; case NOT_EQUAL: jmp = new JumpInsnNode(Opcodes.IFNE, null); mn.instructions.add(jmp); break; case GREATER: jmp = new JumpInsnNode(Opcodes.IFGT, null); mn.instructions.add(jmp); break; case GREATER_EQUAL: jmp = new JumpInsnNode(Opcodes.IFGE, null); mn.instructions.add(jmp); break; case LESS: jmp = new JumpInsnNode(Opcodes.IFLT, null); mn.instructions.add(jmp); break; case LESS_EQUAL: jmp = new JumpInsnNode(Opcodes.IFLE, null); mn.instructions.add(jmp); break; default: ASTUtils.error(node, "Operator not supported"); break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); LabelNode trueLabelNode = new LabelNode(); jmp.label = trueLabelNode; mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else if (type.equals(Type.INT_TYPE)) { LabelNode trueLabelNode = new LabelNode(); switch (op) { case EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPEQ, trueLabelNode)); break; case NOT_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPNE, trueLabelNode)); break; case GREATER: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGT, trueLabelNode)); break; case GREATER_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGE, trueLabelNode)); break; case LESS: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLT, trueLabelNode)); break; case LESS_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLE, trueLabelNode)); break; default: break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else { ASTUtils.error(node, "Cannot compare such types."); } } else { ASTUtils.error(node, "Operator not recognized."); } }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
/** * Assumes top of stack contains two strings *//* w w w . ja v a 2 s .com*/ private void handleStringOperator(ASTNode node, Operator op) throws ASTVisitorException { if (op.equals(Operator.PLUS)) { mn.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/lang/StringBuilder")); mn.instructions.add(new InsnNode(Opcodes.DUP)); mn.instructions.add( new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false)); mn.instructions.add(new InsnNode(Opcodes.SWAP)); mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false)); mn.instructions.add(new InsnNode(Opcodes.SWAP)); mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false)); mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false)); } else if (op.isRelational()) { LabelNode trueLabelNode = new LabelNode(); switch (op) { case EQUAL: mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false)); mn.instructions.add(new JumpInsnNode(Opcodes.IFNE, trueLabelNode)); break; case NOT_EQUAL: mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false)); mn.instructions.add(new JumpInsnNode(Opcodes.IFEQ, trueLabelNode)); break; default: ASTUtils.error(node, "Operator not supported on strings"); break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else { ASTUtils.error(node, "Operator not recognized"); } }
From source file:org.jacoco.core.instr.ResizeInstructionsTest.java
License:Open Source License
/** * Adds code that triggers usage of//from ww w .j a v a 2 s . co m * {@link org.objectweb.asm.MethodWriter#COMPUTE_INSERTED_FRAMES} during * instrumentation. */ private static void addCauseOfResizeInstructions(final MethodVisitor mv) { mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.ICONST_1); final Label target = new Label(); mv.visitJumpInsn(Opcodes.IFLE, target); for (int i = 0; i < Short.MAX_VALUE; i++) { mv.visitInsn(Opcodes.NOP); } mv.visitLabel(target); }
From source file:org.jacoco.core.internal.analysis.AC_MethodAnalyzerTest.java
License:Open Source License
private void createLoop() { final Label l0 = new Label(); method.visitLabel(l0);/* w w w .jav a 2 s . c o m*/ method.visitLineNumber(1001, l0); method.visitInsn(Opcodes.ICONST_0); method.visitVarInsn(Opcodes.ISTORE, 1); final Label l1 = new Label(); method.visitLabel(l1); method.visitLineNumber(1002, l1); method.visitVarInsn(Opcodes.ILOAD, 1); method.visitInsn(Opcodes.ICONST_5); final Label l2 = new Label(); method.visitJumpInsn(Opcodes.IF_ICMPGE, l2); method.visitIincInsn(1, 1); method.visitJumpInsn(Opcodes.GOTO, l1); method.visitLabel(l2); method.visitLineNumber(1003, l2); method.visitInsn(Opcodes.RETURN); }
From source file:org.jacoco.core.internal.analysis.filter.AnnotationGeneratedFilterTest.java
License:Open Source License
@Test public void should_filter_methods_annotated_with_runtime_visible_org_groovy_transform_Generated() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null); m.visitAnnotation("Lgroovy/transform/Generated;", true); m.visitInsn(Opcodes.ICONST_0); m.visitInsn(Opcodes.IRETURN);//from www. j av a 2 s .co m filter.filter(m, context, output); assertMethodIgnored(m); }
From source file:org.jacoco.core.internal.analysis.filter.AnnotationGeneratedFilterTest.java
License:Open Source License
@Test public void should_filter_methods_annotated_with_runtime_invisible_lombok_Generated() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null); m.visitAnnotation("Llombok/Generated;", false); m.visitInsn(Opcodes.ICONST_0); m.visitInsn(Opcodes.IRETURN);// w w w.j a v a2 s . c om filter.filter(m, context, output); assertMethodIgnored(m); }
From source file:org.jacoco.core.internal.analysis.filter.AnnotationGeneratedFilterTest.java
License:Open Source License
@Test public void should_filter_classes_annotated_with_runtime_visible_org_immutables_value_Generated() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null); m.visitInsn(Opcodes.ICONST_0); m.visitInsn(Opcodes.IRETURN);// ww w. j av a 2 s. c om context.classAnnotations.add("Lorg/immutables/value/Generated;"); filter.filter(m, context, output); assertMethodIgnored(m); }
From source file:org.jacoco.core.internal.analysis.filter.AnnotationGeneratedFilterTest.java
License:Open Source License
@Test public void should_filter_when_annotation_is_inner() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null); m.visitInsn(Opcodes.ICONST_0); m.visitInsn(Opcodes.IRETURN);/* w ww. j a v a 2 s .c om*/ context.classAnnotations.add("Lorg/example/Class$Generated;"); filter.filter(m, context, output); assertMethodIgnored(m); }