Skip to content

Commit

Permalink
kernel: move BottomLVars out of TLS
Browse files Browse the repository at this point in the history
A single global BottomLVars shared by all TLS suffices. Note that really only
the address stored in BottomLVars matters, the actual object behind it is
essentially never accessed.
  • Loading branch information
fingolfin authored and ChrisJefferson committed Sep 30, 2020
1 parent 3898420 commit dc28742
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/gapstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ typedef struct GAPState {
Obj CurrNamespace;

/* From vars.c */
Bag BottomLVars;
Bag CurrLVars;
Obj * PtrLVars;
Bag LVarsPool[16];
Expand Down
38 changes: 20 additions & 18 deletions src/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
** have to check for the bottom, slowing it down.
**
*/
/* TL: Bag BottomLVars; */
static Bag BottomLVars;


/****************************************************************************
Expand Down Expand Up @@ -1992,7 +1992,7 @@ static Obj FuncGetCurrentLVars(Obj self)

static Obj FuncGetBottomLVars(Obj self)
{
return STATE(BottomLVars);
return BottomLVars;
}

static Obj FuncParentLVars(Obj self, Obj lvars)
Expand Down Expand Up @@ -2043,7 +2043,7 @@ static Obj FuncENVI_FUNC(Obj self, Obj func)
*/
BOOL IsBottomLVars(Obj lvars)
{
return lvars == STATE(BottomLVars);
return lvars == BottomLVars;
}


Expand All @@ -2053,7 +2053,7 @@ BOOL IsBottomLVars(Obj lvars)
*/
Obj SWITCH_TO_BOTTOM_LVARS(void)
{
return SWITCH_TO_OLD_LVARS(STATE(BottomLVars));
return SWITCH_TO_OLD_LVARS(BottomLVars);
}


Expand Down Expand Up @@ -2178,7 +2178,7 @@ static Int InitKernel (
{
/* make 'CurrLVars' known to Gasman */
InitGlobalBag( &STATE(CurrLVars), "src/vars.c:CurrLVars" );
InitGlobalBag( &STATE(BottomLVars), "src/vars.c:BottomLVars" );
InitGlobalBag( &BottomLVars, "src/vars.c:BottomLVars" );

enum { count = ARRAY_SIZE(STATE(LVarsPool)) };
static char cookies[count][24];
Expand Down Expand Up @@ -2342,7 +2342,7 @@ static Int InitKernel (
static Int PostRestore (
StructInitInfo * module )
{
STATE(CurrLVars) = STATE(BottomLVars);
STATE(CurrLVars) = BottomLVars;
SWITCH_TO_BOTTOM_LVARS();

return 0;
Expand All @@ -2355,29 +2355,31 @@ static Int PostRestore (
*/
static Int InitLibrary (
StructInitInfo * module )
{
/* init filters and functions */
InitGVarFuncsFromTable( GVarFuncs );

return 0;
}


static Int InitModuleState(void)
{
Obj tmpFunc, tmpBody;

STATE(BottomLVars) = NewBag(T_HVARS, 3 * sizeof(Obj));
BottomLVars = NewBag(T_HVARS, 3 * sizeof(Obj));
tmpFunc = NewFunctionC( "bottom", 0, "", 0 );

LVarsHeader * hdr = (LVarsHeader *)ADDR_OBJ(STATE(BottomLVars));
LVarsHeader * hdr = (LVarsHeader *)ADDR_OBJ(BottomLVars);
hdr->func = tmpFunc;
hdr->parent = Fail;
tmpBody = NewFunctionBody();
SET_BODY_FUNC( tmpFunc, tmpBody );

STATE(CurrLVars) = STATE(BottomLVars);
/* init filters and functions */
InitGVarFuncsFromTable( GVarFuncs );

return PostRestore(module);
}


static Int InitModuleState(void)
{
#ifdef HPCGAP
STATE(CurrLVars) = BottomLVars;
SWITCH_TO_BOTTOM_LVARS();
#endif

return 0;
}
Expand Down
15 changes: 1 addition & 14 deletions src/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,7 @@

/****************************************************************************
**
*V BottomLVars . . . . . . . . . . . . . . . . . bottom local variables bag
**
** 'BottomLVars' is the local variables bag at the bottom of the call stack.
** Without such a dummy frame at the bottom, 'SWITCH_TO_NEW_LVARS' would
** have to check for the bottom, slowing it down.
**
*/
/* TL: extern Bag BottomLVars; */


/****************************************************************************
**
*F IsBottomLVars(<lvars>) . . check whether some lvars are the bottom lvars
**
*F IsBottomLVars(<lvars>) . . test whether lvars is at the call stack bottom
*/
BOOL IsBottomLVars(Obj lvars);

Expand Down

0 comments on commit dc28742

Please sign in to comment.