commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r320947 - in /jakarta/commons/sandbox/javaflow/trunk: ./ src/java/org/apache/commons/javaflow/ src/java/org/apache/commons/javaflow/ant/ src/java/org/apache/commons/javaflow/bytecode/ src/java/org/apache/commons/javaflow/utils/ src/test/org...
Date Thu, 13 Oct 2005 23:44:33 GMT
Author: tcurdt
Date: Thu Oct 13 16:44:08 2005
New Revision: 320947

URL: http://svn.apache.org/viewcvs?rev=320947&view=rev
Log:
reworked the testcases (unfortunately some are currently failing)


Added:
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractTestCase.java   (with props)
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/RewritingTestCase.java   (with props)
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SuspendResumeTestCase.java   (with props)
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/UsageTestCase.java   (with props)
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/BlackRed.java   (with props)
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Counter.java   (with props)
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Invoker.java   (with props)
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/NewObject.java   (with props)
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Simple.java   (with props)
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/SimpleSerializable.java   (with props)
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/StackBug.java   (with props)
Removed:
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractClassLoaderTestCase.java
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationCompilingClassLoaderTestCase.java
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationTestCase.java
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationTests.java
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTests.java
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/TestClassLoader.java
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/
Modified:
    jakarta/commons/sandbox/javaflow/trunk/TODO
    jakarta/commons/sandbox/javaflow/trunk/project.properties
    jakarta/commons/sandbox/javaflow/trunk/project.xml
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.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/utils/ReflectionUtils.java
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/utils/RewritingUtils.java
    jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTestCase.java

Modified: jakarta/commons/sandbox/javaflow/trunk/TODO
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/TODO?rev=320947&r1=320946&r2=320947&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/TODO (original)
+++ jakarta/commons/sandbox/javaflow/trunk/TODO Thu Oct 13 16:44:08 2005
@@ -8,16 +8,15 @@
   o inner classes
   o try/catch/finally
   o synchronized(obj)
-o addition to async ContinuationCompilingClassLoader
-  also re-implement the old sync behaviour in the
-  ContinuationClassLoader
-o evaluate makeing the Stack class use a hierarchical
-  approach to support differential continuations
-o maybe only wrap the function calls
+  o accessing .class
+  o new Object() without assignment
+o only wrap the function calls
   that may lead to a suspend (control
   flow analysis) requires 2-pass
   analysing/rewriting
-o asm implementation instead of BCEL
+o maybe: evaluate making the Stack class use a hierarchical
+  approach to support differential continuations
+o maybe: asm implementation instead of BCEL
 
 o BCEL
   o commit bug fixes in BCEL

Modified: jakarta/commons/sandbox/javaflow/trunk/project.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/project.properties?rev=320947&r1=320946&r2=320947&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/project.properties (original)
+++ jakarta/commons/sandbox/javaflow/trunk/project.properties Thu Oct 13 16:44:08 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/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/project.xml?rev=320947&r1=320946&r2=320947&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/project.xml (original)
+++ jakarta/commons/sandbox/javaflow/trunk/project.xml Thu Oct 13 16:44:08 2005
@@ -99,6 +99,11 @@
       <version>3.8.1</version>
     </dependency>
     <dependency>
+      <groupId>junit-addons</groupId>
+      <artifactId>junit-addons</artifactId>
+      <version>1.4</version>
+    </dependency>
+    <dependency>
       <groupId>xstream</groupId>
       <artifactId>xstream</artifactId>
       <version>1.1</version>

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=320947&r1=320946&r2=320947&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 Thu Oct 13 16:44:08 2005
@@ -178,6 +178,10 @@
         }
     }
 
+    public boolean isSerializable() {
+        return stack.isSerializable();
+    }
+    
     /**
      * Stops the running continuation.
      *

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.java?rev=320947&r1=320946&r2=320947&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.java (original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.java Thu Oct 13 16:44:08 2005
@@ -19,13 +19,11 @@
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
-import org.apache.commons.io.IOUtils;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
 import org.apache.commons.javaflow.bytecode.transformation.ResourceTransformer;
 import org.apache.commons.javaflow.bytecode.transformation.bcel.BcelClassTransformer;
+import org.apache.commons.javaflow.utils.RewritingUtils;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
 import org.apache.tools.ant.Project;
@@ -68,93 +66,100 @@
 
     private void checkDir(File dir,String name) {
         if (dir==null) {
-            throw new BuildException("no "+name+" directory is specified",getLocation());
+            throw new BuildException("no " + name + " directory is specified", getLocation());
         }
         if (!dir.exists()) {
-            throw new BuildException(
-                name+" directory \""
-                    + dir
-                    + "\" does not exist ",
-                getLocation());
+            throw new BuildException(name + " directory \"" + dir + "\" does not exist", getLocation());
         }
         if (!dir.isDirectory()) {
-            throw new BuildException(
-                name+" directory \""
-                    + dir
-                    + "\" is not a directory",
-                getLocation());
+            throw new BuildException(name + " directory \"" + dir + "\" is not a directory", getLocation());
         }
     }
 
     public void execute() throws BuildException {
+        // FIXME do we really need the super call?
         super.execute();
+        
         checkParameters();
 
         fileset.setDir(srcDir);
-        DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
-        String[] files = ds.getIncludedFiles();
+        final DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
+        final String[] fileNames = ds.getIncludedFiles();
 
         try {
-            for (int i = 0; i < files.length; i++) {
-                String one = files[i];
+            for (int i = 0; i < fileNames.length; i++) {
+                final String fileName = fileNames[i];
 
-                File source = new File(srcDir, one);
-                File destination = new File(getDestDir(), one);
+                final File source = new File(srcDir, fileName);
+                final File destination = new File(getDestDir(), fileName);
+                
                 if (!destination.getParentFile().exists()) {
-                    log("Making dir: "+destination.getParentFile(), Project.MSG_VERBOSE);
+                    log("Creating dir: " + destination.getParentFile(), Project.MSG_VERBOSE);
                     destination.getParentFile().mkdirs();
                 }
 
-
                 if (source.lastModified() < destination.lastModified()) {
-                    log(source+" omitted as "+destination+" is up to date", Project.MSG_VERBOSE);
+                    log("Omitting " + source + " as " + destination + " is up to date", Project.MSG_VERBOSE);
                     continue;
                 }
-                if (one.endsWith(".class")) {
-                    log("source: "+source + " to "+destination, Project.MSG_VERBOSE);
-
+                
+                if (fileName.endsWith(".class")) {
+                    log("Rewriting " + source + " to " + destination, Project.MSG_VERBOSE);
+
+                    RewritingUtils.rewriteClassFile(
+                            source,
+                            transformer,
+                            destination);
+                    
                     // source might be the same as destination, so be careful
-                    long origSize = source.length();
-                    InputStream in = new FileInputStream(source);
-                    byte[] bytes = IOUtils.toByteArray(in);
-                    in.close();
-                    byte[] newBytes = transformer.transform(bytes);
-                    if(bytes!=newBytes) {
-                        FileOutputStream out = new FileOutputStream(destination);
-                        out.write(newBytes);
-                        out.close();
-                        log("size: " + 100*destination.length()/origSize+ '%');
-                    } else {
-                        log("skipped");
-                    }
+//                    long origSize = source.length();
+//                    InputStream in = new FileInputStream(source);
+//                    byte[] bytes = IOUtils.toByteArray(in);
+//                    in.close();
+//                    byte[] newBytes = transformer.transform(bytes);
+//                    if(bytes!=newBytes) {
+//                        FileOutputStream out = new FileOutputStream(destination);
+//                        out.write(newBytes);
+//                        out.close();
+//                        log("size: " + 100*destination.length()/origSize+ '%');
+//                    } else {
+//                        log("skipped");
+//                    }
                 }
-                if (one.endsWith(".jar")
-                    || one.endsWith(".ear")
-                    || one.endsWith(".zip")
-                    || one.endsWith(".war")) {
-
-                    log("source: "+source + " to "+destination, Project.MSG_VERBOSE);
+                if (fileName.endsWith(".jar")
+                    || fileName.endsWith(".ear")
+                    || fileName.endsWith(".zip")
+                    || fileName.endsWith(".war")) {
+
+                    log("Rewriting " + source + " to " + destination, Project.MSG_VERBOSE);
+                    
+                    RewritingUtils.rewriteJar(
+                            new JarInputStream(new FileInputStream(source)),
+                            transformer,
+                            new JarOutputStream(new FileOutputStream(destination)),
+                            null);
+                    
 
                     // write to a temporary file first because
                     // source might be the same as destination
-                    File tmp = File.createTempFile("javaflow","tmp",destination.getParentFile());
-
-                    ZipInputStream in = new ZipInputStream(new FileInputStream(source));
-                    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tmp));
-                    boolean changed;
-                    try {
-                        changed = processArchive(in,out,1);
-                    } finally {
-                        in.close();
-                        out.close();
-                    }
-
-                    if(changed) {
-                        if(destination.exists()) {
-                            destination.delete();
-                        }
-                        tmp.renameTo(destination);
-                    }
+//                    File tmp = File.createTempFile("javaflow","tmp",destination.getParentFile());
+//
+//                    ZipInputStream in = new ZipInputStream(new FileInputStream(source));
+//                    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tmp));
+//                    boolean changed;
+//                    try {
+//                        changed = processArchive(in,out,1);
+//                    } finally {
+//                        in.close();
+//                        out.close();
+//                    }
+//
+//                    if(changed) {
+//                        if(destination.exists()) {
+//                            destination.delete();
+//                        }
+//                        tmp.renameTo(destination);
+//                    }
                 }
             }
         } catch (IOException e) {
@@ -173,52 +178,52 @@
      *      true if at least one file has been modified. false
      *      if otherwise (meaning input and output are identical.)
      */
-    private boolean processArchive(ZipInputStream in, ZipOutputStream out, int nestLevel) throws IOException {
-        boolean changed = false;
-        ZipEntry e;
-
-        while((e=in.getNextEntry())!=null) {
-            // log the entry
-            StringBuffer buf = new StringBuffer();
-            for( int i=0; i<nestLevel; i++ )
-                buf.append("  ");
-            buf.append("processing "+e.getName());
-            log(buf.toString(), Project.MSG_VERBOSE);
-
-            String one = e.getName();
-
-            if (one.endsWith(".class")) {
-                // source might be the same as destination, so be careful
-                long origSize = e.getSize();
-                byte[] bytes = IOUtils.toByteArray(in);
-                in.close();
-                byte[] newBytes = transformer.transform(bytes);
-                out.putNextEntry(e);
-                out.write(newBytes);
-                out.closeEntry();
-
-                log("Size: " + 100*newBytes.length/origSize+ '%');
-
-                changed |= (bytes!=newBytes);
-            }
-            else
-            if (one.endsWith(".jar")
-                || one.endsWith(".ear")
-                || one.endsWith(".zip")
-                || one.endsWith(".war")) {
-
-                out.putNextEntry(e);
-                changed |= processArchive(new ZipInputStream(in),new ZipOutputStream(out),nestLevel++);
-                out.closeEntry();
-
-                // TODO: compute the size increase
-            } else {
-                // just copy the file as-is.
-                out.putNextEntry(e);
-                IOUtils.copy(in,out);
-                out.closeEntry();
-            }
-        }
-        return changed;
-    }
+//    private boolean processArchive(ZipInputStream in, ZipOutputStream out, int nestLevel) throws IOException {
+//        boolean changed = false;
+//        ZipEntry e;
+//
+//        while((e=in.getNextEntry())!=null) {
+//            // log the entry
+//            StringBuffer buf = new StringBuffer();
+//            for( int i=0; i<nestLevel; i++ )
+//                buf.append("  ");
+//            buf.append("processing "+e.getName());
+//            log(buf.toString(), Project.MSG_VERBOSE);
+//
+//            String one = e.getName();
+//
+//            if (one.endsWith(".class")) {
+//                // source might be the same as destination, so be careful
+//                long origSize = e.getSize();
+//                byte[] bytes = IOUtils.toByteArray(in);
+//                in.close();
+//                byte[] newBytes = transformer.transform(bytes);
+//                out.putNextEntry(e);
+//                out.write(newBytes);
+//                out.closeEntry();
+//
+//                log("Size: " + 100*newBytes.length/origSize+ '%');
+//
+//                changed |= (bytes!=newBytes);
+//            }
+//            else
+//            if (one.endsWith(".jar")
+//                || one.endsWith(".ear")
+//                || one.endsWith(".zip")
+//                || one.endsWith(".war")) {
+//
+//                out.putNextEntry(e);
+//                changed |= processArchive(new ZipInputStream(in),new ZipOutputStream(out),nestLevel++);
+//                out.closeEntry();
+//
+//                // TODO: compute the size increase
+//            } else {
+//                // just copy the file as-is.
+//                out.putNextEntry(e);
+//                IOUtils.copy(in,out);
+//                out.closeEntry();
+//            }
+//        }
+//        return changed;
+//    }
 }

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=320947&r1=320946&r2=320947&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 Thu Oct 13 16:44:08 2005
@@ -43,7 +43,7 @@
     private Object[] ostack;
     private Object[] rstack;
     private int iTop, fTop, dTop, lTop, oTop, rTop;
-    public Runnable runnable;
+    protected Runnable runnable;
 
     public Stack(Runnable pRunnable) {
         istack = new int[10];
@@ -55,26 +55,26 @@
         runnable = pRunnable;
     }
 
-    public Stack(final Stack parent) {
-        istack = new int[parent.istack.length];
-        lstack = new long[parent.lstack.length];
-        dstack = new double[parent.dstack.length];
-        fstack = new float[parent.fstack.length];
-        ostack = new Object[parent.ostack.length];
-        rstack = new Object[parent.rstack.length];
-        iTop = parent.iTop;
-        fTop = parent.fTop;
-        dTop = parent.dTop;
-        lTop = parent.lTop;
-        oTop = parent.oTop;
-        rTop = parent.rTop;
-        System.arraycopy(parent.istack, 0, istack, 0, iTop);
-        System.arraycopy(parent.fstack, 0, fstack, 0, fTop);
-        System.arraycopy(parent.dstack, 0, dstack, 0, dTop);
-        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 Stack(final Stack pParent) {
+        istack = new int[pParent.istack.length];
+        lstack = new long[pParent.lstack.length];
+        dstack = new double[pParent.dstack.length];
+        fstack = new float[pParent.fstack.length];
+        ostack = new Object[pParent.ostack.length];
+        rstack = new Object[pParent.rstack.length];
+        iTop = pParent.iTop;
+        fTop = pParent.fTop;
+        dTop = pParent.dTop;
+        lTop = pParent.lTop;
+        oTop = pParent.oTop;
+        rTop = pParent.rTop;
+        System.arraycopy(pParent.istack, 0, istack, 0, iTop);
+        System.arraycopy(pParent.fstack, 0, fstack, 0, fTop);
+        System.arraycopy(pParent.dstack, 0, dstack, 0, dTop);
+        System.arraycopy(pParent.lstack, 0, lstack, 0, lTop);
+        System.arraycopy(pParent.ostack, 0, ostack, 0, oTop);
+        System.arraycopy(pParent.rstack, 0, rstack, 0, rTop);
+        runnable = pParent.runnable;
     }
 
     public boolean hasDouble() {
@@ -82,7 +82,7 @@
     }
     
     public double popDouble() {
-        if (dTop==0) {
+        if (dTop == 0) {
             throw new EmptyStackException("pop double");
         }
         
@@ -96,7 +96,7 @@
     }
 
     public float popFloat() {
-        if (fTop==0) {
+        if (fTop == 0) {
             throw new EmptyStackException("pop float");
         }
         
@@ -110,7 +110,7 @@
     }
 
     public int popInt() {
-        if (iTop==0) {
+        if (iTop == 0) {
             throw new EmptyStackException("pop int");
         }
         
@@ -124,7 +124,7 @@
     }
 
     public long popLong() {
-        if (lTop==0) {
+        if (lTop == 0) {
             throw new EmptyStackException("pop long");
         }
         
@@ -138,12 +138,12 @@
     }
 
     public Object popObject() {
-        if (oTop==0) {
+        if (oTop == 0) {
             throw new EmptyStackException("pop object");
         }
         
         final Object o = ostack[--oTop];
-        ostack[oTop]=null;  // avoid unnecessary reference to object
+        ostack[oTop] = null;  // avoid unnecessary reference to object
 
         if(log.isDebugEnabled()) {
             final String clazz = ReflectionUtils.getClassName(o);
@@ -160,12 +160,12 @@
     }
 
     public Object popReference() {
-        if (rTop==0) {
+        if (rTop == 0) {
             throw new EmptyStackException("pop reference");
         }
         
         final Object o = rstack[--rTop];
-        rstack[rTop]=null;  // avoid unnecessary reference to object
+        rstack[rTop] = null;  // avoid unnecessary reference to object
 
         if(log.isDebugEnabled()) {
             final String clazz = ReflectionUtils.getClassName(o);
@@ -222,15 +222,11 @@
     }
 
     public void pushObject(Object o) {
-    
-        final String clazz = ReflectionUtils.getClassName(o);
-        final String clazzLoader = ReflectionUtils.getClassLoaderName(o);
-        
-        log.debug("push object " + clazz + "/" + clazzLoader + " [" + o + "] " + getStats());
-        
 
-        if (o != null && !(o instanceof Serializable)) {
-            log.warn("continuation is using class " + clazz + " which is not serializable");
+        if (log.isDebugEnabled()) {
+            final String clazz = ReflectionUtils.getClassName(o);
+            final String clazzLoader = ReflectionUtils.getClassLoaderName(o);            
+            log.debug("push object " + clazz + "/" + clazzLoader + " [" + o + "] " + getStats());
         }
         
         if (oTop == ostack.length) {
@@ -242,15 +238,14 @@
     }
 
     public void pushReference(Object o) {
-        final String clazz = ReflectionUtils.getClassName(o);
-        final String clazzLoader = ReflectionUtils.getClassLoaderName(o);
-
-        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");
+        if (log.isDebugEnabled()) {
+            final String clazz = ReflectionUtils.getClassName(o);
+            final String clazzLoader = ReflectionUtils.getClassLoaderName(o);
+    
+            log.debug("push reference " + clazz + "/" + clazzLoader + " [" + o + "] " + getStats());
         }
-
+        
         if (rTop == rstack.length) {
             Object[] hlp = new Object[rstack.length*2];
             System.arraycopy(rstack, 0, hlp, 0, rstack.length);
@@ -259,6 +254,21 @@
         rstack[rTop++] = o;
     }
 
+    public boolean isSerializable() {
+        for (int i = 0; i < rTop; i++) {
+            final Object r = rstack[i];
+            if (!(r instanceof Serializable)) {
+                return false;
+            }
+        }
+        for (int i = 0; i < oTop; i++) {
+            final Object o = ostack[i];
+            if (!(o instanceof Serializable)) {
+                return false;
+            }
+        }
+        return true;
+    }
 
     public boolean isEmpty() {
         return iTop==0 && lTop==0 && dTop==0 && fTop==0 && oTop==0 && rTop==0;

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=320947&r1=320946&r2=320947&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 Thu Oct 13 16:44:08 2005
@@ -15,11 +15,15 @@
  */
 package org.apache.commons.javaflow.utils;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -139,6 +143,15 @@
         return result;
     }    
 
+    public static Object cast(Object o) throws IOException, ClassNotFoundException {
+        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        final ObjectOutputStream oos = new ObjectOutputStream(buffer);
+        oos.writeObject(o);
+        oos.flush();
+        final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
+        return ois.readObject();
+      }
+    
     public static String getClassName(final Object o) {
         if (o == null) {
             return "unknown";

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=320947&r1=320946&r2=320947&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 Thu Oct 13 16:44:08 2005
@@ -39,14 +39,14 @@
      * @todo multiple transformers
      */
     public static void rewriteClassFile(
-            final File input,
-            final ResourceTransformer transformer,
-            final File output
+            final File pInput,
+            final ResourceTransformer pTransformer,
+            final File pOutput
             ) throws IOException {
         
-        final byte[] original = FileUtils.readFileToByteArray(input);
-        final byte[] transformed = transformer.transform(original);
-        final FileOutputStream os = new FileOutputStream(output);
+        final byte[] original = FileUtils.readFileToByteArray(pInput);
+        final byte[] transformed = pTransformer.transform(original);
+        final FileOutputStream os = new FileOutputStream(pOutput);
         os.write(transformed);
         os.close();
     }
@@ -61,29 +61,29 @@
      * @todo multiple transformers
      */
     public static boolean rewriteJar(
-            final JarInputStream input,
-            final ResourceTransformer transformer,
-            final JarOutputStream output,
-            final String pattern
+            final JarInputStream pInput,
+            final ResourceTransformer pTransformer,
+            final JarOutputStream pOutput,
+            final String pattern //FIXME matcher class
             ) throws IOException {
 
         boolean changed = false;
         
         while(true) {
-            final JarEntry entry = input.getNextJarEntry();
+            final JarEntry entry = pInput.getNextJarEntry();
             
             if (entry == null) {
                 break;
             }
             
             if (entry.isDirectory()) {
-                output.putNextEntry(new JarEntry(entry));
+                pOutput.putNextEntry(new JarEntry(entry));
                 continue;
             }
             
             final String name = entry.getName();
             
-            output.putNextEntry(new JarEntry(name));
+            pOutput.putNextEntry(new JarEntry(name));
 
             if (name.endsWith(".class")) {
                 if (isMatching(name, pattern)) {
@@ -94,10 +94,10 @@
                     
                     System.out.println(name);
                     
-                    final byte[] original = IOUtils.toByteArray(input);
+                    final byte[] original = IOUtils.toByteArray(pInput);
                     
-                    final byte[] transformed = transformer.transform(original);
-                    IOUtils.copy(new ByteArrayInputStream(transformed), output);
+                    final byte[] transformed = pTransformer.transform(original);
+                    IOUtils.copy(new ByteArrayInputStream(transformed), pOutput);
     
                     changed |= transformed.length != original.length;
                     
@@ -109,23 +109,23 @@
                 || name.endsWith(".war")) {
 
                 changed |= rewriteJar(
-                        new JarInputStream(input),
-                        transformer,
-                        new JarOutputStream(output),
+                        new JarInputStream(pInput),
+                        pTransformer,
+                        new JarOutputStream(pOutput),
                         pattern
                         );
                 
                 continue;
             }
             
-            final byte[] original = IOUtils.toByteArray(input);
-            IOUtils.copy(new ByteArrayInputStream(original), output);
+            final byte[] original = IOUtils.toByteArray(pInput);
+            IOUtils.copy(new ByteArrayInputStream(original), pOutput);
             
             System.out.println("copied " + name + "(" + original.length + ")");
         }
         
-        input.close();
-        output.close();
+        pInput.close();
+        pOutput.close();
 
         return changed;
     }

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractTestCase.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractTestCase.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractTestCase.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,33 @@
+package org.apache.commons.javaflow;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import junit.framework.TestCase;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.javaflow.bytecode.BytecodeClassLoader;
+import org.apache.commons.javaflow.bytecode.transformation.ResourceTransformer;
+import org.apache.commons.javaflow.bytecode.transformation.bcel.BcelClassTransformer;
+
+
+public abstract class AbstractTestCase extends TestCase {
+    
+    public Runnable createRunnable(final Class pClazz)  throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SecurityException, IllegalArgumentException, NoSuchMethodException, InvocationTargetException {
+        return createRunnable(pClazz, new Class[] {}, new Object[] {});
+    }
+    
+    public Runnable createRunnable(final Class pClazz, final Class[] pParameterTypes, final Object[] pParameters) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
+        final BytecodeClassLoader clazzloader = new BytecodeClassLoader();
+        final String clazzName = pClazz.getName().replace('.', '/') + ".class";
+        final InputStream is = pClazz.getClassLoader().getResourceAsStream(clazzName);
+        final byte[] clazzBytes = IOUtils.toByteArray(is);
+        final ResourceTransformer t = new BcelClassTransformer();
+        final byte[] newClazzBytes = t.transform(clazzBytes);
+        final Class clazz = clazzloader.loadClass(newClazzBytes);
+        final Constructor constructor = clazz.getConstructor(pParameterTypes);
+        final Object o = constructor.newInstance(pParameters);
+        return (Runnable) o;
+    }
+
+}

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/RewritingTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/RewritingTestCase.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/RewritingTestCase.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/RewritingTestCase.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,43 @@
+package org.apache.commons.javaflow;
+
+import org.apache.commons.javaflow.runnables.BlackRed;
+import org.apache.commons.javaflow.runnables.Counter;
+import org.apache.commons.javaflow.runnables.NewObject;
+import org.apache.commons.javaflow.runnables.StackBug;
+
+
+public final class RewritingTestCase extends AbstractTestCase {
+    
+    public void testNewObject() throws Exception {
+        final Runnable r = createRunnable(NewObject.class);
+        final Continuation c = Continuation.startWith(r);
+        assertTrue(c == null);
+    }
+
+    public void testStackBug() throws Exception {
+        final Runnable r = createRunnable(StackBug.class);
+        final Continuation c = Continuation.startWith(r);
+        assertTrue(c == null);
+    }
+    
+    public void testBlackRed() throws Exception {
+        final Runnable r = createRunnable(BlackRed.class);
+        final Continuation c1 = Continuation.startWith(r);
+        assertTrue(c1 != null);
+        final Continuation c2 = Continuation.continueWith(c1);
+        assertTrue(c2 == null);
+    }
+    
+    public void testCounter() throws Exception {
+        final int count = 5;
+        final Runnable r = createRunnable(Counter.class, new Class[] { Integer.class }, new Object[] { new Integer(count) });
+        
+        int i = 0;
+        for(Continuation c = Continuation.startWith(r); c != null; c = Continuation.continueWith(c)) {
+            i++;
+        }
+        
+        assertTrue(i == count);
+    }
+
+}

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/RewritingTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/RewritingTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTestCase.java?rev=320947&r1=320946&r2=320947&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTestCase.java (original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTestCase.java Thu Oct 13 16:44:08 2005
@@ -1,42 +1,88 @@
-/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 package org.apache.commons.javaflow;
 
-import junit.textui.TestRunner;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import junitx.util.PrivateAccessor;
+import org.apache.commons.javaflow.Continuation;
+import org.apache.commons.javaflow.runnables.Invoker;
+import org.apache.commons.javaflow.runnables.Simple;
+import org.apache.commons.javaflow.runnables.SimpleSerializable;
+import org.apache.commons.javaflow.utils.ReflectionUtils;
+import org.apache.tools.ant.util.FileUtils;
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
 
 
-/**
- * @author tcurdt
- *
- */
-public final class SerializationTestCase extends AbstractClassLoaderTestCase {
+public final class SerializationTestCase extends AbstractTestCase {
 
-    public SerializationTestCase() {
-        super("org.apache.commons.javaflow.SerializationTests");
+    public SimpleSerializable cast(Object o) throws IOException, ClassNotFoundException {
+        return (SimpleSerializable) ReflectionUtils.cast(o);
     }
+    
+    private File output;
+    
+    public void testSuspend() throws Exception {
+        final Runnable r = createRunnable(SimpleSerializable.class);
+        
+        assertTrue(cast(r).g == -1);
+        assertTrue(cast(r).l == -1);
+        
+        Continuation c1 = Continuation.startWith(r);
+        
+        assertTrue(cast(r).g == 0);
+        assertTrue(cast(r).l == 0);
+        
+        final XStream xstream = new XStream(new DomDriver());
+        final String xml = xstream.toXML(c1);        
+
+        output = File.createTempFile("continuation", "xml");
+        output.deleteOnExit();
 
-    public static void main(String[] args) {
-        TestRunner.run(SerializationTestCase.class);
+        final FileOutputStream fos = new FileOutputStream(output);
+        fos.write(xml.getBytes()); 
     }
 
-    public void testStart() throws Exception {
-        call("testStart");
+
+    public void testResume() throws Exception {
+        testSuspend();
+        
+        assertTrue("suspend must succeed to create the output first", output != null);
+
+        final String xml = FileUtils.readFully(new FileReader(output));
+        final XStream xstream = new XStream(new DomDriver());
+        final Object o = xstream.fromXML(xml);
+
+        assertTrue(o instanceof Continuation);
+        
+        final Continuation c1 = (Continuation) o;
+
+        final Runnable r1 = (Runnable) PrivateAccessor.getField(PrivateAccessor.getField(c1, "stack"), "runnable");
+        assertTrue(cast(r1).g == 0);
+        assertTrue(cast(r1).l == 0);
+        
+        final Continuation c2 = Continuation.continueWith(c1);
+
+        final Runnable r2 = (Runnable) PrivateAccessor.getField(PrivateAccessor.getField(c1, "stack"), "runnable");
+        assertTrue(cast(r2).g == 1);
+        assertTrue(cast(r2).l == 1);
+
+        assertTrue(r1 == r2);   
     }
     
-    public void testResume() throws Exception {
-        call("testResume");
-    }    
+    public void testSerializableCheck() throws Exception {
+        final Runnable r1 = createRunnable(SimpleSerializable.class);
+        Continuation c1 = Continuation.startWith(r1);
+        assertTrue(c1.isSerializable());
+
+        final Runnable r2 = createRunnable(SimpleSerializable.class);
+        Continuation c2 = Continuation.startWith(new Invoker(r2));
+        assertTrue(c2.isSerializable());
+
+        final Runnable r3 = createRunnable(Simple.class);
+        Continuation c3 = Continuation.startWith(r3);
+        assertTrue(!c3.isSerializable());
+    }
+
 }

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SuspendResumeTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SuspendResumeTestCase.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SuspendResumeTestCase.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SuspendResumeTestCase.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,63 @@
+package org.apache.commons.javaflow;
+
+import java.io.IOException;
+import org.apache.commons.javaflow.Continuation;
+import org.apache.commons.javaflow.runnables.SimpleSerializable;
+import org.apache.commons.javaflow.utils.ReflectionUtils;
+
+
+public class SuspendResumeTestCase extends AbstractTestCase {
+    
+    public SimpleSerializable cast(Object o) throws IOException, ClassNotFoundException {
+        return (SimpleSerializable) ReflectionUtils.cast(o);
+    }
+    
+    public void testSimpleSuspendResume() throws Exception {
+        final Runnable r = createRunnable(SimpleSerializable.class);
+        
+        assertTrue(cast(r).g == -1);
+        assertTrue(cast(r).l == -1);
+        
+        Continuation c1 = Continuation.startWith(r);
+        
+        assertTrue(cast(r).g == 0);
+        assertTrue(cast(r).l == 0);
+
+        Continuation c2 = Continuation.continueWith(c1);
+
+        assertTrue(cast(r).g == 1);
+        assertTrue(cast(r).l == 1);
+
+        Continuation c3 = Continuation.continueWith(c2);
+
+        assertTrue(cast(r).g == 2);
+        assertTrue(cast(r).l == 2);
+    }
+    
+    public void testContinuationBranching() throws Exception {
+        final Runnable r = createRunnable(SimpleSerializable.class);
+        
+        assertTrue(cast(r).g == -1);
+        assertTrue(cast(r).l == -1);
+        
+        Continuation c1 = Continuation.startWith(r);
+        
+        assertTrue(cast(r).g == 0);
+        assertTrue(cast(r).l == 0);
+
+        Continuation c2 = Continuation.continueWith(c1);
+
+        assertTrue(cast(r).g == 1);
+        assertTrue(cast(r).l == 1);
+
+        Continuation c31 = Continuation.continueWith(c2);
+
+        assertTrue(cast(r).g == 2);
+        assertTrue(cast(r).l == 2);
+
+        Continuation c32 = Continuation.continueWith(c2);
+
+        assertTrue(cast(r).g == 3);
+        assertTrue(cast(r).l == 2);
+    }
+}

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SuspendResumeTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SuspendResumeTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/UsageTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/UsageTestCase.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/UsageTestCase.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/UsageTestCase.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,18 @@
+package org.apache.commons.javaflow;
+
+import org.apache.commons.javaflow.runnables.SimpleSerializable;
+
+
+
+public final class UsageTestCase extends AbstractTestCase {
+
+    public void testIncorrectUsageWithNormalClassLoader() throws Exception {
+        try {
+            final Runnable r = new SimpleSerializable();
+            r.run();
+            fail();
+        } catch (final Exception e) {
+            assertTrue(e instanceof IllegalStateException);
+        }
+    }
+}

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/UsageTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/UsageTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/BlackRed.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/BlackRed.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/BlackRed.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/BlackRed.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,52 @@
+package org.apache.commons.javaflow.runnables;
+
+import org.apache.commons.javaflow.Continuation;
+
+import java.io.Serializable;
+
+/**
+ * Test for making sure that rstack works correctly.
+ *
+ * For this test we need to have a stack frame that goes through multiple objects
+ * of different types.
+ *
+ * @author Kohsuke Kawaguchi
+ */
+public final class BlackRed implements Runnable, Serializable {
+    public void run() {
+        new Black(new Red(new Black(new Suspend()))).run();
+    }
+
+    class Black implements Runnable {
+        final Runnable r;
+
+        public Black(Runnable r) {
+            this.r = r;
+        }
+
+        public void run() {
+            String s = "foo";   // have some random variable
+            r.run();
+        }
+    }
+
+    class Red implements Runnable {
+        final Runnable r;
+
+        public Red(Runnable r) {
+            this.r = r;
+        }
+
+        public void run() {
+            int i = 5;  // have some random variable
+            r.run();
+        }
+    }
+
+    class Suspend implements Runnable {
+        public void run() {
+            Continuation.suspend();
+        }
+    }
+
+}

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/BlackRed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/BlackRed.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Counter.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Counter.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Counter.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Counter.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,21 @@
+package org.apache.commons.javaflow.runnables;
+
+import org.apache.commons.javaflow.Continuation;
+
+/**
+ * @author Kohsuke Kawaguchi
+ */
+public final class Counter implements Runnable {
+
+    final int up;
+
+    public Counter(Integer up) {
+        this.up = up.intValue();
+    }
+
+    public void run() {
+        for( int i=0; i<up; i++ ) {
+            Continuation.suspend();
+        }
+    }
+}

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Counter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Counter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Invoker.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Invoker.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Invoker.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Invoker.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,16 @@
+package org.apache.commons.javaflow.runnables;
+
+
+public final class Invoker implements Runnable {
+
+    private final Runnable runnable;
+    
+    public Invoker(final Runnable pRunnable) {
+        runnable = pRunnable;
+    }
+    
+    public void run() {
+        runnable.run();
+    }
+    
+}

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Invoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Invoker.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/NewObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/NewObject.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/NewObject.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/NewObject.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,25 @@
+package org.apache.commons.javaflow.runnables;
+
+import junit.framework.Assert;
+
+/**
+ * Test that allocates a lot of new objects.
+ *
+ * Javaflow performs some tricky instrumentation on new object allocations,
+ * especially when it has arguments.
+ *
+ * Nesting object allocations makes it even more interesting.
+ *
+ * @author Kohsuke Kawaguchi
+ */
+public final class NewObject implements Runnable {
+    public void run() {
+        char[] ch = {'a','b','c'};
+
+        String s = new String(new String(
+                new String(ch,0,ch.length).toCharArray(), 0, ch.length ));
+
+        Assert.assertEquals(s,"abc");
+    }
+
+}

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/NewObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/NewObject.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Simple.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Simple.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Simple.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Simple.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,22 @@
+package org.apache.commons.javaflow.runnables;
+
+import org.apache.commons.javaflow.Continuation;
+
+public final class Simple implements Runnable {
+
+    public int g = -1; // global count throughout all continuations
+    public int l = -1; // local count mapped to a global variable so
+                       // we can access is
+    
+    public void run() {
+        int local = -1;
+        ++g; l=++local;
+        Continuation.suspend();
+        ++g; l=++local;
+        Continuation.suspend();
+        ++g; l=++local;
+        Continuation.suspend();
+        ++g; l=++local;
+    }
+
+}
\ No newline at end of file

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Simple.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/Simple.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/SimpleSerializable.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/SimpleSerializable.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/SimpleSerializable.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/SimpleSerializable.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,25 @@
+package org.apache.commons.javaflow.runnables;
+
+import java.io.Serializable;
+import org.apache.commons.javaflow.Continuation;
+
+public final class SimpleSerializable implements Runnable, Serializable {
+
+    private static final long serialVersionUID = 1L;
+    
+    public int g = -1; // global count throughout all continuations
+    public int l = -1; // local count mapped to a global variable so
+                       // we can access is
+    
+    public void run() {
+        int local = -1;
+        ++g; l=++local;
+        Continuation.suspend();
+        ++g; l=++local;
+        Continuation.suspend();
+        ++g; l=++local;
+        Continuation.suspend();
+        ++g; l=++local;
+    }
+
+}
\ No newline at end of file

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/SimpleSerializable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/SimpleSerializable.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/StackBug.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/StackBug.java?rev=320947&view=auto
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/StackBug.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/StackBug.java Thu Oct 13 16:44:08 2005
@@ -0,0 +1,35 @@
+package org.apache.commons.javaflow.runnables;
+
+/**
+ * Regression test case.
+ *
+ * <p>
+ * When the stack size reaches the maximum in a constructor method invocation,
+ * there was a bug where we failed to expand the stack size appropriately.
+ *
+ * This is a regression test for that case.
+ *
+ *
+ * @author Kohsuke Kawaguchi
+ */
+public final class StackBug implements Runnable {
+    public void run() {
+        final Object o = foo("abc","def");
+    }
+
+    private Object foo(String a, String b) {
+        return new StrStr(a,b);
+    }
+
+    private static final class StrStr {
+        private final String value;
+
+        public StrStr(String a, String b) {
+            value = a+b;
+        }
+
+        public String toString() {
+            return value;
+        }
+    }
+}

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/StackBug.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/runnables/StackBug.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
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