Merge
authordsamersoff
Mon, 08 Aug 2016 15:53:02 +0000
changeset 40350 63c9f91c74d4
parent 40348 1bcfc9cfdfa0 (current diff)
parent 40349 cf5d284aa566 (diff)
child 40351 65f666dc21a6
child 40352 c2a7d79947a1
child 40355 e9770c31b4f1
Merge
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java	Mon Aug 08 17:15:46 2016 +0300
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java	Mon Aug 08 15:53:02 2016 +0000
@@ -26,6 +26,7 @@
 
 import java.lang.reflect.Modifier;
 import java.util.*;
+import java.util.stream.*;
 import sun.jvm.hotspot.debugger.*;
 import sun.jvm.hotspot.oops.*;
 import sun.jvm.hotspot.runtime.*;
@@ -204,15 +205,29 @@
       }
    }
 
-   protected Object getHashtable(Instance oop, boolean isProperties) {
+   private void setPropertiesEntry(java.util.Properties p, Oop oop) {
+      InstanceKlass ik = (InstanceKlass)oop.getKlass();
+      OopField keyField = (OopField)ik.findField("key", "Ljava/lang/Object;");
+      OopField valueField = (OopField)ik.findField("val", "Ljava/lang/Object;");
+
+      try {
+         p.setProperty((String)readObject(keyField.getValue(oop)),
+                       (String)readObject(valueField.getValue(oop)));
+      } catch (ClassNotFoundException ce) {
+         if (DEBUG) {
+            debugPrintStackTrace(ce);
+         }
+      }
+   }
+
+   protected Object getHashtable(Instance oop) {
       InstanceKlass k = (InstanceKlass)oop.getKlass();
       OopField tableField = (OopField)k.findField("table", "[Ljava/util/Hashtable$Entry;");
       if (tableField == null) {
          debugPrintln("Could not find field of [Ljava/util/Hashtable$Entry;");
          return null;
       }
-      java.util.Hashtable table = (isProperties) ? new java.util.Properties()
-                                                 : new java.util.Hashtable();
+      java.util.Hashtable table = new java.util.Hashtable();
       ObjArray kvs = (ObjArray)tableField.getValue(oop);
       long size = kvs.getLength();
       debugPrintln("Hashtable$Entry Size = " + size);
@@ -225,6 +240,39 @@
       return table;
    }
 
+   private Properties getProperties(Instance oop) {
+      InstanceKlass k = (InstanceKlass)oop.getKlass();
+      OopField mapField = (OopField)k.findField("map", "Ljava/util/concurrent/ConcurrentHashMap;");
+      if (mapField == null) {
+         debugPrintln("Could not find field of Ljava/util/concurrent/ConcurrentHashMap");
+         return null;
+      }
+
+      Instance mapObj = (Instance)mapField.getValue(oop);
+      if (mapObj == null) {
+         debugPrintln("Could not get map field from java.util.Properties");
+         return null;
+      }
+
+      InstanceKlass mk = (InstanceKlass)mapObj.getKlass();
+      OopField tableField = (OopField)mk.findField("table", "[Ljava/util/concurrent/ConcurrentHashMap$Node;");
+      if (tableField == null) {
+         debugPrintln("Could not find field of [Ljava/util/concurrent/ConcurrentHashMap$Node");
+         return null;
+      }
+
+      java.util.Properties props = new java.util.Properties();
+      ObjArray kvs = (ObjArray)tableField.getValue(mapObj);
+      long size = kvs.getLength();
+      debugPrintln("ConcurrentHashMap$Node Size = " + size);
+      LongStream.range(0, size)
+                .mapToObj(kvs::getObjAt)
+                .filter(o -> o != null)
+                .forEach(o -> setPropertiesEntry(props, o));
+
+      return props;
+   }
+
    public Object readInstance(Instance oop) throws ClassNotFoundException {
       Object result = getFromObjTable(oop);
       if (result == null) {
@@ -240,11 +288,11 @@
          }
 
          if (kls.getName().equals(javaUtilHashtable())) {
-            return getHashtable(oop, false);
+            return getHashtable(oop);
          }
 
          if (kls.getName().equals(javaUtilProperties())) {
-            return getHashtable(oop, true);
+            return getProperties(oop);
          }
 
          Class clz = readClass(kls);