Binary size of statically linked java application
Marco Trudel
mtrudel@gmx.ch
Mon Nov 27 14:52:00 GMT 2006
Mohan Embar wrote:
> Hi All,
>>> I usually remove AWT/Swing (the whole GUI stuff) and the whole
>> javax.crypto stuff. Then a real application is about 4.5mb (stripped of
>> course).
>> I'm not clear on why this would work given that the linker is supposed
> to strip out unused code.
Well, I'm not talking about objects that won't be pulled into the final
binary (as you said, that wouldn't make sense). I'm talking about the
ones that will but are actually not really needed... From my FAQ:
Why are the binaries so big? With GCJ X.Y.Z, they were way smaller...
As GCJ evolves, it supports more and more classes of the Java API. The
problem now is, that the Java API classes are heavily interconnected; a
simple "Hello World" application uses the security manager which uses
AWT which uses... Because of this, you will always have a big part of
the GCJ library in your binaries.
For Java, this is not a problem. Endusers require to have the JVM, thus
having all classes anyway. For GCJ, this is a bigger problem because
it's not just a bug that can be fixed. The design of Java doesn't fit
into the concept of native compilation (concerning the size of binaries).
Since NativeJ 0.9, you can exclude parts of the class library if you
don't need them and thus drastically reduce the size of your binaries.
In my experience, AWT/Swing and javax.crypto are really worth being
excluded when they're not needed (~9mb -> ~4.5mb).
Marco
More information about the Java
mailing list