From 675360f4912dad7eeeac4b6a05b782dca234c008 Mon Sep 17 00:00:00 2001
Date: Fri, 22 Jan 2021 16:16:57 +0800
Subject: optimize jmap -F -dump:xxx

Summary: optimize jmap -F -dump:xxx to speed up the dump process
LLT: N/A
Bug url: N/A
---
 .../share/classes/sun/jvm/hotspot/oops/Metadata.java   | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/Metadata.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/Metadata.java
index 4fc2ed8c6..2e56d2708 100644
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/Metadata.java
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/Metadata.java
@@ -45,6 +45,7 @@ abstract public class Metadata extends VMObject {
   }
 
   private static VirtualBaseConstructor<Metadata> metadataConstructor;
+  private static Map map = new HashMap();
 
   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
     metadataConstructor = new VirtualBaseConstructor<Metadata>(db, db.lookupType("Metadata"), null, null);
@@ -65,7 +66,14 @@ abstract public class Metadata extends VMObject {
   }
 
   public static Metadata instantiateWrapperFor(Address addr) {
-    return metadataConstructor.instantiateWrapperFor(addr);
+    Metadata metadata;
+    if (!map.containsKey(addr)) {
+      metadata = metadataConstructor.instantiateWrapperFor(addr);
+      map.put(addr, metadata);
+    } else {
+      metadata = (Metadata)map.get(addr);
+    }
+    return metadata;
   }
 
   public void iterate(MetadataVisitor visitor) {
-- 
2.19.0

