You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jeff Hair <kn...@gmail.com> on 2011/06/24 16:53:58 UTC

[Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Hello everyone,

I have two problems. The relevant stack traces are here:

https://gist.github.com/1044901

I started using Javaflow yesterday in order to implement coroutines into an
interpreter that I'm working on. I made a simple test case, and it worked
despite some really weird build errors. This is my first problem: when using
the ant task to enhance bytecode, javaflow spews out ClasssNotFoundException
errors for every class I'm enhancing. Despite this, the ant build completes
successfully and javaflow seems to work. These exceptions are emitted as
warnings in ant. I'm trying to figure out how to get rid of those warnings
without just suppressing build warnings in ant.

The second problem is much more important. In my (most likely naive and
misguided) implementation of coroutines, I'm getting class cast exceptions
when I attempt to resume a suspended function call. In my interpreter, every
object is an EveObject as far as Java is concerned. Functions (of type
eve.core.Function) are wrapped inside eve.core.EveObject. I implemented some
basic attempt at coroutines/continuations here:

https://github.com/ProjectMoon/eve2/blob/coroutines/src/eve/scope/ScopeManager.java#L344
https://github.com/ProjectMoon/eve2/blob/coroutines/src/eve/statements/expressions/ResumeExpression.java
https://github.com/ProjectMoon/eve2/blob/coroutines/src/eve/statements/expressions/YieldExpression.java

The ScopeManager's invokeCoroutine method is what handles the state tracking
for continuation dispatching in order to make coroutines possible.
YieldExpression (taking the form of "yield <expression>") will yield the
current function to a function returned by <expression>. The resume
statement currently just invokes a function as a coroutine. If the function
identified by the yield statement has not yet been executed as a
continuation, it works fine. But as soon as I try to resume a coroutine that
has been suspended, it craps out with a ClassCastException about trying to
cast an eve.core.Function to an eve.core.EveObject.

I find this very odd. Is it a bug in the library, or am I just doing
something wrong? If anyone would like to help with this, it would be much
appreciated. I uploaded this branch to the GitHub repository if anyone wants
to pull it down and build it. The git repository is:

git://github.com/ProjectMoon/eve2.git

To build it, make sure Ant and Ivy are installed. Run `ant dependencies` and
then `ant jar`. It will pull down the Javaflow library from SVN, build it,
put into the local MVN repo, and then use it as an Ivy dependency along with
everything else. Dependency resolution should only take about 5-6 minutes on
a good connection. After that, building takes ~5 seconds. I've only ever
built it on *nix systems, but I'd assume it will build on Windows too...

I have two particular test cases. One is a test.eve file, while the other is
a hardcoded coroutines test written in Java. Both will produce the same type
of error.

test.eve is invoked thus (assuming Java 1.6):
java -jar dist/eve.jar test.eve

The Java test invoked thus (again, assuming Java 1.6):
java -cp "dist/*:dist/lib/*" eve.core.CoroutinesTest

Re: [Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by wayne <wh...@gmail.com>.
I also met the first problem. but  it seems I  can get
the rewritting classes.


>From  Wayne

2011/6/27 Torsten Curdt <tc...@vafer.org>:
> Hey Jeff,
>
> the good news - I was able to reproduce it with your code base.
> Both the exceptions during rewrite and the exception during resume.
>
> I haven't looked at the ASM code in a long time. Seems like there is
> something fishy going on. Maybe the exceptions prevent proper
> instrumentation. I would have to dig into that.
>
> There a couple of things you can try.
>
> - Try the ClassLoader based rewriting to see if you still get the exceptions
> - Question is why the classes cannot be found. Check the classpath.
> - Give the old BCEL rewriting a try. Just to compare the results.
>
> Either way - a test case that can reproduce this in the javaflow tests
> would make it much easier for me to help you out.
>
> HTH
>
> 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] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by Jeff Hair <kn...@gmail.com>.
>
> Ouch. Got a very long method?
> Javaflow inserts branch instructions and obviously a jump got too big
> there.


Alright, it looks like the ANTLR code was what was screwing up BCEL. It
built without any "warnings" and is not giving off any ClassCastExceptions.
It is, however, going into an infinite loop but I think that's my own
problem. So it's definitely something in the ASM transformer.

Re: [Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by Jeff Hair <kn...@gmail.com>.
>
> Ouch. Got a very long method?
> Javaflow inserts branch instructions and obviously a jump got too big
> there.


Apparently. What constitutes very long? I don't think I have anything HUGE..

Re: [Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by Jeff Hair <kn...@gmail.com>.
>
> Ouch. Got a very long method?
> Javaflow inserts branch instructions and obviously a jump got too big
> there.


Actually, it's probably the ANTLR code. Let me try excluding that.

Re: [Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by Torsten Curdt <tc...@vafer.org>.
> Alright, so I set mode="bcel" on the javaflow attribute, and wind up with an
> exception. It's detailed as the third entry in the gist:

Ouch. Got a very long method?
Javaflow inserts branch instructions and obviously a jump got too big there.

> In the meantime, I'm still working on trying to make a test case for the ASM
> builder.

Great. Thanks!

cheers,
Torsten

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


Re: [Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by Jeff Hair <kn...@gmail.com>.
Alright, so I set mode="bcel" on the javaflow attribute, and wind up with an
exception. It's detailed as the third entry in the gist:

https://gist.github.com/1044901

It says "Branch target offset too large for short."

In the meantime, I'm still working on trying to make a test case for the ASM
builder.

On Tue, Jun 28, 2011 at 4:35 PM, Torsten Curdt <tc...@vafer.org> wrote:

> It's a bit hidden...
>
>
> https://svn.apache.org/repos/asf/commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/ant/AntRewriteTask.java
>
> ...shows there is a "mode" attribute.
>
> cheers,
> Torsten
>
> On Tue, Jun 28, 2011 at 20:09, Jeff Hair <kn...@gmail.com> wrote:
> > Thanks for the references. One more thing: how do I enable the BCEL
> bytecode
> > enhancing?
> >
> > On Mon, Jun 27, 2011 at 11:44 AM, Torsten Curdt <tc...@vafer.org>
> wrote:
> >
> >> Hey Jeff,
> >>
> >> > I will try your suggestions. In the meantime, can you point me to how
> I
> >> > would go about converting this problem to a test case?
> >>
> >> did you already have a look at the current tests?
> >>
> >>
> >>
> https://svn.apache.org/repos/asf/commons/sandbox/javaflow/trunk/src/test/java/org/apache/commons/javaflow/rewrite/
> >>
> >> > I'm not even sure if
> >> > I can reproduce it yet. I haven't been able to identify what
> specifically
> >> > caused the problem. My original coroutine prototype was using a
> <String,
> >> > Continuation> map where the "yield statement" (a method call) would
> just
> >> > yield to a continuation identified by a string name. I copied that
> logic
> >> > verbatim, basically just changing the types. Of course, there's a lot
> >> more
> >> > going on in the interpreter, so it's probably something to do with
> that.
> >>
> >> I would start with a simple continuation testcase that works and then
> >> modify towards your use case until it breaks.
> >>
> >> cheers,
> >> Torsten
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: user-help@commons.apache.org
> >>
> >>
> >
>
>
>
> --
> http://www.yourdailygeekery.com
> http://www.torstencurdt.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by Torsten Curdt <tc...@vafer.org>.
It's a bit hidden...

https://svn.apache.org/repos/asf/commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/ant/AntRewriteTask.java

...shows there is a "mode" attribute.

cheers,
Torsten

On Tue, Jun 28, 2011 at 20:09, Jeff Hair <kn...@gmail.com> wrote:
> Thanks for the references. One more thing: how do I enable the BCEL bytecode
> enhancing?
>
> On Mon, Jun 27, 2011 at 11:44 AM, Torsten Curdt <tc...@vafer.org> wrote:
>
>> Hey Jeff,
>>
>> > I will try your suggestions. In the meantime, can you point me to how I
>> > would go about converting this problem to a test case?
>>
>> did you already have a look at the current tests?
>>
>>
>> https://svn.apache.org/repos/asf/commons/sandbox/javaflow/trunk/src/test/java/org/apache/commons/javaflow/rewrite/
>>
>> > I'm not even sure if
>> > I can reproduce it yet. I haven't been able to identify what specifically
>> > caused the problem. My original coroutine prototype was using a <String,
>> > Continuation> map where the "yield statement" (a method call) would just
>> > yield to a continuation identified by a string name. I copied that logic
>> > verbatim, basically just changing the types. Of course, there's a lot
>> more
>> > going on in the interpreter, so it's probably something to do with that.
>>
>> I would start with a simple continuation testcase that works and then
>> modify towards your use case until it breaks.
>>
>> cheers,
>> Torsten
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>



-- 
http://www.yourdailygeekery.com
http://www.torstencurdt.com

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


Re: [Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by Jeff Hair <kn...@gmail.com>.
Thanks for the references. One more thing: how do I enable the BCEL bytecode
enhancing?

On Mon, Jun 27, 2011 at 11:44 AM, Torsten Curdt <tc...@vafer.org> wrote:

> Hey Jeff,
>
> > I will try your suggestions. In the meantime, can you point me to how I
> > would go about converting this problem to a test case?
>
> did you already have a look at the current tests?
>
>
> https://svn.apache.org/repos/asf/commons/sandbox/javaflow/trunk/src/test/java/org/apache/commons/javaflow/rewrite/
>
> > I'm not even sure if
> > I can reproduce it yet. I haven't been able to identify what specifically
> > caused the problem. My original coroutine prototype was using a <String,
> > Continuation> map where the "yield statement" (a method call) would just
> > yield to a continuation identified by a string name. I copied that logic
> > verbatim, basically just changing the types. Of course, there's a lot
> more
> > going on in the interpreter, so it's probably something to do with that.
>
> I would start with a simple continuation testcase that works and then
> modify towards your use case until it breaks.
>
> cheers,
> Torsten
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by Torsten Curdt <tc...@vafer.org>.
Hey Jeff,

> I will try your suggestions. In the meantime, can you point me to how I
> would go about converting this problem to a test case?

did you already have a look at the current tests?

https://svn.apache.org/repos/asf/commons/sandbox/javaflow/trunk/src/test/java/org/apache/commons/javaflow/rewrite/

> I'm not even sure if
> I can reproduce it yet. I haven't been able to identify what specifically
> caused the problem. My original coroutine prototype was using a <String,
> Continuation> map where the "yield statement" (a method call) would just
> yield to a continuation identified by a string name. I copied that logic
> verbatim, basically just changing the types. Of course, there's a lot more
> going on in the interpreter, so it's probably something to do with that.

I would start with a simple continuation testcase that works and then
modify towards your use case until it breaks.

cheers,
Torsten

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


Re: [Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by Jeff Hair <kn...@gmail.com>.
I will try your suggestions. In the meantime, can you point me to how I
would go about converting this problem to a test case? I'm not even sure if
I can reproduce it yet. I haven't been able to identify what specifically
caused the problem. My original coroutine prototype was using a <String,
Continuation> map where the "yield statement" (a method call) would just
yield to a continuation identified by a string name. I copied that logic
verbatim, basically just changing the types. Of course, there's a lot more
going on in the interpreter, so it's probably something to do with that.

On Mon, Jun 27, 2011 at 3:03 AM, Torsten Curdt <tc...@vafer.org> wrote:

> Hey Jeff,
>
> the good news - I was able to reproduce it with your code base.
> Both the exceptions during rewrite and the exception during resume.
>
> I haven't looked at the ASM code in a long time. Seems like there is
> something fishy going on. Maybe the exceptions prevent proper
> instrumentation. I would have to dig into that.
>
> There a couple of things you can try.
>
> - Try the ClassLoader based rewriting to see if you still get the
> exceptions
> - Question is why the classes cannot be found. Check the classpath.
> - Give the old BCEL rewriting a try. Just to compare the results.
>
> Either way - a test case that can reproduce this in the javaflow tests
> would make it much easier for me to help you out.
>
> HTH
>
> cheers,
> Torsten
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [Javaflow] Weird ClassCastException and ClassNotFoundExceptions during build

Posted by Torsten Curdt <tc...@vafer.org>.
Hey Jeff,

the good news - I was able to reproduce it with your code base.
Both the exceptions during rewrite and the exception during resume.

I haven't looked at the ASM code in a long time. Seems like there is
something fishy going on. Maybe the exceptions prevent proper
instrumentation. I would have to dig into that.

There a couple of things you can try.

- Try the ClassLoader based rewriting to see if you still get the exceptions
- Question is why the classes cannot be found. Check the classpath.
- Give the old BCEL rewriting a try. Just to compare the results.

Either way - a test case that can reproduce this in the javaflow tests
would make it much easier for me to help you out.

HTH

cheers,
Torsten

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