From 04681c0e50c884ef1835af026cee6ce8d8a826bc Mon Sep 17 00:00:00 2001
Date: Wed, 14 May 2025 16:34:14 +0800
Subject: heapdump bug fix

---
 make/common/NativeCompilation.gmk           |  4 ++--
 src/hotspot/os_cpu/linux_arm/linux_arm_32.S |  2 ++
 src/hotspot/share/services/heapDumper.cpp   | 21 ++++++++++++++-------
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/make/common/NativeCompilation.gmk b/make/common/NativeCompilation.gmk
index fbf2f62e0..4106c9de8 100644
--- a/make/common/NativeCompilation.gmk
+++ b/make/common/NativeCompilation.gmk
@@ -795,7 +795,7 @@ define SetupNativeCompilationBody
   ifeq ($$($1_COMPILE_WITH_DEBUG_SYMBOLS), true)
     $1_EXTRA_CFLAGS += $$(CFLAGS_DEBUG_SYMBOLS)
     $1_EXTRA_CXXFLAGS += $$(CFLAGS_DEBUG_SYMBOLS)
-    ifeq ($(findstring $(OPENJDK_TARGET_CPU), arm), )
+    ifneq ($(findstring $(OPENJDK_TARGET_CPU), arm), )
       $1_EXTRA_CFLAGS := $(filter-out -gdwarf-aranges,$(1_EXTRA_CFLAGS))
       $1_EXTRA_CXXFLAGS := $(filter-out -gdwarf-aranges,$(1_EXTRA_CXXFLAGS))
     endif
@@ -904,7 +904,7 @@ define SetupNativeCompilationBody
           $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).gch
           $1_USE_PCH_FLAGS := -I$$($1_OBJECT_DIR)/precompiled
         else ifeq ($(TOOLCHAIN_TYPE), clang)
-          ifeq ($(findstring $(OPENJDK_TARGET_CPU), arm), )
+          ifneq ($(findstring $(OPENJDK_TARGET_CPU), arm), )
             $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).gch
             $1_USE_PCH_FLAGS := -I$$($1_OBJECT_DIR)/precompiled
           else
diff --git a/src/hotspot/os_cpu/linux_arm/linux_arm_32.S b/src/hotspot/os_cpu/linux_arm/linux_arm_32.S
index cfac173b1..aa839a1e3 100644
--- a/src/hotspot/os_cpu/linux_arm/linux_arm_32.S
+++ b/src/hotspot/os_cpu/linux_arm/linux_arm_32.S
@@ -28,6 +28,8 @@
 	# point or use it in the same manner as does the server
 	# compiler.
 
+        .globl _Copy_conjoint_bytes
+        .type _Copy_conjoint_bytes, %function
         .globl _Copy_arrayof_conjoint_bytes
 	.type _Copy_arrayof_conjoint_bytes, %function
 	.globl _Copy_disjoint_words
diff --git a/src/hotspot/share/services/heapDumper.cpp b/src/hotspot/share/services/heapDumper.cpp
index bbef3bfa1..6f7f9afdc 100644
--- a/src/hotspot/share/services/heapDumper.cpp
+++ b/src/hotspot/share/services/heapDumper.cpp
@@ -2492,8 +2492,20 @@ class VM_HeapDumper : public VM_GC_Operation, public WorkerTask {
     assert(_global_writer == nullptr, "Error");
     _global_writer = _local_writer;
   }
+  void set_dump_instance_fields_descriptors() {
+    assert(_dump_instance_fields_descriptors == nullptr, "Error");
+    assert(_global_writer != nullptr, "Error");
+    if(_global_writer->getHeapDumpRedactLevel() == REDACT_ANNOTATION) {
+      _dump_instance_fields_descriptors = DumperSupport::dump_instance_annotation_field_descriptors;
+    } else if(_global_writer->getHeapDumpRedactLevel() == REDACT_DIYRULES) {
+      _dump_instance_fields_descriptors = DumperSupport::dump_instance_diyrules_field_descriptors;
+    } else {
+      _dump_instance_fields_descriptors = DumperSupport::dump_instance_field_descriptors;
+    }
+  }
   void clear_global_dumper() { _global_dumper = nullptr; }
   void clear_global_writer() { _global_writer = nullptr; }
+  void clear_dump_instance_fields_descriptors() { _dump_instance_fields_descriptors = nullptr; }
 
   bool skip_operation() const;
 
@@ -2536,13 +2548,6 @@ class VM_HeapDumper : public VM_GC_Operation, public WorkerTask {
     _dumper_controller = nullptr;
     _poi = nullptr;
     _large_object_list = new (std::nothrow) HeapDumpLargeObjectList();
-    if(writer->getHeapDumpRedactLevel() == REDACT_ANNOTATION) {
-      _dump_instance_fields_descriptors = DumperSupport::dump_instance_annotation_field_descriptors;
-    } else if(writer->getHeapDumpRedactLevel() == REDACT_DIYRULES) {
-      _dump_instance_fields_descriptors = DumperSupport::dump_instance_diyrules_field_descriptors;
-    } else {
-      _dump_instance_fields_descriptors = DumperSupport::dump_instance_field_descriptors;
-    }
 
     if (oome) {
       assert(!Thread::current()->is_VM_thread(), "Dump from OutOfMemoryError cannot be called by the VMThread");
@@ -2807,6 +2812,7 @@ void VM_HeapDumper::doit() {
   // the following should be safe.
   set_global_dumper();
   set_global_writer();
+  set_dump_instance_fields_descriptors();
 
   WorkerThreads* workers = ch->safepoint_workers();
   if (workers == nullptr) {
@@ -2832,6 +2838,7 @@ void VM_HeapDumper::doit() {
   // Now we clear the global variables, so that a future dumper can run.
   clear_global_dumper();
   clear_global_writer();
+  clear_dump_instance_fields_descriptors();
 }
 
 void VM_HeapDumper::work(uint worker_id) {
-- 
2.43.0.windows.1