-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Start to use STL and stdio in superpmi #116422
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
base: main
Are you sure you want to change the base?
Conversation
std::filesystem::path g_realJitPath{""}; // Destructable objects will be cleaned up and won't leak | ||
std::filesystem::path g_logPath{""}; | ||
std::filesystem::path g_HomeDirectory{""}; | ||
std::filesystem::path g_DefaultRealJitPath{""}; | ||
|
||
void SetDefaultPaths() | ||
std::unique_ptr<MethodCallSummarizer> g_globalContext = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://learn.microsoft.com/windows/win32/dlls/dllmain and other documentations I can find, constructors/destructors for global objects with be respected by dll/so unloading. I haven't test it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global destructors are a bug farm. The problem is that they run while the other threads are stopped at random spot (on Windows) and while other threads are running (on non-Windows). Every time we happen to introduce one by mistake, we end up deleting it later to fix intermittent hangs and crashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it compare to DllMain (DETACH)? The counter shim writes statistics on unload, which is simulated by PAL. Is there better approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DllMain (DETACH)
It has the same problems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does is mean that things won't be worse if we replace existing DllMain with global objects? Currently the DllMain of JIT is doing shutdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the DllMain of JIT is doing shutdown.
If I am reading the code correctly, DllMain of JIT is only called on Windows. It is never called on non-Windows.
Does is mean that things won't be worse if we replace existing DllMain with global objects?
I would expect it to be fine for superpmi. I am not sure about regular JIT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am reading the code correctly, DllMain of JIT is only called on Windows. It is never called on non-Windows.
JIT is loaded by CLRLoadLibrary in LoadAndInitializeJIT, which is implemented in PAL with LoadLibraryExW and does DllMain simulation. It's never unloaded though, but if it is, the DllMain will also be called by PAL.
It seems that our linux glibc x64/x86/arm64 build environment aren't ready for C++ 17 STL. Is it because we are targeting the runtime version of lowest supported OS? |
We use Ubuntu |
Is it OK to use some polyfill for superPMI only? We don't need strict compatibility or reliability here. If this is too flaky, I can remove C++ 17 usage and convert to C++ 11 STL instad. |
What would you have to give up on by converting to C++ 11? |
Everything in |
C++11 and C++14 are the biggest wins for the runtime repo from an API perspective. |
@huoyaoyuan In fact, I called this API out specifically in the referenced issue #112419 (comment). We shouldn't be using this without a real benefit. I don't see that in this PR. |
@huoyaoyuan, Given Aaron's comment to avoid |
The major benefit of I'll convert this PR to |
src/coreclr/tools/superpmi/superpmi-shim-counter/methodcallsummarizer.h
Outdated
Show resolved
Hide resolved
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
if (jitLib == NULL) | ||
{ | ||
LogError("LoadRealJitLib - LoadLibrary failed to load '%ws' (0x%08x)", jitLibPath, ::GetLastError()); | ||
LogError("LoadRealJitLib - LoadLibrary failed to load '%s' (%d)", jitLibPath.c_str(), ::GetLastError()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LogError("LoadRealJitLib - LoadLibrary failed to load '%s' (%d)", jitLibPath.c_str(), ::GetLastError()); | |
LogError("LoadRealJitLib - LoadLibrary failed to load '%s' (0x%08x)", jitLibPath.c_str(), ::GetLastError()); |
Win32 error codes are best expressed as hex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Win32 error codes are best expressed as hex.
Nit: Win32 error code != HRESULTs. I believe Win32 error codes are typically displayed in decimal. For example, our own Win32Exception
prints them as decimal - Console.WriteLine(new Win32Exception(3 /* ERROR_PATH_NOT_FOUND */));
gives System.ComponentModel.Win32Exception (3): The system cannot find the path specified.
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This particular case was using hex format, while there are other places using decimal. I tend to keep it as-is for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Win32 error code != HRESULTs.
Agree. That is why I stated Win32 error code :)
I believe Win32 error codes are typically displayed in decimal.
Sadly, yes. That has been the most common experience with user facing scenarios and I continue to believe it isn't a helpful display format. The most common Win32 error codes (for example, 3, 5 ,etc) are sub 10, which display the same. The higher ones are less common and often also used with HRESULT
and LSTATUS
. Consistently displaying them as hex avoids the common signed issue (that is, using %d
instead of %u
) and allows for easier pattern recognition in logs.
In a better world, our error system would have something as simple as dlerror()
as opposed to the painfully baroque FormatMessage()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it isn't a helpful display format.
I believe that it is the common established display format for Windows error code. For example, compare these search results - the first returns good answer for me, the second one returns confusing garbage.
https://www.bing.com/search?q=windows+error+code+3
https://www.bing.com/search?q=windows+error+code+0x00000003
The higher ones are less common and often also used with HRESULT and LSTATUS.
Right, these are different enums that are not interchangeable. I do not have a problem with using hex for HRESULT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are ~100 places that print GetLastError in superpmi. ~85% print it as decimal.
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
/cc @dotnet/jit-contrib PTAL. I'm signed off. |
@EgorBo, PTAL. |
As discussed in #112419, there should not be blocker for adopting C++ 17 in development environment. SuperPMI is I/O intensive and can be simplified significantly with std::filesystem.It's non-starter to introduce C++ 17. Instead, using std::string can also simplify string manipulation a lot.
The end goal is to eliminate PAL simulation of Windows I/O functions. This PR acts as a first step to adopt STL in the dll shim entries.