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