tuxmartin

Kompilace Java do nativni app pomoci GCJ

Oct 13th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. ##################################################################
  2. Porovnani kompilace Java programu do nativni app pomoci GCJ (GNU Compiler for the Java).
  3.  
  4. Opravdu kompiluje do nativniho kodu, neni to jako nastroje ve Windows, ktere vezmou class soubor a pribali k nemu JRE a HelloWorld ma nejednou 100MB.
  5. GCJ binarka ma krasnych 12kB.
  6. Bohuzel se uz GCJ (asi) nevyviji. Podporuje vetsinu (asi) Javy 1.5, novejsi ne.
  7. Na bezne pouziti si to predstavit neumim. Je to ale pekna hracka na vyzkouseni :-)
  8.  
  9. Protoze jsem u toho mel spustenych X dalsich programu, jsou casy pouze orientacni. Je tak videt, ze vysledna binarka i kompilace trva u Oracle Javy i GCJ +- stejne dlouho.
  10. ##################################################################
  11.  
  12. ########### Verze Javy: Oracle Java 8 64bit; gcc (gcj) 4.8.1 64bit
  13.  
  14. martin@martin:~/gcj/test$ gcj -v
  15. Using built-in specs.
  16. Reading specs from /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcj.spec
  17. rename spec startfile to startfileorig
  18. rename spec lib to liborig
  19. COLLECT_GCC=gcj
  20. COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
  21. Target: x86_64-linux-gnu
  22. Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.8.1-10ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
  23. Thread model: posix
  24. gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9)
  25.  
  26. martin@martin:~/gcj/test$ java -version
  27. java version "1.8.0_20"
  28. Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
  29. Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
  30.  
  31.  
  32. ########### Ukazkovy program:
  33.  
  34. martin@martin:~/gcj/test$ cat HelloWorld.java
  35. public class HelloWorld {
  36. public static void main(String[] args) {
  37. Pozdrav pozdrav = new Pozdrav("Hello, world!");
  38. pozdrav.print();
  39. }
  40. }
  41. martin@martin:~/gcj/test$ cat Pozdrav.java
  42. public class Pozdrav {
  43. private String text;
  44.  
  45. public Pozdrav(String pozdrav) {
  46. text = pozdrav;
  47. }
  48. private String getText() {
  49. return text;
  50. }
  51. public void print() {
  52. System.out.println(getText());
  53. }
  54. }
  55.  
  56. ########### Velikosti souboru pred kompilaci:
  57.  
  58. martin@martin:~/gcj/test$ ls -lh
  59. celkem 8,0K
  60. -rw-r--r-- 1 martin martin 160 říj 13 23:12 HelloWorld.java
  61. -rw-r--r-- 1 martin martin 250 říj 13 23:12 Pozdrav.java
  62.  
  63.  
  64. ########### Kompilace pomoci Oracle Javy a GCJ:
  65.  
  66. martin@martin:~/gcj/test$ time javac HelloWorld.java
  67. real 0m0.793s
  68. user 0m1.528s
  69. sys 0m0.076s
  70.  
  71. martin@martin:~/gcj/test$ time gcj -O2 -g -Wall --main=HelloWorld -o HelloWorldGCJ HelloWorld.java Pozdrav.java
  72. real 0m0.597s
  73. user 0m0.515s
  74. sys 0m0.081s
  75.  
  76. ########### Velikosti vystupnich souboru:
  77.  
  78. martin@martin:~/gcj/test$ ls -lh
  79. celkem 40K
  80. -rw-r--r-- 1 martin martin 371 říj 13 23:12 HelloWorld.class
  81. -rwxr-xr-x 1 martin martin 22K říj 13 23:15 HelloWorldGCJ
  82. -rw-r--r-- 1 martin martin 160 říj 13 23:12 HelloWorld.java
  83. -rw-r--r-- 1 martin martin 525 říj 13 23:12 Pozdrav.class
  84. -rw-r--r-- 1 martin martin 250 říj 13 23:12 Pozdrav.java
  85.  
  86. ########### Velikosti vystupnich souboru po stripu GCJ binarky:
  87.  
  88. martin@martin:~/gcj/test$ strip HelloWorldGCJ
  89.  
  90. martin@martin:~/gcj/test$ ls -lh
  91. celkem 28K
  92. -rw-r--r-- 1 martin martin 371 říj 13 23:12 HelloWorld.class
  93. -rwxr-xr-x 1 martin martin 12K říj 13 23:15 HelloWorldGCJ
  94. -rw-r--r-- 1 martin martin 160 říj 13 23:12 HelloWorld.java
  95. -rw-r--r-- 1 martin martin 525 říj 13 23:12 Pozdrav.class
  96. -rw-r--r-- 1 martin martin 250 říj 13 23:12 Pozdrav.java
  97.  
  98. ########### Informace o zkompilovanych souborech:
  99.  
  100. martin@martin:~/gcj/test$ file HelloWorldGCJ
  101. HelloWorldGCJ: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x8a4bf227c54ab5357c44b2b9e5d2d11fc1e7d1d6, stripped
  102.  
  103. martin@martin:~/gcj/test$ file HelloWorld.class
  104. HelloWorld.class: compiled Java class data, version 52.0
  105.  
  106. martin@martin:~/gcj/test$ file Pozdrav.class
  107. Pozdrav.class: compiled Java class data, version 52.0
  108.  
  109. ########### Porovnani rychlosti provedeni programu z Oracle Javy a GCJ binarky:
  110.  
  111. martin@martin:~/gcj/test$ time java HelloWorld
  112. Hello, world!
  113. real 0m0.073s
  114. user 0m0.067s
  115. sys 0m0.019s
  116.  
  117. martin@martin:~/gcj/test$ time ./HelloWorldGCJ
  118. Hello, world!
  119. real 0m0.035s
  120. user 0m0.022s
  121. sys 0m0.013s
Advertisement
Add Comment
Please, Sign In to add comment