Skip to content

Commit

Permalink
Merge pull request #15 from mmtk/strongly-typed-options
Browse files Browse the repository at this point in the history
Use new API for setting MMTk options
  • Loading branch information
chrisseaton authored Aug 3, 2022
2 parents cf8e768 + 0dd0610 commit 0035c98
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
15 changes: 6 additions & 9 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand Down

0 comments on commit 0035c98

Please sign in to comment.