本文整理汇总了Java中jdk.internal.org.objectweb.asm.MethodVisitor.visitCode方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitCode方法的具体用法?Java MethodVisitor.visitCode怎么用?Java MethodVisitor.visitCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.internal.org.objectweb.asm.MethodVisitor
的用法示例。
在下文中一共展示了MethodVisitor.visitCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emitStaticInitializer
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void emitStaticInitializer() {
final String className = scriptClassInfo.getJavaName();
if (! staticInitFound) {
// no user written <clinit> and so create one
final MethodVisitor mv = ClassGenerator.makeStaticInitializer(this);
mv.visitCode();
mv.visitInsn(RETURN);
mv.visitMaxs(Short.MAX_VALUE, 0);
mv.visitEnd();
}
// Now generate $clinit$
final MethodGenerator mi = ClassGenerator.makeStaticInitializer(this, $CLINIT$);
ClassGenerator.emitStaticInitPrefix(mi, className, memberCount);
if (memberCount > 0) {
for (final MemberInfo memInfo : scriptClassInfo.getMembers()) {
if (memInfo.isInstanceProperty() || memInfo.isInstanceFunction()) {
ClassGenerator.linkerAddGetterSetter(mi, className, memInfo);
} else if (memInfo.isInstanceGetter()) {
final MemberInfo setter = scriptClassInfo.findSetter(memInfo);
ClassGenerator.linkerAddGetterSetter(mi, className, memInfo, setter);
}
}
}
ClassGenerator.emitStaticInitSuffix(mi, className);
}
示例2: dumpT2
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static byte[] dumpT2() {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
cw.visit(52, ACC_PUBLIC | ACC_SUPER, "p1/T2", null, "p1/T1", null);
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "p1/T1", "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "m", "()I", null, null);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
示例3: 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());
}
示例4: 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());
}
}
示例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();
}
示例6: 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();
}
示例7: 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();
}
示例8: defineIndyBootstrapMethodClass
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
void defineIndyBootstrapMethodClass(ClassWriter cw) {
cw.visit(52, ACC_SUPER | ACC_PUBLIC,
BOOTSTRAP_METHOD_CLASS_NAME, null, "java/lang/Object", null);
// Bootstrap method is declared to be private
MethodVisitor mv = cw.visitMethod(ACC_PRIVATE | ACC_STATIC,
BOOTSTRAP_METHOD_NAME, BOOTSTRAP_METHOD_DESC, null, null);
mv.visitCode();
defineIndyBootstrapMethodBody(mv);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
示例9: 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();
}
示例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());
}
}
示例11: loadC
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static byte[] loadC(boolean redefine) {
ClassWriter cw = new ClassWriter(0);
cw.visit(52, ACC_SUPER | ACC_PUBLIC, "C", null, "java/lang/Object", null);
{
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "m", "()V", null, null);
mv.visitCode();
// First time we run we will:
// 1) Cache resolution errors
// 2) Redefine the class / method
// 3) Try to read the resolution errors that were cached
//
// The redefined method will never run, throw error to be sure
if (redefine) {
createThrowRuntimeExceptionCode(mv, "The redefined method was called");
} else {
createMethodBody(mv);
}
mv.visitMaxs(3, 0);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
示例12: dumpP1A
import jdk.internal.org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static byte[] dumpP1A() {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "P1/A", 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("A.m");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
mv.visitIntInsn(BIPUSH, 1);
mv.visitInsn(IRETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
示例13: 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();
}
示例14: 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();
}
示例15: 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();
}