当前位置: 首页>>代码示例>>Java>>正文


Java MethodVisitor.visitJumpInsn方法代码示例

本文整理汇总了Java中jdk.internal.org.objectweb.asm.MethodVisitor.visitJumpInsn方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitJumpInsn方法的具体用法?Java MethodVisitor.visitJumpInsn怎么用?Java MethodVisitor.visitJumpInsn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.internal.org.objectweb.asm.MethodVisitor的用法示例。


在下文中一共展示了MethodVisitor.visitJumpInsn方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLoadNonExistentClassCode

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:RedefineRunningMethodsWithResolutionErrors.java

示例2: generateTestMethod

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:TestOSRWithNonEmptyStack.java

示例3: generateTestMethod

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateTestMethod(ClassVisitor cv,
        Label unstableIfLocation) {
    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC | ACC_STATIC, METHOD_NAME,
            "(Z)V", null, null);
    mv.visitCode();

    Label end = new Label();
    Label falseBranch = new Label();

    // push "field" field's value and 1 to stack
    mv.visitFieldInsn(GETSTATIC, CLASS_NAME, FIELD_NAME, "I");
    mv.visitInsn(ICONST_1);
    // load argument's value
    mv.visitVarInsn(ILOAD, 0); // alwaysTrue
    // here is our unstable if
    mv.visitLabel(unstableIfLocation);
    mv.visitJumpInsn(IFEQ, falseBranch);
    // increment on "true"
    mv.visitInsn(IADD);
    mv.visitJumpInsn(GOTO, end);
    // decrement on "false"
    mv.visitLabel(falseBranch);
    mv.visitInsn(ISUB);
    mv.visitLabel(end);
    // bye bye
    mv.visitInsn(RETURN);

    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:TestUnstableIfTrap.java

示例4: accept

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void accept(final MethodVisitor mv) {
    mv.visitJumpInsn(opcode, label.getLabel());
    acceptAnnotations(mv);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:JumpInsnNode.java

示例5: visitMethod

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:77,代码来源:InvokeDynamicPatcher.java


注:本文中的jdk.internal.org.objectweb.asm.MethodVisitor.visitJumpInsn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。