Repository navigation
Report operator new[] allocations as a distinct type in heap profiles. - #1264
Merged
Merged
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
copybara-service
Bot
force-pushed
the
test_992013321
branch
9 times, most recently
from
October 7, 2026 04:19
373241a to
a550068
Compare
Sampled heap profiles label each sample with the family of the allocation
function it came from ("new", "malloc", "aligned malloc"). operator new[]
showed up as "new" because the array operators were symbol aliases of the
scalar ones. That misleads tools which infer the allocated type by matching
a sample's requested size against sizeof(T) of the candidates on its call
stack: an array requests n * sizeof(T), plus an array cookie for some types,
so it rarely matches the single object the stack suggests.
Distinguish the two with a compile-time array sub-policy of TCMallocPolicy
and give the array entry points (the global operators, the
TCMallocInternalNewArray* functions, and the __alloc_token_*__Znam* entry
points used by heap partitioning) bodies of their own, so that sampled
stacks record AllocationType::NewArray and profiles label them "new[]".
Beyond the label, behavior is unchanged: new[] keeps the size-class
partition of scalar new, the delete operators stay aliased, and mismatch
detection still accepts new[]/delete[] exactly as it accepts new/delete.
The policy difference is resolved at compile time, so the non-sampled fast
path is the same code, only instantiated a few more times. operator new[]
does, however, no longer share an address with operator new, which the
alias test used to assert.
The nothrow array alloc-token declaration gains the noexcept of its scalar
counterpart, which its definition now requires.
ProfileTest.HeapProfile is skipped in builds with alloc-token
instrumentation, so a heap_profiling_test case checks the type reported for
new and new[] expressions as the compiler actually emits them.
PiperOrigin-RevId: 994832642
copybara-service
Bot
force-pushed
the
test_992013321
branch
from
October 7, 2026 04:43
a550068 to
4d3496a
Compare
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Report operator new[] allocations as a distinct type in heap profiles.
Sampled heap profiles label each sample with the family of the allocation
function it came from ("new", "malloc", "aligned malloc"). operator new[]
showed up as "new" because the array operators were symbol aliases of the
scalar ones. That misleads tools which infer the allocated type by matching
a sample's requested size against sizeof(T) of the candidates on its call
stack: an array requests n * sizeof(T), plus an array cookie for some types,
so it rarely matches the single object the stack suggests.
Distinguish the two with a compile-time array sub-policy of TCMallocPolicy
and give the array entry points (the global operators, the
TCMallocInternalNewArray* functions, and the _alloc_token__Znam entry
points used by heap partitioning) bodies of their own, so that sampled
stacks record AllocationType::NewArray and profiles label them "new[]".
Beyond the label, behavior is unchanged: new[] keeps the size-class
partition of scalar new, the delete operators stay aliased, and mismatch
detection still accepts new[]/delete[] exactly as it accepts new/delete.
The policy difference is resolved at compile time, so the non-sampled fast
path is the same code, only instantiated a few more times. operator new[]
does, however, no longer share an address with operator new, which the
alias test used to assert.
The nothrow array alloc-token declaration gains the noexcept of its scalar
counterpart, which its definition now requires.
ProfileTest.HeapProfile is skipped in builds with alloc-token
instrumentation, so a heap_profiling_test case checks the type reported for
new and new[] expressions as the compiler actually emits them.