* jni.cc (call): Synchronize if required.
authorTom Tromey <tromey@redhat.com>
Wed, 12 Dec 2001 20:58:41 +0000 (20:58 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Wed, 12 Dec 2001 20:58:41 +0000 (20:58 +0000)
From-SVN: r47949

libjava/ChangeLog
libjava/jni.cc

index 8596f4c378f2f48872640f76e9ce51b9978f4a94..d41ff8d712eee260dbebc1aeb6e1cbfb26ef4f3d 100644 (file)
@@ -1,5 +1,7 @@
 2001-12-12  Tom Tromey  <tromey@redhat.com>
 
+       * jni.cc (call): Synchronize if required.
+
        * gij.cc (main): Clarify --help output.
 
        * gnu/gcj/runtime/StringBuffer.java
index dbe1d1f4f2970a95a6412c60915d1c243b76ef19..1dd299f3aa961ae4e088751e0a9d1d04e86440bf 100644 (file)
@@ -2066,6 +2066,17 @@ _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
   if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
     real_args[offset++].ptr = _this->defining_class;
 
+  // In libgcj, the callee synchronizes.
+  jobject sync = NULL;
+  if ((_this->self->accflags & java::lang::reflect::Modifier::SYNCHRONIZED))
+    {
+      if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
+       sync = _this->defining_class;
+      else
+       sync = (jobject) args[0].ptr;
+      _Jv_MonitorEnter (sync);
+    }
+
   // Copy over passed-in arguments.
   memcpy (&real_args[offset], args, _this->args_raw_size);
 
@@ -2073,6 +2084,9 @@ _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
   ffi_raw_call (&_this->jni_cif, (void (*)()) _this->function,
                ret, real_args);
 
+  if (sync != NULL)
+    _Jv_MonitorExit (sync);
+
   _Jv_JNI_PopSystemFrame (env);
 }