This is the mail archive of the
java-discuss@sourceware.cygnus.com
mailing list for the Java project.
Re: Call compiled Java from C/C++?
- To: Vito dot nospam dot Baggiolini at cern dot ch
- Subject: Re: Call compiled Java from C/C++?
- From: Andrew Haley <aph at pasanda dot cygnus dot co dot uk>
- Date: 1 Oct 1999 11:20:36 -0000
- CC: java-discuss at sourceware dot cygnus dot com
> 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.