From 2e7ce3a50aca6b0633e2fb7b2d0ef3c9e7b6ebc4 Mon Sep 17 00:00:00 2001
Date: Thu, 27 Jul 2023 19:53:53 +0800
Subject: [PATCH] [Huawei]enhance java-heap-oom err log

---
 .../src/share/vm/gc_interface/collectedHeap.inline.hpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp b/hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp
index 8ed2df96a..ab4827a9b 100644
--- a/hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp
+++ b/hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp
@@ -156,8 +156,16 @@ HeapWord* CollectedHeap::common_mem_allocate_noinit(KlassHandle klass, size_t si
 
 
   if (!gc_overhead_limit_was_exceeded) {
+    ResourceMark rm;
+    tty->print_cr("OOM caused by java heap space occurred, allocate size: %zu bytes, type: %s", size * HeapWordSize, klass->signature_name());
+    Universe::heap()->print_on(tty);
+
+    if (THREAD->is_Java_thread()) {
+      tty->print_cr("current stack trace:");
+      ((JavaThread*)THREAD)->print_stack_on(tty);
+    }
     // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
-    report_java_out_of_memory("Java heap space");
+    report_java_out_of_memory(err_msg("Java heap space, allocate size: %zu bytes, type: %s", size * HeapWordSize, klass->signature_name()));
 
     if (JvmtiExport::should_post_resource_exhausted()) {
       JvmtiExport::post_resource_exhausted(
-- 
2.19.1

