List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC
int ACC_PUBLIC
To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.
Click Source Link
From source file:edu.illinois.nondex.instr.PriorityQueueShufflingAdder.java
License:Open Source License
public void addNext() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "next", "()Ljava/lang/Object;", "()TE;", null); mv.visitCode();// w w w . j a v a 2 s.c o m mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "expectedModCount", "I"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "this$0", "Ljava/util/PriorityQueue;"); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue", "modCount", "I"); Label l0 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPEQ, l0); mv.visitTypeInsn(Opcodes.NEW, "java/util/ConcurrentModificationException"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ConcurrentModificationException", "<init>", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "iter", "Ljava/util/Iterator;"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;", true); mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRetElt", "Ljava/lang/Object;"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ICONST_M1); mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRet", "I"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "lastRetElt", "Ljava/lang/Object;"); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(2, 1); mv.visitEnd(); }
From source file:edu.illinois.nondex.instr.PriorityQueueShufflingAdder.java
License:Open Source License
public void addHasNext() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "hasNext", "()Z", null, null); mv.visitCode();/*from w w w .ja v a 2 s . co m*/ mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "iter", "Ljava/util/Iterator;"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:edu.illinois.nondex.instr.WeakHashMapShufflingAdder.java
License:Open Source License
public void addHasNext() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "hasNext", "()Z", null, null); mv.visitCode();// ww w . j a v a2s.c o m mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/WeakHashMap$HashIterator", "iter", "Ljava/util/Iterator;"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:edu.illinois.nondex.instr.WeakHashMapShufflingAdder.java
License:Open Source License
public void addNextEntry() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "nextEntry", "()Ljava/util/WeakHashMap$Entry;", "()Ljava/util/WeakHashMap$Entry<TK;TV;>;", null); mv.visitCode();//from w w w . j av a 2 s . c o m mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/WeakHashMap$HashIterator", "this$0", "Ljava/util/WeakHashMap;"); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/WeakHashMap", "modCount", "I"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/WeakHashMap$HashIterator", "expectedModCount", "I"); Label l0 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPEQ, l0); mv.visitTypeInsn(Opcodes.NEW, "java/util/ConcurrentModificationException"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ConcurrentModificationException", "<init>", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/WeakHashMap$HashIterator", "iter", "Ljava/util/Iterator;"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;", true); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/WeakHashMap$Entry"); mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "lastReturned", "Ljava/util/WeakHashMap$Entry;"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/WeakHashMap$HashIterator", "lastReturned", "Ljava/util/WeakHashMap$Entry;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/WeakHashMap$Entry", "get", "()Ljava/lang/Object;", false); mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "currentKey", "Ljava/lang/Object;"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/WeakHashMap$HashIterator", "lastReturned", "Ljava/util/WeakHashMap$Entry;"); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(2, 1); mv.visitEnd(); }
From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java
License:Open Source License
private static int forcePublic(int access) { return (~(Opcodes.ACC_ENUM | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED) & access) | Opcodes.ACC_PUBLIC; }
From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java
License:Open Source License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from w w w . j a v a 2s .c o m this.name = name; this.isInterface = (Opcodes.ACC_INTERFACE & access) != 0; this.superName = getHologramSuperclassName(isInterface, name, superName); interfaces = getHologramInterfaces(name, isInterface, interfaces); // Force everything to be public, since HologramClassLoader has to reflectively // construct holograms. Again, not a problem because the VM will see the original flags on the ClassMirror instead. // Also remove enum flags. int hologramAccess = forcePublic(access); // Also remove abstract flag. Shouldn't be necessary, but the VM (OpenJDK at least) // creates objects that claim to be an instance of VirtualMachineError, which is abstract. if (name.equals("hologram/java/lang/VirtualMachineError")) { hologramAccess = ~Opcodes.ACC_ABSTRACT & access; } // We need at least 1.5 to use class literal constants // TODO-RS: Work out a better way to interpret 45.X numbers correctly if (version == Opcodes.V1_1 || version < Opcodes.V1_5) { version = 49; } super.visit(version, hologramAccess, name, signature, this.superName, interfaces); if (this.name.equals(hologramThrowableType.getInternalName())) { // Generate aliases for the original superclass' fillInStackTrace and getStackTrace methods, // so we can call them in stubs without hitting hologram code. MethodVisitor v = super.visitMethod(Opcodes.ACC_PUBLIC, "superFillInStackTrace", Type.getMethodDescriptor(Type.VOID_TYPE), null, null); v.visitCode(); v.visitVarInsn(Opcodes.ALOAD, 0); v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "fillInStackTrace", Type.getMethodDescriptor(Type.getType(Throwable.class))); v.visitInsn(Opcodes.RETURN); v.visitMaxs(1, 1); v.visitEnd(); v = super.visitMethod(Opcodes.ACC_PUBLIC, "superGetStackTrace", Type.getMethodDescriptor(Type.getType(StackTraceElement[].class)), null, null); v.visitCode(); v.visitVarInsn(Opcodes.ALOAD, 0); v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "getStackTrace", Type.getMethodDescriptor(Type.getType(StackTraceElement[].class))); v.visitInsn(Opcodes.ARETURN); v.visitMaxs(1, 1); v.visitEnd(); } }
From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java
License:Open Source License
@Override public void visitEnd() { // Generate the static field used to store the corresponding ClassMirror int staticAccess = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC; super.visitField(staticAccess, "classMirror", classMirrorType.getDescriptor(), null, null); // Generate the constructor that takes a mirror instance as an Object parameter String constructorDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Object.class)); if (name.equals(getHologramType(Type.getType(Throwable.class), true).getInternalName())) { // This doesn't extend ObjectHologram so we have to set the field directly super.visitField(Opcodes.ACC_PUBLIC, "mirror", objectMirrorType.getDescriptor(), null, null); MethodVisitor methodVisitor = super.visitMethod(Opcodes.ACC_PUBLIC, "<init>", constructorDesc, null, null);/*from w w w . j av a2 s . c o m*/ methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE)); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, objectMirrorType.getInternalName()); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, name, "mirror", Type.getDescriptor(ObjectMirror.class)); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(2, 2); methodVisitor.visitEnd(); methodVisitor = super.visitMethod(Opcodes.ACC_PUBLIC, "getMirror", Type.getMethodDescriptor(objectMirrorType), null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitFieldInsn(Opcodes.GETFIELD, name, "mirror", Type.getDescriptor(ObjectMirror.class)); methodVisitor.visitInsn(Opcodes.ARETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); } else if (!isInterface) { MethodVisitor methodVisitor = super.visitMethod(Opcodes.ACC_PUBLIC, "<init>", constructorDesc, null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", constructorDesc); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(2, 2); methodVisitor.visitEnd(); } // Add a class initialization method to initialize the static fields, // if one doesn't exist already. if (!hasClinit) { InstructionAdapter mv = new InstructionAdapter( super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "<clinit>", "()V", null, null)); mv.visitCode(); HologramMethodGenerator.initializeStaticFields(Type.getObjectType(this.name), mv); mv.areturn(Type.VOID_TYPE); mv.visitMaxs(2, 2); mv.visitEnd(); } super.visitEnd(); }
From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java
License:Open Source License
public static void generateArray(ClassVisitor visitor, HologramClassLoader loader, HologramClassMirror hologramClassMirror) { boolean isInterface = !hologramClassMirror.isImplementationClass(); ClassMirror classMirror = hologramClassMirror.getOriginal(); Type originalType = Reflection.typeForClassMirror(classMirror); Type originalElementType = originalType.getElementType(); int dims = originalType.getDimensions(); String internalName = getHologramType(originalType, !isInterface).getInternalName(); ClassMirror superClassMirror = null; String superName = isInterface ? Type.getInternalName(Object.class) : Type.getInternalName(ObjectArrayHologram.class); Set<String> interfaces = new HashSet<String>(); int access = Opcodes.ACC_PUBLIC | (isInterface ? Opcodes.ACC_INTERFACE : 0); if (originalElementType.getSort() == Type.OBJECT || originalElementType.getSort() == Type.ARRAY) { ClassMirror elementClass = loader.loadOriginalClassMirror(originalElementType.getClassName()); superClassMirror = elementClass.getSuperClassMirror(); if (isInterface) { if (superClassMirror != null) { Type superType = Reflection.makeArrayType(dims, Type.getObjectType(superClassMirror.getClassName().replace('.', '/'))); String superInterfaceName = getHologramType(superType).getInternalName(); interfaces.add(superInterfaceName); }//from ww w . j a va 2s. c o m for (ClassMirror interfaceMirror : elementClass.getInterfaceMirrors()) { Type superType = Reflection.makeArrayType(dims, Type.getObjectType(interfaceMirror.getClassName().replace('.', '/'))); String interfaceName = getHologramType(superType).getInternalName(); interfaces.add(interfaceName); } interfaces.add(hologramType.getInternalName()); Type nMinus1Type = Reflection.makeArrayType(dims - 1, Type.getType(Object.class)); interfaces.add(getHologramType(nMinus1Type).getInternalName()); } } if (!isInterface) { interfaces.add(getHologramType(originalType, false).getInternalName()); } visitor.visit(Opcodes.V1_5, access, internalName, null, superName, interfaces.toArray(new String[0])); if (isInterface) { // Generate clone() String cloneDesc = Type.getMethodDescriptor(objectType); MethodVisitor mv = visitor.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "clone", cloneDesc, null, null); mv.visitEnd(); } else { // Generate thunk constructors String initDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(ObjectArrayMirror.class)); MethodVisitor mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", initDesc, null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", initDesc); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(2, 2); mv.visitEnd(); initDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE); mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", initDesc, null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", initDesc); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(2, 2); mv.visitEnd(); } // Generate the static field used to store the corresponding ClassMirror and the static initializer to set it int staticAccess = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC; visitor.visitField(staticAccess, "classMirror", classMirrorType.getDescriptor(), null, null); InstructionAdapter mv = new InstructionAdapter( visitor.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "<clinit>", "()V", null, null)); mv.visitCode(); HologramMethodGenerator.initializeStaticFields(Type.getObjectType(internalName), mv); mv.areturn(Type.VOID_TYPE); mv.visitMaxs(2, 2); mv.visitEnd(); visitor.visitEnd(); }
From source file:edu.ubc.mirrors.raw.NativeClassGenerator.java
License:Open Source License
@Override public void visitEnd() { if (!isInterface) { // Generate the no-argument constructor String constructorDesc = Type.getMethodDescriptor(Type.VOID_TYPE); MethodVisitor methodVisitor = super.visitMethod(Opcodes.ACC_PUBLIC, "<init>", constructorDesc, null, null);/* w ww. ja v a 2 s. c om*/ methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", constructorDesc); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); } super.visitEnd(); }
From source file:edu.umd.cs.findbugs.detect.TestASM.java
License:Open Source License
@Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { if ((access & Opcodes.ACC_STATIC) != 0 && (access & Opcodes.ACC_FINAL) != 0 && (access & Opcodes.ACC_PUBLIC) != 0 && !name.equals(name.toUpperCase())) { bugReporter.reportBug(new BugInstance(this, "NM_FIELD_NAMING_CONVENTION", Priorities.LOW_PRIORITY) .addClass(this).addField(this.name, name, desc, access)); }//from w ww . j a v a 2 s . c o m return null; }