1 /*
   2  * Copyright (c) 1997, 2013, 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.Iterator;
  37 
  38 /**
  39  *
  40  * @author      Bill Foote
  41  */
  42 
  43 
  44 class AllClassesQuery extends QueryHandler {
  45 
  46     boolean excludePlatform;
  47     boolean oqlSupported;
  48 
  49     public AllClassesQuery(boolean excludePlatform, boolean oqlSupported) {
  50         this.excludePlatform = excludePlatform;
  51         this.oqlSupported = oqlSupported;
  52     }
  53 
  54     public void run() {
  55         if (excludePlatform) {
  56             startHtml("All Classes (excluding platform)");
  57         } else {
  58             startHtml("All Classes (including platform)");
  59         }
  60 
  61         Iterator classes = snapshot.getClasses();
  62         String lastPackage = null;
  63         while (classes.hasNext()) {
  64             JavaClass clazz = (JavaClass) classes.next();
  65             if (excludePlatform && PlatformClasses.isPlatformClass(clazz)) {
  66                 // skip this..
  67                 continue;
  68             }
  69             String name = clazz.getName();
  70             int pos = name.lastIndexOf('.');
  71             String pkg;
  72             if (name.startsWith("[")) {         // Only in ancient heap dumps
  73                 pkg = "<Arrays>";
  74             } else if (pos == -1) {
  75                 pkg = "<Default Package>";
  76             } else {
  77                 pkg = name.substring(0, pos);
  78             }
  79             if (!pkg.equals(lastPackage)) {
  80                 out.print("<h2>Package ");
  81                 print(pkg);
  82                 out.println("</h2>");
  83             }
  84             lastPackage = pkg;
  85             printClass(clazz);
  86             if (clazz.getId() != -1) {
  87                 print(" [" + clazz.getIdString() + "]");
  88             }
  89             out.println("<br>");
  90         }
  91 
  92         out.println("<h2>Other Queries</h2>");
  93         out.println("<ul>");
  94 
  95         out.println("<li>");
  96         printAnchorStart();
  97         if (excludePlatform) {
  98             out.print("allClassesWithPlatform/\">");
  99             print("All classes including platform");
 100         } else {
 101             out.print("\">");
 102             print("All classes excluding platform");
 103         }
 104         out.println("</a>");
 105 
 106         out.println("<li>");
 107         printAnchorStart();
 108         out.print("showRoots/\">");
 109         print("Show all members of the rootset");
 110         out.println("</a>");
 111 
 112         out.println("<li>");
 113         printAnchorStart();
 114         out.print("showInstanceCounts/includePlatform/\">");
 115         print("Show instance counts for all classes (including platform)");
 116         out.println("</a>");
 117 
 118         out.println("<li>");
 119         printAnchorStart();
 120         out.print("showInstanceCounts/\">");
 121         print("Show instance counts for all classes (excluding platform)");
 122         out.println("</a>");
 123 
 124         out.println("<li>");
 125         printAnchorStart();
 126         out.print("histo/\">");
 127         print("Show heap histogram");
 128         out.println("</a>");
 129 
 130         out.println("<li>");
 131         printAnchorStart();
 132         out.print("finalizerSummary/\">");
 133         print("Show finalizer summary");
 134         out.println("</a>");
 135 
 136         if (oqlSupported) {
 137             out.println("<li>");
 138             printAnchorStart();
 139             out.print("oql/\">");
 140             print("Execute Object Query Language (OQL) query");
 141             out.println("</a>");
 142         }
 143 
 144         out.println("</ul>");
 145 
 146         endHtml();
 147     }
 148 
 149 
 150 }