Showing the changes to java/pkg/com/sun/tools/hat/internal/server/FinalizerSummaryQuery.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,128 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | |||
| 27 | /* | ||
| 28 | * The Original Code is HAT. The Initial Developer of the | ||
| 29 | * Original Code is Bill Foote, with contributions from others | ||
| 30 | * at JavaSoft/Sun. | ||
| 31 | */ | ||
| 32 | |||
| 33 | package com.sun.tools.hat.internal.server; | ||
| 34 | |||
| 35 | import com.sun.tools.hat.internal.model.*; | ||
| 36 | import java.util.*; | ||
| 37 | |||
| 38 | public class FinalizerSummaryQuery extends QueryHandler { | ||
| 39 | public void run() { | ||
| 40 | Enumeration objs = snapshot.getFinalizerObjects(); | ||
| 41 | startHtml("Finalizer Summary"); | ||
| 42 | |||
| 43 | out.println("<p align='center'>"); | ||
| 44 | out.println("<b><a href='/'>All Classes (excluding platform)</a></b>"); | ||
| 45 | out.println("</p>"); | ||
| 46 | |||
| 47 | printFinalizerSummary(objs); | ||
| 48 | endHtml(); | ||
| 49 | } | ||
| 50 | |||
| 51 | private static class HistogramElement { | ||
| 52 | public HistogramElement(JavaClass clazz) { | ||
| 53 | this.clazz = clazz; | ||
| 54 | } | ||
| 55 | |||
| 56 | public void updateCount() { | ||
| 57 | this.count++; | ||
| 58 | } | ||
| 59 | |||
| 60 | public int compare(HistogramElement other) { | ||
| 61 | long diff = other.count - count; | ||
| 62 | return (diff == 0L)? 0 : ((diff > 0L)? +1 : -1); | ||
| 63 | } | ||
| 64 | |||
| 65 | public JavaClass getClazz() { | ||
| 66 | return clazz; | ||
| 67 | } | ||
| 68 | |||
| 69 | public long getCount() { | ||
| 70 | return count; | ||
| 71 | } | ||
| 72 | |||
| 73 | private JavaClass clazz; | ||
| 74 | private long count; | ||
| 75 | } | ||
| 76 | |||
| 77 | private void printFinalizerSummary(Enumeration objs) { | ||
| 78 | int count = 0; | ||
| 79 | Map<JavaClass, HistogramElement> map = new HashMap<JavaClass, HistogramElement>(); | ||
| 80 | |||
| 81 | while (objs.hasMoreElements()) { | ||
| 82 | JavaHeapObject obj = (JavaHeapObject) objs.nextElement(); | ||
| 83 | count++; | ||
| 84 | JavaClass clazz = obj.getClazz(); | ||
| 85 | if (! map.containsKey(clazz)) { | ||
| 86 | map.put(clazz, new HistogramElement(clazz)); | ||
| 87 | } | ||
| 88 | HistogramElement element = map.get(clazz); | ||
| 89 | element.updateCount(); | ||
| 90 | } | ||
| 91 | |||
| 92 | out.println("<p align='center'>"); | ||
| 93 | out.println("<b>"); | ||
| 94 | out.println("Total "); | ||
| 95 | if (count != 0) { | ||
| 96 | out.print("<a href='/finalizerObjects/'>instances</a>"); | ||
| 97 | } else { | ||
| 98 | out.print("instances"); | ||
| 99 | } | ||
| 100 | out.println(" pending finalization: "); | ||
| 101 | out.print(count); | ||
| 102 | out.println("</b></p><hr>"); | ||
| 103 | |||
| 104 | if (count == 0) { | ||
| 105 | return; | ||
| 106 | } | ||
| 107 | |||
| 108 | // calculate and print histogram | ||
| 109 | HistogramElement[] elements = new HistogramElement[map.size()]; | ||
| 110 | map.values().toArray(elements); | ||
| 111 | Arrays.sort(elements, new Comparator<HistogramElement>() { | ||
| 112 | public int compare(HistogramElement o1, HistogramElement o2) { | ||
| 113 | return o1.compare(o2); | ||
| 114 | } | ||
| 115 | }); | ||
| 116 | |||
| 117 | out.println("<table border=1 align=center>"); | ||
| 118 | out.println("<tr><th>Count</th><th>Class</th></tr>"); | ||
| 119 | for (int j = 0; j < elements.length; j++) { | ||
| 120 | out.println("<tr><td>"); | ||
| 121 | out.println(elements[j].getCount()); | ||
| 122 | out.println("</td><td>"); | ||
| 123 | printClass(elements[j].getClazz()); | ||
| 124 | out.println("</td><tr>"); | ||
| 125 | } | ||
| 126 | out.println("</table>"); | ||
| 127 | } | ||
| 128 | } | ||