Call compiled Java from C/C++?
Andrew Haley
aph@pasanda.cygnus.co.uk
Fri Oct 1 04:20:00 GMT 1999
> Date: Fri, 01 Oct 1999 09:02:19 +0200
> From: Vito BAGGIOLINI <Vito.nospam.Baggiolini@cern.ch>
>
> Hello,
>
> I understand that CNI is primarily intended to call C/C++ routines from
> a Java 'main' program.
>
> But is the opposite possible, i.e. to call a compiled Java code from
> a C/C++ 'main' program? (With JNI this is possible, but quite clumsy).
The Java runtime garbage collector scans the stack and assumes that
any pointers it finds which point into the Java heap will point to
Java data structures with valid Java metadata fields. C++ classes
don't have the metadata fields. The gc also knows that if no Java
pointers refer to a gc allocated structure it may be reclaimed.
If you learn about how the gc and metadata work together you can
certainly design a solution that works, but it may be quite tricky.
If you arrange for no C++ struct ever to contain a pointer to a gc
allocated Java object you may be OK, but I wouldn't recommend it.
Andrew.
More information about the Java
mailing list