cool hack

Jeff Sturm jsturm@sigma6.com
Sat Apr 1 00:00:00 GMT 2000


Tom Tromey wrote:
> If you compile a .java file to a .so, and it has a main method, you
> can run it with `gij':
>> creche. gcj -shared -c -o HelloWorld.so HelloWorld.java

(I thought the -c and -shared arguments were mutually exclusive?)
> creche. gij HelloWorld
> Hello World!

That's a nice trick, particularly for libraries that have many possible
entry points.
I used a similar technique long before the shared object loader was
available:
gcj -shared Hello.java -o Hello.so
LD_PRELOAD=./Hello.so gij Hello
That worked on Linux at least. It causes the ELF loader to preload the
shared object and run the initializers, so Class.forName() can resolve
classes within it.
Running gij is still the only way I know of to specify heap parameters
to a compiled Java executable, since jvgenmain doesn't know about -ms
and -mx. You can also set properties at runtime with gij.
--
Jeff Sturm
jsturm@sigma6.com


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /