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

Memory canary #2293

Merged
merged 2 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ AC_ARG_ENABLE([debug],
AC_MSG_CHECKING([whether to enable debug mode])
AC_MSG_RESULT([$enable_debug])

AC_ARG_ENABLE([memory-checking],
[AS_HELP_STRING([--enable-memory-checking], [enable memory checking])],
[AC_DEFINE([GAP_MEM_CHECK], [1], [define if building with memory checking])],
[enable_memory_checking=no]
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option is not available in HPC-GAP, is it? Both because it is GASMAN specific, and because it does not perform any thread locking.

It would be kind of nice if this gave an error here if HPCGAP is enabled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And perhaps also add in "WARNING: this makes GAP super slow" ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing: you already put in some kind of valgrind based memory checking in the past. Looking at this configure option, it is not clear which of the various memory debugging techniques this refers to...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope to tidy up and document the valgrind stuff at some point. I have added a message on GAP startup saying it takes a long time to start up.

AC_MSG_CHECKING([whether to enable memory checking])
AC_MSG_RESULT([$enable_memory_checking])

dnl
dnl User setting: Enable -Werror (off by default)
dnl
Expand Down
3 changes: 3 additions & 0 deletions lib/init.g
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ BindGlobal( "ShowKernelInformation", function()
if GAPInfo.KernelInfo.KernelDebug then
Add( config, "KernelDebug" );
fi;
if GAPInfo.KernelInfo.MemCheck then
Add(config, "MemCheck");
fi;
if config <> [] then
print_info( " Configuration: ", config, "\n" );
fi;
Expand Down
3 changes: 2 additions & 1 deletion lib/system.g
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ BIND_GLOBAL( "GAPInfo", rec(
help := [ "Run ProfileLineByLine(<filename>) with recordMem := true on GAP start"] ),
rec( long := "cover", default := "", arg := "<file>",
help := [ "Run CoverageLineByLine(<filename>) on GAP start"] ),
],
rec( long := "enableMemCheck", default := false)
],
) );


Expand Down
29 changes: 26 additions & 3 deletions src/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,18 @@ Obj FuncGASMAN_LIMITS( Obj self )
return list;
}

#ifdef GAP_MEM_CHECK

extern Int EnableMemCheck;

Obj FuncGASMAN_MEM_CHECK(Obj self, Obj newval)
{
EnableMemCheck = INT_INTOBJ(newval);
return 0;
}

#endif

/****************************************************************************
**
*F FuncTotalMemoryAllocated( <self> ) .expert function 'TotalMemoryAllocated'
Expand Down Expand Up @@ -1985,7 +1997,7 @@ Obj FuncMASTER_POINTER_NUMBER(Obj self, Obj o)
return INTOBJ_INT(0);
}
#ifdef USE_GASMAN
if ((void **) o >= (void **) MptrBags && (void **) o < (void **) OldBags) {
if ((void **) o >= (void **) MptrBags && (void **) o < (void **) MptrEndBags) {
return INTOBJ_INT( ((void **) o - (void **) MptrBags) + 1 );
} else {
return INTOBJ_INT( 0 );
Expand Down Expand Up @@ -2674,6 +2686,13 @@ Obj FuncKERNEL_INFO(Obj self) {
AssPRec(res, r, False);
#endif

r = RNamName("MemCheck");
#ifdef GAP_MEM_CHECK
AssPRec(res, r, True);
#else
AssPRec(res, r, False);
#endif

MakeImmutable(res);

return res;
Expand Down Expand Up @@ -2769,7 +2788,7 @@ void ThreadedInterpreter(void *funcargs) {
**
*V GVarFuncs . . . . . . . . . . . . . . . . . . list of functions to export
*/
static StructGVarFunc GVarFuncs [] = {
static StructGVarFunc GVarFuncs[] = {

GVAR_FUNC(Runtime, 0, ""),
GVAR_FUNC(RUNTIMES, 0, ""),
Expand All @@ -2790,6 +2809,9 @@ static StructGVarFunc GVarFuncs [] = {
GVAR_FUNC(GASMAN_STATS, 0, ""),
GVAR_FUNC(GASMAN_MESSAGE_STATUS, 0, ""),
GVAR_FUNC(GASMAN_LIMITS, 0, ""),
#ifdef GAP_MEM_CHECK
GVAR_FUNC(GASMAN_MEM_CHECK, 1, "int"),
#endif
GVAR_FUNC(TotalMemoryAllocated, 0, ""),
GVAR_FUNC(SIZE_OBJ, 1, "object"),
GVAR_FUNC(TNUM_OBJ, 1, "object"),
Expand All @@ -2804,7 +2826,8 @@ static StructGVarFunc GVarFuncs [] = {
GVAR_FUNC(QUIT_GAP, -1, "args"),
GVAR_FUNC(FORCE_QUIT_GAP, -1, "args"),
GVAR_FUNC(SHOULD_QUIT_ON_BREAK, 0, ""),
GVAR_FUNC(SHELL, -1, "context, canReturnVoid, canReturnObj, lastDepth, setTime, prompt, promptHook, infile, outfile"),
GVAR_FUNC(SHELL, -1, "context, canReturnVoid, canReturnObj, lastDepth, "
"setTime, prompt, promptHook, infile, outfile"),
GVAR_FUNC(CALL_WITH_CATCH, 2, "func, args"),
GVAR_FUNC(JUMP_TO_CATCH, 1, "payload"),
GVAR_FUNC(KERNEL_INFO, 0, ""),
Expand Down
Loading