aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorBryce McKinlay <mckinlay@redhat.com>2004-07-14 00:24:06 +0000
committerBryce McKinlay <bryce@gcc.gnu.org>2004-07-14 01:24:06 +0100
commit158e9fc32007a60964b01cf7ae2dee89c0bd9b25 (patch)
treed1765f2a8fbdcfd693639f4112d948694ca3b5fa /libjava
parent60e881275191fc74cfa8efe9155ce23823636fbd (diff)
re PR libgcj/7587 (direct threaded interpreter not thread-safe)
2004-07-13 Bryce McKinlay <mckinlay@redhat.com> PR libgcj/7587 * interpret.cc (compile_mutex): New. (_Jv_InitInterpreter): New. Initialize compile_mutex. (run): Lock compile_mutex before calling compile() if compilation is required. * prims.cc (_Jv_CreateJavaVM): Call _Jv_InitInterpreter(). * include/java-interp.h (_Jv_InitInterpreter): Declare. From-SVN: r84662
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog10
-rw-r--r--libjava/include/java-interp.h1
-rw-r--r--libjava/include/jvm.h6
-rw-r--r--libjava/interpret.cc24
-rw-r--r--libjava/prims.cc5
5 files changed, 42 insertions, 4 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 5727099a9f2..21071a2c967 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,13 @@
+2004-07-13 Bryce McKinlay <mckinlay@redhat.com>
+
+ PR libgcj/7587
+ * interpret.cc (compile_mutex): New.
+ (_Jv_InitInterpreter): New. Initialize compile_mutex.
+ (run): Lock compile_mutex before calling compile() if compilation is
+ required.
+ * prims.cc (_Jv_CreateJavaVM): Call _Jv_InitInterpreter().
+ * include/java-interp.h (_Jv_InitInterpreter): Declare.
+
2004-07-11 Mohan Embar <gnustuff@thisiscool.com>
* gnu/java/net/natPlainDatagramSocketImplWin32.cc (several):
diff --git a/libjava/include/java-interp.h b/libjava/include/java-interp.h
index 94acfae281f..265b95dd8e5 100644
--- a/libjava/include/java-interp.h
+++ b/libjava/include/java-interp.h
@@ -36,6 +36,7 @@ _Jv_IsInterpretedClass (jclass c)
struct _Jv_ResolvedMethod;
+void _Jv_InitInterpreter ();
void _Jv_DefineClass (jclass, jbyteArray, jint, jint);
void _Jv_InitField (jobject, jclass, int);
diff --git a/libjava/include/jvm.h b/libjava/include/jvm.h
index e1a5c33bbc6..9624a5d39b2 100644
--- a/libjava/include/jvm.h
+++ b/libjava/include/jvm.h
@@ -419,7 +419,8 @@ extern jboolean _Jv_CheckAccess (jclass self_klass, jclass other_klass,
extern jobject _Jv_CallAnyMethodA (jobject obj, jclass return_type,
jmethodID meth, jboolean is_constructor,
JArray<jclass> *parameter_types,
- jobjectArray args);
+ jobjectArray args,
+ jclass iface = NULL);
union jvalue;
extern void _Jv_CallAnyMethodA (jobject obj,
@@ -430,7 +431,8 @@ extern void _Jv_CallAnyMethodA (jobject obj,
JArray<jclass> *parameter_types,
jvalue *args,
jvalue *result,
- jboolean is_jni_call = true);
+ jboolean is_jni_call = true,
+ jclass iface = NULL);
extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
__attribute__((__malloc__));
diff --git a/libjava/interpret.cc b/libjava/interpret.cc
index 5fd2c2b5869..c5d2afdb905 100644
--- a/libjava/interpret.cc
+++ b/libjava/interpret.cc
@@ -54,6 +54,21 @@ static void throw_null_pointer_exception ()
__attribute__ ((__noreturn__));
#endif
+#ifdef DIRECT_THREADED
+// Lock to ensure that methods are not compiled concurrently.
+// We could use a finer-grained lock here, however it is not safe to use
+// the Class monitor as user code in another thread could hold it.
+static _Jv_Mutex_t compile_mutex;
+
+void
+_Jv_InitInterpreter()
+{
+ _Jv_MutexInit (&compile_mutex);
+}
+#else
+void _Jv_InitInterpreter() {}
+#endif
+
extern "C" double __ieee754_fmod (double,double);
// This represents a single slot in the "compiled" form of the
@@ -1032,9 +1047,14 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args)
#define PCVAL(unionval) unionval.p
#define AMPAMP(label) &&label
- // Compile if we must.
+ // Compile if we must. NOTE: Double-check locking.
if (prepared == NULL)
- compile (insn_target);
+ {
+ _Jv_MutexLock (&compile_mutex);
+ if (prepared == NULL)
+ compile (insn_target);
+ _Jv_MutexUnlock (&compile_mutex);
+ }
pc = (insn_slot *) prepared;
#else
diff --git a/libjava/prims.cc b/libjava/prims.cc
index da8f36db01b..e4818c6ba34 100644
--- a/libjava/prims.cc
+++ b/libjava/prims.cc
@@ -25,6 +25,7 @@ details. */
#include <jvm.h>
#include <java-signal.h>
#include <java-threads.h>
+#include <java-interp.h>
#ifdef ENABLE_JVMPI
#include <jvmpi.h>
@@ -905,6 +906,10 @@ _Jv_CreateJavaVM (void* /*vm_args*/)
_Jv_InitThreads ();
_Jv_InitGC ();
_Jv_InitializeSyncMutex ();
+
+#ifdef INTERPRETER
+ _Jv_InitInterpreter ();
+#endif
/* Initialize Utf8 constants declared in jvm.h. */
void_signature = _Jv_makeUtf8Const ("()V", 3);