summaryrefslogtreecommitdiff
path: root/libjava/interpret.cc
diff options
context:
space:
mode:
authorbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-13 21:03:03 +0000
committerbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-13 21:03:03 +0000
commit965daed0d5e71b74e84c92d4e99c316edf76b3d6 (patch)
tree9e450f9a46004f388b904ee291f197c06e3c7f8a /libjava/interpret.cc
parent500b8870f07e2ae2f48f0cbe57c26b36afc981b6 (diff)
downloadgcc-965daed0d5e71b74e84c92d4e99c316edf76b3d6.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@84644 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/interpret.cc')
-rw-r--r--libjava/interpret.cc24
1 files changed, 22 insertions, 2 deletions
diff --git a/libjava/interpret.cc b/libjava/interpret.cc
index 7ec83a23c44..40c7cbaac5a 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