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]

Patch: FYI: JNI and synchronized native


I'm checking this in.

`synchronized native' JNI methods weren't actually synchronized.
This patch fixes.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* jni.cc (call): Synchronize if required.

Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.56
diff -u -r1.56 jni.cc
--- jni.cc 2001/11/17 21:32:22 1.56
+++ jni.cc 2001/12/12 20:57:46
@@ -2066,12 +2066,26 @@
   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);
 
   // The actual call to the JNI function.
   ffi_raw_call (&_this->jni_cif, (void (*)()) _this->function,
 		ret, real_args);
+
+  if (sync != NULL)
+    _Jv_MonitorExit (sync);
 
   _Jv_JNI_PopSystemFrame (env);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]