Example usage for org.objectweb.asm Opcodes NOP

List of usage examples for org.objectweb.asm Opcodes NOP

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes NOP.

Prototype

int NOP

To view the source code for org.objectweb.asm Opcodes NOP.

Click Source Link

Usage

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AsmTypeHelper.java

License:Open Source License

public static AbstractInsnNode getBoxingInstructionForType(Type type) {
    String className = getObjectType(type);
    if (className == null)
        return new InsnNode(Opcodes.NOP);

    String desc = Type.getMethodDescriptor(Type.getObjectType(className), new Type[] { type });
    return new MethodInsnNode(Opcodes.INVOKESTATIC, className, "valueOf", desc, false);
}

From source file:org.evosuite.graphs.cfg.BytecodeInstructionPool.java

License:Open Source License

/**
 * <p>/*from  w  w  w .  jav  a  2 s .c o m*/
 * createFakeInstruction
 * </p>
 * 
 * @param className
 *            a {@link java.lang.String} object.
 * @param methodName
 *            a {@link java.lang.String} object.
 * @return a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 */
public BytecodeInstruction createFakeInstruction(String className, String methodName) {

    AbstractInsnNode fakeNode = new InsnNode(Opcodes.NOP);

    int instructionId = getInstructionsIn(className, methodName).size();

    BytecodeInstruction instruction = new BytecodeInstruction(classLoader, className, methodName, instructionId,
            -1, fakeNode);

    registerInstruction(instruction);

    return instruction;

}

From source file:org.jacoco.core.instr.ResizeInstructionsTest.java

License:Open Source License

/**
 * Test of ASM bug/*from w ww.j ava 2 s  .  co m*/
 * <a href="https://gitlab.ow2.org/asm/asm/issues/317792">#317792</a>.
 */
@Test
public void should_not_loose_InnerClasses_attribute() throws Exception {
    byte[] source = TargetLoader.getClassDataAsBytes(Inner.class);

    final ClassReader cr = InstrSupport.classReaderFor(source);
    final ClassWriter cw = new ClassWriter(0);
    cr.accept(new ClassVisitor(InstrSupport.ASM_API_VERSION, cw) {
        @Override
        public void visitEnd() {
            final MethodVisitor mv = cv.visitMethod(0, "m", "()V", null, null);
            mv.visitCode();
            addCauseOfResizeInstructions(mv);
            mv.visitInsn(Opcodes.NOP);
            mv.visitMaxs(2, 1);
            mv.visitEnd();
            super.visitEnd();
        }
    }, 0);
    source = cw.toByteArray();

    final byte[] bytes = instrumenter.instrument(source, "");

    final TargetLoader targetLoader = new TargetLoader();
    final Class<?> outer = targetLoader.add(ResizeInstructionsTest.class,
            TargetLoader.getClassDataAsBytes(ResizeInstructionsTest.class));
    final Class<?> inner = targetLoader.add(Inner.class, bytes);
    assertSame(outer, inner.getEnclosingClass());
    assertNotNull(inner.getEnclosingClass());
    assertSame(outer, inner.getDeclaringClass());
    assertNotNull(inner.getDeclaringClass());
}

From source file:org.jacoco.core.instr.ResizeInstructionsTest.java

License:Open Source License

/**
 * Adds code that triggers usage of// ww  w  .  j a va2 s .c  om
 * {@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 createLinearSequence() {
    final Label l0 = new Label();
    method.visitLabel(l0);//from ww w.  j a  va  2 s .  c o  m
    method.visitLineNumber(1001, l0);
    method.visitInsn(Opcodes.NOP);
    final Label l1 = new Label();
    method.visitLabel(l1);
    method.visitLineNumber(1002, l1);
    method.visitInsn(Opcodes.RETURN);
}

From source file:org.jacoco.core.internal.analysis.AC_MethodAnalyzerTest.java

License:Open Source License

private void createIfBranchMerge() {
    final Label l0 = new Label();
    method.visitLabel(l0);//from ww  w.  j  a v a  2 s .c  o  m
    method.visitLineNumber(1001, l0);
    method.visitVarInsn(Opcodes.ILOAD, 1);
    Label l1 = new Label();
    method.visitJumpInsn(Opcodes.IFEQ, l1);
    final Label l2 = new Label();
    method.visitLabel(l2);
    method.visitLineNumber(1002, l2);
    method.visitInsn(Opcodes.NOP);
    method.visitLabel(l1);
    method.visitLineNumber(1003, l1);
    method.visitInsn(Opcodes.RETURN);
}

From source file:org.jacoco.core.internal.analysis.filter.AbstractMatcherTest.java

License:Open Source License

@Test
public void skipNonOpcodes() {
    m.visitFrame(Opcodes.F_FULL, 0, null, 0, null);
    final Label label = new Label();
    m.visitLabel(label);/*from w w w  .  j  a  v a 2 s.  c  o m*/
    m.visitLineNumber(42, label);
    m.visitInsn(Opcodes.NOP);

    // should skip all non opcodes
    matcher.cursor = m.instructions.getFirst();
    matcher.skipNonOpcodes();
    assertSame(m.instructions.getLast(), matcher.cursor);

    // should not change cursor when it points on instruction with opcode
    matcher.skipNonOpcodes();
    assertSame(m.instructions.getLast(), matcher.cursor);

    // should not do anything when cursor is null
    matcher.cursor = null;
    matcher.skipNonOpcodes();
}

From source file:org.jacoco.core.internal.analysis.filter.AbstractMatcherTest.java

License:Open Source License

@Test
public void nextIs() {
    m.visitInsn(Opcodes.NOP);
    m.visitInsn(Opcodes.NOP);/*from  w w w  . jav a2  s.c om*/

    // should set cursor to null when opcode mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIs(Opcodes.ATHROW);
    assertNull(matcher.cursor);

    // should set cursor to next instruction when match
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIs(Opcodes.NOP);
    assertSame(m.instructions.getLast(), matcher.cursor);

    // should not do anything when cursor is null
    matcher.cursor = null;
    matcher.nextIs(Opcodes.NOP);
}

From source file:org.jacoco.core.internal.analysis.filter.AbstractMatcherTest.java

License:Open Source License

@Test
public void nextIsSwitch() {
    // should set cursor to null when opcode mismatch
    m.visitInsn(Opcodes.NOP);
    m.visitInsn(Opcodes.NOP);/*from   w  w  w.  j a  va2s.com*/
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsSwitch();
    assertNull(matcher.cursor);

    // should set cursor to next instruction when match
    m.instructions.clear();
    m.visitInsn(Opcodes.NOP);
    m.visitTableSwitchInsn(0, 0, new Label());
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsSwitch();
    assertSame(m.instructions.getLast(), matcher.cursor);

    // should set cursor to next instruction when match
    m.instructions.clear();
    m.visitInsn(Opcodes.NOP);
    m.visitLookupSwitchInsn(new Label(), null, new Label[0]);
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsSwitch();
    assertSame(m.instructions.getLast(), matcher.cursor);

    // should not do anything when cursor is null
    matcher.cursor = null;
    matcher.nextIsSwitch();
}

From source file:org.jacoco.core.internal.analysis.filter.AbstractMatcherTest.java

License:Open Source License

@Test
public void nextIsVar() {
    m.visitInsn(Opcodes.NOP);
    m.visitVarInsn(Opcodes.ILOAD, 42);/*  ww  w.j av  a2  s.c o  m*/

    // should set cursor to null when opcode mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsVar(Opcodes.ALOAD, "name");
    assertNull(matcher.cursor);

    // should set cursor to next instruction when match
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsVar(Opcodes.ILOAD, "name");
    assertSame(m.instructions.getLast(), matcher.cursor);

    // should set cursor to null when var mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.vars.put("name", new VarInsnNode(Opcodes.ILOAD, 13));
    matcher.nextIsVar(Opcodes.ILOAD, "name");
    assertNull(matcher.cursor);

    // should set cursor to next instruction when match
    matcher.cursor = m.instructions.getFirst();
    matcher.vars.put("name", new VarInsnNode(Opcodes.ILOAD, 42));
    matcher.nextIsVar(Opcodes.ILOAD, "name");
    assertSame(m.instructions.getLast(), matcher.cursor);

    // should not do anything when cursor is null
    matcher.cursor = null;
    matcher.nextIsVar(Opcodes.ILOAD, "name");
}