List of usage examples for org.objectweb.asm Opcodes F_SAME1
int F_SAME1
To view the source code for org.objectweb.asm Opcodes F_SAME1.
Click Source Link
From source file:io.syncframework.optimizer.OInterceptorStaticMethodVisitor.java
License:Apache License
public void visitInsn(int opcode) { if (opcode != Opcodes.RETURN) { mv.visitInsn(opcode);// www .j ava2 s .com return; } Label start = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitCode(); mv.visitTryCatchBlock(start, l1, l2, "java/lang/Throwable"); /* * _asParameters = new HashMap<String,Class<?>>() */ { mv.visitLabel(start); mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false); mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asParameters", "Ljava/util/Map;"); } /* * _asParameters.put("name", Type.class); */ for (String name : reflector.getParameters().keySet()) { Label l = new Label(); mv.visitLabel(l); mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asParameters", "Ljava/util/Map;"); mv.visitLdcInsn(name); mv.visitLdcInsn(Type.getType(reflector.getParameters().get(name))); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true); mv.visitInsn(Opcodes.POP); } /* * _asConverters = new HashMap<String,Class<?>>() */ { Label l = new Label(); mv.visitLabel(l); mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false); mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asConverters", "Ljava/util/Map;"); } /* * _asConverters.put("name", Type.class); */ for (String name : reflector.getParameters().keySet()) { if (reflector.getConverters().get(name) != null) { Class<?> converter = reflector.getConverters().get(name); Label l = new Label(); mv.visitLabel(l); mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asConverters", "Ljava/util/Map;"); mv.visitLdcInsn(name); mv.visitLdcInsn(Type.getType(converter)); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true); mv.visitInsn(Opcodes.POP); } } /* * } * catch(Throwable t) { * throw t; * } */ Label throwableStart = new Label(); Label throwableEnd = new Label(); mv.visitLabel(l1); mv.visitJumpInsn(Opcodes.GOTO, throwableEnd); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(Opcodes.ASTORE, 0); mv.visitLabel(throwableStart); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(throwableEnd); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.RETURN); mv.visitLocalVariable("t", "Ljava/lang/Throwable;", null, throwableStart, throwableEnd, 0); }
From source file:org.evosuite.testcarver.instrument.Instrumenter.java
License:Open Source License
/** * public int myMethod(int i)// www . ja va 2 s . com { try { return _sw_prototype_original_myMethod(i) } finally { Capturer.enable(); } } * @param classNode * @param className * @param methodNode */ @SuppressWarnings("unchecked") private MethodNode wrapMethod(final ClassNode classNode, final String className, final MethodNode methodNode) { methodNode.maxStack += 4; // create wrapper for original method final MethodNode wrappingMethodNode = new MethodNode(methodNode.access, methodNode.name, methodNode.desc, methodNode.signature, (String[]) methodNode.exceptions.toArray(new String[methodNode.exceptions.size()])); wrappingMethodNode.maxStack = methodNode.maxStack; // assign annotations to wrapping method wrappingMethodNode.visibleAnnotations = methodNode.visibleAnnotations; wrappingMethodNode.visibleParameterAnnotations = methodNode.visibleParameterAnnotations; // remove annotations from wrapped method to avoid wrong behavior controlled by annotations methodNode.visibleAnnotations = null; methodNode.visibleParameterAnnotations = null; // rename original method methodNode.access = TransformerUtil.modifyVisibility(methodNode.access, Opcodes.ACC_PRIVATE); final LabelNode l0 = new LabelNode(); final LabelNode l1 = new LabelNode(); final LabelNode l2 = new LabelNode(); final InsnList wInstructions = wrappingMethodNode.instructions; if ("<init>".equals(methodNode.name)) { // wrap a constructor methodNode.name = WRAP_NAME_PREFIX + "init" + WRAP_NAME_PREFIX; // move call to other constructors to new method AbstractInsnNode ins = null; ListIterator<AbstractInsnNode> iter = methodNode.instructions.iterator(); int numInvokeSpecials = 0; // number of invokespecial calls before actual constructor call while (iter.hasNext()) { ins = iter.next(); iter.remove(); wInstructions.add(ins); if (ins instanceof MethodInsnNode) { MethodInsnNode mins = (MethodInsnNode) ins; if (ins.getOpcode() == Opcodes.INVOKESPECIAL) { if (mins.name.startsWith("<init>")) { if (numInvokeSpecials == 0) { break; } else { numInvokeSpecials--; } } } } else if (ins instanceof TypeInsnNode) { TypeInsnNode typeIns = (TypeInsnNode) ins; if (typeIns.getOpcode() == Opcodes.NEW || typeIns.getOpcode() == Opcodes.NEWARRAY) { numInvokeSpecials++; } } } } else { methodNode.name = WRAP_NAME_PREFIX + methodNode.name; } int varReturnValue = 0; final Type returnType = Type.getReturnType(methodNode.desc); if (returnType.equals(Type.VOID_TYPE)) { wrappingMethodNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l1, "java/lang/Throwable")); } else { wrappingMethodNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Throwable")); //--- create "Object returnValue = null;" if (!TransformerUtil.isStatic(methodNode.access)) { // load "this" varReturnValue++; } // consider method arguments to find right variable index final Type[] argTypes = Type.getArgumentTypes(methodNode.desc); for (int i = 0; i < argTypes.length; i++) { varReturnValue++; // long/double take two registers if (argTypes[i].equals(Type.LONG_TYPE) || argTypes[i].equals(Type.DOUBLE_TYPE)) { varReturnValue++; } } // push NULL on the stack and initialize variable for return value for it wInstructions.add(new InsnNode(Opcodes.ACONST_NULL)); wInstructions.add(new VarInsnNode(Opcodes.ASTORE, varReturnValue)); } int var = 0; // --- L0 wInstructions.add(l0); wInstructions.add(this.addCaptureCall(TransformerUtil.isStatic(methodNode.access), className, wrappingMethodNode.name, wrappingMethodNode.desc, Type.getArgumentTypes(methodNode.desc))); // --- construct call to wrapped methode if (!TransformerUtil.isStatic(methodNode.access)) { // load "this" to call method wInstructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); var++; } final Type[] argTypes = Type.getArgumentTypes(methodNode.desc); for (int i = 0; i < argTypes.length; i++) { this.addLoadInsn(wInstructions, argTypes[i], var++); // long/double take two registers if (argTypes[i].equals(Type.LONG_TYPE) || argTypes[i].equals(Type.DOUBLE_TYPE)) { var++; } } if (TransformerUtil.isStatic(methodNode.access)) { wInstructions.add( new MethodInsnNode(Opcodes.INVOKESTATIC, classNode.name, methodNode.name, methodNode.desc)); } else { wInstructions.add( new MethodInsnNode(Opcodes.INVOKEVIRTUAL, classNode.name, methodNode.name, methodNode.desc)); } var++; if (returnType.equals(Type.VOID_TYPE)) { wInstructions.add(new JumpInsnNode(Opcodes.GOTO, l2)); // --- L1 wInstructions.add(l1); wInstructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" })); wInstructions.add(new VarInsnNode(Opcodes.ASTORE, --var)); this.addCaptureEnableStatement(className, methodNode, wInstructions, -1); wInstructions.add(new VarInsnNode(Opcodes.ALOAD, var)); wInstructions.add(new InsnNode(Opcodes.ATHROW)); // FIXME <--- DUPLICATE CODE // --- L2 wInstructions.add(l2); wInstructions.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null)); this.addCaptureEnableStatement(className, methodNode, wInstructions, -1); wInstructions.add(new InsnNode(Opcodes.RETURN)); } else { // construct store of the wrapped method call's result this.addBoxingStmt(wInstructions, returnType); wInstructions.add(new VarInsnNode(Opcodes.ASTORE, varReturnValue)); wInstructions.add(new VarInsnNode(Opcodes.ALOAD, varReturnValue)); this.addUnBoxingStmt(wInstructions, returnType); final int storeOpcode = returnType.getOpcode(Opcodes.ISTORE); wInstructions.add(new VarInsnNode(storeOpcode, ++var)); // might be only var // --- L1 wInstructions.add(l1); this.addCaptureEnableStatement(className, methodNode, wInstructions, varReturnValue); // construct load of the wrapped method call's result int loadOpcode = returnType.getOpcode(Opcodes.ILOAD); wInstructions.add(new VarInsnNode(loadOpcode, var)); // construct return of the wrapped method call's result this.addReturnInsn(wInstructions, returnType); //---- L2 wInstructions.add(l2); wInstructions.add( new FrameNode(Opcodes.F_FULL, 2, new Object[] { className, this.getInternalName(returnType) }, 1, new Object[] { "java/lang/Throwable" })); wInstructions.add(new VarInsnNode(Opcodes.ASTORE, --var)); this.addCaptureEnableStatement(className, methodNode, wInstructions, varReturnValue); wInstructions.add(new VarInsnNode(Opcodes.ALOAD, var)); wInstructions.add(new InsnNode(Opcodes.ATHROW)); } transformWrapperCalls(methodNode); return wrappingMethodNode; }
From source file:org.fabric3.implementation.bytecode.proxy.common.ProxyFactoryImpl.java
License:Open Source License
public <T, D extends ProxyDispatcher> T createProxy(URI classLoaderKey, Class<T> type, Method[] methods, Class<D> dispatcherInt, Class<? extends D> dispatcherTmpl, boolean wrapped) throws ProxyException { String className = type.getName() + "_Proxy_" + dispatcherInt.getSimpleName(); // ensure multiple dispatchers can be defined for the same interface // check if the proxy class has already been created BytecodeClassLoader generationLoader = getClassLoader(classLoaderKey); try {//from w w w . ja v a2s .c o m Class<T> proxyClass = (Class<T>) generationLoader.loadClass(className); return proxyClass.newInstance(); } catch (ClassNotFoundException e) { // ignore } catch (InstantiationException e) { throw new ProxyException(e); } catch (IllegalAccessException e) { throw new ProxyException(e); } verifyTemplate(dispatcherTmpl); String classNameInternal = Type.getInternalName(type) + "_Proxy_" + dispatcherInt.getSimpleName(); String thisDescriptor = "L" + classNameInternal + ";"; String dispatcherIntName = Type.getInternalName(dispatcherInt); //Important to use class version of template class that will be copied. If class compiled with JDK 1.5 but copied //to class version 1.7 there will be errors since 1.7 enforces frame stackmaps which were not present in 1.5 int version = getClassVersion(generationLoader, dispatcherTmpl); ClassWriter cw = new ClassWriter(0); MethodVisitor mv; if (type.isInterface()) { String interfazeName = Type.getInternalName(type); cw.visit(version, ACC_PUBLIC + ACC_SUPER, classNameInternal, null, "java/lang/Object", new String[] { dispatcherIntName, interfazeName }); cw.visitSource(type.getName() + "Proxy.java", null); String baseName = Type.getInternalName(Object.class); // write the ctor writeConstructor(baseName, thisDescriptor, cw); } else { verifyBaseClass(type, methods); String baseTypeName = Type.getInternalName(type); cw.visit(version, ACC_PUBLIC + ACC_SUPER, classNameInternal, null, baseTypeName, new String[] { dispatcherIntName }); cw.visitSource(type.getName() + "Proxy.java", null); String baseName = Type.getInternalName(type); // write the ctor writeConstructor(baseName, thisDescriptor, cw); } copyTemplate(generationLoader, classNameInternal, dispatcherTmpl, cw); // write the methods int methodIndex = 0; for (Method method : methods) { //if the method is not overridable do not generate a bytecode method for it. This means any invocation of the class will directly act upon the //the base class or proxy class but since these methods should not be visible anyway it shouldn't matter. The exception could be equals/hashcode/toString/clone if (!isOverridableMethod(method)) { methodIndex++; continue; } String methodSignature = Type.getMethodDescriptor(method); String[] exceptions = new String[method.getExceptionTypes().length]; for (int i = 0; i < exceptions.length; i++) { exceptions[i] = Type.getInternalName(method.getExceptionTypes()[i]); } int visibility = Modifier.isPublic(method.getModifiers()) ? ACC_PUBLIC : Modifier.isProtected(method.getModifiers()) ? ACC_PROTECTED : 0; mv = cw.visitMethod(visibility, method.getName(), methodSignature, null, exceptions); mv.visitCode(); List<Label> exceptionLabels = new ArrayList<Label>(); Label label2 = new Label(); Label label3 = new Label(); for (String exception : exceptions) { Label endLabel = new Label(); exceptionLabels.add(endLabel); mv.visitTryCatchBlock(label2, label3, endLabel, exception); } mv.visitLabel(label2); mv.visitVarInsn(ALOAD, 0); // set the method index used to dispatch on if (methodIndex >= 0 && methodIndex <= 5) { // use an integer constant if within range mv.visitInsn(Opcodes.ICONST_0 + methodIndex); } else { mv.visitIntInsn(Opcodes.BIPUSH, methodIndex); } methodIndex++; int[] index = new int[1]; index[0] = 0; int[] stack = new int[1]; stack[0] = 1; if (method.getParameterTypes().length == 0) { // no params, load null mv.visitInsn(Opcodes.ACONST_NULL); } else { if (wrapped) { emitWrappedParameters(method, mv, index, stack); } else { emitUnWrappedParameters(method, mv, index, stack); } } mv.visitMethodInsn(INVOKEVIRTUAL, classNameInternal, "_f3_invoke", "(ILjava/lang/Object;)Ljava/lang/Object;"); // handle return values writeReturn(method, label3, mv); // implement catch blocks index[0] = 0; for (String exception : exceptions) { Label endLabel = exceptionLabels.get(index[0]); mv.visitLabel(endLabel); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { exception }); mv.visitVarInsn(ASTORE, wrapped ? stack[0] : 1); Label label6 = new Label(); mv.visitLabel(label6); mv.visitVarInsn(ALOAD, wrapped ? stack[0] : 1); mv.visitInsn(ATHROW); index[0]++; } Label label7 = new Label(); mv.visitLabel(label7); mv.visitMaxs(7, 5); mv.visitEnd(); } cw.visitEnd(); byte[] data = cw.toByteArray(); //ClassReader classReader = new ClassReader(data); //classReader.accept(new org.objectweb.asm.util.TraceClassVisitor(null, new org.objectweb.asm.util.ASMifier(), new java.io.PrintWriter(System.out)), 0); Class<?> proxyClass = generationLoader.defineClass(className, data); try { return (T) proxyClass.newInstance(); } catch (InstantiationException e) { throw new ProxyException(e); } catch (IllegalAccessException e) { throw new ProxyException(e); } }
From source file:org.glassfish.pfl.tf.tools.enhancer.SimpleMethodTracer.java
License:Open Source License
private String getFrameType(int type) { switch (type) { case Opcodes.F_APPEND: return "APPEND"; case Opcodes.F_CHOP: return "CHOP"; case Opcodes.F_FULL: return "FULL"; case Opcodes.F_NEW: return "NEW"; case Opcodes.F_SAME: return "SAME"; case Opcodes.F_SAME1: return "SAME1"; }//from ww w . j a va2 s.c o m return "BAD_FRAME_TYPE"; }
From source file:org.kjots.json.object.JsonObjectGeneratorBase.java
License:Apache License
/** * Generate a get Java primitive property method. * * @param classVisitor The class visitor. * @param jsonObjectImplType The type of the JSON object implementation. * @param method The method.//from w w w . j av a 2s . c o m * @param propertyName The name of the property. * @param jsonPrimitiveType The type of the JSON primitive. * @param javaPrimitiveType The type of the Java primitive. */ private void generateGetJavaPrimitivePropertyMethod(ClassVisitor classVisitor, Type jsonObjectImplType, Method method, String propertyName, Type jsonPrimitiveType, Type javaPrimitiveType) { MethodVisitor methodVisitor = classVisitor.visitMethod(ACC_PUBLIC + ACC_FINAL, method, null, null); Label start = new Label(); Label l0 = new Label(); Label l1 = new Label(); Label end = new Label(); methodVisitor.visitCode(); methodVisitor.visitLabel(start); methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitLdcInsn(propertyName); methodVisitor.visitMethodInsn(INVOKEVIRTUAL, jsonObjectImplType, this.getGetJsonPrimitivePropertyMethod(jsonPrimitiveType)); methodVisitor.visitVarInsn(ASTORE, 1); methodVisitor.visitVarInsn(ALOAD, 1); methodVisitor.visitJumpInsn(IFNULL, l0); methodVisitor.visitVarInsn(ALOAD, 1); methodVisitor.visitMethodInsn(INVOKEVIRTUAL, jsonPrimitiveType, this.getToJavaPrimitiveMethod(javaPrimitiveType)); methodVisitor.visitJumpInsn(GOTO, l1); methodVisitor.visitLabel(l0); methodVisitor.visitFrame(Opcodes.F_APPEND, 1, new Object[] { jsonPrimitiveType }, 0, null); methodVisitor.visitInsn(this.getDefaultConstOpcode(javaPrimitiveType)); methodVisitor.visitLabel(l1); methodVisitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { this.getStackElement(javaPrimitiveType) }); methodVisitor.visitInsn(javaPrimitiveType.getOpcode(IRETURN)); methodVisitor.visitLabel(end); methodVisitor.visitLocalVariable("this", jsonObjectImplType, null, start, end, 0); methodVisitor.visitLocalVariable("_" + propertyName, jsonPrimitiveType, null, start, end, 1); methodVisitor.visitMaxs(2, 2); methodVisitor.visitEnd(); }
From source file:org.kjots.json.object.JsonObjectGeneratorBase.java
License:Apache License
/** * Generate a get Java character primitive property method. * * @param classVisitor The class visitor. * @param jsonObjectImplType The type of the JSON object implementation. * @param method The method./* w w w . java2 s.co m*/ * @param propertyName The name of the property. */ private void generateGetJavaCharacterPrimitivePropertyMethod(ClassVisitor classVisitor, Type jsonObjectImplType, Method method, String propertyName) { Type jsonStringPrimitiveType = Type.getType(String.class); MethodVisitor methodVisitor = classVisitor.visitMethod(ACC_PUBLIC + ACC_FINAL, method, null, null); Label start = new Label(); Label l0 = new Label(); Label l1 = new Label(); Label end = new Label(); methodVisitor.visitCode(); methodVisitor.visitLabel(start); methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitLdcInsn(propertyName); methodVisitor.visitMethodInsn(INVOKEVIRTUAL, jsonObjectImplType, this.getGetJsonPrimitivePropertyMethod(jsonStringPrimitiveType)); methodVisitor.visitVarInsn(ASTORE, 1); methodVisitor.visitVarInsn(ALOAD, 1); methodVisitor.visitJumpInsn(IFNULL, l0); methodVisitor.visitVarInsn(ALOAD, 1); methodVisitor.visitMethodInsn(INVOKEVIRTUAL, jsonStringPrimitiveType, new Method("isEmpty", Type.BOOLEAN_TYPE, new Type[] {})); methodVisitor.visitJumpInsn(IFNE, l0); methodVisitor.visitVarInsn(ALOAD, 1); methodVisitor.visitInsn(ICONST_0); methodVisitor.visitMethodInsn(INVOKEVIRTUAL, jsonStringPrimitiveType, new Method("charAt", Type.CHAR_TYPE, new Type[] { Type.INT_TYPE })); methodVisitor.visitJumpInsn(GOTO, l1); methodVisitor.visitLabel(l0); methodVisitor.visitFrame(Opcodes.F_APPEND, 1, new Object[] { jsonStringPrimitiveType }, 0, null); methodVisitor.visitInsn(ICONST_0); methodVisitor.visitLabel(l1); methodVisitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER }); methodVisitor.visitInsn(IRETURN); methodVisitor.visitLabel(end); methodVisitor.visitLocalVariable("this", jsonObjectImplType, null, start, end, 0); methodVisitor.visitLocalVariable("_" + propertyName, jsonStringPrimitiveType, null, start, end, 1); methodVisitor.visitMaxs(2, 2); methodVisitor.visitEnd(); }
From source file:org.kjots.json.object.JsonObjectGeneratorBase.java
License:Apache License
/** * Generate a get composite JSON object property method. * * @param classVisitor The class visitor. * @param jsonObjectImplType The type of the JSON object implementation. * @param method The method./*from w w w .j a v a2s. c o m*/ * @param propertyName The name of the property. * @param jsonObjectType The type of the JSON object. * @param elementType The type of the element. */ private void generateGetCompositeJsonObjectPropertyMethod(ClassVisitor classVisitor, Type jsonObjectImplType, Method method, String propertyName, Type jsonObjectType, Type elementType) { MethodVisitor methodVisitor = classVisitor.visitMethod(ACC_PUBLIC + ACC_FINAL, method, null, null); Label start = new Label(); Label l0 = new Label(); Label l1 = new Label(); Label end = new Label(); methodVisitor.visitCode(); methodVisitor.visitLabel(start); methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitLdcInsn(propertyName); methodVisitor.visitLdcInsn(jsonObjectType); methodVisitor.visitMethodInsn(INVOKEVIRTUAL, jsonObjectImplType, this.getGetJsonObjectPropertyMethod()); methodVisitor.visitTypeInsn(CHECKCAST, jsonObjectType); methodVisitor.visitVarInsn(ASTORE, 1); methodVisitor.visitVarInsn(ALOAD, 1); methodVisitor.visitJumpInsn(IFNULL, l0); methodVisitor.visitVarInsn(ALOAD, 1); methodVisitor.visitLdcInsn(elementType); methodVisitor.visitMethodInsn(INVOKEINTERFACE, jsonObjectType, this.getCastCompositeJsonObjectElementMethod(jsonObjectType)); methodVisitor.visitJumpInsn(GOTO, l1); methodVisitor.visitLabel(l0); methodVisitor.visitFrame(Opcodes.F_APPEND, 1, new Object[] { jsonObjectType }, 0, null); methodVisitor.visitInsn(ACONST_NULL); methodVisitor.visitLabel(l1); methodVisitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { jsonObjectType }); methodVisitor.visitInsn(ARETURN); methodVisitor.visitLabel(end); methodVisitor.visitLocalVariable("this", jsonObjectImplType, null, start, end, 0); methodVisitor.visitLocalVariable("_" + propertyName, jsonObjectType, null, start, end, 1); methodVisitor.visitMaxs(3, 2); methodVisitor.visitEnd(); }
From source file:org.qi4j.runtime.composite.FragmentClassLoader.java
License:Open Source License
public static byte[] generateClass(String name, Class baseClass) throws ClassNotFoundException { String classSlash = name.replace('.', '/'); String baseClassSlash = getInternalName(baseClass); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); // Class definition start cw.visit(jdkVersion, ACC_PUBLIC + ACC_SUPER, classSlash, null, baseClassSlash, null); // Composite reference {/*from w ww.j a va 2s . c o m*/ cw.visitField(ACC_PUBLIC, "_instance", "Lorg/qi4j/api/composite/CompositeInvoker;", null, null) .visitEnd(); } // Static Method references boolean hasProxyMethods = false; { int idx = 1; for (Method method : baseClass.getMethods()) { if (isOverridden(method, baseClass)) { cw.visitField(ACC_PRIVATE + ACC_STATIC, "m" + idx++, "Ljava/lang/reflect/Method;", null, null) .visitEnd(); hasProxyMethods = true; } } } // Constructors for (Constructor constructor : baseClass.getDeclaredConstructors()) { if (Modifier.isPublic(constructor.getModifiers()) || Modifier.isProtected(constructor.getModifiers())) { String desc = org.objectweb.asm.commons.Method.getMethod(constructor).getDescriptor(); MethodVisitor cmv = cw.visitMethod(ACC_PUBLIC, "<init>", desc, null, null); cmv.visitCode(); cmv.visitVarInsn(ALOAD, 0); int idx = 1; for (Class aClass : constructor.getParameterTypes()) { final int opcode; if (aClass.equals(Integer.TYPE)) { opcode = ILOAD; } else if (aClass.equals(Long.TYPE)) { opcode = LLOAD; } else if (aClass.equals(Float.TYPE)) { opcode = FLOAD; } else if (aClass.equals(Double.TYPE)) { opcode = DLOAD; } else { opcode = ALOAD; } cmv.visitVarInsn(opcode, idx++); } cmv.visitMethodInsn(INVOKESPECIAL, baseClassSlash, "<init>", desc); cmv.visitInsn(RETURN); cmv.visitMaxs(idx, idx); cmv.visitEnd(); } } // Overloaded and unimplemented methods if (hasProxyMethods) { Method[] methods = baseClass.getMethods(); int idx = 0; List<Label> exceptionLabels = new ArrayList<Label>(); for (Method method : methods) { if (isOverridden(method, baseClass)) { idx++; String methodName = method.getName(); String desc = org.objectweb.asm.commons.Method.getMethod(method).getDescriptor(); String[] exceptions = null; { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, desc, null, exceptions); if (isInternalQi4jMethod(method, baseClass)) { // generate a NoOp method... mv.visitInsn(RETURN); } else { Label endLabel = null; // Use this if return type is void if (method.getExceptionTypes().length > 0) { exceptions = new String[method.getExceptionTypes().length]; for (int i = 0; i < method.getExceptionTypes().length; i++) { Class<?> aClass = method.getExceptionTypes()[i]; exceptions[i] = getInternalName(aClass); } } mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); exceptionLabels.clear(); for (Class<?> declaredException : method.getExceptionTypes()) { Label ld = new Label(); mv.visitTryCatchBlock(l0, l1, ld, getInternalName(declaredException)); exceptionLabels.add(ld); // Reuse this further down for the catch } Label lruntime = new Label(); mv.visitTryCatchBlock(l0, l1, lruntime, "java/lang/RuntimeException"); Label lerror = new Label(); mv.visitTryCatchBlock(l0, l1, lerror, "java/lang/Throwable"); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, classSlash, "_instance", "Lorg/qi4j/api/composite/CompositeInvoker;"); mv.visitFieldInsn(GETSTATIC, classSlash, "m" + idx, "Ljava/lang/reflect/Method;"); int paramCount = method.getParameterTypes().length; int stackIdx = 0; if (paramCount == 0) { // Send in null as parameter mv.visitInsn(ACONST_NULL); } else { insn(mv, paramCount); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); int pidx = 0; for (Class<?> aClass : method.getParameterTypes()) { mv.visitInsn(DUP); insn(mv, pidx++); stackIdx = wrapParameter(mv, aClass, stackIdx + 1); mv.visitInsn(AASTORE); } } // Call method mv.visitMethodInsn(INVOKEINTERFACE, "org/qi4j/api/composite/CompositeInvoker", "invokeComposite", "(Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"); // Return value if (!method.getReturnType().equals(Void.TYPE)) { unwrapResult(mv, method.getReturnType(), l1); } else { mv.visitInsn(POP); mv.visitLabel(l1); endLabel = new Label(); mv.visitJumpInsn(GOTO, endLabel); } // Increase stack to beyond method args stackIdx++; // Declared exceptions int exceptionIdx = 0; for (Class<?> aClass : method.getExceptionTypes()) { mv.visitLabel(exceptionLabels.get(exceptionIdx++)); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { getInternalName(aClass) }); mv.visitVarInsn(ASTORE, stackIdx); mv.visitVarInsn(ALOAD, stackIdx); mv.visitInsn(ATHROW); } // RuntimeException and Error catch-all mv.visitLabel(lruntime); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/RuntimeException" }); mv.visitVarInsn(ASTORE, stackIdx); mv.visitVarInsn(ALOAD, stackIdx); mv.visitInsn(ATHROW); mv.visitLabel(lerror); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, stackIdx); mv.visitVarInsn(ALOAD, stackIdx); mv.visitTypeInsn(CHECKCAST, "java/lang/Error"); mv.visitInsn(ATHROW); // Return type = void if (endLabel != null) { mv.visitLabel(endLabel); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); } mv.visitMaxs(0, 0); mv.visitEnd(); } } if (!Modifier.isAbstract(method.getModifiers())) { // Add method with _ as prefix MethodVisitor mv; mv = cw.visitMethod(ACC_PUBLIC, "_" + method.getName(), desc, null, exceptions); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); // Parameters int stackIdx = 1; for (Class<?> aClass : method.getParameterTypes()) { stackIdx = loadParameter(mv, aClass, stackIdx) + 1; } // Call method mv.visitMethodInsn(INVOKESPECIAL, baseClassSlash, method.getName(), desc); // Return value if (!method.getReturnType().equals(Void.TYPE)) { returnResult(mv, method.getReturnType()); } else { mv.visitInsn(RETURN); } mv.visitMaxs(1, 1); mv.visitEnd(); } } } // Class initializer { MethodVisitor mv; mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchMethodException"); mv.visitLabel(l0); // Lookup methods and store in static variables int midx = 0; for (Method method : methods) { if (isOverridden(method, baseClass)) { method.setAccessible(true); Class methodClass; if (Modifier.isAbstract(method.getModifiers())) { methodClass = method.getDeclaringClass(); } else { try { methodClass = getInterfaceMethodDeclaration(method, baseClass); // Overridden method lookup } catch (NoSuchMethodException e) { throw new ClassNotFoundException(name, e); } } midx++; mv.visitLdcInsn(Type.getType(methodClass)); mv.visitLdcInsn(method.getName()); insn(mv, method.getParameterTypes().length); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); int pidx = 0; for (Class<?> aClass : method.getParameterTypes()) { mv.visitInsn(DUP); insn(mv, pidx++); type(mv, aClass); mv.visitInsn(AASTORE); } mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); mv.visitFieldInsn(PUTSTATIC, classSlash, "m" + midx, "Ljava/lang/reflect/Method;"); } } mv.visitLabel(l1); Label l3 = new Label(); mv.visitJumpInsn(GOTO, l3); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchMethodException" }); mv.visitVarInsn(ASTORE, 0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/NoSuchMethodException", "printStackTrace", "()V"); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(6, 1); mv.visitEnd(); } } cw.visitEnd(); return cw.toByteArray(); }
From source file:org.qi4j.runtime.composite.TransientClassLoader.java
License:Open Source License
public static byte[] generateClass(String name, Class baseClass) throws ClassNotFoundException { String classSlash = name.replace('.', '/'); String baseClassSlash = getInternalName(baseClass); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); FieldVisitor fv;//from w w w . jav a 2 s. com MethodVisitor mv; AnnotationVisitor av0; // Class definition start cw.visit(jdkVersion, ACC_PUBLIC + ACC_SUPER, classSlash, null, baseClassSlash, null); // Composite reference { fv = cw.visitField(ACC_PUBLIC, "_instance", "Lorg/qi4j/api/composite/CompositeInvoker;", null, null); fv.visitEnd(); } // Static Method references { int idx = 1; for (Method method : baseClass.getMethods()) { if (isOverloaded(method, baseClass)) { fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "m" + idx++, "Ljava/lang/reflect/Method;", null, null); fv.visitEnd(); } } } // Constructors for (Constructor constructor : baseClass.getDeclaredConstructors()) { if (Modifier.isPublic(constructor.getModifiers()) || Modifier.isProtected(constructor.getModifiers())) { String desc = org.objectweb.asm.commons.Method.getMethod(constructor).getDescriptor(); mv = cw.visitMethod(ACC_PUBLIC, "<init>", desc, null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); int idx = 1; for (Class aClass : constructor.getParameterTypes()) { // TODO Handle other types than objects (?) mv.visitVarInsn(ALOAD, idx++); } mv.visitMethodInsn(INVOKESPECIAL, baseClassSlash, "<init>", desc); mv.visitInsn(RETURN); mv.visitMaxs(idx, idx); mv.visitEnd(); } } // Overloaded and unimplemented methods Method[] methods = baseClass.getMethods(); int idx = 0; List<Label> exceptionLabels = new ArrayList<Label>(); for (Method method : methods) { if (isOverloaded(method, baseClass)) { idx++; String methodName = method.getName(); String desc = org.objectweb.asm.commons.Method.getMethod(method).getDescriptor(); String[] exceptions = null; { mv = cw.visitMethod(ACC_PUBLIC, methodName, desc, null, exceptions); if (isInternalQi4jMethod(method, baseClass)) { // generate a NoOp method... mv.visitInsn(RETURN); } else { Label endLabel = null; // Use this if return type is void if (method.getExceptionTypes().length > 0) { exceptions = new String[method.getExceptionTypes().length]; for (int i = 0; i < method.getExceptionTypes().length; i++) { Class<?> aClass = method.getExceptionTypes()[i]; exceptions[i] = getInternalName(aClass); } } mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); exceptionLabels.clear(); for (Class<?> declaredException : method.getExceptionTypes()) { Label ld = new Label(); mv.visitTryCatchBlock(l0, l1, ld, getInternalName(declaredException)); exceptionLabels.add(ld); // Reuse this further down for the catch } Label lruntime = new Label(); mv.visitTryCatchBlock(l0, l1, lruntime, "java/lang/RuntimeException"); Label lerror = new Label(); mv.visitTryCatchBlock(l0, l1, lerror, "java/lang/Throwable"); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, classSlash, "_instance", "Lorg/qi4j/api/composite/CompositeInvoker;"); mv.visitFieldInsn(GETSTATIC, classSlash, "m" + idx, "Ljava/lang/reflect/Method;"); int paramCount = method.getParameterTypes().length; int stackIdx = 0; if (paramCount == 0) { // Send in null as parameter mv.visitInsn(ACONST_NULL); } else { insn(mv, paramCount); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); int pidx = 0; for (Class<?> aClass : method.getParameterTypes()) { mv.visitInsn(DUP); insn(mv, pidx++); stackIdx = wrapParameter(mv, aClass, stackIdx + 1); mv.visitInsn(AASTORE); } } // Call method mv.visitMethodInsn(INVOKEINTERFACE, "org/qi4j/api/composite/CompositeInvoker", "invokeComposite", "(Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"); // Return value if (!method.getReturnType().equals(Void.TYPE)) { unwrapResult(mv, method.getReturnType(), l1); } else { mv.visitInsn(POP); mv.visitLabel(l1); endLabel = new Label(); mv.visitJumpInsn(GOTO, endLabel); } // Increase stack to beyond method args stackIdx++; // Declared exceptions int exceptionIdx = 0; for (Class<?> aClass : method.getExceptionTypes()) { mv.visitLabel(exceptionLabels.get(exceptionIdx++)); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { getInternalName(aClass) }); mv.visitVarInsn(ASTORE, stackIdx); mv.visitVarInsn(ALOAD, stackIdx); mv.visitInsn(ATHROW); } // RuntimeException and Error catch-all mv.visitLabel(lruntime); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/RuntimeException" }); mv.visitVarInsn(ASTORE, stackIdx); mv.visitVarInsn(ALOAD, stackIdx); mv.visitInsn(ATHROW); mv.visitLabel(lerror); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, stackIdx); mv.visitVarInsn(ALOAD, stackIdx); mv.visitTypeInsn(CHECKCAST, "java/lang/Error"); mv.visitInsn(ATHROW); // Return type = void if (endLabel != null) { mv.visitLabel(endLabel); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); } mv.visitMaxs(0, 0); mv.visitEnd(); } } if (!Modifier.isAbstract(method.getModifiers())) { // Add method with _ as prefix mv = cw.visitMethod(ACC_PUBLIC, "_" + method.getName(), desc, null, exceptions); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); // Parameters int stackIdx = 1; for (Class<?> aClass : method.getParameterTypes()) { stackIdx = loadParameter(mv, aClass, stackIdx) + 1; } // Call method mv.visitMethodInsn(INVOKESPECIAL, baseClassSlash, method.getName(), desc); // Return value if (!method.getReturnType().equals(Void.TYPE)) { returnResult(mv, method.getReturnType()); } else { mv.visitInsn(RETURN); } mv.visitMaxs(1, 1); mv.visitEnd(); } } } // Class initializer { mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchMethodException"); mv.visitLabel(l0); // Lookup methods and store in static variables int midx = 0; for (Method method : methods) { if (isOverloaded(method, baseClass)) { method.setAccessible(true); Class methodClass; methodClass = method.getDeclaringClass(); midx++; mv.visitLdcInsn(Type.getType(methodClass)); mv.visitLdcInsn(method.getName()); insn(mv, method.getParameterTypes().length); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); int pidx = 0; for (Class<?> aClass : method.getParameterTypes()) { mv.visitInsn(DUP); insn(mv, pidx++); type(mv, aClass); mv.visitInsn(AASTORE); } mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); mv.visitFieldInsn(PUTSTATIC, classSlash, "m" + midx, "Ljava/lang/reflect/Method;"); } } mv.visitLabel(l1); Label l3 = new Label(); mv.visitJumpInsn(GOTO, l3); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchMethodException" }); mv.visitVarInsn(ASTORE, 0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/NoSuchMethodException", "printStackTrace", "()V"); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(6, 1); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }
From source file:org.qi4j.test.ASMTest.java
License:Open Source License
public static byte[] generateClass() { ClassWriter cw = new ClassWriter(0); FieldVisitor fv;/* w w w.j a v a 2s .c o m*/ MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "org/qi4j/satisfiedBy/SomeMixin_Stub", null, "org/qi4j/satisfiedBy/SomeMixin", null); { fv = cw.visitField(ACC_PUBLIC, "_instance", "Lorg/qi4j/spi/composite/CompositeInvoker;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "m1", "Ljava/lang/reflect/Method;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "m2", "Ljava/lang/reflect/Method;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "m3", "Ljava/lang/reflect/Method;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "m4", "Ljava/lang/reflect/Method;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "m5", "Ljava/lang/reflect/Method;", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "org/qi4j/satisfiedBy/SomeMixin", "<init>", "()V"); mv.visitInsn(RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(Ljava/lang/String;)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, "org/qi4j/satisfiedBy/SomeMixin", "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(RETURN); mv.visitMaxs(2, 2); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "other", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable"); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "org/qi4j/satisfiedBy/SomeMixin_Stub", "_instance", "Lorg/qi4j/spi/composite/CompositeInvoker;"); mv.visitFieldInsn(GETSTATIC, "org/qi4j/satisfiedBy/SomeMixin_Stub", "m1", "Ljava/lang/reflect/Method;"); mv.visitInsn(ACONST_NULL); mv.visitMethodInsn(INVOKEINTERFACE, "org/qi4j/spi/composite/CompositeInvoker", "invokeComposite", "(Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/lang/String"); mv.visitLabel(l1); mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, 1); mv.visitTypeInsn(NEW, "java/lang/reflect/UndeclaredThrowableException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/reflect/UndeclaredThrowableException", "<init>", "(Ljava/lang/Throwable;)V"); mv.visitInsn(ATHROW); mv.visitMaxs(3, 2); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "foo", "(Ljava/lang/String;I)Ljava/lang/String;", null, new String[] { "java/lang/IllegalArgumentException" }); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/IllegalArgumentException"); Label l3 = new Label(); mv.visitTryCatchBlock(l0, l1, l3, "java/lang/Throwable"); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "org/qi4j/satisfiedBy/SomeMixin_Stub", "_instance", "Lorg/qi4j/spi/composite/CompositeInvoker;"); mv.visitFieldInsn(GETSTATIC, "org/qi4j/satisfiedBy/SomeMixin_Stub", "m2", "Ljava/lang/reflect/Method;"); mv.visitInsn(ICONST_2); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitInsn(DUP); mv.visitInsn(ICONST_0); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitVarInsn(ILOAD, 2); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKEINTERFACE, "org/qi4j/spi/composite/CompositeInvoker", "invokeComposite", "(Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/lang/String"); mv.visitLabel(l1); mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/IllegalArgumentException" }); mv.visitVarInsn(ASTORE, 3); mv.visitVarInsn(ALOAD, 3); mv.visitInsn(ATHROW); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, 3); mv.visitTypeInsn(NEW, "java/lang/reflect/UndeclaredThrowableException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/reflect/UndeclaredThrowableException", "<init>", "(Ljava/lang/Throwable;)V"); mv.visitInsn(ATHROW); mv.visitMaxs(6, 4); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "bar", "(DZFCIJSBLjava/lang/Double;[Ljava/lang/Object;[I)V", null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable"); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "org/qi4j/satisfiedBy/SomeMixin_Stub", "_instance", "Lorg/qi4j/spi/composite/CompositeInvoker;"); mv.visitFieldInsn(GETSTATIC, "org/qi4j/satisfiedBy/SomeMixin_Stub", "m3", "Ljava/lang/reflect/Method;"); mv.visitIntInsn(BIPUSH, 11); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitInsn(DUP); mv.visitInsn(ICONST_0); mv.visitVarInsn(DLOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitVarInsn(ILOAD, 3); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_2); mv.visitVarInsn(FLOAD, 4); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_3); mv.visitVarInsn(ILOAD, 5); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_4); mv.visitVarInsn(ILOAD, 6); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_5); mv.visitVarInsn(LLOAD, 7); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 6); mv.visitVarInsn(ILOAD, 9); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 7); mv.visitVarInsn(ILOAD, 10); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 8); mv.visitVarInsn(ALOAD, 11); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 9); mv.visitVarInsn(ALOAD, 12); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 10); mv.visitVarInsn(ALOAD, 13); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKEINTERFACE, "org/qi4j/spi/composite/CompositeInvoker", "invokeComposite", "(Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(POP); mv.visitLabel(l1); Label l3 = new Label(); mv.visitJumpInsn(GOTO, l3); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, 14); mv.visitTypeInsn(NEW, "java/lang/reflect/UndeclaredThrowableException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 14); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/reflect/UndeclaredThrowableException", "<init>", "(Ljava/lang/Throwable;)V"); mv.visitInsn(ATHROW); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(7, 15); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "multiEx", "(Ljava/lang/String;)V", null, new String[] { "org/qi4j/satisfiedBy/Exception1", "org/qi4j/satisfiedBy/Exception2" }); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "org/qi4j/satisfiedBy/Exception1"); Label l3 = new Label(); mv.visitTryCatchBlock(l0, l1, l3, "org/qi4j/satisfiedBy/Exception2"); Label l4 = new Label(); mv.visitTryCatchBlock(l0, l1, l4, "java/lang/Throwable"); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "org/qi4j/satisfiedBy/SomeMixin_Stub", "_instance", "Lorg/qi4j/spi/composite/CompositeInvoker;"); mv.visitFieldInsn(GETSTATIC, "org/qi4j/satisfiedBy/SomeMixin_Stub", "m4", "Ljava/lang/reflect/Method;"); mv.visitInsn(ICONST_1); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitInsn(DUP); mv.visitInsn(ICONST_0); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKEINTERFACE, "org/qi4j/spi/composite/CompositeInvoker", "invokeComposite", "(Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(POP); mv.visitLabel(l1); Label l5 = new Label(); mv.visitJumpInsn(GOTO, l5); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "org/qi4j/satisfiedBy/Exception1" }); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); mv.visitInsn(ATHROW); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "org/qi4j/satisfiedBy/Exception2" }); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); mv.visitInsn(ATHROW); mv.visitLabel(l4); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, 2); mv.visitTypeInsn(NEW, "java/lang/reflect/UndeclaredThrowableException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/reflect/UndeclaredThrowableException", "<init>", "(Ljava/lang/Throwable;)V"); mv.visitInsn(ATHROW); mv.visitLabel(l5); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(6, 3); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "unwrapResult", "()I", null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable"); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "org/qi4j/satisfiedBy/SomeMixin_Stub", "_instance", "Lorg/qi4j/spi/composite/CompositeInvoker;"); mv.visitFieldInsn(GETSTATIC, "org/qi4j/satisfiedBy/SomeMixin_Stub", "m5", "Ljava/lang/reflect/Method;"); mv.visitInsn(ACONST_NULL); mv.visitMethodInsn(INVOKEINTERFACE, "org/qi4j/spi/composite/CompositeInvoker", "invokeComposite", "(Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/lang/Integer"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I"); mv.visitLabel(l1); mv.visitInsn(IRETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, 1); mv.visitTypeInsn(NEW, "java/lang/reflect/UndeclaredThrowableException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/reflect/UndeclaredThrowableException", "<init>", "(Ljava/lang/Throwable;)V"); mv.visitInsn(ATHROW); mv.visitMaxs(3, 2); mv.visitEnd(); } { mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchMethodException"); mv.visitLabel(l0); mv.visitLdcInsn(Type.getType("Lorg/qi4j/satisfiedBy/Other;")); mv.visitLdcInsn("other"); mv.visitInsn(ICONST_0); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); mv.visitFieldInsn(PUTSTATIC, "org/qi4j/satisfiedBy/SomeMixin_Stub", "m1", "Ljava/lang/reflect/Method;"); mv.visitLdcInsn(Type.getType("Lorg/qi4j/satisfiedBy/Other;")); mv.visitLdcInsn("foo"); mv.visitInsn(ICONST_2); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); mv.visitInsn(DUP); mv.visitInsn(ICONST_0); mv.visitLdcInsn(Type.getType("Ljava/lang/String;")); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); mv.visitFieldInsn(PUTSTATIC, "org/qi4j/satisfiedBy/SomeMixin_Stub", "m2", "Ljava/lang/reflect/Method;"); mv.visitLdcInsn(Type.getType("Lorg/qi4j/satisfiedBy/Other;")); mv.visitLdcInsn("bar"); mv.visitIntInsn(BIPUSH, 11); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); mv.visitInsn(DUP); mv.visitInsn(ICONST_0); mv.visitFieldInsn(GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_2); mv.visitFieldInsn(GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_3); mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_4); mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_5); mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 6); mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 7); mv.visitFieldInsn(GETSTATIC, "java/lang/Byte", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 8); mv.visitLdcInsn(Type.getType("Ljava/lang/Double;")); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 9); mv.visitLdcInsn(Type.getType("[Ljava/lang/Object;")); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 10); mv.visitLdcInsn(Type.getType("[I")); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); mv.visitFieldInsn(PUTSTATIC, "org/qi4j/satisfiedBy/SomeMixin_Stub", "m3", "Ljava/lang/reflect/Method;"); mv.visitLdcInsn(Type.getType("Lorg/qi4j/satisfiedBy/Other;")); mv.visitLdcInsn("multiEx"); mv.visitInsn(ICONST_1); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); mv.visitInsn(DUP); mv.visitInsn(ICONST_0); mv.visitLdcInsn(Type.getType("Ljava/lang/String;")); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); mv.visitFieldInsn(PUTSTATIC, "org/qi4j/satisfiedBy/SomeMixin_Stub", "m4", "Ljava/lang/reflect/Method;"); mv.visitLdcInsn(Type.getType("Lorg/qi4j/satisfiedBy/Other;")); mv.visitLdcInsn("unwrapResult"); mv.visitInsn(ICONST_0); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); mv.visitFieldInsn(PUTSTATIC, "org/qi4j/satisfiedBy/SomeMixin_Stub", "m5", "Ljava/lang/reflect/Method;"); mv.visitLabel(l1); Label l3 = new Label(); mv.visitJumpInsn(GOTO, l3); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchMethodException" }); mv.visitVarInsn(ASTORE, 0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/NoSuchMethodException", "printStackTrace", "()V"); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(6, 1); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }