aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2010-02-10 21:45:57 +0100
committerMike Pall <mike>2010-02-10 21:45:57 +0100
commitbb0384c36628c94a2232955e0cac5cf45679039f (patch)
treed13f58838029a49fc1f7117ff9a78defc4c7fd0e /src
parentd5a46621f9d1299a7e5c06c59dfc02d61dc04a79 (diff)
downloadluajit-bb0384c36628c94a2232955e0cac5cf45679039f.tar.gz
luajit-bb0384c36628c94a2232955e0cac5cf45679039f.tar.bz2
luajit-bb0384c36628c94a2232955e0cac5cf45679039f.zip
Replace GCproto reference with bytecode PC in GCfuncL.
Diffstat (limited to 'src')
-rw-r--r--src/buildvm_x86.dasc51
-rw-r--r--src/lj_func.c6
-rw-r--r--src/lj_obj.h5
3 files changed, 32 insertions, 30 deletions
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc
index e09c37e9..90d80dbf 100644
--- a/src/buildvm_x86.dasc
+++ b/src/buildvm_x86.dasc
@@ -305,6 +305,8 @@
305#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) 305#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
306#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) 306#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
307| 307|
308#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
309|
308|// Decrement hashed hotcount and trigger trace recorder if zero. 310|// Decrement hashed hotcount and trigger trace recorder if zero.
309|.macro hotloop, reg 311|.macro hotloop, reg
310| mov reg, PC 312| mov reg, PC
@@ -406,11 +408,10 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
406 | // RA = new base, RB = LFUNC, RC = nargs+1, (BASE = old base), PC = return 408 | // RA = new base, RB = LFUNC, RC = nargs+1, (BASE = old base), PC = return
407 | // DISPATCH initialized 409 | // DISPATCH initialized
408 | mov BASE, RA 410 | mov BASE, RA
409 | mov PROTO:RB, LFUNC:RB->pt
410 | mov [BASE-4], PC // Store caller PC. 411 | mov [BASE-4], PC // Store caller PC.
411 | movzx RA, byte PROTO:RB->framesize 412 | mov PC, LFUNC:RB->pc
412 | lea PC, [PROTO:RB+sizeof(GCproto)] 413 | movzx RA, byte [PC+PC2PROTO(framesize)]
413 | mov KBASE, PROTO:RB->k 414 | mov KBASE, [PC+PC2PROTO(k)]
414 | mov L:RB, SAVE_L 415 | mov L:RB, SAVE_L
415 | lea RA, [BASE+RA*8] // Top of frame. 416 | lea RA, [BASE+RA*8] // Top of frame.
416 | lea RC, [BASE+NARGS:RC*8-4] // Points to tag of 1st free slot. 417 | lea RC, [BASE+NARGS:RC*8-4] // Points to tag of 1st free slot.
@@ -437,16 +438,16 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
437 | lea PC, [NARGS:RC*8+FRAME_VARG] 438 | lea PC, [NARGS:RC*8+FRAME_VARG]
438 | lea BASE, [RA+PC-FRAME_VARG] 439 | lea BASE, [RA+PC-FRAME_VARG]
439 | mov [BASE-8], LFUNC:RB // Store copy of LFUNC. 440 | mov [BASE-8], LFUNC:RB // Store copy of LFUNC.
440 | mov PROTO:RB, LFUNC:RB->pt
441 | mov [BASE-4], PC // Store delta + FRAME_VARG. 441 | mov [BASE-4], PC // Store delta + FRAME_VARG.
442 | movzx PC, byte PROTO:RB->framesize 442 | mov PC, LFUNC:RB->pc
443 | lea KBASE, [BASE+PC*8] 443 | movzx RB, byte [PC+PC2PROTO(framesize)]
444 | mov L:PC, SAVE_L 444 | lea KBASE, [BASE+RB*8]
445 | mov L:RB, SAVE_L
445 | lea RC, [BASE+4] 446 | lea RC, [BASE+4]
446 | cmp KBASE, L:PC->maxstack 447 | cmp KBASE, L:RB->maxstack
447 | ja ->gate_lv_growstack // Need to grow stack. 448 | ja ->gate_lv_growstack // Need to grow stack.
448 | movzx PC, byte PROTO:RB->numparams 449 | movzx RB, byte [PC+PC2PROTO(numparams)]
449 | test PC, PC 450 | test RB, RB
450 | jz >2 451 | jz >2
451 |1: // Copy fixarg slots up. 452 |1: // Copy fixarg slots up.
452 | add RA, 8 453 | add RA, 8
@@ -458,12 +459,11 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
458 | mov [RC], KBASE 459 | mov [RC], KBASE
459 | add RC, 8 460 | add RC, 8
460 | mov dword [RA-4], LJ_TNIL // Clear old fixarg slot (help the GC). 461 | mov dword [RA-4], LJ_TNIL // Clear old fixarg slot (help the GC).
461 | sub PC, 1 462 | sub RB, 1
462 | jnz <1 463 | jnz <1
463 |2: 464 |2:
464 | movzx RA, byte PROTO:RB->framesize 465 | movzx RA, byte [PC+PC2PROTO(framesize)]
465 | lea PC, [PROTO:RB+sizeof(GCproto)] 466 | mov KBASE, [PC+PC2PROTO(k)]
466 | mov KBASE, PROTO:RB->k
467 | lea RA, [BASE+RA*8] 467 | lea RA, [BASE+RA*8]
468 | jmp <9 468 | jmp <9
469 | 469 |
@@ -663,6 +663,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
663 | jmp >1 663 | jmp >1
664 | 664 |
665 |->gate_lv_growstack: // Grow stack for vararg Lua function. 665 |->gate_lv_growstack: // Grow stack for vararg Lua function.
666 //XXX
666 | sub RC, 8 667 | sub RC, 8
667 | mov BASE, RA 668 | mov BASE, RA
668 | mov RA, KBASE 669 | mov RA, KBASE
@@ -863,8 +864,8 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
863 | mov RA, dword [RB-16] 864 | mov RA, dword [RB-16]
864 |.endif 865 |.endif
865 | mov LFUNC:KBASE, [BASE-8] 866 | mov LFUNC:KBASE, [BASE-8]
866 | mov PROTO:KBASE, LFUNC:KBASE->pt 867 | mov KBASE, LFUNC:KBASE->pc
867 | mov KBASE, PROTO:KBASE->k 868 | mov KBASE, [KBASE+PC2PROTO(k)]
868 | // BASE = base, RC = result, RB = meta base 869 | // BASE = base, RC = result, RB = meta base
869 | jmp RAa // Jump to continuation. 870 | jmp RAa // Jump to continuation.
870 | 871 |
@@ -2719,8 +2720,8 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
2719 |->vm_exit_interp: 2720 |->vm_exit_interp:
2720#if LJ_HASJIT 2721#if LJ_HASJIT
2721 | mov LFUNC:KBASE, [BASE-8] 2722 | mov LFUNC:KBASE, [BASE-8]
2722 | mov PROTO:KBASE, LFUNC:KBASE->pt 2723 | mov KBASE, LFUNC:KBASE->pc
2723 | mov KBASE, PROTO:KBASE->k 2724 | mov KBASE, [KBASE+PC2PROTO(k)]
2724 | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0 2725 | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0
2725 | set_vmstate INTERP 2726 | set_vmstate INTERP
2726 | ins_next 2727 | ins_next
@@ -4454,8 +4455,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
4454 | not RDa 4455 | not RDa
4455 | lea BASE, [BASE+RD*8] 4456 | lea BASE, [BASE+RD*8]
4456 | mov LFUNC:KBASE, [BASE-8] 4457 | mov LFUNC:KBASE, [BASE-8]
4457 | mov PROTO:KBASE, LFUNC:KBASE->pt 4458 | mov KBASE, LFUNC:KBASE->pc
4458 | mov KBASE, PROTO:KBASE->k 4459 | mov KBASE, [KBASE+PC2PROTO(k)]
4459 | jmp <4 4460 | jmp <4
4460 | 4461 |
4461 |7: // Tailcall from a vararg function. 4462 |7: // Tailcall from a vararg function.
@@ -4492,8 +4493,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
4492 | ins_AB_ // RA = base, RB = nresults+1, (RC = 1) 4493 | ins_AB_ // RA = base, RB = nresults+1, (RC = 1)
4493 | mov LFUNC:RC, [BASE-8] 4494 | mov LFUNC:RC, [BASE-8]
4494 | lea RA, [BASE+RA*8] 4495 | lea RA, [BASE+RA*8]
4495 | mov PROTO:RC, LFUNC:RC->pt 4496 | mov RC, LFUNC:RC->pc
4496 | movzx RC, byte PROTO:RC->numparams 4497 | movzx RC, byte [RC+PC2PROTO(numparams)]
4497 | mov TMP1, KBASE // Need one more free register. 4498 | mov TMP1, KBASE // Need one more free register.
4498 | lea KBASE, [BASE+RC*8+(8+FRAME_VARG)] 4499 | lea KBASE, [BASE+RC*8+(8+FRAME_VARG)]
4499 | sub KBASE, [BASE-4] 4500 | sub KBASE, [BASE-4]
@@ -4618,8 +4619,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
4618 | not RAa // Note: ~RA = -(RA+1) 4619 | not RAa // Note: ~RA = -(RA+1)
4619 | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8 4620 | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8
4620 | mov LFUNC:KBASE, [BASE-8] 4621 | mov LFUNC:KBASE, [BASE-8]
4621 | mov PROTO:KBASE, LFUNC:KBASE->pt 4622 | mov KBASE, LFUNC:KBASE->pc
4622 | mov KBASE, PROTO:KBASE->k 4623 | mov KBASE, [KBASE+PC2PROTO(k)]
4623 | ins_next 4624 | ins_next
4624 | 4625 |
4625 |6: // Fill up results with nil. 4626 |6: // Fill up results with nil.
diff --git a/src/lj_func.c b/src/lj_func.c
index adc8c039..7d130176 100644
--- a/src/lj_func.c
+++ b/src/lj_func.c
@@ -112,8 +112,8 @@ GCfunc *lj_func_newL(lua_State *L, GCproto *pt, GCtab *env)
112 fn->l.gct = ~LJ_TFUNC; 112 fn->l.gct = ~LJ_TFUNC;
113 fn->l.ffid = FF_LUA; 113 fn->l.ffid = FF_LUA;
114 fn->l.nupvalues = cast_byte(pt->sizeuv); 114 fn->l.nupvalues = cast_byte(pt->sizeuv);
115 /* NOBARRIER: The GCfunc is new (marked white). */ 115 /* NOBARRIER: Really a setgcref. But the GCfunc is new (marked white). */
116 setgcref(fn->l.pt, obj2gco(pt)); 116 setmref(fn->l.pc, proto_bc(pt));
117 setgcref(fn->l.env, obj2gco(env)); 117 setgcref(fn->l.env, obj2gco(env));
118 fn->l.gate = (pt->flags & PROTO_IS_VARARG) ? lj_gate_lv : lj_gate_lf; 118 fn->l.gate = (pt->flags & PROTO_IS_VARARG) ? lj_gate_lv : lj_gate_lf;
119 return fn; 119 return fn;
@@ -137,7 +137,7 @@ GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent)
137 GCupval *uv; 137 GCupval *uv;
138 if ((v & 0x8000)) { 138 if ((v & 0x8000)) {
139 uv = func_finduv(L, base + (v & 0xff)); 139 uv = func_finduv(L, base + (v & 0xff));
140 uv->dhash = (uint32_t)(uintptr_t)gcref(parent->pt) ^ (v << 24); 140 uv->dhash = (uint32_t)(uintptr_t)mref(parent->pc, char) ^ (v << 24);
141 } else { 141 } else {
142 uv = &gcref(puv[v])->uv; 142 uv = &gcref(puv[v])->uv;
143 } 143 }
diff --git a/src/lj_obj.h b/src/lj_obj.h
index f243a75b..a6637954 100644
--- a/src/lj_obj.h
+++ b/src/lj_obj.h
@@ -429,7 +429,7 @@ typedef struct GCfuncC {
429 429
430typedef struct GCfuncL { 430typedef struct GCfuncL {
431 GCfuncHeader; 431 GCfuncHeader;
432 GCRef pt; /* Link to prototype this function is based on. */ 432 MRef pc; /* Start PC (and GCproto reference). */
433 GCRef uvptr[1]; /* Array of _pointers_ to upvalue objects (GCupval). */ 433 GCRef uvptr[1]; /* Array of _pointers_ to upvalue objects (GCupval). */
434} GCfuncL; 434} GCfuncL;
435 435
@@ -443,7 +443,8 @@ typedef union GCfunc {
443#define isluafunc(fn) ((fn)->c.ffid == FF_LUA) 443#define isluafunc(fn) ((fn)->c.ffid == FF_LUA)
444#define iscfunc(fn) ((fn)->c.ffid == FF_C) 444#define iscfunc(fn) ((fn)->c.ffid == FF_C)
445#define isffunc(fn) ((fn)->c.ffid > FF_C) 445#define isffunc(fn) ((fn)->c.ffid > FF_C)
446#define funcproto(fn) check_exp(isluafunc(fn), &gcref((fn)->l.pt)->pt) 446#define funcproto(fn) \
447 check_exp(isluafunc(fn), (GCproto *)(mref((fn)->l.pc, char)-sizeof(GCproto)))
447#define sizeCfunc(n) (sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n)) 448#define sizeCfunc(n) (sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n))
448#define sizeLfunc(n) (sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n)) 449#define sizeLfunc(n) (sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n))
449 450