Example usage for org.objectweb.asm Label Label

List of usage examples for org.objectweb.asm Label Label

Introduction

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

Prototype

public Label() 

Source Link

Document

Constructs a new label.

Usage

From source file:com.microsoft.applicationinsights.agent.internal.agent.redis.JedisMethodVisitor.java

License:Open Source License

private void reportFinishWithArgs1(int opcode) {

    int resultIndex = this.newLocal(Type.getType(Integer.class));
    super.visitFieldInsn(GETSTATIC, ImplementationsCoordinator.internalName, "INSTANCE",
            ImplementationsCoordinator.internalNameAsJavaName);

    mv.visitLdcInsn(getMethodName());//w w w .j a  v  a 2  s . c om

    mv.visitMethodInsn(INVOKEVIRTUAL, ImplementationsCoordinator.internalName, FINISH_DETECT_METHOD_NAME,
            FINISH_METHOD_DEFAULT_SIGNATURE, false);

    mv.visitVarInsn(ISTORE, resultIndex);
    mv.visitVarInsn(ILOAD, resultIndex);
    Label ok = new Label();
    mv.visitJumpInsn(IFEQ, ok);

    int boxedArgumentsIndex = 0;
    int argumentIndex = isMethodStatic() ? 0 : 1;

    TempArrayVar arrayOfArgumentsAfterBoxing;
    arrayOfArgumentsAfterBoxing = createArray(numberOfArguments());

    // Fill the array with method parameters after boxing the primitive ones.
    for (Type argumentType : getArgumentTypes()) {
        setBoxedValueIntoArray(arrayOfArgumentsAfterBoxing, boxedArgumentsIndex, argumentType, argumentIndex);

        boxedArgumentsIndex++;
        if (ByteCodeUtils.isLargeType(argumentType)) {
            argumentIndex += 2;
        } else {
            ++argumentIndex;
        }
    }

    super.visitFieldInsn(GETSTATIC, ImplementationsCoordinator.internalName, "INSTANCE",
            ImplementationsCoordinator.internalNameAsJavaName);

    mv.visitLdcInsn(getMethodName());
    mv.visitVarInsn(Opcodes.ALOAD, arrayOfArgumentsAfterBoxing.tempVarIndex);

    mv.visitMethodInsn(INVOKEVIRTUAL, ImplementationsCoordinator.internalName, FINISH_DETECT_METHOD_NAME,
            FINISH_METHOD_DEFAULT_SIGNATURE, false);

    mv.visitLabel(ok);

    super.byteCodeForMethodExit(opcode);
}

From source file:com.microsoft.applicationinsights.agent.internal.agent.RestTemplateMethodVisitor.java

License:Open Source License

@Override
public void onMethodEnter() {
    int stringLocalIndex = this.newLocal(Type.getType(String.class));

    mv.visitVarInsn(ALOAD, 1);/*ww w  .  j  a  v  a2 s  . co m*/
    Label nullLabel = new Label();

    mv.visitJumpInsn(IFNULL, nullLabel);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/net/URI", "toString", "()Ljava/lang/String;", false);
    mv.visitVarInsn(ASTORE, stringLocalIndex);

    super.visitFieldInsn(GETSTATIC, ImplementationsCoordinator.internalName, "INSTANCE",
            ImplementationsCoordinator.internalNameAsJavaName);
    mv.visitLdcInsn(getMethodName());
    mv.visitVarInsn(ALOAD, stringLocalIndex);
    mv.visitMethodInsn(INVOKEVIRTUAL, ImplementationsCoordinator.internalName, ON_ENTER_METHOD_NAME,
            ON_ENTER_METHOD_SIGNATURE, false);

    Label notNullLabel = new Label();
    mv.visitJumpInsn(GOTO, notNullLabel);

    mv.visitLabel(nullLabel);

    super.visitFieldInsn(GETSTATIC, ImplementationsCoordinator.internalName, "INSTANCE",
            ImplementationsCoordinator.internalNameAsJavaName);
    mv.visitLdcInsn(getMethodName());
    mv.visitInsn(ACONST_NULL);

    mv.visitMethodInsn(INVOKEVIRTUAL, ImplementationsCoordinator.internalName, ON_ENTER_METHOD_NAME,
            ON_ENTER_METHOD_SIGNATURE, false);

    mv.visitLabel(notNullLabel);
}

From source file:com.microsoft.applicationinsights.agent.internal.agent.sql.PreparedStatementSetMethod.java

License:Open Source License

@Override
protected void onMethodEnter() {
    if (!"setInt".equals(methodName)) {
        return;// w  ww.ja v a  2 s  .c om
    }
    if (!"setShort".equals(methodName)) {
        return;
    }

    if (!"setBoolean".equals(methodName)) {
        return;
    }

    localIndex = this.newLocal(Type.INT_TYPE);
    tmpArrayIndex = this.newLocal(Type.getType(Object.class));

    System.out.println("index: " + methodName + " " + localIndex + " " + tmpArrayIndex);

    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;");
    Label l0 = new Label();
    mv.visitJumpInsn(IFNONNULL, l0);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitInsn(ICONST_1);
    mv.visitInsn(IADD);
    mv.visitVarInsn(ISTORE, localIndex);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ILOAD, 3);
    mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
    mv.visitFieldInsn(PUTFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;");
    Label l1 = new Label();
    mv.visitJumpInsn(GOTO, l1);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;");
    mv.visitInsn(ARRAYLENGTH);
    mv.visitVarInsn(ISTORE, localIndex);
    mv.visitVarInsn(ILOAD, localIndex);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitJumpInsn(IF_ICMPGE, l1);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;");
    mv.visitVarInsn(ASTORE, tmpArrayIndex);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");

    mv.visitFieldInsn(PUTFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;");
    mv.visitVarInsn(ALOAD, tmpArrayIndex);
    mv.visitInsn(ICONST_0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;");
    mv.visitInsn(ICONST_0);
    mv.visitVarInsn(ALOAD, tmpArrayIndex);
    mv.visitInsn(ARRAYLENGTH);
    mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "arraycopy",
            "(Ljava/lang/Object;ILjava/lang/Object;II)V", false);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);

    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;");
    mv.visitVarInsn(ILOAD, 1);

    addArgument();
    mv.visitInsn(AASTORE);
}

From source file:com.microsoft.applicationinsights.agent.internal.agent.sql.QueryStatementWithPossibleExplainMethodVisitor.java

License:Open Source License

@Override
protected void onMethodEnter() {

    mv.visitVarInsn(ALOAD, 1);/* w  w w .  j  a  va2s .  c o  m*/
    mv.visitLdcInsn("EXPLAIN");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "startsWith", "(Ljava/lang/String;)Z", false);
    Label l0 = new Label();
    mv.visitJumpInsn(IFNE, l0);

    super.visitFieldInsn(GETSTATIC, ImplementationsCoordinator.internalName, "INSTANCE",
            ImplementationsCoordinator.internalNameAsJavaName);
    mv.visitLdcInsn(getMethodName());
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, ImplementationsCoordinator.internalName, ON_ENTER_METHOD_NANE,
            ON_ENTER_METHOD_SIGNATURE, false);

    mv.visitLabel(l0);
}

From source file:com.microsoft.applicationinsights.agent.internal.agent.sql.QueryStatementWithPossibleExplainMethodVisitor.java

License:Open Source License

@Override
protected void byteCodeForMethodExit(int opcode) {
    mv.visitVarInsn(ALOAD, 1);/* ww w  . ja  va2 s .  c  o  m*/
    mv.visitLdcInsn("EXPLAIN");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "startsWith", "(Ljava/lang/String;)Z", false);
    Label l0 = new Label();
    mv.visitJumpInsn(IFNE, l0);

    super.byteCodeForMethodExit(opcode);

    mv.visitLabel(l0);
}

From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java

License:Apache License

public void addSupportMethod() {
    int access = Opcodes.ACC_PUBLIC;
    Method m = new Method("isSupport", "(I)Z");
    MethodVisitor mv = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null);

    mv.visitCode();/*from   w w w .  j  av a2 s.  co  m*/
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    //        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);

    int[] hashArray = new int[fixMtds.size()];
    Label[] labelArray = new Label[fixMtds.size()];
    Label l0 = new Label();
    Label l1 = new Label();
    for (int i = 0; i < fixMtds.size(); i++) {
        hashArray[i] = AcesoProguardMap.instance().getClassData(visitedClassName).getMtdIndex(fixMtds.get(i));
        labelArray[i] = l0;
    }

    mv.visitLookupSwitchInsn(l1, hashArray, labelArray);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitMaxs(1, 2);
    mv.visitEnd();

    mv.visitMaxs(0, 0);
    mv.visitEnd();

}

From source file:com.mogujie.instantrun.IntSwitch.java

License:Apache License

private void visitx(GeneratorAdapter mv, List<String> strings) {
    if (strings.size() == 1) {
        visitCase(strings.get(0));//from www .jav  a 2s  . c o m
        return;
    }
    for (String string : strings) {
        Label label = new Label();
        visitString();
        mv.visitLdcInsn(string);
        mv.invokeVirtual(STRING_TYPE, Method.getMethod("boolean equals(Object)"));
        mv.visitJumpInsn(Opcodes.IFEQ, label);
        visitCase(string);
        mv.visitLabel(label);
    }

    visitDefault();
}

From source file:com.mogujie.instantrun.IntSwitch.java

License:Apache License

private void visitClassifier(GeneratorAdapter mv, Set<String> strings) {
    visitInt();//from   w w w.  j a  va2  s. co m

    Multimap<Integer, String> buckets = Multimaps.index(strings, HASH_METHOD);
    List<Map.Entry<Integer, Collection<String>>> sorted = Ordering.natural()
            .onResultOf(new Function<Map.Entry<Integer, Collection<String>>, Integer>() {
                @Override
                public Integer apply(Map.Entry<Integer, Collection<String>> entry) {
                    return entry.getKey();
                }
            }).immutableSortedCopy(buckets.asMap().entrySet());

    int sortedHashes[] = new int[sorted.size()];
    List<String> sortedCases[] = new List[sorted.size()];
    int index = 0;
    for (Map.Entry<Integer, Collection<String>> entry : sorted) {
        sortedHashes[index] = entry.getKey();
        sortedCases[index] = Lists.newCopyOnWriteArrayList(entry.getValue());
        index++;
    }

    // Label for each hash and for default.
    Label labels[] = new Label[sorted.size()];
    Label defaultLabel = new Label();
    for (int i = 0; i < sorted.size(); ++i) {
        labels[i] = new Label();
    }

    // Create a switch that dispatches to each label from the hash code of
    mv.visitLookupSwitchInsn(defaultLabel, sortedHashes, labels);

    // Create the cases.
    for (int i = 0; i < sorted.size(); ++i) {
        mv.visitLabel(labels[i]);
        visitx(mv, sortedCases[i]);
    }
    mv.visitLabel(defaultLabel);
    visitDefault();
}

From source file:com.mogujie.instantrun.Redirection.java

License:Apache License

/**
 * Adds the instructions to do a generic redirection.
 *//*  ww w . j  ava 2  s. c  o  m*/
protected void redirect(GeneratorAdapter mv, int change) {
    // code to check if a new implementation of the current class is available.
    Label l0 = new Label();
    mv.loadLocal(change);
    mv.visitJumpInsn(Opcodes.IFNULL, l0);
    doRedirect(mv, change);

    // Return
    if (type == Type.VOID_TYPE) {
        mv.pop();
    } else {
        ByteCodeUtils.unbox(mv, type);
    }
    mv.returnValue();

    // jump label for classes without any new implementation, just invoke the original
    // method implementation.
    mv.visitLabel(l0);
}

From source file:com.mto.asm.helloworld.ASMCodeGenerator.java

License:Open Source License

/**
 * Generate the byte code of a simple HelloWorld program
 *
 * public class HelloWorld/*w  w w.  java 2s.c  om*/
 * {
 *    public void sayHello()
 *    {
 *       System.out.println("Hello World");
 *    }
 * }
 * @return
 */
public byte[] generateHelloWorld() {
    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;

    cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "com/mto/asm/helloworld/HelloWorld", null, "java/lang/Object", null);

    cw.visitSource("HelloWorld.java", null);

    mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(25, l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
    mv.visitInsn(RETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", "Lcom/mto/asm/helloworld/HelloWorld;", null, l0, l1, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();

    mv = cw.visitMethod(ACC_PUBLIC, "sayHello", "()V", null, null);
    mv.visitCode();
    l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(29, l0);
    mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    mv.visitLdcInsn("Hello World");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
    l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLineNumber(30, l1);
    mv.visitInsn(RETURN);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitLocalVariable("this", "Lcom/mto/asm/helloworld/HelloWorld;", null, l0, l2, 0);
    mv.visitMaxs(2, 1);
    mv.visitEnd();
    cw.visitEnd();

    return cw.toByteArray();
}