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


Java MethodVisitor.visitInsn方法代码示例

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


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

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

示例2: createMethodBody

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void createMethodBody(MethodVisitor mv) {
    Label classExists = new Label();

    // Cache resolution errors
    createLoadNonExistentClassCode(mv, classExists);

    // Redefine our own class and method
    mv.visitMethodInsn(INVOKESTATIC, "RedefineRunningMethodsWithResolutionErrors", "redefine", "()V");

    // Provoke the same error again to make sure the resolution error cache works
    createLoadNonExistentClassCode(mv, classExists);

    // Test passed
    mv.visitInsn(RETURN);

    mv.visitFrame(F_SAME, 0, new Object[0], 0, new Object[0]);
    mv.visitLabel(classExists);

    createThrowRuntimeExceptionCode(mv, "Loaded class that shouldn't exist (\"NonExistentClass\")");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:RedefineRunningMethodsWithResolutionErrors.java

示例3: swap

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void swap(final MethodVisitor method, final Type above, final Type below) {
    if (below.isCategory2()) {
        if (above.isCategory2()) {
            method.visitInsn(DUP2_X2);
            method.visitInsn(POP2);
        } else {
            method.visitInsn(DUP_X2);
            method.visitInsn(POP);
        }
    } else {
        if (above.isCategory2()) {
            method.visitInsn(DUP2_X1);
            method.visitInsn(POP2);
        } else {
            method.visitInsn(SWAP);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:Type.java

示例4: ldc

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Type ldc(final MethodVisitor method, final Object c) {
    if (c == null) {
        method.visitInsn(ACONST_NULL);
    } else if (c instanceof Undefined) {
        return loadUndefined(method);
    } else if (c instanceof String) {
        method.visitLdcInsn(c);
        return STRING;
    } else if (c instanceof Handle) {
        method.visitLdcInsn(c);
        return Type.typeFor(MethodHandle.class);
    } else {
        throw new UnsupportedOperationException("implementation missing for class " + c.getClass() + " value=" + c);
    }

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

示例5: add

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Type add(final MethodVisitor method, final int programPoint) {
    if(programPoint == INVALID_PROGRAM_POINT) {
        method.visitInsn(IADD);
    } else {
        ldc(method, programPoint);
        JSType.ADD_EXACT.invoke(method);
    }
    return INT;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:IntType.java

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

示例7: defineIndyBootstrapMethodBody

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
void defineIndyBootstrapMethodBody(MethodVisitor mv) {
    // Invoke the method whose name is methodName which will throw
    // an exception
    mv.visitMethodInsn(INVOKESTATIC, "BootstrapMethodErrorTest",
                       methodName, "()V", false);
    mv.visitInsn(ACONST_NULL);
    mv.visitInsn(ARETURN);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:BootstrapMethodErrorTest.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: 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

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

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

示例12: and

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Type and(final MethodVisitor method) {
    method.visitInsn(IAND);
    return INT;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:IntType.java

示例13: cmp

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

示例14: arraylength

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

示例15: astore

import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void astore(final MethodVisitor method) {
    method.visitInsn(DASTORE);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:Type.java


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