Java Code Examples for jdk.internal.org.objectweb.asm.MethodVisitor#visitJumpInsn()

The following examples show how to use jdk.internal.org.objectweb.asm.MethodVisitor#visitJumpInsn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedefineRunningMethodsWithResolutionErrors.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void createLoadNonExistentClassCode(MethodVisitor mv, Label classExists) {
    Label tryLoadBegin = new Label();
    Label tryLoadEnd = new Label();
    Label catchLoadBlock = new Label();
    mv.visitTryCatchBlock(tryLoadBegin, tryLoadEnd, catchLoadBlock, "java/lang/NoClassDefFoundError");

    // Try to load a class that does not exist to provoke resolution errors
    mv.visitLabel(tryLoadBegin);
    mv.visitMethodInsn(INVOKESTATIC, "NonExistentClass", "nonExistentMethod", "()V");
    mv.visitLabel(tryLoadEnd);

    // No NoClassDefFoundError means NonExistentClass existed, which shouldn't happen
    mv.visitJumpInsn(GOTO, classExists);

    mv.visitFrame(F_SAME1, 0, new Object[0], 1, new Object[] { "java/lang/NoClassDefFoundError" });
    mv.visitLabel(catchLoadBlock);

    // Ignore the expected NoClassDefFoundError
    mv.visitInsn(POP);
}
 
Example 2
Source File: RedefineRunningMethodsWithResolutionErrors.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void createLoadNonExistentClassCode(MethodVisitor mv, Label classExists) {
    Label tryLoadBegin = new Label();
    Label tryLoadEnd = new Label();
    Label catchLoadBlock = new Label();
    mv.visitTryCatchBlock(tryLoadBegin, tryLoadEnd, catchLoadBlock, "java/lang/NoClassDefFoundError");

    // Try to load a class that does not exist to provoke resolution errors
    mv.visitLabel(tryLoadBegin);
    mv.visitMethodInsn(INVOKESTATIC, "NonExistentClass", "nonExistentMethod", "()V");
    mv.visitLabel(tryLoadEnd);

    // No NoClassDefFoundError means NonExistentClass existed, which shouldn't happen
    mv.visitJumpInsn(GOTO, classExists);

    mv.visitFrame(F_SAME1, 0, new Object[0], 1, new Object[] { "java/lang/NoClassDefFoundError" });
    mv.visitLabel(catchLoadBlock);

    // Ignore the expected NoClassDefFoundError
    mv.visitInsn(POP);
}
 
Example 3
Source File: RedefineRunningMethodsWithResolutionErrors.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void createLoadNonExistentClassCode(MethodVisitor mv, Label classExists) {
    Label tryLoadBegin = new Label();
    Label tryLoadEnd = new Label();
    Label catchLoadBlock = new Label();
    mv.visitTryCatchBlock(tryLoadBegin, tryLoadEnd, catchLoadBlock, "java/lang/NoClassDefFoundError");

    // Try to load a class that does not exist to provoke resolution errors
    mv.visitLabel(tryLoadBegin);
    mv.visitMethodInsn(INVOKESTATIC, "NonExistentClass", "nonExistentMethod", "()V");
    mv.visitLabel(tryLoadEnd);

    // No NoClassDefFoundError means NonExistentClass existed, which shouldn't happen
    mv.visitJumpInsn(GOTO, classExists);

    mv.visitFrame(F_SAME1, 0, new Object[0], 1, new Object[] { "java/lang/NoClassDefFoundError" });
    mv.visitLabel(catchLoadBlock);

    // Ignore the expected NoClassDefFoundError
    mv.visitInsn(POP);
}
 
Example 4
Source File: TestOSRWithNonEmptyStack.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void generateTestMethod(ClassWriter classWriter) {
    MethodVisitor mv = classWriter.visitMethod(ACC_PUBLIC,
            TestOSRWithNonEmptyStack.METHOD_NAME, "()V", null, null);
    Label osrEntryPoint = new Label();

    mv.visitCode();
    // Push 'this' into stack before OSR entry point to bail out compilation
    mv.visitVarInsn(ALOAD, 0);
    // Setup loop counter
    mv.visitInsn(ICONST_0);
    mv.visitVarInsn(ISTORE, 1);
    // Begin loop
    mv.visitLabel(osrEntryPoint);
    // Increment loop counter
    mv.visitVarInsn(ILOAD, 1);
    mv.visitInsn(ICONST_1);
    mv.visitInsn(IADD);
    // Duplicate it for loop condition check
    mv.visitInsn(DUP);
    mv.visitVarInsn(ISTORE, 1);
    // Check loop condition
    mv.visitLdcInsn(TestOSRWithNonEmptyStack.ITERATIONS);
    mv.visitJumpInsn(IF_ICMPLT, osrEntryPoint);
    // Pop 'this'.
    mv.visitInsn(POP);
    mv.visitInsn(RETURN);

    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
Example 5
Source File: TestOSRWithNonEmptyStack.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void generateTestMethod(ClassWriter classWriter) {
    MethodVisitor mv = classWriter.visitMethod(ACC_PUBLIC,
            TestOSRWithNonEmptyStack.METHOD_NAME, "()V", null, null);
    Label osrEntryPoint = new Label();

    mv.visitCode();
    // Push 'this' into stack before OSR entry point to bail out compilation
    mv.visitVarInsn(ALOAD, 0);
    // Setup loop counter
    mv.visitInsn(ICONST_0);
    mv.visitVarInsn(ISTORE, 1);
    // Begin loop
    mv.visitLabel(osrEntryPoint);
    // Increment loop counter
    mv.visitVarInsn(ILOAD, 1);
    mv.visitInsn(ICONST_1);
    mv.visitInsn(IADD);
    // Duplicate it for loop condition check
    mv.visitInsn(DUP);
    mv.visitVarInsn(ISTORE, 1);
    // Check loop condition
    mv.visitLdcInsn(TestOSRWithNonEmptyStack.ITERATIONS);
    mv.visitJumpInsn(IF_ICMPLT, osrEntryPoint);
    // Pop 'this'.
    mv.visitInsn(POP);
    mv.visitInsn(RETURN);

    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
Example 6
Source File: TestOSRWithNonEmptyStack.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void generateTestMethod(ClassWriter classWriter) {
    MethodVisitor mv = classWriter.visitMethod(ACC_PUBLIC,
            TestOSRWithNonEmptyStack.METHOD_NAME, "()V", null, null);
    Label osrEntryPoint = new Label();

    mv.visitCode();
    // Push 'this' into stack before OSR entry point to bail out compilation
    mv.visitVarInsn(ALOAD, 0);
    // Setup loop counter
    mv.visitInsn(ICONST_0);
    mv.visitVarInsn(ISTORE, 1);
    // Begin loop
    mv.visitLabel(osrEntryPoint);
    // Increment loop counter
    mv.visitVarInsn(ILOAD, 1);
    mv.visitInsn(ICONST_1);
    mv.visitInsn(IADD);
    // Duplicate it for loop condition check
    mv.visitInsn(DUP);
    mv.visitVarInsn(ISTORE, 1);
    // Check loop condition
    mv.visitLdcInsn(TestOSRWithNonEmptyStack.ITERATIONS);
    mv.visitJumpInsn(IF_ICMPLT, osrEntryPoint);
    // Pop 'this'.
    mv.visitInsn(POP);
    mv.visitInsn(RETURN);

    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
Example 7
Source File: TestOSRWithNonEmptyStack.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void generateTestMethod(ClassWriter classWriter) {
    MethodVisitor mv = classWriter.visitMethod(ACC_PUBLIC,
            TestOSRWithNonEmptyStack.METHOD_NAME, "()V", null, null);
    Label osrEntryPoint = new Label();

    mv.visitCode();
    // Push 'this' into stack before OSR entry point to bail out compilation
    mv.visitVarInsn(ALOAD, 0);
    // Setup loop counter
    mv.visitInsn(ICONST_0);
    mv.visitVarInsn(ISTORE, 1);
    // Begin loop
    mv.visitLabel(osrEntryPoint);
    // Increment loop counter
    mv.visitVarInsn(ILOAD, 1);
    mv.visitInsn(ICONST_1);
    mv.visitInsn(IADD);
    // Duplicate it for loop condition check
    mv.visitInsn(DUP);
    mv.visitVarInsn(ISTORE, 1);
    // Check loop condition
    mv.visitLdcInsn(TestOSRWithNonEmptyStack.ITERATIONS);
    mv.visitJumpInsn(IF_ICMPLT, osrEntryPoint);
    // Pop 'this'.
    mv.visitInsn(POP);
    mv.visitInsn(RETURN);

    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
Example 8
Source File: JumpInsnNode.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}
 
Example 9
Source File: JumpInsnNode.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}
 
Example 10
Source File: JumpInsnNode.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}
 
Example 11
Source File: JumpInsnNode.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}
 
Example 12
Source File: JumpInsnNode.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}
 
Example 13
Source File: InvokeDynamicPatcher.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodVisitor visitMethod(final int access, final String name,
        final String desc, final String signature,
        final String[] exceptions) {
    /* a code generate looks like
     *  0: aload_0
     *  1: ldc           #125  // int 1
     *  3: ldc2_w        #126  // long 2l
     *  6: ldc           #128  // float 3.0f
     *  8: ldc2_w        #129  // double 4.0d
     * 11: ldc           #132  // String 5
     * 13: aload_0
     * 14: getfield      #135  // Field nativeCallee:Z
     * 17: ifeq          28
     * 20: invokedynamic #181,  0            // InvokeDynamic #1:calleeNative:(Lcompiler/calls/common/InvokeDynamic;IJFDLjava/lang/String;)Z
     * 25: goto          33
     * 28: invokedynamic #183,  0            // InvokeDynamic #1:callee:(Lcompiler/calls/common/InvokeDynamic;IJFDLjava/lang/String;)Z
     * 33: ldc           #185                // String Call insuccessfull
     * 35: invokestatic  #191                // Method jdk/test/lib/Asserts.assertTrue:(ZLjava/lang/String;)V
     * 38: return
     *
     * or, using java-like pseudo-code
     * if (this.nativeCallee == false) {
     *     invokedynamic-call-return-value = invokedynamic-of-callee
     * } else {
     *     invokedynamic-call-return-value = invokedynamic-of-nativeCallee
     * }
     * Asserts.assertTrue(invokedynamic-call-return-value, error-message);
     * return;
     */
    if (name.equals(CALLER_METHOD_NAME)) {
        MethodVisitor mv = cv.visitMethod(access, name, desc,
                signature, exceptions);
        Label nonNativeLabel = new Label();
        Label checkLabel = new Label();
        MethodType mtype = MethodType.methodType(CallSite.class,
                MethodHandles.Lookup.class, String.class, MethodType.class);
        Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, CLASS,
                BOOTSTRAP_METHOD_NAME, mtype.toMethodDescriptorString());
        mv.visitCode();
        // push callee parameters onto stack
        mv.visitVarInsn(Opcodes.ALOAD, 0);//push "this"
        mv.visitLdcInsn(1);
        mv.visitLdcInsn(2L);
        mv.visitLdcInsn(3.0f);
        mv.visitLdcInsn(4.0d);
        mv.visitLdcInsn("5");
        // params loaded. let's decide what method to call
        mv.visitVarInsn(Opcodes.ALOAD, 0); // push "this"
        // get nativeCallee field
        mv.visitFieldInsn(Opcodes.GETFIELD, CLASS, CALL_NATIVE_FIELD,
                CALL_NATIVE_FIELD_DESC);
        // if nativeCallee == false goto nonNativeLabel
        mv.visitJumpInsn(Opcodes.IFEQ, nonNativeLabel);
        // invokedynamic nativeCalleeMethod using bootstrap method
        mv.visitInvokeDynamicInsn(NATIVE_CALLEE_METHOD_NAME,
                CALLEE_METHOD_DESC, bootstrap);
        // goto checkLabel
        mv.visitJumpInsn(Opcodes.GOTO, checkLabel);
        // label: nonNativeLabel
        mv.visitLabel(nonNativeLabel);
        // invokedynamic calleeMethod using bootstrap method
        mv.visitInvokeDynamicInsn(CALLEE_METHOD_NAME, CALLEE_METHOD_DESC,
                bootstrap);
        mv.visitLabel(checkLabel);
        mv.visitLdcInsn(CallsBase.CALL_ERR_MSG);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, ASSERTS_CLASS,
                ASSERTTRUE_METHOD_NAME, ASSERTTRUE_METHOD_DESC, false);
        // label: return
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
        return null;
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
}
 
Example 14
Source File: JumpInsnNode.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}
 
Example 15
Source File: JumpInsnNode.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor methodVisitor) {
    methodVisitor.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(methodVisitor);
}
 
Example 16
Source File: JumpInsnNode.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
}
 
Example 17
Source File: JumpInsnNode.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}
 
Example 18
Source File: JumpInsnNode.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}
 
Example 19
Source File: JumpInsnNode.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}
 
Example 20
Source File: JumpInsnNode.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}