Skip to content

Commit

Permalink
Make iseq conditional PPP.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wks committed Jul 8, 2024
1 parent c9ff790 commit 305484a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions iseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
18 changes: 18 additions & 0 deletions iseq.h
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
8 changes: 8 additions & 0 deletions mmtk_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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)
{
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 305484a

Please sign in to comment.