summaryrefslogtreecommitdiff
path: root/src/lj_record.c
diff options
context:
space:
mode:
authorMike Pall <mike>2010-02-22 17:37:26 +0100
committerMike Pall <mike>2010-02-22 17:37:26 +0100
commit659ea9de7b1b272454e76a8b7fb1b5ba980dee3e (patch)
tree62f1f3af8d98df6cac66f726ea140d6a4bb33912 /src/lj_record.c
parent3336434aa009c60d38716d7c9ec083297192a224 (diff)
downloadluajit-659ea9de7b1b272454e76a8b7fb1b5ba980dee3e.tar.gz
luajit-659ea9de7b1b272454e76a8b7fb1b5ba980dee3e.tar.bz2
luajit-659ea9de7b1b272454e76a8b7fb1b5ba980dee3e.zip
Ensure function and all args have a reference for call recording.
In practice this is only needed after a return to a lower frame.
Diffstat (limited to 'src/lj_record.c')
-rw-r--r--src/lj_record.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/lj_record.c b/src/lj_record.c
index 1d72f933..2b63b87d 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -479,9 +479,10 @@ static void rec_call_setup(jit_State *J, BCReg func, ptrdiff_t nargs)
479 RecordIndex ix; 479 RecordIndex ix;
480 TValue *functv = &J->L->base[func]; 480 TValue *functv = &J->L->base[func];
481 TRef trfunc, *fbase = &J->base[func]; 481 TRef trfunc, *fbase = &J->base[func];
482 482 ptrdiff_t i;
483 for (i = 0; i <= nargs; i++)
484 getslot(J, func+i); /* Ensure func and all args have a reference. */
483 if (!tref_isfunc(fbase[0])) { /* Resolve __call metamethod. */ 485 if (!tref_isfunc(fbase[0])) { /* Resolve __call metamethod. */
484 ptrdiff_t i;
485 ix.tab = fbase[0]; 486 ix.tab = fbase[0];
486 copyTV(J->L, &ix.tabv, functv); 487 copyTV(J->L, &ix.tabv, functv);
487 if (!rec_mm_lookup(J, &ix, MM_call) || !tref_isfunc(ix.mobj)) 488 if (!rec_mm_lookup(J, &ix, MM_call) || !tref_isfunc(ix.mobj))
@@ -1019,15 +1020,29 @@ static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
1019 } 1020 }
1020} 1021}
1021 1022
1022/* -- Record calls to fast functions -------------------------------------- */ 1023/* -- Fast function recording handlers ------------------------------------ */
1023 1024
1024/* Note: The function and the arguments for the bytecode CALL instructions 1025/* Conventions for fast function call handlers:
1025** always occupy _new_ stack slots (above the highest active variable). 1026**
1026** This means they must have been stored there by previous instructions 1027** The argument slots start at J->base[0]. All of them are guaranteed to be
1027** (MOV, K*, ADD etc.) which must be part of the same trace. This in turn 1028** valid and type-specialized references. J->base[J->maxslot] is set to 0
1028** means their reference slots are already valid and their types have 1029** as a sentinel. The runtime argument values start at rd->argv[0].
1029** already been specialized (i.e. getslot() would be redundant). 1030**
1030** The 1st slot beyond the arguments is set to 0 before calling recff_*. 1031** In general fast functions should check for presence of all of their
1032** arguments and for the correct argument types. Some simplifications
1033** are allowed if the interpreter throws instead. But even if recording
1034** is aborted, the generated IR must be consistent (no zero-refs).
1035**
1036** The number of results in rd->nres is set to 1. Handlers that return
1037** a different number of results need to override it. A negative value
1038** prevents return processing (e.g. for pending calls).
1039**
1040** Results need to be stored starting at J->base[0]. Return processing
1041** moves them to the right slots later.
1042**
1043** The per-ffid auxiliary data is the value of the 2nd part of the
1044** LJLIB_REC() annotation. This allows handling similar functionality
1045** in a common handler.
1031*/ 1046*/
1032 1047
1033/* Data used by handlers to record a fast function. */ 1048/* Data used by handlers to record a fast function. */
@@ -1688,6 +1703,8 @@ static void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd)
1688 J->base[0] = TREF_TRUE; 1703 J->base[0] = TREF_TRUE;
1689} 1704}
1690 1705
1706/* -- Record calls to fast functions -------------------------------------- */
1707
1691#include "lj_recdef.h" 1708#include "lj_recdef.h"
1692 1709
1693static uint32_t recdef_lookup(GCfunc *fn) 1710static uint32_t recdef_lookup(GCfunc *fn)