Skip to content

Commit

Permalink
[gc] add stop-the-world api (#42138)
Browse files Browse the repository at this point in the history
It's sometimes useful to have a way for the runtime to stop the world.  Only works on SGen.

Co-authored-by: lambdageek <lambdageek@users.noreply.github.com>
  • Loading branch information
monojenkins and lambdageek authored Sep 12, 2020
1 parent dea933a commit 4bc91cb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/mono/mono/metadata/boehm-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,18 @@ mono_gc_collection_count (int generation)
return GC_get_gc_no ();
}

void
mono_gc_stop_world ()
{
g_assert ("mono_gc_stop_world is not supported in Boehm");
}

void
mono_gc_restart_world ()
{
g_assert ("mono_gc_restart_world is not supported in Boehm");
}

/**
* mono_gc_add_memory_pressure:
* \param value amount of bytes
Expand Down
6 changes: 6 additions & 0 deletions src/mono/mono/metadata/mono-gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ MONO_API int mono_gc_walk_heap (int flags, MonoGCReferences callback,
MONO_API MONO_RT_EXTERNAL_ONLY void
mono_gc_init_finalizer_thread (void);

/*
* Only supported under SGen. These two with Sgen will take and release the LOCK_GC
*/
void mono_gc_stop_world (void);
void mono_gc_restart_world (void);

MONO_END_DECLS

#endif /* __METADATA_MONO_GC_H__ */
Expand Down
12 changes: 12 additions & 0 deletions src/mono/mono/metadata/null-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ mono_gc_collection_count (int generation)
return 0;
}

void
mono_gc_stop_world ()
{
g_assert ("mono_gc_stop_world is not supported in null GC");
}

void
mono_gc_restart_world ()
{
g_assert ("mono_gc_restart_world is not supported in null GC");
}

void
mono_gc_add_memory_pressure (gint64 value)
{
Expand Down
14 changes: 14 additions & 0 deletions src/mono/mono/metadata/sgen-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,20 @@ sgen_finish_concurrent_work (const char *reason, gboolean stw)
sgen_major_collector.finish_sweeping ();
}

void
mono_gc_stop_world ()
{
LOCK_GC;
sgen_stop_world (0, FALSE);
}

void
mono_gc_restart_world ()
{
sgen_restart_world (0, FALSE);
UNLOCK_GC;
}

/*
* When appdomains are unloaded we can easily remove objects that have finalizers,
* but all the others could still be present in random places on the heap.
Expand Down

0 comments on commit 4bc91cb

Please sign in to comment.