[Issue 14892] -profile=gc doesn't account for GC API allocations

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 18 15:28:20 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=14892

--- Comment #1 from hsteoh at quickfur.ath.cx ---
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).

--


More information about the Digitalmars-d-bugs mailing list