Skip to content

Commit

Permalink
Always disable GC in a coroutine unless the patch is applied
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickvP committed Mar 1, 2023
1 parent 4c73eab commit 1760057
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
22 changes: 19 additions & 3 deletions boehmgc-coroutine-sp-fallback.diff
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
diff --git a/darwin_stop_world.c b/darwin_stop_world.c
index 3dbaa3fb..36a1d1f7 100644
index 0468aaec..b348d869 100644
--- a/darwin_stop_world.c
+++ b/darwin_stop_world.c
@@ -352,6 +352,7 @@ GC_INNER void GC_push_all_stacks(void)
@@ -356,6 +356,7 @@ GC_INNER void GC_push_all_stacks(void)
int nthreads = 0;
word total_size = 0;
mach_msg_type_number_t listcount = (mach_msg_type_number_t)THREAD_TABLE_SZ;
+ size_t stack_limit;
if (!EXPECT(GC_thr_initialized, TRUE))
GC_thr_init();

@@ -407,6 +408,19 @@ GC_INNER void GC_push_all_stacks(void)
@@ -411,6 +412,19 @@ GC_INNER void GC_push_all_stacks(void)
GC_push_all_stack_sections(lo, hi, p->traced_stack_sect);
}
if (altstack_lo) {
Expand All @@ -30,6 +30,22 @@ index 3dbaa3fb..36a1d1f7 100644
total_size += altstack_hi - altstack_lo;
GC_push_all_stack(altstack_lo, altstack_hi);
}
diff --git a/include/gc.h b/include/gc.h
index edab6c22..f2c61282 100644
--- a/include/gc.h
+++ b/include/gc.h
@@ -2172,6 +2172,11 @@ GC_API void GC_CALL GC_win32_free_heap(void);
(*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic_ignore_off_page)
#endif /* _AMIGA && !GC_AMIGA_MAKINGLIB */

+#if !__APPLE__
+/* Patch doesn't work on apple */
+#define NIX_BOEHM_PATCH_VERSION 1
+#endif
+
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/pthread_stop_world.c b/pthread_stop_world.c
index b5d71e62..aed7b0bf 100644
--- a/pthread_stop_world.c
Expand Down
4 changes: 3 additions & 1 deletion src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,12 @@ void initGC()
StackAllocator::defaultAllocator = &boehmGCStackAllocator;


#if NIX_BOEHM_PATCH_VERSION != 1
/* Used to disable GC when entering coroutines on macOS */
create_disable_gc = []() -> std::shared_ptr<void> {
create_coro_gc_hook = []() -> std::shared_ptr<void> {
return std::make_shared<BoehmDisableGC>();
};
#endif

/* Set the initial heap size to something fairly big (25% of
physical RAM, up to a maximum of 384 MiB) so that in most cases
Expand Down
9 changes: 4 additions & 5 deletions src/libutil/serialise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,17 @@ static DefaultStackAllocator defaultAllocatorSingleton;
StackAllocator *StackAllocator::defaultAllocator = &defaultAllocatorSingleton;


std::shared_ptr<void> (*create_disable_gc)() = []() -> std::shared_ptr<void> {
std::shared_ptr<void> (*create_coro_gc_hook)() = []() -> std::shared_ptr<void> {
return {};
};

/* This class is used for entry and exit hooks on coroutines */
class CoroutineContext {
#if __APPLE__
/* Disable GC when entering the coroutine on macOS, since it doesn't find the main thread stack in this case.
/* Disable GC when entering the coroutine without the boehm patch,
* since it doesn't find the main thread stack in this case.
* std::shared_ptr<void> performs type-erasure, so it will call the right
* deleter. */
const std::shared_ptr<void> disable_gc = create_disable_gc();
#endif
const std::shared_ptr<void> coro_gc_hook = create_coro_gc_hook();
public:
CoroutineContext() {};
~CoroutineContext() {};
Expand Down
4 changes: 2 additions & 2 deletions src/libutil/serialise.hh
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,10 @@ struct StackAllocator {
static StackAllocator *defaultAllocator;
};

/* Disabling GC when entering a coroutine (on macos).
/* Disabling GC when entering a coroutine (without the boehm patch).
mutable to avoid boehm gc dependency in libutil.
*/
extern std::shared_ptr<void> (*create_disable_gc)();
extern std::shared_ptr<void> (*create_coro_gc_hook)();


}

0 comments on commit 1760057

Please sign in to comment.