Skip to content

Commit

Permalink
8322043: HeapDumper should use parallel dump by default
Browse files Browse the repository at this point in the history
Reviewed-by: yyang, sspitsyn, dholmes
  • Loading branch information
Alex Menkov committed May 1, 2024
1 parent 62d5d1e commit 0a24dae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/share/services/attachListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static jint dump_heap(AttachOperation* op, outputStream* out) {
// This helps reduces the amount of unreachable objects in the dump
// and makes it easier to browse.
HeapDumper dumper(live_objects_only /* request GC */);
dumper.dump(path, out, level, false, HeapDumper::default_num_of_dump_threads());
dumper.dump(path, out, level);
}
return JNI_OK;
}
Expand Down
12 changes: 12 additions & 0 deletions src/hotspot/share/services/heapDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2604,6 +2604,18 @@ int HeapDumper::dump(const char* path, outputStream* out, int compression, bool
out->print_cr("Dumping heap to %s ...", path);
timer()->start();
}

if (_oome && num_dump_threads > 1) {
// Each additional parallel writer requires several MB of internal memory
// (DumpWriter buffer, DumperClassCacheTable, GZipCompressor buffers).
// For the OOM handling we may already be limited in memory.
// Lets ensure we have at least 20MB per thread.
julong max_threads = os::free_memory() / (20 * M);
if (num_dump_threads > max_threads) {
num_dump_threads = MAX2<uint>(1, (uint)max_threads);
}
}

// create JFR event
EventHeapDump event;

Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/services/heapDumper.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -60,8 +60,8 @@ class HeapDumper : public StackObj {
// dumps the heap to the specified file, returns 0 if success.
// additional info is written to out if not null.
// compression >= 0 creates a gzipped file with the given compression level.
// parallel_thread_num >= 0 indicates thread numbers of parallel object dump
int dump(const char* path, outputStream* out = nullptr, int compression = -1, bool overwrite = false, uint parallel_thread_num = 1);
// parallel_thread_num >= 0 indicates thread numbers of parallel object dump.
int dump(const char* path, outputStream* out = nullptr, int compression = -1, bool overwrite = false, uint parallel_thread_num = default_num_of_dump_threads());

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

1 comment on commit 0a24dae

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.