Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0cc73ca

Browse files
maximecbXrXr
authored andcommitted
Malloc branch entries (#112)
* Malloc branch entries * Add ASM comment for stack overflow check * WIP * Fix branch GC code. Add rb_darray_remove_unordered(). * Fix block end_pos after branch rewriting. Remove dst_patched bits.
1 parent 33c975b commit 0cc73ca

File tree

5 files changed

+176
-152
lines changed

5 files changed

+176
-152
lines changed

darray.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,20 @@
5151
1 \
5252
) : 0)
5353

54+
// Last element of the array
55+
//
56+
#define rb_darray_back(ary) ((ary)->data[(ary)->meta.size - 1])
57+
5458
// Remove the last element of the array.
5559
//
5660
#define rb_darray_pop_back(ary) ((ary)->meta.size--)
5761

62+
// Remove element at idx and replace it by the last element
63+
#define rb_darray_remove_unordered(ary, idx) do { \
64+
rb_darray_set(ary, idx, rb_darray_back(ary)); \
65+
rb_darray_pop_back(ary); \
66+
} while (0);
67+
5868
// Iterate over items of the array in a for loop
5969
//
6070
#define rb_darray_foreach(ary, idx_name, elem_ptr_var) \

yjit_codegen.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ jit_jump_to_next_insn(jitstate_t *jit, const ctx_t *current_context)
301301

302302
// Generate the jump instruction
303303
gen_direct_jump(
304+
jit->block,
304305
&reset_depth,
305306
jump_block
306307
);
@@ -722,6 +723,7 @@ jit_chain_guard(enum jcc_kinds jcc, jitstate_t *jit, const ctx_t *ctx, uint8_t d
722723
deeper.chain_depth++;
723724

724725
gen_branch(
726+
jit->block,
725727
ctx,
726728
(blockid_t) { jit->iseq, jit->insn_idx },
727729
&deeper,
@@ -1334,6 +1336,7 @@ gen_branchif(jitstate_t* jit, ctx_t* ctx)
13341336

13351337
// Generate the branch instructions
13361338
gen_branch(
1339+
jit->block,
13371340
ctx,
13381341
jump_block,
13391342
ctx,
@@ -1387,6 +1390,7 @@ gen_branchunless(jitstate_t* jit, ctx_t* ctx)
13871390

13881391
// Generate the branch instructions
13891392
gen_branch(
1393+
jit->block,
13901394
ctx,
13911395
jump_block,
13921396
ctx,
@@ -1412,6 +1416,7 @@ gen_jump(jitstate_t* jit, ctx_t* ctx)
14121416

14131417
// Generate the jump instruction
14141418
gen_direct_jump(
1419+
jit->block,
14151420
ctx,
14161421
jump_block
14171422
);
@@ -1726,6 +1731,7 @@ gen_oswb_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
17261731

17271732
// Stack overflow check
17281733
// #define CHECK_VM_STACK_OVERFLOW0(cfp, sp, margin)
1734+
ADD_COMMENT(cb, "stack overflow check");
17291735
lea(cb, REG0, ctx_sp_opnd(ctx, sizeof(VALUE) * (num_locals + iseq->body->stack_max) + sizeof(rb_control_frame_t)));
17301736
cmp(cb, REG_CFP, REG0);
17311737
jle_ptr(cb, COUNTED_EXIT(side_exit, oswb_se_cf_overflow));
@@ -1802,6 +1808,7 @@ gen_oswb_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
18021808

18031809
// Write the JIT return address on the callee frame
18041810
gen_branch(
1811+
jit->block,
18051812
ctx,
18061813
return_block,
18071814
&return_ctx,
@@ -1818,6 +1825,7 @@ gen_oswb_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
18181825

18191826
// Directly jump to the entry point of the callee
18201827
gen_direct_jump(
1828+
jit->block,
18211829
&callee_ctx,
18221830
(blockid_t){ iseq, 0 }
18231831
);
@@ -2049,6 +2057,7 @@ gen_opt_getinlinecache(jitstate_t *jit, ctx_t *ctx)
20492057
// Jump over the code for filling the cache
20502058
uint32_t jump_idx = jit_next_insn_idx(jit) + (int32_t)jump_offset;
20512059
gen_direct_jump(
2060+
jit->block,
20522061
ctx,
20532062
(blockid_t){ .iseq = jit->iseq, .idx = jump_idx }
20542063
);

0 commit comments

Comments
 (0)