felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r635395 - in /felix/sandbox/clement/ipojo: core/src/main/java/org/apache/felix/ipojo/ core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ manipulator/src/main/java/org/apache/felix/ipojo/manipulation/
Date Sun, 09 Mar 2008 23:39:18 GMT
Author: clement
Date: Sun Mar  9 16:39:15 2008
New Revision: 635395

URL: http://svn.apache.org/viewvc?rev=635395&view=rev
Log:
Add argument access during method interception
Modify service usage to improve the service field injection

Modified:
    felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
    felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
    felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
    felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
    felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
    felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java
    felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java?rev=635395&r1=635394&r2=635395&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
(original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
Sun Mar  9 16:39:15 2008
@@ -439,7 +439,7 @@
         m_componentDesc = null;
         m_componentInstances.clear();
     }
-    
+
     /**
      * Destroy the factory. The factory cannot be restarted.
      * Only the extender can call this method.

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java?rev=635395&r1=635394&r2=635395&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
(original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
Sun Mar  9 16:39:15 2008
@@ -18,7 +18,6 @@
  */
 package org.apache.felix.ipojo;
 
-import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
@@ -503,16 +502,18 @@
                 try {
                     Constructor cst = m_clazz.getDeclaredConstructor(new Class[] { InstanceManager.class,
BundleContext.class });
                     cst.setAccessible(true);
-                    onEntry(null, m_className);
-                    instance = cst.newInstance(new Object[] { this, m_context });
+                    Object[] args = new Object[] { this, m_context }; //TODO hide the instance
manager.
+                    onEntry(null, m_className,  args);
+                    instance = cst.newInstance(args);
                     onExit(null, m_className, instance);
                 } catch (NoSuchMethodException e) {
                     // Create an instance if no instance are already created with <init>()BundleContext
                     if (instance == null) {
                         Constructor cst = m_clazz.getDeclaredConstructor(new Class[] { InstanceManager.class
});
                         cst.setAccessible(true);
-                        onEntry(null, m_className);
-                        instance = cst.newInstance(new Object[] { this });
+                        Object[] args = new Object[] { this }; // TODO hide the instance
manager.
+                        onEntry(null, m_className, args);
+                        instance = cst.newInstance(args);
                         onExit(null, m_className, instance);
                     }
                 }
@@ -558,15 +559,17 @@
                 try {
                     factory = m_clazz.getDeclaredMethod(m_factoryMethod, new Class[] { BundleContext.class
});
                     factory.setAccessible(true);
-                    onEntry(null, m_className);
+                    Object[] args = new Object[] { m_context };
+                    onEntry(null, m_className, args);
                     instance = factory.invoke(null, new Object[] { m_context });
                 } catch (NoSuchMethodException e1) {
                     // Try without the bundle context
                     try {
                         factory = m_clazz.getDeclaredMethod(m_factoryMethod, new Class[0]);
                         factory.setAccessible(true);
-                        onEntry(null, m_className);
-                        instance = factory.invoke(null, new Object[0]);
+                        Object[] args = new Object[0];
+                        onEntry(null, m_className, args);
+                        instance = factory.invoke(null, args);
                     } catch (NoSuchMethodException e2) {
                         // Error : factory-method not found
                         m_factory.getLogger().log(
@@ -753,15 +756,16 @@
      * Dispatch entry method event on registered handler.
      * @param pojo : the pojo object on which method is invoked.
      * @param methodId : method id
+     * @param args : argument array
      */
-    public void onEntry(Object pojo, String methodId) {
+    public void onEntry(Object pojo, String methodId, Object[] args) {
         if (m_methodRegistration == null) {
             return;
         }
         PrimitiveHandler[] list = (PrimitiveHandler[]) m_methodRegistration.get(methodId);
         Method method = getMethodById(methodId);
         for (int i = 0; list != null && i < list.length; i++) {
-            list[i].onEntry(pojo, method);
+            list[i].onEntry(pojo, method, args);
         }
     }
 
@@ -794,6 +798,9 @@
      * @param error : throwable object.
      */
     public void onError(Object pojo, String methodId, Throwable error) {
+        System.out.println("Error detected in the pojo : " + pojo + " - " + error.getMessage());
+        error.printStackTrace();
+        
         if (m_methodRegistration == null) {
             return;
         }

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java?rev=635395&r1=635394&r2=635395&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
(original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
Sun Mar  9 16:39:15 2008
@@ -119,8 +119,9 @@
      * This method is called when the execution enter in a method.
      * @param pojo : pojo on which the method is called.
      * @param method : method invoked.
+     * @param args arguments array.
      */
-    public void onEntry(Object pojo, Method method) { 
+    public void onEntry(Object pojo, Method method, Object[] args) { 
         // Nothing do do in the default implementation
     }
 

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java?rev=635395&r1=635394&r2=635395&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
(original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
Sun Mar  9 16:39:15 2008
@@ -28,6 +28,7 @@
 import org.apache.felix.ipojo.InstanceManager;
 import org.apache.felix.ipojo.Nullable;
 import org.apache.felix.ipojo.PolicyServiceContext;
+import org.apache.felix.ipojo.handlers.dependency.ServiceUsage.Usage;
 import org.apache.felix.ipojo.util.DependencyModel;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Filter;
@@ -52,17 +53,17 @@
     /**
      * List of dependency callback.
      */
-    private DependencyCallback[] m_callbacks = new DependencyCallback[0];
+    private DependencyCallback[] m_callbacks;
 
     /**
      * Is the dependency a service level dependency.
      */
-    private boolean m_isServiceLevelRequirement = false;
+    private boolean m_isServiceLevelRequirement;
 
     /**
      * Is the provider set frozen ?
      */
-    private boolean m_isFrozen = false;
+    private boolean m_isFrozen;
 
     /**
      * Is the dependency started ?
@@ -72,7 +73,7 @@
     /**
      * Thread Local.
      */
-    private ServiceUsage m_usage = new ServiceUsage();
+    private ServiceUsage m_usage;
 
     /**
      * Nullable object.
@@ -107,7 +108,10 @@
     public Dependency(DependencyHandler handler, String field, Class spec, Filter filter,
boolean isOptional, boolean isAggregate, String identity, BundleContext context, int policy,
Comparator cmp, String defaultImplem) {
         super(spec, isAggregate, isOptional, filter, cmp, policy, context, handler);
         m_handler = handler;
-        m_field = field;
+        if (field != null) {
+            m_field = field;
+            m_usage = new ServiceUsage();
+        }
         m_di = defaultImplem;
 
         if (identity == null) {
@@ -143,13 +147,13 @@
      * @param callback : callback to add
      */
     protected void addDependencyCallback(DependencyCallback callback) {
-        if (m_callbacks.length > 0) {
+        if (m_callbacks == null) {
+            m_callbacks = new DependencyCallback[] { callback };
+        } else {
             DependencyCallback[] newCallbacks = new DependencyCallback[m_callbacks.length
+ 1];
             System.arraycopy(m_callbacks, 0, newCallbacks, 0, m_callbacks.length);
             newCallbacks[m_callbacks.length] = callback;
             m_callbacks = newCallbacks;
-        } else {
-            m_callbacks = new DependencyCallback[] { callback };
         }
     }
 
@@ -173,6 +177,8 @@
     public DependencyHandler getHandler() {
         return m_handler;
     }
+    
+
 
     /**
      * This method is called by the replaced code in the component
@@ -183,32 +189,42 @@
      */
     Object get() {
         // Initialize the thread local object is not already touched.
-        if (m_usage.getObjects().isEmpty()) {
-            if (isAggregate()) {
-                ServiceReference[] refs = super.getServiceReferences();
-                for (int i = 0; refs != null && i < refs.length; i++) {
-                    ServiceReference ref = refs[i];
-                    m_usage.addUsage(getService(ref), ref);
+        Usage usage = (Usage) m_usage.get();
+        if (usage.m_stack == 0) { // uninitialized usage.
+            ServiceReference[] refs = super.getServiceReferences();
+            if (isAggregate()) { // If we are aggregate we get the objects.
+                if (refs == null) {
+                    usage.m_objects = (Object[]) Array.newInstance(getSpecification(), 0);
// Create an empty array.
+                } else {
+                   // Use a reflective construction to avoid class cast exception. This method
allow to set the component type.
+                    usage.m_objects = (Object[]) Array.newInstance(getSpecification(), refs.length);

+                    for (int i = 0; refs != null && i < refs.length; i++) {
+                        ServiceReference ref = refs[i];
+                        usage.m_objects[i] = getService(ref);
+                    }
                 }
-            } else {
-                if (getSize() == 0) {
+            } else { // We are singular.
+                // Use a reflective construction to avoid class cast exception. This method
allow to set the component type.
+                usage.m_objects = (Object[]) Array.newInstance(getSpecification(), 1);
+                if (refs == null) {
                     if (m_nullable == null) {
                         m_handler.warn("[" + m_handler.getInstanceManager().getInstanceName()
+ "] The dependency is not optional, however no service object can be injected in " + m_field
+ " -> " + getSpecification().getName());
                         return null;
                     }
-                    m_usage.getObjects().add(m_nullable);
+                    usage.m_objects[0] = m_nullable;
                 } else {
                     ServiceReference ref = getServiceReference();
-                    m_usage.addUsage(getService(ref), ref);
+                    usage.m_objects[0] = getService(ref);
                 }
             }
-            m_usage.setStackLevel(1);
+            usage.inc(); // Start the tracking, so fix the stack level to 1
+            m_usage.set(usage);
         }
 
         if (isAggregate()) { // Multiple dependency
-            return (Object[]) m_usage.getObjects().toArray((Object[]) Array.newInstance(getSpecification(),
m_usage.getObjects().size()));
+            return usage.m_objects;
         } else {
-            return m_usage.getObjects().get(0);
+            return usage.m_objects[0];
         }
     }
 
@@ -232,7 +248,7 @@
         if (isOptional() && getSize() == 0) { return; }
 
         // Call bind callback.
-        for (int j = 0; j < m_callbacks.length; j++) {
+        for (int j = 0; m_callbacks != null && j < m_callbacks.length; j++) {
             if (m_callbacks[j].getMethodType() == DependencyCallback.BIND) {
                 if (isAggregate()) {
                     ServiceReference[] refs = getServiceReferences();
@@ -255,7 +271,7 @@
      */
     private void callUnbindMethod(ServiceReference ref) {
         if (m_handler.getInstanceManager().getState() > InstanceManager.STOPPED &&
m_handler.getInstanceManager().getPojoObjects() != null) {
-            for (int i = 0; i < m_callbacks.length; i++) {
+            for (int i = 0; m_callbacks != null && i < m_callbacks.length; i++)
{
                 if (m_callbacks[i].getMethodType() == DependencyCallback.UNBIND) {
                     invokeCallback(m_callbacks[i], ref, null); // Call on each created pojo
objects.
                 }
@@ -297,18 +313,18 @@
         // call bind method :
         // if (m_handler.getInstanceManager().getState() == InstanceManager.VALID) {
         if (m_handler.getInstanceManager().getState() > InstanceManager.STOPPED &&
m_handler.getInstanceManager().getPojoObjects() != null) {
-            for (int i = 0; i < m_callbacks.length; i++) {
+            for (int i = 0; m_callbacks != null && i < m_callbacks.length; i++)
{
                 if (m_callbacks[i].getMethodType() == DependencyCallback.BIND) {
                     invokeCallback(m_callbacks[i], ref, null);
                 }
             }
         }
     }
-
+    
     /**
      * Start the dependency.
      */
-    public void start() {
+    public void start() {        
         if (isOptional() && !isAggregate()) {
             if (m_di == null) {
                 // To load the proxy we use the POJO class loader. Indeed, this classloader
imports iPOJO (so can access to Nullable) and has access to the service specification.
@@ -361,9 +377,18 @@
      * Method called when a thread enters in a method.
      */
     public void entry() {
-        if (!m_usage.getObjects().isEmpty()) {
-            int level = m_usage.getStackLevel();
-            m_usage.setStackLevel(level++);
+        if (m_usage == null) {
+            //DEBUG
+            if (m_field != null) {
+                System.out.println("Eror in dependency : field " + m_field + " but no usage");
+            }
+            return;
+        }
+        
+        Usage usage = (Usage) m_usage.get();
+        if (usage.m_stack > 0) {
+            usage.inc();
+            m_usage.set(usage); // Set the Thread local as value has been modified 
         }
     }
 
@@ -371,12 +396,20 @@
      * Method called when a thread exits a method.
      */
     public void exit() {
-        if (!m_usage.getObjects().isEmpty()) {
-            int level = m_usage.getStackLevel();
-            level = level - 1;
-            if (level == 0) {
-                // Exit the method flow => Release all object
-                m_usage.clearUsage();
+        if (m_usage == null) {
+            //DEBUG
+            if (m_field != null) {
+                System.out.println("Eror in dependency : field " + m_field + " but no usage");
+            }
+            return;
+        }
+        
+        Usage usage = (Usage) m_usage.get();
+        if (usage.m_stack > 0) {
+            if (usage.dec()) {
+                // Exit the method flow => Release all objects
+                usage.clear();
+                m_usage.set(usage); // Set the Thread local as value has been modified
             }
         }
     }

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java?rev=635395&r1=635394&r2=635395&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
(original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
Sun Mar  9 16:39:15 2008
@@ -154,11 +154,11 @@
         String field = dep.getField();
         DependencyCallback[] callbacks = dep.getCallbacks();
 
-        if (callbacks.length == 0 && field == null) {
+        if (callbacks == null && field == null) {
             throw new ConfigurationException("A service requirement requires at least callbacks
or a field");
         }
 
-        for (int i = 0; i < callbacks.length; i++) {
+        for (int i = 0; callbacks != null && i < callbacks.length; i++) {
             MethodMetadata[] mets = manipulation.getMethods(callbacks[i].getMethodName());
             if (mets.length == 0) {
                 info("A requirement callback " + callbacks[i].getMethodName() + " does not
exist in the implementation, try the super classes");
@@ -354,10 +354,8 @@
             }
         }
 
-        if (deps.length > 0) {
+        if (! fields.isEmpty()) { // Does register only if we have fields
             getInstanceManager().register(this, (FieldMetadata[]) fields.toArray(new FieldMetadata[fields.size()]),
manipulation.getMethods());
-        } else {
-            throw new ConfigurationException("No dependencies found in " + getInstanceManager().getInstanceName());
         }
     }
 
@@ -372,8 +370,7 @@
     public Object onGet(Object pojo, String fieldName, Object value) {
         for (int i = 0; i < m_dependencies.length; i++) {
             Dependency dep = m_dependencies[i];
-            String field = dep.getField();
-            if (field != null && field.equals(fieldName)) {
+            if (fieldName.equals(dep.getField())) {
                 // The field name is a dependency, return the get
                 return dep.get();
             }
@@ -386,14 +383,12 @@
      * Method Entry callback.
      * @param pojo : pojo object on which the method is invoked.
      * @param method : method object representing the invoked method.
-     * @see org.apache.felix.ipojo.Handler#onEntry(Object, Method)
+     * @param args : argument array
+     * @see org.apache.felix.ipojo.Handler#onEntry(Object, Method, Object[])
      */
-    public void onEntry(Object pojo, Method method) {
+    public void onEntry(Object pojo, Method method, Object[] args) {
         for (int i = 0; i < m_dependencies.length; i++) {
-            Dependency dep = m_dependencies[i];
-            if (dep.getField() != null) {
-                dep.entry();
-            }
+            m_dependencies[i].entry();
         }
     }
 
@@ -405,10 +400,7 @@
      */
     public void onFinally(Object pojo, Method method) {
         for (int i = 0; i < m_dependencies.length; i++) {
-            Dependency dep = m_dependencies[i];
-            if (dep.getField() != null) { // Only field injection require to be notified.

-                dep.exit();
-            }
+            m_dependencies[i].exit();
         }
     }
 

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java?rev=635395&r1=635394&r2=635395&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java
(original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java
Sun Mar  9 16:39:15 2008
@@ -18,10 +18,6 @@
  */
 package org.apache.felix.ipojo.handlers.dependency;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.osgi.framework.ServiceReference;
 
 /**
  * Object managing thread local copy of required services.
@@ -33,20 +29,39 @@
     /**
      * Structure contained in the Thread Local.
      */
-    private class Usage {
+    public class Usage {
         
         /**
          * Stack Size.
          */
-        Integer m_stack = new Integer(0);
+        int m_stack = 0;
         /**
-         * List of used service references.
+         * List of used objects.
          */
-        List m_refs = new ArrayList();
+        Object[] m_objects;
+        
         /**
-         * List of used objects.
+         * Increment the statck level.
+         */
+        public void inc() {
+            m_stack++;
+        }
+        
+        /**
+         * Decrement the stack level.
+         * @return  true if the stack is 0 after the decrement.
+         */
+        public boolean dec() {
+            m_stack--;
+            return m_stack == 0;
+        }
+        
+        /**
+         * Clear the service object array.
          */
-        List m_objects = new ArrayList();
+        public void clear() {
+            m_objects = null;
+        }
         
     }
     
@@ -57,66 +72,6 @@
      */
     public Object initialValue() {
         return new Usage();
-    }
-    
-    /**
-     * Get the list of stored references.
-     * @return the list of stored references.
-     */
-    public List getReferences() {
-        return ((Usage) super.get()).m_refs;
-    }
-    
-    /**
-     * Get the lost of stored object.
-     * @return the list of stored service objects.
-     */
-    public List getObjects() {
-        return ((Usage) super.get()).m_objects;
-    }
-    
-    /**
-     * Add a service usage. 
-     * @param object : object used
-     * @param ref : service reference
-     */
-    public void addUsage(Object object, ServiceReference ref) {
-        Usage use = (Usage) get();
-        use.m_objects.add(object);
-        use.m_refs.add(ref);
-        set(use);
-    }
-    
-    /**
-     * Delete all service usage.
-     */
-    public void clearUsage() {
-        Usage use = (Usage) get();
-        use.m_objects.clear();
-        use.m_refs.clear();
-        set(use);
-    }
-    
-    /**
-     * Get the stack level.
-     * @return the stack level.
-     */
-    public int getStackLevel() {
-        Usage use = (Usage) get();
-        return use.m_stack.intValue();
-    }
-    
-    /**
-     * Set the stack level.
-     * @param level : the new stack level.
-     */
-    public void setStackLevel(int level) {
-        Usage use = (Usage) get();
-        use.m_stack = new Integer(level);
-        set(use);
-    }
-    
-    
-    
+    }   
 
 }

Modified: felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java?rev=635395&r1=635394&r2=635395&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
(original)
+++ felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
Sun Mar  9 16:39:15 2008
@@ -275,26 +275,23 @@
      * @param exceptions : declared exceptions.
      */
     private void generateMethodHeader(int access, String name, String desc, String signature,
String[] exceptions) {
-        MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
+        GeneratorAdapter mv = new GeneratorAdapter(cv.visitMethod(access, name, desc, signature,
exceptions), access, name, desc); 
+        
         mv.visitCode();
         Type returnType = Type.getReturnType(desc);
-        Type[] args = Type.getArgumentTypes(desc);
 
         // Compute result and exception stack location
         int result = -1;
         int exception = -1;
-
-        int argLength = 0;
-        for (int i = 0; i < args.length; i++) {
-            argLength += args[i].getSize(); // Use getSize to shift in case of J, F and D.
-        }
+        
+        //int arguments = mv.newLocal(Type.getType((new Object[0]).getClass()));
 
         if (returnType.getSort() != Type.VOID) {
             // The method returns something 
-            result = argLength + 1; //  The result will to be store after the arguments 
-            exception = argLength + returnType.getSize() + 1; // The exception (if occurs)
will be stored after the arguments and the result.
+            result = mv.newLocal(returnType);
+            exception = mv.newLocal(Type.getType(Throwable.class));
         } else {
-            exception = argLength + 1;  //  The exception will be stored after the arguments
+            exception = mv.newLocal(Type.getType(Throwable.class));
         }
 
         Label l0 = new Label();
@@ -308,30 +305,25 @@
         mv.visitJumpInsn(IFNE, l0);
 
         mv.visitVarInsn(ALOAD, 0);
-        // Put every arguments on stack.
-        int j = 1;
-        for (int i = 0; i < args.length; i++) {
-            mv.visitVarInsn(args[i].getOpcode(ILOAD), j);
-            j += args[i].getSize();
-        }
+        mv.loadArgs();
         mv.visitMethodInsn(INVOKESPECIAL, m_owner, PREFIX + name, desc);
         mv.visitInsn(returnType.getOpcode(IRETURN));
 
+        // end of the non intercepted method invocation.
+        
         mv.visitLabel(l0);
-
+        
         mv.visitVarInsn(ALOAD, 0);
         mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
         mv.visitVarInsn(ALOAD, 0);
         mv.visitLdcInsn(generateMethodId(name, desc));
-        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", ENTRY,
"(Ljava/lang/Object;Ljava/lang/String;)V");
-
-        mv.visitVarInsn(ALOAD, 0);
-        // Put every arguments on stack.
-        j = 1;
-        for (int i = 0; i < args.length; i++) {
-            mv.visitVarInsn(args[i].getOpcode(ILOAD), j);
-            j += args[i].getSize();
-        }
+        mv.loadArgArray();
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", ENTRY,
"(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V");
+        
+        mv.visitVarInsn(ALOAD, 0);
+            
+        // Do not allow argument modification : just reload arguments.
+        mv.loadArgs();
         mv.visitMethodInsn(INVOKESPECIAL, m_owner, PREFIX + name, desc);
 
         if (returnType.getSort() != Type.VOID) {
@@ -343,14 +335,13 @@
         mv.visitVarInsn(ALOAD, 0);
         mv.visitLdcInsn(generateMethodId(name, desc));
         if (returnType.getSort() != Type.VOID) {
-            GeneratorAdapter gen = new GeneratorAdapter(mv, access, name, desc);
             mv.visitVarInsn(returnType.getOpcode(ILOAD), result);
-            gen.box(returnType);
+            mv.box(returnType);
         } else {
             mv.visitInsn(ACONST_NULL);
         }
         mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", EXIT,
"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
-
+        
         mv.visitLabel(l1);
         Label l7 = new Label();
         mv.visitJumpInsn(GOTO, l7);



Mime
View raw message