Java Code Examples for jdk.internal.org.objectweb.asm.MethodVisitor#visitFieldInsn()
The following examples show how to use
jdk.internal.org.objectweb.asm.MethodVisitor#visitFieldInsn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoundMethodHandle.java From Java8CN with Apache License 2.0 | 5 votes |
private static void emitPushFields(String types, String className, MethodVisitor mv) { for (int i = 0; i < types.length(); ++i) { char tc = types.charAt(i); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, makeFieldName(types, i), typeSig(tc)); } }
Example 2
Source File: EventHandlerCreator.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void buildConstructor() { MethodVisitor mv = classWriter.visitMethod(Opcodes.ACC_PRIVATE, METHOD_EVENT_HANDLER_CONSTRUCTOR.getName(), makeConstructorDescriptor(settingInfos), null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); // this mv.visitVarInsn(Opcodes.ILOAD, 1); // registered mv.visitVarInsn(Opcodes.ALOAD, 2); // event type mv.visitVarInsn(Opcodes.ALOAD, 3); // event control mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(EventHandler.class), METHOD_EVENT_HANDLER_CONSTRUCTOR.getName(), METHOD_EVENT_HANDLER_CONSTRUCTOR.getDescriptor(), false); for (SettingInfo si : settingInfos) { mv.visitVarInsn(Opcodes.ALOAD, 0); // this mv.visitVarInsn(Opcodes.ALOAD, si.index + 4); // Setting Control mv.visitFieldInsn(Opcodes.PUTFIELD, internalClassName, si.fieldName, TYPE_SETTING_CONTROL.getDescriptor()); } // initialized string field writers int fieldIndex = 0; for (FieldInfo field : fields) { if (field.isString()) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(EventHandler.class), "createStringFieldWriter", "()" + TYPE_STRING_POOL.getDescriptor(), false); mv.visitFieldInsn(Opcodes.PUTFIELD, internalClassName, FIELD_PREFIX_STRING_POOL + fieldIndex, TYPE_STRING_POOL.getDescriptor()); } fieldIndex++; } mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
Example 3
Source File: TestConcreteClassWithAbstractMethod.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 4
Source File: BoundMethodHandle.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
private static void emitPushFields(String types, String className, MethodVisitor mv) { for (int i = 0; i < types.length(); ++i) { char tc = types.charAt(i); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, makeFieldName(types, i), typeSig(tc)); } }
Example 5
Source File: UntrustedInterfaces.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { if (name.equals(POISON_IMPL_NAME)) { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, POISON_IMPL_NAME.replace('.', '/'), null, Type.getInternalName(Pill.class), null); // constructor MethodVisitor constructor = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); constructor.visitCode(); constructor.visitVarInsn(Opcodes.ALOAD, 0); constructor.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Pill.class), "<init>", "()V", false); constructor.visitInsn(Opcodes.RETURN); constructor.visitMaxs(0, 0); constructor.visitEnd(); MethodVisitor setList = cw.visitMethod(Opcodes.ACC_PUBLIC, "setField", "()V", null, null); setList.visitCode(); setList.visitVarInsn(Opcodes.ALOAD, 0); setList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class)); setList.visitInsn(Opcodes.DUP); setList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false); setList.visitFieldInsn(Opcodes.PUTFIELD, Type.getInternalName(Pill.class), "field", Type.getDescriptor(TestInterface.class)); setList.visitInsn(Opcodes.RETURN); setList.visitMaxs(0, 0); setList.visitEnd(); MethodVisitor setStaticList = cw.visitMethod(Opcodes.ACC_PUBLIC, "setStaticField", "()V", null, null); setStaticList.visitCode(); setStaticList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class)); setStaticList.visitInsn(Opcodes.DUP); setStaticList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false); setStaticList.visitFieldInsn(Opcodes.PUTSTATIC, Type.getInternalName(Pill.class), "staticField", Type.getDescriptor(TestInterface.class)); setStaticList.visitInsn(Opcodes.RETURN); setStaticList.visitMaxs(0, 0); setStaticList.visitEnd(); MethodVisitor callMe = cw.visitMethod(Opcodes.ACC_PUBLIC, "callMe", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(CallBack.class)), null, null); callMe.visitCode(); callMe.visitVarInsn(Opcodes.ALOAD, 1); callMe.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class)); callMe.visitInsn(Opcodes.DUP); callMe.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false); callMe.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(CallBack.class), "callBack", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(TestInterface.class)), true); callMe.visitInsn(Opcodes.IRETURN); callMe.visitMaxs(0, 0); callMe.visitEnd(); MethodVisitor getList = cw.visitMethod(Opcodes.ACC_PUBLIC, "get", Type.getMethodDescriptor(Type.getType(TestInterface.class)), null, null); getList.visitCode(); getList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class)); getList.visitInsn(Opcodes.DUP); getList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false); getList.visitInsn(Opcodes.ARETURN); getList.visitMaxs(0, 0); getList.visitEnd(); cw.visitEnd(); byte[] bytes = cw.toByteArray(); return defineClass(name, bytes, 0, bytes.length); } return super.findClass(name); }
Example 6
Source File: FieldInsnNode.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor mv) { mv.visitFieldInsn(opcode, owner, name, desc); acceptAnnotations(mv); }
Example 7
Source File: TestConcreteClassWithAbstractMethod.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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(); }
Example 8
Source File: ObjectType.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public Type loadUndefined(final MethodVisitor method) { method.visitFieldInsn(GETSTATIC, className(ScriptRuntime.class), "UNDEFINED", typeDescriptor(Undefined.class)); return UNDEFINED; }
Example 9
Source File: SystemModulesPlugin.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Loads an Enum field. */ void visitElement(T t, MethodVisitor mv) { mv.visitFieldInsn(GETSTATIC, className, t.toString(), "L" + className + ";"); }
Example 10
Source File: ObjectType.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override public Type loadUndefined(final MethodVisitor method) { method.visitFieldInsn(GETSTATIC, className(ScriptRuntime.class), "UNDEFINED", typeDescriptor(Undefined.class)); return UNDEFINED; }
Example 11
Source File: TestConcreteClassWithAbstractMethod.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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(); }
Example 12
Source File: ObjectType.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
@Override public Type loadEmpty(final MethodVisitor method) { method.visitFieldInsn(GETSTATIC, className(ScriptRuntime.class), "EMPTY", typeDescriptor(Undefined.class)); return UNDEFINED; }
Example 13
Source File: ObjectType.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override public Type loadEmpty(final MethodVisitor method) { method.visitFieldInsn(GETSTATIC, className(ScriptRuntime.class), "EMPTY", typeDescriptor(Undefined.class)); return UNDEFINED; }
Example 14
Source File: ObjectType.java From nashorn with GNU General Public License v2.0 | 4 votes |
@Override public Type loadEmpty(final MethodVisitor method) { method.visitFieldInsn(GETSTATIC, className(ScriptRuntime.class), "EMPTY", typeDescriptor(Undefined.class)); return OBJECT; }
Example 15
Source File: FieldInsnNode.java From hottub with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor mv) { mv.visitFieldInsn(opcode, owner, name, desc); acceptAnnotations(mv); }
Example 16
Source File: TestMeetIncompatibleInterfaceArrays.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
static void generateTestClass(int dim, boolean good) throws Exception { String baseClassName = "MeetIncompatibleInterfaceArrays"; if (good) baseClassName += "Good"; String createName = "createI2" + (good ? "1" : "") + "Array"; String a = ""; for (int i = 0; i < dim; i++) a += "["; ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cw.visit(V1_8, ACC_PUBLIC, baseClassName + dim + "ASM", null, "java/lang/Object", null); MethodVisitor constr = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); constr.visitCode(); constr.visitVarInsn(ALOAD, 0); constr.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); constr.visitInsn(RETURN); constr.visitMaxs(0, 0); constr.visitEnd(); MethodVisitor run = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "run", "()" + a + "LTestMeetIncompatibleInterfaceArrays$I1;", null, null); run.visitCode(); if (dim == 4) { run.visitMethodInsn(INVOKESTATIC, "TestMeetIncompatibleInterfaceArrays$Helper", createName + 3, "()" + "[[[" + "LTestMeetIncompatibleInterfaceArrays$I2;", false); } else { run.visitMethodInsn(INVOKESTATIC, "TestMeetIncompatibleInterfaceArrays$Helper", createName + dim, "()" + a + "LTestMeetIncompatibleInterfaceArrays$I2;", false); } run.visitInsn(ARETURN); run.visitMaxs(0, 0); run.visitEnd(); MethodVisitor test = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "test", "()V", null, null); test.visitCode(); test.visitMethodInsn(INVOKESTATIC, baseClassName + dim + "ASM", "run", "()" + a + "LTestMeetIncompatibleInterfaceArrays$I1;", false); test.visitVarInsn(ASTORE, 0); if (dim > 0) { test.visitVarInsn(ALOAD, 0); for (int i = 1; i <= dim; i++) { test.visitInsn(ICONST_0); test.visitInsn(AALOAD); } test.visitVarInsn(ASTORE, 1); } test.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); test.visitVarInsn(ALOAD, dim > 0 ? 1 : 0); test.visitMethodInsn(INVOKEINTERFACE, "TestMeetIncompatibleInterfaceArrays$I1", "getName", "()Ljava/lang/String;", true); test.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V", false); test.visitInsn(RETURN); test.visitMaxs(0, 0); test.visitEnd(); // Get the bytes of the class.. byte[] b = cw.toByteArray(); // ..and write them into a class file (for debugging) FileOutputStream fos = new FileOutputStream(PATH + baseClassName + dim + "ASM.class"); fos.write(b); fos.close(); }
Example 17
Source File: TransitiveOverrideCFV50.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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(); }
Example 18
Source File: ObjectType.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override public Type loadEmpty(final MethodVisitor method) { method.visitFieldInsn(GETSTATIC, className(ScriptRuntime.class), "EMPTY", typeDescriptor(Undefined.class)); return OBJECT; }
Example 19
Source File: FieldInsnNode.java From nashorn with GNU General Public License v2.0 | 4 votes |
@Override public void accept(final MethodVisitor cv) { cv.visitFieldInsn(opcode, owner, name, desc); }
Example 20
Source File: TestMeetIncompatibleInterfaceArrays.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
static void generateTestClass(int dim, boolean good) throws Exception { String baseClassName = "MeetIncompatibleInterfaceArrays"; if (good) baseClassName += "Good"; String createName = "createI2" + (good ? "1" : "") + "Array"; String a = ""; for (int i = 0; i < dim; i++) a += "["; ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cw.visit(V1_8, ACC_PUBLIC, baseClassName + dim + "ASM", null, "java/lang/Object", null); MethodVisitor constr = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); constr.visitCode(); constr.visitVarInsn(ALOAD, 0); constr.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); constr.visitInsn(RETURN); constr.visitMaxs(0, 0); constr.visitEnd(); MethodVisitor run = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "run", "()" + a + "LTestMeetIncompatibleInterfaceArrays$I1;", null, null); run.visitCode(); if (dim == 4) { run.visitMethodInsn(INVOKESTATIC, "TestMeetIncompatibleInterfaceArrays$Helper", createName + 3, "()" + "[[[" + "LTestMeetIncompatibleInterfaceArrays$I2;", false); } else { run.visitMethodInsn(INVOKESTATIC, "TestMeetIncompatibleInterfaceArrays$Helper", createName + dim, "()" + a + "LTestMeetIncompatibleInterfaceArrays$I2;", false); } run.visitInsn(ARETURN); run.visitMaxs(0, 0); run.visitEnd(); MethodVisitor test = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "test", "()V", null, null); test.visitCode(); test.visitMethodInsn(INVOKESTATIC, baseClassName + dim + "ASM", "run", "()" + a + "LTestMeetIncompatibleInterfaceArrays$I1;", false); test.visitVarInsn(ASTORE, 0); if (dim > 0) { test.visitVarInsn(ALOAD, 0); for (int i = 1; i <= dim; i++) { test.visitInsn(ICONST_0); test.visitInsn(AALOAD); } test.visitVarInsn(ASTORE, 1); } test.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); test.visitVarInsn(ALOAD, dim > 0 ? 1 : 0); test.visitMethodInsn(INVOKEINTERFACE, "TestMeetIncompatibleInterfaceArrays$I1", "getName", "()Ljava/lang/String;", true); test.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V", false); test.visitInsn(RETURN); test.visitMaxs(0, 0); test.visitEnd(); // Get the bytes of the class.. byte[] b = cw.toByteArray(); // ..and write them into a class file (for debugging) FileOutputStream fos = new FileOutputStream(PATH + baseClassName + dim + "ASM.class"); fos.write(b); fos.close(); }