CNI namespace
Per Bothner
per@bothner.com
Mon Apr 3 12:56:00 GMT 2000
Tom Tromey <tromey@cygnus.com> writes:
> The current plan is to use Paul's wrapper class idea.
> Changing g++ would work, but there is nobody to do the actual
> implementation. (And, in my estimation, it is unlikely that the g++
> maintainers would accept the patch in any case.)
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.
Do you have a pointer to the "wrapper class" idea?
A hybrid idea: Modify gcc to to implement __builtin_jnienv().
This get the JNIEnv environment. This would only be valid in
native method that has a JNIEnv parameter *or* in a function
that gets inlined into the latter. Similarly, __builtin_jthis
gets the "this" paramater passed to a native metod.
Next change gcjh so:
class Foo
{
int x;
Foo f(double y);
}
gets emitted as:
class Foo : public java::lang::Object
{
jint x;
#ifdef CNI
inline jint get$x() { return x; }
inline void set$x(jint n) { x = n; }
Foo* f(jdouble y);
#else
static jfieldID x$fieldID = 0;
static jmethodID f = 0;
static jclass Foo$class = 0;
inline jint get$x() {
JNIEnv *env = *__builtin_jni_env();
if (Foo$class == 0) Foo$class = ...;
if (x$fieldID == 0)
jfieldID = (*env)->GetFieldID(env, Foo$class, "x", "I");
return (*env)->GetIntField(env, __builtin_jthis(), x$fieldID);
}
inline void set$x(jint n) { ... }
inline Foo* f(jdouble y) {
JNIEnv *env = *__builtin_jni_env();
if (Foo$class == 0) Foo$class = ...;
if (f$methodId == 0) f$methodId = ...;
return (*env)->CallObjectMethod(env, __builtin_jthis(), f$methodId, y);
}
#endif
}
This requires fairly minimal changes to g++. It requires that
inline methods get inlined in the g++ front-end, *before* __builtin_xxx
is expanded. However, I believe that is now the case, thanks to
Mark Mitchell's work. In addition, we need to implement a few
builtin functions like __builtin_jnienv and __builtin_jthis in g++,
but this a fairly localized and should have no impact on the rest of
g++.
It does mean that code meant to work for bothy jni and cni has to
use get$x and set$x pseudo-methods instead of using x directly.
--
--Per Bothner
per@bothner.com http://www.bothner.com/~per/
More information about the Java
mailing list