From 6187fd28ad121ea6a3adabdcf106df70d9ea0429 Mon Sep 17 00:00:00 2001 From: Bryce McKinlay Date: Tue, 13 Jul 2004 21:03:03 +0000 Subject: [PATCH] re PR libgcj/7587 (direct threaded interpreter not thread-safe) 2004-07-13 Bryce McKinlay 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: r84644 --- libjava/ChangeLog | 10 ++++++++++ libjava/include/java-interp.h | 1 + libjava/interpret.cc | 24 ++++++++++++++++++++++-- libjava/prims.cc | 5 +++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 3c0b041b0ec..476795a111d 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,13 @@ +2004-07-13 Bryce McKinlay + + 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-12 Bryce McKinlay PR libgcj/15713 diff --git a/libjava/include/java-interp.h b/libjava/include/java-interp.h index c57c146dacb..12bc21f2436 100644 --- a/libjava/include/java-interp.h +++ b/libjava/include/java-interp.h @@ -35,6 +35,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/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 diff --git a/libjava/prims.cc b/libjava/prims.cc index 7aac58497aa..19bce1e62a0 100644 --- a/libjava/prims.cc +++ b/libjava/prims.cc @@ -25,6 +25,7 @@ details. */ #include #include #include +#include #ifdef ENABLE_JVMPI #include @@ -953,6 +954,10 @@ _Jv_CreateJavaVM (void* /*vm_args*/) _Jv_InitThreads (); _Jv_InitGC (); _Jv_InitializeSyncMutex (); + +#ifdef INTERPRETER + _Jv_InitInterpreter (); +#endif #ifdef HANDLE_SEGV INIT_SEGV; -- 2.30.2