commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r295143 - in /jakarta/commons/sandbox/javaflow/trunk: ./ src/java/org/apache/commons/javaflow/ src/java/org/apache/commons/javaflow/bytecode/ src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/ src/java/org/apache/commons/jav...
Date Thu, 06 Oct 2005 00:06:41 GMT
Author: tcurdt
Date: Wed Oct  5 17:06:30 2005
New Revision: 295143

URL: http://svn.apache.org/viewcvs?rev=295143&view=rev
Log:
more verbose debugging for the moment


Modified:
    jakarta/commons/sandbox/javaflow/trunk/project.properties
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/Stack.java
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/StackRecorder.java
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/ReflectionUtils.java
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java

Modified: jakarta/commons/sandbox/javaflow/trunk/project.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/project.properties?rev=295143&r1=295142&r2=295143&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/project.properties (original)
+++ jakarta/commons/sandbox/javaflow/trunk/project.properties Wed Oct  5 17:06:30 2005
@@ -20,6 +20,7 @@
 maven.jar.excludes=**/package.html
 maven.junit.fork=true
 maven.test.failure.ignore = true
+maven.test.skip = true
 maven.junit.sysproperties=org.xml.sax.driver
 org.xml.sax.driver=org.apache.xerces.parsers.SAXParser
 

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java?rev=295143&r1=295142&r2=295143&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java
Wed Oct  5 17:06:30 2005
@@ -15,12 +15,12 @@
  */
 package org.apache.commons.javaflow;
 
+import java.io.Serializable;
 import org.apache.commons.javaflow.bytecode.StackRecorder;
+import org.apache.commons.javaflow.utils.ReflectionUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.Serializable;
-
 /**
  * Snapshot of a thread execution state.
  *
@@ -45,6 +45,8 @@
     
     private final StackRecorder stack;
 
+    private static final long serialVersionUID = 1L;
+
     
     /**
      * Create a new continuation, which continue a previous continuation.
@@ -124,7 +126,7 @@
             throw new IllegalArgumentException("target is null");
         }
 
-        log.debug("starting new flow from " + target);
+        log.debug("starting new flow from " + ReflectionUtils.getClassName(target) + "/"
+ ReflectionUtils.getClassLoaderName(target));
 
         return execute(new StackRecorder(target), context);
     }
@@ -162,7 +164,7 @@
             throw new IllegalArgumentException("continuation parameter must not be null.");
         }
 
-        log.debug("continueing with continuation " + resumed);
+        log.debug("continueing with continuation " + ReflectionUtils.getClassName(resumed)
+ "/" + ReflectionUtils.getClassLoaderName(resumed));
 
         return execute(new StackRecorder(resumed.stack),context);
     }
@@ -192,8 +194,6 @@
     }
 
     public String toString() {
-        return "Continuation@" + hashCode() + " in " + getClass().getClassLoader();
+        return "Continuation@" + hashCode() + "/" + ReflectionUtils.getClassLoaderName(this);
     }
-
-    private static final long serialVersionUID = 1L;
 }

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/Stack.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/Stack.java?rev=295143&r1=295142&r2=295143&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/Stack.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/Stack.java
Wed Oct  5 17:06:30 2005
@@ -15,11 +15,11 @@
  */
 package org.apache.commons.javaflow.bytecode;
 
-import java.io.Serializable;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-
+import java.io.Serializable;
+import org.apache.commons.javaflow.utils.ReflectionUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -43,14 +43,16 @@
     private Object[] ostack;
     private Object[] rstack;
     private int iTop, fTop, dTop, lTop, oTop, rTop;
+    public Runnable runnable;
 
-    public Stack() {
+    public Stack(Runnable pRunnable) {
         istack = new int[10];
         lstack = new long[5];
         dstack = new double[5];
         fstack = new float[5];
         ostack = new Object[10];
         rstack = new Object[5];
+        runnable = pRunnable;
     }
 
     public Stack(final Stack parent) {
@@ -72,6 +74,7 @@
         System.arraycopy(parent.lstack, 0, lstack, 0, lTop);
         System.arraycopy(parent.ostack, 0, ostack, 0, oTop);
         System.arraycopy(parent.rstack, 0, rstack, 0, rTop);
+        runnable = parent.runnable;
     }
 
     public boolean hasDouble() {
@@ -84,7 +87,7 @@
         }
         
         final double d = dstack[--dTop];
-        log.debug("pop double " + d + " " + toString());
+        log.debug("pop double " + d + " " + getStats());
         return d;
     }
 
@@ -98,7 +101,7 @@
         }
         
         final float f = fstack[--fTop];
-        log.debug("pop float " + f + " " + toString());
+        log.debug("pop float " + f + " " + getStats());
         return f;
     }
 
@@ -112,7 +115,7 @@
         }
         
         final int i = istack[--iTop];
-        log.debug("pop int " + i + " " + toString());
+        log.debug("pop int " + i + " " + getStats());
         return i;
     }
 
@@ -126,7 +129,7 @@
         }
         
         final long l = lstack[--lTop];
-        log.debug("pop long " + l + " " + toString());
+        log.debug("pop long " + l + " " + getStats());
         return l;
     }
 
@@ -143,10 +146,10 @@
         ostack[oTop]=null;  // avoid unnecessary reference to object
 
         if(log.isDebugEnabled()) {
-            final String clazz = getClassName(o);
-            final String clazzLoader = getClassLoaderName(o);
+            final String clazz = ReflectionUtils.getClassName(o);
+            final String clazzLoader = ReflectionUtils.getClassLoaderName(o);
 
-            log.debug("pop object "+ clazz + "/" + clazzLoader + " [" + o + "] " + toString());
+            log.debug("pop object "+ clazz + "/" + clazzLoader + " [" + o + "] ");
         }
         
         return o;
@@ -165,17 +168,17 @@
         rstack[rTop]=null;  // avoid unnecessary reference to object
 
         if(log.isDebugEnabled()) {
-            final String clazz = getClassName(o);
-            final String clazzLoader = getClassLoaderName(o);
+            final String clazz = ReflectionUtils.getClassName(o);
+            final String clazzLoader = ReflectionUtils.getClassLoaderName(o);
 
-            log.debug("pop reference "+ clazz + "/" + clazzLoader + " [" + o + "] " + toString());
+            log.debug("pop reference "+ clazz + "/" + clazzLoader + " [" + o + "] " + getStats());
         }
         
         return o;
     }
 
     public void pushDouble(double d) {
-        log.debug("push double " + d + " " + toString());
+        log.debug("push double " + d + " " + getStats());
 
         if (dTop == dstack.length) {
             double[] hlp = new double[dstack.length*2];
@@ -186,7 +189,7 @@
     }
 
     public void pushFloat(float f) {
-        log.debug("push float " + f + " " + toString());
+        log.debug("push float " + f + " " + getStats());
         
         if (fTop == fstack.length) {
             float[] hlp = new float[fstack.length*2];
@@ -197,7 +200,7 @@
     }
 
     public void pushInt(int i) {
-        log.debug("push int " + i + " " + toString());
+        log.debug("push int " + i + " " + getStats());
 
         if (iTop == istack.length) {
             int[] hlp = new int[istack.length*2];
@@ -208,7 +211,7 @@
     }
 
     public void pushLong(long l) {
-        log.debug("push long " + l + " " + toString());
+        log.debug("push long " + l + " " + getStats());
         
         if (lTop == lstack.length) {
             long[] hlp = new long[lstack.length*2];
@@ -220,10 +223,10 @@
 
     public void pushObject(Object o) {
     
-        final String clazz = getClassName(o);
-        final String clazzLoader = getClassLoaderName(o);
+        final String clazz = ReflectionUtils.getClassName(o);
+        final String clazzLoader = ReflectionUtils.getClassLoaderName(o);
         
-        log.debug("push object " + clazz + "/" + clazzLoader + " [" + o + "] " + toString());
+        log.debug("push object " + clazz + "/" + clazzLoader + " [" + o + "] " + getStats());
         
 
         if (o != null && !(o instanceof Serializable)) {
@@ -239,10 +242,10 @@
     }
 
     public void pushReference(Object o) {
-        final String clazz = getClassName(o);
-        final String clazzLoader = getClassLoaderName(o);
+        final String clazz = ReflectionUtils.getClassName(o);
+        final String clazzLoader = ReflectionUtils.getClassLoaderName(o);
 
-        log.debug("push reference " + clazz + "/" + clazzLoader + " [" + o + "] " + toString());
+        log.debug("push reference " + clazz + "/" + clazzLoader + " [" + o + "] " + getStats());
 
         if (o != null && !(o instanceof Serializable)) {
             log.warn("continuation is referencing class " + clazz + " which is not serializable");
@@ -256,36 +259,48 @@
         rstack[rTop++] = o;
     }
 
-    private static String getClassName(final Object o) {
-        if (o == null) {
-            return "unknown";
-        }
-        
-        return o.getClass().getName() + "@" + o.hashCode();
-    }
-
-    private static String getClassLoaderName(final Object o) {
-        if (o == null) {
-            return "unknown";
-        }
-        
-        return String.valueOf(o.getClass().getClassLoader());
-    }
 
     public boolean isEmpty() {
         return iTop==0 && lTop==0 && dTop==0 && fTop==0 &&
oTop==0 && rTop==0;
     }
 
-
+    private String getStats() {
+        final StringBuffer sb = new StringBuffer();
+        sb.append("i[").append(iTop).append("],");
+        sb.append("l[").append(lTop).append("],");
+        sb.append("d[").append(dTop).append("],");
+        sb.append("f[").append(fTop).append("],");
+        sb.append("o[").append(oTop).append("],");
+        sb.append("r[").append(rTop).append("]");
+        return sb.toString();
+    }
+
+    private String getContent() {
+        final StringBuffer sb = new StringBuffer();
+        sb.append("i[").append(iTop).append("]\n");
+        sb.append("l[").append(lTop).append("]\n");
+        sb.append("d[").append(dTop).append("]\n");
+        sb.append("f[").append(fTop).append("]\n");
+        sb.append("o[").append(oTop).append("]\n");
+        for(int i=0; i<oTop;i++) {
+            sb.append(' ').append(i).append(": ");
+            sb.append(ReflectionUtils.getClassName(ostack[i])).append('/').append(ReflectionUtils.getClassLoaderName(ostack[i]));
+            sb.append('\n');
+        }
+        sb.append("r[").append(rTop).append("]\n");
+        for(int i=0; i<rTop;i++) {
+            sb.append(' ').append(i).append(": ");
+            sb.append(ReflectionUtils.getClassName(rstack[i])).append('/').append(ReflectionUtils.getClassLoaderName(rstack[i]));
+            sb.append('\n');
+        }
+        
+        return sb.toString();
+    }
+    
     public String toString() {
-        return
-          "i=" + iTop +
-         ",l=" + lTop +
-         ",d=" + dTop +
-         ",f=" + fTop +
-         ",o=" + oTop +
-         ",r=" + rTop;
+        return getContent();
     }
+
 
     private void writeObject(ObjectOutputStream s) throws IOException {
         s.writeInt(iTop);

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/StackRecorder.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/StackRecorder.java?rev=295143&r1=295142&r2=295143&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/StackRecorder.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/StackRecorder.java
Wed Oct  5 17:06:30 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.commons.javaflow.bytecode;
 
+import org.apache.commons.javaflow.utils.ReflectionUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -42,7 +43,7 @@
      * Creates a new empty {@link StackRecorder} that runs the given target.
      */
     public StackRecorder(Runnable target) {
-        pushReference(target);
+        super(target);
     }
 
     /**
@@ -82,19 +83,34 @@
 
     public StackRecorder execute(final Object context) {
         final StackRecorder old = registerThread();
-        Runnable target = (Runnable)popReference();
         try {
+            Object target = runnable;
+            
             restoring = !isEmpty(); // start restoring if we have a filled stack
             this.context = context;
-            target.run();
-            if (!capturing) {
-                return null;
+            
+            if (restoring) {
+                log.debug("Restoring state of " + ReflectionUtils.getClassName(target) +
"/" + ReflectionUtils.getClassLoaderName(target));
             }
+            
+            if (target instanceof Runnable) {
+                log.debug("calling runnable");
+                ((Runnable)target).run();                
+            } else {
+                log.error("No runnable on stack. " + ReflectionUtils.getClassName(target)
+ "/" + ReflectionUtils.getClassLoaderName(target));
+            }
+            
+            if (capturing) {
+                return this;
+            }
+        } catch(Throwable t) {
+            log.error(t.getMessage(),t);
         } finally {
             this.context = null;
             deregisterThread(old);
         }
-        return this;
+        
+        return null;
     }
 
     public Object getContext() {

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java?rev=295143&r1=295142&r2=295143&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
Wed Oct  5 17:06:30 2005
@@ -97,11 +97,11 @@
     private static final String CAPURING_METHOD = "isCapturing";
 
     private boolean currentMethodStatic = false;
-    public static boolean debug = false;
+    public static boolean debug = true;
 
     static {
         try {
-            debug = System.getProperty(BcelClassTransformer.class.getName()+".debug")!=null;
+            //debug = System.getProperty(BcelClassTransformer.class.getName()+".debug")!=null;
         } catch (SecurityException e) {
             // assume no debugging
         }
@@ -197,6 +197,9 @@
         FileOutputStream out = null;
         try {
             out = new FileOutputStream(path);
+            
+            log.debug("writing " + path);
+            
             out.write(orig);
             out.flush();
         } catch (final IOException e) {
@@ -215,6 +218,9 @@
 
         try {
             out = new FileOutputStream(path + ".java");
+
+            log.debug("writing " + path + ".java");
+
             final DecompilingVisitor v = new DecompilingVisitor(javaClazz, out);
             v.start();
         } catch (final Exception e) {

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/ReflectionUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/ReflectionUtils.java?rev=295143&r1=295142&r2=295143&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/ReflectionUtils.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/ReflectionUtils.java
Wed Oct  5 17:06:30 2005
@@ -139,4 +139,19 @@
         return result;
     }    
 
+    public static String getClassName(final Object o) {
+        if (o == null) {
+            return "unknown";
+        }
+        
+        return o.getClass().getName() + "@" + o.hashCode();
+    }
+
+    public static String getClassLoaderName(final Object o) {
+        if (o == null) {
+            return "unknown";
+        }
+        
+        return getClassName(o.getClass().getClassLoader());
+    }
 }

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java?rev=295143&r1=295142&r2=295143&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java
Wed Oct  5 17:06:30 2005
@@ -17,6 +17,8 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.jar.JarEntry;
@@ -25,6 +27,7 @@
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.javaflow.bytecode.transformation.ResourceTransformer;
+import org.apache.commons.javaflow.bytecode.transformation.bcel.BcelClassTransformer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -48,16 +51,24 @@
         os.close();
     }
     
+    public static boolean isMatching(final String name, final String pattern) {
+        //FIXME proper matching
+        return "org/apache/cocoon/components/flow/java/AbstractContinuable.class".equals(name);
+        //|| "org/apache/cocoon/components/flow/java/Invoker.class".equals(name);
+    }
+    
     /*
-     * @todo recurse
      * @todo multiple transformers
      */
-    public static void rewriteJar(
+    public static boolean rewriteJar(
             final JarInputStream input,
             final ResourceTransformer transformer,
-            final JarOutputStream output
+            final JarOutputStream output,
+            final String pattern
             ) throws IOException {
 
+        boolean changed = false;
+        
         while(true) {
             final JarEntry entry = input.getNextJarEntry();
             
@@ -66,31 +77,76 @@
             }
             
             if (entry.isDirectory()) {
+                output.putNextEntry(new JarEntry(entry));
                 continue;
             }
             
             final String name = entry.getName();
             
-            final byte[] original = IOUtils.toByteArray(input);
-            
             output.putNextEntry(new JarEntry(name));
 
             if (name.endsWith(".class")) {
-                
-                if (log.isDebugEnabled()) {
-                    log.debug("transforming " + name);
+                if (isMatching(name, pattern)) {
+                    
+                    if (log.isDebugEnabled()) {
+                        log.debug("transforming " + name);
+                    }
+                    
+                    System.out.println(name);
+                    
+                    final byte[] original = IOUtils.toByteArray(input);
+                    
+                    final byte[] transformed = transformer.transform(original);
+                    IOUtils.copy(new ByteArrayInputStream(transformed), output);
+    
+                    changed |= transformed.length != original.length;
+                    
+                    continue;
                 }
-
-                final byte[] transformed = transformer.transform(original);
-                IOUtils.copy(new ByteArrayInputStream(transformed), output);
-                
-            } else {
+            } else if (name.endsWith(".jar")
+                || name.endsWith(".ear")
+                || name.endsWith(".zip")
+                || name.endsWith(".war")) {
+
+                changed |= rewriteJar(
+                        new JarInputStream(input),
+                        transformer,
+                        new JarOutputStream(output),
+                        pattern
+                        );
                 
-                IOUtils.copy(new ByteArrayInputStream(original), output);
+                continue;
             }
+            
+            final byte[] original = IOUtils.toByteArray(input);
+            IOUtils.copy(new ByteArrayInputStream(original), output);
+            
+            System.out.println("copied " + name + "(" + original.length + ")");
         }
         
         input.close();
         output.close();
+
+        return changed;
     }
+
+    public static void main(final String[] args) throws FileNotFoundException, IOException
{
+        System.out.println("rewriting");
+        
+        ResourceTransformer transformer = new BcelClassTransformer();
+        
+        for (int i=0; i<args.length; i+=2) {
+            System.out.println("rewriting " + args[i]);
+
+            RewritingUtils.rewriteJar(
+                    new JarInputStream(new FileInputStream(args[i])),
+                    new BcelClassTransformer(),
+                    new JarOutputStream(new FileOutputStream(args[i+1])),
+                    "");
+        }
+
+        System.out.println("done");
+        
+    }
+    
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message