Java Code Examples for sun.jvm.hotspot.utilities.SystemDictionaryHelper#findInstanceKlass()
The following examples show how to use
sun.jvm.hotspot.utilities.SystemDictionaryHelper#findInstanceKlass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestInstanceKlassSizeForInterface.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void SAInstanceKlassSize(int lingeredAppPid, String[] instanceKlassNames) { HotSpotAgent agent = new HotSpotAgent(); try { agent.attach(lingeredAppPid); } catch (DebuggerException e) { System.out.println(e.getMessage()); System.err.println("Unable to connect to process ID: " + lingeredAppPid); agent.detach(); e.printStackTrace(); } for (String instanceKlassName : instanceKlassNames) { InstanceKlass iKlass = SystemDictionaryHelper.findInstanceKlass( instanceKlassName); Asserts.assertNotNull(iKlass, String.format("Unable to find instance klass for %s", instanceKlassName)); System.out.println("SA: The size of " + instanceKlassName + " is " + iKlass.getSize()); } agent.detach(); }
Example 2
Source File: TestInstanceKlassSize.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void SAInstanceKlassSize(int pid, String[] SAInstanceKlassNames) { HotSpotAgent agent = new HotSpotAgent(); try { agent.attach(pid); } catch (DebuggerException e) { System.out.println(e.getMessage()); System.err.println("Unable to connect to process ID: " + pid); agent.detach(); e.printStackTrace(); } for (String SAInstanceKlassName : SAInstanceKlassNames) { InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass( SAInstanceKlassName); Asserts.assertNotNull(ik, String.format("Unable to find instance klass for %s", ik)); System.out.println("SA: The size of " + SAInstanceKlassName + " is " + ik.getSize()); } agent.detach(); }
Example 3
Source File: TestCpoolForInvokeDynamic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void printBytecodes(String pid, String[] instanceKlassNames) { HotSpotAgent agent = new HotSpotAgent(); try { agent.attach(Integer.parseInt(pid)); } catch (DebuggerException e) { System.out.println(e.getMessage()); System.err.println("Unable to connect to process ID: " + pid); agent.detach(); e.printStackTrace(); } for (String instanceKlassName : instanceKlassNames) { InstanceKlass iKlass = SystemDictionaryHelper.findInstanceKlass(instanceKlassName); MethodArray methods = iKlass.getMethods(); for (int i = 0; i < methods.length(); i++) { Method m = methods.at(i); System.out.println("Method: " + m.getName().asString() + " in instance klass: " + instanceKlassName); HTMLGenerator gen = new HTMLGenerator(false); System.out.println(gen.genHTML(m)); } } agent.detach(); }
Example 4
Source File: TestDefaultMethods.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void printDefaultMethods(String pid, String[] instanceKlassNames) { HotSpotAgent agent = new HotSpotAgent(); try { agent.attach(Integer.parseInt(pid)); } catch (DebuggerException e) { System.out.println(e.getMessage()); System.err.println("Unable to connect to process ID: " + pid); agent.detach(); e.printStackTrace(); } for (String instanceKlassName : instanceKlassNames) { InstanceKlass iKlass = SystemDictionaryHelper.findInstanceKlass(instanceKlassName); MethodArray methods = iKlass.getMethods(); MethodArray defaultMethods = iKlass.getDefaultMethods(); for (int i = 0; i < methods.length(); i++) { Method m = methods.at(i); System.out.println("Method: " + m.getName().asString() + " in instance klass: " + instanceKlassName); } if (defaultMethods != null) { for (int j = 0; j < defaultMethods.length(); j++) { Method dm = defaultMethods.at(j); System.out.println("Default method: " + dm.getName().asString() + " in instance klass: " + instanceKlassName); } } else { System.out.println("No default methods in " + instanceKlassName); } } agent.detach(); }
Example 5
Source File: FinalizerInfo.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void run() { /* * The implementation here has a dependency on the implementation of * java.lang.ref.Finalizer. If the Finalizer implementation changes it's * possible this method will require changes too. We looked into using * ObjectReader to deserialize the objects from the target VM but as * there aren't any public methods to traverse the queue it means using * reflection which will also tie us to the implementation. * * The assumption here is that Finalizer.queue is the ReferenceQueue * with the objects awaiting finalization. The ReferenceQueue queueLength * is the number of objects in the queue, and 'head' is the head of the * queue. */ InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer"); final Oop[] queueref = new Oop[1]; ik.iterateStaticFields(new DefaultOopVisitor() { public void doOop(OopField field, boolean isVMField) { String name = field.getID().getName(); if (name.equals("queue")) { queueref[0] = field.getValue(getObj()); } } }); Oop queue = queueref[0]; InstanceKlass k = (InstanceKlass) queue.getKlass(); LongField queueLengthField = (LongField) k.findField("queueLength", "J"); long queueLength = queueLengthField.getValue(queue); OopField headField = (OopField) k.findField("head", "Ljava/lang/ref/Reference;"); Oop head = headField.getValue(queue); System.out.println("Number of objects pending for finalization: " + queueLength); /* * If 'head' is non-NULL then it is the head of a list of References. * We iterate over the list (end of list is when head.next == head) */ if (head != null) { k = (InstanceKlass) head.getKlass(); OopField referentField = (OopField) k.findField("referent", "Ljava/lang/Object;"); OopField nextField = (OopField) k.findField("next", "Ljava/lang/ref/Reference;"); HashMap map = new HashMap(); for (;;) { Oop referent = referentField.getValue(head); Klass klass = referent.getKlass(); if (!map.containsKey(klass)) { map.put(klass, new ObjectHistogramElement(klass)); } ((ObjectHistogramElement)map.get(klass)).updateWith(referent); Oop next = nextField.getValue(head); if (next == null || next.equals(head)) break; head = next; } /* * Sort results - decending order by total size */ ArrayList list = new ArrayList(); list.addAll(map.values()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2); } }); /* * Print summary of objects in queue */ System.out.println(""); System.out.println("Count" + "\t" + "Class description"); System.out.println("-------------------------------------------------------"); for (int i=0; i<list.size(); i++) { ObjectHistogramElement e = (ObjectHistogramElement)list.get(i); System.out.println(e.getCount() + "\t" + e.getDescription()); } } }
Example 6
Source File: FinalizerInfo.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void run() { /* * The implementation here has a dependency on the implementation of * java.lang.ref.Finalizer. If the Finalizer implementation changes it's * possible this method will require changes too. We looked into using * ObjectReader to deserialize the objects from the target VM but as * there aren't any public methods to traverse the queue it means using * reflection which will also tie us to the implementation. * * The assumption here is that Finalizer.queue is the ReferenceQueue * with the objects awaiting finalization. The ReferenceQueue queueLength * is the number of objects in the queue, and 'head' is the head of the * queue. */ InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer"); final Oop[] queueref = new Oop[1]; ik.iterateStaticFields(new DefaultOopVisitor() { public void doOop(OopField field, boolean isVMField) { String name = field.getID().getName(); if (name.equals("queue")) { queueref[0] = field.getValue(getObj()); } } }); Oop queue = queueref[0]; InstanceKlass k = (InstanceKlass) queue.getKlass(); LongField queueLengthField = (LongField) k.findField("queueLength", "J"); long queueLength = queueLengthField.getValue(queue); OopField headField = (OopField) k.findField("head", "Ljava/lang/ref/Reference;"); Oop head = headField.getValue(queue); System.out.println("Number of objects pending for finalization: " + queueLength); /* * If 'head' is non-NULL then it is the head of a list of References. * We iterate over the list (end of list is when head.next == head) */ if (head != null) { k = (InstanceKlass) head.getKlass(); OopField referentField = (OopField) k.findField("referent", "Ljava/lang/Object;"); OopField nextField = (OopField) k.findField("next", "Ljava/lang/ref/Reference;"); HashMap map = new HashMap(); for (;;) { Oop referent = referentField.getValue(head); Klass klass = referent.getKlass(); if (!map.containsKey(klass)) { map.put(klass, new ObjectHistogramElement(klass)); } ((ObjectHistogramElement)map.get(klass)).updateWith(referent); Oop next = nextField.getValue(head); if (next == null || next.equals(head)) break; head = next; } /* * Sort results - decending order by total size */ ArrayList list = new ArrayList(); list.addAll(map.values()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2); } }); /* * Print summary of objects in queue */ System.out.println(""); System.out.println("Count" + "\t" + "Class description"); System.out.println("-------------------------------------------------------"); for (int i=0; i<list.size(); i++) { ObjectHistogramElement e = (ObjectHistogramElement)list.get(i); System.out.println(e.getCount() + "\t" + e.getDescription()); } } }
Example 7
Source File: FinalizerInfo.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public void run() { /* * The implementation here has a dependency on the implementation of * java.lang.ref.Finalizer. If the Finalizer implementation changes it's * possible this method will require changes too. We looked into using * ObjectReader to deserialize the objects from the target VM but as * there aren't any public methods to traverse the queue it means using * reflection which will also tie us to the implementation. * * The assumption here is that Finalizer.queue is the ReferenceQueue * with the objects awaiting finalization. The ReferenceQueue queueLength * is the number of objects in the queue, and 'head' is the head of the * queue. */ InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer"); final Oop[] queueref = new Oop[1]; ik.iterateStaticFields(new DefaultOopVisitor() { public void doOop(OopField field, boolean isVMField) { String name = field.getID().getName(); if (name.equals("queue")) { queueref[0] = field.getValue(getObj()); } } }); Oop queue = queueref[0]; InstanceKlass k = (InstanceKlass) queue.getKlass(); LongField queueLengthField = (LongField) k.findField("queueLength", "J"); long queueLength = queueLengthField.getValue(queue); OopField headField = (OopField) k.findField("head", "Ljava/lang/ref/Reference;"); Oop head = headField.getValue(queue); System.out.println("Number of objects pending for finalization: " + queueLength); /* * If 'head' is non-NULL then it is the head of a list of References. * We iterate over the list (end of list is when head.next == head) */ if (head != null) { k = (InstanceKlass) head.getKlass(); OopField referentField = (OopField) k.findField("referent", "Ljava/lang/Object;"); OopField nextField = (OopField) k.findField("next", "Ljava/lang/ref/Reference;"); HashMap map = new HashMap(); for (;;) { Oop referent = referentField.getValue(head); Klass klass = referent.getKlass(); if (!map.containsKey(klass)) { map.put(klass, new ObjectHistogramElement(klass)); } ((ObjectHistogramElement)map.get(klass)).updateWith(referent); Oop next = nextField.getValue(head); if (next == null || next.equals(head)) break; head = next; } /* * Sort results - decending order by total size */ ArrayList list = new ArrayList(); list.addAll(map.values()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2); } }); /* * Print summary of objects in queue */ System.out.println(""); System.out.println("Count" + "\t" + "Class description"); System.out.println("-------------------------------------------------------"); for (int i=0; i<list.size(); i++) { ObjectHistogramElement e = (ObjectHistogramElement)list.get(i); System.out.println(e.getCount() + "\t" + e.getDescription()); } } }
Example 8
Source File: FinalizerInfo.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public void run() { /* * The implementation here has a dependency on the implementation of * java.lang.ref.Finalizer. If the Finalizer implementation changes it's * possible this method will require changes too. We looked into using * ObjectReader to deserialize the objects from the target VM but as * there aren't any public methods to traverse the queue it means using * reflection which will also tie us to the implementation. * * The assumption here is that Finalizer.queue is the ReferenceQueue * with the objects awaiting finalization. The ReferenceQueue queueLength * is the number of objects in the queue, and 'head' is the head of the * queue. */ InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer"); final Oop[] queueref = new Oop[1]; ik.iterateStaticFields(new DefaultOopVisitor() { public void doOop(OopField field, boolean isVMField) { String name = field.getID().getName(); if (name.equals("queue")) { queueref[0] = field.getValue(getObj()); } } }); Oop queue = queueref[0]; InstanceKlass k = (InstanceKlass) queue.getKlass(); LongField queueLengthField = (LongField) k.findField("queueLength", "J"); long queueLength = queueLengthField.getValue(queue); OopField headField = (OopField) k.findField("head", "Ljava/lang/ref/Reference;"); Oop head = headField.getValue(queue); System.out.println("Number of objects pending for finalization: " + queueLength); /* * If 'head' is non-NULL then it is the head of a list of References. * We iterate over the list (end of list is when head.next == head) */ if (head != null) { k = (InstanceKlass) head.getKlass(); OopField referentField = (OopField) k.findField("referent", "Ljava/lang/Object;"); OopField nextField = (OopField) k.findField("next", "Ljava/lang/ref/Reference;"); HashMap map = new HashMap(); for (;;) { Oop referent = referentField.getValue(head); Klass klass = referent.getKlass(); if (!map.containsKey(klass)) { map.put(klass, new ObjectHistogramElement(klass)); } ((ObjectHistogramElement)map.get(klass)).updateWith(referent); Oop next = nextField.getValue(head); if (next == null || next.equals(head)) break; head = next; } /* * Sort results - decending order by total size */ ArrayList list = new ArrayList(); list.addAll(map.values()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2); } }); /* * Print summary of objects in queue */ System.out.println(""); System.out.println("Count" + "\t" + "Class description"); System.out.println("-------------------------------------------------------"); for (int i=0; i<list.size(); i++) { ObjectHistogramElement e = (ObjectHistogramElement)list.get(i); System.out.println(e.getCount() + "\t" + e.getDescription()); } } }
Example 9
Source File: FinalizerInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void run() { /* * The implementation here has a dependency on the implementation of * java.lang.ref.Finalizer. If the Finalizer implementation changes it's * possible this method will require changes too. We looked into using * ObjectReader to deserialize the objects from the target VM but as * there aren't any public methods to traverse the queue it means using * reflection which will also tie us to the implementation. * * The assumption here is that Finalizer.queue is the ReferenceQueue * with the objects awaiting finalization. The ReferenceQueue queueLength * is the number of objects in the queue, and 'head' is the head of the * queue. */ InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer"); final Oop[] queueref = new Oop[1]; ik.iterateStaticFields(new DefaultOopVisitor() { public void doOop(OopField field, boolean isVMField) { String name = field.getID().getName(); if (name.equals("queue")) { queueref[0] = field.getValue(getObj()); } } }); Oop queue = queueref[0]; InstanceKlass k = (InstanceKlass) queue.getKlass(); LongField queueLengthField = (LongField) k.findField("queueLength", "J"); long queueLength = queueLengthField.getValue(queue); OopField headField = (OopField) k.findField("head", "Ljava/lang/ref/Reference;"); Oop head = headField.getValue(queue); System.out.println("Number of objects pending for finalization: " + queueLength); /* * If 'head' is non-NULL then it is the head of a list of References. * We iterate over the list (end of list is when head.next == head) */ if (head != null) { k = (InstanceKlass) head.getKlass(); OopField referentField = (OopField) k.findField("referent", "Ljava/lang/Object;"); OopField nextField = (OopField) k.findField("next", "Ljava/lang/ref/Reference;"); HashMap map = new HashMap(); for (;;) { Oop referent = referentField.getValue(head); Klass klass = referent.getKlass(); if (!map.containsKey(klass)) { map.put(klass, new ObjectHistogramElement(klass)); } ((ObjectHistogramElement)map.get(klass)).updateWith(referent); Oop next = nextField.getValue(head); if (next == null || next.equals(head)) break; head = next; } /* * Sort results - decending order by total size */ ArrayList list = new ArrayList(); list.addAll(map.values()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2); } }); /* * Print summary of objects in queue */ System.out.println(""); System.out.println("Count" + "\t" + "Class description"); System.out.println("-------------------------------------------------------"); for (int i=0; i<list.size(); i++) { ObjectHistogramElement e = (ObjectHistogramElement)list.get(i); System.out.println(e.getCount() + "\t" + e.getDescription()); } } }
Example 10
Source File: FinalizerInfo.java From hottub with GNU General Public License v2.0 | 4 votes |
public void run() { /* * The implementation here has a dependency on the implementation of * java.lang.ref.Finalizer. If the Finalizer implementation changes it's * possible this method will require changes too. We looked into using * ObjectReader to deserialize the objects from the target VM but as * there aren't any public methods to traverse the queue it means using * reflection which will also tie us to the implementation. * * The assumption here is that Finalizer.queue is the ReferenceQueue * with the objects awaiting finalization. The ReferenceQueue queueLength * is the number of objects in the queue, and 'head' is the head of the * queue. */ InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer"); final Oop[] queueref = new Oop[1]; ik.iterateStaticFields(new DefaultOopVisitor() { public void doOop(OopField field, boolean isVMField) { String name = field.getID().getName(); if (name.equals("queue")) { queueref[0] = field.getValue(getObj()); } } }); Oop queue = queueref[0]; InstanceKlass k = (InstanceKlass) queue.getKlass(); LongField queueLengthField = (LongField) k.findField("queueLength", "J"); long queueLength = queueLengthField.getValue(queue); OopField headField = (OopField) k.findField("head", "Ljava/lang/ref/Reference;"); Oop head = headField.getValue(queue); System.out.println("Number of objects pending for finalization: " + queueLength); /* * If 'head' is non-NULL then it is the head of a list of References. * We iterate over the list (end of list is when head.next == head) */ if (head != null) { k = (InstanceKlass) head.getKlass(); OopField referentField = (OopField) k.findField("referent", "Ljava/lang/Object;"); OopField nextField = (OopField) k.findField("next", "Ljava/lang/ref/Reference;"); HashMap map = new HashMap(); for (;;) { Oop referent = referentField.getValue(head); Klass klass = referent.getKlass(); if (!map.containsKey(klass)) { map.put(klass, new ObjectHistogramElement(klass)); } ((ObjectHistogramElement)map.get(klass)).updateWith(referent); Oop next = nextField.getValue(head); if (next == null || next.equals(head)) break; head = next; } /* * Sort results - decending order by total size */ ArrayList list = new ArrayList(); list.addAll(map.values()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2); } }); /* * Print summary of objects in queue */ System.out.println(""); System.out.println("Count" + "\t" + "Class description"); System.out.println("-------------------------------------------------------"); for (int i=0; i<list.size(); i++) { ObjectHistogramElement e = (ObjectHistogramElement)list.get(i); System.out.println(e.getCount() + "\t" + e.getDescription()); } } }
Example 11
Source File: FinalizerInfo.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public void run() { /* * The implementation here has a dependency on the implementation of * java.lang.ref.Finalizer. If the Finalizer implementation changes it's * possible this method will require changes too. We looked into using * ObjectReader to deserialize the objects from the target VM but as * there aren't any public methods to traverse the queue it means using * reflection which will also tie us to the implementation. * * The assumption here is that Finalizer.queue is the ReferenceQueue * with the objects awaiting finalization. The ReferenceQueue queueLength * is the number of objects in the queue, and 'head' is the head of the * queue. */ InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer"); final Oop[] queueref = new Oop[1]; ik.iterateStaticFields(new DefaultOopVisitor() { public void doOop(OopField field, boolean isVMField) { String name = field.getID().getName(); if (name.equals("queue")) { queueref[0] = field.getValue(getObj()); } } }); Oop queue = queueref[0]; InstanceKlass k = (InstanceKlass) queue.getKlass(); LongField queueLengthField = (LongField) k.findField("queueLength", "J"); long queueLength = queueLengthField.getValue(queue); OopField headField = (OopField) k.findField("head", "Ljava/lang/ref/Reference;"); Oop head = headField.getValue(queue); System.out.println("Number of objects pending for finalization: " + queueLength); /* * If 'head' is non-NULL then it is the head of a list of References. * We iterate over the list (end of list is when head.next == head) */ if (head != null) { k = (InstanceKlass) head.getKlass(); OopField referentField = (OopField) k.findField("referent", "Ljava/lang/Object;"); OopField nextField = (OopField) k.findField("next", "Ljava/lang/ref/Reference;"); HashMap map = new HashMap(); for (;;) { Oop referent = referentField.getValue(head); Klass klass = referent.getKlass(); if (!map.containsKey(klass)) { map.put(klass, new ObjectHistogramElement(klass)); } ((ObjectHistogramElement)map.get(klass)).updateWith(referent); Oop next = nextField.getValue(head); if (next == null || next.equals(head)) break; head = next; } /* * Sort results - decending order by total size */ ArrayList list = new ArrayList(); list.addAll(map.values()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2); } }); /* * Print summary of objects in queue */ System.out.println(""); System.out.println("Count" + "\t" + "Class description"); System.out.println("-------------------------------------------------------"); for (int i=0; i<list.size(); i++) { ObjectHistogramElement e = (ObjectHistogramElement)list.get(i); System.out.println(e.getCount() + "\t" + e.getDescription()); } } }
Example 12
Source File: FinalizerInfo.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public void run() { /* * The implementation here has a dependency on the implementation of * java.lang.ref.Finalizer. If the Finalizer implementation changes it's * possible this method will require changes too. We looked into using * ObjectReader to deserialize the objects from the target VM but as * there aren't any public methods to traverse the queue it means using * reflection which will also tie us to the implementation. * * The assumption here is that Finalizer.queue is the ReferenceQueue * with the objects awaiting finalization. The ReferenceQueue queueLength * is the number of objects in the queue, and 'head' is the head of the * queue. */ InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer"); final Oop[] queueref = new Oop[1]; ik.iterateStaticFields(new DefaultOopVisitor() { public void doOop(OopField field, boolean isVMField) { String name = field.getID().getName(); if (name.equals("queue")) { queueref[0] = field.getValue(getObj()); } } }); Oop queue = queueref[0]; InstanceKlass k = (InstanceKlass) queue.getKlass(); LongField queueLengthField = (LongField) k.findField("queueLength", "J"); long queueLength = queueLengthField.getValue(queue); OopField headField = (OopField) k.findField("head", "Ljava/lang/ref/Reference;"); Oop head = headField.getValue(queue); System.out.println("Number of objects pending for finalization: " + queueLength); /* * If 'head' is non-NULL then it is the head of a list of References. * We iterate over the list (end of list is when head.next == head) */ if (head != null) { k = (InstanceKlass) head.getKlass(); OopField referentField = (OopField) k.findField("referent", "Ljava/lang/Object;"); OopField nextField = (OopField) k.findField("next", "Ljava/lang/ref/Reference;"); HashMap map = new HashMap(); for (;;) { Oop referent = referentField.getValue(head); Klass klass = referent.getKlass(); if (!map.containsKey(klass)) { map.put(klass, new ObjectHistogramElement(klass)); } ((ObjectHistogramElement)map.get(klass)).updateWith(referent); Oop next = nextField.getValue(head); if (next == null || next.equals(head)) break; head = next; } /* * Sort results - decending order by total size */ ArrayList list = new ArrayList(); list.addAll(map.values()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2); } }); /* * Print summary of objects in queue */ System.out.println(""); System.out.println("Count" + "\t" + "Class description"); System.out.println("-------------------------------------------------------"); for (int i=0; i<list.size(); i++) { ObjectHistogramElement e = (ObjectHistogramElement)list.get(i); System.out.println(e.getCount() + "\t" + e.getDescription()); } } }