Skip to content

Commit 3e59db9

Browse files
author
duke
committedMay 1, 2024
Automatic merge of jdk:master into master
2 parents 935b134 + 0a24dae commit 3e59db9

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed
 

‎src/hotspot/share/services/attachListener.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static jint dump_heap(AttachOperation* op, outputStream* out) {
254254
// This helps reduces the amount of unreachable objects in the dump
255255
// and makes it easier to browse.
256256
HeapDumper dumper(live_objects_only /* request GC */);
257-
dumper.dump(path, out, level, false, HeapDumper::default_num_of_dump_threads());
257+
dumper.dump(path, out, level);
258258
}
259259
return JNI_OK;
260260
}

‎src/hotspot/share/services/heapDumper.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,18 @@ int HeapDumper::dump(const char* path, outputStream* out, int compression, bool
26042604
out->print_cr("Dumping heap to %s ...", path);
26052605
timer()->start();
26062606
}
2607+
2608+
if (_oome && num_dump_threads > 1) {
2609+
// Each additional parallel writer requires several MB of internal memory
2610+
// (DumpWriter buffer, DumperClassCacheTable, GZipCompressor buffers).
2611+
// For the OOM handling we may already be limited in memory.
2612+
// Lets ensure we have at least 20MB per thread.
2613+
julong max_threads = os::free_memory() / (20 * M);
2614+
if (num_dump_threads > max_threads) {
2615+
num_dump_threads = MAX2<uint>(1, (uint)max_threads);
2616+
}
2617+
}
2618+
26072619
// create JFR event
26082620
EventHeapDump event;
26092621

‎src/hotspot/share/services/heapDumper.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -60,8 +60,8 @@ class HeapDumper : public StackObj {
6060
// dumps the heap to the specified file, returns 0 if success.
6161
// additional info is written to out if not null.
6262
// compression >= 0 creates a gzipped file with the given compression level.
63-
// parallel_thread_num >= 0 indicates thread numbers of parallel object dump
64-
int dump(const char* path, outputStream* out = nullptr, int compression = -1, bool overwrite = false, uint parallel_thread_num = 1);
63+
// parallel_thread_num >= 0 indicates thread numbers of parallel object dump.
64+
int dump(const char* path, outputStream* out = nullptr, int compression = -1, bool overwrite = false, uint parallel_thread_num = default_num_of_dump_threads());
6565

6666
// returns error message (resource allocated), or null if no error
6767
char* error_as_C_string() const;

0 commit comments

Comments
 (0)