Bug 37758 - Weaving rt.jar results in stack overflow
Summary: Weaving rt.jar results in stack overflow
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: ---   Edit
Assignee: Jim Hugunin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-16 09:02 EDT by James Howe CLA
Modified: 2003-05-21 14:05 EDT (History)
0 users

See Also:


Attachments
Aspect used in failed compilation (1.79 KB, application/octet-stream)
2003-05-16 09:07 EDT, James Howe CLA
no flags Details
Directory containing code, batch files, jars which are used to reproduce the bug. (34.05 KB, application/octet-stream)
2003-05-20 14:31 EDT, James Howe CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Howe CLA 2003-05-16 09:02:21 EDT
I have an aspect that I would like to weave into the JDK 1.4 rt.jar file.  I 
compiled the aspect separately and tried to weave it into rt.jar using the 
following procedure:
 
1. Generate a 'unitTestAspects.jar' file from ajc by compiling my aspect and 
using the -outjar option to put the compiled aspect into a jar.
 
2. Ran the ajc compiler as follows:
 
   ajc -injars rt.jar -aspectpath unitTestAspects.jar -outjar rt_aj.jar
 
After fixing an OutOfMemory error by increasing the memory available to ajc, I 
ran the compiler once again.  After a period of time the compiler aborted with 
the following:
 
java.lang.StackOverflowError
        at org.aspectj.weaver.bcel.Utility.getSourceLine(Utility.java:436)
        at org.aspectj.weaver.bcel.Utility.getSourceLine(Utility.java:436)
        ...
 
I'm running with AspectJ 1.1rc2 on Windows XP with JDK 1.4.01.
Comment 1 James Howe CLA 2003-05-16 09:07:40 EDT
Created attachment 4892 [details]
Aspect used in failed compilation
Comment 2 Jim Hugunin CLA 2003-05-19 16:36:53 EDT
I can't reproduce this under Windows XP with SUN J2SDK 1.4.1_01.  Can you 
confirm the exact version of JVM that you're seeing this in?  (I assume 
1.4.0_01?)  Can you also try the same experiment with the latest from SUN to 
see if this is a bug they've fixed in their rt.jar?

Finally, some more info might be helpful.  Could you copy the full text of the 
console created by your command?  Also, could you add the following to your 
aspect?

    declare warning: staticinitialization(*): "static initializer";

This will generate a warning for every class that is woven, which is the 
easiest way to generate that debugging info today.
Comment 3 James Howe CLA 2003-05-20 14:24:06 EDT
>I can't reproduce this under Windows XP with SUN J2SDK 1.4.1_01.  
>Can you confirm the exact version of JVM that you're seeing this in?

I was using 1.4.1_01.  I downloaded the latest release (not beta) version of 1.
4.1 today (1.4.1_02).  The rt.jar has a date/time of 2/20/2003 1:17PM.  Using 
this file I still have the same problem.

>Finally, some more info might be helpful.  Could you copy the full text 
>of the console created by your command?  Also, could you add the following
>to your aspect? [...]

Here is a slightly edited version of the output from my compile attempt.  I 
deleted duplicate lines in the stack overflow, and I deleted most of the 
'warning' messages generated by the addition to the aspect you had me make:

C:\dev\java\Aspect Development - Error>ajc -injars lib\rt.jar -aspectpath 
aspects\unitTestAspects.jar -outjar lib\rt_aj.jar 

C:\dev\java\Aspect Development - Error\com\sun\corba\se\ActivationIDL\Activator.
java:0 static initializer
C:\dev\java\Aspect Development - 
Error\com\sun\corba\se\ActivationIDL\ActivatorHelper.java:13 static initializer
C:\dev\java\Aspect Development - 
Error\com\sun\corba\se\ActivationIDL\ActivatorHolder.java:0 static initializer

[... bunch of similar lines deleted ...]


C:\dev\java\Aspect Development - Error\java\awt\im\InputMethodHighlight.java:67 
static initializer
ABORT
Exception thrown from AspectJ 1.1rc2

This might be logged as a bug already -- find current bugs at
  http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&component=Compiler

Bugs for exceptions thrown have titles File:line from the top stack, 
e.g., "SomeFile.java:243"

If you don't find the exception below in a bug, please add a new bug
at http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ
To make the bug a priority, please include a test program
that can reproduce this exception.
null
java.lang.StackOverflowError
	at org.aspectj.weaver.bcel.Utility.getSourceLine(Utility.java:436)
	at org.aspectj.weaver.bcel.Utility.getSourceLine(Utility.java:436)
	[... bunch of identical lines deleted ...]

1 fail|abort, 7383 warnings

I'm also going to post an attachment which is a zip file of the directory with 
the code used to produce this error.
Comment 4 James Howe CLA 2003-05-20 14:31:43 EDT
Created attachment 4919 [details]
Directory containing code, batch files, jars which are used to reproduce the bug.

Here is a zip file containing a test directory which can be used to reproduce
this bug.  In addition to this directory, you would need the AspectJ 1.1r2 code
release and possibly the JSDK 1.4.1_02 release.  I also didn't include the
rt.jar file that I was using as an injar, and I didn't include the junit.jar
which is referenced by the code (made the zip file too big to upload).	For my
test, you need to have rt.jar and junit.jar (3.8.1) residing in the 'lib'
directory of this zipped archive.
Comment 5 Jim Hugunin CLA 2003-05-21 14:05:42 EDT
This is fixed in the tree with a minimal test in bugs/lines.

The reason this bug was hard to reproduce is that it is very sensitive to the 
exact VM and environment that the compiler is run in.  It is caused by a 
(tail) recursive method that tries to find the line number for an instruction 
being called enough times to exceed the JVMs maximum stack size.  This method 
has been changed to use iteration instead of recursion to avoid this issue.

For those who care, this would not be a bug if the JVM properly implemented 
tail-recursion...

Thanks for providing such a detailed demonstration of the bug.  This made it 
possible to track down this odd bug that is very sensitive to the details of 
the JVM and environment.  For example, this bug doesn't show up when running 
the compiler under a 1.3 JVM even when weaving into the rt.jar from 1.4 (which 
is what I was doing when first attempting to reproduce the bug).