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


Java ClassWriter.COMPUTE_MAXS属性代码示例

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


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

示例1: badHostClass

static public void badHostClass(Class<?> hostClass) {
    // choose a class name in the same package as the host class
    String className;
    if (hostClass != null) {
        String prefix = packageName(hostClass);
        if (prefix.length() > 0)
            prefix = prefix.replace('.', '/') + "/";
        className = prefix + "Anon";
    } else {
       className = "Anon";
    }

    // create the class
    String superName = "java/lang/Object";
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
                                     + ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER,
             className, null, superName, null);
    byte[] classBytes = cw.toByteArray();
    int cpPoolSize = constantPoolSize(classBytes);
    Class<?> anonClass
        = unsafe.defineAnonymousClass(hostClass, classBytes, new Object[cpPoolSize]);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TestBadHostClass.java

示例2: getAnonClass

static Class<?> getAnonClass(Class<?> hostClass, final String className) {
    final String superName = "java/lang/Object";
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
    cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, className, null, superName, null);

    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, "test", "()V", null, null);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "p1/T", "test0", "()V", false);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "p1/T", "test1", "()V", false);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "p1/T", "test2", "()V", false);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "p1/T", "test3", "()V", false);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    final byte[] classBytes = cw.toByteArray();
    Class<?> invokerClass = UNSAFE.defineAnonymousClass(hostClass, classBytes, new Object[0]);
    UNSAFE.ensureClassInitialized(invokerClass);
    return invokerClass;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:DefineAnon.java

示例3: getClassFile

static byte[] getClassFile(String suffix) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    MethodVisitor mv;
    cw.visit(52, ACC_PUBLIC | ACC_SUPER, CLASS_NAME + suffix, null, "java/lang/Object", null);
    {
        mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, METHOD_NAME, TYPE.toMethodDescriptorString(), null, null);
        mv.visitCode();
        Handle bsm = new Handle(H_INVOKESTATIC,
                CallSiteDepContextTest.class.getName().replace(".", "/"),
                "bootstrap",
                bsmMH.type().toMethodDescriptorString());
        mv.visitInvokeDynamicInsn("methodName", TYPE.toMethodDescriptorString(), bsm);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    cw.visitEnd();
    return cw.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:CallSiteDepContextTest.java

示例4: getClassFile

/**
 * Generates a class of the following shape:
 *     static class T {
 *         @DontInline public static int f() { return $r; }
 *     }
 */
static byte[] getClassFile(int r) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    MethodVisitor mv;
    cw.visit(52, ACC_PUBLIC | ACC_SUPER, NAME, null, "java/lang/Object", null);
    {
        mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "f", "()I", null, null);
        mv.visitAnnotation("Ljdk/internal/vm/annotation/DontInline;", true);
        mv.visitCode();
        mv.visitLdcInsn(r);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    cw.visitEnd();
    return cw.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:RedefineTest.java

示例5: generateClass

/**
 * 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,代码行数:24,代码来源:DefineClassTest.java

示例6: bytesForD

/**
 * 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:campolake,项目名称:openjdk9,代码行数:29,代码来源:TestAMEnotNPE.java

示例7: testGetModuleOnVMAnonymousClass

/**
 * Exercise Class::getModule on VM anonymous classes
 */
@Test(dataProvider = "hostclasses")
public void testGetModuleOnVMAnonymousClass(Class<?> hostClass, String ignore) {

    // choose a class name in the same package as the host class
    String prefix = packageName(hostClass);
    if (prefix.length() > 0)
        prefix = prefix.replace('.', '/') + "/";
    String className = prefix + "Anon";

    // create the class
    String superName = "java/lang/Object";
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
                                     + ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER,
             className, null, superName, null);
    byte[] classBytes = cw.toByteArray();
    int cpPoolSize = constantPoolSize(classBytes);
    Class<?> anonClass
        = U.defineAnonymousClass(hostClass, classBytes, new Object[cpPoolSize]);

    assertTrue(anonClass.getModule() == hostClass.getModule());
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:25,代码来源:GetModuleTest.java

示例8: makeClassWriter

static ClassWriter makeClassWriter() {
    return new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS) {
        @Override
        protected String getCommonSuperClass(final String type1, final String type2) {
            try {
                return super.getCommonSuperClass(type1, type2);
            } catch (final RuntimeException | LinkageError e) {
                return StringConstants.OBJECT_TYPE;
            }
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:ClassGenerator.java

示例9: ClassEmitter

/**
 * Constructor from the compiler
 *
 * @param env           Script environment
 * @param sourceName    Source name
 * @param unitClassName Compile unit class name.
 * @param strictMode    Should we generate this method in strict mode
 */
ClassEmitter(final Context context, final String sourceName, final String unitClassName, final boolean strictMode) {
    this(context,
         new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS) {
            private static final String OBJECT_CLASS  = "java/lang/Object";

            @Override
            protected String getCommonSuperClass(final String type1, final String type2) {
                try {
                    return super.getCommonSuperClass(type1, type2);
                } catch (final RuntimeException e) {
                    if (isScriptObject(Compiler.SCRIPTS_PACKAGE, type1) && isScriptObject(Compiler.SCRIPTS_PACKAGE, type2)) {
                        return className(ScriptObject.class);
                    }
                    return OBJECT_CLASS;
                }
            }
        });

    this.unitClassName        = unitClassName;
    this.constantMethodNeeded = new HashSet<>();

    cw.visit(V1_7, ACC_PUBLIC | ACC_SUPER, unitClassName, null, pathName(jdk.nashorn.internal.scripts.JS.class.getName()), null);
    cw.visitSource(sourceName, null);

    defineCommonStatics(strictMode);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:ClassEmitter.java

示例10: loadClassData

private byte[] loadClassData(String name) throws Exception {
    ClassWriter cw = new ClassWriter(
            ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    if (name.equals(BOOTSTRAP_METHOD_CLASS_NAME)) {
        defineIndyBootstrapMethodClass(cw);
        return cw.toByteArray();
    }
    else if (name.equals("Exec")) {
        defineIndyCallingClass(cw);
        return cw.toByteArray();
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:BootstrapMethodErrorTest.java

示例11: ClassEmitter

/**
 * Constructor from the compiler.
 *
 * @param env           Script environment
 * @param sourceName    Source name
 * @param unitClassName Compile unit class name.
 * @param strictMode    Should we generate this method in strict mode
 */
ClassEmitter(final Context context, final String sourceName, final String unitClassName, final boolean strictMode) {
    this(context,
         new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS) {
            private static final String OBJECT_CLASS  = "java/lang/Object";

            @Override
            protected String getCommonSuperClass(final String type1, final String type2) {
                try {
                    return super.getCommonSuperClass(type1, type2);
                } catch (final RuntimeException e) {
                    if (isScriptObject(Compiler.SCRIPTS_PACKAGE, type1) && isScriptObject(Compiler.SCRIPTS_PACKAGE, type2)) {
                        return className(ScriptObject.class);
                    }
                    return OBJECT_CLASS;
                }
            }
        });

    this.unitClassName        = unitClassName;
    this.constantMethodNeeded = new HashSet<>();

    cw.visit(V1_7, ACC_PUBLIC | ACC_SUPER, unitClassName, null, pathName(jdk.nashorn.internal.scripts.JS.class.getName()), null);
    cw.visitSource(sourceName, null);

    defineCommonStatics(strictMode);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:ClassEmitter.java

示例12: classFilePrologue

/**
 * Set up class file generation.
 */
private ClassWriter classFilePrologue() {
    final int NOT_ACC_PUBLIC = 0;  // not ACC_PUBLIC
    cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
    cw.visit(Opcodes.V1_8, NOT_ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
            CLASS_PREFIX + className, null, INVOKER_SUPER_NAME, null);
    cw.visitSource(SOURCE_PREFIX + className, null);
    return cw;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:InvokerBytecodeGenerator.java

示例13: generateCodeBytesForLFs

private static byte[] generateCodeBytesForLFs(String className,
        String[] names, LambdaForm[] forms) {

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
    cw.visit(Opcodes.V1_8, Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
            className, null, InvokerBytecodeGenerator.INVOKER_SUPER_NAME, null);
    cw.visitSource(className.substring(className.lastIndexOf('/') + 1), null);

    for (int i = 0; i < forms.length; i++) {
        addMethod(className, names[i], forms[i],
                forms[i].methodType(), cw);
    }
    return cw.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:GenerateJLIClassesHelper.java

示例14: makeClassWriter

static ClassWriter makeClassWriter() {
    return new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS) {
        @Override
        protected String getCommonSuperClass(final String type1, final String type2) {
            try {
                return super.getCommonSuperClass(type1, type2);
            } catch (final RuntimeException | LinkageError e) {
                if (MemberInfo.isScriptObject(type1) && MemberInfo.isScriptObject(type2)) {
                    return StringConstants.SCRIPTOBJECT_TYPE;
                }
                return StringConstants.OBJECT_TYPE;
            }
        }
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ClassGenerator.java

示例15: generateClassWithInitializer

/**
 * Generate a class file with the given class name. The class will initializer
 * to invokestatic the given targetClass/targetMethod.
 */
byte[] generateClassWithInitializer(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",
            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();

    // <clinit>
    String tc = targetClass.replace(".", "/");
    mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()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,代码行数:36,代码来源:DefineClassTest.java


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