This week I’ve been working on the new gcj binary compatibility
code some more. This is looking pretty solid now, so I thought I’d
write a little tutorial on compiling a random Java application. If
you want to do this, you will need to check out the BC branch and
build it. We’re planning to merge all this into the trunk in time for
GCC 4.0.
The general approach is to make a small database that maps class
files (by hash code) to the shared library defining the class. This
approach doesn’t give the best possible performance, but it has the
advantage of working transparently with any application. If you’re
willing to modify your application a little (or if your application
just uses the standard class loaders like
URLClassLoader
), then you can do a little better.
The branch has Andrew’s new jv-dbtool
program
(probably will be renamed) which is used to manipulate the database.
First run it to create your database:
mkdir /libdir jv-dbtool -n /libdir/eclipse.db
Now, compile each jar file using the new verifier (eventually this
will be the default) and the indirect dispatch code:
gcj -fnew-verifier -findirect-dispatch -fjni -fPIC -shared -o /libdir/foo.jar.so foo.jar
Update the database to know about the new jar:
jv-dbtool -a /libdir/eclipse.db foo.jar /libdir/foo.jar.so
Now you’re ready to launch your application. Run it using
gij
, and arrange to set the system property
gnu.gcj.precompiled.db
to point to your database (you
can use a number of databases separated by “:” if you like):
gij -Dgnu.gcj.precompiled.db=/libdir/eclipse.db My.Application.Class
That’s all there is to it! Your application will use the compiled
classes. You can debug your application with gdb, profile it with
oprofile, etc.
Be the first to leave a comment. Don’t be shy.