From 305484af3e8fa3ab8fe8a375d85c3f4cea8a07fc Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Mon, 8 Jul 2024 17:03:06 +0800 Subject: [PATCH] Make iseq conditional PPP. We use the ISEQ_USE_COMPILE_DATA flag to determine if it is a PPP. We will remove it from the list of PPPs if it no longer has that flag. --- internal/mmtk.h | 1 + iseq.c | 14 ++++++++++++++ iseq.h | 18 ++++++++++++++++++ mmtk_support.c | 8 ++++++++ 4 files changed, 41 insertions(+) diff --git a/internal/mmtk.h b/internal/mmtk.h index 1938db8ef760c5..6cca8a486c0d34 100644 --- a/internal/mmtk.h +++ b/internal/mmtk.h @@ -80,6 +80,7 @@ typedef struct MMTk_RubyUpcalls { void *(*get_original_givtbl)(MMTk_ObjectReference object); void (*move_givtbl)(MMTk_ObjectReference old_objref, MMTk_ObjectReference new_objref); size_t (*vm_live_bytes)(void); + bool (*is_ppp)(MMTk_ObjectReference object); void (*update_frozen_strings_table)(void); void (*update_finalizer_table)(void); void (*update_obj_id_tables)(void); diff --git a/iseq.c b/iseq.c index 512cfe1bcc69f4..53f65edd60fdd6 100644 --- a/iseq.c +++ b/iseq.c @@ -436,6 +436,20 @@ rb_iseq_mark_and_move(rb_iseq_t *iseq, bool reference_updating) RUBY_MARK_LEAVE("iseq"); } +#if USE_MMTK +bool +rb_mmtk_iseq_is_ppp(VALUE iseq) +{ + return FL_TEST_RAW((VALUE)iseq, ISEQ_USE_COMPILE_DATA); +} + +void +rb_mmtk_iseq_register_ppp(rb_iseq_t *iseq) +{ + mmtk_register_ppp((MMTk_ObjectReference)iseq); +} +#endif + static size_t param_keyword_size(const struct rb_iseq_param_keyword *pkw) { diff --git a/iseq.h b/iseq.h index a0b59c441f6a8c..cb69d8df5529c5 100644 --- a/iseq.h +++ b/iseq.h @@ -15,6 +15,11 @@ #include "vm_core.h" #include "prism_compile.h" +#if USE_MMTK +#include "internal/mmtk_macros.h" +#include "internal/mmtk_support.h" +#endif + RUBY_EXTERN const int ruby_api_version[]; #define ISEQ_MAJOR_VERSION ((unsigned int)ruby_api_version[0]) #define ISEQ_MINOR_VERSION ((unsigned int)ruby_api_version[1]) @@ -151,7 +156,16 @@ static inline void ISEQ_COMPILE_DATA_ALLOC(rb_iseq_t *iseq) { iseq->aux.compile_data = ZALLOC(struct iseq_compile_data); + WHEN_USING_MMTK({ + RUBY_ASSERT((iseq->flags & ISEQ_USE_COMPILE_DATA) == 0); + }) iseq->flags |= ISEQ_USE_COMPILE_DATA; + WHEN_USING_MMTK({ + // Defined in iseq.c + void rb_mmtk_iseq_register_ppp(rb_iseq_t *iseq); + + rb_mmtk_iseq_register_ppp(iseq); + }) } static inline void @@ -184,6 +198,10 @@ unsigned int *rb_iseq_insns_info_decode_positions(const struct rb_iseq_constant_ int rb_vm_insn_addr2opcode(const void *addr); +#if USE_MMTK +bool rb_mmtk_iseq_is_ppp(VALUE iseq); +#endif + RUBY_SYMBOL_EXPORT_BEGIN /* compile.c */ diff --git a/mmtk_support.c b/mmtk_support.c index 65ed7b19bc9298..778ee34b2d347a 100644 --- a/mmtk_support.c +++ b/mmtk_support.c @@ -10,6 +10,7 @@ #include "internal/mmtk.h" #include "internal/thread.h" #include "internal/variable.h" +#include "iseq.h" #include "ruby/ruby.h" #include "ractor_core.h" #include "vm_core.h" @@ -615,6 +616,7 @@ rb_mmtk_is_ppp(VALUE obj) { case T_IMEMO: switch (imemo_type(obj)) { case imemo_iseq: + return rb_mmtk_iseq_is_ppp(obj); case imemo_tmpbuf: case imemo_ast: case imemo_ifunc: @@ -629,6 +631,11 @@ rb_mmtk_is_ppp(VALUE obj) { } } +static bool +rb_mmtk_is_ppp_wrapper(MMTk_ObjectReference obj) { + rb_mmtk_is_ppp((VALUE)obj); +} + static void rb_mmtk_flush_ppp_buffer(struct rb_mmtk_values_buffer *buffer) { @@ -1629,6 +1636,7 @@ MMTk_RubyUpcalls ruby_upcalls = { rb_mmtk_get_original_givtbl, rb_mmtk_move_givtbl, rb_mmtk_vm_live_bytes, + rb_mmtk_is_ppp_wrapper, rb_mmtk_update_frozen_strings_table, rb_mmtk_update_finalizer_table, rb_mmtk_update_obj_id_tables,