This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Hello,
While debugging the issue with the Subclipse not working under the GCJ
(look at the message
http://svn.haxx.se/subusers/archive-2006-07/0210.shtml for example) I
found the following problem. When native method is called, the
env->klass value is always NULL. It looks like that JNIEnv is reused in
the "_Jv_GetJNIEnvNewFrame" function and the env->klass value is not
updated during the call.
So, if some native method calls env->FindClass function, the
_Jv_JNI_FindClass function uses system classloader for loading the
required class (since env->klass is NULL) instead of using the
classloader of the class that defines this native method!
Perhaps, it is OK in most cases, except the cases with complex
classloaders logic. The Eclipse is the example of an application with
such logic. When the Subclipse native method (getAdminDirectoryName)
calls FindClass("org.tigris.subversion.javahl.SVNClient"), the system
classloader is used (instead of the classloader that loaded the defining
class, the SVNClient class itself). And since this class is available
only through the chain of Eclipse classloaders and not available through
the system classloader, the FindClass fails - giving the exception
described in the email above.
I've attached a patch that solves the problem with the Subclipse. It
simply updates the env->klass value just before making the ffi call.
P.S.
Steps to reproduce behavior:
1. Install gcj-4.1.1.
2. Run Eclipse with -vm /path/to/gij
3. Install Subclipse extension (http://subclipse.tigris.org).
4. Open Windows->Preferences dialog, then open Team->SVN tab. The
Eclipse shows error message.
--
WBR,
Ivan S. Dubrov
diff -ur gcc-4.1.1.orig/libjava/jni.cc gcc-4.1.1/libjava/jni.cc --- gcc-4.1.1.orig/libjava/jni.cc 2006-01-19 06:45:55.000000000 +0600 +++ gcc-4.1.1/libjava/jni.cc 2006-07-29 23:26:51.000000000 +0700 @@ -2301,6 +2301,10 @@ // Copy over passed-in arguments. memcpy (&real_args[offset], args, _this->args_raw_size); + // Setup the klass field + jclass old_klass = env->klass; + env->klass = _this->defining_class; + // The actual call to the JNI function. #if FFI_NATIVE_RAW_API ffi_raw_call (&_this->jni_cif, (void (*)()) _this->function, @@ -2309,6 +2313,8 @@ ffi_java_raw_call (&_this->jni_cif, (void (*)()) _this->function, ret, real_args); #endif + // Restore the old klass value + env->klass = old_klass; // We might need to unwrap a JNI weak reference here. if (_this->jni_cif.rtype == &ffi_type_pointer)
Attachment:
signature.asc
Description: OpenPGP digital signature
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |