hotspot/agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java
author kvn
Wed, 10 Sep 2008 18:23:32 -0700
changeset 1135 9487203e5789
parent 670 ddf3e9583f2f
child 4095 6e0acfda1d47
permissions -rw-r--r--
6706829: Compressed Oops: add debug info for narrow oops Summary: Add support for narrow oops in debug info to avoid decoding. Reviewed-by: rasbold, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
670
ddf3e9583f2f 6719955: Update copyright year
xdono
parents: 360
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.ui.classbrowser;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.asm.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.asm.sparc.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.asm.x86.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.asm.ia64.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.code.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.compiler.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import sun.jvm.hotspot.interpreter.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
import sun.jvm.hotspot.memory.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
import sun.jvm.hotspot.tools.jcore.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
public class HTMLGenerator implements /* imports */ ClassConstants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    static class Formatter {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
        boolean html;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
        StringBuffer buf = new StringBuffer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
        Formatter(boolean h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
            html = h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
        void append(String s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
            buf.append(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
        void append(int s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
            buf.append(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
        void append(char s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
            buf.append(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
        void append(StringBuffer s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
            buf.append(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
        void append(Formatter s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
            buf.append(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
        StringBuffer getBuffer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
            return buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
        public String toString() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
            return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
        void wrap(String tag, String text) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
            wrap(tag, tag, text);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
        void wrap(String before, String after, String text) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
            beginTag(before);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
            append(text);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
            endTag(after);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
        // header tags
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        void h1(String s) { nl(); wrap("h1", s); nl(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
        void h2(String s) { nl(); wrap("h2", s); nl(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        void h3(String s) { nl(); wrap("h3", s); nl(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        void h4(String s) { nl(); wrap("h4", s); nl(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
        // list tags
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        void beginList()  { beginTag("ul"); nl(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        void li(String s) { wrap("li", s); nl();  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
        void endList()    { endTag("ul"); nl();   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
        // table tags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
        void beginTable(int border) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
            beginTag("table border='" + border + "'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        void cell(String s) { wrap("td", s); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        void headerCell(String s) { wrap("th", s); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        void endTable() { endTag("table"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        void link(String href, String text) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
            wrap("a href='" + href + "'", "a", text);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        void beginTag(String s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
            if (html) { append("<"); append(s); append(">"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
        void endTag(String s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
            if (html) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
               append("</"); append(s); append(">");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
               if (s.equals("table") || s.equals("tr")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
                  nl();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
               if (s.equals("td") || s.equals("th")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
                  append(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
        void bold(String s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
            wrap("b", s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
        void nl() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
            if (!html) buf.append("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        void br() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
            if (html) append("<br>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
            else      append("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        void genEmptyHTML() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
            if (html) append("<html></html>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        void genHTMLPrologue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
            if (html) append("<html><body>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
        void genHTMLPrologue(String title) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
            if (html) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
                append("<html><head><title>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
                append(title);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
                append("</title></head>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
                append("<body>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
            h2(title);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        void genHTMLEpilogue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
            if (html) append("</body></html>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
   private static final String DUMP_KLASS_OUTPUT_DIR = ".";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
   private static final int NATIVE_CODE_SIZE = 200;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
   private final String spaces;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
   private final String tab;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
   private boolean genHTML = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
   public HTMLGenerator() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
       this(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
   public HTMLGenerator(boolean html) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
       genHTML = html;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
       if (html) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
           spaces = "&nbsp;&nbsp;";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
           tab = "&nbsp;&nbsp;&nbsp;&nbsp;";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
       } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
           spaces = "  ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
           tab = "    ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
   private static CPUHelper cpuHelper;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
   static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
         public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
            initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
   private static synchronized void initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      String cpu = VM.getVM().getCPU();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      if (cpu.equals("sparc")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
         cpuHelper = new SPARCHelper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      } else if (cpu.equals("x86")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
         cpuHelper = new X86Helper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      } else if (cpu.equals("ia64")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
         cpuHelper = new IA64Helper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
          throw new RuntimeException("cpu '" + cpu + "' is not yet supported!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
   protected static synchronized CPUHelper getCPUHelper() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      return cpuHelper;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
   protected String escapeHTMLSpecialChars(String value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      if (!genHTML) return value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      int len = value.length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      for (int i=0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
         char c = value.charAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
         switch (c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
            case '<':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
               buf.append("&lt;");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
            case '>':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
               buf.append("&gt;");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
            case '&':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
               buf.append("&amp;");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
            default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
               buf.append(c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
   public String genHTMLForMessage(String message) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      buf.genHTMLPrologue(message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
   public String genHTMLErrorMessage(Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      exp.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      return genHTMLForMessage(exp.getClass().getName() + " : " + exp.getMessage());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
   public String genHTMLForWait(String message) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      buf.genHTMLPrologue("Please wait ..");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      buf.h2(message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
   protected String genKlassTitle(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      AccessFlags acc = klass.getAccessFlagsObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      if (acc.isPublic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
         buf.append("public ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      } else if (acc.isProtected()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
         buf.append("protected ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      } else if (acc.isPrivate()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
         buf.append("private ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
      if (acc.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
         buf.append("static ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      if (acc.isAbstract() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
         buf.append("abstract ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      } else if (acc.isFinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
         buf.append("final ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      if (acc.isStrict()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
         buf.append("strict ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      // javac generated flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      if (acc.isEnum()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
         buf.append("[enum] ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      if (acc.isSynthetic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
         buf.append("[synthetic] ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      if (klass.isInterface()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
         buf.append("interface");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
         buf.append("class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      buf.append(' ');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      buf.append(klass.getName().asString().replace('/', '.'));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
      // is it generic?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      Symbol genSig = klass.getGenericSignature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      if (genSig != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
         buf.append(" [signature ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
         buf.append(escapeHTMLSpecialChars(genSig.asString()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
         buf.append("] ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
         buf.append(' ');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      buf.append('@');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
      buf.append(klass.getHandle().toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
   protected String genBaseHref() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      return "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
   protected String genKlassHref(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      return genBaseHref() + "klass=" + klass.getHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
   protected String genKlassLink(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      buf.link(genKlassHref(klass), genKlassTitle(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
   protected String genMethodModifierString(AccessFlags acc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      if (acc.isPrivate()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
         buf.append("private ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      } else if (acc.isProtected()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
         buf.append("protected ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      } else if (acc.isPublic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
         buf.append("public ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      if (acc.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
         buf.append("static ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      } else if (acc.isAbstract() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
         buf.append("abstract ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      } else if (acc.isFinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
         buf.append("final ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
       if (acc.isNative()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
         buf.append("native ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      if (acc.isStrict()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
         buf.append("strict ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      if (acc.isSynchronized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
         buf.append("synchronized ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
      // javac generated flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      if (acc.isBridge()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
         buf.append("[bridge] ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      if (acc.isSynthetic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
         buf.append("[synthetic] ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      if (acc.isVarArgs()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
         buf.append("[varargs] ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
   protected String genMethodNameAndSignature(Method method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      buf.append(genMethodModifierString(method.getAccessFlagsObj()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      Symbol sig = method.getSignature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      new SignatureConverter(sig, buf.getBuffer()).iterateReturntype();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      buf.append(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      String methodName = method.getName().asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      buf.append(escapeHTMLSpecialChars(methodName));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      buf.append('(');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      new SignatureConverter(sig, buf.getBuffer()).iterateParameters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      buf.append(')');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      // is it generic?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      Symbol genSig = method.getGenericSignature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
      if (genSig != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
         buf.append(" [signature ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
         buf.append(escapeHTMLSpecialChars(genSig.asString()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
         buf.append("] ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
      return buf.toString().replace('/', '.');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
   protected String genMethodTitle(Method method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      buf.append(genMethodNameAndSignature(method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
      buf.append(' ');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
      buf.append('@');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      buf.append(method.getHandle().toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
   protected String genMethodHref(Method m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      return genBaseHref() + "method=" + m.getHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
   protected String genMethodLink(Method m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      buf.link(genMethodHref(m), genMethodTitle(m));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
   protected String genMethodAndKlassLink(Method m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
      buf.append(genMethodLink(m));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
      buf.append(" of ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
      buf.append(genKlassLink((InstanceKlass) m.getMethodHolder()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
   protected String genNMethodHref(NMethod nm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
      return genBaseHref() + "nmethod=" + nm.getAddress();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
   public String genNMethodTitle(NMethod nmethod) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      Method m = nmethod.getMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
      buf.append("Disassembly for compiled method [");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
      buf.append(genMethodTitle(m));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      buf.append(" ] ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      buf.append('@');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
      buf.append(nmethod.getAddress().toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
   protected String genNMethodLink(NMethod nm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
      buf.link(genNMethodHref(nm), genNMethodTitle(nm));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
   public String genCodeBlobTitle(CodeBlob blob) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
      buf.append("Disassembly for code blob " + blob.getName() + " [");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      buf.append(blob.getClass().getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      buf.append(" ] @");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
      buf.append(blob.getAddress().toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
   protected BytecodeDisassembler createBytecodeDisassembler(Method m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
      return new BytecodeDisassembler(m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
   private String genLowHighShort(int val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      buf.append('#');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
      buf.append(Integer.toString(val & 0xFFFF));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
      buf.append(" #");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
      buf.append(Integer.toString((val >> 16) & 0xFFFF));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
   protected String genHTMLTableForConstantPool(ConstantPool cpool) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      buf.beginTable(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
      buf.beginTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
      buf.headerCell("Index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
      buf.headerCell("Constant Type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
      buf.headerCell("Constant Value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      buf.endTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
      final int length = (int) cpool.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
      // zero'th pool entry is always invalid. ignore it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
      for (int index = 1; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
         buf.beginTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
         buf.cell(Integer.toString(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
         int ctag = (int) cpool.getTags().getByteAt((int) index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
         switch (ctag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
            case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
               buf.cell("JVM_CONSTANT_Integer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
               buf.cell(Integer.toString(cpool.getIntAt(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
            case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
               buf.cell("JVM_CONSTANT_Float");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
               buf.cell(Float.toString(cpool.getFloatAt(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
            case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
               buf.cell("JVM_CONSTANT_Long");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
               buf.cell(Long.toString(cpool.getLongAt(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
               // long entries occupy two slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
               index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
            case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
               buf.cell("JVM_CONSTANT_Double");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
               buf.cell(Double.toString(cpool.getDoubleAt(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
               // double entries occupy two slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
               index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
            case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
               buf.cell("JVM_CONSTANT_UnresolvedClass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
               buf.cell(cpool.getSymbolAt(index).asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
            case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
               buf.cell("JVM_CONSTANT_Class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
               Klass klass = (Klass) cpool.getObjAt(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
               if (klass instanceof InstanceKlass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
                  buf.cell(genKlassLink((InstanceKlass) klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
               } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
                  buf.cell(klass.getName().asString().replace('/', '.'));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
            case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
               buf.cell("JVM_CONSTANT_UnresolvedString");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
               buf.cell("\"" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
                 escapeHTMLSpecialChars(cpool.getSymbolAt(index).asString()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
                 "\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
            case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
               buf.cell("JVM_CONSTANT_Utf8");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
               buf.cell("\"" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
                 escapeHTMLSpecialChars(cpool.getSymbolAt(index).asString()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
                 "\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
            case JVM_CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
               buf.cell("JVM_CONSTANT_String");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
               buf.cell("\"" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
                 escapeHTMLSpecialChars(OopUtilities.stringOopToString(cpool.getObjAt(index))) + "\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
            case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
               buf.cell("JVM_CONSTANT_Fieldref");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
               buf.cell(genLowHighShort(cpool.getIntAt(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
            case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
               buf.cell("JVM_CONSTANT_Methodref");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
               buf.cell(genLowHighShort(cpool.getIntAt(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
            case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
               buf.cell("JVM_CONSTANT_InterfaceMethodref");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
               buf.cell(genLowHighShort(cpool.getIntAt(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
            case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
               buf.cell("JVM_CONSTANT_NameAndType");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
               buf.cell(genLowHighShort(cpool.getIntAt(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
            case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
               buf.cell("JVM_CONSTANT_ClassIndex");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
               buf.cell(Integer.toString(cpool.getIntAt(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
            case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
               buf.cell("JVM_CONSTANT_StringIndex");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
               buf.cell(Integer.toString(cpool.getIntAt(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
               break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
         buf.endTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
      buf.endTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
   public String genHTML(ConstantPool cpool) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
         Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
         buf.genHTMLPrologue(genConstantPoolTitle(cpool));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
         buf.h3("Holder Class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
         buf.append(genKlassLink((InstanceKlass) cpool.getPoolHolder()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
         buf.h3("Constants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
         buf.append(genHTMLTableForConstantPool(cpool));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
         buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
   protected String genConstantPoolHref(ConstantPool cpool) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
      return genBaseHref() + "cpool=" + cpool.getHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
   protected String genConstantPoolTitle(ConstantPool cpool) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
      buf.append("Constant Pool of [");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
      buf.append(genKlassTitle((InstanceKlass) cpool.getPoolHolder()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
      buf.append("] @");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
      buf.append(cpool.getHandle().toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
   protected String genConstantPoolLink(ConstantPool cpool) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
      buf.link(genConstantPoolHref(cpool), genConstantPoolTitle(cpool));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
   public String genHTML(Method method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
         final Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
         buf.genHTMLPrologue(genMethodTitle(method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
         buf.h3("Holder Class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
         buf.append(genKlassLink((InstanceKlass) method.getMethodHolder()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
         NMethod nmethod = method.getNativeMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
         if (nmethod != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
            buf.h3("Compiled Code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
            buf.append(genNMethodLink(nmethod));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
         boolean hasThrows = method.hasCheckedExceptions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
         ConstantPool cpool = ((InstanceKlass) method.getMethodHolder()).getConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
         if (hasThrows) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
            buf.h3("Checked Exception(s)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
            CheckedExceptionElement[] exceptions = method.getCheckedExceptions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
            buf.beginTag("ul");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
            for (int exp = 0; exp < exceptions.length; exp++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
               short cpIndex = (short) exceptions[exp].getClassCPIndex();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
               Oop obj = cpool.getObjAt(cpIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
               if (obj instanceof Symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
                  buf.li(((Symbol)obj).asString().replace('/', '.'));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
               } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
                  buf.li(genKlassLink((InstanceKlass)obj));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
            buf.endTag("ul");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
         if (method.isNative() || method.isAbstract()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
           buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
           return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
         buf.h3("Bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
         BytecodeDisassembler disasm = createBytecodeDisassembler(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
         final boolean hasLineNumbers = method.hasLineNumberTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
         disasm.decode(new BytecodeVisitor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
                          private Method method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
                          public void prologue(Method m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
                             method = m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
                             buf.beginTable(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
                             buf.beginTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
                             if (hasLineNumbers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
                                buf.headerCell("line");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
                             buf.headerCell("bci" + spaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
                             buf.headerCell("bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
                             buf.endTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
                          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
                          public void visit(Bytecode instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
                             int curBci = instr.bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
                             buf.beginTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
                             if (hasLineNumbers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
                                int lineNumber = method.getLineNumberFromBCI(curBci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
                                buf.cell(Integer.toString(lineNumber) + spaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
                             buf.cell(Integer.toString(curBci) + spaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
                             buf.beginTag("td");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
                             String instrStr = escapeHTMLSpecialChars(instr.toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
                             if (instr instanceof BytecodeNew) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
                                BytecodeNew newBytecode = (BytecodeNew) instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
                                InstanceKlass klass = newBytecode.getNewKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
                                if (klass != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
                                    buf.link(genKlassHref(klass), instrStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
                                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
                                    buf.append(instrStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
                                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
                             } else if(instr instanceof BytecodeInvoke) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
                                BytecodeInvoke invokeBytecode = (BytecodeInvoke) instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
                                Method m = invokeBytecode.getInvokedMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
                                if (m != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
                                   buf.link(genMethodHref(m), instrStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
                                   buf.append(" of ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
                                   InstanceKlass klass = (InstanceKlass) m.getMethodHolder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
                                   buf.link(genKlassHref(klass), genKlassTitle(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
                                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
                                   buf.append(instrStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
                                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
                             } else if (instr instanceof BytecodeGetPut) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
                                BytecodeGetPut getPut = (BytecodeGetPut) instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
                                sun.jvm.hotspot.oops.Field f = getPut.getField();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
                                buf.append(instrStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
                                if (f != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
                                   InstanceKlass klass = f.getFieldHolder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
                                   buf.append(" of ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
                                   buf.link(genKlassHref(klass), genKlassTitle(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
                                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
                             } else if (instr instanceof BytecodeLoadConstant) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
                                BytecodeLoadConstant ldc = (BytecodeLoadConstant) instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
                                if (ldc.isKlassConstant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
                                   Oop oop = ldc.getKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
                                   if (oop instanceof Klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
                                      buf.append("<a href='");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
                                      buf.append(genKlassHref((InstanceKlass) oop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
                                      buf.append("'>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
                                      buf.append(instrStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
                                      buf.append("</a>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
                                   } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
                                      // unresolved klass literal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
                                      buf.append(instrStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
                                   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
                                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
                                   // not a klass literal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
                                   buf.append(instrStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
                                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
                             } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
                                buf.append(instrStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
                             buf.endTag("td");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
                             buf.endTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
                          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
                          public void epilogue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
                             buf.endTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
                          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
                       });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
         // display exception table for this method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
         TypeArray exceptionTable = method.getExceptionTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
         // exception table is 4 tuple array of shorts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
         int numEntries = (int)exceptionTable.getLength() / 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
         if (numEntries != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
            buf.h4("Exception Table");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
            buf.beginTable(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
            buf.beginTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
            buf.headerCell("start bci");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
            buf.headerCell("end bci");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
            buf.headerCell("handler bci");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
            buf.headerCell("catch type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
            buf.endTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
            for (int e = 0; e < numEntries; e += 4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
               buf.beginTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
               buf.cell(Integer.toString(exceptionTable.getIntAt(e)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
               buf.cell(Integer.toString(exceptionTable.getIntAt(e + 1)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
               buf.cell(Integer.toString(exceptionTable.getIntAt(e + 2)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
               short cpIndex = (short) exceptionTable.getIntAt(e + 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
               Oop obj = cpIndex == 0? null : cpool.getObjAt(cpIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
               if (obj == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
                  buf.cell("Any");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
               } else if (obj instanceof Symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
                  buf.cell(((Symbol)obj).asString().replace('/', '.'));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
               } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
                  buf.cell(genKlassLink((InstanceKlass)obj));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
               buf.endTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
            buf.endTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
         // display constant pool hyperlink
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
         buf.h3("Constant Pool");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
         buf.append(genConstantPoolLink(cpool));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
         buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
   protected Disassembler createDisassembler(long startPc, byte[] code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
      return getCPUHelper().createDisassembler(startPc, code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
   protected SymbolFinder createSymbolFinder() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
      return new DummySymbolFinder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
   // genHTML for a given address. Address may be a PC or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
   // methodOop or klassOop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
   public String genHTMLForAddress(String addrStr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
      return genHTML(parseAddress(addrStr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
   public String genHTML(sun.jvm.hotspot.debugger.Address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
      CodeBlob blob = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
         blob = (CodeBlob)VM.getVM().getCodeCache().findBlobUnsafe(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
         // ignore
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
      if (blob != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
         if (blob instanceof NMethod) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
            return genHTML((NMethod)blob);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
         } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
            // may be interpreter code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
            Interpreter interp = VM.getVM().getInterpreter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
            if (interp.contains(pc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
               InterpreterCodelet codelet = interp.getCodeletContaining(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
               return genHTML(codelet);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
            return genHTML(blob);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
      } else if (VM.getVM().getCodeCache().contains(pc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
         return "Unknown location in the CodeCache: " + pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
      // did not find nmethod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
      // try methodOop, klassOop and constantPoolOop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
         Oop obj = getOopAtAddress(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
         if (obj != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
            if (obj instanceof Method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
               return genHTML((Method) obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
            } else if (obj instanceof InstanceKlass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
               return genHTML((InstanceKlass) obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
            } else if (obj instanceof ConstantPool) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
               return genHTML((ConstantPool) obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
         // ignore
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
      // didn't find any. do raw disassembly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
      return genHTMLForRawDisassembly(pc, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
   protected byte[] readBuffer(sun.jvm.hotspot.debugger.Address addr, int size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
      byte[] buf = new byte[size];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
      for (int b = 0; b < size; b++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
         buf[b] = (byte) addr.getJByteAt(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
      return buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    public String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address startPc, int size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
         return genHTMLForRawDisassembly(startPc, null, readBuffer(startPc, size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
   protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address startPc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
                                             String prevPCs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
         return genHTMLForRawDisassembly(startPc, prevPCs, readBuffer(startPc, NATIVE_CODE_SIZE));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
   protected String genPCHref(long targetPc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
      return genBaseHref() + "pc=0x" + Long.toHexString(targetPc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
   protected String genMultPCHref(String pcs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
      StringBuffer buf = new StringBuffer(genBaseHref());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
      buf.append("pc_multiple=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
      buf.append(pcs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
   protected String genPCHref(long currentPc, sun.jvm.hotspot.asm.Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
      String href = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
      if (addr instanceof PCRelativeAddress) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
         PCRelativeAddress pcRelAddr = (PCRelativeAddress) addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
         href = genPCHref(currentPc + pcRelAddr.getDisplacement());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
      } else if(addr instanceof DirectAddress) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
         href =  genPCHref(((DirectAddress) addr).getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
      return href;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
   class RawCodeVisitor implements InstructionVisitor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
      private int instrSize = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
      private Formatter buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
      private SymbolFinder symFinder = createSymbolFinder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
      RawCodeVisitor(Formatter buf) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
         this.buf = buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
      public int getInstructionSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
         return  instrSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
      public void prologue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
      public void visit(long currentPc, Instruction instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
         String href = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
          if (instr.isCall()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
             CallInstruction call = (CallInstruction) instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
             sun.jvm.hotspot.asm.Address addr = call.getBranchDestination();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
             href = genPCHref(currentPc, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
          instrSize += instr.getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
          buf.append("0x");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
          buf.append(Long.toHexString(currentPc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
          buf.append(':');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
          buf.append(tab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
          if (href != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
             buf.link(href, instr.asString(currentPc, symFinder));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
             buf.append(instr.asString(currentPc, symFinder));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
          buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
      public void epilogue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
   };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
   protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
                                             String prevPCs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
                                             byte[] code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
         long startPc = addressToLong(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
         Disassembler disasm = createDisassembler(startPc, code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
         final Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
         buf.genHTMLPrologue("Disassembly @0x" + Long.toHexString(startPc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
         if (prevPCs != null && genHTML) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
             buf.beginTag("p");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
             buf.link(genMultPCHref(prevPCs), "show previous code ..");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
             buf.endTag("p");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
         buf.h3("Code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
         RawCodeVisitor visitor = new RawCodeVisitor(buf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
         disasm.decode(visitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
         if (genHTML) buf.beginTag("p");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
         Formatter tmpBuf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
         tmpBuf.append("0x");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
         tmpBuf.append(Long.toHexString(startPc + visitor.getInstructionSize()).toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
         tmpBuf.append(",0x");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
         tmpBuf.append(Long.toHexString(startPc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
         if (prevPCs != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
            tmpBuf.append(',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
            tmpBuf.append(prevPCs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
         if (genHTML) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
             buf.link(genMultPCHref(tmpBuf.toString()), "show more code ..");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
             buf.endTag("p");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
         buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
   protected String genSafepointInfo(NMethod nm, PCDesc pcDesc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
      ScopeDesc sd = nm.getScopeDescAt(pcDesc.getRealPC(nm));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
      Formatter tabs = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
      buf.beginTag("pre");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
      genScope(buf, tabs, sd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
      buf.endTag("pre");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
      buf.append(genOopMapInfo(nm, pcDesc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
    protected void genScope(Formatter buf, Formatter tabs, ScopeDesc sd) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
        if (sd == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
        genScope(buf, tabs, sd.sender());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
        buf.append(tabs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
        Method m = sd.getMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
        buf.append(genMethodAndKlassLink(m));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
        int bci = sd.getBCI();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
        buf.append(" @ bci = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
        buf.append(Integer.toString(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
        int line = m.getLineNumberFromBCI(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
        if (line != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
            buf.append(", line = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
            buf.append(Integer.toString(line));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
        List locals = sd.getLocals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
        if (locals != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
            buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
            buf.append(tabs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
            buf.append(genHTMLForLocals(sd, locals));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
        List expressions = sd.getExpressions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
        if (expressions != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
            buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
            buf.append(tabs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
            buf.append(genHTMLForExpressions(sd, expressions));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
        List monitors = sd.getMonitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
        if (monitors != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
            buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
            buf.append(tabs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
            buf.append(genHTMLForMonitors(sd, monitors));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
        tabs.append(tab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
        buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
   protected String genHTMLForOopMap(OopMap map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
      final int stack0 = VMRegImpl.getStack0().getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
      final class OopMapValueIterator {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
         final Formatter iterate(OopMapStream oms, String type, boolean printContentReg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
            Formatter tmpBuf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
            boolean found = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
            tmpBuf.beginTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
            tmpBuf.beginTag("td");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
            tmpBuf.append(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
            tmpBuf.endTag("td");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
            tmpBuf.endTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
            for (; ! oms.isDone(); oms.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
               OopMapValue omv = oms.getCurrent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
               if (omv == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
                  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
               found = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
               VMReg vmReg = omv.getReg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
               int reg = vmReg.getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
               if (reg < stack0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
                  tmpBuf.append(VMRegImpl.getRegisterName(vmReg.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
               } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
                  tmpBuf.append('[');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
                  tmpBuf.append(Integer.toString((reg - stack0) * 4));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
                  tmpBuf.append(']');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
               if (printContentReg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
                  tmpBuf.append(" = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
                  VMReg vmContentReg = omv.getContentReg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
                  int contentReg = vmContentReg.getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
                  tmpBuf.append(VMRegImpl.getRegisterName(vmContentReg.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
               tmpBuf.append(spaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
            tmpBuf.endTag("td");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
            tmpBuf.endTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
            return found ? tmpBuf : new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
      buf.beginTable(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
      OopMapValueIterator omvIterator = new OopMapValueIterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
      OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.OOP_VALUE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
      buf.append(omvIterator.iterate(oms, "Oop:", false));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
      oms = new OopMapStream(map, OopMapValue.OopTypes.VALUE_VALUE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
      buf.append(omvIterator.iterate(oms, "Value:", false));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1080
      oms = new OopMapStream(map, OopMapValue.OopTypes.NARROWOOP_VALUE);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1081
      buf.append(omvIterator.iterate(oms, "Oop:", false));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
      oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
      buf.append(omvIterator.iterate(oms, "Callee saved:",  true));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
      oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
      buf.append(omvIterator.iterate(oms, "Derived oop:", true));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
      buf.endTag("table");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
   protected String genOopMapInfo(NMethod nmethod, PCDesc pcDesc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
      OopMapSet mapSet = nmethod.getOopMaps();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
      int pcOffset = pcDesc.getPCOffset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
      OopMap map = mapSet.findMapAtOffset(pcOffset, VM.getVM().isDebugging());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
      if (map == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
         throw new IllegalArgumentException("no oopmap at safepoint!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
      return genOopMapInfo(map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
   protected String genOopMapInfo(OopMap map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
     Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
     buf.beginTag("pre");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
     buf.append("OopMap: ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
     buf.append(genHTMLForOopMap(map));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
     buf.endTag("pre");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
     return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
   protected String locationAsString(Location loc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
      if (loc.isIllegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
         buf.append("illegal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
         Location.Where  w  = loc.getWhere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
         Location.Type type = loc.getType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
         if (w == Location.Where.ON_STACK) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
            buf.append("stack[" + loc.getStackOffset() + "]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
         } else if (w == Location.Where.IN_REGISTER) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
            boolean isFloat = (type == Location.Type.FLOAT_IN_DBL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
                               type == Location.Type.DBL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
            int regNum = loc.getRegisterNumber();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
            VMReg vmReg = new VMReg(regNum);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
            buf.append(VMRegImpl.getRegisterName(vmReg.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
         buf.append(", ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
         if (type == Location.Type.NORMAL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
            buf.append("normal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
         } else if (type == Location.Type.OOP) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
            buf.append("oop");
1135
9487203e5789 6706829: Compressed Oops: add debug info for narrow oops
kvn
parents: 670
diff changeset
  1138
         } else if (type == Location.Type.NARROWOOP) {
9487203e5789 6706829: Compressed Oops: add debug info for narrow oops
kvn
parents: 670
diff changeset
  1139
            buf.append("narrowoop");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
         } else if (type == Location.Type.INT_IN_LONG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
            buf.append("int");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
         } else if (type == Location.Type.LNG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
            buf.append("long");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
         } else if (type == Location.Type.FLOAT_IN_DBL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
            buf.append("float");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
         } else if (type == Location.Type.DBL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
            buf.append("double");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
         } else if (type == Location.Type.ADDR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
            buf.append("address");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
         } else if (type == Location.Type.INVALID) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
            buf.append("invalid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
   private String scopeValueAsString(ScopeValue sv) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
      if (sv.isConstantInt()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
         buf.append("int ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
         ConstantIntValue intValue = (ConstantIntValue) sv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
         buf.append(Integer.toString(intValue.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
      } else if (sv.isConstantLong()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
         buf.append("long ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
         ConstantLongValue longValue = (ConstantLongValue) sv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
         buf.append(Long.toString(longValue.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
         buf.append("L");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
      } else if (sv.isConstantDouble()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
         buf.append("double ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
         ConstantDoubleValue dblValue = (ConstantDoubleValue) sv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
         buf.append(Double.toString(dblValue.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
         buf.append("D");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
      } else if (sv.isConstantOop()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
         buf.append("oop ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
         ConstantOopReadValue oopValue = (ConstantOopReadValue) sv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
         OopHandle oopHandle = oopValue.getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
         if (oopHandle != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
            buf.append(oopHandle.toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
         } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
            buf.append("null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
      } else if (sv.isLocation()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
         LocationValue lvalue = (LocationValue) sv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
         Location loc = lvalue.getLocation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
         if (loc != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
            buf.append(locationAsString(loc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
         } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
            buf.append("null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
   protected String genHTMLForScopeValues(ScopeDesc sd, boolean locals, List values) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
      int length = values.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
      buf.append(locals? "locals " : "expressions ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
      for (int i = 0; i < length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
         ScopeValue sv = (ScopeValue) values.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
         if (sv == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
            continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
         buf.append('(');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
         if (locals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
            Symbol name = sd.getMethod().getLocalVariableName(sd.getBCI(), i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
            if (name != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
               buf.append("'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
               buf.append(name.asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
               buf.append('\'');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
               buf.append("[");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
               buf.append(Integer.toString(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
               buf.append(']');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
         } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
            buf.append("[");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
            buf.append(Integer.toString(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
            buf.append(']');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
         buf.append(", ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
         buf.append(scopeValueAsString(sv));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
         buf.append(") ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
   protected String genHTMLForLocals(ScopeDesc sd, List locals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
      return genHTMLForScopeValues(sd, true, locals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
   protected String genHTMLForExpressions(ScopeDesc sd, List expressions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
      return genHTMLForScopeValues(sd, false, expressions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
   protected String genHTMLForMonitors(ScopeDesc sd, List monitors) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
      int length = monitors.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
      buf.append("monitors ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
      for (int i = 0; i < length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
         MonitorValue mv = (MonitorValue) monitors.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
         if (mv == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
            continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
         buf.append("(owner = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
         ScopeValue owner = mv.owner();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
         if (owner != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
            buf.append(scopeValueAsString(owner));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
         } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
            buf.append("null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
         buf.append(", lock = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
         Location loc = mv.basicLock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
         if (loc != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
            buf.append(locationAsString(loc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
         } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
            buf.append("null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
         buf.append(") ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
   public String genHTML(final NMethod nmethod) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
         final Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
         buf.genHTMLPrologue(genNMethodTitle(nmethod));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
         buf.h3("Method");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
         buf.append(genMethodAndKlassLink(nmethod.getMethod()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
         buf.h3("Compiled Code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
         sun.jvm.hotspot.debugger.Address codeBegin = nmethod.codeBegin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
         sun.jvm.hotspot.debugger.Address codeEnd   = nmethod.codeEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
         final int codeSize = (int)codeEnd.minus(codeBegin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
         final long startPc = addressToLong(codeBegin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
         final byte[] code = new byte[codeSize];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
         for (int i=0; i < code.length; i++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
            code[i] = codeBegin.getJByteAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
         final long verifiedEntryPoint = addressToLong(nmethod.getVerifiedEntryPoint());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
         final long entryPoint = addressToLong(nmethod.getEntryPoint());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
         final Map safepoints = nmethod.getSafepoints();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
         final SymbolFinder symFinder = createSymbolFinder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
         final Disassembler disasm = createDisassembler(startPc, code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
         class NMethodVisitor implements InstructionVisitor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
            boolean prevWasCall;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
            public void prologue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
               prevWasCall = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
            public void visit(long currentPc, Instruction instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
               String href = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
               if (instr.isCall()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
                  CallInstruction call = (CallInstruction) instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
                  sun.jvm.hotspot.asm.Address addr = call.getBranchDestination();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
                  href = genPCHref(currentPc, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
               if (currentPc == verifiedEntryPoint) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
                   buf.bold("Verified Entry Point"); buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
               if (currentPc == entryPoint) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
                   buf.bold(">Entry Point"); buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
               PCDesc pcDesc = (PCDesc) safepoints.get(longToAddress(currentPc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
               boolean isSafepoint = (pcDesc != null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
               if (isSafepoint && prevWasCall) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
                  buf.append(genSafepointInfo(nmethod, pcDesc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
               buf.append("0x");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
               buf.append(Long.toHexString(currentPc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
               buf.append(':');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
               buf.append(tab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
               if (href != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
                  buf.link(href, instr.asString(currentPc, symFinder));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
               } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
                  buf.append(instr.asString(currentPc, symFinder));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
               if (isSafepoint && !prevWasCall) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
                  buf.append(genSafepointInfo(nmethod, pcDesc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
               buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
               prevWasCall = instr.isCall();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
            public void epilogue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
         };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
         disasm.decode(new NMethodVisitor());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
         sun.jvm.hotspot.debugger.Address stubBegin = nmethod.stubBegin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
         if (stubBegin != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
            sun.jvm.hotspot.debugger.Address stubEnd   = nmethod.stubEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
            buf.h3("Stub");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
            long stubStartPc = addressToLong(stubBegin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
            long stubEndPc = addressToLong(stubEnd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
            int range = (int) (stubEndPc - stubStartPc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
            byte[] stubCode = readBuffer(stubBegin, range);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
            Disassembler disasm2 = createDisassembler(stubStartPc, stubCode);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
            disasm2.decode(new NMethodVisitor());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
         buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
  public String genHTML(final CodeBlob blob) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
         final Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
         buf.genHTMLPrologue(genCodeBlobTitle(blob));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
         buf.h3("CodeBlob");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
         buf.h3("Compiled Code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
         final sun.jvm.hotspot.debugger.Address codeBegin = blob.instructionsBegin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
         final int codeSize = blob.getInstructionsSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
         final long startPc = addressToLong(codeBegin);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
         final byte[] code = new byte[codeSize];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
         for (int i=0; i < code.length; i++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
            code[i] = codeBegin.getJByteAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
         final SymbolFinder symFinder = createSymbolFinder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
         final Disassembler disasm = createDisassembler(startPc, code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
         class CodeBlobVisitor implements InstructionVisitor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
            OopMapSet maps;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
            OopMap curMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
            int curMapIndex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
            long curMapOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
            public void prologue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
              maps = blob.getOopMaps();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
              if (maps != null && (maps.getSize() > 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
                curMap = maps.getMapAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
                if (curMap != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
                  curMapOffset = curMap.getOffset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
            public void visit(long currentPc, Instruction instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
               String href = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
               if (instr.isCall()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
                  CallInstruction call = (CallInstruction) instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
                  sun.jvm.hotspot.asm.Address addr = call.getBranchDestination();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
                  href = genPCHref(currentPc, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
               buf.append("0x");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
               buf.append(Long.toHexString(currentPc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
               buf.append(':');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
               buf.append(tab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
               if (href != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
                  buf.link(href, instr.asString(currentPc, symFinder));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
               } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
                   buf.append(instr.asString(currentPc, symFinder));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
               buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
               // See whether we have an oop map at this PC
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
               if (curMap != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
                 long curOffset = currentPc - startPc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
                 if (curOffset == curMapOffset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
                   buf.append(genOopMapInfo(curMap));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
                   if (++curMapIndex >= maps.getSize()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
                     curMap = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
                   } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
                     curMap = maps.getMapAt(curMapIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
                     if (curMap != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
                       curMapOffset = curMap.getOffset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
                     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
                   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
                 }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
            public void epilogue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
         };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
         disasm.decode(new CodeBlobVisitor());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
         buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
   protected String genInterpreterCodeletTitle(InterpreterCodelet codelet) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
      buf.append("Interpreter codelet [");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
      buf.append(codelet.codeBegin().toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
      buf.append(',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
      buf.append(codelet.codeEnd().toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
      buf.append(") - ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
      buf.append(codelet.getDescription());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
   protected String genInterpreterCodeletLinkPageHref(StubQueue stubq) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
      return genBaseHref() + "interp_codelets";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
   public String genInterpreterCodeletLinksPage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
      buf.genHTMLPrologue("Interpreter Codelets");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
      buf.beginTag("ul");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
      Interpreter interp = VM.getVM().getInterpreter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
      StubQueue code = interp.getCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
      InterpreterCodelet stub = (InterpreterCodelet) code.getFirst();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
      while (stub != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
         buf.beginTag("li");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
         sun.jvm.hotspot.debugger.Address addr = stub.codeBegin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
         buf.link(genPCHref(addressToLong(addr)), stub.getDescription() + " @" + addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
         buf.endTag("li");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
         stub = (InterpreterCodelet) code.getNext(stub);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
      buf.endTag("ul");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
      buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
   public String genHTML(InterpreterCodelet codelet) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
      buf.genHTMLPrologue(genInterpreterCodeletTitle(codelet));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
      Interpreter interp = VM.getVM().getInterpreter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
      StubQueue stubq = interp.getCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
      if (genHTML) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
         buf.beginTag("h3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
         buf.link(genInterpreterCodeletLinkPageHref(stubq), "View links for all codelets");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
         buf.endTag("h3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
         buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
      Stub prev = stubq.getPrev(codelet);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
      if (prev != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
         if (genHTML) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
            buf.beginTag("h3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
            buf.link(genPCHref(addressToLong(prev.codeBegin())), "View Previous Codelet");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
            buf.endTag("h3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
            buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
         } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
            buf.h3("Previous Codelet = 0x" + Long.toHexString(addressToLong(prev.codeBegin())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
      buf.h3("Code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
      long stubStartPc = addressToLong(codelet.codeBegin());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
      long stubEndPc = addressToLong(codelet.codeEnd());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
      int range = (int) (stubEndPc - stubStartPc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
      byte[] stubCode = readBuffer(codelet.codeBegin(), range);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
      Disassembler disasm = createDisassembler(stubStartPc, stubCode);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
      disasm.decode(new RawCodeVisitor(buf));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
      Stub next = stubq.getNext(codelet);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
      if (next != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
         if (genHTML) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
            buf.beginTag("h3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
            buf.link(genPCHref(addressToLong(next.codeBegin())), "View Next Codelet");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
            buf.endTag("h3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
         } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
            buf.h3("Next Codelet = 0x" + Long.toHexString(addressToLong(next.codeBegin())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
      buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
   protected String genDumpKlassesTitle(InstanceKlass[] klasses) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
      return (klasses.length == 1) ? "Create .class for this class"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
                                   : "Create .class for all classes";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
   protected String genDumpKlassesHref(InstanceKlass[] klasses) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
      StringBuffer buf = new StringBuffer(genBaseHref());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
      buf.append("jcore_multiple=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
      for (int k = 0; k < klasses.length; k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
         buf.append(klasses[k].getHandle().toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
         buf.append(',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
   protected String genDumpKlassesLink(InstanceKlass[] klasses) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
      if (!genHTML) return "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
      buf.link(genDumpKlassesHref(klasses), genDumpKlassesTitle(klasses));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
   public String genHTMLForKlassNames(InstanceKlass[] klasses) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
         Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
         buf.genHTMLPrologue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
         buf.h3(genDumpKlassesLink(klasses));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
         buf.append(genHTMLListForKlassNames(klasses));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
         buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
   protected String genHTMLListForKlassNames(InstanceKlass[] klasses) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
      final Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
      buf.beginTable(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
      for (int i = 0; i < klasses.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
         InstanceKlass ik = klasses[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
         buf.beginTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
         buf.cell(genKlassLink(ik));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
         buf.endTag("tr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
      buf.endTable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
   public String genHTMLForMethodNames(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
         Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
         buf.genHTMLPrologue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
         buf.append(genHTMLListForMethods(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
         buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
   protected String genHTMLListForMethods(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
      ObjArray methods = klass.getMethods();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
      int numMethods = (int) methods.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
      if (numMethods != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
         buf.h3("Methods");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
         buf.beginTag("ul");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
         for (int m = 0; m < numMethods; m++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
            Method mtd = (Method) methods.getObjAt(m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
            buf.li(genMethodLink(mtd) + ";");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
         buf.endTag("ul");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
   protected String genHTMLListForInterfaces(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
         Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
         ObjArray interfaces = klass.getLocalInterfaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
         int numInterfaces = (int) interfaces.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
         if (numInterfaces != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
            buf.h3("Interfaces");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
            buf.beginTag("ul");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
            for (int i = 0; i < numInterfaces; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
               InstanceKlass inf = (InstanceKlass) interfaces.getObjAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
               buf.li(genKlassLink(inf));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
            buf.endTag("ul");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
   protected String genFieldModifierString(AccessFlags acc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
      if (acc.isPrivate()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
         buf.append("private ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
      } else if (acc.isProtected()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
         buf.append("protected ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
      } else if (acc.isPublic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
         buf.append("public ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
      if (acc.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
         buf.append("static ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
      if (acc.isFinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
         buf.append("final ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
      if (acc.isVolatile()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
         buf.append("volatile ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
      if (acc.isTransient()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
         buf.append("transient ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
      // javac generated flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
      if (acc.isSynthetic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
         buf.append("[synthetic] ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
   public String genHTMLForFieldNames(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
         Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
         buf.genHTMLPrologue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
         buf.append(genHTMLListForFields(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
         buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
      } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
   protected String genHTMLListForFields(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
      TypeArray fields = klass.getFields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
      int numFields = (int) fields.getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
      ConstantPool cp = klass.getConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
      if (numFields != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
         buf.h3("Fields");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
         buf.beginList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
         for (int f = 0; f < numFields; f += InstanceKlass.NEXT_OFFSET) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
           int nameIndex = fields.getShortAt(f + InstanceKlass.NAME_INDEX_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
           int sigIndex  = fields.getShortAt(f + InstanceKlass.SIGNATURE_INDEX_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
           int genSigIndex = fields.getShortAt(f + InstanceKlass.GENERIC_SIGNATURE_INDEX_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
           Symbol f_name = cp.getSymbolAt(nameIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
           Symbol f_sig  = cp.getSymbolAt(sigIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
           Symbol f_genSig = (genSigIndex != 0)? cp.getSymbolAt(genSigIndex) : null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
           AccessFlags acc = new AccessFlags(fields.getShortAt(f + InstanceKlass.ACCESS_FLAGS_OFFSET));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
           buf.beginTag("li");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
           buf.append(genFieldModifierString(acc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
           buf.append(' ');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
           Formatter sigBuf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
           new SignatureConverter(f_sig, sigBuf.getBuffer()).dispatchField();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
           buf.append(sigBuf.toString().replace('/', '.'));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
           buf.append(' ');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
           buf.append(f_name.asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
           buf.append(';');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
           // is it generic?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
           if (f_genSig != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
              buf.append(" [signature ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
              buf.append(escapeHTMLSpecialChars(f_genSig.asString()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
              buf.append("] ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
           buf.endTag("li");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
         buf.endList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
   protected String genKlassHierarchyHref(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
      return genBaseHref() + "hierarchy=" + klass.getHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
   protected String genKlassHierarchyTitle(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
      buf.append("Class Hierarchy of ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
      buf.append(genKlassTitle(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
   protected String genKlassHierarchyLink(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
      buf.link(genKlassHierarchyHref(klass), genKlassHierarchyTitle(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
   protected String genHTMLListForSubKlasses(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
      Klass subklass = klass.getSubklassKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
      if (subklass != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
         buf.beginList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
         while (subklass != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
            if (subklass instanceof InstanceKlass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
               buf.li(genKlassLink((InstanceKlass)subklass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
            subklass = subklass.getNextSiblingKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
         buf.endList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
   public String genHTMLForKlassHierarchy(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
      buf.genHTMLPrologue(genKlassHierarchyTitle(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
      buf.beginTag("pre");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
      buf.append(genKlassLink(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
      buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
      StringBuffer tabs = new StringBuffer(tab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
      InstanceKlass superKlass = klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
      while ( (superKlass = (InstanceKlass) superKlass.getSuper()) != null ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
         buf.append(tabs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
         buf.append(genKlassLink(superKlass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
         tabs.append(tab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
         buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
      buf.endTag("pre");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
      // generate subklass list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
      Klass subklass = klass.getSubklassKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
      if (subklass != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
         buf.h3("Direct Subclasses");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
         buf.append(genHTMLListForSubKlasses(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
      buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
   protected String genDumpKlassHref(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
      return genBaseHref() + "jcore=" + klass.getHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
   protected String genDumpKlassLink(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
      if (!genHTML) return "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
      buf.link(genDumpKlassHref(klass), "Create .class File");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
   public String genHTML(InstanceKlass klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
      buf.genHTMLPrologue(genKlassTitle(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
      InstanceKlass superKlass = (InstanceKlass) klass.getSuper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
      if (genHTML) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
          // super class tree and subclass list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
          buf.beginTag("h3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
          buf.link(genKlassHierarchyHref(klass), "View Class Hierarchy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
          buf.endTag("h3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
      // jcore - create .class link
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
      buf.h3(genDumpKlassLink(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
      // super class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
      if (superKlass != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
         buf.h3("Super Class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
         buf.append(genKlassLink(superKlass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
      // interfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
      buf.append(genHTMLListForInterfaces(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
      // fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
      buf.append(genHTMLListForFields(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
      // methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
      buf.append(genHTMLListForMethods(klass));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
      // constant pool link
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
      buf.h3("Constant Pool");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
      buf.append(genConstantPoolLink(klass.getConstants()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
      buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
   protected sun.jvm.hotspot.debugger.Address parseAddress(String address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
      VM vm = VM.getVM();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
      sun.jvm.hotspot.debugger.Address addr = vm.getDebugger().parseAddress(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
      return addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
   protected long addressToLong(sun.jvm.hotspot.debugger.Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
      return VM.getVM().getDebugger().getAddressValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
   protected sun.jvm.hotspot.debugger.Address longToAddress(long addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
      return parseAddress("0x" + Long.toHexString(addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
   protected Oop getOopAtAddress(sun.jvm.hotspot.debugger.Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
      OopHandle oopHandle = addr.addOffsetToAsOopHandle(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
      return VM.getVM().getObjectHeap().newOop(oopHandle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
   protected Oop getOopAtAddress(String address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
      sun.jvm.hotspot.debugger.Address addr = parseAddress(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
      return getOopAtAddress(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
   private void dumpKlass(InstanceKlass kls) throws IOException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
      String klassName = kls.getName().asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
      klassName = klassName.replace('/', File.separatorChar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
      int index = klassName.lastIndexOf(File.separatorChar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
      File dir = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
      if (index != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
        String dirName = klassName.substring(0, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
        dir =  new File(DUMP_KLASS_OUTPUT_DIR,  dirName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
        dir = new File(DUMP_KLASS_OUTPUT_DIR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
      dir.mkdirs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
      File f = new File(dir, klassName.substring(klassName.lastIndexOf(File.separatorChar) + 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
                              + ".class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
      f.createNewFile();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
      FileOutputStream fis = new FileOutputStream(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
      ClassWriter cw = new ClassWriter(kls, fis);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
      cw.write();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
   public String genDumpKlass(InstanceKlass kls) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
         dumpKlass(kls);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
         Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
         buf.genHTMLPrologue(genKlassTitle(kls));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
         buf.append(".class created for ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
         buf.append(genKlassLink(kls));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
         buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
      } catch(IOException exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
         return genHTMLErrorMessage(exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
   protected String genJavaStackTraceTitle(JavaThread thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
      buf.append("Java Stack Trace for ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
      buf.append(thread.getThreadName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
   public String genHTMLForJavaStackTrace(JavaThread thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
      Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
      buf.genHTMLPrologue(genJavaStackTraceTitle(thread));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
      buf.append("Thread state = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
      buf.append(thread.getThreadState().toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
      buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
      buf.beginTag("pre");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
      for (JavaVFrame vf = thread.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
         Method method = vf.getMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
         buf.append(" - ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
         buf.append(genMethodLink(method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
         buf.append(" @bci = " + vf.getBCI());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
         int lineNumber = method.getLineNumberFromBCI(vf.getBCI());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
         if (lineNumber != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
            buf.append(", line = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
            buf.append(lineNumber);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
         sun.jvm.hotspot.debugger.Address pc = vf.getFrame().getPC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
         if (pc != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
            buf.append(", pc = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
            buf.link(genPCHref(addressToLong(pc)), pc.toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
         if (vf.isCompiledFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
            buf.append(" (Compiled");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
         else if (vf.isInterpretedFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
            buf.append(" (Interpreted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
         if (vf.mayBeImpreciseDbg()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
            buf.append("; information may be imprecise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
         buf.append(")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
         buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
      buf.endTag("pre");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
      buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
      return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
   public String genHTMLForHyperlink(String href) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
      if (href.startsWith("klass=")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
         href = href.substring(href.indexOf('=') + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
         Oop obj = getOopAtAddress(href);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
         if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
            Assert.that(obj instanceof InstanceKlass, "class= href with improper InstanceKlass!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
         return genHTML((InstanceKlass) obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
      } else if (href.startsWith("method=")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
         href = href.substring(href.indexOf('=') + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
         Oop obj = getOopAtAddress(href);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
         if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
            Assert.that(obj instanceof Method, "method= href with improper Method!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
         return genHTML((Method) obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
      } else if (href.startsWith("nmethod=")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
         String addr = href.substring(href.indexOf('=') + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
         Object obj = VMObjectFactory.newObject(NMethod.class, parseAddress(addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
         if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
            Assert.that(obj instanceof NMethod, "nmethod= href with improper NMethod!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
         return genHTML((NMethod) obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
      } else if (href.startsWith("pc=")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
         String address = href.substring(href.indexOf('=') + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
         return genHTML(parseAddress(address));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
      } else if (href.startsWith("pc_multiple=")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
         int indexOfComma = href.indexOf(',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
         if (indexOfComma == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
            String firstPC = href.substring(href.indexOf('=') + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
            return genHTMLForRawDisassembly(parseAddress(firstPC), null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
         } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
            String firstPC = href.substring(href.indexOf('=') + 1, indexOfComma);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
            return genHTMLForRawDisassembly(parseAddress(firstPC), href.substring(indexOfComma + 1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
      } else if (href.startsWith("interp_codelets")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
         return genInterpreterCodeletLinksPage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
      } else if (href.startsWith("hierarchy=")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
         href = href.substring(href.indexOf('=') + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1967
         Oop obj = getOopAtAddress(href);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
         if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
            Assert.that(obj instanceof InstanceKlass, "class= href with improper InstanceKlass!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
         return genHTMLForKlassHierarchy((InstanceKlass) obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
      } else if (href.startsWith("cpool=")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
         href = href.substring(href.indexOf('=') + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
         Oop obj = getOopAtAddress(href);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
         if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
            Assert.that(obj instanceof ConstantPool, "cpool= href with improper ConstantPool!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
         return genHTML((ConstantPool) obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
      } else if (href.startsWith("jcore=")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
         href = href.substring(href.indexOf('=') + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
         Oop obj = getOopAtAddress(href);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
         if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
            Assert.that(obj instanceof InstanceKlass, "jcore= href with improper InstanceKlass!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
         return genDumpKlass((InstanceKlass) obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
      } else if (href.startsWith("jcore_multiple=")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
         href = href.substring(href.indexOf('=') + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
         Formatter buf = new Formatter(genHTML);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
         buf.genHTMLPrologue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
         StringTokenizer st = new StringTokenizer(href, ",");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
         while (st.hasMoreTokens()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
            Oop obj = getOopAtAddress(st.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
            if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
               Assert.that(obj instanceof InstanceKlass, "jcore_multiple= href with improper InstanceKlass!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
            InstanceKlass kls = (InstanceKlass) obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
            try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
               dumpKlass(kls);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2000
               buf.append(".class created for ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
               buf.append(genKlassLink(kls));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
            } catch(Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
               buf.bold("can't .class for " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
                        genKlassTitle(kls) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
                        " : " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
                        exp.getMessage());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
            buf.br();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
         buf.genHTMLEpilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
         return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
         if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
            Assert.that(false, "unknown href link!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
         return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
}