Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel: use more accurate marking #2408

Merged
merged 8 commits into from
Apr 28, 2018
Merged
4 changes: 4 additions & 0 deletions src/boehm_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ void MarkAllSubBags(Bag bag)
{
}

void MarkAllButFirstSubBags(Bag bag)
{
}

void MarkArrayOfBags(const Bag array[], UInt count)
{
}
29 changes: 23 additions & 6 deletions src/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ Obj NewFunctionT (
SET_NAME_FUNC(func, ConvImmString(name));
SET_NARG_FUNC(func, narg);
SET_NAMS_FUNC(func, nams);
SET_NLOC_FUNC(func, 0);
if (nams) MakeBagPublic(nams);
CHANGED_BAG(func);

Expand Down Expand Up @@ -1547,6 +1548,7 @@ Obj FuncPROFILE_FUNC(
SET_NARG_FUNC(copy, NARG_FUNC(func));
SET_NAMS_FUNC(copy, NAMS_FUNC(func));
SET_PROF_FUNC(copy, PROF_FUNC(func));
SET_NLOC_FUNC(copy, NLOC_FUNC(func));
SET_HDLR_FUNC(func,0, DoProf0args);
SET_HDLR_FUNC(func,1, DoProf1args);
SET_HDLR_FUNC(func,2, DoProf2args);
Expand Down Expand Up @@ -1730,14 +1732,14 @@ static ObjFunc LoadHandler( void )
*/
void SaveFunction ( Obj func )
{
FuncBag * header = FUNC(func);
const FuncBag * header = CONST_FUNC(func);
for (UInt i = 0; i <= 7; i++)
SaveHandler(header->handlers[i]);
SaveSubObj(header->name);
SaveUInt(header->nargs);
SaveSubObj(header->nargs);
SaveSubObj(header->namesOfLocals);
SaveSubObj(header->prof);
SaveUInt(header->nloc);
SaveSubObj(header->nloc);
SaveSubObj(header->body);
SaveSubObj(header->envi);
SaveSubObj(header->fexs);
Expand All @@ -1756,10 +1758,10 @@ void LoadFunction ( Obj func )
for (UInt i = 0; i <= 7; i++)
header->handlers[i] = LoadHandler();
header->name = LoadSubObj();
header->nargs = LoadUInt();
header->nargs = LoadSubObj();
header->namesOfLocals = LoadSubObj();
header->prof = LoadSubObj();
header->nloc = LoadUInt();
header->nloc = LoadSubObj();
header->body = LoadSubObj();
header->envi = LoadSubObj();
header->fexs = LoadSubObj();
Expand All @@ -1769,6 +1771,21 @@ void LoadFunction ( Obj func )

#endif

/****************************************************************************
**
*F MarkFunctionSubBags( <bag> ) . . . . . . . marking function for functions
**
** 'MarkFunctionSubBags' is the marking function for bags of type 'T_FUNCTION'.
*/
void MarkFunctionSubBags(Obj func)
{
// the first eight slots are pointers to C functions, so we need
// to skip those for marking
UInt size = SIZE_BAG(func) / sizeof(Obj) - 8;
const Bag * data = CONST_PTR_BAG(func) + 8;
MarkArrayOfBags(data, size);
}


/****************************************************************************
**
Expand Down Expand Up @@ -1836,7 +1853,7 @@ static Int InitKernel (

/* install the marking functions */
InfoBags[ T_FUNCTION ].name = "function";
InitMarkFuncBags( T_FUNCTION , MarkAllSubBags );
InitMarkFuncBags(T_FUNCTION, MarkFunctionSubBags);

/* Allocate functions in the public region */
MakeBagTypePublic(T_FUNCTION);
Expand Down
12 changes: 6 additions & 6 deletions src/calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ typedef Obj (* ObjFunc_6ARGS) (Obj self, Obj a1, Obj a2, Obj a3, Obj a4, Obj a5,
typedef struct {
ObjFunc handlers[8];
Obj name;
Int nargs;
Obj nargs;
Obj namesOfLocals;
Obj prof;
UInt nloc;
Obj nloc;
Obj body;
Obj envi;
Obj fexs;
Expand Down Expand Up @@ -146,7 +146,7 @@ static inline Obj NAME_FUNC(Obj func)

static inline Int NARG_FUNC(Obj func)
{
return CONST_FUNC(func)->nargs;
return INT_INTOBJ(CONST_FUNC(func)->nargs);
}

static inline Obj NAMS_FUNC(Obj func)
Expand All @@ -163,7 +163,7 @@ static inline Obj PROF_FUNC(Obj func)

static inline UInt NLOC_FUNC(Obj func)
{
return CONST_FUNC(func)->nloc;
return INT_INTOBJ(CONST_FUNC(func)->nloc);
}

static inline Obj BODY_FUNC(Obj func)
Expand Down Expand Up @@ -199,7 +199,7 @@ extern void SET_NAME_FUNC(Obj func, Obj name);

static inline void SET_NARG_FUNC(Obj func, Int nargs)
{
FUNC(func)->nargs = nargs;
FUNC(func)->nargs = INTOBJ_INT(nargs);
}

static inline void SET_NAMS_FUNC(Obj func, Obj namesOfLocals)
Expand All @@ -214,7 +214,7 @@ static inline void SET_PROF_FUNC(Obj func, Obj prof)

static inline void SET_NLOC_FUNC(Obj func, UInt nloc)
{
FUNC(func)->nloc = nloc;
FUNC(func)->nloc = INTOBJ_INT(nloc);
}

static inline void SET_BODY_FUNC(Obj func, Obj body)
Expand Down
78 changes: 46 additions & 32 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

GAP_STATIC_ASSERT(sizeof(StatHeader) == 8, "StatHeader has wrong size");


static Obj TYPE_KERNEL_OBJECT;


/****************************************************************************
**
*V PtrBody . . . . . . . . . . . . . . . . . . . . . pointer to current body
Expand Down Expand Up @@ -294,24 +298,28 @@ Expr NewExpr (
** 'PopStat' returns the top statement from the statements stack and pops
** it. It is an error if the stack is empty.
*/
/* TL: Bag StackStat; */

/* TL: Int CountStat; */
static inline UInt CapacityStatStack(void)
{
return SIZE_BAG(STATE(StackStat))/sizeof(Stat) - 1;
}

static void PushStat (
Stat stat )
{
/* there must be a stack, it must not be underfull or overfull */
assert( STATE(StackStat) != 0 );
assert( 0 <= STATE(CountStat) );
assert( STATE(CountStat) <= SIZE_BAG(STATE(StackStat))/sizeof(Stat) );
assert( STATE(CountStat) <= CapacityStatStack() );
assert( stat != 0 );

/* count up and put the statement onto the stack */
if ( STATE(CountStat) == SIZE_BAG(STATE(StackStat))/sizeof(Stat) ) {
ResizeBag( STATE(StackStat), 2*STATE(CountStat)*sizeof(Stat) );
// count up and put the statement onto the stack
if ( STATE(CountStat) == CapacityStatStack() ) {
ResizeBag( STATE(StackStat), (2*STATE(CountStat) + 1)*sizeof(Stat) );
}
((Stat*)PTR_BAG(STATE(StackStat)))[STATE(CountStat)] = stat;

// put
Stat * data = (Stat *)PTR_BAG(STATE(StackStat)) + 1;
data[STATE(CountStat)] = stat;
STATE(CountStat)++;
}

Expand All @@ -322,11 +330,12 @@ static Stat PopStat ( void )
/* there must be a stack, it must not be underfull/empty or overfull */
assert( STATE(StackStat) != 0 );
assert( 1 <= STATE(CountStat) );
assert( STATE(CountStat) <= SIZE_BAG(STATE(StackStat))/sizeof(Stat) );
assert( STATE(CountStat) <= CapacityStatStack() );

/* get the top statement from the stack, and count down */
STATE(CountStat)--;
stat = ((Stat*)PTR_BAG(STATE(StackStat)))[STATE(CountStat)];
Stat * data = (Stat *)PTR_BAG(STATE(StackStat)) + 1;
stat = data[STATE(CountStat)];

/* return the popped statement */
return stat;
Expand Down Expand Up @@ -415,39 +424,42 @@ static inline Stat PopLoopStat(UInt baseType, UInt extra, UInt nr)
** 'PopExpr' returns the top expressions from the expressions stack and pops
** it. It is an error if the stack is empty.
*/
/* TL: Bag StackExpr; */

/* TL: Int CountExpr; */
static inline UInt CapacityStackExpr(void)
{
return SIZE_BAG(STATE(StackExpr))/sizeof(Expr) - 1;
}

void PushExpr (
Expr expr )
static void PushExpr(Expr expr)
{
/* there must be a stack, it must not be underfull or overfull */
assert( STATE(StackExpr) != 0 );
assert( 0 <= STATE(CountExpr) );
assert( STATE(CountExpr) <= SIZE_BAG(STATE(StackExpr))/sizeof(Expr) );
assert( STATE(CountExpr) <= CapacityStackExpr() );
assert( expr != 0 );

/* count up and put the expression onto the stack */
if ( STATE(CountExpr) == SIZE_BAG(STATE(StackExpr))/sizeof(Expr) ) {
ResizeBag( STATE(StackExpr), 2*STATE(CountExpr)*sizeof(Expr) );
if ( STATE(CountExpr) == CapacityStackExpr() ) {
ResizeBag( STATE(StackExpr), (2*STATE(CountExpr) + 1)*sizeof(Expr) );
}
((Expr*)PTR_BAG(STATE(StackExpr)))[STATE(CountExpr)] = expr;

Expr * data = (Expr *)PTR_BAG(STATE(StackExpr)) + 1;
data[STATE(CountExpr)] = expr;
STATE(CountExpr)++;
}

Expr PopExpr ( void )
static Expr PopExpr(void)
{
Expr expr;

/* there must be a stack, it must not be underfull/empty or overfull */
assert( STATE(StackExpr) != 0 );
assert( 1 <= STATE(CountExpr) );
assert( STATE(CountExpr) <= SIZE_BAG(STATE(StackExpr))/sizeof(Expr) );
assert( STATE(CountExpr) <= CapacityStackExpr() );

/* get the top expression from the stack, and count down */
STATE(CountExpr)--;
expr = ((Expr*)PTR_BAG(STATE(StackExpr)))[STATE(CountExpr)];
Expr * data = (Expr *)PTR_BAG(STATE(StackExpr)) + 1;
expr = data[STATE(CountExpr)];

/* return the popped expression */
return expr;
Expand Down Expand Up @@ -3347,6 +3359,8 @@ static Int InitKernel (

InitHdlrFuncsFromTable( GVarFuncs );

ImportGVarFromLibrary( "TYPE_KERNEL_OBJECT", &TYPE_KERNEL_OBJECT );

/* return success */
return 0;
}
Expand Down Expand Up @@ -3401,20 +3415,18 @@ static Int PostRestore (
static Int PreSave (
StructInitInfo * module )
{
UInt i;

/* Can't save in mid-parsing */
if (STATE(CountExpr) || STATE(CountStat))
return 1;

/* push the FP cache index out into a GAP Variable */
AssGVar(GVarName("SavedFloatIndex"), INTOBJ_INT(NextFloatExprNumber));

/* clean any old data out of the statement and expression stacks */
for (i = 0; i < SIZE_BAG(STATE(StackStat))/sizeof(UInt); i++)
ADDR_OBJ(STATE(StackStat))[i] = (Obj)0;
for (i = 0; i < SIZE_BAG(STATE(StackExpr))/sizeof(UInt); i++)
ADDR_OBJ(STATE(StackExpr))[i] = (Obj)0;
// clean any old data out of the statement and expression stacks,
// but leave the type field alone
memset(ADDR_OBJ(STATE(StackStat)) + 1, 0, SIZE_BAG(STATE(StackStat)) - sizeof(Obj));
memset(ADDR_OBJ(STATE(StackExpr)) + 1, 0, SIZE_BAG(STATE(StackExpr)) - sizeof(Obj));

/* return success */
return 0;
}
Expand All @@ -3425,9 +3437,11 @@ static void InitModuleState(ModuleStateOffset offset)
STATE(LoopNesting) = 0;
STATE(LoopStackCount) = 0;

/* allocate the statements and expressions stacks */
STATE(StackStat) = NewBag( T_BODY, 64*sizeof(Stat) );
STATE(StackExpr) = NewBag( T_BODY, 64*sizeof(Expr) );
// allocate the statements and expressions stacks
STATE(StackStat) = NewBag(T_DATOBJ, sizeof(Obj) + 64*sizeof(Stat));
STATE(StackExpr) = NewBag(T_DATOBJ, sizeof(Obj) + 64*sizeof(Expr));
SET_TYPE_DATOBJ(STATE(StackStat), TYPE_KERNEL_OBJECT);
SET_TYPE_DATOBJ(STATE(StackExpr), TYPE_KERNEL_OBJECT);

#ifdef HPCGAP
STATE(OffsBodyStack) = AllocateMemoryBlock(MAX_FUNC_EXPR_NESTING*sizeof(Stat));
Expand Down
Loading