You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by tc...@apache.org on 2005/02/09 22:34:15 UTC
svn commit: r153121 - 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/bcel/
src/test/org/apache/commons/javaflow/
src/test/org/apache/commons/javaflow/testcode/
Author: tcurdt
Date: Wed Feb 9 13:34:11 2005
New Revision: 153121
URL: http://svn.apache.org/viewcvs?view=rev&rev=153121
Log:
major rewrite of the classloader,
continuation serialization,
check the flow in the testcases via statics (no intstance reference anymore),
removed the BCEL dependency on the ClassTransformer interface,
removed an instanceOf check that required the BCEL Repository (need to re-check this),
better logging messages
Added:
jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractClassLoaderTestCase.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/SerializationTestCase.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/testcode/SomeReference.java
Removed:
jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationClassLoaderTestCase.java
jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/Main.java
Modified:
jakarta/commons/sandbox/javaflow/trunk/TODO
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/ContinuationClassLoader.java
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/ClassTransformer.java
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/RewritingResourceStore.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/bcel/BcelClassTransformer.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/testcode/Calculator.java
Modified: jakarta/commons/sandbox/javaflow/trunk/TODO
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/TODO?view=diff&r1=153120&r2=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/TODO (original)
+++ jakarta/commons/sandbox/javaflow/trunk/TODO Wed Feb 9 13:34:11 2005
@@ -7,10 +7,6 @@
maybe re-evaluate
o make the Stack class use a hierarchical
approach to support differential continuations
-o make the Stack and Continuation classes
- serializable. (make sure all dynamics are
- handled through the context object. what
- about logging?)
o get rid of the Continuable and ContinuationCapable
marker interfaces
o fix bugs:
@@ -22,19 +18,13 @@
o addition to async ContinuationCompilingClassLoader
also re-implement the old sync behaviour in the
ContinuationClassLoader
-o change the ClassTransform interface to
- be byte-code library independend
-
- byte[] transform( final InputStream is ) or
- byte[] transform( byte[] clazz )
-
- o check whether we need two passes
+o check whether we need two passes
1. parsing
2. rewriting
- o maybe only wrap the function calls
- that may lead to a suspend (control
- flow analysis)
- o asm implementation instead of BCEL
+o maybe only wrap the function calls
+ that may lead to a suspend (control
+ flow analysis)
+o asm implementation instead of BCEL
o BCEL
o push some bug fixes in BCEL
Modified: jakarta/commons/sandbox/javaflow/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/project.xml?view=diff&r1=153120&r2=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/project.xml (original)
+++ jakarta/commons/sandbox/javaflow/trunk/project.xml Wed Feb 9 13:34:11 2005
@@ -4,20 +4,18 @@
-->
<extend>../commons-build/sandbox-project.xml</extend>
+ <pomVersion>1</pomVersion>
+ <artifactId>commons-javaflow</artifactId>
<name>Commons Javaflow</name>
+ <groupId>commons-javaflow</groupId>
<id>commons-javaflow</id>
<logo>/images/javaflow-logo-white.png</logo>
<url>http://jakarta.apache.org/commons/sandbox/javaflow/</url>
<inceptionYear>2004</inceptionYear>
<shortDescription>Commons Javaflow</shortDescription>
<description>Commons Javaflow</description>
-
<currentVersion>0.1-dev</currentVersion>
- <versions></versions>
- <branches></branches>
-
<package>org.apache.commons.javaflow.*</package>
-
<developers>
<developer>
<name>Torsten Curdt</name>
@@ -25,8 +23,6 @@
<email>tcurdt at apache.org</email>
</developer>
</developers>
-
-
<build>
<sourceDirectory>src/java</sourceDirectory>
<unitTestSourceDirectory>src/test</unitTestSourceDirectory>
@@ -34,46 +30,62 @@
<includes>
<include>**/*TestCase.java</include>
</includes>
+ <excludes>
+ <exclude>**/Abstract*TestCase.java</exclude>
+ </excludes>
</unitTest>
</build>
-
<dependencies>
-
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>bcel</groupId>
+ <artifactId>bcel</artifactId>
+ <version>20040329</version>
+ <jar>${basedir}/lib/jakarta-bcel-20040329.jar</jar>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>commons-jci</groupId>
+ <artifactId>commons-jci</artifactId>
+ <version>0.1-dev</version>
+ <jar>${basedir}/lib/commons-jci-0.1-dev.jar</jar>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.5.3-1</version>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>xstream</groupId>
+ <artifactId>xstream</artifactId>
+ <version>1.1</version>
+ <type>jar</type>
</dependency>
-
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
<version>1.0.4</version>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.0</version>
+ <type>jar</type>
</dependency>
-
- <dependency>
- <groupId>bcel</groupId>
- <artifactId>bcel</artifactId>
- <version>20040329</version>
- </dependency>
-
- <dependency>
- <groupId>commons-jci</groupId>
- <artifactId>commons-jci</artifactId>
- <version>0.1-dev</version>
- </dependency>
-
- <dependency>
- <groupId>ant</groupId>
- <artifactId>ant</artifactId>
- <version>1.5.3-1</version>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- </dependency>
-
</dependencies>
</project>
+
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?view=diff&r1=153120&r2=153121
==============================================================================
--- 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 Feb 9 13:34:11 2005
@@ -76,7 +76,6 @@
public Object getContext() {
return context;
}
-
public static Continuation startWith( final String methodName, final ContinuationContext context ) {
@@ -116,12 +115,22 @@
// REVISIT: use instance from root continuation
if (continuation.method == null) {
+ log.debug("looking up method " + continuation.methodName);
final MethodLookup lookup = context.getMethodLookup();
continuation.method = lookup.getMethod(continuation.methodName);
+ log.debug("found method " + continuation.method + " in " +
+ continuation.method.getDeclaringClass().getClassLoader()
+ );
}
if (continuation.instance == null) {
+ log.debug("creating instance " + continuation.method.getDeclaringClass().getName());
continuation.instance = continuation.method.getDeclaringClass().newInstance();
+ log.debug("created instance " +
+ continuation.instance.getClass().getName() + "@" + continuation.instance.hashCode() +
+ "-" +
+ continuation.instance.getClass().getClassLoader()
+ );
}
continuation.context = context;
@@ -206,8 +215,7 @@
}
}
-
public String toString() {
- return "Continuation@" + hashCode();
+ return "Continuation@" + hashCode() + " in " + getClass().getClassLoader();
}
}
Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ContinuationClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ContinuationClassLoader.java?view=diff&r1=153120&r2=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ContinuationClassLoader.java (original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ContinuationClassLoader.java Wed Feb 9 13:34:11 2005
@@ -15,11 +15,14 @@
*/
package org.apache.commons.javaflow;
-import org.apache.bcel.Repository;
-import org.apache.bcel.classfile.JavaClass;
-import org.apache.bcel.util.ClassLoaderRepository;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
import org.apache.commons.javaflow.bytecode.ClassTransformer;
import org.apache.commons.javaflow.bytecode.bcel.BcelClassTransformer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* @author tcurdt
@@ -27,31 +30,66 @@
*/
public final class ContinuationClassLoader extends ClassLoader {
+ private final static Log log = LogFactory.getLog(ContinuationCompilingClassLoader.class);
+
private ClassTransformer transformer = new BcelClassTransformer();
public ContinuationClassLoader(ClassLoader parent) {
super(parent);
- Repository.setRepository(new ClassLoaderRepository(parent));
+ //Repository.setRepository(new ClassLoaderRepository(parent));
}
protected synchronized Class loadClass(String name, boolean resolve)
throws ClassNotFoundException {
- // this finds also classes, which are already transformed, via findLoadedClass
- Class c = super.loadClass(name, resolve);
+
+ Class c = findLoadedClass(name);
+
+ if (c == null) {
+ if (!name.startsWith("java.") &&
+ !name.startsWith("javax.") &&
+ !name.startsWith("sun.") &&
+ !name.startsWith("org.xml.") &&
+ !name.startsWith("org.w3c.") &&
+ !name.startsWith("org.apache.commons.logging.")
+ ) {
- // transform class if class is continuable and not continuation capable
- if ((Continuable.class.isAssignableFrom(c)) &&
- (!ContinuationCapable.class.isAssignableFrom(c)) &&
- (!c.isInterface())) {
+ final InputStream is = super.getResourceAsStream(name.replace('.','/') + ".class");
+
+ if (is != null) {
+
+ if (name.startsWith("org.apache.commons.javaflow.testcode")) {
+ //log.debug("transforming " + name);
+
+ final byte data[] = transformer.transform(is);
+ return defineClass(name, data, 0, data.length);
+ }
+
+ try {
+ final byte data[] = IOUtils.toByteArray(is);
+
+ //log.debug("loading "+ name);
+
+ return defineClass(name, data, 0, data.length);
+ } catch (final IOException e) {
+ throw new ClassNotFoundException("could not read class", e);
+ }
+ } else {
+ log.debug("could not find " + name);
+ }
+ }
- JavaClass clazz = Repository.lookupClass(c);
+ final ClassLoader parent = getParent();
+ if (parent != null) {
+ //log.debug("parent loading " + name);
+ c = parent.loadClass(name);
+ } else {
+ throw new ClassNotFoundException(name);
+ }
- byte data[] = transformer.transform(clazz);
- c = defineClass(name, data, 0, data.length);
- }
- if (c == null) {
- throw new ClassNotFoundException(name);
+ } else {
+ log.debug("already loaded " + name);
}
+
if (resolve) {
resolveClass(c);
}
Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/ClassTransformer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/ClassTransformer.java?view=diff&r1=153120&r2=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/ClassTransformer.java (original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/ClassTransformer.java Wed Feb 9 13:34:11 2005
@@ -15,12 +15,12 @@
*/
package org.apache.commons.javaflow.bytecode;
-import org.apache.bcel.classfile.JavaClass;
+import java.io.InputStream;
/**
* @author tcurdt
*
*/
public interface ClassTransformer {
- byte[] transform( final JavaClass clazz );
+ byte[] transform( final InputStream is );
}
Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/RewritingResourceStore.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/RewritingResourceStore.java?view=diff&r1=153120&r2=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/RewritingResourceStore.java (original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/RewritingResourceStore.java Wed Feb 9 13:34:11 2005
@@ -55,7 +55,7 @@
public void write(String resourceName, byte[] resourceData) {
super.write(resourceName, resourceData);
changes.add(resourceName);
-
+/*
try {
final InputStream is = new ByteArrayInputStream(resourceData);
@@ -70,7 +70,8 @@
} catch (IOException e) {
e.printStackTrace();
- }
+ }
+ */
}
public void onStop() {
@@ -82,9 +83,14 @@
for (Iterator it = changes.iterator(); it.hasNext();) {
final String clazzName = (String) it.next();
try {
- final JavaClass clazz = Repository.lookupClass(clazzName);
- final byte[] clazzBytes = transformer.transform(clazz);
- super.write(clazzName, clazzBytes);
+ final byte[] oldClazz = read(clazzName);
+
+ if (oldClazz == null) {
+ throw new ClassNotFoundException("could not find " + clazzName);
+ }
+
+ final byte[] newClazz = transformer.transform(new ByteArrayInputStream(oldClazz));
+ super.write(clazzName, newClazz);
log.debug("rewrote " + clazzName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
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?view=diff&r1=153120&r2=153121
==============================================================================
--- 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 Feb 9 13:34:11 2005
@@ -25,7 +25,7 @@
*
* @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
* @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
- * @version CVS $Id: Stack.java,v 1.1 2005/01/23 03:55:22 tcurdt Exp $
+ * @version CVS $Id$
*/
public class Stack implements java.io.Serializable {
@@ -72,55 +72,78 @@
}
public double popDouble() {
- if (dTop==0)
+ if (dTop==0) {
throw new EmptyStackException("pop double");
- double d = dstack[--dTop];
- log.debug("pop double "+d+" "+toString());
+ }
+
+ final double d = dstack[--dTop];
+ log.debug("pop double " + d + " " + toString());
return d;
}
public float popFloat() {
- if (fTop==0)
+ if (fTop==0) {
throw new EmptyStackException("pop float");
- float f = fstack[--fTop];
- log.debug("pop float "+f+" "+toString());
+ }
+
+ final float f = fstack[--fTop];
+ log.debug("pop float " + f + " " + toString());
return f;
}
public int popInt() {
- if (iTop==0)
+ if (iTop==0) {
throw new EmptyStackException("pop int");
- int i = istack[--iTop];
- log.debug("pop int "+i+" "+toString());
+ }
+
+ final int i = istack[--iTop];
+ log.debug("pop int " + i + " " + toString());
return i;
}
public long popLong() {
- if (lTop==0)
+ if (lTop==0) {
throw new EmptyStackException("pop long");
- long l = lstack[--lTop];
- log.debug("pop long "+l+" "+toString());
+ }
+
+ final long l = lstack[--lTop];
+ log.debug("pop long " + l + " " + toString());
return l;
}
public Object popObject() {
- if (oTop==0)
+ if (oTop==0) {
throw new EmptyStackException("pop object");
- Object o = ostack[--oTop];
- log.debug("pop object "+ o.getClass().getName() + " " + o + " " + toString());
+ }
+
+ final Object o = ostack[--oTop];
+
+ final String clazz = getClassName(o);
+ final String clazzLoader = getClassLoaderName(o);
+
+ log.debug("pop object "+ clazz + "/" + clazzLoader + " [" + o + "] " + toString());
+
return o;
}
public Object popReference() {
- if (rTop==0)
+ if (rTop==0) {
throw new EmptyStackException("pop reference");
- Object o = rstack[--rTop];
- log.debug("pop reference "+ o.getClass().getName() + " " + o + " " + toString());
+ }
+
+ final Object o = rstack[--rTop];
+
+ final String clazz = getClassName(o);
+ final String clazzLoader = getClassLoaderName(o);
+
+ log.debug("pop reference "+ clazz + "/" + clazzLoader + " [" + o + "] " + toString());
+
return o;
}
public void pushDouble(double d) {
- log.debug("push double "+d+" "+toString());
+ log.debug("push double " + d + " " + toString());
+
dstack[dTop++] = d;
if (dTop == dstack.length) {
double[] hlp = new double[dstack.length + 10];
@@ -130,7 +153,8 @@
}
public void pushFloat(float f) {
- log.debug("push float "+f+" "+toString());
+ log.debug("push float " + f + " " + toString());
+
fstack[fTop++] = f;
if (fTop == fstack.length) {
float[] hlp = new float[fstack.length + 10];
@@ -140,7 +164,8 @@
}
public void pushInt(int i) {
- log.debug("push int "+i+" "+toString());
+ log.debug("push int " + i + " " + toString());
+
istack[iTop++] = i;
if (iTop == istack.length) {
int[] hlp = new int[istack.length + 10];
@@ -150,7 +175,8 @@
}
public void pushLong(long l) {
- log.debug("push long "+l+" "+toString());
+ log.debug("push long " + l + " " + toString());
+
lstack[lTop++] = l;
if (lTop == lstack.length) {
long[] hlp = new long[lstack.length + 10];
@@ -160,10 +186,15 @@
}
public void pushObject(Object o) {
- log.debug("push object " + o.getClass().getName() + " " + o + " " + toString());
+
+ final String clazz = getClassName(o);
+ final String clazzLoader = getClassLoaderName(o);
+
+ log.debug("push object " + clazz + "/" + clazzLoader + " [" + o + "] " + toString());
+
- if (!(o instanceof Serializable)) {
- log.warn("continuation is using class " + o.getClass().getName() + " which is not serializable");
+ if (o != null && !(o instanceof Serializable)) {
+ log.warn("continuation is using class " + clazz + " which is not serializable");
}
ostack[oTop++] = o;
@@ -175,10 +206,13 @@
}
public void pushReference(Object o) {
- log.debug("push reference " + o.getClass().getName() + " " + o + " " + toString());
+ final String clazz = getClassName(o);
+ final String clazzLoader = getClassLoaderName(o);
- if (!(o instanceof Serializable)) {
- log.warn("continuation is referencing class " + o.getClass().getName() + " which is not serializable");
+ log.debug("push reference " + clazz + "/" + clazzLoader + " [" + o + "] " + toString());
+
+ if (o != null && !(o instanceof Serializable)) {
+ log.warn("continuation is referencing class " + clazz + " which is not serializable");
}
rstack[rTop++] = o;
@@ -188,6 +222,23 @@
rstack = hlp;
}
}
+
+ 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 String toString() {
return
Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/bcel/BcelClassTransformer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/bcel/BcelClassTransformer.java?view=diff&r1=153120&r2=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/bcel/BcelClassTransformer.java (original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/bcel/BcelClassTransformer.java Wed Feb 9 13:34:11 2005
@@ -17,11 +17,14 @@
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Vector;
import org.apache.bcel.Constants;
import org.apache.bcel.Repository;
+import org.apache.bcel.classfile.ClassFormatException;
+import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.ConstantCP;
import org.apache.bcel.classfile.ConstantNameAndType;
import org.apache.bcel.classfile.ConstantPool;
@@ -98,7 +101,21 @@
private boolean currentMethodStatic = false;
private boolean debug = true;
- public byte[] transform(final JavaClass javaClazz) {
+ public byte[] transform(final InputStream is) {
+
+ final ClassParser parser = new ClassParser(is, null);
+ JavaClass javaClazz = null;
+ try {
+ javaClazz = parser.parse();
+ } catch (ClassFormatException e2) {
+ e2.printStackTrace();
+ } catch (IOException e2) {
+ e2.printStackTrace();
+ }
+
+ Repository.addClass(javaClazz);
+
+
log.debug("transforming class " + javaClazz.getClassName());
//final JavaClass clazz = Repository.lookupClass(clazzName);
@@ -522,7 +539,10 @@
// rewrite invocation if object is continuable or a continuation
// object
- return Repository.implementationOf(classname, CONTINUABLE_CLASS) || Repository.instanceOf(classname, CONTINUATION_CLASS);
+
+ // FIXME:
+ //return Repository.implementationOf(classname, CONTINUABLE_CLASS) || Repository.instanceOf(classname, CONTINUATION_CLASS);
+ return true;
}
return false;
}
Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractClassLoaderTestCase.java?view=auto&rev=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractClassLoaderTestCase.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/AbstractClassLoaderTestCase.java Wed Feb 9 13:34:11 2005
@@ -0,0 +1,54 @@
+/*
+ * 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 java.lang.reflect.Method;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.javaflow.utils.ReflectionUtils;
+
+/**
+ * @author tcurdt
+ *
+ */
+public abstract class AbstractClassLoaderTestCase extends TestCase {
+
+ final String clazzName;
+
+ protected AbstractClassLoaderTestCase(final String pClazzName) {
+ clazzName = pClazzName;
+ }
+
+ protected void call(final String methodName) throws Exception {
+ final ClassLoader cl = new ContinuationClassLoader(getClass().getClassLoader());
+ final Class clazz = cl.loadClass(clazzName);
+ final Object instance = clazz.newInstance();
+ assertNotNull(clazz);
+
+ // get all methods
+ final Map methods = ReflectionUtils.discoverMethods(clazz);
+ assertNotNull(methods);
+ assertTrue(methods.size() > 0);
+
+ Thread.currentThread().setContextClassLoader(cl);
+
+ final Method method = (Method) methods.get(methodName);
+ method.invoke(instance, new Object[] { });
+ }
+
+}
Modified: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationCompilingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationCompilingClassLoaderTestCase.java?view=diff&r1=153120&r2=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationCompilingClassLoaderTestCase.java (original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationCompilingClassLoaderTestCase.java Wed Feb 9 13:34:11 2005
@@ -52,9 +52,5 @@
}
*/
}
-
- public static void main(String[] args) throws Exception {
- ContinuationCompilingClassLoaderTestCase t = new ContinuationCompilingClassLoaderTestCase();
- t.testReloading();
- }
+
}
Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationTestCase.java?view=auto&rev=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationTestCase.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationTestCase.java Wed Feb 9 13:34:11 2005
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+
+
+/**
+ * @author tcurdt
+ *
+ */
+public final class ContinuationTestCase extends AbstractClassLoaderTestCase {
+
+ public ContinuationTestCase() {
+ super("org.apache.commons.javaflow.ContinuationTests");
+ }
+
+ public void testHierarchy() throws Exception {
+ call("testHierarchy");
+ }
+
+ public void testIncorrectUsageWithNormalClassLoader() throws Exception {
+ call("testIncorrectUsageWithNormalClassLoader");
+ }
+
+}
Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationTests.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationTests.java?view=auto&rev=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationTests.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationTests.java Wed Feb 9 13:34:11 2005
@@ -0,0 +1,111 @@
+/*
+ * 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 java.lang.reflect.Method;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.javaflow.testcode.Calculator;
+import org.apache.commons.javaflow.utils.ReflectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author tcurdt
+ *
+ */
+public final class ContinuationTests {
+
+ private final static Log log = LogFactory.getLog(ContinuationTests.class);
+
+ private ContinuationContext createContinuationContext() {
+
+ final Map methods = ReflectionUtils.discoverMethods(Calculator.class);
+ TestCase.assertNotNull(methods);
+ TestCase.assertTrue(methods.size() > 0);
+
+ final MethodLookup lookup = new MethodLookup() {
+ public Method getMethod(final String methodName) {
+ final Method method = (Method) methods.get(methodName);
+ if (method == null) {
+ throw new NullPointerException("method " + methodName + " could not be found");
+ }
+ return method;
+ }
+ };
+
+ final ContinuationContext context = new ContinuationContext();
+ context.setMethodLookup(lookup);
+
+ return context;
+ }
+
+ public void testHierarchy() throws Exception {
+
+ log.debug("Testing hierarchy...");
+
+ Continuation continuation = null;
+ ContinuationContext context = createContinuationContext();
+
+ TestCase.assertTrue(
+ Calculator.global == 0 &&
+ Calculator.local == 0
+ );
+
+ continuation = Continuation.startWith("main", context);
+ TestCase.assertTrue(
+ Calculator.global == 1 &&
+ Calculator.local == 1
+ );
+
+ final Continuation parent = continuation;
+
+ context = createContinuationContext();
+
+ final Continuation continuation11 = Continuation.continueWith(parent, context);
+ TestCase.assertTrue(
+ Calculator.global == 2 &&
+ Calculator.local == 2
+ );
+
+ final Continuation continuation12 = Continuation.continueWith(parent, context);
+ TestCase.assertTrue(
+ Calculator.global == 3 &&
+ Calculator.local == 2
+ );
+
+ }
+
+ public void testIncorrectUsageWithNormalClassLoader() throws Exception {
+
+ log.debug("Testing incorrect use of continuation...");
+
+ boolean exceptionThrown = false;
+
+ try {
+ final Calculator c = new Calculator();
+ c.main();
+ } catch (final Exception e) {
+ log.debug("Catching a " + e);
+ TestCase.assertTrue(e instanceof IllegalStateException);
+ exceptionThrown = true;
+ }
+
+ TestCase.assertTrue(exceptionThrown);
+ }
+}
Added: 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?view=auto&rev=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTestCase.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTestCase.java Wed Feb 9 13:34:11 2005
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+
+
+/**
+ * @author tcurdt
+ *
+ */
+public final class SerializationTestCase extends AbstractClassLoaderTestCase {
+
+ public SerializationTestCase() {
+ super("org.apache.commons.javaflow.SerializationTests");
+ }
+
+ public void testStart() throws Exception {
+ call("testStart");
+ }
+
+ public void testResume() throws Exception {
+ call("testResume");
+ }
+}
Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTests.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTests.java?view=auto&rev=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTests.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/SerializationTests.java Wed Feb 9 13:34:11 2005
@@ -0,0 +1,114 @@
+/*
+ * 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 java.io.FileOutputStream;
+import java.io.FileReader;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.javaflow.testcode.Calculator;
+import org.apache.commons.javaflow.utils.ReflectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tools.ant.util.FileUtils;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+
+/**
+ * @author tcurdt
+ *
+ */
+public final class SerializationTests {
+
+ private final static Log log = LogFactory.getLog(SerializationTests.class);
+
+
+ private ContinuationContext createContinuationContext() {
+
+ final Map methods = ReflectionUtils.discoverMethods(Calculator.class);
+ TestCase.assertNotNull(methods);
+ TestCase.assertTrue(methods.size() > 0);
+
+ final MethodLookup lookup = new MethodLookup() {
+ public Method getMethod(final String methodName) {
+ final Method method = (Method) methods.get(methodName);
+ if (method == null) {
+ throw new NullPointerException("method " + methodName + " could not be found");
+ }
+ return method;
+ }
+ };
+
+ final ContinuationContext context = new ContinuationContext();
+ context.setMethodLookup(lookup);
+
+ return context;
+ }
+
+
+ public void testStart() throws Exception {
+
+ final ContinuationContext context = createContinuationContext();
+
+ TestCase.assertTrue(
+ Calculator.global == 0 &&
+ Calculator.local == 0
+ );
+
+ final Continuation continuation = Continuation.startWith("main", context);
+
+ log.debug("back from contination " + continuation);
+
+ TestCase.assertTrue(
+ Calculator.global == 1 &&
+ Calculator.local == 1
+ );
+
+ final XStream xstream = new XStream(new DomDriver());
+ final String xml = xstream.toXML(continuation);
+ final FileOutputStream fos = new FileOutputStream("continuation.xml");
+ fos.write(xml.getBytes());
+
+ log.debug("continuation saved " + continuation);
+
+ }
+
+ public void testResume() throws Exception {
+
+ final ContinuationContext context = createContinuationContext();
+
+ final String xml = FileUtils.readFully(new FileReader("continuation.xml"));
+ final XStream xstream = new XStream(new DomDriver());
+ final Object o = xstream.fromXML(xml);
+
+ final Continuation parent = (Continuation) o;
+
+ log.debug("continuation restored " + parent);
+
+ final Continuation continuation = Continuation.continueWith(parent, context);
+
+ log.debug("back from contination " + continuation);
+
+ TestCase.assertTrue( "g=" + Calculator.global + " l=" + Calculator.local,
+ Calculator.global == 1 &&
+ Calculator.local == 2
+ );
+ }
+}
Modified: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/Calculator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/Calculator.java?view=diff&r1=153120&r2=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/Calculator.java (original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/Calculator.java Wed Feb 9 13:34:11 2005
@@ -30,31 +30,32 @@
private static final Log log = LogFactory.getLog(Calculator.class);
- private int global = 0;
- private int local = 0;
+ public static transient int global;
+ public static transient int local;
public void main() {
+ global = 0;
+ local = 0;
+
+ SomeReference ref = new SomeReference();
+
int l = 0;
- log.debug("Start of Calculator: g=" + global + " l=" + local);
+ log.debug("Start of Calculator@" + hashCode() + ": g=" + global + " l=" + l);
global++;
local = ++l;
- log.debug("Calculator Step 1: g=" + global + " l=" + local);
+ log.debug("Calculator@" + hashCode() + " Step 1: g=" + global + " l=" + l);
Continuation.suspend();
- log.debug("Calculator Step 2: g=" + global + " l=" + local);
+ log.debug("Calculator@" + hashCode() + " Step 2: g=" + global + " l=" + l);
global++;
local = ++l;
- log.debug("End of Calculator: g=" + global + " l=" + local);
- }
-
- public String toString() {
- return "" + global + "." + local;
- }
+ log.debug("End of Calculator@" + hashCode() + ": g=" + global + " l=" + l);
+ }
}
Added: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/SomeReference.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/SomeReference.java?view=auto&rev=153121
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/SomeReference.java (added)
+++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/SomeReference.java Wed Feb 9 13:34:11 2005
@@ -0,0 +1,26 @@
+/*
+ * 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.testcode;
+
+import java.io.Serializable;
+
+/**
+ * @author tcurdt
+ *
+ */
+public class SomeReference implements Serializable {
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org