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


Java MethodVisitor.visitTypeInsn方法代码示例

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


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

示例1: generateBootstrapMethod

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private Handle generateBootstrapMethod(Handle h) {
    String bootstrapName = "bootstrapMethod";
    MethodType bootstrapType = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);

    MethodVisitor bmv = cv.visitMethod(ACC_PUBLIC | ACC_STATIC, bootstrapName, bootstrapType.toMethodDescriptorString(), null, null);
    bmv.visitCode();

    String constCallSite = "java/lang/invoke/ConstantCallSite";
    bmv.visitTypeInsn(NEW, constCallSite);
    bmv.visitInsn(DUP);

    bmv.visitLdcInsn(h);

    bmv.visitMethodInsn(INVOKESPECIAL, constCallSite, "<init>", "(Ljava/lang/invoke/MethodHandle;)V", false);
    bmv.visitInsn(ARETURN);

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

    return new Handle(H_INVOKESTATIC, ownerClassName, bootstrapName, bootstrapType.toMethodDescriptorString());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:Method.java

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

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

示例4: genModuleHashesMethod

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Generate bytecode for moduleHashes method
 */
private void genModuleHashesMethod(ClassWriter cw) {
    MethodVisitor hmv =
        cw.visitMethod(ACC_PUBLIC,
                       "moduleHashes",
                       "()" + MODULE_HASHES_ARRAY_SIGNATURE,
                       "()" + MODULE_HASHES_ARRAY_SIGNATURE,
                       null);
    hmv.visitCode();
    pushInt(hmv, moduleInfos.size());
    hmv.visitTypeInsn(ANEWARRAY, "jdk/internal/module/ModuleHashes");
    hmv.visitVarInsn(ASTORE, MH_VAR);

    for (int index = 0; index < moduleInfos.size(); index++) {
        ModuleInfo minfo = moduleInfos.get(index);
        if (minfo.recordedHashes() != null) {
            new ModuleHashesBuilder(minfo.recordedHashes(),
                                    index,
                                    hmv).build();
        }
    }

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

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

示例6: accept

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

示例7: newarray

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Type newarray(final MethodVisitor method) {
    method.visitTypeInsn(ANEWARRAY, getElementType().getInternalName());
    return this;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:ArrayType.java

示例8: convert

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Type convert(final MethodVisitor method, final Type to) {
    final boolean toString = to.isString();
    if (!toString) {
        if (to.isArray()) {
            final Type elemType = ((ArrayType)to).getElementType();

            //note that if this an array, things won't work. see {link @ArrayType} subclass.
            //we also have the unpleasant case of NativeArray which looks like an Object, but is
            //an array to the type system. This is treated specially at the known load points

            if (elemType.isString()) {
                method.visitTypeInsn(CHECKCAST, CompilerConstants.className(String[].class));
            } else if (elemType.isNumber()) {
                method.visitTypeInsn(CHECKCAST, CompilerConstants.className(double[].class));
            } else if (elemType.isLong()) {
                method.visitTypeInsn(CHECKCAST, CompilerConstants.className(long[].class));
            } else if (elemType.isInteger()) {
                method.visitTypeInsn(CHECKCAST, CompilerConstants.className(int[].class));
            } else {
                method.visitTypeInsn(CHECKCAST, CompilerConstants.className(Object[].class));
            }
            return to;
        } else if (to.isObject()) {
            final Class<?> toClass = to.getTypeClass();
            if(!toClass.isAssignableFrom(getTypeClass())) {
                method.visitTypeInsn(CHECKCAST, CompilerConstants.className(toClass));
            }
            return to;
        }
    } else if (isString()) {
        return to;
    }

    if (to.isInteger()) {
        invokestatic(method, JSType.TO_INT32);
    } else if (to.isNumber()) {
        invokestatic(method, JSType.TO_NUMBER);
    } else if (to.isLong()) {
        invokestatic(method, JSType.TO_LONG);
    } else if (to.isBoolean()) {
        invokestatic(method, JSType.TO_BOOLEAN);
    } else if (to.isString()) {
        invokestatic(method, JSType.TO_PRIMITIVE_TO_STRING);
    } else if (to.isCharSequence()) {
        invokestatic(method, JSType.TO_PRIMITIVE_TO_CHARSEQUENCE);
    } else {
        throw new UnsupportedOperationException("Illegal conversion " + this + " -> " + to + " " + isString() + " " + toString);
    }

    return to;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:53,代码来源:ObjectType.java

示例9: dumpT3

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

    cw.visit(52, ACC_PUBLIC + ACC_SUPER, "p1/T3", null, "p1/T2", null);

    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "p1/T2", "<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/T3.m()");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V", false);
        mv.visitIntInsn(BIPUSH, 2);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(2, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "()I", null, null);
        mv.visitCode();
        mv.visitTypeInsn(NEW, "p1/T3");
        mv.visitInsn(DUP);
        mv.visitMethodInsn(INVOKESPECIAL, "p1/T3", "<init>", "()V", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "p1/T2", "m", "()I", false);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(3, 2);
        mv.visitEnd();
    }
    cw.visitEnd();

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

示例10: dumpP2C

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

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

        cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "P2/C", null, "P1/B", null);

        {
            mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
            mv.visitCode();
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKESPECIAL, "P1/B", "<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("P2/C.m");
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
            mv.visitIntInsn(BIPUSH, 3);
            mv.visitInsn(IRETURN);
            mv.visitMaxs(2, 1);
            mv.visitEnd();
        }
        {
            mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "()I", null, null);
            mv.visitCode();
            mv.visitTypeInsn(NEW, "P2/C");
            mv.visitInsn(DUP);
            mv.visitMethodInsn(INVOKESPECIAL, "P2/C", "<init>", "()V", false);
            mv.visitMethodInsn(INVOKEVIRTUAL, "P1/A", "m", "()I", false);
            mv.visitInsn(IRETURN);
            mv.visitMaxs(3, 2);
            mv.visitEnd();
        }

        cw.visitEnd();

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

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

示例12: testWithTwoFactoryMethods

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Test a service provider that defines more than one no-args
 * public static "provider" method.
 */
@Test(expectedExceptions = ServiceConfigurationError.class)
public void testWithTwoFactoryMethods() throws Exception {
    Path mods = compileTest(TEST1_MODULE);

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
                                     + ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_9,
            ACC_PUBLIC + ACC_SUPER,
            "p/ProviderFactory",
            null,
            "java/lang/Object",
            null);

    // public static p.Service provider()
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC,
            "provider",
            "()Lp/Service;",
            null,
            null);
    mv.visitTypeInsn(NEW, "p/ProviderFactory$1");
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL,
            "p/ProviderFactory$1",
            "<init>", "()V",
            false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    // public static p.ProviderFactory$1 provider()
    mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC,
            "provider",
            "()Lp/ProviderFactory$1;",
            null,
            null);
    mv.visitTypeInsn(NEW, "p/ProviderFactory$1");
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL,
            "p/ProviderFactory$1",
            "<init>",
            "()V",
            false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    cw.visitEnd();

    // write the class bytes into the compiled module directory
    Path classFile = mods.resolve(TEST1_MODULE)
            .resolve("p")
            .resolve("ProviderFactory.class");
    Files.write(classFile, cw.toByteArray());

    // load providers and instantiate each one
    loadProviders(mods, TEST1_MODULE).forEach(Provider::get);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:62,代码来源:BadProvidersTest.java


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