Adding -XX option for overwriting HeapDumpPath

Aleksey Shipilev shade at redhat.com
Mon Nov 21 14:39:34 UTC 2022


On 11/21/22 15:21, Mariell Hoversholm wrote:
> Would it be possible to add a new option for overwriting the file provided by the 
> `-XX:HeapDumpPath`[1] option?

It is technically simple to do: define a flag in globals.hpp and pass it in HeapDumper::dump_heap to 
HeapDumper::dump, which already takes "overwrite" argument. But the larger question is if this 
warrants the extension of (product) flag set. Once we add the flag, it adds up to maintenance costs, 
and would require multiple JDK releases to get rid of, once unused.

> Our use-case entails ensuring the created path is known beforehand to running the JVM itself, and 
> this is ensured by using `mktemp`[2].  In short, because of how `mktemp` works, it will create an 
> empty file to mark it used; this fact is used to ensure there are no name collisions, as it will 
> simply re-generate a file name until it finds a non-existent file.  We would like to preserve this 
> ability (meaning we cannot use the "unsafe" option `--dry-run`).

Is your use case specifically about HeapDumpOnOutOfMemoryError?

Because I think if you request heapdump through jcmd, then you would get `-overwrite` option today:

$ jcmd 2383127 GC.heap_dump idea.heap
2383127:
Dumping heap to idea.heap ...
Heap dump file created [1810669511 bytes in 14.977 secs]

$ jcmd 2383127 GC.heap_dump idea.heap
2383127:
Dumping heap to idea.heap ...
Unable to create idea.heap: File exists

$ jcmd 2383127 GC.heap_dump idea.heap -overwrite
2383127:
Dumping heap to idea.heap ...
Heap dump file created [1806642566 bytes in 14.780 secs]


-- 
Thanks,
-Aleksey



More information about the hotspot-dev mailing list