From 80039faee1680f3c67d7e0c86388354dc413d920 Mon Sep 17 00:00:00 2001 From: Sergiy Kuryata Date: Mon, 19 Oct 2015 21:13:01 -0700 Subject: [PATCH] Disable DEBUG_MESSAGES in release build of CoreCLR PAL This reduces the size of libcoreclr by 1.3MB and improves performace results by a few percent on some benchmarks. Commit migrated from https://github.com/dotnet/coreclr/commit/d1ee2104052aeb3b4dacdf33d9ecf55f1ed33f1d --- src/coreclr/src/pal/src/config.h.in | 2 - src/coreclr/src/pal/src/cruntime/misc.cpp | 16 ++--- src/coreclr/src/pal/src/exception/console.cpp | 8 +-- src/coreclr/src/pal/src/file/find.cpp | 4 +- src/coreclr/src/pal/src/include/pal/dbgmsg.h | 73 +++++++++++------------ src/coreclr/src/pal/src/include/pal/palinternal.h | 6 ++ src/coreclr/src/pal/src/init/sxs.cpp | 2 +- src/coreclr/src/pal/src/loader/module.cpp | 32 +++++----- src/coreclr/src/pal/src/synchmgr/synchmanager.cpp | 8 +-- 9 files changed, 75 insertions(+), 76 deletions(-) diff --git a/src/coreclr/src/pal/src/config.h.in b/src/coreclr/src/pal/src/config.h.in index 2abb791..ba6018e 100644 --- a/src/coreclr/src/pal/src/config.h.in +++ b/src/coreclr/src/pal/src/config.h.in @@ -1,8 +1,6 @@ #ifndef _PAL_CONFIG_H_INCLUDED #define _PAL_CONFIG_H_INCLUDED 1 -#define _NO_DEBUG_MESSAGES_ 0 - #cmakedefine01 HAVE_IEEEFP_H #cmakedefine01 HAVE_ALLOCA_H #cmakedefine01 HAVE_SYS_VMPARAM_H diff --git a/src/coreclr/src/pal/src/cruntime/misc.cpp b/src/coreclr/src/pal/src/cruntime/misc.cpp index 2e90c58..2c48214 100644 --- a/src/coreclr/src/pal/src/cruntime/misc.cpp +++ b/src/coreclr/src/pal/src/cruntime/misc.cpp @@ -334,19 +334,19 @@ PAL_qsort(void *base, size_t nmemb, size_t size, /* reset ENTRY nesting level back to zero, qsort will invoke app-defined callbacks and we want their entry traces... */ -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ { int old_level; old_level = DBG_change_entrylevel(0); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ qsort(base,nmemb,size,compar); /* ...and set nesting level back to what it was */ -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ DBG_change_entrylevel(old_level); } -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ LOGEXIT("qsort returns\n"); PERF_EXIT(qsort); @@ -365,19 +365,19 @@ PAL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, /* reset ENTRY nesting level back to zero, bsearch will invoke app-defined callbacks and we want their entry traces... */ -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ { int old_level; old_level = DBG_change_entrylevel(0); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ retval = bsearch(key,base,nmemb,size,compar); /* ...and set nesting level back to what it was */ -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ DBG_change_entrylevel(old_level); } -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ LOGEXIT("bsearch returns %p\n",retval); PERF_EXIT(bsearch); diff --git a/src/coreclr/src/pal/src/exception/console.cpp b/src/coreclr/src/pal/src/exception/console.cpp index 95de10e..56adb81 100644 --- a/src/coreclr/src/pal/src/exception/console.cpp +++ b/src/coreclr/src/pal/src/exception/console.cpp @@ -340,19 +340,19 @@ void SEHHandleControlEvent(DWORD event, LPVOID eip) BOOL handler_retval; /* reset ENTRY nesting level back to zero while inside the callback... */ -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ { int old_level; old_level = DBG_change_entrylevel(0); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ handler_retval = handler->handler(event); /* ...and set nesting level back to what it was */ -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ DBG_change_entrylevel(old_level); } -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ if(handler_retval) { diff --git a/src/coreclr/src/pal/src/file/find.cpp b/src/coreclr/src/pal/src/file/find.cpp index c24962f..76a88cf 100644 --- a/src/coreclr/src/pal/src/file/find.cpp +++ b/src/coreclr/src/pal/src/file/find.cpp @@ -737,9 +737,9 @@ static void FILEEscapeSquareBrackets(char *pattern, char *escaped_pattern) TRACE("Entering FILEEscapeSquareBrackets: [%p (%s)][%p]\n", pattern,pattern,escaped_pattern); -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ char *escaped_pattern_base = escaped_pattern; -#endif // !_NO_DEBUG_MESSAGES +#endif // _ENABLE_DEBUG_MESSAGES_ while(*pattern) { diff --git a/src/coreclr/src/pal/src/include/pal/dbgmsg.h b/src/coreclr/src/pal/src/include/pal/dbgmsg.h index 6e658cd..bf16bc4 100644 --- a/src/coreclr/src/pal/src/include/pal/dbgmsg.h +++ b/src/coreclr/src/pal/src/include/pal/dbgmsg.h @@ -136,12 +136,10 @@ Using Debug channels at Run Time set to nonzero, channels will be open or closed based on PAL_DBG_CHANNELS Notes : - If _NO_DEBUG_MESSAGES_ was defined at build-time, no debug messages + If _ENABLE_DEBUG_MESSAGES_ was not defined at build-time, no debug messages will be generated. - If _NO_DEBUG_MESSAGES_ was NOT defined, all debug levels will be enabled, + If _ENABLE_DEBUG_MESSAGES_ was defined, all debug levels will be enabled, but all channels will be closed by default - To define NO_DEBUG_MESSAGES, run the configure script with the parameter - --disable-dbgmsg Another configure option is --enable-appendtraces Normally, if the file specified by PAL_API_TRACING exists, its content will @@ -229,18 +227,8 @@ extern FILE *output_file; extern Volatile dbg_master_switch ; -/* output macros */ - -#define SET_DEFAULT_DEBUG_CHANNEL(x) \ - static const DBG_CHANNEL_ID defdbgchan = DCI_##x - -/* Is debug output enabled for the given level and channel? */ -#define DBG_ENABLED(level, channel) (output_file && \ - dbg_master_switch && \ - (dbg_channel_flags[channel] & (1 << (level)))) - /* conditionnal compilation for other debug messages */ -#if _NO_DEBUG_MESSAGES_ +#if !_ENABLE_DEBUG_MESSAGES_ /* compile out these trace levels; see the definition of NOTRACE */ #define TRACE NOTRACE @@ -256,11 +244,24 @@ extern Volatile dbg_master_switch ; #define DBGOUT_(x) NOTRACE #define ERROR NOTRACE #define ERROR_(x) NOTRACE +#define DBG_PRINTF(level, channel, bHeader) NOTRACE #define CHECK_STACK_ALIGN -#else /* _NO_DEBUG_MESSAGES_ */ +#define SET_DEFAULT_DEBUG_CHANNEL(x) +#define DBG_ENABLED(level, channel) +#else /* _ENABLE_DEBUG_MESSAGES_ */ + +/* output macros */ + +#define SET_DEFAULT_DEBUG_CHANNEL(x) \ + static const DBG_CHANNEL_ID defdbgchan = DCI_##x + +/* Is debug output enabled for the given level and channel? */ +#define DBG_ENABLED(level, channel) (output_file && \ + dbg_master_switch && \ + (dbg_channel_flags[channel] & (1 << (level)))) #define TRACE \ DBG_PRINTF(DLI_TRACE,defdbgchan,TRUE) @@ -312,16 +313,6 @@ bool DBG_ShouldCheckStackAlignment(); #define ERROR_(x) \ DBG_PRINTF(DLI_ERROR,DCI_##x,TRUE) -#endif /* _NO_DEBUG_MESSAGES_ */ - -/* Use GNU C-specific features if available : __FUNCTION__ pseudo-macro, - variable-argument macros */ -#ifdef __GNUC__ - -/* define NOTRACE as nothing; this will absorb the variable-argument list used - in tracing macros */ -#define NOTRACE(args...) - #define DBG_PRINTF(level, channel, bHeader) \ {\ if( DBG_ENABLED(level, channel) ) { \ @@ -330,11 +321,28 @@ bool DBG_ShouldCheckStackAlignment(); BOOL __bHeader = bHeader;\ DBG_PRINTF2 +#ifdef __GNUC__ #define DBG_PRINTF2(args...)\ DBG_printf_gcc(__chanid,__levid,__bHeader,__FUNCTION__,__FILE__,\ __LINE__,args);\ }\ } +#else /* __GNUC__ */ +#define DBG_PRINTF2(...)\ + DBG_printf_c99(__chanid,__levid,__bHeader,__FILE__,__LINE__,__VA_ARGS__);\ + }\ +} +#endif /* __GNUC__ */ + +#endif /* _ENABLE_DEBUG_MESSAGES_ */ + +/* Use GNU C-specific features if available : __FUNCTION__ pseudo-macro, + variable-argument macros */ +#ifdef __GNUC__ + +/* define NOTRACE as nothing; this will absorb the variable-argument list used + in tracing macros */ +#define NOTRACE(args...) #if defined(__cplusplus) && defined(FEATURE_PAL_SXS) #define __ASSERT_ENTER() \ @@ -389,19 +397,6 @@ bool DBG_ShouldCheckStackAlignment(); in tracing macros */ #define NOTRACE(...) -#define DBG_PRINTF(level, channel, bHeader) \ -{\ - if( DBG_ENABLED(level, channel) ) { \ - DBG_CHANNEL_ID __chanid=channel;\ - DBG_LEVEL_ID __levid=level;\ - BOOL __bHeader = bHeader;\ - DBG_PRINTF2 - -#define DBG_PRINTF2(...)\ - DBG_printf_c99(__chanid,__levid,__bHeader,__FILE__,__LINE__,__VA_ARGS__);\ - }\ -} - #if !defined(_DEBUG) #define ASSERT(...) diff --git a/src/coreclr/src/pal/src/include/pal/palinternal.h b/src/coreclr/src/pal/src/include/pal/palinternal.h index 6bf51e4..4ea8c3b 100644 --- a/src/coreclr/src/pal/src/include/pal/palinternal.h +++ b/src/coreclr/src/pal/src/include/pal/palinternal.h @@ -148,6 +148,12 @@ function_name() to call the system's implementation compiling PAL implementation files. */ #include "config.h" +#ifdef DEBUG +#define _ENABLE_DEBUG_MESSAGES_ 1 +#else +#define _ENABLE_DEBUG_MESSAGES_ 0 +#endif + #ifdef PAL_PERF #include "pal_perf.h" #endif diff --git a/src/coreclr/src/pal/src/init/sxs.cpp b/src/coreclr/src/pal/src/init/sxs.cpp index e3fed10..f568711 100644 --- a/src/coreclr/src/pal/src/init/sxs.cpp +++ b/src/coreclr/src/pal/src/init/sxs.cpp @@ -230,7 +230,7 @@ PAL_ReenterForEH() } else if (!pThread->IsInPal()) { -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ DBG_PRINTF(DLI_ENTRY, defdbgchan, TRUE)("PAL_ReenterForEH()\n"); #endif diff --git a/src/coreclr/src/pal/src/loader/module.cpp b/src/coreclr/src/pal/src/loader/module.cpp index 29d8d19..07bb765 100644 --- a/src/coreclr/src/pal/src/loader/module.cpp +++ b/src/coreclr/src/pal/src/loader/module.cpp @@ -540,11 +540,11 @@ FreeLibrary( module->lib_name ? module->lib_name : W16_NULLSTRING); /* reset ENTRY nesting level back to zero while inside the callback... */ -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ { int old_level; old_level = DBG_change_entrylevel(0); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ { // This module may be foreign to our PAL, so leave our PAL. @@ -562,10 +562,10 @@ FreeLibrary( } } /* ...and set nesting level back to what it was */ -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ DBG_change_entrylevel(old_level); } -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ } if (module->dl_handle && 0 != dlclose(module->dl_handle)) @@ -1137,11 +1137,11 @@ void LOADCallDllMain(DWORD dwReason, LPVOID lpReserved) { if (module->pDllMain) { -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ /* reset ENTRY nesting level back to zero while inside the callback... */ int old_level; old_level = DBG_change_entrylevel(0); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ { // This module may be foreign to our PAL, so leave our PAL. @@ -1150,10 +1150,10 @@ void LOADCallDllMain(DWORD dwReason, LPVOID lpReserved) module->pDllMain(module->hinstance, dwReason, lpReserved); } -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ /* ...and set nesting level back to what it was */ DBG_change_entrylevel(old_level); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ } } @@ -1541,11 +1541,11 @@ static HMODULE LOADRegisterLibraryDirect(HMODULE dl_handle, LPCSTR libraryNameOr BOOL dllMainRetVal; { -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ /* reset ENTRY nesting level back to zero while inside the callback... */ int old_level; old_level = DBG_change_entrylevel(0); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ { // This module may be foreign to our PAL, so leave our PAL. @@ -1554,10 +1554,10 @@ static HMODULE LOADRegisterLibraryDirect(HMODULE dl_handle, LPCSTR libraryNameOr dllMainRetVal = module->pDllMain(module->hinstance, DLL_PROCESS_ATTACH, fDynamic ? NULL : (LPVOID)-1); } -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ /* ...and set nesting level back to what it was */ DBG_change_entrylevel(old_level); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ } // If DlMain(DLL_PROCESS_ATTACH) returns FALSE, we must immediately unload the module @@ -1696,10 +1696,10 @@ we're terminating anyway. */ static void LOAD_SEH_CallDllMain(MODSTRUCT *module, DWORD dwReason, LPVOID lpReserved) { -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ /* reset ENTRY nesting level back to zero while inside the callback... */ int old_level = DBG_change_entrylevel(0); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ struct Param { @@ -1731,10 +1731,10 @@ static void LOAD_SEH_CallDllMain(MODSTRUCT *module, DWORD dwReason, LPVOID lpRes } PAL_ENDTRY -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ /* ...and set nesting level back to what it was */ DBG_change_entrylevel(old_level); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ } /*++ diff --git a/src/coreclr/src/pal/src/synchmgr/synchmanager.cpp b/src/coreclr/src/pal/src/synchmgr/synchmanager.cpp index 4ccfec6..e47707d 100644 --- a/src/coreclr/src/pal/src/synchmgr/synchmanager.cpp +++ b/src/coreclr/src/pal/src/synchmgr/synchmanager.cpp @@ -1423,11 +1423,11 @@ namespace CorUnix ptainNode = ptainLocalHead; ptainLocalHead = ptainNode->pNext; -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ // reset ENTRY nesting level back to zero while // inside the callback ... int iOldLevel = DBG_change_entrylevel(0); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ TRACE("Calling APC %p with parameter %#x\n", ptainNode->pfnAPC, ptainNode->pfnAPC); @@ -1435,10 +1435,10 @@ namespace CorUnix // Actual APC call ptainNode->pfnAPC(ptainNode->pAPCData); -#if !_NO_DEBUG_MESSAGES_ +#if _ENABLE_DEBUG_MESSAGES_ // ... and set nesting level back to what it was DBG_change_entrylevel(iOldLevel); -#endif /* !_NO_DEBUG_MESSAGES_ */ +#endif /* _ENABLE_DEBUG_MESSAGES_ */ iAPCsCalled++; m_cacheThreadApcInfoNodes.Add(pthrCurrent, ptainNode); -- 2.7.4