From 844511f2b4b6a4be079fc5ac2f2d5b56826df85a Mon Sep 17 00:00:00 2001
Date: Tue, 4 Jun 2024 19:09:40 +0800
Subject: [PATCH] [Huawei]Keep objects when remove unshareable info
---
 hotspot/src/share/vm/oops/instanceKlass.cpp    | 18 +++---------------
 .../Thread/TestThreadDumpClassInitMonitor.java | 15 +++++++++++----
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/hotspot/src/share/vm/oops/instanceKlass.cpp b/hotspot/src/share/vm/oops/instanceKlass.cpp
index 833cf9afe..df9aaabfb 100644
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp
@@ -2467,21 +2467,6 @@ void InstanceKlass::remove_unshareable_info() {
     m->remove_unshareable_info();
   }
 
-  if (UseAppCDS || DynamicDumpSharedSpaces) {
-    if (_oop_map_cache != NULL) {
-      delete _oop_map_cache;
-      _oop_map_cache = NULL;
-    }
-
-    JNIid::deallocate(jni_ids());
-    set_jni_ids(NULL);
-
-    jmethodID* jmeths = methods_jmethod_ids_acquire();
-    if (jmeths != (jmethodID*)NULL) {
-      release_set_methods_jmethod_ids(NULL);
-      FreeHeap(jmeths);
-    }
-  }
   // do array classes also.
   array_klasses_do(remove_unshareable_in_class);
   // These are not allocated from metaspace. They are safe to set to NULL.
@@ -2489,6 +2474,9 @@ void InstanceKlass::remove_unshareable_info() {
   _member_names = NULL;
   _osr_nmethods_head = NULL;
   _init_thread = NULL;
+  _oop_map_cache = NULL;
+  _jni_ids = NULL;
+  _methods_jmethod_ids = NULL;
 }
 
 void InstanceKlass::remove_java_mirror() {
diff --git a/hotspot/test/runtime/Thread/TestThreadDumpClassInitMonitor.java b/hotspot/test/runtime/Thread/TestThreadDumpClassInitMonitor.java
index 8aa218efb..a2111c362 100644
--- a/hotspot/test/runtime/Thread/TestThreadDumpClassInitMonitor.java
+++ b/hotspot/test/runtime/Thread/TestThreadDumpClassInitMonitor.java
@@ -148,34 +148,41 @@ public class TestThreadDumpClassInitMonitor {
                         throw new Error("Unexpected thread state line: " + line);
                     }
                     if (isProduct) {
-                        foundLines += 3;
+                        foundLines += 4;
                     } else {
                         foundLines++;
                     }
                     continue;
                 }
                 case 2: { // Debug build
+                    if (!line.trim().equals(JAVATHREAD_STATE)) {
+                        throw new Error("Unexpected JavaThread state line: " + line);
+                    }
+                    foundLines++;
+                    continue;
+                }
+                case 3: { // Debug build
                     if (!line.startsWith(THREAD_INFO)) {
                         throw new Error("Unexpected thread info line: " + line);
                     }
                     foundLines++;
                     continue;
                 }
-                case 3: { // Debug build
+                case 4: { // Debug build
                     if (!line.trim().equals(JAVATHREAD_STATE)) {
                         throw new Error("Unexpected JavaThread state line: " + line);
                     }
                     foundLines++;
                     continue;
                 }
-                case 4: {
+                case 5: {
                     if (!line.trim().startsWith(CURRENT_METHOD)) {
                         throw new Error("Unexpected current method line: " + line);
                     }
                     foundLines++;
                     continue;
                 }
-                case 5: {
+                case 6: {
                     if (!line.trim().equals(WAIT_INFO)) {
                         throw new Error("Unexpected monitor information line: " + line);
                     }
-- 
2.23.0

