Re: custom libgcj

David Daney <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
Andrew Haley wrote:
> Bryce McKinlay wrote:
>> On Mon, Apr 20, 2009 at 12:41 PM, abhishek desai <[email protected]> wrote:
>>
>>> I want to customize libgcj compilation to include only the garbage
>>> collector part and other required files for a simple java program to
>>> compile and execute in native using gcj. Then I want to add my own
>>> java files to libgcj. Is there some way this can be done? Which files
>>> can I edit for this ?
>> This would certainly be a very useful feature. Unfortunately, there is
>> no easy way to do it. You could edit Makefile.am files by hand to
>> remove classes you don't want, but you're likely to get missing symbol
>> errors at link time due to the way libgcj is compiled.
> 
> I agree.
> 
> I think the only way to do it is iterate.
> 
> 1.  Link app statcially with libgcj and make sure it still works.
> 
> 2.  Run app with -verbose:class to see what gets used.
> 
> 3.  Remove stuff that isn't listed in -verbose:class.
> 
> 4.  Fix link errors.
> 
> 5.  If that isn't enough, start tracing through -verbose:class and edit
> the library source to prune dependencies.
> 
> 6.  Goto 4...
> 

That's right, unfortunately libgcj has many dependencies that are not 
obvious.  For example (from memory):

All programs have a ClassLoader...

ClassLoader->SecureClassLoader->URLClassLoader->(all known URL Handlers 
including https)->(Most of the crypto code)->(much of the xml 
code),(some javax.swing dialogs for certificate verification)->All of 
javax.swing

On a mips-linux system I was able to with a little work get the static 
image size of HelloWorld.java down to about 9MB (down from about 20MB). 
  To get much smaller than that would take some real work and create a 
library that is not really compatible with the reference implementation.

David Daney
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.