Skip to content

Commit 5e077a1

Browse files
committed
asm: snapshot x86 CNEW ctype metadata
1 parent c37182d commit 5e077a1

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# x86 ASM CNEW CType Snapshot
2+
3+
`asm_cnew()` now reconstructs `CNEW`/`CNEWI` allocation metadata through
4+
`lj_ctype_info_predefined()` or the sequence-checked
5+
`lj_ctype_info_snapshot()` helper instead of calling the live `lj_ctype_info()`
6+
walker during backend assembly.
7+
8+
The x64 allocation code still receives the same size and alignment bits when
9+
the ctype table is stable. If a parser publish is active or the snapshot races
10+
ctype table growth, assembly aborts with `CTBUSY` and the interpreter can retry
11+
later rather than assembling allocation code from a stale `CType *`.
12+
13+
Validation:
14+
15+
- `make -C src -j$(nproc) TARGET_STRIP=:`
16+
- `tools/ci/lua_test.sh m7_ffi_jit_cnew`
17+
- `tools/ci/lua_test.sh m7_ffi_typeinfo_snapshot`

src/lj_asm_x86.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3011,7 +3011,14 @@ static void asm_cnew(ASMState *as, IRIns *ir)
30113011
CTState *cts = ctype_ctsG(J2G(as->J));
30123012
CTypeID id = (CTypeID)IR(ir->op1)->i;
30133013
CTSize sz;
3014-
CTInfo info = lj_ctype_info(cts, id, &sz);
3014+
CTInfo info;
3015+
int ok = lj_ctype_info_predefined(cts, id, &info, &sz, NULL, NULL);
3016+
if (ok <= 0)
3017+
ok = lj_ctype_info_snapshot(cts, id, &info, &sz, NULL, NULL);
3018+
if (ok < 0)
3019+
lj_trace_err(as->J, LJ_TRERR_CTBUSY);
3020+
if (!ok)
3021+
lj_trace_err(as->J, LJ_TRERR_BADTYPE);
30153022
const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_cdata_new_forjit];
30163023
IRRef args[4];
30173024
lj_assertA(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL),

0 commit comments

Comments
 (0)