Skip to content

Add --mmtk option, but at the moment it has to match the compilation configuration #10

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

Merged
merged 1 commit into from
Jul 25, 2022
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
10 changes: 9 additions & 1 deletion gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ RubyUpcalls ruby_upcalls;
#endif

#ifdef USE_THIRD_PARTY_HEAP
static bool mmtk_enable = false;
static const char *mmtk_env_plan = NULL;
static const char *mmtk_pre_arg_plan = NULL;
static const char *mmtk_post_arg_plan = NULL;
Expand Down Expand Up @@ -15143,6 +15144,9 @@ void rb_mmtk_pre_process_opts(int argc, char **argv) {
bool enable_rubyopt = true;

mmtk_env_plan = getenv("MMTK_PLAN");
if (mmtk_env_plan) {
mmtk_enable = true;
}

for (int n = 1; n < argc; n++) {
if (strcmp(argv[n], "--") == 0) {
Expand Down Expand Up @@ -15222,10 +15226,14 @@ void rb_mmtk_post_process_opts(const char *s) {
}
}

void rb_mmtk_post_process_opts_finish(void) {
void rb_mmtk_post_process_opts_finish(bool enable) {
mmtk_enable |= enable;
if (strcmp(mmtk_pre_arg_plan ? mmtk_pre_arg_plan : "", mmtk_post_arg_plan ? mmtk_post_arg_plan : "") != 0) {
rb_raise(rb_eRuntimeError, "--mmtk-plan values disagree");
}
if (!mmtk_enable) {
rb_bug("must enable MMTk");
}
}

#endif
2 changes: 1 addition & 1 deletion gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct rb_thread_struct;
void rb_gc_init_collection();
void rb_mmtk_pre_process_opts(int argc, char **argv);
void rb_mmtk_post_process_opts(const char *arg);
void rb_mmtk_post_process_opts_finish(void);
void rb_mmtk_post_process_opts_finish(bool enable);
#endif // USE_THIRD_PARTY_HEAP

RUBY_SYMBOL_EXPORT_BEGIN
Expand Down
15 changes: 14 additions & 1 deletion ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ void rb_warning_category_update(unsigned int mask, unsigned int bits);
X(mjit) \
SEP \
X(yjit) \
SEP \
X(mmtk) \
/* END OF FEATURES */
#define EACH_DEBUG_FEATURES(X, SEP) \
X(frozen_string_literal) \
Expand Down Expand Up @@ -194,6 +196,7 @@ enum {
#endif
& ~FEATURE_BIT(frozen_string_literal)
& ~feature_jit_mask
& ~FEATURE_BIT(mmtk)
)
};

Expand All @@ -211,6 +214,9 @@ cmdline_options_init(ruby_cmdline_options_t *opt)
#elif defined(YJIT_FORCE_ENABLE)
opt->features.set |= FEATURE_BIT(yjit);
#endif
#ifdef MMTK_FORCE_ENABLE /* to use with: ./configure cppflags="-DMMTK_FORCE_ENABLE" */
opt->features.set |= FEATURE_BIT(mmtk);
#endif

return opt;
}
Expand Down Expand Up @@ -284,6 +290,9 @@ usage(const char *name, int help, int highlight, int columns)
#endif
#if YJIT_BUILD
M("--yjit", "", "enable in-process JIT compiler (experimental)"),
#endif
#ifdef USE_THIRD_PARTY_HEAP
M("--mmtk", "", "use MMTk for garbage collection (experimental)"),
#endif
M("-h", "", "show this message, --help for more info"),
};
Expand Down Expand Up @@ -318,6 +327,9 @@ usage(const char *name, int help, int highlight, int columns)
#endif
#if YJIT_BUILD
M("yjit", "", "in-process JIT compiler (default: disabled)"),
#endif
#ifdef USE_THIRD_PARTY_HEAP
M("mmtk", "", "MMTk garbage collection (default: disabled)"),
#endif
};
static const struct ruby_opt_message warn_categories[] = {
Expand Down Expand Up @@ -1457,6 +1469,7 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
}
else if (is_option_with_optarg("mmtk", '-', true, false, false)) {
#ifdef USE_THIRD_PARTY_HEAP
FEATURE_SET(opt->features, FEATURE_BIT(mmtk));
rb_mmtk_post_process_opts(s);
#undef opt_match_noarg
#undef opt_match_arg
Expand Down Expand Up @@ -1829,7 +1842,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
}

#ifdef USE_THIRD_PARTY_HEAP
rb_mmtk_post_process_opts_finish();
rb_mmtk_post_process_opts_finish(FEATURE_SET_P(opt->features, mmtk));
#endif

if (opt->src.enc.name)
Expand Down