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


Java MethodVisitor.visitMethodInsn方法代码示例

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


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

示例1: generateClass

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Generates a class file with the given class name
 */
byte[] generateClass(String className) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
                                     + ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_9,
            ACC_PUBLIC + ACC_SUPER,
            className.replace(".", "/"),
            null,
            "java/lang/Object",
            null);

    // <init>
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    cw.visitEnd();
    return cw.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:DefineClassTest.java

示例2: bytesForD

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * The bytes for D, a NOT abstract class extending abstract class C without
 * supplying an implementation for abstract method m. There is a default
 * method in the interface I, but it should lose to the abstract class.
 *
 * @return
 * @throws Exception
 */
public static byte[] bytesForD() throws Exception {

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES
            | ClassWriter.COMPUTE_MAXS);
    MethodVisitor mv;

    cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "p/D", null, "p/C", null);

    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "p/C", "<init>", "()V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    cw.visitEnd();

    return cw.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:TestAMEnotNPE.java

示例3: 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

示例4: genConstructor

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Generate byteccode for no-arg constructor
 */
private void genConstructor(ClassWriter cw) {
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL,
                       "java/lang/Object",
                       "<init>",
                       "()V",
                       false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:SystemModulesPlugin.java

示例5: createThrowRuntimeExceptionCode

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void createThrowRuntimeExceptionCode(MethodVisitor mv, String msg) {
    mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
    mv.visitInsn(DUP);
    mv.visitLdcInsn(msg);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V");
    mv.visitInsn(ATHROW);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:RedefineRunningMethodsWithResolutionErrors.java

示例6: generateInvokerTemplate

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/** Produces byte code for a class that is used as an injected invoker. */
private static byte[] generateInvokerTemplate() {
    ClassWriter cw = new ClassWriter(0);

    // private static class InjectedInvoker {
    //     @Hidden
    //     static Object invoke_V(MethodHandle vamh, Object[] args) throws Throwable {
    //        return vamh.invokeExact(args);
    //     }
    // }
    cw.visit(52, ACC_PRIVATE | ACC_SUPER, "InjectedInvoker", null, "java/lang/Object", null);

    MethodVisitor mv = cw.visitMethod(ACC_STATIC, "invoke_V",
                  "(Ljava/lang/invoke/MethodHandle;[Ljava/lang/Object;)Ljava/lang/Object;",
                  null, null);

    // Suppress invoker method in stack traces.
    AnnotationVisitor av0 = mv.visitAnnotation("Ljava/lang/invoke/LambdaForm$Hidden;", true);
    av0.visitEnd();

    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invokeExact",
                       "([Ljava/lang/Object;)Ljava/lang/Object;", false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(2, 2);
    mv.visitEnd();

    cw.visitEnd();
    return cw.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:MethodHandleImpl.java

示例7: defineIndyBootstrapMethodBody

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
void defineIndyBootstrapMethodBody(MethodVisitor mv) {
    // Invoke the method BootstrapMethodErrorTest.getCallSite to obtain
    // a CallSite instance whose target is different from that of
    // the indy call site
    mv.visitMethodInsn(INVOKESTATIC, "BootstrapMethodErrorTest",
                       "getCallSite", "()Ljava/lang/invoke/CallSite;", false);
    mv.visitInsn(ARETURN);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:BootstrapMethodErrorTest.java

示例8: loadClassData

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private byte[] loadClassData(String name) throws Exception {
    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;
    switch (name) {
        case INTERFACE_NAME:
            cw.visit(V1_8, ACC_ABSTRACT | ACC_INTERFACE | ACC_PUBLIC, INTERFACE_NAME, null, "java/lang/Object", null);
            {
                mv = cw.visitMethod(ACC_PRIVATE, "privInstance", "()I", null, null);
                mv.visitCode();
                mv.visitLdcInsn(EXPECTED);
                mv.visitInsn(IRETURN);
                mv.visitMaxs(1, 1);
                mv.visitEnd();
            }
            break;
        case CLASS_NAME:
            cw.visit(52, ACC_SUPER | ACC_PUBLIC, CLASS_NAME, null, "java/lang/Object", new String[]{INTERFACE_NAME});
            {
                mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
                mv.visitCode();
                mv.visitVarInsn(ALOAD, 0);
                mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
                mv.visitInsn(RETURN);
                mv.visitMaxs(1, 1);
                mv.visitEnd();
            }
            break;
        default:
            break;
    }
    cw.visitEnd();

    return cw.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:TestPrivateInterfaceMethodReflect.java

示例9: dumpClassFile

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static byte[] dumpClassFile(int cfv, int testDimension264, String arrayDim) throws Exception {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    MethodVisitor mv;

    classCName = "classCName_" + cfv + "_" + testDimension264;

    cw.visit(cfv, ACC_PUBLIC + ACC_SUPER, classCName, null, "java/lang/Object", null);
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {   // classCName main method
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
        mv.visitCode();
        mv.visitIntInsn(BIPUSH, 1);
        mv.visitTypeInsn(ANEWARRAY, arrayDim); // Test ANEWARRAY bytecode with various dimensions
        mv.visitInsn(RETURN);
        mv.visitMaxs(2, 2);
        mv.visitEnd();
    }
    cw.visitEnd();
    return cw.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:TestANewArray.java

示例10: writeClassFile

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static void writeClassFile(int cfv) throws Exception {
    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;

    cw.visit(cfv, ACC_PUBLIC + ACC_SUPER, "ClassFile", null, "java/lang/Object", null);
    mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();

    mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
    mv.visitCode();
    mv.visitInsn(ICONST_1);
    mv.visitInsn(ICONST_2);
    mv.visitMultiANewArrayInsn("[I", 2);
    mv.visitVarInsn(ASTORE, 1);
    mv.visitInsn(RETURN);
    mv.visitMaxs(2, 2);
    mv.visitEnd();

    cw.visitEnd();

    try (FileOutputStream fos = new FileOutputStream(new File("ClassFile.class"))) {
         fos.write(cw.toByteArray());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:TestMultiANewArray.java

示例11: genModuleResolutionsMethod

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Generate bytecode for moduleResolutions method
 */
private void genModuleResolutionsMethod(ClassWriter cw) {
    MethodVisitor mresmv =
        cw.visitMethod(ACC_PUBLIC,
                       "moduleResolutions",
                       "()" + MODULE_RESOLUTIONS_ARRAY_SIGNATURE,
                       "()" + MODULE_RESOLUTIONS_ARRAY_SIGNATURE,
                       null);
    mresmv.visitCode();
    pushInt(mresmv, moduleInfos.size());
    mresmv.visitTypeInsn(ANEWARRAY, MODULE_RESOLUTION_CLASSNAME);
    mresmv.visitVarInsn(ASTORE, 0);

    for (int index=0; index < moduleInfos.size(); index++) {
        ModuleInfo minfo = moduleInfos.get(index);
        if (minfo.moduleResolution() != null) {
            mresmv.visitVarInsn(ALOAD, 0);
            pushInt(mresmv, index);
            mresmv.visitTypeInsn(NEW, MODULE_RESOLUTION_CLASSNAME);
            mresmv.visitInsn(DUP);
            mresmv.visitLdcInsn(minfo.moduleResolution().value());
            mresmv.visitMethodInsn(INVOKESPECIAL,
                                   MODULE_RESOLUTION_CLASSNAME,
                                   "<init>",
                                   "(I)V", false);
            mresmv.visitInsn(AASTORE);
        }
    }
    mresmv.visitVarInsn(ALOAD, 0);
    mresmv.visitInsn(ARETURN);
    mresmv.visitMaxs(0, 0);
    mresmv.visitEnd();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:SystemModulesPlugin.java

示例12: invokestatic

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
static void invokestatic(final MethodVisitor method, final Call call) {
    method.visitMethodInsn(INVOKESTATIC, call.className(), call.name(), call.descriptor(), false);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:Type.java

示例13: accept

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void accept(final MethodVisitor mv) {
    mv.visitMethodInsn(opcode, owner, name, desc, itf);
    acceptAnnotations(mv);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:MethodInsnNode.java

示例14: genModuleTargetsMethod

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Generate bytecode for moduleTargets method
 */
private void genModuleTargetsMethod(ClassWriter cw) {
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC,
                                      "moduleTargets",
                                      "()" + MODULE_TARGET_ARRAY_SIGNATURE,
                                      "()" + MODULE_TARGET_ARRAY_SIGNATURE,
                                      null);
    mv.visitCode();
    pushInt(mv, moduleInfos.size());
    mv.visitTypeInsn(ANEWARRAY, MODULE_TARGET_CLASSNAME);
    mv.visitVarInsn(ASTORE, MT_VAR);


    // if java.base has a ModuleTarget attribute then generate the array
    // with one element, all other elements will be null.

    ModuleInfo base = moduleInfos.get(0);
    if (!base.moduleName().equals("java.base"))
        throw new InternalError("java.base should be first module in list");
    ModuleTarget target = base.target();

    int count;
    if (target != null && target.targetPlatform() != null) {
        count = 1;
    } else {
        count = moduleInfos.size();
    }

    for (int index = 0; index < count; index++) {
        ModuleInfo minfo = moduleInfos.get(index);
        if (minfo.target() != null) {
            mv.visitVarInsn(ALOAD, MT_VAR);
            pushInt(mv, index);

            // new ModuleTarget(String)
            mv.visitTypeInsn(NEW, MODULE_TARGET_CLASSNAME);
            mv.visitInsn(DUP);
            mv.visitLdcInsn(minfo.target().targetPlatform());
            mv.visitMethodInsn(INVOKESPECIAL, MODULE_TARGET_CLASSNAME,
                               "<init>", "(Ljava/lang/String;)V", false);

            mv.visitInsn(AASTORE);
        }
    }

    mv.visitVarInsn(ALOAD, MT_VAR);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:53,代码来源:SystemModulesPlugin.java

示例15: generateTestClass

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
static void generateTestClass(int dim, boolean good) throws Exception {
    String baseClassName = "MeetIncompatibleInterfaceArrays";
    if (good)
        baseClassName += "Good";
    String createName = "createI2" + (good ? "1" : "") + "Array";
    String a = "";
    for (int i = 0; i < dim; i++)
        a += "[";
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_8, ACC_PUBLIC, baseClassName + dim + "ASM", null, "java/lang/Object", null);
    MethodVisitor constr = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    constr.visitCode();
    constr.visitVarInsn(ALOAD, 0);
    constr.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    constr.visitInsn(RETURN);
    constr.visitMaxs(0, 0);
    constr.visitEnd();
    MethodVisitor run = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "run",
            "()" + a + "Lcompiler/types/TestMeetIncompatibleInterfaceArrays$I1;", null, null);
    run.visitCode();
    if (dim == 4) {
        run.visitMethodInsn(INVOKESTATIC, "compiler/types/TestMeetIncompatibleInterfaceArrays$Helper", createName + 3,
                "()" + "[[[" + "Lcompiler/types/TestMeetIncompatibleInterfaceArrays$I2;", false);
    } else {
        run.visitMethodInsn(INVOKESTATIC, "compiler/types/TestMeetIncompatibleInterfaceArrays$Helper", createName + dim,
                "()" + a + "Lcompiler/types/TestMeetIncompatibleInterfaceArrays$I2;", false);
    }
    run.visitInsn(ARETURN);
    run.visitMaxs(0, 0);
    run.visitEnd();
    MethodVisitor test = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "test", "()V", null, null);
    test.visitCode();
    test.visitMethodInsn(INVOKESTATIC, baseClassName + dim + "ASM", "run",
            "()" + a + "Lcompiler/types/TestMeetIncompatibleInterfaceArrays$I1;", false);
    test.visitVarInsn(ASTORE, 0);
    if (dim > 0) {
        test.visitVarInsn(ALOAD, 0);
        for (int i = 1; i <= dim; i++) {
            test.visitInsn(ICONST_0);
            test.visitInsn(AALOAD);
        }
        test.visitVarInsn(ASTORE, 1);
    }
    test.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    test.visitVarInsn(ALOAD, dim > 0 ? 1 : 0);
    test.visitMethodInsn(INVOKEINTERFACE, "compiler/types/TestMeetIncompatibleInterfaceArrays$I1", "getName",
            "()Ljava/lang/String;", true);
    test.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V", false);
    test.visitInsn(RETURN);
    test.visitMaxs(0, 0);
    test.visitEnd();

    // Get the bytes of the class..
    byte[] b = cw.toByteArray();
    // ..and write them into a class file (for debugging)
    FileOutputStream fos = new FileOutputStream(PATH + baseClassName + dim + "ASM.class");
    fos.write(b);
    fos.close();

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:TestMeetIncompatibleInterfaceArrays.java


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