本文整理汇总了Java中jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES属性的典型用法代码示例。如果您正苦于以下问题:Java ClassWriter.COMPUTE_FRAMES属性的具体用法?Java ClassWriter.COMPUTE_FRAMES怎么用?Java ClassWriter.COMPUTE_FRAMES使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类jdk.internal.org.objectweb.asm.ClassWriter
的用法示例。
在下文中一共展示了ClassWriter.COMPUTE_FRAMES属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
示例3: 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();
}
示例4: 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]);
}
示例5: visit
@Override
public void visit() {
AsmPools pools = getPools();
AsmGlobalPool globalPool = pools.getGlobalPool();
WritableClassPool transformedClasses = globalPool.getTransformedClasses();
expected = globalPool.getClasses().size();
for (ModuleEntry res : globalPool.getClasses()) {
ClassReader reader = globalPool.getClassReader(res);
String className = reader.getClassName();
if (!className.endsWith("module-info")) {
ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES);
reader.accept(new RenameClassVisitor(writer), ClassReader.EXPAND_FRAMES);
transformedClasses.addClass(writer);
++expected;
}
}
}
示例6: renameClasses
private void renameClasses() throws IOException {
AsmPools pools = getPools();
AsmGlobalPool globalPool = pools.getGlobalPool();
WritableClassPool transformedClasses = globalPool.getTransformedClasses();
for (ModuleEntry res : globalPool.getClasses()) {
if (res.getPath().endsWith("module-info.class")) {
continue;
}
ClassReader reader = globalPool.getClassReader(res);
ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES);
RenameClassVisitor visitor = new RenameClassVisitor(writer);
reader.accept(visitor, ClassReader.EXPAND_FRAMES);
transformedClasses.forgetClass(reader.getClassName());
transformedClasses.addClass(writer);
}
}
示例7: 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;
}
}
};
}
示例8: generateRunner
/**
* 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();
}
示例9: ClassConstruct
/**
* Base constructor for building a Class or Interface
* @param name Name of Class/Interface, including package name
* @param extending Name of extending Class if any
* @param access Access for Class/Interface
* @param classFileVersion Class file version
* @param interfaces Interface implemented
*/
public ClassConstruct(String name,
String extending,
int access,
int classFileVersion,
int index,
String... interfaces) {
this.name = name;
isInterface = (access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE;
cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
cw.visit(classFileVersion, access, name, null, extending, interfaces == null ? new String[] { } : interfaces);
this.index = index;
}
示例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;
}
示例11: 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();
}
示例12: 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);
}
示例13: 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;
}
示例14: 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();
}
示例15: toByteArray
/**
* Returns the bytes of the modified module-info.class.
* Once this method has been called then the Extender object should
* be discarded.
*/
public byte[] toByteArray() throws IOException {
ClassWriter cw
= new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
AttributeAddingClassVisitor cv
= new AttributeAddingClassVisitor(Opcodes.ASM5, cw);
ClassReader cr = new ClassReader(in);
if (packages != null)
cv.addAttribute(new ModulePackagesAttribute(packages));
if (mainClass != null)
cv.addAttribute(new ModuleMainClassAttribute(mainClass));
if (targetPlatform != null)
cv.addAttribute(new ModuleTargetAttribute(targetPlatform));
if (hashes != null)
cv.addAttribute(new ModuleHashesAttribute(hashes));
if (moduleResolution != null)
cv.addAttribute(new ModuleResolutionAttribute(moduleResolution.value()));
List<Attribute> attrs = new ArrayList<>();
// prototypes of attributes that should be parsed
attrs.add(new ModuleAttribute(version));
attrs.add(new ModulePackagesAttribute());
attrs.add(new ModuleMainClassAttribute());
attrs.add(new ModuleTargetAttribute());
attrs.add(new ModuleHashesAttribute());
cr.accept(cv, attrs.toArray(new Attribute[0]), 0);
// add any attributes that didn't replace previous attributes
cv.finish();
return cw.toByteArray();
}