From 0dd06103d837ce1d4aa0a97f9e61ff0f6eb3a32b Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Tue, 2 Aug 2022 19:28:52 +0800 Subject: [PATCH] Use new API for setting MMTk options Now mmtk-ruby provides several API functions to create MMTKBuilder and set options. We no longer need to temporarily set environment variables to set the MMTk plan. --- gc.c | 15 ++++++--------- mmtk.h | 14 +++++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/gc.c b/gc.c index d908520a67fb33..ff0e9c80bd18c2 100644 --- a/gc.c +++ b/gc.c @@ -1877,20 +1877,17 @@ rb_objspace_alloc(void) #if USE_MMTK if (rb_mmtk_enabled_p()) { - if (!mmtk_env_plan && setenv("MMTK_PLAN", mmtk_chosen_plan, 0) != 0) { - fputs("[FATAL] could not set MMTK_PLAN\n", stderr); - exit(EXIT_FAILURE); - } + MMTk_Builder mmtk_builder = mmtk_builder_default(); + + mmtk_builder_set_plan(mmtk_builder, mmtk_chosen_plan); // Note: the limit is currently broken for NoGC, but we still attempt to // initialise it properly regardless. // See https://github.com/mmtk/mmtk-core/issues/214 - mmtk_init_binding(rb_mmtk_heap_limit(), &ruby_upcalls); + size_t heap_size = rb_mmtk_heap_limit(); + mmtk_builder_set_heap_size(mmtk_builder, heap_size); - if (!mmtk_env_plan && unsetenv("MMTK_PLAN") != 0) { - fputs("[FATAL] could not unset MMTK_PLAN\n", stderr); - exit(EXIT_FAILURE); - } + mmtk_init_binding(mmtk_builder, &ruby_upcalls); } #endif diff --git a/mmtk.h b/mmtk.h index c1991f19374e3f..d5dfcabf6a7890 100644 --- a/mmtk.h +++ b/mmtk.h @@ -13,6 +13,7 @@ extern "C" { #define MMTK_MIN_OBJ_ALIGN 8 #define MMTK_OBJREF_OFFSET 8 +typedef void* MMTk_Builder; typedef void* MMTk_Mutator; typedef void* MMTk_TraceLocal; @@ -38,10 +39,21 @@ typedef struct { void (*scan_object_ruby_style)(void *object); } RubyUpcalls; +/** + * MMTK builder and options + */ +MMTk_Builder mmtk_builder_default(); + +void mmtk_builder_set_heap_size(MMTk_Builder builder, uintptr_t heap_size); + +void mmtk_builder_set_plan(MMTk_Builder builder, const char *plan_name); + +void mmtk_init_binding(MMTk_Builder builder, const RubyUpcalls *upcalls); + /** * Initialization */ -extern void mmtk_init_binding(size_t heap_size, RubyUpcalls *ruby_upcalls); +extern void mmtk_init_binding(MMTk_Builder builder, const RubyUpcalls *upcalls); extern void mmtk_initialize_collection(void *tls); extern void mmtk_enable_collection();