Chris said:
The only way to proceed that's spec-safe is to use the JNI invocation
API to create an instance of a Java VM, and run the code in that VM.
That's very heavyweight, but it definitely works, even across Java
virtual machines and platforms. Otherwise, there may be a vendor-
specific way to do this. Someone who knows more about Jet than I do
could perhaps take up the question.
Excelsior JET is certified Java Compatible, so it also supports JNI.
Fetch a trial from
http://www.excelsior-usa.com/jetdleval.html, install
it, and look under samples/Invocation to get going.
GCJ (
http://gcc.gnu.org/java/) implements its own Java-native interface
called CNI. Here is an excerpt from the GCJ FAQ
(
http://gcc.gnu.org/java/faq.html):
----------------------------------------------------
2.2 Does GCJ support using straight C native methods ala JNI?
Yes. libgcj now has experimental support for JNI, in addition to
its native Compiled Native Interface (CNI). gcjh will generate JNI
stubs and headers using the "-jni" option. However, we do prefer CNI:
it is more efficient, easier to write, and (at least potentially)
easier to debug.
2.3 Why does GCJ use CNI?
Per Bothner explains:
We use CNI because we think it is a better solution, especially
for a Java implementation that is based on the idea that Java is just
another programming language that can be implemented using standard
compilation techniques. Given that, and the idea that languages
implemented using Gcc should be compatible where it makes sense, it
follows that the Java calling convention should be as similar as
practical to that used for other languages, especially C++, since we
can think of Java as a subset of C++. CNI is just a set of helper
functions and conventions built on the idea that C++ and Java have the
*same* calling convention and object layout; they are binary
compatible. (This is a simplification, but close enough.)
----------------------------------------------------
I would recommend anyone to stick to JNI, though, as it is THE standard
and thus must be supported by all compatible JVMs.
LDV