This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Call compiled Java from C/C++?


>>>>> "Vito" == Vito BAGGIOLINI <Vito.nospam.Baggiolini@cern.ch> writes:

Vito> I understand that CNI is primarily intended to call C/C++
Vito> routines from a Java 'main' program.

Vito> But is the opposite possible, i.e. to call a compiled Java code
Vito> from a C/C++ 'main' program? (With JNI this is possible, but
Vito> quite clumsy).

It is possible, but it might be hard.

In a gcj-compiled program, main() is actually written in C (the
"--main" option generates and compiles a simple C program).

However, the runtime more or less assumes that the program is
following the startup sequence given in prims.cc (see JvRunMain).

You could write your own main() that follows these lines.
This is a bad idea, though, because the implementation of JvRunMain is
a detail which we will change at our convenience.

I haven't looked to see how JNI works when you want to start the JVM
once your program is already running.  Since we do want to implement
JNI eventually, we will need to support this.  So if you hack on it,
try to more-or-less follow JNI (while keeping in the spirit of CNI, if
this idea makes sense), and tell us what you come up with.

FYI, CNI actually goes both ways: it is a way for Java to call C++
native methods, but it also lets C++ code call Java methods directly.

Tom

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]