Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SapMachine #1901: Feature Request to allow service to crash if direct memory is OOM #1916

Open
wants to merge 5 commits into
base: sapmachine
Choose a base branch
from

Conversation

ansteiner
Copy link
Member

If the direct memory buffer run into OOM, DirectByteBuffer allocation code can notify the jvm if the system property "jdk.nio.reportErrorOnDirectMemoryOom" is set.

Benefits:

  • In a containerized environment, using Crash/ExitOnOutOfMemoryError allows a app/JVM that can no longer provide services and application code is handling the OOM of DirectByteBuffer to crash/exit and enabling the service to restart.
  • To analyze direct memory OutOfMemoryErrors, heap dumps are necessary to examine reference relationships. This can be facilitated using the HeapDumpOnOutOfMemoryError option.

Implementation with some minor adaptions from closed issue/PR from OpenJDK: openjdk/jdk#16176

fixes #1901

@SapMachine
Copy link
Member

Hello @ansteiner, this pull request fulfills all formal requirements.

@@ -478,6 +478,12 @@ UNSAFE_LEAF (void, Unsafe_WriteBackPostSync0(JNIEnv *env, jobject unsafe)) {
doWriteBackSync0(false);
} UNSAFE_END

// SapMachine 2025-02-05: Report error for DirectByteBufferOom to exit the VM
UNSAFE_LEAF (void, Unsafe_ReportJavaOutOfMemory0(JNIEnv *env, jobject unsafe,jstring message)) {
char *utf_message = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(message));
Copy link
Member

Choose a reason for hiding this comment

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

On other usage of java_lang_String::as_utf8_string I see a ResourceMark usage, seems this is missing here.

Copy link
Member

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

Looks good overall. I made a few suggestions. Also, the new test is failing because the VM seems to exit with a different rc.

src/hotspot/share/prims/unsafe.cpp Outdated Show resolved Hide resolved
src/hotspot/share/prims/unsafe.cpp Outdated Show resolved Hide resolved
src/java.base/share/classes/java/nio/Bits.java Outdated Show resolved Hide resolved
src/java.base/share/classes/java/nio/Bits.java Outdated Show resolved Hide resolved
@SapMachine
Copy link
Member

Hello @ansteiner, this pull request fulfills all formal requirements.

@SapMachine
Copy link
Member

Hello @ansteiner, this pull request fulfills all formal requirements.

@RealCLanger
Copy link
Member

OK, we need to figure out what happens in the test.

Copy link
Member

@schmelter-sap schmelter-sap left a comment

Choose a reason for hiding this comment

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

The type of the entry is wrong.

@@ -478,6 +478,12 @@ UNSAFE_LEAF (void, Unsafe_WriteBackPostSync0(JNIEnv *env, jobject unsafe)) {
doWriteBackSync0(false);
} UNSAFE_END

// SapMachine 2025-02-05: Report error for DirectMemoryOom to exit the VM
UNSAFE_LEAF (void, Unsafe_ReportJavaOutOfMemory0(JNIEnv *env, jobject unsafe, jstring message)) {
Copy link
Member

Choose a reason for hiding this comment

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

This should be UNSAFE_ENTRY instead of UNSAFE_LEAF

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.

Feature Request to allow service to crash if direct memory is OOM
5 participants