# HG changeset patch # User stuefe # Date 1554188395 -7200 # Tue Apr 02 08:59:55 2019 +0200 # Node ID 197b5e0a261c56412439532095a004ffaab5f883 # Parent baf213e62aeb80214a0f1e8e9b98f55147dcf481 [mq]: aport-on-resource-exhausted diff -r baf213e62aeb -r 197b5e0a261c src/hotspot/share/gc/shared/memAllocator.cpp --- a/src/hotspot/share/gc/shared/memAllocator.cpp Mon Apr 01 18:36:12 2019 +0200 +++ b/src/hotspot/share/gc/shared/memAllocator.cpp Tue Apr 02 08:59:55 2019 +0200 @@ -125,7 +125,7 @@ // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support report_java_out_of_memory(message); - if (JvmtiExport::should_post_resource_exhausted()) { + if (AbortOnResourceExhausted || JvmtiExport::should_post_resource_exhausted()) { JvmtiExport::post_resource_exhausted( JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP, message); diff -r baf213e62aeb -r 197b5e0a261c src/hotspot/share/memory/metaspace.cpp --- a/src/hotspot/share/memory/metaspace.cpp Mon Apr 01 18:36:12 2019 +0200 +++ b/src/hotspot/share/memory/metaspace.cpp Tue Apr 02 08:59:55 2019 +0200 @@ -1370,7 +1370,7 @@ report_java_out_of_memory(space_string); - if (JvmtiExport::should_post_resource_exhausted()) { + if (AbortOnResourceExhausted || JvmtiExport::should_post_resource_exhausted()) { JvmtiExport::post_resource_exhausted( JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR, space_string); diff -r baf213e62aeb -r 197b5e0a261c src/hotspot/share/prims/jvm.cpp --- a/src/hotspot/share/prims/jvm.cpp Mon Apr 01 18:36:12 2019 +0200 +++ b/src/hotspot/share/prims/jvm.cpp Tue Apr 02 08:59:55 2019 +0200 @@ -2794,7 +2794,7 @@ if (native_thread->osthread() == NULL) { // No one should hold a reference to the 'native_thread'. native_thread->smr_delete(); - if (JvmtiExport::should_post_resource_exhausted()) { + if (AbortOnResourceExhausted || JvmtiExport::should_post_resource_exhausted()) { JvmtiExport::post_resource_exhausted( JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS, os::native_thread_creation_failed_msg()); diff -r baf213e62aeb -r 197b5e0a261c src/hotspot/share/prims/jvmtiExport.cpp --- a/src/hotspot/share/prims/jvmtiExport.cpp Mon Apr 01 18:36:12 2019 +0200 +++ b/src/hotspot/share/prims/jvmtiExport.cpp Tue Apr 02 08:59:55 2019 +0200 @@ -1484,10 +1484,37 @@ } } +static char* describe_resource_exhausted_flags(jint flags, char* buf, size_t len) { + stringStream ss(buf, len); + const struct { jint v; const char* s; } valid_flags[] = + { { JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR, "JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR" }, + { JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP, "JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP" }, + { JVMTI_RESOURCE_EXHAUSTED_THREADS, "JVMTI_RESOURCE_EXHAUSTED_THREADS" }, + { 0, NULL } }; + bool comma = false; + for (int i = 0; valid_flags[i].s != NULL; i++) { + if (flags | valid_flags[i].v) { + if (comma) { + ss.print_raw(", "); + } + ss.print_raw(valid_flags[i].s); + } + } + return buf; +} + void JvmtiExport::post_resource_exhausted(jint resource_exhausted_flags, const char* description) { JavaThread *thread = JavaThread::current(); + // Abort right away and write an error report if AbortOnResourceExhausted is set + if (AbortOnResourceExhausted) { + char tmp[256]; + fatal("Resource exhausted (%s, %s)", + describe_resource_exhausted_flags(resource_exhausted_flags, tmp, sizeof(tmp)), + description != NULL ? description : "(no details)"); + } + // JDK-8213834: handlers of ResourceExhausted may attempt some analysis // which often requires running java. // This will cause problems on threads not able to run java, e.g. compiler diff -r baf213e62aeb -r 197b5e0a261c src/hotspot/share/prims/jvmtiExport.hpp --- a/src/hotspot/share/prims/jvmtiExport.hpp Mon Apr 01 18:36:12 2019 +0200 +++ b/src/hotspot/share/prims/jvmtiExport.hpp Tue Apr 02 08:59:55 2019 +0200 @@ -379,7 +379,7 @@ } inline static void post_array_size_exhausted() { - if (should_post_resource_exhausted()) { + if (AbortOnResourceExhausted || should_post_resource_exhausted()) { post_resource_exhausted(JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR, "Requested array size exceeds VM limit"); } diff -r baf213e62aeb -r 197b5e0a261c src/hotspot/share/runtime/globals.hpp --- a/src/hotspot/share/runtime/globals.hpp Mon Apr 01 18:36:12 2019 +0200 +++ b/src/hotspot/share/runtime/globals.hpp Tue Apr 02 08:59:55 2019 +0200 @@ -519,6 +519,9 @@ "Delay in milliseconds for option AbortVMOnVMOperationTimeout") \ range(0, max_intx) \ \ + diagnostic(bool, AbortOnResourceExhausted, false, \ + "Abort upon exhausted resources") \ + \ /* 50 retries * (5 * current_retry_count) millis = ~6.375 seconds */ \ /* typically, at most a few retries are needed */ \ product(intx, SuspendRetryCount, 50, \