diff --git a/mps/code/lock.h b/mps/code/lock.h index 861ac6c272a..1a02d7997ed 100644 --- a/mps/code/lock.h +++ b/mps/code/lock.h @@ -78,7 +78,7 @@ extern void LockRelease(Lock lock); extern Bool LockCheck(Lock lock); -/* LockIsHeld -- test whether lock is held */ +/* LockIsHeld -- test whether lock is held by any thread */ extern Bool LockIsHeld(Lock lock); diff --git a/mps/code/mpsi.c b/mps/code/mpsi.c index 5bb6e7fa860..3449c1aaed6 100644 --- a/mps/code/mpsi.c +++ b/mps/code/mpsi.c @@ -264,6 +264,7 @@ void mps_arena_postmortem(mps_arena_t arena) { /* Don't call ArenaEnter -- one of the purposes of this function is * to release the arena lock if it's held */ + AVER(TESTT(Arena, arena)); ArenaPostmortem(ArenaGlobals(arena)); } @@ -386,6 +387,9 @@ void mps_arena_destroy(mps_arena_t arena) mps_bool_t mps_arena_busy(mps_arena_t arena) { + /* Don't call ArenaEnter -- the purpose of this function is to + * determine if the arena lock is held */ + AVER(TESTT(Arena, arena)); return ArenaBusy(arena); } diff --git a/mps/code/traceanc.c b/mps/code/traceanc.c index a446aa41b67..5326c5f2e21 100644 --- a/mps/code/traceanc.c +++ b/mps/code/traceanc.c @@ -830,6 +830,7 @@ void ArenaRestoreProtection(Globals globals) } } } + arenaForgetProtection(globals); } diff --git a/mps/design/lock.txt b/mps/design/lock.txt index 4ce41baba4c..45737737bb4 100644 --- a/mps/design/lock.txt +++ b/mps/design/lock.txt @@ -62,7 +62,9 @@ recursive lock.) _`.req.held`: Provide a means to test if a lock is held. (This is needed for debugging a dynamic function table callback on Windows on x86-64. See ``mps_arena_busy()`` for a detailed description of this -use case.) +use case. Note that in this use case the program is running +single-threaded and so there is no need for this feature to be +thread-safe.) _`.req.global`: Provide *global* locks: that is locks that need not be allocated or initialized by the user. @@ -131,7 +133,8 @@ corresponding ``LockClaimRecursive()`` call. ``Bool LockIsHeld(Lock lock)`` -Return true if the lock is held, false otherwise. +Return true if the lock is held by any thread, false otherwise. Note +that this function need not be thread-safe (see `.req.held`_). ``void LockClaimGlobal(void)`` diff --git a/mps/manual/source/glossary/p.rst b/mps/manual/source/glossary/p.rst index 228c1264e32..f968a6471d0 100644 --- a/mps/manual/source/glossary/p.rst +++ b/mps/manual/source/glossary/p.rst @@ -179,14 +179,15 @@ Memory Management Glossary: P .. mps:specific:: - One of the three states an :term:`arena` can be in (the - others being the :term:`clamped state` and the - :term:`unclamped state`). In the parked state, no - :term:`garbage collection` is in progress, no object - motion occurs and the staleness of :term:`location - dependencies` does not change. Call - :c:func:`mps_arena_park` or :c:func:`mps_arena_collect` to - put an arena into the parked state. + One of the four states an :term:`arena` can be in (the + others being the :term:`clamped state`, the + :term:`postmortem state`, and the :term:`unclamped + state`). In the parked state, no :term:`garbage + collection` is in progress, no object motion occurs and + the staleness of :term:`location dependencies` does not + change. Call :c:func:`mps_arena_park` or + :c:func:`mps_arena_collect` to put an arena into the + parked state. perfect fit diff --git a/mps/manual/source/topic/arena.rst b/mps/manual/source/topic/arena.rst index 61c81b49ab2..a64c468325a 100644 --- a/mps/manual/source/topic/arena.rst +++ b/mps/manual/source/topic/arena.rst @@ -676,7 +676,6 @@ New collections may start? yes Objects may move? yes no no no Location dependencies may become stale? yes no no no Memory may be returned to the OS? yes no no no -Memory protection may be applied? yes yes yes no Safe to continue running? yes yes yes no Functions that leave the arena in this state :c:func:`mps_arena_create_k`, :c:func:`mps_arena_clamp`, :c:func:`mps_arena_park`, :c:func:`mps_arena_postmortem` :c:func:`mps_arena_release`, :c:func:`mps_arena_step` :c:func:`mps_arena_collect` @@ -762,10 +761,17 @@ can only be called in this state. .. warning:: - After calling this function, memory managed by the arena is not - in a consistent state, and so it is no longer safe to continue - running the client program. This functions is intended for - postmortem debugging only. + 1. After calling this function, memory managed by the arena is + not in a consistent state, and so it is no longer safe to + continue running the client program. This functions is + intended for postmortem debugging only. + + 2. This function must be called from the thread that holds the + arena lock (if any thread holds it). This is the case if the + program is single-threaded, or if it is called from an MPS + assertion handler. When calling this function from the + debugger, check the stack to see which thread has the MPS + arena lock. .. index::