0N/A/*
2362N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
245N/A/*
0N/A * The Original Code is HAT. The Initial Developer of the
0N/A * Original Code is Bill Foote, with contributions from others
245N/A * at JavaSoft/Sun.
0N/A */
0N/A
0N/Apackage com.sun.tools.hat.internal.server;
0N/A
0N/Aimport java.util.Vector;
0N/A
0N/Aimport com.sun.tools.hat.internal.model.*;
0N/Aimport com.sun.tools.hat.internal.util.ArraySorter;
0N/Aimport com.sun.tools.hat.internal.util.Comparer;
0N/A
0N/A/**
0N/A *
0N/A * @author Bill Foote
0N/A */
0N/A
0N/A
0N/Aclass RootsQuery extends QueryHandler {
0N/A
0N/A private boolean includeWeak;
0N/A
0N/A public RootsQuery(boolean includeWeak) {
0N/A this.includeWeak = includeWeak;
0N/A }
0N/A
0N/A public void run() {
0N/A long id = parseHex(query);
0N/A JavaHeapObject target = snapshot.findThing(id);
0N/A if (target == null) {
0N/A startHtml("Object not found for rootset");
0N/A error("object not found");
0N/A endHtml();
0N/A return;
0N/A }
0N/A if (includeWeak) {
0N/A startHtml("Rootset references to " + target
0N/A + " (includes weak refs)");
0N/A } else {
0N/A startHtml("Rootset references to " + target
0N/A + " (excludes weak refs)");
0N/A }
0N/A out.flush();
0N/A
0N/A ReferenceChain[] refs
0N/A = snapshot.rootsetReferencesTo(target, includeWeak);
0N/A ArraySorter.sort(refs, new Comparer() {
0N/A public int compare(Object lhs, Object rhs) {
0N/A ReferenceChain left = (ReferenceChain) lhs;
0N/A ReferenceChain right = (ReferenceChain) rhs;
0N/A Root leftR = left.getObj().getRoot();
0N/A Root rightR = right.getObj().getRoot();
0N/A int d = leftR.getType() - rightR.getType();
0N/A if (d != 0) {
0N/A return -d; // More interesting values are *higher*
0N/A }
0N/A return left.getDepth() - right.getDepth();
0N/A }
0N/A });
0N/A
0N/A out.print("<h1>References to ");
0N/A printThing(target);
0N/A out.println("</h1>");
0N/A int lastType = Root.INVALID_TYPE;
0N/A for (int i= 0; i < refs.length; i++) {
0N/A ReferenceChain ref = refs[i];
0N/A Root root = ref.getObj().getRoot();
0N/A if (root.getType() != lastType) {
0N/A lastType = root.getType();
0N/A out.print("<h2>");
0N/A print(root.getTypeName() + " References");
0N/A out.println("</h2>");
0N/A }
0N/A out.print("<h3>");
0N/A printRoot(root);
0N/A if (root.getReferer() != null) {
0N/A out.print("<small> (from ");
0N/A printThingAnchorTag(root.getReferer().getId());
0N/A print(root.getReferer().toString());
0N/A out.print(")</a></small>");
0N/A
0N/A }
0N/A out.print(" :</h3>");
0N/A while (ref != null) {
0N/A ReferenceChain next = ref.getNext();
0N/A JavaHeapObject obj = ref.getObj();
0N/A print("--> ");
0N/A printThing(obj);
0N/A if (next != null) {
0N/A print(" (" +
0N/A obj.describeReferenceTo(next.getObj(), snapshot)
0N/A + ":)");
0N/A }
0N/A out.println("<br>");
0N/A ref = next;
0N/A }
0N/A }
0N/A
0N/A out.println("<h2>Other queries</h2>");
0N/A
0N/A if (includeWeak) {
0N/A printAnchorStart();
0N/A out.print("roots/");
0N/A printHex(id);
0N/A out.print("\">");
0N/A out.println("Exclude weak refs</a><br>");
0N/A endHtml();
0N/A }
0N/A
0N/A if (!includeWeak) {
0N/A printAnchorStart();
0N/A out.print("allRoots/");
0N/A printHex(id);
0N/A out.print("\">");
0N/A out.println("Include weak refs</a><br>");
0N/A }
0N/A }
0N/A
0N/A}