來到新公司 ,一切都還算習慣.好久沒怎么寫代碼. 這幾天沒什么任務,做個工具方便打補丁包. 和同事溝通了哈.簡單的說就是想做個自動編譯java,并且打包的工具.以前用過點ant,于是就用它了.大概寫了哈腳本.
環境如下: ant1.7
jdk 1.42
不過很不興 編譯大概3000多個文件.過程中出現了2個問題:
1 out of memory 解決方式:在build.xml中<javac>指定memoryMaximumSize="1024m".問題解決.
2 stackoverflow 開始感覺的是在eclipse 中 指定-Xss=100m.這個是指定堆棧的大小,不過問題還是存在.
異常如下:
[javac] Compiling 2230 source files to D:\60work\xyg60\test
[javac] The system is out of resources.
[javac] Consult the following stack trace for details.
[javac] java.lang.StackOverflowError
[javac] at com.sun.tools.javac.v8.comp.Attr.visitApply(Attr.java:689)
[javac] at com.sun.tools.javac.v8.tree.Tree$Apply.accept(Tree.java:877)
[javac] at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:198)
[javac] at com.sun.tools.javac.v8.comp.Attr.visitSelect(Attr.java:1071)
[javac] at com.sun.tools.javac.v8.tree.Tree$Select.accept(Tree.java:1091)
[javac] at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:198)
....................................................................................................
上網查了哈.發現是sun的一個bug:http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6623981
簡單描述如下:
1.The cause of StackOverFlowError
When compiling a source(javac ... *.java), the classes depending on
the compiled source become translation objects if not existing on
classpath. There is a max limit of source/class number set to be 502
when analyzing a source code. Analytical information that javac holds
internally grows to translate a huge amount of source program at a
time and that results in a stack overflow.
2.Why the option "-J-Xss10m" did not work
The thread where stack overflow occurred was generated by OS when
starting javac.exe. Its size was fixed to be 256KB on Windows so
"-J-Xss10m" did not work. This option is valid only for the threads
generated by Java VM.
To solve the problem, one way is not to make a recursive call in the
processing of javac.
This problem was not seen in jdk 5.0.
Posted Date : 2007-10-31 03:57:57.0
Test case and instruction for reproduction has been added.
Please see Comment section.
Posted Date : 2007-11-27 10:13:04.0
Evaluation :
Fixing by starting the javac "work" in a new thread, to avoid any possible limitation of the primordial thread stack size by the OS.
This applies to 5.0 and earlier, later JDKs have the launcher start the application in a new thread.
Posted Date : 2008-08-25 19:28:25.0
可恨的sun 竟然搞到1.5的update17才解決.
下了個最新的jdk1.5update20 問題解決了.
由于我打包的東東是要在jdk1.4中運行的.還要想把辦法把1.5的class 轉換成1.4的.....
或者可以自己修改1.4的jdk.按照他的Evaluation ,來改jdk 這個放到有時間在搞.