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


Java MethodVisitor.visitVarInsn方法代码示例

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


在下文中一共展示了MethodVisitor.visitVarInsn方法的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: writeClassFile

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

    cw.visit(99, 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();
    cw.visitEnd();

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

示例3: emitPushFields

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void emitPushFields(String types, String className, MethodVisitor mv) {
    for (int i = 0; i < types.length(); ++i) {
        char tc = types.charAt(i);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, className, makeFieldName(types, i), typeSig(tc));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:BoundMethodHandle.java

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

示例5: dumpT1

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static byte[] dumpT1() {
    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;

    cw.visit(52, ACC_PUBLIC | ACC_SUPER, "p1/T1", 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, "m", "()I", null, null);
        mv.visitCode();
        mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        mv.visitLdcInsn("p1/T1.m()");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V", false);
        mv.visitIntInsn(BIPUSH, 3);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(2, 1);
        mv.visitEnd();
    }
    cw.visitEnd();

    return cw.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:TestConcreteClassWithAbstractMethod.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: dump_HasFinal

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static void dump_HasFinal () throws Exception {

        ClassWriter cw = new ClassWriter(0);
        MethodVisitor mv;

        cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "HasFinal", 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");
            mv.visitInsn(RETURN);
            mv.visitMaxs(1, 1);
            mv.visitEnd();
        }
        {
            mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "m", "(Ljava/lang/String;)V", null, null);
            mv.visitCode();
            mv.visitInsn(RETURN);
            mv.visitMaxs(0, 2);
            mv.visitEnd();
        }
        cw.visitEnd();
        try (FileOutputStream fos = new FileOutputStream(new File("HasFinal.class"))) {
             fos.write(cw.toByteArray());
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:OverriderMsg.java

示例8: dump_Overrider

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static void dump_Overrider () throws Exception {

        ClassWriter cw = new ClassWriter(0);
        MethodVisitor mv;
        cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "Overrider", null, "HasFinal", null);

        {
            mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
            mv.visitCode();
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKESPECIAL, "HasFinal", "<init>", "()V");
            mv.visitInsn(RETURN);
            mv.visitMaxs(1, 1);
            mv.visitEnd();
        }
        {
            mv = cw.visitMethod(ACC_PUBLIC, "m", "(Ljava/lang/String;)V", null, null);
            mv.visitCode();
            mv.visitInsn(RETURN);
            mv.visitMaxs(0, 2);
            mv.visitEnd();
        }
        {
            mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
            mv.visitCode();
            mv.visitInsn(RETURN);
            mv.visitMaxs(0, 1);
            mv.visitEnd();
        }
        cw.visitEnd();

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

示例9: generateConstructor

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateConstructor(ClassWriter classWriter) {
    MethodVisitor mv = classWriter.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(0, 0);
    mv.visitEnd();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:TestOSRWithNonEmptyStack.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: generateRunner

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Generate a class file with the given class name. The class implements Runnable
 * with a run method to invokestatic the given targetClass/targetMethod.
 */
byte[] generateRunner(String className,
                      String targetClass,
                      String targetMethod) throws Exception {

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
                                     + ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_9,
            ACC_PUBLIC + ACC_SUPER,
            className.replace(".", "/"),
            null,
            "java/lang/Object",
            new String[] { "java/lang/Runnable" });

    // <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();

    // run()
    String tc = targetClass.replace(".", "/");
    mv = cw.visitMethod(ACC_PUBLIC, "run", "()V", null, null);
    mv.visitMethodInsn(INVOKESTATIC, tc, targetMethod, "()V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

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

示例12: dumpP1B

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static byte[] dumpP1B() {

        ClassWriter cw = new ClassWriter(0);
        MethodVisitor mv;

        cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "P1/B", null, "P1/A", null);

        {
            mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
            mv.visitCode();
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKESPECIAL, "P1/A", "<init>", "()V", false);
            mv.visitInsn(RETURN);
            mv.visitMaxs(1, 1);
            mv.visitEnd();
        }
        {
            mv = cw.visitMethod(0, "m", "()I", null, null);
            mv.visitCode();
            mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
            mv.visitLdcInsn("B.m");
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
            mv.visitIntInsn(BIPUSH, 2);
            mv.visitInsn(IRETURN);
            mv.visitMaxs(2, 1);
            mv.visitEnd();
        }
        cw.visitEnd();

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

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

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

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


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