diff options
author | Peter Zhu <[email protected]> | 2024-08-08 12:19:35 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-08-08 12:19:35 -0400 |
commit | 0bff07644ba5aff9c844b6cf75a0e1365c35c6a3 (patch) | |
tree | 8f21e77683eb74e6ae2c2563907ab68f99d94f2e | |
parent | 868d63f0a3a2f63cfc0d5a1a3e6f073722c4fb8e (diff) |
Make YJIT a GC root rather than an object (#11343)
YJIT currently uses the YJIT root object to mark objects during GC and
update references during compaction. This object otherwise serves no
purpose.
This commit changes it YJIT to be step when marking the GC root. This
saves some memory from being allocated from the system and the GC.
Notes
Notes:
Merged-By: maximecb <[email protected]>
-rw-r--r-- | common.mk | 1 | ||||
-rw-r--r-- | gc.c | 18 | ||||
-rw-r--r-- | yjit.c | 27 | ||||
-rw-r--r-- | yjit/src/invariants.rs | 4 | ||||
-rw-r--r-- | yjit/src/yjit.rs | 6 |
5 files changed, 21 insertions, 35 deletions
@@ -7503,6 +7503,7 @@ gc.$(OBJEXT): {$(VPATH)}vm_core.h gc.$(OBJEXT): {$(VPATH)}vm_debug.h gc.$(OBJEXT): {$(VPATH)}vm_opts.h gc.$(OBJEXT): {$(VPATH)}vm_sync.h +gc.$(OBJEXT): {$(VPATH)}yjit.h goruby.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h goruby.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h goruby.$(OBJEXT): $(CCAN_DIR)/list/list.h @@ -122,6 +122,7 @@ #include "vm_sync.h" #include "vm_callinfo.h" #include "ractor_core.h" +#include "yjit.h" #include "builtin.h" #include "shape.h" @@ -2474,6 +2475,15 @@ rb_gc_mark_roots(void *objspace, const char **categoryp) MARK_CHECKPOINT("global_tbl"); rb_gc_mark_global_tbl(); +#if USE_YJIT + void rb_yjit_root_mark(void); // in Rust + + if (rb_yjit_enabled_p) { + MARK_CHECKPOINT("YJIT"); + rb_yjit_root_mark(); + } +#endif + MARK_CHECKPOINT("finish"); #undef MARK_CHECKPOINT } @@ -3152,6 +3162,14 @@ rb_gc_update_vm_references(void *objspace) global_symbols.ids = rb_gc_impl_location(objspace, global_symbols.ids); global_symbols.dsymbol_fstr_hash = rb_gc_impl_location(objspace, global_symbols.dsymbol_fstr_hash); gc_update_table_refs(objspace, global_symbols.str_sym); + +#if USE_YJIT + void rb_yjit_root_update_references(void); // in Rust + + if (rb_yjit_enabled_p) { + rb_yjit_root_update_references(); + } +#endif } void @@ -1156,24 +1156,6 @@ struct yjit_root_struct { bool unused; // empty structs are not legal in C99 }; -static size_t -yjit_root_memsize(const void *ptr) -{ - // Count off-gc-heap allocation size of the dependency table - return 0; // TODO: more accurate accounting -} - -void rb_yjit_root_mark(void *ptr); // in Rust -void rb_yjit_root_update_references(void *ptr); // in Rust - -// Custom type for interacting with the GC -// TODO: make this write barrier protected -static const rb_data_type_t yjit_root_type = { - "yjit_root", - {rb_yjit_root_mark, RUBY_DEFAULT_FREE, yjit_root_memsize, rb_yjit_root_update_references}, - 0, 0, RUBY_TYPED_FREE_IMMEDIATELY -}; - // For dealing with refinements void rb_yjit_invalidate_all_method_lookup_assumptions(void) @@ -1256,12 +1238,3 @@ VALUE rb_yjit_enable(rb_execution_context_t *ec, VALUE self, VALUE gen_stats, VA // Preprocessed yjit.rb generated during build #include "yjit.rbinc" - -// Initialize the GC hooks -void -rb_yjit_init_gc_hooks(void) -{ - struct yjit_root_struct *root; - VALUE yjit_root = TypedData_Make_Struct(0, struct yjit_root_struct, &yjit_root_type, root); - rb_vm_register_global_object(yjit_root); -} diff --git a/yjit/src/invariants.rs b/yjit/src/invariants.rs index b1da603b27..98516aa400 100644 --- a/yjit/src/invariants.rs +++ b/yjit/src/invariants.rs @@ -345,7 +345,7 @@ pub extern "C" fn rb_yjit_constant_state_changed(id: ID) { /// Callback for marking GC objects inside [Invariants]. /// See `struct yjijt_root_struct` in C. #[no_mangle] -pub extern "C" fn rb_yjit_root_mark(_: *mut c_void) { +pub extern "C" fn rb_yjit_root_mark() { // Call rb_gc_mark on exit location's raw_samples to // wrap frames in a GC allocated object. This needs to be called // at the same time as root mark. @@ -374,7 +374,7 @@ pub extern "C" fn rb_yjit_root_mark(_: *mut c_void) { } #[no_mangle] -pub extern "C" fn rb_yjit_root_update_references(_: *mut c_void) { +pub extern "C" fn rb_yjit_root_update_references() { if unsafe { INVARIANTS.is_none() } { return; } diff --git a/yjit/src/yjit.rs b/yjit/src/yjit.rs index 5de9d17624..c2647d55f7 100644 --- a/yjit/src/yjit.rs +++ b/yjit/src/yjit.rs @@ -75,12 +75,6 @@ fn yjit_init() { let _ = std::fs::remove_file(&perf_map); println!("YJIT perf map: {perf_map}"); } - - // Initialize the GC hooks. Do this at last as some code depend on Rust initialization. - extern "C" { - fn rb_yjit_init_gc_hooks(); - } - unsafe { rb_yjit_init_gc_hooks() } } /// At the moment, we abort in all cases we panic. |