Skip to content

Report operator new[] allocations as a distinct type in heap profiles. - #1264

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_992013321
Oct 7, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_992013321

Conversation

@copybara-service

Copy link
Copy Markdown

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.

@google-cla

google-cla Bot commented Oct 3, 2026

Copy link
Copy Markdown

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
copybara-service Bot force-pushed the test_992013321 branch 9 times, most recently from 373241a to a550068 Compare October 7, 2026 04:19
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
copybara-service Bot merged commit 4d3496a into master Oct 7, 2026
2 of 3 checks passed
@copybara-service
copybara-service Bot deleted the test_992013321 branch October 7, 2026 04:43

This branch was successfully deployed

1 active deployment
github-pages — 4d3496a6 Deployed Oct 7, 2026 by github-pages[bot] via deploy #2924
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants