From 29cf2c471bf046cd58bd6fefd617a2b03040d4ff Mon Sep 17 00:00:00 2001 From: Alex Menkov Date: Fri, 3 Nov 2023 20:44:36 +0000 Subject: [PATCH] 8319053: Segment dump files remain after parallel heap dump on Windows Reviewed-by: dholmes, yyang --- src/hotspot/share/services/heapDumper.cpp | 7 +++++-- .../dcmd/gc/HeapDumpParallelTest.java | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/hotspot/share/services/heapDumper.cpp b/src/hotspot/share/services/heapDumper.cpp index fb2b618f3e6..9fc7407ed8e 100644 --- a/src/hotspot/share/services/heapDumper.cpp +++ b/src/hotspot/share/services/heapDumper.cpp @@ -389,7 +389,7 @@ enum { // Supports I/O operations for a dump // Base class for dump and parallel dump -class AbstractDumpWriter : public ResourceObj { +class AbstractDumpWriter : public CHeapObj { protected: enum { io_buffer_max_size = 1*M, @@ -1955,7 +1955,9 @@ void DumpMerger::do_merge() { merge_file(path); } // Delete selected segmented heap file nevertheless - remove(path); + if (remove(path) != 0) { + log_info(heapdump)("Removal of segment file (%d) failed (%d)", i, errno); + } } // restore compressor for further use @@ -2358,6 +2360,7 @@ void VM_HeapDumper::work(uint worker_id) { _dumper_controller->wait_all_dumpers_complete(); } else { _dumper_controller->dumper_complete(local_writer, writer()); + delete local_writer; return; } } diff --git a/test/hotspot/jtreg/serviceability/dcmd/gc/HeapDumpParallelTest.java b/test/hotspot/jtreg/serviceability/dcmd/gc/HeapDumpParallelTest.java index c07e1161592..2ea09dd1597 100644 --- a/test/hotspot/jtreg/serviceability/dcmd/gc/HeapDumpParallelTest.java +++ b/test/hotspot/jtreg/serviceability/dcmd/gc/HeapDumpParallelTest.java @@ -26,6 +26,8 @@ import java.io.IOException; import java.nio.file.Files; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import jdk.test.lib.Asserts; import jdk.test.lib.JDKToolLauncher; @@ -39,7 +41,7 @@ import jdk.test.lib.hprof.HprofParser; /** * @test - * @bug 8306441 + * @bug 8306441 8319053 * @summary Verify the integrity of generated heap dump and capability of parallel dump * @library /test/lib * @run main HeapDumpParallelTest @@ -47,6 +49,8 @@ import jdk.test.lib.hprof.HprofParser; public class HeapDumpParallelTest { + private static final String heapDumpFileName = "parallelHeapDump.bin"; + private static void checkAndVerify(OutputAnalyzer dcmdOut, LingeredApp app, File heapDumpFile, boolean expectSerial) throws Exception { dcmdOut.shouldHaveExitValue(0); dcmdOut.shouldContain("Heap dump file created"); @@ -65,6 +69,16 @@ public class HeapDumpParallelTest { appOut.shouldNotContain("Merge heap files complete"); } HprofParser.parseAndVerify(heapDumpFile); + + List files + = Stream.of(heapDumpFile.getAbsoluteFile().getParentFile().listFiles()) + .filter(file -> !file.isDirectory()) + .map(File::getName) + .filter(name -> name.startsWith(heapDumpFileName) && !name.equals(heapDumpFileName)) + .collect(Collectors.toList()); + if (!files.isEmpty()) { + throw new RuntimeException("Unexpected files left: " + files); + } if (heapDumpFile.exists()) { heapDumpFile.delete(); } @@ -79,8 +93,6 @@ public class HeapDumpParallelTest { } public static void main(String[] args) throws Exception { - String heapDumpFileName = "parallelHeapDump.bin"; - File heapDumpFile = new File(heapDumpFileName); if (heapDumpFile.exists()) { heapDumpFile.delete();