On Fri, 11 Mar 2022 05:59:00 GMT, David Holmes <david.hol...@oracle.com> wrote:
> > I ended up changing `os::malloc()` to zero the buffer when running with > > -Xshare:dump. Hopefully one extra check of `if (DumpSharedSpaces)` doesn't > > matter too much for regular VM executions because `os::malloc()` already > > has a high overhead. > > This is raising red flags for me sorry. Every user of the JDK is now paying a > penalty because of something only needed when dumping the shared archive. It > might not be much but it is the old "death by a thousand cuts". Is there any > way to tell the OS to pre-zero all memory provided to the current process, > such that we could set that when dumping and not have to check on each > allocation? I don't know how to tell the OS (or C library) to zero out the buffer returned by malloc. However, in the current code path, we already have a test for an uncommon condition when `os::malloc()` calls `MemTracker::record_malloc()` which calls `MallocTracker::record_malloc()` void* MallocTracker::record_malloc(void* malloc_base, size_t size, MEMFLAGS flags, const NativeCallStack& stack) { if (MemTracker::tracking_level() == NMT_detail) { MallocSiteTable::allocation_at(stack, size, &mst_marker, flags); } I can combine the tests for `MemTracker::tracking_level()` and `DumpSharedSpaces` into a single test and do more work only when the uncommon path is taken. This would require some refactoring of the MemTracker/MallocTracker code. I'd rather do that in a separate RFE. In fact, `MemTracker::_tracking_level` is tested twice in the current implementation. We can change it to do a single test in the most common case (NMT_summary) if we really want to cut down the number of tests. But honestly I don't think this makes any difference. > And I have to wonder how easy it would be to re-introduce non-deterministic > values in these data structures that are being dumped. Does malloc itself > even guarantee to return the same set of addresses for the same sequence of > requests in different executions of a program? The malloc'ed objects are copied into the CDS archive at deterministic addresses. Any pointers inside such objects will be relocated. ------------- PR: https://git.openjdk.java.net/jdk/pull/7748