Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,38 @@ const int ObjectAlignmentInBytes = 8;
"compression. Otherwise the level must be between 1 and 9.") \
range(0, 9) \
\
/* SapMachine 2026-06-16: Allow to overwrite the heap dump file. */ \
product(bool, HeapDumpOverwrite, false, MANAGEABLE, \
"If enabled, the heap dump on out of memory error can " \
"overwrite an already existing file.") \
\
/* SapMachine 2026-06-16: For upward compatibility. */ \
product(uint, HeapDumpParallelism, 0, MANAGEABLE, \
"This is ignored.") \
range(0, 100000) \
\
/* SapMachine 2026-06-16: Allow to skip content of arrays in dumps.*/ \
product(bool, LimitPrimitiveArrayContentInHeapDump, false, MANAGEABLE, \
"If enabled, the content of primitive arrays is not completely " \
"written to a heap dump for large arrays. Note that this only " \
"really saves space, if the compression of the heap dump is " \
"enabled too, since the skipped elements are written as " \
"0 or false.") \
\
/* SapMachine 2026-06-16: Allow to skip content of arrays in dumps.*/ \
product(int, StringLikeContentSizeLimitInHeapDump, 120, MANAGEABLE, \
"The number of entries in primitive char and byte arrays to " \
"not skip in a heap dump when " \
"LimitPrimitiveArrayContentInHeapDump is enabled.") \
range(0, 100000) \
\
/* SapMachine 2026-06-16: Allow to skip contents of arrays in dumps.*/ \
product(int, ArrayContentSizeLimitInHeapDump, 50, MANAGEABLE, \
"The number of entries in a primitive array other than char and " \
"byte arrays to not skip in a heap dump when " \
"LimitPrimitiveArrayContentInHeapDump is enabled.") \
range(0, 100000) \
\
product(ccstr, NativeMemoryTracking, DEBUG_ONLY("summary") NOT_DEBUG("off"), \
"Native memory tracking options") \
\
Expand Down
51 changes: 49 additions & 2 deletions src/hotspot/share/services/heapDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ class AbstractDumpWriter : public StackObj {
void write_symbolID(Symbol* o);
void write_classID(Klass* k);
void write_id(u4 x);
// SapMachine 2026-06-16: Writes zeros to the buffer.
void write_zero(size_t len);

// Start a new sub-record. Starts a new heap dump segment if needed.
void start_sub_record(u1 tag, u4 len);
Expand Down Expand Up @@ -543,6 +545,26 @@ void AbstractDumpWriter::write_id(u4 x) {
#endif
}

// SapMachine 2026-06-16: Writes zeros to the buffer.
void AbstractDumpWriter::write_zero(size_t len) {
assert(!_in_dump_segment || (_sub_record_left >= len), "sub-record too large");
DEBUG_ONLY(_sub_record_left -= len);

// flush buffer to make room.
while (len > buffer_size() - position()) {
assert(!_in_dump_segment || _is_huge_sub_record,
"Cannot overflow in non-huge sub-record.");
size_t to_write = buffer_size() - position();
memset(buffer() + position(), 0, to_write);
len -= to_write;
set_position(position() + to_write);
flush();
}

memset(buffer() + position(), 0, len);
set_position(position() + len);
}

// We use java mirror as the class ID
void AbstractDumpWriter::write_classID(Klass* k) {
write_objectID(k->java_mirror());
Expand Down Expand Up @@ -1531,6 +1553,24 @@ void DumperSupport::dump_prim_array(AbstractDumpWriter* writer, typeArrayOop arr
return;
}

// SapMachine 2026-06-16: If enabled, we don't dump the whole content of large arrays, but just the start
// and fill the rest with zeroes.
int fill_with_zero = 0;

if (LimitPrimitiveArrayContentInHeapDump) {
int limit = ArrayContentSizeLimitInHeapDump;

if (type == T_BYTE || type == T_CHAR) {
limit = StringLikeContentSizeLimitInHeapDump;
}

if (length > limit) {
fill_with_zero = length - limit;
length = limit;
length_in_bytes = (u4)length * type_size;
}
}

// If the byte ordering is big endian then we can copy most types directly

switch (type) {
Expand Down Expand Up @@ -1598,6 +1638,11 @@ void DumperSupport::dump_prim_array(AbstractDumpWriter* writer, typeArrayOop arr
default : ShouldNotReachHere();
}

// SapMachine 2026-06-16: Fill with zeros, if we don't dump the whole content of the array.
if (fill_with_zero > 0) {
writer->write_zero((u4)fill_with_zero * type_size);
}

writer->end_sub_record();
}

Expand Down Expand Up @@ -2621,7 +2666,8 @@ void HeapDumper::set_error(char const* error) {
// outside of a JVM safepoint
void HeapDumper::dump_heap_from_oome() {
// SapMachine 2024-05-10: HeapDumpPath for jcmd
HeapDumper::dump_heap(false, true);
// SapMachine 2026-06-16: Handle HeapDumpOverwrite
HeapDumper::dump_heap(false, true, tty, -1, HeapDumpOverwrite);
}

// Called by error reporting by a single Java thread outside of a JVM safepoint,
Expand All @@ -2631,7 +2677,8 @@ void HeapDumper::dump_heap_from_oome() {
// inteference when updating the static variables base_path and dump_file_seq below.
void HeapDumper::dump_heap() {
// SapMachine 2024-05-10: HeapDumpPath for jcmd
HeapDumper::dump_heap(false, false);
// SapMachine 2026-06-16: Handle HeapDumpOverwrite
HeapDumper::dump_heap(false, false, tty, -1, HeapDumpOverwrite);
}

// SapMachine 2024-05-10: HeapDumpPath for jcmd
Expand Down
Loading
Loading