fix(prof): Speedup hot path in allocator and fix possible crash #3505
+35
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
We got some crash reports with stacks like this:
None of these are actually helpful, because this would just look like a crash in the engine's
execute_exfunction somewhere. But now we got a new crash trace adding some stack frames that look like stack corruption, but reveal something interesting nonetheless:There is just no way that
alloc_prof_reallocwould call intoalloc_prof_rshutdownand from there, there is no way to call intozend_mm_gc...But there are a few ideas and things to this stack anyway: Aaccording to the runtime stack trace, it is in
Composer\Autoload\ClassLoader::findFileWithExtension()line 505 which could trigger a reallocation, which on the way down, could call intozend_mm_gc. So at least this makes sense, not 100% with the stack trace we see, but ...So anyway: I was thinking: we might not need to do all of this
get_or_init()dance and use aRefCellat runtime, when we can instead initialise theALLOCATION_PROFILING_STATSinGINITand then just "know" that this is initialised and use it.Reviewer checklist