General questions on allocating objects from native code
Per Bothner
bothner at cygnus.com
Tue Feb 25 20:57:01 PST 1997
> extern object* AllocObject(char*);
> etc...
> Now I have object which won't be garbage collected by Java runtime
> (well I hope so since I keep a link on them from the C data structures).
Actually, no, unless you keep a pointer to the object in the C
stack or registers (or some other Java object). If the only pointer is
in a global variable, it will go away, since the new Kaffe gc does not
scan the C data segments.
In any case, though I don't know what Tim's plans are, I would not
recommend counting on any "official" interface. Even if something is
in native.h, it does not mean it is frozen and safe to use. Kaffe
is a work in progress; expect interfaces to change incompatibly.
Long-term, it may make most sense to implement Sun's new "Java Native
Interface" (from JDK 1.1). This is designed for binary portability,
and therefore has some overheads that may be undesirable. However,
the old interface as also bad, because they require classes and
methods to always be specified by name. which requires searching.
I think Kaffe should provide two native interfaces:
a) the standard JNI, for people who want a stable, documented,
portable interface; and
b) a low-level API that provides direct access, but would change
with the implementation.
If someone could implement the new JNI, that would be very helpful.
--Per Bothner
Cygnus Solutions bothner at cygnus.com http://www.cygnus.com/~bothner
More information about the kaffe
mailing list