List of usage examples for org.objectweb.asm Opcodes ACC_SUPER
int ACC_SUPER
To view the source code for org.objectweb.asm Opcodes ACC_SUPER.
Click Source Link
From source file:org.actorsguildframework.internal.codegenerator.BeanCreator.java
License:Apache License
/** * Creates and loads the bean's factory class. * @param beanClass the Bean class/*from w w w . j a v a2 s. c o m*/ * @param generatedBeanClassName the name of the class that this factory will produce * @param bcd the bean class descriptor * @param synchronizeInitializers true to synchronize the initializer invocations (actors * do this), false otherwise * @return the new factory */ public static BeanFactory generateFactoryClass(Class<?> beanClass, String generatedBeanClassName, BeanClassDescriptor bcd, boolean synchronizeInitializers) { String className = String.format("%s__BEANFACTORY", beanClass.getName()); String classNameInternal = className.replace('.', '/'); String generatedBeanClassNameInternal = generatedBeanClassName.replace('.', '/'); 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, "java/lang/Object", new String[] { Type.getInternalName(BeanFactory.class) }); cw.visitSource(null, null); { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); mv.visitInsn(Opcodes.RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + classNameInternal + ";", null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); } { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "createNewInstance", "(Lorg/actorsguildframework/internal/Controller;Lorg/actorsguildframework/Props;)Ljava/lang/Object;", null, null); mv.visitCode(); final int initCount = bcd.getInitializerCount(); Label tryStart = new Label(); Label tryEnd = new Label(); Label tryFinally = new Label(); Label tryFinallyEnd = new Label(); if (synchronizeInitializers && (initCount > 0)) { mv.visitTryCatchBlock(tryStart, tryEnd, tryFinally, null); mv.visitTryCatchBlock(tryFinally, tryFinallyEnd, tryFinally, null); } Label l0 = new Label(); mv.visitLabel(l0); mv.visitTypeInsn(Opcodes.NEW, generatedBeanClassNameInternal); mv.visitInsn(Opcodes.DUP); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, generatedBeanClassNameInternal, "<init>", "(Lorg/actorsguildframework/internal/Controller;Lorg/actorsguildframework/Props;)V"); if (synchronizeInitializers) { mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.MONITORENTER); mv.visitLabel(tryStart); } for (int i = 0; i < initCount; i++) { Method m = bcd.getInitializers(i); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, generatedBeanClassNameInternal, m.getName(), Type.getMethodDescriptor(m)); } if (synchronizeInitializers) { if (initCount > 0) { mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.MONITOREXIT); mv.visitLabel(tryEnd); mv.visitJumpInsn(Opcodes.GOTO, tryFinallyEnd); } mv.visitLabel(tryFinally); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.MONITOREXIT); mv.visitLabel(tryFinallyEnd); } mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + classNameInternal + ";", null, l0, l1, 0); mv.visitLocalVariable("controller", "Lorg/actorsguildframework/internal/Controller;", null, l0, l1, 1); mv.visitLocalVariable("props", "Lorg/actorsguildframework/Props;", null, l0, l1, 2); mv.visitLocalVariable("synchronizeInitializer", "Z", null, l0, l1, 3); mv.visitMaxs(4, 3); mv.visitEnd(); } cw.visitEnd(); Class<?> newClass = GenerationUtils.loadClass(className, cw.toByteArray()); try { return (BeanFactory) newClass.newInstance(); } catch (Exception e) { throw new ConfigurationException("Failure loading ActorProxyFactory", e); } }
From source file:org.actorsguildframework.internal.codegenerator.BeanCreator.java
License:Apache License
/** * Creates and loads the bean implementation class. * @param beanClass the bean class/*from w w w .j av a2 s . c o m*/ * @param bcd the BeanClassDescriptor to use * @throws ConfigurationException if the agent is not configured correctly */ private static Class<?> generateBeanClass(Class<?> beanClass, BeanClassDescriptor bcd) throws NoSuchMethodException { String className = String.format("%s__BEAN", beanClass.getName()); String classNameInternal = className.replace('.', '/'); 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(beanClass), new String[] {}); cw.visitSource(null, null); // write @Prop fields writePropFields(bcd, cw); // static constructor { mv = cw.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } // constructor(Controller, Props) writeConstructor(beanClass, bcd, classNameInternal, cw, null); // Write @Prop accessors writePropAccessors(bcd, classNameInternal, cw); cw.visitEnd(); try { return (Class<?>) GenerationUtils.loadClass(className, cw.toByteArray()); } catch (Exception e) { throw new ConfigurationException("Failure loading generated Bean", e); } }
From source file:org.adjective.stout.writer.ByteCodeWriter.java
License:Apache License
private int getModifierCode(Set<ElementModifier> modifiers, MemberType type) { int code = getModifierCode(modifiers, (Sort) null); int illegal = Opcodes.ACC_ANNOTATION | Opcodes.ACC_BRIDGE | Opcodes.ACC_ENUM | Opcodes.ACC_INTERFACE | Opcodes.ACC_SUPER; switch (type) { case FIELD:/*from w w w . j a va2s . c om*/ illegal |= Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE | Opcodes.ACC_STRICT | Opcodes.ACC_SYNCHRONIZED; break; case METHOD: if (isBitSet(Opcodes.ACC_ABSTRACT, code)) { illegal |= Opcodes.ACC_NATIVE | Opcodes.ACC_STRICT | Opcodes.ACC_SYNCHRONIZED | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL; } break; } if (isBitSet(illegal, code)) { throw new IllegalStateException( "Illegal combination of modifier codes: " + code + " (illegal codes: " + illegal + ")"); } return code; }
From source file:org.apache.cassandra.cql3.functions.UDFByteCodeVerifier.java
License:Apache License
public Set<String> verify(byte[] bytes) { Set<String> errors = new TreeSet<>(); // it's a TreeSet for unit tests ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM5) { public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { errors.add("field declared: " + name); return null; }//w w w . ja v a 2 s .com public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if ("<init>".equals(name) && CTOR_SIG.equals(desc)) { if (Opcodes.ACC_PUBLIC != access) errors.add("constructor not public"); // allowed constructor - JavaUDF(TypeCodec returnCodec, TypeCodec[] argCodecs) return new ConstructorVisitor(errors); } if ("executeImpl".equals(name) && "(ILjava/util/List;)Ljava/nio/ByteBuffer;".equals(desc)) { if (Opcodes.ACC_PROTECTED != access) errors.add("executeImpl not protected"); // the executeImpl method - ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params) return new ExecuteImplVisitor(errors); } if ("<clinit>".equals(name)) { errors.add("static initializer declared"); } else { errors.add("not allowed method declared: " + name + desc); return new ExecuteImplVisitor(errors); } return null; } public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { if (!JAVA_UDF_NAME.equals(superName)) { errors.add("class does not extend " + JavaUDF.class.getName()); } if (access != (Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER)) { errors.add("class not public final"); } super.visit(version, access, name, signature, superName, interfaces); } public void visitInnerClass(String name, String outerName, String innerName, int access) { errors.add("class declared as inner class"); super.visitInnerClass(name, outerName, innerName, access); } }; ClassReader classReader = new ClassReader(bytes); classReader.accept(classVisitor, ClassReader.SKIP_DEBUG); return errors; }
From source file:org.apache.commons.weaver.privilizer.ActionGenerator.java
License:Apache License
private void begin() { owner.visitInnerClass(action.getInternalName(), owner.className, simpleName, Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC); final SignatureWriter type = new SignatureWriter(); final SignatureVisitor actionImplemented = type.visitInterface(); actionImplemented.visitClassType(actionInterface.getInternalName()); final SignatureVisitor visitTypeArgument = actionImplemented.visitTypeArgument('='); new SignatureReader(Privilizer.wrap(methd.getReturnType()).getDescriptor()).accept(visitTypeArgument); actionImplemented.visitEnd();/*from ww w . j ava 2 s. com*/ final String signature = type.toString(); visit(Opcodes.V1_5, Opcodes.ACC_SUPER | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_FINAL, action.getInternalName(), signature, Type.getType(Object.class).getInternalName(), new String[] { actionInterface.getInternalName() }); }
From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java
License:Apache License
private static synchronized void createFixedAnyConstructor() { if (fixedAnyConstructor != null) { return;/*w w w. j a v a2s . com*/ } ASMHelper helper = new ASMHelper(); ClassWriter cw = helper.createClassWriter(); FieldVisitor fv; cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", null, "com/sun/corba/se/impl/corba/AnyImpl", null); cw.visitSource("FixedAnyImpl.java", null); fv = cw.visitField(0, "obj", "Lorg/omg/CORBA/portable/Streamable;", null, null); fv.visitEnd(); addFixedAnyConstructor(cw); addInsertOverride(cw); addExtractOverride(cw); addReadOverride(cw); addWriteOverride(cw); cw.visitEnd(); byte[] b = cw.toByteArray(); Class<?> c = helper.loadClass("org.apache.cxf.binding.corba.utils.FixedAnyImpl", CorbaAnyHelper.class, b); try { fixedAnyConstructor = c.getConstructor(ORB.class, Any.class); } catch (Exception e) { //shouldn't happen since we generated that constructor } }
From source file:org.apache.cxf.jaxb.JAXBUtils.java
License:Apache License
private static Class<?> createNamespaceWrapperInternal(ASMHelper helper, ClassWriter cw) { String className = "org.apache.cxf.jaxb.NamespaceMapperInternal"; FieldVisitor fv;// ww w . j a va 2 s.c o m MethodVisitor mv; cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, "org/apache/cxf/jaxb/NamespaceMapperInternal", null, "com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper", null); cw.visitSource("NamespaceMapper.java", null); fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "nspref", "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", null); fv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Ljava/util/Map;)V", "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V", null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(30, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper", "<init>", "()V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(31, l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, "org/apache/cxf/jaxb/NamespaceMapperInternal", "nspref", "Ljava/util/Map;"); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(32, l2); mv.visitInsn(Opcodes.RETURN); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapperInternal;", null, l0, l3, 0); mv.visitLocalVariable("nspref", "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", l0, l3, 1); mv.visitMaxs(2, 2); mv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPreferredPrefix", "(Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;", null, null); mv.visitCode(); l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(38, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/jaxb/NamespaceMapperInternal", "nspref", "Ljava/util/Map;"); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/String"); mv.visitVarInsn(Opcodes.ASTORE, 4); l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(39, l1); mv.visitVarInsn(Opcodes.ALOAD, 4); l2 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l2); l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(40, l3); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(l2); mv.visitLineNumber(42, l2); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitInsn(Opcodes.ARETURN); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapperInternal;", null, l0, l4, 0); mv.visitLocalVariable("namespaceUri", "Ljava/lang/String;", null, l0, l4, 1); mv.visitLocalVariable("suggestion", "Ljava/lang/String;", null, l0, l4, 2); mv.visitLocalVariable("requirePrefix", "Z", null, l0, l4, 3); mv.visitLocalVariable("prefix", "Ljava/lang/String;", null, l1, l4, 4); mv.visitMaxs(2, 5); mv.visitEnd(); cw.visitEnd(); byte bts[] = cw.toByteArray(); return helper.loadClass(className, JAXBUtils.class, bts); }
From source file:org.apache.cxf.jaxb.WrapperHelperCompiler.java
License:Apache License
public WrapperHelper compile() { if (cw == null) { return null; }/*from w w w . java 2 s . c om*/ int count = 1; String newClassName = wrapperType.getName() + "_WrapperTypeHelper" + count; newClassName = newClassName.replaceAll("\\$", "."); newClassName = periodToSlashes(newClassName); Class<?> cls = super.findClass(newClassName.replace('/', '.'), wrapperType); while (cls != null) { try { WrapperHelper helper = WrapperHelper.class.cast(cls.newInstance()); if (!helper.getSignature().equals(computeSignature())) { count++; newClassName = wrapperType.getName() + "_WrapperTypeHelper" + count; newClassName = newClassName.replaceAll("\\$", "."); newClassName = periodToSlashes(newClassName); cls = super.findClass(newClassName.replace('/', '.'), wrapperType); } else { return helper; } } catch (Exception e) { return null; } } cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, newClassName, null, "java/lang/Object", new String[] { periodToSlashes(WrapperHelper.class.getName()) }); addConstructor(newClassName, cw, objectFactory == null ? null : objectFactory.getClass()); boolean b = addSignature(); if (b) { b = addCreateWrapperObject(newClassName, objectFactory == null ? null : objectFactory.getClass()); } if (b) { b = addGetWrapperParts(newClassName, wrapperType, getMethods, fields, cw); } try { if (b) { cw.visitEnd(); byte bt[] = cw.toByteArray(); Class<?> cl = loadClass(newClassName.replace('/', '.'), wrapperType, bt); Object o = cl.newInstance(); return WrapperHelper.class.cast(o); } } catch (Throwable e) { // ignore, we'll just fall down to reflection based } return null; }
From source file:org.apache.cxf.jaxws.WrapperClassGenerator.java
License:Apache License
private void createWrapperClass(MessagePartInfo wrapperPart, MessageInfo messageInfo, OperationInfo op, Method method, boolean isRequest) { QName wrapperElement = messageInfo.getName(); boolean anonymous = factory.getAnonymousWrapperTypes(); ClassWriter cw = createClassWriter(); String pkg = getPackageName(method) + ".jaxws_asm" + (anonymous ? "_an" : ""); String className = pkg + "." + StringUtils.capitalize(op.getName().getLocalPart()); if (!isRequest) { className = className + "Response"; }//from w ww . j av a2 s. c o m String pname = pkg + ".package-info"; Class<?> def = findClass(pname, method.getDeclaringClass()); if (def == null) { generatePackageInfo(pname, wrapperElement.getNamespaceURI(), method.getDeclaringClass()); } def = findClass(className, method.getDeclaringClass()); if (def != null) { wrapperPart.setTypeClass(def); wrapperBeans.add(def); return; } String classFileName = periodToSlashes(className); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, classFileName, null, "java/lang/Object", null); AnnotationVisitor av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlRootElement;", true); av0.visit("name", wrapperElement.getLocalPart()); av0.visit("namespace", wrapperElement.getNamespaceURI()); av0.visitEnd(); av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlAccessorType;", true); av0.visitEnum("value", "Ljavax/xml/bind/annotation/XmlAccessType;", "FIELD"); av0.visitEnd(); av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlType;", true); if (!anonymous) { av0.visit("name", wrapperElement.getLocalPart()); av0.visit("namespace", wrapperElement.getNamespaceURI()); } else { av0.visit("name", ""); } av0.visitEnd(); // add constructor MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); Label lbegin = new Label(); mv.visitLabel(lbegin); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); mv.visitInsn(Opcodes.RETURN); Label lend = new Label(); mv.visitLabel(lend); mv.visitLocalVariable("this", "L" + classFileName + ";", null, lbegin, lend, 0); mv.visitMaxs(1, 1); mv.visitEnd(); for (MessagePartInfo mpi : messageInfo.getMessageParts()) { generateMessagePart(cw, mpi, method, classFileName); } cw.visitEnd(); Class<?> clz = loadClass(className, method.getDeclaringClass(), cw.toByteArray()); wrapperPart.setTypeClass(clz); wrapperBeans.add(clz); }
From source file:org.apache.deltaspike.partialbean.impl.proxy.AsmProxyClassGenerator.java
License:Apache License
private static byte[] generateProxyClassBytes(Class<?> targetClass, Class<? extends InvocationHandler> invocationHandlerClass, String proxyName, java.lang.reflect.Method[] redirectMethods, java.lang.reflect.Method[] interceptionMethods) { Class<?> superClass = targetClass; String[] interfaces = new String[] {}; if (targetClass.isInterface()) { superClass = Object.class; interfaces = new String[] { Type.getInternalName(targetClass) }; }//from w w w. jav a 2 s.c o m // add PartialBeanProxy as interface interfaces = Arrays.copyOf(interfaces, interfaces.length + 1); interfaces[interfaces.length - 1] = Type.getInternalName(PartialBeanProxy.class); Type superType = Type.getType(superClass); Type proxyType = Type.getObjectType(proxyName); Type invocationHandlerType = Type.getType(invocationHandlerClass); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, proxyType.getInternalName(), null, superType.getInternalName(), interfaces); // copy annotations for (Annotation annotation : targetClass.getDeclaredAnnotations()) { cw.visitAnnotation(Type.getDescriptor(annotation.annotationType()), true).visitEnd(); } defineInvocationHandlerField(cw, invocationHandlerType); defineConstructor(cw, proxyType, superType); definePartialBeanProxyMethods(cw, proxyType, invocationHandlerType); for (java.lang.reflect.Method method : redirectMethods) { defineMethod(cw, method, proxyType, invocationHandlerType, superType, true); } for (java.lang.reflect.Method method : interceptionMethods) { defineMethod(cw, method, proxyType, invocationHandlerType, superType, false); } return cw.toByteArray(); }