From 78bfc4fbd634f34870e4c11f280c36b7ed696c9f Mon Sep 17 00:00:00 2001 From: Brian Sullivan Date: Fri, 26 Apr 2019 14:07:29 -0700 Subject: Revert "Added method ReleaseManagedCommandLine to release memory" This reverts commit 1f2435763926f6068fc88a36a2b8dc49c263f271. --- src/vm/ceeload.cpp | 13 +------------ src/vm/ceeload.h | 2 -- src/vm/corhost.cpp | 5 ----- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/vm/ceeload.cpp b/src/vm/ceeload.cpp index ab5d6e83a3..66b8d535ce 100644 --- a/src/vm/ceeload.cpp +++ b/src/vm/ceeload.cpp @@ -11700,7 +11700,7 @@ void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv) CONTRACTL_END; // Get the command line. - LPCWSTR osCommandLine = GetCommandLineW(); + LPCWSTR osCommandLine = GetCommandLineW(); #ifndef FEATURE_PAL // On Windows, osCommandLine contains the executable and all arguments. @@ -11737,17 +11737,6 @@ void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv) #endif } -// Release any memory that we allocated for the managed command line -void ReleaseManagedCommandLine() -{ - LIMITED_METHOD_CONTRACT; - -#ifdef FEATURE_PAL - delete[] s_pCommandLine; - s_pCommandLine = NULL; -#endif -} - static void ProfileDataAllocateScenarioInfo(ProfileEmitter * pEmitter, LPCSTR scopeName, GUID* pMvid) { CONTRACTL diff --git a/src/vm/ceeload.h b/src/vm/ceeload.h index adfefccc5c..407d96933c 100644 --- a/src/vm/ceeload.h +++ b/src/vm/ceeload.h @@ -3423,7 +3423,5 @@ struct VASigCookieEx : public VASigCookie LPCWSTR GetManagedCommandLine(); // Save the command line for the current process. void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv); -// Release any memory that we allocated for the managed command line -void ReleaseManagedCommandLine(); #endif // !CEELOAD_H_ diff --git a/src/vm/corhost.cpp b/src/vm/corhost.cpp index c588e3110a..6487c52fca 100644 --- a/src/vm/corhost.cpp +++ b/src/vm/corhost.cpp @@ -469,11 +469,6 @@ HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId, GCPROTECT_END(); - // When running under FEATURE_PAL, the SetCommandLineArgs call above will - // call SaveManagedCommandLine which will allocate memory using new WCHAR[] - // We can release this memory now. - // - ReleaseManagedCommandLine(); } UNINSTALL_UNWIND_AND_CONTINUE_HANDLER; -- cgit v1.2.3 From 1a30173f2fb4e6cf427dfbd962ab4f80a36583a3 Mon Sep 17 00:00:00 2001 From: Brian Sullivan Date: Fri, 26 Apr 2019 14:08:01 -0700 Subject: Revert "Fix for IBC profile data on Linux - Build the full command line for FEATURE_PAL" This reverts commit 08422af33fa2026953c2e720cecf000ed4345a32. --- src/vm/ceeload.cpp | 90 ++-------------------------------------------------- src/vm/ceeload.h | 5 --- src/vm/ceemain.cpp | 8 ++--- src/vm/corhost.cpp | 11 +++++-- src/vm/eventpipe.cpp | 51 +++++++++++++++++++++++++++-- src/vm/eventpipe.h | 4 +++ 6 files changed, 68 insertions(+), 101 deletions(-) diff --git a/src/vm/ceeload.cpp b/src/vm/ceeload.cpp index 66b8d535ce..0de5dd4a53 100644 --- a/src/vm/ceeload.cpp +++ b/src/vm/ceeload.cpp @@ -74,6 +74,7 @@ #include "peimagelayout.inl" #include "ildbsymlib.h" + #if defined(PROFILING_SUPPORTED) #include "profilermetadataemitvalidator.h" #endif @@ -11652,91 +11653,6 @@ static bool GetBasename(LPCWSTR _src, __out_ecount(dstlen) __out_z LPWSTR _dst, return true; } -static LPCWSTR s_pCommandLine = NULL; - -// Rerieve the full command line for the current process. -LPCWSTR GetManagedCommandLine() -{ - LIMITED_METHOD_CONTRACT; - return s_pCommandLine; -} - -void Append_Next_Item(LPWSTR* ppCursor, SIZE_T* pRemainingLen, LPCWSTR pItem, bool addSpace) -{ - // read the writeback args and setup pCursor and remainingLen - LPWSTR pCursor = *ppCursor; - SIZE_T remainingLen = *pRemainingLen; - - // Calculate the length of pItem - SIZE_T itemLen = wcslen(pItem); - - // Append pItem at pCursor - wcscpy_s(pCursor, remainingLen, pItem); - pCursor += itemLen; - remainingLen -= itemLen; - - // Also append a space after pItem, if requested - if (addSpace) - { - // Append a space at pCursor - wcscpy_s(pCursor, remainingLen, W(" ")); - pCursor += 1; - remainingLen -= 1; - } - - // writeback and update ppCursor and pRemainingLen - *ppCursor = pCursor; - *pRemainingLen = remainingLen; -} - -void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv) -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - } - CONTRACTL_END; - - // Get the command line. - LPCWSTR osCommandLine = GetCommandLineW(); - -#ifndef FEATURE_PAL - // On Windows, osCommandLine contains the executable and all arguments. - s_pCommandLine = osCommandLine; -#else - // On UNIX, the PAL doesn't have the command line arguments, so we must build the command line. - // osCommandLine contains the full path to the executable. - SIZE_T commandLineLen = (wcslen(osCommandLine) + 1); - - // We will append pwzAssemblyPath to the 'corerun' osCommandLine - commandLineLen += (wcslen(pwzAssemblyPath) + 1); - - for (int i = 0; i < argc; i++) - { - commandLineLen += (wcslen(argv[i]) + 1); - } - commandLineLen++; // Add 1 for the null-termination - - // Allocate a new string for the command line. - LPWSTR pNewCommandLine = new WCHAR[commandLineLen]; - SIZE_T remainingLen = commandLineLen; - LPWSTR pCursor = pNewCommandLine; - - Append_Next_Item(&pCursor, &remainingLen, osCommandLine, true); - Append_Next_Item(&pCursor, &remainingLen, pwzAssemblyPath, true); - - for (int i = 0; i < argc; i++) - { - bool moreArgs = (i < (argc-1)); - Append_Next_Item(&pCursor, &remainingLen, argv[i], moreArgs); - } - - s_pCommandLine = pNewCommandLine; -#endif -} - static void ProfileDataAllocateScenarioInfo(ProfileEmitter * pEmitter, LPCSTR scopeName, GUID* pMvid) { CONTRACTL @@ -11765,9 +11681,7 @@ static void ProfileDataAllocateScenarioInfo(ProfileEmitter * pEmitter, LPCSTR sc // Allocate and initialize the scenario header section // { - // Get the managed command line. - LPCWSTR pCmdLine = GetManagedCommandLine(); - + LPCWSTR pCmdLine = GetCommandLineW(); S_SIZE_T cCmdLine = S_SIZE_T(wcslen(pCmdLine)); cCmdLine += 1; if (cCmdLine.IsOverflow()) diff --git a/src/vm/ceeload.h b/src/vm/ceeload.h index 407d96933c..04d78c3b5c 100644 --- a/src/vm/ceeload.h +++ b/src/vm/ceeload.h @@ -3419,9 +3419,4 @@ struct VASigCookieEx : public VASigCookie const BYTE *m_pArgs; // pointer to first unfixed unmanaged arg }; -// Rerieve the full command line for the current process. -LPCWSTR GetManagedCommandLine(); -// Save the command line for the current process. -void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv); - #endif // !CEELOAD_H_ diff --git a/src/vm/ceemain.cpp b/src/vm/ceemain.cpp index e595e88868..10216f58ec 100644 --- a/src/vm/ceemain.cpp +++ b/src/vm/ceemain.cpp @@ -770,9 +770,8 @@ void EEStartupHelper(COINITIEE fFlags) #ifndef CROSSGEN_COMPILE - // Cross-process named objects are not supported in PAL - // (see CorUnix::InternalCreateEvent - src/pal/src/synchobj/event.cpp.272) -#if defined(FEATURE_PREJIT) && !defined(FEATURE_PAL) + +#ifdef FEATURE_PREJIT // Initialize the sweeper thread. if (g_pConfig->GetZapBBInstr() != NULL) { @@ -786,7 +785,7 @@ void EEStartupHelper(COINITIEE fFlags) _ASSERTE(hBBSweepThread); g_BBSweep.SetBBSweepThreadHandle(hBBSweepThread); } -#endif // FEATURE_PREJIT && FEATURE_PAL +#endif // FEATURE_PREJIT #ifdef FEATURE_INTERPRETER Interpreter::Initialize(); @@ -2605,6 +2604,7 @@ INT32 GetLatchedExitCode (void) return LatchedExitCode; } + // --------------------------------------------------------------------------- // Impl for UtilLoadStringRC Callback: In VM, we let the thread decide culture // Return an int uniquely describing which language this thread is using for ui. diff --git a/src/vm/corhost.cpp b/src/vm/corhost.cpp index 6487c52fca..b42fc28a85 100644 --- a/src/vm/corhost.cpp +++ b/src/vm/corhost.cpp @@ -39,6 +39,11 @@ #include "dwreport.h" #endif // !FEATURE_PAL +#include "stringarraylist.h" +#ifdef FEATURE_PERFTRACING +#include "eventpipe.h" +#endif // FEATURE_PERFTRACING + #ifdef FEATURE_COMINTEROP #include "winrttypenameconverter.h" #endif @@ -338,8 +343,10 @@ void SetCommandLineArgs(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR* argv) } CONTRACTL_END; - // Record the command line. - SaveManagedCommandLine(pwzAssemblyPath, argc, argv); + // Send the command line to EventPipe. +#ifdef FEATURE_PERFTRACING + EventPipe::SaveCommandLine(pwzAssemblyPath, argc, argv); +#endif // FEATURE_PERFTRACING // Send the command line to System.Environment. struct _gc diff --git a/src/vm/eventpipe.cpp b/src/vm/eventpipe.cpp index 04907561e5..3a13dbd0cf 100644 --- a/src/vm/eventpipe.cpp +++ b/src/vm/eventpipe.cpp @@ -19,7 +19,6 @@ #include "eventtracebase.h" #include "sampleprofiler.h" #include "win32threadpool.h" -#include "ceemain.h" #ifdef FEATURE_PAL #include "pal.h" @@ -34,6 +33,7 @@ EventPipeSession *EventPipe::s_pSession = NULL; EventPipeBufferManager *EventPipe::s_pBufferManager = NULL; EventPipeFile *EventPipe::s_pFile = NULL; EventPipeEventSource *EventPipe::s_pEventSource = NULL; +LPCWSTR EventPipe::s_pCommandLine = NULL; HANDLE EventPipe::s_fileSwitchTimerHandle = NULL; ULONGLONG EventPipe::s_lastFlushSwitchTime = 0; @@ -223,6 +223,12 @@ void EventPipe::Shutdown() delete s_pEventSource; s_pEventSource = NULL; + // On Windows, this is just a pointer to the return value from + // GetCommandLineW(), so don't attempt to free it. +#ifdef FEATURE_PAL + delete[] s_pCommandLine; + s_pCommandLine = NULL; +#endif } EventPipeSessionID EventPipe::Enable( @@ -374,7 +380,7 @@ void EventPipe::DisableInternal(EventPipeSessionID id, EventPipeProviderCallback SampleProfiler::Disable(); // Log the process information event. - s_pEventSource->SendProcessInfo(GetManagedCommandLine()); + s_pEventSource->SendProcessInfo(s_pCommandLine); // Log the runtime information event. ETW::InfoLog::RuntimeInformation(ETW::InfoLog::InfoStructs::Normal); @@ -884,6 +890,47 @@ StackWalkAction EventPipe::StackWalkCallback(CrawlFrame *pCf, StackContents *pDa return SWA_CONTINUE; } +void EventPipe::SaveCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv) +{ + CONTRACTL + { + THROWS; + GC_TRIGGERS; + MODE_COOPERATIVE; + PRECONDITION(pwzAssemblyPath != NULL); + PRECONDITION(argc <= 0 || argv != NULL); + } + CONTRACTL_END; + + // Get the command line. + LPCWSTR osCommandLine = GetCommandLineW(); + +#ifndef FEATURE_PAL + // On Windows, osCommandLine contains the executable and all arguments. + s_pCommandLine = osCommandLine; +#else + // On UNIX, the PAL doesn't have the command line arguments, so we must build the command line. + // osCommandLine contains the full path to the executable. + SString commandLine(osCommandLine); + commandLine.Append((WCHAR)' '); + commandLine.Append(pwzAssemblyPath); + + for (int i = 0; i < argc; i++) + { + commandLine.Append((WCHAR)' '); + commandLine.Append(argv[i]); + } + + // Allocate a new string for the command line. + SIZE_T commandLineLen = commandLine.GetCount(); + WCHAR *pCommandLine = new WCHAR[commandLineLen + 1]; + wcsncpy(pCommandLine, commandLine.GetUnicode(), commandLineLen); + pCommandLine[commandLineLen] = '\0'; + + s_pCommandLine = pCommandLine; +#endif +} + EventPipeEventInstance *EventPipe::GetNextEvent() { CONTRACTL diff --git a/src/vm/eventpipe.h b/src/vm/eventpipe.h index ad0e84e2ad..c8094e34d0 100644 --- a/src/vm/eventpipe.h +++ b/src/vm/eventpipe.h @@ -330,6 +330,9 @@ public: // Get the managed call stack for the specified thread. static bool WalkManagedStackForThread(Thread *pThread, StackContents &stackContents); + // Save the command line for the current process. + static void SaveCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv); + // Get next event. static EventPipeEventInstance *GetNextEvent(); @@ -396,6 +399,7 @@ private: static EventPipeBufferManager *s_pBufferManager; static EventPipeFile *s_pFile; static EventPipeEventSource *s_pEventSource; + static LPCWSTR s_pCommandLine; static HANDLE s_fileSwitchTimerHandle; static ULONGLONG s_lastFlushSwitchTime; }; -- cgit v1.2.3