Java Code Examples for jdk.internal.org.objectweb.asm.MethodVisitor#visitLdcInsn()
The following examples show how to use
jdk.internal.org.objectweb.asm.MethodVisitor#visitLdcInsn() .
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: AddressVarHandleGenerator.java From Bytecoder with Apache License 2.0 | 6 votes |
void addConstructor(BinderClassWriter cw) { MethodType constrType = MethodType.methodType(void.class, VarForm.class, boolean.class, long.class, long.class, long.class, long[].class); MethodVisitor mv = cw.visitMethod(0, "<init>", constrType.toMethodDescriptorString(), null, null); mv.visitCode(); //super call mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, Type.getInternalName(VarForm.class)); mv.visitVarInsn(ILOAD, 2); mv.visitVarInsn(LLOAD, 3); mv.visitVarInsn(LLOAD, 5); mv.visitVarInsn(LLOAD, 7); mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(BASE_CLASS), "<init>", MethodType.methodType(void.class, VarForm.class, boolean.class, long.class, long.class, long.class).toMethodDescriptorString(), false); //init dimensions for (int i = 0 ; i < dimensions ; i++) { mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 9); mv.visitLdcInsn(i); mv.visitInsn(LALOAD); mv.visitFieldInsn(PUTFIELD, implClassName, "dim" + i, "J"); } mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
Example 2
Source File: TestPrivateInterfaceMethodReflect.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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(); }
Example 3
Source File: TestOSRWithNonEmptyStack.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 4
Source File: TestPrivateInterfaceMethodReflect.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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(); }
Example 5
Source File: TestPrivateInterfaceMethodReflect.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 6
Source File: UnsafeGetConstantField.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void initField(MethodVisitor mv) { if (hasDefaultValue) { return; // Nothing to do } if (!isStatic()) { mv.visitVarInsn(ALOAD, 0); } mv.visitLdcInsn(type.value); mv.visitFieldInsn((isStatic() ? PUTSTATIC : PUTFIELD), className, FIELD_NAME, fieldDesc); }
Example 7
Source File: UnloadClass.java From LearningOfThinkInJava with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws NoSuchMethodException,SecurityException, IllegalAccessException,IllegalArgumentException,InvocationTargetException{ ClassWriter cw=new ClassWriter(ClassWriter.COMPUTE_MAXS|ClassWriter.COMPUTE_FRAMES); cw.visit(V1_7,ACC_PUBLIC,"Example",null,"java/lang/Object",null); MethodVisitor mw=cw.visitMethod(ACC_PUBLIC,"<init>","()V",null,null); mw.visitVarInsn(ALOAD,0); mw.visitMethodInsn(INVOKESPECIAL,"java/lang/Object","<init>","()V"); mw.visitInsn(RETURN); mw.visitMaxs(0,0); mw.visitEnd(); mw=cw.visitMethod(ACC_PUBLIC+ACC_STATIC,"main","([Ljava/lang/String;)V",null,null); mw.visitFieldInsn(GETSTATIC,"java/lang/System","out","Ljava/io/PrintStream;"); mw.visitLdcInsn("Hello world!"); mw.visitMethodInsn(INVOKEVIRTUAL,"java/io/PrintStream","println","(Ljava/lang/String;)V"); mw.visitInsn(RETURN); mw.visitMaxs(0,0); mw.visitEnd(); byte[] code=cw.toByteArray(); for(int i=0;i<1;i++){ ClassLoader loader=UnloadClass.class.getClassLoader(); Method m=ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class); m.setAccessible(true); m.invoke(loader,"Example",code,0,code.length); m.setAccessible(false); System.gc(); } }
Example 8
Source File: TestOSRWithNonEmptyStack.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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(); }
Example 9
Source File: StringConcatFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * The following method is copied from * org.objectweb.asm.commons.InstructionAdapter. Part of ASM: a very small * and fast Java bytecode manipulation framework. * Copyright (c) 2000-2005 INRIA, France Telecom All rights reserved. */ private static void iconst(MethodVisitor mv, final int cst) { if (cst >= -1 && cst <= 5) { mv.visitInsn(Opcodes.ICONST_0 + cst); } else if (cst >= Byte.MIN_VALUE && cst <= Byte.MAX_VALUE) { mv.visitIntInsn(Opcodes.BIPUSH, cst); } else if (cst >= Short.MIN_VALUE && cst <= Short.MAX_VALUE) { mv.visitIntInsn(Opcodes.SIPUSH, cst); } else { mv.visitLdcInsn(cst); } }
Example 10
Source File: LongType.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override public Type loadUndefined(final MethodVisitor method) { method.visitLdcInsn(UNDEFINED_LONG); return LONG; }
Example 11
Source File: LongType.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public Type loadUndefined(final MethodVisitor method) { method.visitLdcInsn(UNDEFINED_LONG); return LONG; }
Example 12
Source File: TestAMEnotNPE.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * The bytecodes for a class p/T defining a methods test() and test(11args) * that contain an invokeExact of a particular methodHandle, I.m. * * Test will be passed values that may imperfectly implement I, * and thus may in turn throw exceptions. * * @return * @throws Exception */ public static byte[] bytesForT() throws Exception { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); MethodVisitor mv; cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "p/T", 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"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } // static int test(I) { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "(Lp/I;)I", null, null); mv.visitCode(); mv.visitLdcInsn(new Handle(Opcodes.H_INVOKEINTERFACE, "p/I", "m", "()I")); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invokeExact", "(Lp/I;)I"); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } // static int test(I,11args) { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "(Lp/I;BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I", null, null); mv.visitCode(); mv.visitLdcInsn(new Handle(Opcodes.H_INVOKEINTERFACE, "p/I", "m", "(BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I")); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 1); mv.visitVarInsn(ILOAD, 2); mv.visitVarInsn(ILOAD, 3); mv.visitVarInsn(ILOAD, 4); mv.visitVarInsn(LLOAD, 5); mv.visitVarInsn(ALOAD, 7); mv.visitVarInsn(ALOAD, 8); mv.visitVarInsn(ALOAD, 9); mv.visitVarInsn(ALOAD, 10); mv.visitVarInsn(ALOAD, 11); mv.visitVarInsn(ALOAD, 12); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invokeExact", "(Lp/I;BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I"); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }
Example 13
Source File: IntType.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public Type loadUndefined(final MethodVisitor method) { method.visitLdcInsn(ObjectClassGenerator.UNDEFINED_INT); return INT; }
Example 14
Source File: BooleanType.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
@Override public Type loadUndefined(final MethodVisitor method) { method.visitLdcInsn(UNDEFINED_INT); return BOOLEAN; }
Example 15
Source File: BooleanType.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public Type loadUndefined(final MethodVisitor method) { method.visitLdcInsn(UNDEFINED_INT); return BOOLEAN; }
Example 16
Source File: NumberType.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
@Override public Type loadUndefined(final MethodVisitor method) { method.visitLdcInsn(UNDEFINED_DOUBLE); return NUMBER; }
Example 17
Source File: Proxy.java From totallylazy with Apache License 2.0 | 4 votes |
private static void loadMethod(MethodVisitor mv, String superClass, String methodName, String methodDescriptor) { mv.visitLdcInsn(superClass); mv.visitLdcInsn(methodName); mv.visitLdcInsn(methodDescriptor); mv.visitMethodInsn(INVOKESTATIC, "com/googlecode/totallylazy/reflection/Methods", "method", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/reflect/Method;", false); }
Example 18
Source File: TestAMEnotNPE.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Returns the bytes for a class with name d_name (presumably "D" in some * package), extending some class with name sub_what, implementing p.I, * and defining two methods m() and m(11args) with access method_acc. * * @param d_name Name of class that is defined * @param sub_what Name of class that it extends * @param method_acc Accessibility of method(s) m in defined class. * @return * @throws Exception */ public static byte[] bytesForSomeDsubSomethingSomeAccess (String d_name, String sub_what, int method_acc) throws Exception { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); MethodVisitor mv; String[] interfaces = {"p/I"}; cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, d_name, null, sub_what, interfaces); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, sub_what, "<init>", "()V"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } // int m() {return 3;} { mv = cw.visitMethod(method_acc, "m", "()I", null, null); mv.visitCode(); mv.visitLdcInsn(new Integer(3)); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } // int m(11args) {return 3;} { mv = cw.visitMethod(method_acc, "m", "(BCSIJ" + "Ljava/lang/Object;" + "Ljava/lang/Object;" + "Ljava/lang/Object;" + "Ljava/lang/Object;" + "Ljava/lang/Object;" + "Ljava/lang/Object;" + ")I", null, null); mv.visitCode(); mv.visitLdcInsn(new Integer(3)); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }
Example 19
Source File: TestConcreteClassWithAbstractMethod.java From openjdk-jdk9 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 20
Source File: TestAMEnotNPE.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * The bytecodes for a class p/T defining a methods test() and test(11args) * that contain an invokeExact of a particular methodHandle, I.m. * * Test will be passed values that may imperfectly implement I, * and thus may in turn throw exceptions. * * @return * @throws Exception */ public static byte[] bytesForT() throws Exception { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); MethodVisitor mv; cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "p/T", 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"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } // static int test(I) { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "(Lp/I;)I", null, null); mv.visitCode(); mv.visitLdcInsn(new Handle(Opcodes.H_INVOKEINTERFACE, "p/I", "m", "()I")); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invokeExact", "(Lp/I;)I"); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } // static int test(I,11args) { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "(Lp/I;BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I", null, null); mv.visitCode(); mv.visitLdcInsn(new Handle(Opcodes.H_INVOKEINTERFACE, "p/I", "m", "(BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I")); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 1); mv.visitVarInsn(ILOAD, 2); mv.visitVarInsn(ILOAD, 3); mv.visitVarInsn(ILOAD, 4); mv.visitVarInsn(LLOAD, 5); mv.visitVarInsn(ALOAD, 7); mv.visitVarInsn(ALOAD, 8); mv.visitVarInsn(ALOAD, 9); mv.visitVarInsn(ALOAD, 10); mv.visitVarInsn(ALOAD, 11); mv.visitVarInsn(ALOAD, 12); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invokeExact", "(Lp/I;BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I"); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }