Showing the changes to java/pkg/com/sun/tools/hat/internal/server/RootsQuery.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,147 @@ | |||
| 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 java.util.Vector; | ||
| 36 | |||
| 37 | import com.sun.tools.hat.internal.model.*; | ||
| 38 | import com.sun.tools.hat.internal.util.ArraySorter; | ||
| 39 | import com.sun.tools.hat.internal.util.Comparer; | ||
| 40 | |||
| 41 | /** | ||
| 42 | * | ||
| 43 | * @author Bill Foote | ||
| 44 | */ | ||
| 45 | |||
| 46 | |||
| 47 | class RootsQuery extends QueryHandler { | ||
| 48 | |||
| 49 | private boolean includeWeak; | ||
| 50 | |||
| 51 | public RootsQuery(boolean includeWeak) { | ||
| 52 | this.includeWeak = includeWeak; | ||
| 53 | } | ||
| 54 | |||
| 55 | public void run() { | ||
| 56 | long id = parseHex(query); | ||
| 57 | JavaHeapObject target = snapshot.findThing(id); | ||
| 58 | if (target == null) { | ||
| 59 | startHtml("Object not found for rootset"); | ||
| 60 | error("object not found"); | ||
| 61 | endHtml(); | ||
| 62 | return; | ||
| 63 | } | ||
| 64 | if (includeWeak) { | ||
| 65 | startHtml("Rootset references to " + target | ||
| 66 | + " (includes weak refs)"); | ||
| 67 | } else { | ||
| 68 | startHtml("Rootset references to " + target | ||
| 69 | + " (excludes weak refs)"); | ||
| 70 | } | ||
| 71 | out.flush(); | ||
| 72 | |||
| 73 | ReferenceChain[] refs | ||
| 74 | = snapshot.rootsetReferencesTo(target, includeWeak); | ||
| 75 | ArraySorter.sort(refs, new Comparer() { | ||
| 76 | public int compare(Object lhs, Object rhs) { | ||
| 77 | ReferenceChain left = (ReferenceChain) lhs; | ||
| 78 | ReferenceChain right = (ReferenceChain) rhs; | ||
| 79 | Root leftR = left.getObj().getRoot(); | ||
| 80 | Root rightR = right.getObj().getRoot(); | ||
| 81 | int d = leftR.getType() - rightR.getType(); | ||
| 82 | if (d != 0) { | ||
| 83 | return -d; // More interesting values are *higher* | ||
| 84 | } | ||
| 85 | return left.getDepth() - right.getDepth(); | ||
| 86 | } | ||
| 87 | }); | ||
| 88 | |||
| 89 | out.print("<h1>References to "); | ||
| 90 | printThing(target); | ||
| 91 | out.println("</h1>"); | ||
| 92 | int lastType = Root.INVALID_TYPE; | ||
| 93 | for (int i= 0; i < refs.length; i++) { | ||
| 94 | ReferenceChain ref = refs[i]; | ||
| 95 | Root root = ref.getObj().getRoot(); | ||
| 96 | if (root.getType() != lastType) { | ||
| 97 | lastType = root.getType(); | ||
| 98 | out.print("<h2>"); | ||
| 99 | print(root.getTypeName() + " References"); | ||
| 100 | out.println("</h2>"); | ||
| 101 | } | ||
| 102 | out.print("<h3>"); | ||
| 103 | printRoot(root); | ||
| 104 | if (root.getReferer() != null) { | ||
| 105 | out.print("<small> (from "); | ||
| 106 | printThingAnchorTag(root.getReferer().getId()); | ||
| 107 | print(root.getReferer().toString()); | ||
| 108 | out.print(")</a></small>"); | ||
| 109 | |||
| 110 | } | ||
| 111 | out.print(" :</h3>"); | ||
| 112 | while (ref != null) { | ||
| 113 | ReferenceChain next = ref.getNext(); | ||
| 114 | JavaHeapObject obj = ref.getObj(); | ||
| 115 | print("--> "); | ||
| 116 | printThing(obj); | ||
| 117 | if (next != null) { | ||
| 118 | print(" (" + | ||
| 119 | obj.describeReferenceTo(next.getObj(), snapshot) | ||
| 120 | + ":)"); | ||
| 121 | } | ||
| 122 | out.println("<br>"); | ||
| 123 | ref = next; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | out.println("<h2>Other queries</h2>"); | ||
| 128 | |||
| 129 | if (includeWeak) { | ||
| 130 | printAnchorStart(); | ||
| 131 | out.print("roots/"); | ||
| 132 | printHex(id); | ||
| 133 | out.print("\">"); | ||
| 134 | out.println("Exclude weak refs</a><br>"); | ||
| 135 | endHtml(); | ||
| 136 | } | ||
| 137 | |||
| 138 | if (!includeWeak) { | ||
| 139 | printAnchorStart(); | ||
| 140 | out.print("allRoots/"); | ||
| 141 | printHex(id); | ||
| 142 | out.print("\">"); | ||
| 143 | out.println("Include weak refs</a><br>"); | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | } | ||