views:

119

answers:

4

Hey All,

I have a Java project that contains many very large source files and it compiles fine in Eclipse, however it will not compile with javac from the command line or within Ant.

When I try to compile it from the command with javac (or using Ant) I get a StackOverflow Exception:

   [javac] java.lang.StackOverflowError
   [javac]  at com.sun.tools.javac.jvm.Gen.genCond(Gen.java:786)
   [javac]  at com.sun.tools.javac.jvm.Gen.genCond(Gen.java:739)
   [javac]  at com.sun.tools.javac.jvm.Gen.visitBinary(Gen.java:1841)
   [javac]  at com.sun.tools.javac.tree.Tree$Binary.accept(Tree.java:926)
   [javac]  at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:806)
   [javac]  at com.sun.tools.javac.jvm.Gen.genCond(Gen.java:786)
   ...
   ...
   ...

I have tried passing a number of arguments to the JVM such as -Xss, -Xmx, -Xoss etc both on the command line and in the Ant javac task but I always get the same error.

From what I have read, it seems that the Eclipse IDE has a compiler that is different to the Sun JDK. Is there a way to get the JDK to compile in a similar way to Eclipse?

Thanks, Stef

A: 

You may have to give the compiler LOTS of memory, when this happens (or you may have hit a bug, hard to say). Also be certain that the javac is forked in a separate process, otherwise these options are just ignored.

Thorbjørn Ravn Andersen
I have tried giving it the maximum amount of memory I can and it still happened so I don't know how eclipse could give it more memory.I have set the forked="true" so the options are being used and when I print verbose output I can see the arguments applied to javac from ant
Stefg
A: 

You should be able to tell Eclipse to use the same JDK that your command shell sees.

I believe the Eclipse JDK is from IBM, so that might explain the difference.

duffymo
That's what I thought, but it seems that Eclipse uses it's own compiler even when I set the JDK, unless I'm doing it wrong of course :)
Stefg
@Stefg: that's right. Eclipse only uses the JDK to load the classes to compile against. It always uses its own compiler.
Joachim Sauer
Another reason to not like Eclipse.
duffymo
A: 

This is odd, but I have found that I can compile the code with JDK 1.6.

This isn't solving my problem because the code is used as a lib by another project and it complains and compiled version numbers as JDK 1.5 is the project standard at the moment (and will be for another few months).

Does anyone know what has changed in 1.6 and is it possible to apply those changes to 1.5 by flags?

Stefg
+2  A: 

When you are running the "javac" command from the commandline, JVM parameters need to be specified using the "-J" option. For example; -J-Xms48m sets the initial heap size.

This is documented in the javac(1) manual page.

If you are getting StackOverflowErrors, the option you should be tweaking is the thread stack size; e.g. -J-Xss5m.

This is odd, but I have found that I can compile the code with JDK 1.6.

I expect that the explanation is one of the following:

  • you are tickling a javac bug that has been fixed in JDK 1.6 or a later patch release of JDK 1.5,
  • javac in JDK 1.6 is less stack hungry, or
  • the default stack size for javac has been increased.

One possible bug is http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6273455

EDIT

... and is it possible to apply those changes to 1.5 by flags?

Assuming you mean flags to enable the compiler bug fix, the answer is most likely No. Indeed, if it is the bug above, then it looks like upgrading to the last JDK 1.5 patch release won't help either. However, there are two possible solutions:

  1. The bug report above gives a possible workaround that entails changing the source code that is triggering the bug. But first you will need to confirm that this is the bug that is causing the problem, and identify the offending source code files.

  2. It may be possible to compile your production code using the Sun JDK 1.6 compiler with the flags -source 1.5 -target 1.5.

Stephen C
Thanks for that Stephen, I had been using the -J option so I guess it may be a bug that is fixed in 1.6...
Stefg