1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

MJIT: Share rb_mjit_unit through mjit_unit.h

mjit_compile.c should be able to access this more easily.
This commit is contained in:
Takashi Kokubun 2022-07-14 21:53:41 -07:00
parent ed8c21bbd5
commit 6c2cad835a
Notes: git 2022-07-15 14:54:43 +09:00
4 changed files with 34 additions and 33 deletions

View file

@ -9658,6 +9658,7 @@ mjit.$(OBJEXT): {$(VPATH)}mjit.h
mjit.$(OBJEXT): {$(VPATH)}mjit.rb
mjit.$(OBJEXT): {$(VPATH)}mjit.rbinc
mjit.$(OBJEXT): {$(VPATH)}mjit_config.h
mjit.$(OBJEXT): {$(VPATH)}mjit_unit.h
mjit.$(OBJEXT): {$(VPATH)}node.h
mjit.$(OBJEXT): {$(VPATH)}onigmo.h
mjit.$(OBJEXT): {$(VPATH)}oniguruma.h
@ -9865,6 +9866,7 @@ mjit_compile.$(OBJEXT): {$(VPATH)}missing.h
mjit_compile.$(OBJEXT): {$(VPATH)}mjit.h
mjit_compile.$(OBJEXT): {$(VPATH)}mjit_compile.c
mjit_compile.$(OBJEXT): {$(VPATH)}mjit_compile.inc
mjit_compile.$(OBJEXT): {$(VPATH)}mjit_unit.h
mjit_compile.$(OBJEXT): {$(VPATH)}node.h
mjit_compile.$(OBJEXT): {$(VPATH)}ruby_assert.h
mjit_compile.$(OBJEXT): {$(VPATH)}ruby_atomic.h

31
mjit.c
View file

@ -87,6 +87,7 @@
#include "vm_core.h"
#include "vm_callinfo.h"
#include "mjit.h"
#include "mjit_unit.h"
#include "gc.h"
#include "ruby_assert.h"
#include "ruby/debug.h"
@ -149,29 +150,6 @@ typedef intptr_t pid_t;
# define USE_JIT_COMPACTION 1
#endif
// The unit structure that holds metadata of ISeq for MJIT.
struct rb_mjit_unit {
struct ccan_list_node unode;
// Unique order number of unit.
int id;
// Dlopen handle of the loaded object file.
void *handle;
rb_iseq_t *iseq;
#if defined(_WIN32)
// DLL cannot be removed while loaded on Windows. If this is set, it'll be lazily deleted.
char *so_file;
#endif
// Only used by unload_units. Flag to check this unit is currently on stack or not.
bool used_code_p;
// True if it's a unit for JIT compaction
bool compact_p;
// mjit_compile's optimization switches
struct rb_mjit_compile_info compile_info;
// captured CC values, they should be marked with iseq.
const struct rb_callcache **cc_entries;
unsigned int cc_entries_size; // ISEQ_BODY(iseq)->ci_size + ones of inlined iseqs
};
// Linked list of struct rb_mjit_unit.
struct rb_mjit_unit_list {
struct ccan_list_head head;
@ -1138,13 +1116,6 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
}
#endif
// To see cc_entries using index returned by `mjit_capture_cc_entries` in mjit_compile.c
const struct rb_callcache **
mjit_iseq_cc_entries(const struct rb_iseq_constant_body *const body)
{
return body->jit_unit->cc_entries;
}
// Capture cc entries of `captured_iseq` and append them to `compiled_iseq->jit_unit->cc_entries`.
// This is needed when `captured_iseq` is inlined by `compiled_iseq` and GC needs to mark inlined cc.
//

View file

@ -20,6 +20,7 @@
#include "internal/object.h"
#include "internal/variable.h"
#include "mjit.h"
#include "mjit_unit.h"
#include "vm_core.h"
#include "vm_callinfo.h"
#include "vm_exec.h"
@ -87,8 +88,6 @@ call_data_index(CALL_DATA cd, const struct rb_iseq_constant_body *body)
return cd - body->call_data;
}
const struct rb_callcache ** mjit_iseq_cc_entries(const struct rb_iseq_constant_body *const body);
// Using this function to refer to cc_entries allocated by `mjit_capture_cc_entries`
// instead of storing cc_entries in status directly so that we always refer to a new address
// returned by `realloc` inside it.
@ -96,7 +95,7 @@ static const struct rb_callcache **
captured_cc_entries(const struct compile_status *status)
{
VM_ASSERT(status->cc_entries_index != -1);
return mjit_iseq_cc_entries(status->compiled_iseq) + status->cc_entries_index;
return status->compiled_iseq->jit_unit->cc_entries + status->cc_entries_index;
}
// Returns true if call cache is still not obsoleted and vm_cc_cme(cc)->def->type is available.

29
mjit_unit.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef INTERNAL_MJIT_H
#define INTERNAL_MJIT_H
#include "ccan/list/list.h"
// The unit structure that holds metadata of ISeq for MJIT.
struct rb_mjit_unit {
struct ccan_list_node unode;
// Unique order number of unit.
int id;
// Dlopen handle of the loaded object file.
void *handle;
rb_iseq_t *iseq;
#if defined(_WIN32)
// DLL cannot be removed while loaded on Windows. If this is set, it'll be lazily deleted.
char *so_file;
#endif
// Only used by unload_units. Flag to check this unit is currently on stack or not.
bool used_code_p;
// True if it's a unit for JIT compaction
bool compact_p;
// mjit_compile's optimization switches
struct rb_mjit_compile_info compile_info;
// captured CC values, they should be marked with iseq.
const struct rb_callcache **cc_entries;
unsigned int cc_entries_size; // ISEQ_BODY(iseq)->ci_size + ones of inlined iseqs
};
#endif /* INTERNAL_MJIT_H */