Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Fix stresslog (#4062)
Browse files Browse the repository at this point in the history
- Fix initialization of stress log, cleaned up the overall initialization sequence
- Remove spurious NO_STRESSLOG definion that disabled some of the stresslogging
  • Loading branch information
jkotas authored Jul 6, 2017
1 parent 739e44d commit 5856164
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 272 deletions.
41 changes: 9 additions & 32 deletions src/Native/Bootstrap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,30 +226,17 @@ extern "C" void __fail_fast()
exit(-1);
}

extern "C" bool REDHAWK_PALAPI PalInit();

#define DLL_PROCESS_ATTACH 1
extern "C" BOOL WINAPI RtuDllMain(HANDLE hPalInstance, DWORD dwReason, void* pvReserved);

extern "C" bool RhInitialize();
extern "C" void RhpEnableConservativeStackReporting();
extern "C" void RhpShutdown();

extern "C" int32_t RhpEnableConservativeStackReporting();

#ifndef CPPCODEGEN

extern "C" bool RhpRegisterCoffModule(void * pModule,
extern "C" bool RhRegisterOSModule(void * pModule,
void * pvStartRange, uint32_t cbRange,
void ** pClasslibFunctions, uint32_t nClasslibFunctions);

extern "C" bool RhpRegisterUnixModule(void * pModule,
void * pvStartRange, uint32_t cbRange,
void ** pClasslibFunctions, uint32_t nClasslibFunctions);

#ifdef _WIN32
extern "C" void* WINAPI GetModuleHandleW(const wchar_t *);
#else
extern "C" void* WINAPI PalGetModuleHandleFromPointer(void* pointer);
#endif
extern "C" void* PalGetModuleHandleFromPointer(void* pointer);

extern "C" void GetRuntimeException();
extern "C" void FailFast();
Expand Down Expand Up @@ -279,27 +266,17 @@ extern "C" int __managed__Main(int argc, char* argv[]);
int main(int argc, char* argv[])
#endif
{
if (!PalInit())
return -1;

if (!RtuDllMain(NULL, DLL_PROCESS_ATTACH, NULL))
if (!RhInitialize())
return -1;

#if defined(CPPCODEGEN)
if (!RhpEnableConservativeStackReporting())
return -1;
RhpEnableConservativeStackReporting();
#endif // CPPCODEGEN

#ifndef CPPCODEGEN
void *osModule;

#if defined(_WIN32)
osModule = GetModuleHandleW(NULL);
if (!RhpRegisterCoffModule(osModule,
#else // _WIN32
osModule = PalGetModuleHandleFromPointer((void*)&main);
if (!RhpRegisterUnixModule(osModule,
#endif // _WIN32
void * osModule = PalGetModuleHandleFromPointer((void*)&__managed__Main);
if (!RhRegisterOSModule(
osModule,
(void*)&__managedcode_a, (uint32_t)((char *)&__managedcode_z - (char*)&__managedcode_a),
(void **)&c_classlibFunctions, _countof(c_classlibFunctions)))
{
Expand Down
2 changes: 0 additions & 2 deletions src/Native/Runtime/AsmOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ ASM_SIZEOF( 14, 20, EHEnum)
ASM_OFFSET( 0, 0, gc_alloc_context, alloc_ptr)
ASM_OFFSET( 4, 8, gc_alloc_context, alloc_limit)

ASM_OFFSET( 4, 8, RuntimeInstance, m_pThreadStore)

#ifdef FEATURE_CACHED_INTERFACE_DISPATCH
ASM_OFFSET( 4, 8, InterfaceDispatchCell, m_pCache)
#ifndef BIT64
Expand Down
1 change: 0 additions & 1 deletion src/Native/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ set(COMMON_RUNTIME_SOURCES
DebugEventSource.cpp
DebugFuncEval.cpp
DebuggerHook.cpp
dllmain.cpp
eetype.cpp
EHHelpers.cpp
event.cpp
Expand Down
15 changes: 0 additions & 15 deletions src/Native/Runtime/PalRedhawk.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,6 @@ struct SYSTEM_INFO
// defined in gcrhenv.cpp
bool __SwitchToThread(uint32_t dwSleepMSec, uint32_t dwSwitchCount);

struct OSVERSIONINFOEXW
{
UInt32 dwOSVersionInfoSize;
UInt32 dwMajorVersion;
UInt32 dwMinorVersion;
UInt32 dwBuildNumber;
UInt32 dwPlatformId;
WCHAR szCSDVersion[128];
UInt16 wServicePackMajor;
UInt16 wServicePackMinor;
UInt16 wSuiteMask;
UInt8 wProductType;
UInt8 wReserved;
};

struct FILETIME
{
UInt32 dwLowDateTime;
Expand Down
31 changes: 0 additions & 31 deletions src/Native/Runtime/PalRedhawkFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,6 @@ inline void * PalGetProcAddress(HANDLE arg1, const char * arg2)
return GetProcAddress(arg1, arg2);
}

extern "C" HANDLE __stdcall GetProcessHeap();
inline HANDLE PalGetProcessHeap()
{
return GetProcessHeap();
}


extern "C" void* __stdcall HeapAlloc(HANDLE, UInt32, UIntNative);
inline void* PalHeapAlloc(HANDLE arg1, UInt32 arg2, UIntNative arg3)
{
return HeapAlloc(arg1, arg2, arg3);
}

extern "C" UInt32_BOOL __stdcall HeapFree(HANDLE, UInt32, void *);
inline UInt32_BOOL PalHeapFree(HANDLE arg1, UInt32 arg2, void * arg3)
{
return HeapFree(arg1, arg2, arg3);
}

extern "C" UInt32_BOOL __stdcall InitializeCriticalSectionEx(CRITICAL_SECTION *, UInt32, UInt32);
inline UInt32_BOOL PalInitializeCriticalSectionEx(CRITICAL_SECTION * arg1, UInt32 arg2, UInt32 arg3)
{
Expand Down Expand Up @@ -185,25 +166,13 @@ inline void PalTerminateProcess(HANDLE arg1, UInt32 arg2)
TerminateProcess(arg1, arg2);
}

extern "C" UInt32 __stdcall WaitForMultipleObjectsEx(UInt32, HANDLE *, UInt32_BOOL, UInt32, UInt32_BOOL);
inline UInt32 PalWaitForMultipleObjectsEx(UInt32 arg1, HANDLE * arg2, UInt32_BOOL arg3, UInt32 arg4, UInt32_BOOL arg5)
{
return WaitForMultipleObjectsEx(arg1, arg2, arg3, arg4, arg5);
}

extern "C" UInt32 __stdcall WaitForSingleObjectEx(HANDLE, UInt32, UInt32_BOOL);
inline UInt32 PalWaitForSingleObjectEx(HANDLE arg1, UInt32 arg2, UInt32_BOOL arg3)
{
return WaitForSingleObjectEx(arg1, arg2, arg3);
}

#ifdef PAL_REDHAWK_INCLUDED
extern "C" void __stdcall GetNativeSystemInfo(SYSTEM_INFO *);
inline void PalGetNativeSystemInfo(SYSTEM_INFO * arg1)
{
GetNativeSystemInfo(arg1);
}

extern "C" void __stdcall GetSystemTimeAsFileTime(FILETIME *);
inline void PalGetSystemTimeAsFileTime(FILETIME * arg1)
{
Expand Down
20 changes: 11 additions & 9 deletions src/Native/Runtime/RuntimeInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ ICodeManager * RuntimeInstance::FindCodeManagerByAddress(PTR_VOID pvAddress)
return NULL;
}

GPTR_DECL(RuntimeInstance, g_pTheRuntimeInstance);
GPTR_IMPL_INIT(RuntimeInstance, g_pTheRuntimeInstance, NULL);

PTR_RuntimeInstance GetRuntimeInstance()
{
return g_pTheRuntimeInstance;
Expand Down Expand Up @@ -306,10 +307,9 @@ HANDLE RuntimeInstance::GetPalInstance()
return m_hPalInstance;
}

bool RuntimeInstance::EnableConservativeStackReporting()
void RuntimeInstance::EnableConservativeStackReporting()
{
m_conservativeStackReportingEnabled = true;
return true;
}

EXTERN_C void REDHAWK_CALLCONV RhpSetHaveNewClasslibs();
Expand Down Expand Up @@ -480,30 +480,32 @@ RuntimeInstance::TypeManagerList& RuntimeInstance::GetTypeManagerList()
}

// static
RuntimeInstance * RuntimeInstance::Create(HANDLE hPalInstance)
bool RuntimeInstance::Initialize(HANDLE hPalInstance)
{
NewHolder<RuntimeInstance> pRuntimeInstance = new (nothrow) RuntimeInstance();
if (NULL == pRuntimeInstance)
return NULL;
return false;

CreateHolder<ThreadStore> pThreadStore = ThreadStore::Create(pRuntimeInstance);
if (NULL == pThreadStore)
return NULL;
return false;

pThreadStore.SuppressRelease();
pRuntimeInstance.SuppressRelease();

pRuntimeInstance->m_pThreadStore = pThreadStore;
pRuntimeInstance->m_hPalInstance = hPalInstance;

#ifdef FEATURE_PROFILING
pRuntimeInstance->m_fProfileThreadCreated = false;
#endif

pRuntimeInstance.SuppressRelease();
ASSERT_MSG(g_pTheRuntimeInstance == NULL, "multi-instances are not supported");
g_pTheRuntimeInstance = pRuntimeInstance;

return pRuntimeInstance;
return true;
}


void RuntimeInstance::Destroy()
{
delete this;
Expand Down
5 changes: 2 additions & 3 deletions src/Native/Runtime/RuntimeInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class RuntimeInstance
friend struct DefaultSListTraits<RuntimeInstance>;
friend class Thread;

PTR_RuntimeInstance m_pNext;
PTR_ThreadStore m_pThreadStore;
HANDLE m_hPalInstance; // this is the HANDLE passed into DllMain
SList<Module> m_ModuleList;
Expand Down Expand Up @@ -164,7 +163,7 @@ class RuntimeInstance
Module * FindModuleByReadOnlyDataAddress(PTR_VOID Data);
Module * FindModuleByOsHandle(HANDLE hOsHandle);
PTR_UInt8 FindMethodStartAddress(PTR_VOID ControlPC);
bool EnableConservativeStackReporting();
void EnableConservativeStackReporting();
bool IsConservativeStackReportingEnabled() { return m_conservativeStackReportingEnabled; }

#ifdef FEATURE_DYNAMIC_CODE
Expand All @@ -184,7 +183,7 @@ class RuntimeInstance
typedef void (* EnumerateModulesCallbackPFN)(Module *pModule, void *pvContext);
void EnumerateModulesUnderLock(EnumerateModulesCallbackPFN pCallback, void *pvContext);

static RuntimeInstance * Create(HANDLE hPalInstance);
static bool Initialize(HANDLE hPalInstance);
void Destroy();

void EnumStaticGCRefDescs(void * pfnCallback, void * pvCallbackData);
Expand Down
62 changes: 0 additions & 62 deletions src/Native/Runtime/dllmain.cpp

This file was deleted.

18 changes: 2 additions & 16 deletions src/Native/Runtime/inc/stressLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,20 +494,6 @@ struct StressLogChunk
UInt32 dwSig2;

#ifndef DACCESS_COMPILE
static HANDLE s_LogChunkHeap;

void * operator new (size_t)
{
_ASSERTE (s_LogChunkHeap != NULL);
//no need to zero memory because we could handle garbage contents
return PalHeapAlloc (s_LogChunkHeap, 0, sizeof (StressLogChunk));
}

void operator delete (void * chunk)
{
_ASSERTE (s_LogChunkHeap != NULL);
PalHeapFree (s_LogChunkHeap, 0, chunk);
}

StressLogChunk (PTR_StressLogChunk p = NULL, PTR_StressLogChunk n = NULL)
:prev (p), next (n), dwSig1 (0xCFCFCFCF), dwSig2 (0xCFCFCFCF)
Expand Down Expand Up @@ -701,7 +687,7 @@ inline StressMsg* ThreadStressLog::AdvReadPastBoundary() {
inline ThreadStressLog::ThreadStressLog()
{
chunkListHead = chunkListTail = curWriteChunk = NULL;
StressLogChunk * newChunk =new StressLogChunk;
StressLogChunk * newChunk = new (nothrow) StressLogChunk;
//OOM or in cantalloc region
if (newChunk == NULL)
{
Expand Down Expand Up @@ -754,7 +740,7 @@ FORCEINLINE bool ThreadStressLog::GrowChunkList ()
{
return FALSE;
}
StressLogChunk * newChunk = new StressLogChunk (chunkListTail, chunkListHead);
StressLogChunk * newChunk = new (nothrow) StressLogChunk (chunkListTail, chunkListHead);
if (newChunk == NULL)
{
return FALSE;
Expand Down
Loading

0 comments on commit 5856164

Please sign in to comment.