Bug 14892 – -profile=gc doesn't account for GC API allocations

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-09T18:38:54Z
Last change time
2022-01-26T01:19:09Z
Keywords
pull
Assigned to
No Owner
Creator
Martin Nowak

Comments

Comment #0 by code — 2015-08-09T18:38:54Z
FWIW -profile=gc doesn't trace GC allocations using the core.memory/gc_x APIs.
Comment #1 by hsteoh — 2022-01-18T15:28:20Z
Looked at the dmd code for this. Apparently -profile=gc works by detecting language constructs that trigger an allocation, and replacing the druntime calls with alternative druntime calls that inject tracing information. Direct calls to the GC allocator are not detected since this is triggered by language constructs only. There are a few possible approaches I can see: 1) Detect calls to specific druntime symbols and substitute them with the tracing versions when compiling with -profile=gc. This is perhaps the simplest quick-fix solution, but it's rather hackish, and may or may not work well depending on how much information is available at the callsite. 2) Move the magic out of the compiler and delegate to druntime/Phobos so that commonly-used GC allocation triggering functions like std.array.array can decide how to implement tracing. E.g., set a version=profileGC and have std.array.array call the tracing version of the allocator instead of the one it's currently using. This approach is more flexible, but could be prone to abuse. 3) Variation on (2): templatize the affected druntime functions so that they *always* receive all the information they need to do tracing, but when version=profileGC is not set, this information is discarded and the non-tracing code is called. When version=profileGC is set, branch to the tracing versions of the code. Then in places like std.array.array, Phobos could meaningfully provide the allocation call with something pointing to user code (rather than std.array.array itself).
Comment #2 by dlang-bot — 2022-01-18T17:24:54Z
@quickfur created dlang/druntime pull request #3681 "Issue 14892: need to wrap _d_newarrayU as well for -profile=gc." mentioning this issue: - Issue 14892: need to wrap _d_newarrayU as well for -profile=gc. https://github.com/dlang/druntime/pull/3681
Comment #3 by dlang-bot — 2022-01-18T17:29:51Z
@quickfur created dlang/dmd pull request #13545 "Partial fix for issue 14892: define D_ProfileGC for -profile=gc" mentioning this issue: - Partial fix for issue 14892: define D_ProfileGC. To enable Phobos to propagate file/line/function information from user code to the trace functions. https://github.com/dlang/dmd/pull/13545
Comment #4 by dlang-bot — 2022-01-18T17:33:06Z
@quickfur created dlang/phobos pull request #8361 "WIP: Fix issue 14892: std.array.array support for -profile=gc." fixing this issue: - Fix issue 14892: std.array.array support for -profile=gc. https://github.com/dlang/phobos/pull/8361
Comment #5 by dlang-bot — 2022-01-18T22:04:53Z
dlang/druntime pull request #3681 "Issue 14892: need to wrap _d_newarrayU as well for -profile=gc." was merged into master: - 58b3e1ee6f526ac5167a16cf744c1dc1488684aa by H. S. Teoh: Issue 14892: need to wrap _d_newarrayU as well for -profile=gc. https://github.com/dlang/druntime/pull/3681
Comment #6 by dlang-bot — 2022-01-18T22:06:54Z
dlang/dmd pull request #13545 "Partial fix for issue 14892: define D_ProfileGC for -profile=gc" was merged into master: - 0474a7e35d94dbc8e731e64aff27a2f961cb4114 by H. S. Teoh: Partial fix for issue 14892: define D_ProfileGC. To enable Phobos to propagate file/line/function information from user code to the trace functions. https://github.com/dlang/dmd/pull/13545
Comment #7 by dlang-bot — 2022-01-19T09:10:44Z
dlang/phobos pull request #8361 "Fix issue 14892: std.array.array support for -profile=gc." was merged into master: - 75d7378f66e8891426dbff24268233673d6a2f86 by H. S. Teoh: Fix issue 14892: std.array.array support for -profile=gc. https://github.com/dlang/phobos/pull/8361
Comment #8 by hsteoh — 2022-01-19T16:05:42Z
Just realized that the Phobos PR has not *completely* fixed this issue: calls to GC.malloc for example are still missed. Will post a follow-up PR on that soon.
Comment #9 by dlang-bot — 2022-01-19T19:14:41Z
@quickfur created dlang/druntime pull request #3691 "Fix 14892: Add tracing wrappers for core.memory.GC allocation calls." fixing this issue: - Fix 14892: Add tracing wrappers for core.memory.GC allocation calls. https://github.com/dlang/druntime/pull/3691
Comment #10 by dlang-bot — 2022-01-26T01:19:09Z
dlang/druntime pull request #3691 "Fix 14892: Add tracing wrappers for core.memory.GC allocation calls." was merged into master: - 499044a65e18efc0275bfb1eaefac5a42c517ff5 by H. S. Teoh: Fix 14892: Add tracing wrappers for core.memory.GC allocation calls. https://github.com/dlang/druntime/pull/3691