List of usage examples for org.objectweb.asm Opcodes ACC_FINAL
int ACC_FINAL
To view the source code for org.objectweb.asm Opcodes ACC_FINAL.
Click Source Link
From source file:sg.atom.core.actor.internal.codegenerator.ActorProxyCreator.java
License:Apache License
/** * Creates and loads the actor's proxy class. * * @param actorClass the Actor class//from w ww . jav a 2 s. c o m * @param acd the actor's class descriptor * @throws ConfigurationException if the agent is not configured correctly */ @SuppressWarnings("unchecked") private static Class<?> generateProxyClass(Class<?> actorClass, final ActorClassDescriptor acd) throws NoSuchMethodException { BeanClassDescriptor bcd = acd.getBeanClassDescriptor(); String className = String.format("%s__ACTORPROXY", actorClass.getName()); final String classNameInternal = className.replace('.', '/'); String classNameDescriptor = "L" + classNameInternal + ";"; final Type actorState = Type .getType(acd.getConcurrencyModel().isMultiThreadingCapable() ? MultiThreadedActorState.class : SingleThreadedActorState.class); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); MethodVisitor mv; cw.visit(codeVersion, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER + Opcodes.ACC_SYNTHETIC, classNameInternal, null, Type.getInternalName(actorClass), new String[] { "org/actorsguildframework/internal/ActorProxy" }); cw.visitSource(null, null); { for (int i = 0; i < acd.getMessageCount(); i++) { cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, String.format(MESSAGE_CALLER_NAME_FORMAT, i), "Lorg/actorsguildframework/internal/MessageCaller;", "Lorg/actorsguildframework/internal/MessageCaller<*>;", null).visitEnd(); } cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "actorState__ACTORPROXY", actorState.getDescriptor(), null, null).visitEnd(); } BeanCreator.writePropFields(bcd, cw); { mv = cw.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); for (int i = 0; i < acd.getMessageCount(); i++) { Class<?> caller = createMessageCaller(acd.getMessage(i).getOwnerClass(), acd.getMessage(i).getMethod()); String mcName = Type.getInternalName(caller); mv.visitTypeInsn(Opcodes.NEW, mcName); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, mcName, "<init>", "()V"); mv.visitFieldInsn(Opcodes.PUTSTATIC, classNameInternal, String.format(MESSAGE_CALLER_NAME_FORMAT, i), "Lorg/actorsguildframework/internal/MessageCaller;"); } mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } BeanCreator.writeConstructor(actorClass, bcd, classNameInternal, cw, new BeanCreator.SnippetWriter() { @Override public void write(MethodVisitor mv) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.NEW, actorState.getInternalName()); mv.visitInsn(Opcodes.DUP); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, actorState.getInternalName(), "<init>", "(Lorg/actorsguildframework/internal/Controller;Lorg/actorsguildframework/Actor;)V"); mv.visitFieldInsn(Opcodes.PUTFIELD, classNameInternal, "actorState__ACTORPROXY", actorState.getDescriptor()); } }); BeanCreator.writePropAccessors(bcd, classNameInternal, cw); { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getState__ACTORPROXYMETHOD", "()Lorg/actorsguildframework/internal/ActorState;", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, classNameInternal, "actorState__ACTORPROXY", actorState.getDescriptor()); mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", classNameDescriptor, null, l0, l1, 0); mv.visitMaxs(0, 0); mv.visitEnd(); } for (int i = 0; i < acd.getMessageCount(); i++) { MessageImplDescriptor mid = acd.getMessage(i); Method method = mid.getMethod(); String simpleDescriptor = Type.getMethodDescriptor(method); String genericSignature = GenericTypeHelper.getSignature(method); writeProxyMethod(classNameInternal, classNameDescriptor, cw, i, actorState, acd.getConcurrencyModel(), mid, method, simpleDescriptor, genericSignature); writeSuperProxyMethod(actorClass, classNameDescriptor, cw, method, simpleDescriptor, genericSignature, !acd.getConcurrencyModel().isMultiThreadingCapable()); } { mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_SYNCHRONIZED, "toString", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "toString", "()Ljava/lang/String;"); mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", classNameDescriptor, null, l0, l1, 0); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); try { return (Class<? extends ActorProxy>) GenerationUtils.loadClass(className, cw.toByteArray()); } catch (Exception e) { throw new ConfigurationException("Failure loading ActorProxy", e); } }
From source file:sg.atom.core.actor.internal.codegenerator.BeanCreator.java
License:Apache License
/** * Write the fields of/*w w w . j a va2 s.c om*/ * * @Prop properties. * @param bcd the class descriptor * @param cw the ClassWriter to write to */ public static void writePropFields(BeanClassDescriptor bcd, ClassWriter cw) { for (int i = 0; i < bcd.getPropertyCount(); i++) { PropertyDescriptor pd = bcd.getProperty(i); if (pd.getPropertySource() != PropertySource.ABSTRACT_METHOD) { continue; } cw.visitField(Opcodes.ACC_PRIVATE + (pd.getAccess().isWritable() ? 0 : Opcodes.ACC_FINAL), String.format(PROP_FIELD_NAME_TEMPLATE, pd.getName()), Type.getDescriptor(pd.getPropertyClass()), GenericTypeHelper.getSignature(pd.getPropertyType()), null).visitEnd(); } }
From source file:the.bytecode.club.bytecodeviewer.decompilers.bytecode.ClassNodeDecompiler.java
License:Open Source License
public static String getAccessString(int access) { List<String> tokens = new ArrayList<String>(); if ((access & Opcodes.ACC_PUBLIC) != 0) tokens.add("public"); if ((access & Opcodes.ACC_PRIVATE) != 0) tokens.add("private"); if ((access & Opcodes.ACC_PROTECTED) != 0) tokens.add("protected"); if ((access & Opcodes.ACC_FINAL) != 0) tokens.add("final"); if ((access & Opcodes.ACC_SYNTHETIC) != 0) tokens.add("synthetic"); // if ((access & Opcodes.ACC_SUPER) != 0) // tokens.add("super"); implied by invokespecial insn if ((access & Opcodes.ACC_ABSTRACT) != 0) tokens.add("abstract"); if ((access & Opcodes.ACC_INTERFACE) != 0) tokens.add("interface"); if ((access & Opcodes.ACC_ENUM) != 0) tokens.add("enum"); if ((access & Opcodes.ACC_ANNOTATION) != 0) tokens.add("annotation"); if (!tokens.contains("interface") && !tokens.contains("enum") && !tokens.contains("annotation")) tokens.add("class"); if (tokens.size() == 0) return "[Error parsing]"; // hackery delimeters StringBuilder sb = new StringBuilder(tokens.get(0)); for (int i = 1; i < tokens.size(); i++) { sb.append(" "); sb.append(tokens.get(i));// w w w. j a v a 2s. c om } return sb.toString(); }
From source file:the.bytecode.club.bytecodeviewer.decompilers.bytecode.FieldNodeDecompiler.java
License:Open Source License
private static String getAccessString(int access) { List<String> tokens = new ArrayList<String>(); if ((access & Opcodes.ACC_PUBLIC) != 0) tokens.add("public"); if ((access & Opcodes.ACC_PRIVATE) != 0) tokens.add("private"); if ((access & Opcodes.ACC_PROTECTED) != 0) tokens.add("protected"); if ((access & Opcodes.ACC_SYNTHETIC) != 0) tokens.add("synthetic"); if ((access & Opcodes.ACC_STATIC) != 0) tokens.add("static"); if ((access & Opcodes.ACC_FINAL) != 0) tokens.add("final"); if ((access & Opcodes.ACC_TRANSIENT) != 0) tokens.add("transient"); if ((access & Opcodes.ACC_VOLATILE) != 0) tokens.add("volatile"); if (tokens.size() == 0) return ""; // hackery delimeters StringBuilder sb = new StringBuilder(tokens.get(0)); for (int i = 1; i < tokens.size(); i++) { sb.append(" "); sb.append(tokens.get(i));//from ww w. j av a2s.c o m } return sb.toString(); }
From source file:the.bytecode.club.bytecodeviewer.decompilers.bytecode.MethodNodeDecompiler.java
License:Open Source License
private static String getAccessString(int access) { // public, protected, private, abstract, static, // final, synchronized, native & strictfp are permitted List<String> tokens = new ArrayList<String>(); if ((access & Opcodes.ACC_PUBLIC) != 0) tokens.add("public"); if ((access & Opcodes.ACC_PRIVATE) != 0) tokens.add("private"); if ((access & Opcodes.ACC_PROTECTED) != 0) tokens.add("protected"); if ((access & Opcodes.ACC_STATIC) != 0) tokens.add("static"); if ((access & Opcodes.ACC_ABSTRACT) != 0) tokens.add("abstract"); if ((access & Opcodes.ACC_FINAL) != 0) tokens.add("final"); if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) tokens.add("synchronized"); if ((access & Opcodes.ACC_NATIVE) != 0) tokens.add("native"); if ((access & Opcodes.ACC_STRICT) != 0) tokens.add("strictfp"); if ((access & Opcodes.ACC_BRIDGE) != 0) tokens.add("bridge"); if ((access & Opcodes.ACC_VARARGS) != 0) tokens.add("varargs"); if (tokens.size() == 0) return ""; // hackery delimeters StringBuilder sb = new StringBuilder(tokens.get(0)); for (int i = 1; i < tokens.size(); i++) { sb.append(" "); sb.append(tokens.get(i));//w w w. j a v a 2 s . c o m } return sb.toString(); }
From source file:the.bytecode.club.bytecodeviewer.plugin.preinstalled.EZInjection.java
License:Open Source License
@SuppressWarnings("deprecation") @Override/* www. j a va2s . c o m*/ public void execute(ArrayList<ClassNode> classNodeList) { BytecodeViewer.viewer.setIcon(true); gui.setText(""); if (console) gui.setVisible(true); if (accessModifiers) print("Setting all of the access modifiers to public/public static."); if (injectHooks) print("Injecting hook..."); if (debugHooks) print("Hooks are debugging."); else if (injectHooks) print("Hooks are not debugging."); else print("Hooks are disabled completely."); if (useProxy) print("Forcing proxy as '" + proxy + "'."); if (launchKit) print("Launching the Graphicial Reflection Kit upon a succcessful invoke of the main method."); for (ClassNode classNode : classNodeList) { for (Object o : classNode.fields.toArray()) { FieldNode f = (FieldNode) o; if (accessModifiers) { if (f.access == Opcodes.ACC_PRIVATE || f.access == Opcodes.ACC_PROTECTED) f.access = Opcodes.ACC_PUBLIC; if (f.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC || f.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC) f.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC; if (f.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL || f.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL) f.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL; if (f.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC || f.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC) f.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC; } } for (Object o : classNode.methods.toArray()) { MethodNode m = (MethodNode) o; if (accessModifiers) { if (m.access == Opcodes.ACC_PRIVATE || m.access == Opcodes.ACC_PROTECTED) m.access = Opcodes.ACC_PUBLIC; if (m.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC || m.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC) m.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC; if (m.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL || m.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL) m.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL; if (m.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC || m.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC) m.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC; } if (injectHooks && m.access != Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PRIVATE + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PROTECTED + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_FINAL + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC + Opcodes.ACC_ABSTRACT) { boolean inject = true; if (m.instructions.size() >= 2 && m.instructions.get(1) instanceof MethodInsnNode) { MethodInsnNode mn = (MethodInsnNode) m.instructions.get(1); if (mn.owner.equals("the/bytecode/club/bytecodeviewer/plugins/EZInjection")) // already // been // injected inject = false; } if (inject) { // make this function grab parameters eventually m.instructions.insert(new MethodInsnNode(Opcodes.INVOKESTATIC, "the/bytecode/club/bytecodeviewer/plugins/EZInjection", "hook", "(Ljava/lang/String;)V")); m.instructions.insert(new LdcInsnNode(classNode.name + "." + m.name + m.desc)); } } } } if (useProxy) { try { String[] split = proxy.split(":"); setProxy(split[0], split[1]); } catch (Exception e) { // ignore } } print("Done setting up."); setFinished(); if (invokeMethod) { for (ClassNode cn : BytecodeViewer.getLoadedClasses()) // load all the classnodes into the classloader the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().addClass(cn); print("Invoking " + invokeMethodInformation + ":" + BytecodeViewer.nl + BytecodeViewer.nl); for (ClassNode classNode : classNodeList) { for (Object o : classNode.methods.toArray()) { MethodNode m = (MethodNode) o; String methodInformation = classNode.name + "." + m.name + m.desc; if (invokeMethodInformation.equals(methodInformation)) { for (Method m2 : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader() .nodeToClass(classNode).getMethods()) { if (m2.getName().equals(m.name)) { try { m2.invoke(classNode.getClass().newInstance(), (Object[]) new String[1]); if (launchKit) new GraphicialReflectionKit().setVisible(true); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); e.printStackTrace(); print(sw.toString()); } } } } } } } BytecodeViewer.viewer.setIcon(false); }
From source file:travis.model.project.structure.StructComponent.java
License:Open Source License
public boolean isFinal() { return StructUtil.isFlagSet(access, Opcodes.ACC_FINAL); }