Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove coordinator and support forking #60

Merged
merged 8 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ typedef uint32_t MMTk_AllocationSemantics;

#define MMTK_MIN_OBJ_ALIGN 8

#define MMTK_GC_THREAD_KIND_CONTROLLER 0

#define MMTK_GC_THREAD_KIND_WORKER 1

typedef struct RubyBindingOptions {
Expand Down Expand Up @@ -146,6 +144,10 @@ bool mmtk_will_never_move(MMTk_ObjectReference object);

void mmtk_initialize_collection(MMTk_VMThread tls);

void mmtk_prepare_to_fork(void);

void mmtk_after_fork(MMTk_VMThread tls);

void mmtk_enable_collection(void);

void mmtk_disable_collection(void);
Expand Down
4 changes: 4 additions & 0 deletions internal/mmtk_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ VALUE* rb_mmtk_objbuf_to_elems(rb_mmtk_objbuf_t* objbuf);

void rb_mmtk_pin_array_buffer(VALUE array, volatile VALUE *stack_slot);

// Forking support
void rb_mmtk_shutdown_gc_threads(void);
void rb_mmtk_respawn_gc_threads(void);

// MMTk-specific Ruby module (GC::MMTk)
void rb_mmtk_define_gc_mmtk_module(void);
VALUE rb_mmtk_plan_name(VALUE _);
Expand Down
14 changes: 14 additions & 0 deletions mmtk_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,20 @@ rb_mmtk_pin_array_buffer(VALUE array, volatile VALUE *stack_slot)
}
}

////////////////////////////////////////////////////////////////////////////////
// Forking support
////////////////////////////////////////////////////////////////////////////////
void
rb_mmtk_shutdown_gc_threads(void)
{
mmtk_prepare_to_fork();
}

void rb_mmtk_respawn_gc_threads(void)
{
mmtk_after_fork(GET_THREAD());
}

////////////////////////////////////////////////////////////////////////////////
// MMTk-specific Ruby module (GC::MMTk)
////////////////////////////////////////////////////////////////////////////////
Expand Down
18 changes: 10 additions & 8 deletions process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1677,11 +1677,21 @@ static void
before_fork_ruby(void)
{
before_exec();
#if USE_MMTK
if (rb_mmtk_enabled_p()) {
rb_mmtk_shutdown_gc_threads();
}
#endif
}

static void
after_fork_ruby(rb_pid_t pid)
{
#if USE_MMTK
if (rb_mmtk_enabled_p()) {
rb_mmtk_respawn_gc_threads();
}
#endif
rb_threadptr_pending_interrupt_clear(GET_THREAD());
if (pid == 0) {
// child
Expand Down Expand Up @@ -9236,15 +9246,7 @@ InitVM_process(void)
#endif

rb_define_singleton_method(rb_mProcess, "exec", f_exec, -1);
#if USE_MMTK
// FIXME: MMTk currently doesn't support forking, so Process will not respond to :fork for not.
// We should add necessary mechanism to mmtk-core in order to support forking.
if (!rb_mmtk_enabled_p()) {
#endif
rb_define_singleton_method(rb_mProcess, "fork", rb_f_fork, 0);
#if USE_MMTK
}
#endif
rb_define_singleton_method(rb_mProcess, "spawn", rb_f_spawn, -1);
rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1);
rb_define_singleton_method(rb_mProcess, "exit", f_exit, -1);
Expand Down
5 changes: 3 additions & 2 deletions test/ruby/test_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,8 @@ def test_daemon_detached
end
end

if File.directory?("/proc/self/task") && /netbsd[a-z]*[1-6]/ !~ RUBY_PLATFORM
# Note: MMTk has many GC worker threads, and they will be visible in /proc/self/task.
if File.directory?("/proc/self/task") && /netbsd[a-z]*[1-6]/ !~ RUBY_PLATFORM && !defined?(GC::MMTk)
def test_daemon_no_threads
pid, data = IO.popen("-", "r+") do |f|
break f.pid, f.readlines if f
Expand All @@ -1931,7 +1932,7 @@ def test_daemon_no_threads
assert_include(1..2, data.size, bug4920)
assert_not_include(data.map(&:to_i), pid)
end
else # darwin
else # darwin or MMTk
def test_daemon_no_threads
data = EnvUtil.timeout(3) do
IO.popen("-") do |f|
Expand Down
Loading