Skip to content

SapMachine #2250: Add adjustments to heap dumps for the buildpack#2251

Open
schmelter-sap wants to merge 9 commits into
SAP:sapmachinefrom
schmelter-sap:heapdump-adjustments-for-buildpack
Open

SapMachine #2250: Add adjustments to heap dumps for the buildpack#2251
schmelter-sap wants to merge 9 commits into
SAP:sapmachinefrom
schmelter-sap:heapdump-adjustments-for-buildpack

Conversation

@schmelter-sap
Copy link
Copy Markdown
Member

@schmelter-sap schmelter-sap commented May 19, 2026

This change adds features to the heap dump for the cf buildpack to be able to store heap dumps for customers in the object store. It includes the following features:

  • Added -XX:+HeapDumpOverwrite flag. This allows a heap dump to overwrite and existing files. It is also need to write to a named pipe. The latter will be used by the buildpack to stream from the named pipe to the object store. You could already do this in the jcmd GC.heap_dump command.
  • Added -XX:HeapDumpParallelism=<nr-of-threads> flag. This allows to specify the number of threads to use when writing the heap dump. You could already do this in the jcmd GC.heap_dump command.
  • When using only one thread to dump the heap, the code will use additional files apart from the heap dump file. This ensures that no extra disk space is used when using only one thread.
  • Added -XX:+LimitPrimArrayContentInHeapDump flag. If enabled, the heap dump will only write the real content for the first elements of large primitive arrays. The rest is fill with 0 (or false for boolean arrays). This makes the heap dump much more compressible, making upload to the object store faster. The number of entries to keep can be set via -XX:StringLikeContentSizeLimitInHeapDump=<limit> for byte and char arrays (default is 120) or -XX:ArrayContentSizeLimitInHeapDump=<limit> for the other primitive arrays (default is 50).

fixes #2250

@schmelter-sap schmelter-sap requested a review from MBaesken May 20, 2026 08:48
@SapMachine
Copy link
Copy Markdown
Member

Hello @schmelter-sap, this pull request fulfills all formal requirements.

@schmelter-sap schmelter-sap requested a review from RealCLanger May 20, 2026 08:49
@MBaesken
Copy link
Copy Markdown
Member

Couple of minor adjustments might be needed in globals.hpp
"the content of primitive arrays in not completely" should be "is not"
"this only really safes space" should be "saves"
In StringLikeContentSizeLimitInHeapDump description - "primitive char and bytes arrays" should be "byte"


// SAPJVM 2026-05-06: 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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be size_t like it is used in the declaration of write_zero ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The length in bytes in this function always uses u4. So for consistency with other code I kept it that way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with @MBaesken . This can overflow and the write_zero function takes size_t anyways. So why do this cast to u4 here?

Comment thread src/hotspot/share/runtime/globals.hpp
"-XX:+HeapDumpOverwrite",
"-XX:HeapDumpParallelism=1");
verifyDump(dumpFile, false);
Asserts.assertTrue(firstSegment.exists(), "Segment file should not have been created (parallelism=1).");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If firstSegments is NOT there (exists fails), assertTrue fails; so should the message be better something like 'should exist but does not' ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This tests if the segment file was created during the heap dump. It would overwrite the existing file and is deleted when the heap dump is merged. So if the segment file was created, the fristSegment file doesn't exist anymore.

Comment thread test/hotspot/jtreg/serviceability/HeapDump/PartialArrayContentTest.java Outdated
@SapMachine
Copy link
Copy Markdown
Member

Hello @schmelter-sap, this pull request fulfills all formal requirements.

Comment thread src/hotspot/share/runtime/globals.hpp Outdated
"the VM decide.") \
\
/* SAPJVM 2026-05-06: Allow to skip content of large arrays in dumps.*/ \
product(bool, LimitPrimArrayContentInHeapDump, false, MANAGEABLE, \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe consider the naming: Primitive instead of Prim. The name is long anyways so we can use a precise name.

Comment thread src/hotspot/share/runtime/globals.hpp Outdated
"Sets the parallelism of the heap dump creation. 0 means to let "\
"the VM decide.") \
\
/* SAPJVM 2026-05-06: Allow to skip content of large arrays in dumps.*/ \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should the SAPJVM comments be SapMachine?

int length = calculate_array_max_length(writer, array, header_size);
int type_size = type2aelembytes(type);
// SapMachine 2026-05-06
int fill_with_zero = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could move that to the next hunk (after line 1399), so we do not need this lonely comment, right?


// SAPJVM 2026-05-06: 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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with @MBaesken . This can overflow and the write_zero function takes size_t anyways. So why do this cast to u4 here?

}

class ArrayAllocOOMApp extends ArrayAllocApp {
public static int arraySize = 54321;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not needed / not used isn't it? The value used by allocArrays() seems to be in ArrayAllocApp.

return;
}

// SAPJVM 2026-05-06: If enabled, we don't dump the whole content of large arrays, but just the start.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still some 'SAPJVM' instead of SapMachine (at various source locations).

@SapMachine
Copy link
Copy Markdown
Member

Hello @schmelter-sap, this pull request fulfills all formal requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add adjustments to heap dumps for the buildpack

4 participants