List of usage examples for org.objectweb.asm Opcodes ACC_STATIC
int ACC_STATIC
To view the source code for org.objectweb.asm Opcodes ACC_STATIC.
Click Source Link
From source file:dodola.anole.lib.IncrementalSupportVisitor.java
License:Apache License
/** * Add all unseen methods from the passed ClassNode's methods. {@see ClassNode#methods} * * @param methods the methods already encountered in the ClassNode hierarchy * @param classNode the class to save all new methods from. *///from w ww . j a v a 2s .com private static void addAllNewMethods(Map<String, MethodReference> methods, ClassNode classNode) { //noinspection unchecked for (MethodNode method : (List<MethodNode>) classNode.methods) { if (method.name.equals(AsmUtils.CONSTRUCTOR) || method.name.equals("<clinit>")) { continue; } String name = method.name + "." + method.desc; if (isAccessCompatibleWithInstantRun(method.access) && !methods.containsKey(name) && (method.access & Opcodes.ACC_STATIC) == 0 && (method.access & Opcodes.ACC_PRIVATE) == 0) { methods.put(name, new MethodReference(method, classNode)); } } }
From source file:dyco4j.instrumentation.internals.AuxiliaryDataCollectingClassVisitor.java
License:BSD License
private static void collectMemberInfo(final int access, final String name, final String desc, final String owner, final Map<String, String> id2Name, final Map<String, String> shortName2Id, final String prefix) { final String _shortName = Helper.createShortNameDesc(name, owner, desc); if (!shortName2Id.containsKey(_shortName)) { final String _tmp = prefix + String.valueOf(shortName2Id.size()); shortName2Id.put(_shortName, _tmp); final String _name = Helper.createNameDesc(name, owner, desc, (access & Opcodes.ACC_STATIC) != 0, (access & Opcodes.ACC_PRIVATE) == 0); id2Name.put(_tmp, _name); }// w ww.j a v a2 s . c o m }
From source file:dyco4j.instrumentation.internals.ProgramDataCollectingClassVisitor.java
License:BSD License
private static void collectMemberInfo(final Optional<Integer> access, final String name, final String desc, final Optional<String> owner, final Map<String, String> id2Name, final Map<String, String> shortName2Id, final String prefix) { final String _shortName = ClassNameHelper.createShortNameDesc(name, owner, desc); if (!shortName2Id.containsKey(_shortName)) { final String _tmp = prefix + String.valueOf(shortName2Id.size()); shortName2Id.put(_shortName, _tmp); final Optional<Boolean> _isStatic = access.map(v -> (v & Opcodes.ACC_STATIC) != 0); final Optional<Boolean> _isPublished = access.map(v -> (v & Opcodes.ACC_PRIVATE) == 0); final String _name = ClassNameHelper.createNameDesc(name, owner, desc, _isStatic, _isPublished); id2Name.put(_tmp, _name); }/*from w ww .jav a 2s . com*/ }
From source file:dyco4j.instrumentation.internals.TracingMethodVisitor.java
License:BSD License
TracingMethodVisitor(final int access, final String name, final String desc, final MethodVisitor mv, final TracingClassVisitor owner, final boolean thisInitialized) { super(CLI.ASM_VERSION, mv); this.method = new Method(name, desc); this.isStatic = (access & Opcodes.ACC_STATIC) != 0; this.methodId = owner.getMethodId(name, desc); this.cv = owner; this.thisInitialized = thisInitialized; this.beginLabel2endLabel = new HashMap<>(); }
From source file:dyco4j.instrumentation.LoggerInitializingClassVisitor.java
License:BSD License
public void visitEnd() { if (!this.isClinitVisited) { final org.objectweb.asm.MethodVisitor _mv = super.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);/* w w w . ja v a 2 s. c o m*/ if (_mv != null) { LoggingHelper.emitInsnToLoadAndInitializeLogger(_mv); _mv.visitInsn(Opcodes.RETURN); } } }
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 ww . j a v a 2 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 w w w . j av a2 s .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.holograms.HologramMethodGenerator.java
License:Open Source License
public void generateNativeThunk() { visitCode();/*from w w w. ja v a 2s .co m*/ getClassMirror(owner); aconst(name); aconst(HologramClassGenerator.getOriginalType(methodType).getDescriptor()); Type[] parameterTypes = methodType.getArgumentTypes(); int var = 0; if ((Opcodes.ACC_STATIC & access) == 0) { load(var, owner); MethodHandle.OBJECT_HOLOGRAM_GET_MIRROR.invoke(this); var++; } else { aconst(null); } aconst(parameterTypes.length); newarray(OBJECT_TYPE); for (int param = 0; param < parameterTypes.length; param++) { Type paramType = parameterTypes[param]; dup(); aconst(param); load(var, paramType); boxIfNeeded(paramType); if (HologramClassGenerator.isRefType(paramType)) { MethodHandle.OBJECT_HOLOGRAM_GET_MIRROR.invoke(this); } astore(OBJECT_TYPE); var += paramType.getSize(); } MethodHandle.OBJECT_HOLOGRAM_INVOKE_METHOD_HANDLER.invoke(this); Type returnType = methodType.getReturnType(); if (returnType.getSort() != Type.VOID) { Class<?> boxingType = Reflection.getBoxingType(returnType); if (boxingType != null) { checkcast(Type.getType(boxingType)); invokevirtual(Type.getInternalName(boxingType), returnType.getClassName() + "Value", Type.getMethodType(returnType).getDescriptor()); } else { MethodHandle.OBJECT_HOLOGRAM_MAKE.invoke(this); checkcast(returnType); } } areturn(returnType); visitMaxs(Math.max(2, var + 1), Math.max(2, var + 1)); visitEnd(); }
From source file:edu.ubc.mirrors.holograms.MainEntryAdaptor.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor superVisitor = super.visitMethod(access, name, desc, signature, exceptions); if (superVisitor != null && name.equals("main") && (Opcodes.ACC_STATIC & access) != 0 && desc.equals(mainDesc)) { superVisitor.visitCode();/*from ww w . j av a 2 s. c o m*/ superVisitor.visitLdcInsn(Type.getObjectType(className)); superVisitor.visitVarInsn(Opcodes.ALOAD, 0); superVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(ObjectHologram.class), "invokeHologramMainMethod", invokeHologramMainMethodDesc); superVisitor.visitInsn(Opcodes.RETURN); superVisitor.visitMaxs(2, 1); superVisitor.visitEnd(); return null; } else { return superVisitor; } }
From source file:edu.ubc.mirrors.holographs.jdkplugins.NativeStubsInvocationHandler.java
License:Open Source License
@Override public Object invoke(InstanceMirror object, MethodMirror method, Object[] args) throws MirrorInvocationTargetException { Object[] stubsArgs = args;/*from w ww . j a v a 2s .co m*/ if ((Opcodes.ACC_STATIC & method.getModifiers()) == 0) { stubsArgs = new Object[args.length + 1]; stubsArgs[0] = object; System.arraycopy(args, 0, stubsArgs, 1, args.length); } try { return stubsMethod.invoke(stubsClassInstance, stubsArgs); } catch (InvocationTargetException e) { if (e.getCause() instanceof MirrorInvocationTargetException) { throw (MirrorInvocationTargetException) e.getCause(); } throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }