This is the mail archive of the
java-discuss@sourceware.cygnus.com
mailing list for the Java project.
Re: CNI namespace
- To: java-discuss at sourceware dot cygnus dot com
- Subject: Re: CNI namespace
- From: Paul Fisher <pnfisher at redhat dot com>
- Date: 04 Apr 2000 01:12:37 -0400
- References: <y683dpaetn2.fsf_-_@ignucius.devel.redhat.com> <m2r9ct8pho.fsf@kelso.bothner.com> <y68k8ilcrfj.fsf@idoru.labs.redhat.com> <m2hfdp8hjy.fsf@kelso.bothner.com> <y6866u5cn4b.fsf@idoru.labs.redhat.com> <m27lel8eb3.fsf@kelso.bothner.com> <200004031916.MAA02911@ferrule.cygnus.com> <m2d7o7m05d.fsf@kelso.bothner.com>
Per Bothner <per@bothner.com> writes:
> Paul sent me some private email, which didn't really explain the
> idea. For one thing, I don't see how the JNIEnv can get passed.
Sorry for the delay in replying -- been sick of late.
The JNIEnv and jobject (this) is passed into a function from the
foreign VM, so it's always around for calling member functions and
accessing fields. When it's not possible to pass around the JNIEnv
(ie. when calling a non-member function), it can be simply retrieved
as thread local data. No changes to g++ should be necessary.
gcjh could be modified to churn out appropriate code to handle calling
CNI functions from JNI entry points, and Java functions via JNI from
CNI entry points.
For example, a native routine for Object.hashCode () written in CNI,
and a Java routine for Object.equals (), gcjh might generate code that
looks something like:
class Object
{
static jmethodID *method_ids;
jobject obj;
JNIEnv *env;
public:
Object (JNIEnv *env, jobject obj);
int hashCode ();
jboolean equals (Object *o);
};
// foreign VM JNI entry point -- passes in JNIEnv and `this'
jint
Java_java_lang_Object_hashCode (JNIEnv *env, jobject obj)
{
Object o = Object (env, obj);
return o.hashCode ();
}
// user written CNI routine
jint
hashCode ()
{
return 1;
}
// turns a CNI/Java call into a JNI/Java call
jboolean
Object::equals (Object *o)
{
if (!method_ids[EQUALS_ID])
{
method_ids[EQUALS_ID] =
env->GetMethodID (env->FindClass ("java/lang/Object"),
"equals", "(Ljava/lang/Object;)Z");
}
return env->CallBooleanMethod (obj, method_ids[EQUALS_ID], o->obj);
}