-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Use alternative mechanisms to allow us to use the default new/delete implementations #101947
Conversation
…nt to allow us to use the standard allocators.
… for OOM logging and we can handle std::bad_alloc
@@ -27,9 +27,9 @@ | |||
// case we need to wrap memory allocations, in the latter there is no | |||
// infrastructure to support this. Detect which way we're building and provide a | |||
// very simple abstraction layer (handles allocating bytes only). | |||
#ifdef _BLD_CLR |
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.
The comment above is stale after removing this ifdef.
src/coreclr/vm/ceemain.cpp
Outdated
} | ||
else | ||
{ | ||
throw std::bad_alloc(); |
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.
Hmm, this makes me wonder - couldn't we just make this handler throw our OutOfMemoryException here instead of making all the changes in the exception handling macros?
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.
We can't as the new handler is technically process-global. So with this change, we would technically report more OOMs (as we'd report an OOM with the stack from ICU for example) but we wouldn't break a C++ library that is expecting to catch std::bad_alloc
.
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.
Ah, makes sense, thank you for the explanation.
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.
We can't as the new handler is technically process-global.
Does that mean that some other library loaded in the process can break us, or vice versa?
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.
I am wondering whether it would be better to drop this stresslogging. I do not think it is particularly important.
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.
I agree that is it not particularly important. Both from dump and live debugging, it will be clear that there was an OOM, so having it in the stresslog doesn't seem to provide any benefit.
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.
I'll remove it from this path then.
@@ -32,9 +32,10 @@ set(SOURCES | |||
|
|||
include_directories(../../../coreclr/pal/prebuilt/inc) | |||
|
|||
add_compile_definitions(SOS_INCLUDE) |
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 define can use a better name.
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.
I'll come back to this and clean this up in a future PR.
set_new_handler
.std::bad_alloc
and translate it to our pre-allocatedOutOfMemoryException
.With these changes, we can switch to the global
new
anddelete
implementations provided by the C++ Standard Library.Also remove
_BLD_CLR
define as we always define it in the product. Adjust the one test native binary that was using the headers without defining it.