Creating small binaries.

Tom Rathbone tom.rathbone@gmail.com
Fri Jun 10 09:41:00 GMT 2005


Hi,

I have an ARM system with just 16MB of RAM (so can't fit libgcj) and
have been playing to see whether I can create a static binary with GCJ
that I can run on this system.

The kernel and ramdisk take up the first 8MB leaving me with 8MB of free ram.

I compile the following familiar code:

public class HelloWorld
{
    public static void main(String[] args)
    {
        System.out.println("Hello World!");
    }
}

# arm-gcj --main=HelloWorld -static HelloWorld.java -o hw 

this gives a 26MB binary, stripping it gives 3.8MB.  The system is
running from a ramdisk so the binary takes 4MB of the free space leave
~4MB left to load and run the executable.  When run the program
segfaults and I believe this is simply as it's out of memory.

Is there any way that the binary size can be reduced? At the moment
the majority of libgcj seems to be being linked in.  I realise this is
a rather strange thing to be trying to do but at the same time is it
really true that a hello world program must compile to 4MB?

Any pointers on creating leaner binaries will be greatly appreciated.

Tom.



More information about the Java mailing list