From 972791c2823bfc1694d827b1e943eb725847e2d8 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 2 Feb 2016 23:08:24 +0100 Subject: [PATCH 1/1] don't destroy synchro in a simcall, this drives the JVM nuts The destroy is called from the GC thread when running in the JVM. And that thread is obviously not a simix thread, so the simcall mechanism won't work properly. I tried to make it a simix thread when I see it (ie, when JavaThreadFactory::self() is about to return NULL), but it leads to further complications, such as the following error message: Can't extend stack to 0x22f35958 during signal delivery for thread 9: no stack segment Oha. That hurts. I've no idea of why that thread has no stack, and I think I don't want to know. Actually, it makes no sense to delete the synchronization objects from a simcall only. Why would this need to be linearized in a reproductible way? So, delete these objects directly, and everything works well. That bug was reported in: https://gforge.inria.fr/tracker/index.php?func=detail&aid=19893&group_id=12&atid=165 --- examples/msg/actions/actions.c | 4 +-- include/simgrid/simix.h | 6 ++-- src/msg/msg_synchro.cpp | 2 +- src/simix/libsmx.cpp | 27 -------------- src/simix/popping_accessors.h | 21 ----------- src/simix/popping_bodies.cpp | 63 --------------------------------- src/simix/popping_enum.h | 3 -- src/simix/popping_generated.cpp | 18 ---------- src/simix/simcalls.in | 3 -- src/simix/smx_synchro_private.h | 3 -- src/xbt/xbt_os_synchro.c | 4 +-- 11 files changed, 8 insertions(+), 146 deletions(-) diff --git a/examples/msg/actions/actions.c b/examples/msg/actions/actions.c index bd5a62aa27..e43c1d45f5 100644 --- a/examples/msg/actions/actions.c +++ b/examples/msg/actions/actions.c @@ -230,8 +230,8 @@ static void action_barrier(const char *const *action) processes_arrived_sofar--; if (!processes_arrived_sofar) { - simcall_cond_destroy(cond); - simcall_mutex_destroy(mutex); + SIMIX_cond_destroy(cond); + SIMIX_mutex_destroy(mutex); mutex = NULL; } } diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index d931d13084..bd12391e93 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -410,13 +410,13 @@ XBT_PUBLIC(void) simcall_set_category(smx_synchro_t synchro, const char *categor /************************** Synchro simcalls **********************************/ XBT_PUBLIC(smx_mutex_t) simcall_mutex_init(void); -XBT_PUBLIC(void) simcall_mutex_destroy(smx_mutex_t mutex); +XBT_PUBLIC(void) SIMIX_mutex_destroy(smx_mutex_t mutex); XBT_PUBLIC(void) simcall_mutex_lock(smx_mutex_t mutex); XBT_PUBLIC(int) simcall_mutex_trylock(smx_mutex_t mutex); XBT_PUBLIC(void) simcall_mutex_unlock(smx_mutex_t mutex); XBT_PUBLIC(smx_cond_t) simcall_cond_init(void); -XBT_PUBLIC(void) simcall_cond_destroy(smx_cond_t cond); +XBT_PUBLIC(void) SIMIX_cond_destroy(smx_cond_t cond); XBT_PUBLIC(void) simcall_cond_signal(smx_cond_t cond); XBT_PUBLIC(void) simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex); XBT_PUBLIC(void) simcall_cond_wait_timeout(smx_cond_t cond, @@ -425,7 +425,7 @@ XBT_PUBLIC(void) simcall_cond_wait_timeout(smx_cond_t cond, XBT_PUBLIC(void) simcall_cond_broadcast(smx_cond_t cond); XBT_PUBLIC(smx_sem_t) simcall_sem_init(int capacity); -XBT_PUBLIC(void) simcall_sem_destroy(smx_sem_t sem); +XBT_PUBLIC(void) SIMIX_sem_destroy(smx_sem_t sem); XBT_PUBLIC(void) simcall_sem_release(smx_sem_t sem); XBT_PUBLIC(int) simcall_sem_would_block(smx_sem_t sem); XBT_PUBLIC(void) simcall_sem_acquire(smx_sem_t sem); diff --git a/src/msg/msg_synchro.cpp b/src/msg/msg_synchro.cpp index 70f13837fc..6547de0507 100644 --- a/src/msg/msg_synchro.cpp +++ b/src/msg/msg_synchro.cpp @@ -54,7 +54,7 @@ void MSG_sem_get_capacity(msg_sem_t sem) { } void MSG_sem_destroy(msg_sem_t sem) { - simcall_sem_destroy(sem); + SIMIX_sem_destroy(sem); } /** @brief returns a boolean indicating if this semaphore would block at this very specific time * diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index baa00625bf..901f49fff8 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -1031,15 +1031,6 @@ smx_mutex_t simcall_mutex_init(void) return simcall_BODY_mutex_init(); } -/** - * \ingroup simix_synchro_management - * - */ -void simcall_mutex_destroy(smx_mutex_t mutex) -{ - simcall_BODY_mutex_destroy(mutex); -} - /** * \ingroup simix_synchro_management * @@ -1076,15 +1067,6 @@ smx_cond_t simcall_cond_init(void) return simcall_BODY_cond_init(); } -/** - * \ingroup simix_synchro_management - * - */ -void simcall_cond_destroy(smx_cond_t cond) -{ - simcall_BODY_cond_destroy(cond); -} - /** * \ingroup simix_synchro_management * @@ -1133,15 +1115,6 @@ smx_sem_t simcall_sem_init(int capacity) return simcall_BODY_sem_init(capacity); } -/** - * \ingroup simix_synchro_management - * - */ -void simcall_sem_destroy(smx_sem_t sem) -{ - simcall_BODY_sem_destroy(sem); -} - /** * \ingroup simix_synchro_management * diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index 981ded3bd8..cdd7775335 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -941,13 +941,6 @@ static inline void simcall_mutex_init__set__result(smx_simcall_t simcall, void* simcall->result.dp = result; } -static inline smx_mutex_t simcall_mutex_destroy__get__mutex(smx_simcall_t simcall) { - return (smx_mutex_t) simcall->args[0].dp; -} -static inline void simcall_mutex_destroy__set__mutex(smx_simcall_t simcall, void* arg) { - simcall->args[0].dp = arg; -} - static inline smx_mutex_t simcall_mutex_lock__get__mutex(smx_simcall_t simcall) { return (smx_mutex_t) simcall->args[0].dp; } @@ -982,13 +975,6 @@ static inline void simcall_cond_init__set__result(smx_simcall_t simcall, void* r simcall->result.dp = result; } -static inline smx_cond_t simcall_cond_destroy__get__cond(smx_simcall_t simcall) { - return (smx_cond_t) simcall->args[0].dp; -} -static inline void simcall_cond_destroy__set__cond(smx_simcall_t simcall, void* arg) { - simcall->args[0].dp = arg; -} - static inline smx_cond_t simcall_cond_signal__get__cond(smx_simcall_t simcall) { return (smx_cond_t) simcall->args[0].dp; } @@ -1048,13 +1034,6 @@ static inline void simcall_sem_init__set__result(smx_simcall_t simcall, void* re simcall->result.dp = result; } -static inline smx_sem_t simcall_sem_destroy__get__sem(smx_simcall_t simcall) { - return (smx_sem_t) simcall->args[0].dp; -} -static inline void simcall_sem_destroy__set__sem(smx_simcall_t simcall, void* arg) { - simcall->args[0].dp = arg; -} - static inline smx_sem_t simcall_sem_release__get__sem(smx_simcall_t simcall) { return (smx_sem_t) simcall->args[0].dp; } diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index b6c206aa53..8f7a88037f 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -1158,27 +1158,6 @@ inline static smx_mutex_t simcall_BODY_mutex_init() { return (smx_mutex_t) self->simcall.result.dp; } -inline static void simcall_BODY_mutex_destroy(smx_mutex_t mutex) { - smx_process_t self = SIMIX_process_self(); - - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) SIMIX_mutex_destroy(mutex); - /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */ - - self->simcall.call = SIMCALL_MUTEX_DESTROY; - memset(&self->simcall.result, 0, sizeof(self->simcall.result)); - memset(self->simcall.args, 0, sizeof(self->simcall.args)); - self->simcall.args[0].dp = (void*) mutex; - if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, - SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); - SIMIX_process_yield(self); - } else { - SIMIX_simcall_handle(&self->simcall, 0); - } - - } - inline static void simcall_BODY_mutex_lock(smx_mutex_t mutex) { smx_process_t self = SIMIX_process_self(); @@ -1263,27 +1242,6 @@ inline static smx_cond_t simcall_BODY_cond_init() { return (smx_cond_t) self->simcall.result.dp; } -inline static void simcall_BODY_cond_destroy(smx_cond_t cond) { - smx_process_t self = SIMIX_process_self(); - - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) SIMIX_cond_destroy(cond); - /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */ - - self->simcall.call = SIMCALL_COND_DESTROY; - memset(&self->simcall.result, 0, sizeof(self->simcall.result)); - memset(self->simcall.args, 0, sizeof(self->simcall.args)); - self->simcall.args[0].dp = (void*) cond; - if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, - SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); - SIMIX_process_yield(self); - } else { - SIMIX_simcall_handle(&self->simcall, 0); - } - - } - inline static void simcall_BODY_cond_signal(smx_cond_t cond) { smx_process_t self = SIMIX_process_self(); @@ -1392,27 +1350,6 @@ inline static smx_sem_t simcall_BODY_sem_init(unsigned int capacity) { return (smx_sem_t) self->simcall.result.dp; } -inline static void simcall_BODY_sem_destroy(smx_sem_t sem) { - smx_process_t self = SIMIX_process_self(); - - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) SIMIX_sem_destroy(sem); - /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */ - - self->simcall.call = SIMCALL_SEM_DESTROY; - memset(&self->simcall.result, 0, sizeof(self->simcall.result)); - memset(self->simcall.args, 0, sizeof(self->simcall.args)); - self->simcall.args[0].dp = (void*) sem; - if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, - SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); - SIMIX_process_yield(self); - } else { - SIMIX_simcall_handle(&self->simcall, 0); - } - - } - inline static void simcall_BODY_sem_release(smx_sem_t sem) { smx_process_t self = SIMIX_process_self(); diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index 9c0b346bcc..a523f45b11 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -69,18 +69,15 @@ typedef enum { SIMCALL_COMM_GET_SRC_PROC, SIMCALL_COMM_GET_DST_PROC, SIMCALL_MUTEX_INIT, - SIMCALL_MUTEX_DESTROY, SIMCALL_MUTEX_LOCK, SIMCALL_MUTEX_TRYLOCK, SIMCALL_MUTEX_UNLOCK, SIMCALL_COND_INIT, - SIMCALL_COND_DESTROY, SIMCALL_COND_SIGNAL, SIMCALL_COND_WAIT, SIMCALL_COND_WAIT_TIMEOUT, SIMCALL_COND_BROADCAST, SIMCALL_SEM_INIT, - SIMCALL_SEM_DESTROY, SIMCALL_SEM_RELEASE, SIMCALL_SEM_WOULD_BLOCK, SIMCALL_SEM_ACQUIRE, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 9b9b802fd5..418256ce99 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -74,18 +74,15 @@ const char* simcall_names[] = { "SIMCALL_COMM_GET_SRC_PROC", "SIMCALL_COMM_GET_DST_PROC", "SIMCALL_MUTEX_INIT", - "SIMCALL_MUTEX_DESTROY", "SIMCALL_MUTEX_LOCK", "SIMCALL_MUTEX_TRYLOCK", "SIMCALL_MUTEX_UNLOCK", "SIMCALL_COND_INIT", - "SIMCALL_COND_DESTROY", "SIMCALL_COND_SIGNAL", "SIMCALL_COND_WAIT", "SIMCALL_COND_WAIT_TIMEOUT", "SIMCALL_COND_BROADCAST", "SIMCALL_SEM_INIT", - "SIMCALL_SEM_DESTROY", "SIMCALL_SEM_RELEASE", "SIMCALL_SEM_WOULD_BLOCK", "SIMCALL_SEM_ACQUIRE", @@ -375,11 +372,6 @@ case SIMCALL_MUTEX_INIT: SIMIX_simcall_answer(simcall); break; -case SIMCALL_MUTEX_DESTROY: - SIMIX_mutex_destroy((smx_mutex_t) simcall->args[0].dp); - SIMIX_simcall_answer(simcall); - break; - case SIMCALL_MUTEX_LOCK: simcall_HANDLER_mutex_lock(simcall , (smx_mutex_t) simcall->args[0].dp); break; @@ -399,11 +391,6 @@ case SIMCALL_COND_INIT: SIMIX_simcall_answer(simcall); break; -case SIMCALL_COND_DESTROY: - SIMIX_cond_destroy((smx_cond_t) simcall->args[0].dp); - SIMIX_simcall_answer(simcall); - break; - case SIMCALL_COND_SIGNAL: SIMIX_cond_signal((smx_cond_t) simcall->args[0].dp); SIMIX_simcall_answer(simcall); @@ -427,11 +414,6 @@ case SIMCALL_SEM_INIT: SIMIX_simcall_answer(simcall); break; -case SIMCALL_SEM_DESTROY: - SIMIX_sem_destroy((smx_sem_t) simcall->args[0].dp); - SIMIX_simcall_answer(simcall); - break; - case SIMCALL_SEM_RELEASE: simcall_HANDLER_sem_release(simcall , (smx_sem_t) simcall->args[0].dp); SIMIX_simcall_answer(simcall); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 60b8c72de7..43299df5f8 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -103,20 +103,17 @@ Func - comm_get_src_proc (void*, smx_process_t) (comm, void*, smx_synchro_t) Func - comm_get_dst_proc (void*, smx_process_t) (comm, void*, smx_synchro_t) Func H mutex_init (void*, smx_mutex_t) -Proc - mutex_destroy (void) (mutex, void*, smx_mutex_t) Blck H mutex_lock (void) (mutex, void*, smx_mutex_t) Func H mutex_trylock (int) (mutex, void*, smx_mutex_t) Proc H mutex_unlock (void) (mutex, void*, smx_mutex_t) Func - cond_init (void*, smx_cond_t) -Proc - cond_destroy (void) (cond, void*, smx_cond_t) Proc - cond_signal (void) (cond, void*, smx_cond_t) Blck H cond_wait (void) (cond, void*, smx_cond_t) (mutex, void*, smx_mutex_t) Blck H cond_wait_timeout (void) (cond, void*, smx_cond_t) (mutex, void*, smx_mutex_t) (timeout, double) Proc - cond_broadcast (void) (cond, void*, smx_cond_t) Func - sem_init (void*, smx_sem_t) (capacity, unsigned int) -Proc - sem_destroy (void) (sem, void*, smx_sem_t) Proc H sem_release (void) (sem, void*, smx_sem_t) Func H sem_would_block (int) (sem, void*, smx_sem_t) Blck H sem_acquire (void) (sem, void*, smx_sem_t) diff --git a/src/simix/smx_synchro_private.h b/src/simix/smx_synchro_private.h index d6da8045f7..9cf259203a 100644 --- a/src/simix/smx_synchro_private.h +++ b/src/simix/smx_synchro_private.h @@ -32,16 +32,13 @@ XBT_PRIVATE void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t XBT_PRIVATE void SIMIX_synchro_destroy(smx_synchro_t synchro); XBT_PRIVATE smx_mutex_t SIMIX_mutex_init(void); -XBT_PRIVATE void SIMIX_mutex_destroy(smx_mutex_t mutex); XBT_PRIVATE int SIMIX_mutex_trylock(smx_mutex_t mutex, smx_process_t issuer); XBT_PRIVATE void SIMIX_mutex_unlock(smx_mutex_t mutex, smx_process_t issuer); XBT_PRIVATE smx_cond_t SIMIX_cond_init(void); -XBT_PRIVATE void SIMIX_cond_destroy(smx_cond_t cond); XBT_PRIVATE void SIMIX_cond_broadcast(smx_cond_t cond); XBT_PRIVATE void SIMIX_cond_signal(smx_cond_t cond); -XBT_PRIVATE void SIMIX_sem_destroy(smx_sem_t sem); XBT_PRIVATE XBT_PRIVATE smx_sem_t SIMIX_sem_init(unsigned int value); XBT_PRIVATE void SIMIX_sem_release(smx_sem_t sem); XBT_PRIVATE int SIMIX_sem_would_block(smx_sem_t sem); diff --git a/src/xbt/xbt_os_synchro.c b/src/xbt/xbt_os_synchro.c index db8e2acbde..fd52a4deae 100644 --- a/src/xbt/xbt_os_synchro.c +++ b/src/xbt/xbt_os_synchro.c @@ -45,7 +45,7 @@ void xbt_mutex_release(xbt_mutex_t mutex) void xbt_mutex_destroy(xbt_mutex_t mutex) { - simcall_mutex_destroy((smx_mutex_t) mutex); + SIMIX_mutex_destroy((smx_mutex_t) mutex); } /***** condition related functions *****/ @@ -80,7 +80,7 @@ void xbt_cond_broadcast(xbt_cond_t cond) void xbt_cond_destroy(xbt_cond_t cond) { - simcall_cond_destroy((smx_cond_t) cond); + SIMIX_cond_destroy((smx_cond_t) cond); } /***** barrier related functions *****/ -- 2.20.1