Skip to content

Commit 6c2cad8

Browse files
committed
MJIT: Share rb_mjit_unit through mjit_unit.h
mjit_compile.c should be able to access this more easily.
1 parent ed8c21b commit 6c2cad8

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

common.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9658,6 +9658,7 @@ mjit.$(OBJEXT): {$(VPATH)}mjit.h
96589658
mjit.$(OBJEXT): {$(VPATH)}mjit.rb
96599659
mjit.$(OBJEXT): {$(VPATH)}mjit.rbinc
96609660
mjit.$(OBJEXT): {$(VPATH)}mjit_config.h
9661+
mjit.$(OBJEXT): {$(VPATH)}mjit_unit.h
96619662
mjit.$(OBJEXT): {$(VPATH)}node.h
96629663
mjit.$(OBJEXT): {$(VPATH)}onigmo.h
96639664
mjit.$(OBJEXT): {$(VPATH)}oniguruma.h
@@ -9865,6 +9866,7 @@ mjit_compile.$(OBJEXT): {$(VPATH)}missing.h
98659866
mjit_compile.$(OBJEXT): {$(VPATH)}mjit.h
98669867
mjit_compile.$(OBJEXT): {$(VPATH)}mjit_compile.c
98679868
mjit_compile.$(OBJEXT): {$(VPATH)}mjit_compile.inc
9869+
mjit_compile.$(OBJEXT): {$(VPATH)}mjit_unit.h
98689870
mjit_compile.$(OBJEXT): {$(VPATH)}node.h
98699871
mjit_compile.$(OBJEXT): {$(VPATH)}ruby_assert.h
98709872
mjit_compile.$(OBJEXT): {$(VPATH)}ruby_atomic.h

mjit.c

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
#include "vm_core.h"
8888
#include "vm_callinfo.h"
8989
#include "mjit.h"
90+
#include "mjit_unit.h"
9091
#include "gc.h"
9192
#include "ruby_assert.h"
9293
#include "ruby/debug.h"
@@ -149,29 +150,6 @@ typedef intptr_t pid_t;
149150
# define USE_JIT_COMPACTION 1
150151
#endif
151152

152-
// The unit structure that holds metadata of ISeq for MJIT.
153-
struct rb_mjit_unit {
154-
struct ccan_list_node unode;
155-
// Unique order number of unit.
156-
int id;
157-
// Dlopen handle of the loaded object file.
158-
void *handle;
159-
rb_iseq_t *iseq;
160-
#if defined(_WIN32)
161-
// DLL cannot be removed while loaded on Windows. If this is set, it'll be lazily deleted.
162-
char *so_file;
163-
#endif
164-
// Only used by unload_units. Flag to check this unit is currently on stack or not.
165-
bool used_code_p;
166-
// True if it's a unit for JIT compaction
167-
bool compact_p;
168-
// mjit_compile's optimization switches
169-
struct rb_mjit_compile_info compile_info;
170-
// captured CC values, they should be marked with iseq.
171-
const struct rb_callcache **cc_entries;
172-
unsigned int cc_entries_size; // ISEQ_BODY(iseq)->ci_size + ones of inlined iseqs
173-
};
174-
175153
// Linked list of struct rb_mjit_unit.
176154
struct rb_mjit_unit_list {
177155
struct ccan_list_head head;
@@ -1138,13 +1116,6 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
11381116
}
11391117
#endif
11401118

1141-
// To see cc_entries using index returned by `mjit_capture_cc_entries` in mjit_compile.c
1142-
const struct rb_callcache **
1143-
mjit_iseq_cc_entries(const struct rb_iseq_constant_body *const body)
1144-
{
1145-
return body->jit_unit->cc_entries;
1146-
}
1147-
11481119
// Capture cc entries of `captured_iseq` and append them to `compiled_iseq->jit_unit->cc_entries`.
11491120
// This is needed when `captured_iseq` is inlined by `compiled_iseq` and GC needs to mark inlined cc.
11501121
//

mjit_compile.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "internal/object.h"
2121
#include "internal/variable.h"
2222
#include "mjit.h"
23+
#include "mjit_unit.h"
2324
#include "vm_core.h"
2425
#include "vm_callinfo.h"
2526
#include "vm_exec.h"
@@ -87,16 +88,14 @@ call_data_index(CALL_DATA cd, const struct rb_iseq_constant_body *body)
8788
return cd - body->call_data;
8889
}
8990

90-
const struct rb_callcache ** mjit_iseq_cc_entries(const struct rb_iseq_constant_body *const body);
91-
9291
// Using this function to refer to cc_entries allocated by `mjit_capture_cc_entries`
9392
// instead of storing cc_entries in status directly so that we always refer to a new address
9493
// returned by `realloc` inside it.
9594
static const struct rb_callcache **
9695
captured_cc_entries(const struct compile_status *status)
9796
{
9897
VM_ASSERT(status->cc_entries_index != -1);
99-
return mjit_iseq_cc_entries(status->compiled_iseq) + status->cc_entries_index;
98+
return status->compiled_iseq->jit_unit->cc_entries + status->cc_entries_index;
10099
}
101100

102101
// Returns true if call cache is still not obsoleted and vm_cc_cme(cc)->def->type is available.

mjit_unit.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef INTERNAL_MJIT_H
2+
#define INTERNAL_MJIT_H
3+
4+
#include "ccan/list/list.h"
5+
6+
// The unit structure that holds metadata of ISeq for MJIT.
7+
struct rb_mjit_unit {
8+
struct ccan_list_node unode;
9+
// Unique order number of unit.
10+
int id;
11+
// Dlopen handle of the loaded object file.
12+
void *handle;
13+
rb_iseq_t *iseq;
14+
#if defined(_WIN32)
15+
// DLL cannot be removed while loaded on Windows. If this is set, it'll be lazily deleted.
16+
char *so_file;
17+
#endif
18+
// Only used by unload_units. Flag to check this unit is currently on stack or not.
19+
bool used_code_p;
20+
// True if it's a unit for JIT compaction
21+
bool compact_p;
22+
// mjit_compile's optimization switches
23+
struct rb_mjit_compile_info compile_info;
24+
// captured CC values, they should be marked with iseq.
25+
const struct rb_callcache **cc_entries;
26+
unsigned int cc_entries_size; // ISEQ_BODY(iseq)->ci_size + ones of inlined iseqs
27+
};
28+
29+
#endif /* INTERNAL_MJIT_H */

0 commit comments

Comments
 (0)