You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Sciss <co...@sciss.de> on 2007/12/02 21:45:20 UTC

[javaflow] Re: getting javaflow

thank you wendy, un-commenting the <repository> elements in pom.xml  
helped.

now i get a runtime exception from running the tutorial example. i'm  
trying to use the dynamic method, having a regular class JavaflowTest  
and one MyRunnable that gets loaded with the special javaflow class  
loader:

// continuation test from the javaflow tutorial
import org.apache.commons.javaflow.*;

public class MyRunnable
{
	public MyRunnable()
	{
		Continuation d = Continuation.startWith(new Runnable() {
			public void run() {
				System.out.println("started!");
				for( int i=0; i<10; i++ )
					echo(i);
			}

			private void echo(int x) {
				System.out.println(x);
				Continuation.suspend();
			}
		});
		System.out.println("returned a continuation");
		while(d!=null) {
			d = Continuation.continueWith(d);
		}  	
    	}
}

// helper class to run the example
import org.apache.commons.javaflow.*;
import java.net.*;

public class JavaflowTest {
	public static void main( String[] args )
	{
	    try {
      	final ClassLoader cl = new ContinuationClassLoader(
            new URL[]{ new URL( "file://MyRunnable.jar" )},
            JavaflowTest.class.getClassLoader()); // parent class loader
          final Class clz = cl.loadClass( "MyRunnable" );
		 clz.newInstance();
		}
		catch( Exception e ) { e.printStackTrace(); }
	}
}

i'm preparing the URL class loader jar using

$ jar cvf MyRunnable.jar MyRunnable.class

and i run the test using

$ java -cp ../fromSVN/javaflow/trunk/target/javaflow-1.0- 
SNAPSHOT.jar:../fromSVN/javaflow/trunk/lib/bcel-5.2.jar:../commons- 
logging-1.1.1/commons-logging-1.1.1.jar:. JavaflowTest

but end up with

started!
0
1
2
3
4
5
6
7
8
9
02.12.2007 21:41:47  
org.apache.commons.javaflow.bytecode.StackRecorder execute
SCHWERWIEGEND: stack corruption. Is class MyRunnable$1 instrumented  
for javaflow?
java.lang.IllegalStateException: stack corruption. Is class MyRunnable 
$1 instrumented for javaflow?
         at org.apache.commons.javaflow.bytecode.StackRecorder.execute 
(StackRecorder.java:103)
         at org.apache.commons.javaflow.Continuation.continueWith 
(Continuation.java:171)
         at org.apache.commons.javaflow.Continuation.startWith 
(Continuation.java:130)
         at org.apache.commons.javaflow.Continuation.startWith 
(Continuation.java:103)
         at MyRunnable.<init>(MyRunnable.java:7)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0 
(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance 
(NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance 
(DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance 
(Constructor.java:494)
         at java.lang.Class.newInstance0(Class.java:350)
         at java.lang.Class.newInstance(Class.java:303)
         at JavaflowTest.main(JavaflowTest.java:12)


thanks again for help! ciao, -sciss-



Am 02.12.2007 um 19:57 schrieb Wendy Smoak:

> On Dec 2, 2007 11:39 AM, Sciss <co...@sciss.de> wrote:
>
>> i'm trying to do the javaflow tutorial from http:// 
>> commons.apache.org/
>> sandbox/javaflow/tutorial.html , but i don't know how to download and
>> install javaflow. both
>>
>> http://vmgump.apache.org/gump/public-jars/commons-sandbox/jars/
>> http://people.apache.org/builds/jakarta-commons/nightly/
>>
>> don't have a .jar at hand. i did
>
> The only snapshots I can find are here, but they're really old...
> http://people.apache.org/repo/m1-snapshot-repository/commons- 
> javaflow/jars/
>
> (Also, please tag future subject lines with [javaflow] to help people
> sort messages.)
>
>> $ svn co http://svn.apache.org/repos/asf/commons/sandbox/javaflow
>>
>> , found that i need a build-tool called maven, downloaded maven,  
>> tried
>>
>> $ ~/Desktop/apache-maven-2.0.8/bin/mvn clean install
>>
>> but only get an error message
>
> Edit the javaflow/trunk/pom.xml file and un-comment the <repository>
> elements that you see there.  After that, it builds for me.
>
> Another option is to check out commons-sandbox-parent and build that
> locally with:
>   svn co http://svn.apache.org/repos/asf/commons/proper/commons- 
> sandbox-parent/trunk/
> commons-sandbox-parent
>   cd commons-sandbox-parent
>   mvn install
>
> HTH,
> -- 
> Wendy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


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


Re: [javaflow] Re: getting javaflow

Posted by Sciss <co...@sciss.de>.
i have a rather ugly workaround by reading/writing the seed from a  
local variable:

	private static class MyRandom
	extends java.util.Random
	{
	    private long seed;
	    private final static long multiplier = 0x5DEECE66DL;
	    private final static long addend = 0xBL;
	    private final static long mask = (1L << 48) - 1;
		
	    synchronized public void setSeed( long seed ) {
	        seed = (seed ^ multiplier) & mask;
	    }

	    protected int next( int bits ) {
	    	seed = (seed * multiplier + addend) & mask;
	        return (int) (seed >>> (48 - bits));
	    }
	};

	private void test()
	{
		final Runnable r = new Runnable() {
			public void run()
			{
				final MyRandom rnd = new MyRandom();
				int value	= 500;
				int d;
				long seedCopy = rnd.seed;
				
				while( true ) {
					rnd.seed = seedCopy;
					d = rnd.nextInt( 51 ) - 25;
					seedCopy = rnd.seed;
					System.out.println( "val = " + value + "; d = " + d );
					value += d;
					if( value < 0 ) {
						value += 1001;
					} else if( value > 1000 ) {
						value -= 1001;
					}
					Continuation.suspend();
				}
			}
		};

		final Continuation c = Continuation.startSuspendedWith( r );
		Continuation d;
		d = c;
		System.out.println( "First run" );
		for( int i = 0; i < 5; i++ ) d = Continuation.continueWith( d );
		d = c;
		System.out.println( "Second run" );
		for( int i = 0; i < 5; i++ ) d = Continuation.continueWith( d );
	}


... but i would a prefer a solution that is "opaque" to the person  
that writes the Runnable. Also i will have additional problems with  
other objects.

In fact java.util.Random implements Serializable, so it can indeed be  
re-stored with its old seed...

ciao, -sciss-


Am 04.12.2007 um 18:53 schrieb Sciss:

> hello torsten,
>
> i have another question: how can i include objects other than  
> primitives into the continuation storage? in this example:
>
> 		final Runnable r = new Runnable() {
> 			public void run()
> 			{
> 				final java.util.Random rnd = new java.util.Random();
> 				int value	= 500;
> 				int d;
> 				
> 				while( true ) {
> 					d = rnd.nextInt( 51 ) - 25;
> 					System.out.println( "val = " + value + "; d = " + d );
> 					value += d;
> 					if( value < 0 ) {
> 						value += 1001;
> 					} else if( value > 1000 ) {
> 						value -= 1001;
> 					}
> 					Continuation.suspend();
> 				}
> 			}
> 		};
>
> 		final Continuation c = Continuation.startSuspendedWith( r );
> 		Continuation d;
>
> 		System.out.println( "First run" );
> 		d = c;
> 		for( int i = 0; i < 5; i++ ) d = Continuation.continueWith( d );
>
> 		System.out.println( "Second run" );
> 		d = c;
> 		for( int i = 0; i < 5; i++ ) d = Continuation.continueWith( d );
>
> ... the output is something like:
>
> 	First run
> 	val = 500; d = 11
> 	val = 511; d = 5
> 	val = 516; d = -19
> 	val = 497; d = 11
> 	val = 508; d = 21
> 	Second run
> 	val = 500; d = -25
> 	val = 475; d = -6
> 	val = 469; d = -15
> 	val = 454; d = -11
> 	val = 443; d = 9
>
> so obviously 'value' got restored, but the random generator doesn't  
> restore its seed. so can i make javaflow store the internal state  
> of 'rnd', too?
>
> thanks, -sciss-
>
>
>
>
>
> Am 04.12.2007 um 16:04 schrieb Torsten Curdt:
>
>> Great! ...but still added the example to my TODO.
>> Javaflow needs some polishing anyway.
>>
>> cheers
>> --
>> Torsten
>>
>> On 04.12.2007, at 14:51, Sciss wrote:
>>
>>> thank you torsten,
>>>
>>> putting my runnable in a dedicated package and using  
>>> addLoaderPackageRoot("your.package.the.runnable.is.in") did it!
>>>
>>> now going back to experimentation ;-9
>>>
>>> ciao, -sciss-
>>>
>>>
>>> Am 03.12.2007 um 12:23 schrieb Torsten Curdt:
>>>
>>>> Seems like I badly need to look into providing the tutorial  
>>>> example to just run out of the box.
>>>>
>>>> On the first glance your try on the class loading seems a bit  
>>>> unorthodox but should still work. (I never used the classloader  
>>>> but always used javaflow through jci) ...but looking at the code  
>>>> I'd assume you also need to tell the classloader what classes to  
>>>> instrument. You might want to try
>>>>
>>>>   addLoaderPackageRoot("your.package.the.runnable.is.in");
>>>>
>>>> or set
>>>>
>>>>   setParentFirst(false);
>>>>
>>>> Let me know if that helped.
>>>>
>>>> cheers
>>>> --
>>>> Torsten
>>>>
>>>> ------------------------------------------------------------------- 
>>>> --
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>
>>>
>>> -------------------------------------------------------------------- 
>>> -
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


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


Re: [javaflow] Re: getting javaflow

Posted by Sciss <co...@sciss.de>.
hello torsten,

i have another question: how can i include objects other than  
primitives into the continuation storage? in this example:

		final Runnable r = new Runnable() {
			public void run()
			{
				final java.util.Random rnd = new java.util.Random();
				int value	= 500;
				int d;
				
				while( true ) {
					d = rnd.nextInt( 51 ) - 25;
					System.out.println( "val = " + value + "; d = " + d );
					value += d;
					if( value < 0 ) {
						value += 1001;
					} else if( value > 1000 ) {
						value -= 1001;
					}
					Continuation.suspend();
				}
			}
		};

		final Continuation c = Continuation.startSuspendedWith( r );
		Continuation d;

		System.out.println( "First run" );
		d = c;
		for( int i = 0; i < 5; i++ ) d = Continuation.continueWith( d );

		System.out.println( "Second run" );
		d = c;
		for( int i = 0; i < 5; i++ ) d = Continuation.continueWith( d );

... the output is something like:

	First run
	val = 500; d = 11
	val = 511; d = 5
	val = 516; d = -19
	val = 497; d = 11
	val = 508; d = 21
	Second run
	val = 500; d = -25
	val = 475; d = -6
	val = 469; d = -15
	val = 454; d = -11
	val = 443; d = 9

so obviously 'value' got restored, but the random generator doesn't  
restore its seed. so can i make javaflow store the internal state of  
'rnd', too?

thanks, -sciss-





Am 04.12.2007 um 16:04 schrieb Torsten Curdt:

> Great! ...but still added the example to my TODO.
> Javaflow needs some polishing anyway.
>
> cheers
> --
> Torsten
>
> On 04.12.2007, at 14:51, Sciss wrote:
>
>> thank you torsten,
>>
>> putting my runnable in a dedicated package and using  
>> addLoaderPackageRoot("your.package.the.runnable.is.in") did it!
>>
>> now going back to experimentation ;-9
>>
>> ciao, -sciss-
>>
>>
>> Am 03.12.2007 um 12:23 schrieb Torsten Curdt:
>>
>>> Seems like I badly need to look into providing the tutorial  
>>> example to just run out of the box.
>>>
>>> On the first glance your try on the class loading seems a bit  
>>> unorthodox but should still work. (I never used the classloader  
>>> but always used javaflow through jci) ...but looking at the code  
>>> I'd assume you also need to tell the classloader what classes to  
>>> instrument. You might want to try
>>>
>>>   addLoaderPackageRoot("your.package.the.runnable.is.in");
>>>
>>> or set
>>>
>>>   setParentFirst(false);
>>>
>>> Let me know if that helped.
>>>
>>> cheers
>>> --
>>> Torsten
>>>
>>> -------------------------------------------------------------------- 
>>> -
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


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


Re: [javaflow] Re: getting javaflow

Posted by Torsten Curdt <tc...@apache.org>.
Great! ...but still added the example to my TODO.
Javaflow needs some polishing anyway.

cheers
--
Torsten

On 04.12.2007, at 14:51, Sciss wrote:

> thank you torsten,
>
> putting my runnable in a dedicated package and using  
> addLoaderPackageRoot("your.package.the.runnable.is.in") did it!
>
> now going back to experimentation ;-9
>
> ciao, -sciss-
>
>
> Am 03.12.2007 um 12:23 schrieb Torsten Curdt:
>
>> Seems like I badly need to look into providing the tutorial  
>> example to just run out of the box.
>>
>> On the first glance your try on the class loading seems a bit  
>> unorthodox but should still work. (I never used the classloader  
>> but always used javaflow through jci) ...but looking at the code  
>> I'd assume you also need to tell the classloader what classes to  
>> instrument. You might want to try
>>
>>   addLoaderPackageRoot("your.package.the.runnable.is.in");
>>
>> or set
>>
>>   setParentFirst(false);
>>
>> Let me know if that helped.
>>
>> cheers
>> --
>> Torsten
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


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


Re: [javaflow] Re: getting javaflow

Posted by Sciss <co...@sciss.de>.
thank you torsten,

putting my runnable in a dedicated package and using  
addLoaderPackageRoot("your.package.the.runnable.is.in") did it!

now going back to experimentation ;-9

ciao, -sciss-


Am 03.12.2007 um 12:23 schrieb Torsten Curdt:

> Seems like I badly need to look into providing the tutorial example  
> to just run out of the box.
>
> On the first glance your try on the class loading seems a bit  
> unorthodox but should still work. (I never used the classloader but  
> always used javaflow through jci) ...but looking at the code I'd  
> assume you also need to tell the classloader what classes to  
> instrument. You might want to try
>
>   addLoaderPackageRoot("your.package.the.runnable.is.in");
>
> or set
>
>   setParentFirst(false);
>
> Let me know if that helped.
>
> cheers
> --
> Torsten
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


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


Re: [javaflow] Re: getting javaflow

Posted by Torsten Curdt <tc...@apache.org>.
Seems like I badly need to look into providing the tutorial example  
to just run out of the box.

On the first glance your try on the class loading seems a bit  
unorthodox but should still work. (I never used the classloader but  
always used javaflow through jci) ...but looking at the code I'd  
assume you also need to tell the classloader what classes to  
instrument. You might want to try

   addLoaderPackageRoot("your.package.the.runnable.is.in");

or set

   setParentFirst(false);

Let me know if that helped.

cheers
--
Torsten

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