hotspot/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java
author mikael
Tue, 24 Dec 2013 11:48:39 -0800
changeset 22234 da823d78ad65
parent 20011 d74937287461
child 34665 9fdcc78b5398
permissions -rw-r--r--
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013 Summary: Copyright year updated for files modified during 2013 Reviewed-by: twisti, iveresov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 20011
diff changeset
     2
 * Copyright (c) 2005, 2013, 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;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
16357
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    27
import java.io.BufferedOutputStream;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    28
import java.io.BufferedReader;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    29
import java.io.ByteArrayOutputStream;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    30
import java.io.FileInputStream;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    31
import java.io.FileOutputStream;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    32
import java.io.IOException;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    33
import java.io.InputStreamReader;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    34
import java.io.PrintStream;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    35
import java.util.ArrayList;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    36
import java.util.Arrays;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    37
import java.util.Comparator;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    38
import java.util.HashMap;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    39
import java.util.HashSet;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    40
import java.util.Iterator;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    41
import java.util.Stack;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    42
import java.util.regex.Matcher;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    43
import java.util.regex.Pattern;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
16357
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    45
import sun.jvm.hotspot.ci.ciEnv;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    46
import sun.jvm.hotspot.code.CodeBlob;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    47
import sun.jvm.hotspot.code.CodeCacheVisitor;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    48
import sun.jvm.hotspot.code.NMethod;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    49
import sun.jvm.hotspot.debugger.Address;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    50
import sun.jvm.hotspot.debugger.OopHandle;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    51
import sun.jvm.hotspot.memory.SymbolTable;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    52
import sun.jvm.hotspot.memory.SystemDictionary;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    53
import sun.jvm.hotspot.memory.Universe;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    54
import sun.jvm.hotspot.oops.DefaultHeapVisitor;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    55
import sun.jvm.hotspot.oops.HeapVisitor;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    56
import sun.jvm.hotspot.oops.InstanceKlass;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    57
import sun.jvm.hotspot.oops.Klass;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    58
import sun.jvm.hotspot.oops.Metadata;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    59
import sun.jvm.hotspot.oops.Method;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    60
import sun.jvm.hotspot.oops.MethodData;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    61
import sun.jvm.hotspot.oops.Oop;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    62
import sun.jvm.hotspot.oops.RawHeapVisitor;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    63
import sun.jvm.hotspot.oops.Symbol;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    64
import sun.jvm.hotspot.oops.UnknownOopException;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    65
import sun.jvm.hotspot.opto.Compile;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    66
import sun.jvm.hotspot.opto.InlineTree;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    67
import sun.jvm.hotspot.runtime.CompiledVFrame;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    68
import sun.jvm.hotspot.runtime.CompilerThread;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    69
import sun.jvm.hotspot.runtime.JavaThread;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    70
import sun.jvm.hotspot.runtime.JavaVFrame;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    71
import sun.jvm.hotspot.runtime.Threads;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    72
import sun.jvm.hotspot.runtime.VM;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
import sun.jvm.hotspot.tools.ObjectHistogram;
16357
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    74
import sun.jvm.hotspot.tools.PMap;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    75
import sun.jvm.hotspot.tools.PStack;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
import sun.jvm.hotspot.tools.StackTrace;
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
    77
import sun.jvm.hotspot.tools.jcore.ClassDump;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
    78
import sun.jvm.hotspot.tools.jcore.ClassFilter;
16357
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    79
import sun.jvm.hotspot.types.CIntegerType;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    80
import sun.jvm.hotspot.types.Field;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    81
import sun.jvm.hotspot.types.Type;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    82
import sun.jvm.hotspot.types.basic.BasicType;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    83
import sun.jvm.hotspot.ui.classbrowser.HTMLGenerator;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    84
import sun.jvm.hotspot.ui.tree.CTypeTreeNodeAdapter;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    85
import sun.jvm.hotspot.ui.tree.OopTreeNodeAdapter;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    86
import sun.jvm.hotspot.ui.tree.SimpleTreeNode;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    87
import sun.jvm.hotspot.utilities.AddressOps;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    88
import sun.jvm.hotspot.utilities.Assert;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    89
import sun.jvm.hotspot.utilities.HeapProgressThunk;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    90
import sun.jvm.hotspot.utilities.LivenessPathElement;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    91
import sun.jvm.hotspot.utilities.MethodArray;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    92
import sun.jvm.hotspot.utilities.ObjectReader;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    93
import sun.jvm.hotspot.utilities.PointerFinder;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    94
import sun.jvm.hotspot.utilities.PointerLocation;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    95
import sun.jvm.hotspot.utilities.ReversePtrs;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    96
import sun.jvm.hotspot.utilities.ReversePtrsAnalysis;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    97
import sun.jvm.hotspot.utilities.RobustOopDeterminator;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    98
import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
    99
import sun.jvm.hotspot.utilities.soql.JSJavaFactory;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
   100
import sun.jvm.hotspot.utilities.soql.JSJavaFactoryImpl;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
   101
import sun.jvm.hotspot.utilities.soql.JSJavaScriptEngine;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
public class CommandProcessor {
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 16357
diff changeset
   104
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 16357
diff changeset
   105
    volatile boolean quit;
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 16357
diff changeset
   106
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    public abstract static class DebuggerInterface {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
        public abstract HotSpotAgent getAgent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        public abstract boolean isAttached();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
        public abstract void attach(String pid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
        public abstract void attach(String java, String core);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        public abstract void detach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
        public abstract void reattach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   116
    public static class BootFilter implements ClassFilter {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   117
        public boolean canInclude(InstanceKlass kls) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   118
            return kls.getClassLoader() == null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   119
        }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   120
    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   121
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   122
    public static class NonBootFilter implements ClassFilter {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   123
        private HashMap emitted = new HashMap();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   124
        public boolean canInclude(InstanceKlass kls) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   125
            if (kls.getClassLoader() == null) return false;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   126
            if (emitted.get(kls.getName()) != null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   127
                // Since multiple class loaders are being shoved
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   128
                // together duplicate classes are a possibilty.  For
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   129
                // now just ignore them.
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   130
                return false;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   131
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   132
            emitted.put(kls.getName(), kls);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   133
            return true;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   134
        }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   135
    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   136
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    static class Tokens {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
        final String input;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
        String[] tokens;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        int length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        String[] splitWhitespace(String cmd) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
            String[] t = cmd.split("\\s");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
            if (t.length == 1 && t[0].length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
                return new String[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
            return t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        void add(String s, ArrayList t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
            if (s.length() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
                t.add(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
        Tokens(String cmd) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
            input = cmd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
            // check for quoting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
            int quote = cmd.indexOf('"');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
            ArrayList t = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
            if (quote != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
                while (cmd.length() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
                    if (quote != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
                        int endquote = cmd.indexOf('"', quote + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                        if (endquote == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
                            throw new RuntimeException("mismatched quotes: " + input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
                        String before = cmd.substring(0, quote).trim();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
                        String quoted = cmd.substring(quote + 1, endquote);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
                        cmd = cmd.substring(endquote + 1).trim();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
                        if (before.length() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
                            String[] w = splitWhitespace(before);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
                            for (int i = 0; i < w.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
                                add(w[i], t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
                        add(quoted, t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                        quote = cmd.indexOf('"');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
                    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
                        String[] w = splitWhitespace(cmd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
                        for (int i = 0; i < w.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
                            add(w[i], t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
                        cmd = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
                String[] w = splitWhitespace(cmd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
                for (int i = 0; i < w.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
                    add(w[i], t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
            tokens = (String[])t.toArray(new String[0]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
            i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
            length = tokens.length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
            //for (int i = 0; i < tokens.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
            //    System.out.println("\"" + tokens[i] + "\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
            //}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
        String nextToken() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
            return tokens[i++];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
        boolean hasMoreTokens() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
            return i < length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
        int countTokens() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
            return length - i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        void trim(int n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
            if (length >= n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
                length -= n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
                throw new IndexOutOfBoundsException(String.valueOf(n));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
        String join(String sep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
            StringBuffer result = new StringBuffer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
            for (int w = i; w < length; w++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
                result.append(tokens[w]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
                if (w + 1 < length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
                    result.append(sep);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
            return result.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        String at(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
            if (i < 0 || i >= length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
                throw new IndexOutOfBoundsException(String.valueOf(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
            return tokens[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    abstract class Command {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        Command(String n, String u, boolean ok) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
            name = n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
            usage = u;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
            okIfDisconnected = ok;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        Command(String n, boolean ok) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
            name = n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
            usage = n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
            okIfDisconnected = ok;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
        final String name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        final String usage;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        final boolean okIfDisconnected;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        abstract void doit(Tokens t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        void usage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
            out.println("Usage: " + usage);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
        void printOopValue(Oop oop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
            if (oop != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
                Klass k = oop.getKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
                Symbol s = k.getName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
                if (s != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
                    out.print("Oop for " + s.asString() + " @ ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
                    out.print("Oop @ ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
                Oop.printOopAddressOn(oop, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
                out.print("null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
        void printNode(SimpleTreeNode node) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
            int count = node.getChildCount();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
            for (int i = 0; i < count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
                try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
                    SimpleTreeNode field = node.getChild(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
                    if (field instanceof OopTreeNodeAdapter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
                        out.print(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
                        out.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
                        printOopValue(((OopTreeNodeAdapter)field).getOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
                        out.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
                    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
                        out.println(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
                } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
                    out.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
                    out.println("Error: " + e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
                    if (verboseExceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
                        e.printStackTrace(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    void quote(String s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
        if (s.indexOf(" ") == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
            out.print(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
            out.print("\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
            out.print(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
            out.print("\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    void dumpType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
        out.print("type ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
        quote(type.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
        out.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
        if (type.getSuperclass() != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
            quote(type.getSuperclass().getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
            out.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
            out.print("null ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
        out.print(type.isOopType());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
        out.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
        if (type.isCIntegerType()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
            out.print("true ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
            out.print(((CIntegerType)type).isUnsigned());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
            out.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
            out.print("false false ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
        out.print(type.getSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
        out.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    void dumpFields(Type type) {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   336
        dumpFields(type, true);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   337
    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   338
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   339
    void dumpFields(Type type, boolean allowStatic) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
        Iterator i = type.getFields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
        while (i.hasNext()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
            Field f = (Field) i.next();
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   343
            if (!allowStatic && f.isStatic()) continue;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
            out.print("field ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
            quote(type.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
            out.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
            out.print(f.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
            out.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
            quote(f.getType().getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
            out.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
            out.print(f.isStatic());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
            out.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
            if (f.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
                out.print("0 ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
                out.print(f.getStaticFieldAddress());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
                out.print(f.getOffset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
                out.print(" 0x0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
            out.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    Address lookup(String symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
        if (symbol.indexOf("::") != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
            String[] parts = symbol.split("::");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
            StringBuffer mangled = new StringBuffer("__1c");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
            for (int i = 0; i < parts.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
                int len = parts[i].length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
                if (len >= 26) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
                    mangled.append((char)('a' + (len / 26)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
                    len = len % 26;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
                mangled.append((char)('A' + len));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
                mangled.append(parts[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
            mangled.append("_");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
            symbol = mangled.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
        return VM.getVM().getDebugger().lookup(null, symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    Address parseAddress(String addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
        return VM.getVM().getDebugger().parseAddress(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    private final Command[] commandList = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
        new Command("reattach", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
                int tokens = t.countTokens();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
                if (tokens != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
                    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
                preAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
                debugger.reattach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
                postAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
        new Command("attach", "attach pid | exec core", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
                int tokens = t.countTokens();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
                if (tokens == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
                    preAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
                    debugger.attach(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
                    postAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
                } else if (tokens == 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
                    preAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
                    debugger.attach(t.nextToken(), t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
                    postAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
        new Command("detach", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
                if (t.countTokens() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
                    debugger.detach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
        new Command("examine", "examine [ address/count ] | [ address,address]", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
            Pattern args1 = Pattern.compile("^(0x[0-9a-f]+)(/([0-9]*)([a-z]*))?$");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
            Pattern args2 = Pattern.compile("^(0x[0-9a-f]+),(0x[0-9a-f]+)(/[a-z]*)?$");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
            String fill(Address a, int width) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
                String s = "0x0";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
                if (a != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
                    s = a.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
                if (s.length() != width) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
                    return s.substring(0, 2) + "000000000000000000000".substring(0, width - s.length()) + s.substring(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
                return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
                if (t.countTokens() != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
                    String arg = t.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
                    Matcher m1 = args1.matcher(arg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
                    Matcher m2 = args2.matcher(arg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
                    Address start = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
                    Address end   = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
                    String format = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
                    int formatSize = (int)VM.getVM().getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
                    if (m1.matches()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
                        start = VM.getVM().getDebugger().parseAddress(m1.group(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
                        int count = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
                        if (m1.group(2) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
                            count = Integer.parseInt(m1.group(3));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
                        end = start.addOffsetTo(count * formatSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
                    } else if (m2.matches()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
                        start = VM.getVM().getDebugger().parseAddress(m2.group(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
                        end   = VM.getVM().getDebugger().parseAddress(m2.group(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
                    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
                        usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
                        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
                    int line = 80;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
                    int formatWidth = formatSize * 8 / 4 + 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
                    out.print(fill(start, formatWidth));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
                    out.print(": ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
                    int width = line - formatWidth - 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
                    boolean needsPrintln = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
                    while (start != null && start.lessThan(end)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
                        Address val = start.getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
                        out.print(fill(val, formatWidth));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
                        needsPrintln = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
                        width -= formatWidth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
                        start = start.addOffsetTo(formatSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
                        if (width <= formatWidth) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
                            out.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
                            needsPrintln = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
                            if (start.lessThan(end)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
                                out.print(fill(start, formatWidth));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
                                out.print(": ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
                                width = line - formatWidth - 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
                        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
                            out.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
                            width -= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
                    if (needsPrintln) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
                        out.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
        },
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   500
        new Command("dumpreplaydata", "dumpreplaydata { <address > | -a | <thread_id> }", false) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   501
            // This is used to dump replay data from ciInstanceKlass, ciMethodData etc
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   502
            // default file name is replay.txt, also if java crashes in compiler
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   503
            // thread, this file will be dumped in error processing.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   504
            public void doit(Tokens t) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   505
                if (t.countTokens() != 1) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   506
                    usage();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   507
                    return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   508
                }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   509
                String name = t.nextToken();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   510
                Address a = null;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   511
                try {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   512
                    a = VM.getVM().getDebugger().parseAddress(name);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   513
                } catch (NumberFormatException e) { }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   514
                if (a != null) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   515
                    // only nmethod, Method, MethodData and InstanceKlass needed to
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   516
                    // dump replay data
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   517
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   518
                    CodeBlob cb = VM.getVM().getCodeCache().findBlob(a);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   519
                    if (cb != null && (cb instanceof NMethod)) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   520
                        ((NMethod)cb).dumpReplayData(out);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   521
                        return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   522
                    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   523
                    // assume it is Metadata
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   524
                    Metadata meta = Metadata.instantiateWrapperFor(a);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   525
                    if (meta != null) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   526
                        meta.dumpReplayData(out);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   527
                    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   528
                        usage();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   529
                        return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   530
                    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   531
                }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   532
                // Not an address
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   533
                boolean all = name.equals("-a");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   534
                Threads threads = VM.getVM().getThreads();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   535
                for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   536
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   537
                    thread.printThreadIDOn(new PrintStream(bos));
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   538
                    if (all || bos.toString().equals(name)) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   539
                        if (thread instanceof CompilerThread) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   540
                            CompilerThread ct = (CompilerThread)thread;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   541
                            ciEnv env = ct.env();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   542
                            if (env != null) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   543
                               env.dumpReplayData(out);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   544
                            }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   545
                        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   546
                    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   547
                }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   548
            }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   549
        },
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   550
        new Command("buildreplayjars", "buildreplayjars [ all | app | boot ]  | [ prefix ]", false) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   551
            // This is used to dump jar files of all the classes
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   552
            // loaded in the core.  Everything on the bootclasspath
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   553
            // will go in boot.jar and everything else will go in
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   554
            // app.jar.  Then the classes can be loaded by the replay
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   555
            // jvm using -Xbootclasspath/p:boot.jar -cp app.jar. boot.jar usually
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   556
            // not needed, unless changed by jvmti.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   557
            public void doit(Tokens t) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   558
                int tcount = t.countTokens();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   559
                if (tcount > 2) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   560
                    usage();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   561
                    return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   562
                }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   563
                try {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   564
                   String prefix = "";
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   565
                   String option = "all"; // default
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   566
                   switch(tcount) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   567
                       case 0:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   568
                           break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   569
                       case 1:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   570
                           option = t.nextToken();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   571
                           if (!option.equalsIgnoreCase("all") && !option.equalsIgnoreCase("app") &&
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   572
                               !option.equalsIgnoreCase("root")) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   573
                              prefix = option;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   574
                              option = "all";
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   575
                           }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   576
                           break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   577
                       case 2:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   578
                           option = t.nextToken();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   579
                           prefix = t.nextToken();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   580
                           break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   581
                       default:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   582
                           usage();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   583
                           return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   584
                   }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   585
                   if (!option.equalsIgnoreCase("all") && !option.equalsIgnoreCase("app") &&
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   586
                               !option.equalsIgnoreCase("boot")) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   587
                       usage();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   588
                       return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   589
                   }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   590
                   ClassDump cd = new ClassDump();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   591
                   if (option.equalsIgnoreCase("all") || option.equalsIgnoreCase("boot")) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   592
                     cd.setClassFilter(new BootFilter());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   593
                     cd.setJarOutput(prefix + "boot.jar");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   594
                     cd.run();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   595
                   }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   596
                   if (option.equalsIgnoreCase("all") || option.equalsIgnoreCase("app")) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   597
                     cd.setClassFilter(new NonBootFilter());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   598
                     cd.setJarOutput(prefix + "app.jar");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   599
                     cd.run();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   600
                   }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   601
                } catch (IOException ioe) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   602
                   ioe.printStackTrace();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   603
                }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   604
            }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13873
diff changeset
   605
        },
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
        new Command("findpc", "findpc address", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
                if (t.countTokens() != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
                    Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
                    PointerLocation loc = PointerFinder.find(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
                    loc.printOn(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
        },
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   617
        new Command("symbol", "symbol address", false) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   618
            public void doit(Tokens t) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   619
                if (t.countTokens() != 1) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   620
                    usage();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   621
                } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   622
                    Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   623
                    Symbol.create(a).printValueOn(out);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   624
                    out.println();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   625
                }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   626
            }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   627
        },
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   628
        new Command("symboltable", "symboltable name", false) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   629
            public void doit(Tokens t) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   630
                if (t.countTokens() != 1) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   631
                    usage();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   632
                } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   633
                    out.println(SymbolTable.getTheTable().probe(t.nextToken()));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   634
                }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   635
            }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   636
        },
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   637
        new Command("symboldump", "symboldump", false) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   638
            public void doit(Tokens t) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   639
                SymbolTable.getTheTable().symbolsDo(new SymbolTable.SymbolVisitor() {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   640
                        public void visit(Symbol sym) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   641
                            sym.printValueOn(out);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   642
                            out.println();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   643
                        }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   644
                    });
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   645
            }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
   646
        },
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   647
        new Command("flags", "flags [ flag | -nd ]", false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
                int tokens = t.countTokens();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
                if (tokens != 0 && tokens != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
                    String name = tokens > 0 ? t.nextToken() : null;
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   654
                    boolean nonDefault = false;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   655
                    if (name != null && name.equals("-nd")) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   656
                        name = null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   657
                        nonDefault = true;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   658
                    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
                    VM.Flag[] flags = VM.getVM().getCommandLineFlags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
                    if (flags == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
                        out.println("Command Flag info not available (use 1.4.1_03 or later)!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
                    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
                        boolean printed = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
                        for (int f = 0; f < flags.length; f++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
                            VM.Flag flag = flags[f];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
                            if (name == null || flag.getName().equals(name)) {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   668
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   669
                                if (nonDefault && flag.getOrigin() == 0) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   670
                                    // only print flags which aren't their defaults
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   671
                                    continue;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   672
                                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   673
                                out.println(flag.getName() + " = " + flag.getValue() + " " + flag.getOrigin());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
                                printed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
                        if (name != null && !printed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
                            out.println("Couldn't find flag: " + name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
        new Command("help", "help [ command ]", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
                int tokens = t.countTokens();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
                Command cmd = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
                if (tokens == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
                    cmd = findCommand(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
                if (cmd != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
                    cmd.usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
                } else if (tokens == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
                    out.println("Available commands:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
                    Object[] keys = commands.keySet().toArray();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
                    Arrays.sort(keys, new Comparator() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
                             public int compare(Object o1, Object o2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
                                 return o1.toString().compareTo(o2.toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
                          });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
                    for (int i = 0; i < keys.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
                        out.print("  ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
                        out.println(((Command)commands.get(keys[i])).usage);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
        new Command("history", "history", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
                int tokens = t.countTokens();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
                if (tokens != 0 && (tokens != 1 || !t.nextToken().equals("-h"))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
                    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
                boolean printIndex = tokens == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
                for (int i = 0; i < history.size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
                    if (printIndex) out.print(i + " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
                    out.println(history.get(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
        },
13873
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   723
        // decode raw address
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   724
        new Command("dis", "dis address [length]", false) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   725
            public void doit(Tokens t) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   726
                int tokens = t.countTokens();
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   727
                if (tokens != 1 && tokens != 2) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   728
                    usage();
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   729
                    return;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   730
                }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   731
                String name = t.nextToken();
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   732
                Address addr = null;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   733
                int len = 0x10; // default length
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   734
                try {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   735
                    addr = VM.getVM().getDebugger().parseAddress(name);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   736
                } catch (NumberFormatException e) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   737
                   out.println(e);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   738
                   return;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   739
                }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   740
                if (tokens == 2) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   741
                    try {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   742
                        len = Integer.parseInt(t.nextToken());
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   743
                    } catch (NumberFormatException e) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   744
                        out.println(e);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   745
                        return;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   746
                    }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   747
                }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   748
                HTMLGenerator generator = new HTMLGenerator(false);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   749
                out.println(generator.genHTMLForRawDisassembly(addr, len));
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   750
            }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   751
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   752
        },
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   753
        // decode codeblob or nmethod
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   754
        new Command("disassemble", "disassemble address", false) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   755
            public void doit(Tokens t) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   756
                int tokens = t.countTokens();
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   757
                if (tokens != 1) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   758
                    usage();
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   759
                    return;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   760
                }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   761
                String name = t.nextToken();
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   762
                Address addr = null;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   763
                try {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   764
                    addr = VM.getVM().getDebugger().parseAddress(name);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   765
                } catch (NumberFormatException e) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   766
                   out.println(e);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   767
                   return;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   768
                }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   769
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   770
                HTMLGenerator generator = new HTMLGenerator(false);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   771
                out.println(generator.genHTML(addr));
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   772
            }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   773
        },
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   774
        // print Java bytecode disassembly
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   775
        new Command("jdis", "jdis address", false) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   776
            public void doit(Tokens t) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   777
                int tokens = t.countTokens();
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   778
                if (tokens != 1) {
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   779
                    usage();
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   780
                    return;
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   781
                }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   782
                Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   783
                Method m = (Method)Metadata.instantiateWrapperFor(a);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   784
                HTMLGenerator html = new HTMLGenerator(false);
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   785
                out.println(html.genHTML(m));
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   786
            }
7b72e3873785 6879063: SA should use hsdis for disassembly
minqi
parents: 13728
diff changeset
   787
        },
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   788
        new Command("revptrs", "revptrs address", false) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   789
            public void doit(Tokens t) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   790
                int tokens = t.countTokens();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   791
                if (tokens != 1 && (tokens != 2 || !t.nextToken().equals("-c"))) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   792
                    usage();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   793
                    return;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   794
                }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   795
                boolean chase = tokens == 2;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   796
                ReversePtrs revptrs = VM.getVM().getRevPtrs();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   797
                if (revptrs == null) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   798
                    out.println("Computing reverse pointers...");
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   799
                    ReversePtrsAnalysis analysis = new ReversePtrsAnalysis();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   800
                    final boolean[] complete = new boolean[1];
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   801
                    HeapProgressThunk thunk = new HeapProgressThunk() {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   802
                            public void heapIterationFractionUpdate(double d) {}
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   803
                            public synchronized void heapIterationComplete() {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   804
                                complete[0] = true;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   805
                                notify();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   806
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   807
                        };
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   808
                    analysis.setHeapProgressThunk(thunk);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   809
                    analysis.run();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   810
                    while (!complete[0]) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   811
                        synchronized (thunk) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   812
                            try {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   813
                                thunk.wait();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   814
                            } catch (Exception e) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   815
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   816
                        }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   817
                    }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   818
                    revptrs = VM.getVM().getRevPtrs();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   819
                    out.println("Done.");
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   820
                }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   821
                Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   822
                if (VM.getVM().getUniverse().heap().isInReserved(a)) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   823
                    OopHandle handle = a.addOffsetToAsOopHandle(0);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   824
                    Oop oop = VM.getVM().getObjectHeap().newOop(handle);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   825
                    ArrayList ptrs = revptrs.get(oop);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   826
                    if (ptrs == null) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   827
                        out.println("no live references to " + a);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   828
                    } else {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   829
                        if (chase) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   830
                            while (ptrs.size() == 1) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   831
                                LivenessPathElement e = (LivenessPathElement)ptrs.get(0);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   832
                                ByteArrayOutputStream bos = new ByteArrayOutputStream();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   833
                                Oop.printOopValueOn(e.getObj(), new PrintStream(bos));
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   834
                                out.println(bos.toString());
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   835
                                ptrs = revptrs.get(e.getObj());
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   836
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   837
                        } else {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   838
                            for (int i = 0; i < ptrs.size(); i++) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   839
                                LivenessPathElement e = (LivenessPathElement)ptrs.get(i);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   840
                                ByteArrayOutputStream bos = new ByteArrayOutputStream();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   841
                                Oop.printOopValueOn(e.getObj(), new PrintStream(bos));
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   842
                                out.println(bos.toString());
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   843
                                oop = e.getObj();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   844
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   845
                        }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   846
                    }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   847
                }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   848
            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
   849
        },
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   850
        new Command("printmdo", "printmdo [ -a | expression ]", false) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   851
            // Print every MDO in the heap or the one referenced by expression.
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   852
            public void doit(Tokens t) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   853
                if (t.countTokens() != 1) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   854
                    usage();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   855
                } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   856
                    String s = t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   857
                    if (s.equals("-a")) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   858
                        SystemDictionary sysDict = VM.getVM().getSystemDictionary();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   859
                        sysDict.allClassesDo(new SystemDictionary.ClassVisitor() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   860
                                public void visit(Klass k) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   861
                                    if (k instanceof InstanceKlass) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   862
                                        MethodArray methods = ((InstanceKlass)k).getMethods();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   863
                                        for (int i = 0; i < methods.length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   864
                                            Method m = methods.at(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   865
                                            MethodData mdo = m.getMethodData();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   866
                                            if (mdo != null) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   867
                                                out.println("MethodData " + mdo.getAddress() + " for " +
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   868
                                                    "method " + m.getMethodHolder().getName().asString() + "." +
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   869
                                                    m.getName().asString() +
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   870
                                                            m.getSignature().asString() + "@" + m.getAddress());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   871
                                                mdo.printDataOn(out);
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   872
                                    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   873
                                }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   874
                                    }
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   875
                                }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   876
                            }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   877
                            );
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   878
                    } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   879
                        Address a = VM.getVM().getDebugger().parseAddress(s);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   880
                        MethodData mdo = (MethodData) Metadata.instantiateWrapperFor(a);
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   881
                        mdo.printDataOn(out);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   882
                    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   883
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   884
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   885
        },
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   886
        new Command("printall", "printall", false) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   887
            // Print every MDO in the heap or the one referenced by expression.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   888
            public void doit(Tokens t) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   889
                if (t.countTokens() != 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   890
                    usage();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   891
                } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   892
                    SystemDictionary sysDict = VM.getVM().getSystemDictionary();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   893
                    sysDict.allClassesDo(new SystemDictionary.ClassVisitor() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   894
                            public void visit(Klass k) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   895
                                if (k instanceof InstanceKlass && ((InstanceKlass)k).getConstants().getCache() != null) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   896
                                    MethodArray methods = ((InstanceKlass)k).getMethods();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   897
                                    for (int i = 0; i < methods.length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   898
                                        Method m = methods.at(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   899
                                        HTMLGenerator gen = new HTMLGenerator(false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   900
                                        out.println(gen.genHTML(m));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   901
                                    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   902
                                }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   903
                            }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   904
                        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   905
                        );
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   906
                }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   907
            }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   908
        },
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   909
        new Command("dumpideal", "dumpideal { -a | id }", false) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   910
            // Do a full dump of the nodes reachabile from root in each compiler thread.
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   911
            public void doit(Tokens t) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   912
                if (t.countTokens() != 1) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   913
                    usage();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   914
                } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   915
                    String name = t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   916
                    boolean all = name.equals("-a");
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   917
                    Threads threads = VM.getVM().getThreads();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   918
                    for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   919
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   920
                        thread.printThreadIDOn(new PrintStream(bos));
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   921
                        if (all || bos.toString().equals(name)) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   922
                          if (thread instanceof CompilerThread) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   923
                            CompilerThread ct = (CompilerThread)thread;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   924
                            out.println(ct);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   925
                            ciEnv env = ct.env();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   926
                            if (env != null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   927
                              Compile c = env.compilerData();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   928
                              c.root().dump(9999, out);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   929
                            } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   930
                              out.println("  not compiling");
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   931
                            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   932
                          }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   933
                        }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   934
                    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   935
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   936
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   937
        },
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   938
        new Command("dumpcfg", "dumpcfg { -a | id }", false) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   939
            // Dump the PhaseCFG for every compiler thread that has one live.
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   940
            public void doit(Tokens t) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   941
                if (t.countTokens() != 1) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   942
                    usage();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   943
                } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   944
                    String name = t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   945
                    boolean all = name.equals("-a");
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   946
                    Threads threads = VM.getVM().getThreads();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   947
                    for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   948
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   949
                        thread.printThreadIDOn(new PrintStream(bos));
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   950
                        if (all || bos.toString().equals(name)) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   951
                          if (thread instanceof CompilerThread) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   952
                            CompilerThread ct = (CompilerThread)thread;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   953
                            out.println(ct);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   954
                            ciEnv env = ct.env();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   955
                            if (env != null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   956
                              Compile c = env.compilerData();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   957
                              c.cfg().dump(out);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   958
                            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   959
                          }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   960
                        }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   961
                    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   962
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   963
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   964
        },
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   965
        new Command("dumpilt", "dumpilt { -a | id }", false) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   966
            // dumps the InlineTree of a C2 compile
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   967
            public void doit(Tokens t) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   968
                if (t.countTokens() != 1) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   969
                    usage();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   970
                } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   971
                    String name = t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   972
                    boolean all = name.equals("-a");
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   973
                    Threads threads = VM.getVM().getThreads();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   974
                    for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   975
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   976
                        thread.printThreadIDOn(new PrintStream(bos));
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   977
                        if (all || bos.toString().equals(name)) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   978
                            if (thread instanceof CompilerThread) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   979
                                CompilerThread ct = (CompilerThread)thread;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   980
                                ciEnv env = ct.env();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   981
                                if (env != null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   982
                                    Compile c = env.compilerData();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   983
                                    InlineTree ilt = c.ilt();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   984
                                    if (ilt != null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   985
                                        ilt.print(out);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   986
                                    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   987
                                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   988
                            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   989
                        }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   990
                    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   991
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   992
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   993
        },
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   994
        new Command("vmstructsdump", "vmstructsdump", false) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   995
            public void doit(Tokens t) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   996
                if (t.countTokens() != 0) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   997
                    usage();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   998
                    return;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
   999
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1000
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1001
                // Dump a copy of the type database in a form that can
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1002
                // be read back.
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1003
                Iterator i = agent.getTypeDataBase().getTypes();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1004
                // Make sure the types are emitted in an order than can be read back in
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1005
                HashSet emitted = new HashSet();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1006
                Stack pending = new Stack();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1007
                while (i.hasNext()) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1008
                    Type n = (Type)i.next();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1009
                    if (emitted.contains(n.getName())) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1010
                        continue;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1011
                    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1012
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1013
                    while (n != null && !emitted.contains(n.getName())) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1014
                        pending.push(n);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1015
                        n = n.getSuperclass();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1016
                    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1017
                    while (!pending.empty()) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1018
                        n = (Type)pending.pop();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1019
                        dumpType(n);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1020
                        emitted.add(n.getName());
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1021
                    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1022
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1023
                i = agent.getTypeDataBase().getTypes();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1024
                while (i.hasNext()) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1025
                    dumpFields((Type)i.next(), false);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1026
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1027
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1028
        },
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1029
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
        new Command("inspect", "inspect expression", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
                if (t.countTokens() != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
                    Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
                    SimpleTreeNode node = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
                    if (VM.getVM().getUniverse().heap().isInReserved(a)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
                        OopHandle handle = a.addOffsetToAsOopHandle(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
                        Oop oop = VM.getVM().getObjectHeap().newOop(handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
                        node = new OopTreeNodeAdapter(oop, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
                        out.println("instance of " + node.getValue() + " @ " + a +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
                                    " (size = " + oop.getObjectSize() + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
                    } else if (VM.getVM().getCodeCache().contains(a)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
                        CodeBlob blob = VM.getVM().getCodeCache().findBlobUnsafe(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
                        a = blob.headerBegin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
                    if (node == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
                        Type type = VM.getVM().getTypeDataBase().guessTypeForAddress(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
                        if (type != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
                            out.println("Type is " + type.getName() + " (size of " + type.getSize() + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
                            node = new CTypeTreeNodeAdapter(a, type, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
                    if (node != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
                        printNode(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
        new Command("jhisto", "jhisto", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
                 ObjectHistogram histo = new ObjectHistogram();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
                 histo.run(out, err);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
        new Command("jstack", "jstack [-v]", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
                boolean verbose = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
                if (t.countTokens() > 0 && t.nextToken().equals("-v")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
                    verbose = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
                StackTrace jstack = new StackTrace(verbose, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
                jstack.run(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
        new Command("print", "print expression", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
                if (t.countTokens() != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
                    Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
                    HTMLGenerator gen = new HTMLGenerator(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
                    out.println(gen.genHTML(a));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
        new Command("printas", "printas type expression", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
                if (t.countTokens() != 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
                    Type type = agent.getTypeDataBase().lookupType(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
                    Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
                    CTypeTreeNodeAdapter node = new CTypeTreeNodeAdapter(a, type, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
                    out.println("pointer to " + type + " @ " + a +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
                                " (size = " + type.getSize() + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
                    printNode(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
        new Command("printstatics", "printstatics [ type ]", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
                if (t.countTokens() > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
                    if (t.countTokens() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
                        out.println("All known static fields");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
                        printNode(new CTypeTreeNodeAdapter(agent.getTypeDataBase().getTypes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
                    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
                        Type type = agent.getTypeDataBase().lookupType(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
                        out.println("Static fields of " + type.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
                        printNode(new CTypeTreeNodeAdapter(type));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
        new Command("pmap", "pmap", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
                PMap pmap = new PMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
                pmap.run(out, debugger.getAgent().getDebugger());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
        new Command("pstack", "pstack [-v]", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
                boolean verbose = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
                if (t.countTokens() > 0 && t.nextToken().equals("-v")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
                    verbose = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
                PStack pstack = new PStack(verbose, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
                pstack.run(out, debugger.getAgent().getDebugger());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
        new Command("quit", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
                if (t.countTokens() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
                    debugger.detach();
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 16357
diff changeset
  1141
                    quit = true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
        new Command("echo", "echo [ true | false ]", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
                if (t.countTokens() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
                    out.println("echo is " + doEcho);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
                } else if (t.countTokens() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
                    doEcho = Boolean.valueOf(t.nextToken()).booleanValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
        new Command("versioncheck", "versioncheck [ true | false ]", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
                if (t.countTokens() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
                    out.println("versioncheck is " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
                                (System.getProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck") == null));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
                } else if (t.countTokens() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
                    if (Boolean.valueOf(t.nextToken()).booleanValue()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
                        System.setProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck", null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
                    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
                        System.setProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck", "true");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
        new Command("scanoops", "scanoops start end [ type ]", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
                if (t.countTokens() != 2 && t.countTokens() != 3) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
                    long stride = VM.getVM().getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
                    Address base = VM.getVM().getDebugger().parseAddress(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
                    Address end  = VM.getVM().getDebugger().parseAddress(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
                    Klass klass = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
                    if (t.countTokens() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
                        klass = SystemDictionaryHelper.findInstanceKlass(t.nextToken());
16357
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
  1183
                        if (klass == null) {
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
  1184
                            out.println("No such type.");
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
  1185
                            return;
bdc20ac97a12 8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents: 16351
diff changeset
  1186
                        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
                    while (base != null && base.lessThan(end)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
                        long step = stride;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
                        OopHandle handle = base.addOffsetToAsOopHandle(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
                        if (RobustOopDeterminator.oopLooksValid(handle)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
                            try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
                                Oop oop = VM.getVM().getObjectHeap().newOop(handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
                                if (klass == null || oop.getKlass().isSubtypeOf(klass))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
                                    out.println(handle.toString() + " " + oop.getKlass().getName().asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
                                step = oop.getObjectSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
                            } catch (UnknownOopException ex) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
                                // ok
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
                            } catch (RuntimeException ex) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
                                ex.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
                        base = base.addOffsetTo(step);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
        },
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1208
        new Command("intConstant", "intConstant [ name [ value ] ]", true) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1209
            public void doit(Tokens t) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1210
                if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 2) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1211
                    usage();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1212
                    return;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1213
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1214
                HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1215
                if (t.countTokens() == 1) {
20011
d74937287461 8024760: add more types, fields and constants to VMStructs
twisti
parents: 18481
diff changeset
  1216
                    String name = t.nextToken();
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1217
                    out.println("intConstant " + name + " " + db.lookupIntConstant(name));
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1218
                } else if (t.countTokens() == 0) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1219
                    Iterator i = db.getIntConstants();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1220
                    while (i.hasNext()) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1221
                        String name = (String)i.next();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1222
                        out.println("intConstant " + name + " " + db.lookupIntConstant(name));
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1223
                    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1224
                } else if (t.countTokens() == 2) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1225
                    String name = t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1226
                    Integer value = Integer.valueOf(t.nextToken());
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1227
                    db.addIntConstant(name, value);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1228
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1229
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1230
        },
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1231
        new Command("longConstant", "longConstant [ name [ value ] ]", true) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1232
            public void doit(Tokens t) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1233
                if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 2) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1234
                    usage();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1235
                    return;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1236
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1237
                HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1238
                if (t.countTokens() == 1) {
20011
d74937287461 8024760: add more types, fields and constants to VMStructs
twisti
parents: 18481
diff changeset
  1239
                    String name = t.nextToken();
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1240
                    out.println("longConstant " + name + " " + db.lookupLongConstant(name));
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1241
                } else if (t.countTokens() == 0) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1242
                    Iterator i = db.getLongConstants();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1243
                    while (i.hasNext()) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1244
                        String name = (String)i.next();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1245
                        out.println("longConstant " + name + " " + db.lookupLongConstant(name));
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1246
                    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1247
                } else if (t.countTokens() == 2) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1248
                    String name = t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1249
                    Long value = Long.valueOf(t.nextToken());
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1250
                    db.addLongConstant(name, value);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1251
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1252
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1253
        },
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
        new Command("field", "field [ type [ name fieldtype isStatic offset address ] ]", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
                if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 6) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
                    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
                if (t.countTokens() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
                    Type type = agent.getTypeDataBase().lookupType(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
                    dumpFields(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
                } else if (t.countTokens() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
                    Iterator i = agent.getTypeDataBase().getTypes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
                    while (i.hasNext()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
                        dumpFields((Type)i.next());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
                    BasicType containingType = (BasicType)agent.getTypeDataBase().lookupType(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
                    String fieldName = t.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
                    // The field's Type must already be in the database -- no exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
                    Type fieldType = agent.getTypeDataBase().lookupType(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
                    boolean isStatic = Boolean.valueOf(t.nextToken()).booleanValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
                    long offset = Long.parseLong(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
                    Address staticAddress = parseAddress(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
                    if (isStatic && staticAddress == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
                        staticAddress = lookup(containingType.getName() + "::" + fieldName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
                    // check to see if the field already exists
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
                    Iterator i = containingType.getFields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
                    while (i.hasNext()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
                        Field f = (Field) i.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
                        if (f.getName().equals(fieldName)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
                            if (f.isStatic() != isStatic) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
                                throw new RuntimeException("static/nonstatic mismatch: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
                            if (!isStatic) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
                                if (f.getOffset() != offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
                                    throw new RuntimeException("bad redefinition of field offset: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
                                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
                            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
                                if (!f.getStaticFieldAddress().equals(staticAddress)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
                                    throw new RuntimeException("bad redefinition of field location: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
                                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
                            if (f.getType() != fieldType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
                                throw new RuntimeException("bad redefinition of field type: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
                            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
                    // Create field by type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
                    HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
                    db.createField(containingType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
                                   fieldName, fieldType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
                                   isStatic,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
                                   offset,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
                                   staticAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
        new Command("tokenize", "tokenize ...", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
                while (t.hasMoreTokens()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
                    out.println("\"" + t.nextToken() + "\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
        new Command("type", "type [ type [ name super isOop isInteger isUnsigned size ] ]", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
                if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 6) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
                    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
                if (t.countTokens() == 6) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
                    String typeName = t.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
                    String superclassName = t.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
                    if (superclassName.equals("null")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
                        superclassName = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
                    boolean isOop = Boolean.valueOf(t.nextToken()).booleanValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
                    boolean isInteger = Boolean.valueOf(t.nextToken()).booleanValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
                    boolean isUnsigned = Boolean.valueOf(t.nextToken()).booleanValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
                    long size = Long.parseLong(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
                    BasicType type = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
                    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
                        type = (BasicType)agent.getTypeDataBase().lookupType(typeName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
                    } catch (RuntimeException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
                    if (type != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
                        if (type.isOopType() != isOop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
                            throw new RuntimeException("oop mismatch in type definition: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
                        if (type.isCIntegerType() != isInteger) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
                            throw new RuntimeException("integer type mismatch in type definition: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
                        if (type.isCIntegerType() && (((CIntegerType)type).isUnsigned()) != isUnsigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
                            throw new RuntimeException("unsigned mismatch in type definition: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
                        if (type.getSuperclass() == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
                            if (superclassName != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
                                if (type.getSize() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
                                    type.setSuperclass(agent.getTypeDataBase().lookupType(superclassName));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
                                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
                                    throw new RuntimeException("unexpected superclass in type definition: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
                                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
                        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
                            if (superclassName == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
                                throw new RuntimeException("missing superclass in type definition: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
                            if (!type.getSuperclass().getName().equals(superclassName)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
                                throw new RuntimeException("incorrect superclass in type definition: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
                        if (type.getSize() != size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
                            if (type.getSize() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
                                type.setSize(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
                            throw new RuntimeException("size mismatch in type definition: " + t.input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
                        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
                    // Create type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
                    HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
                    db.createType(typeName, superclassName, isOop, isInteger, isUnsigned, size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
                } else if (t.countTokens() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
                    Type type = agent.getTypeDataBase().lookupType(t.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
                    dumpType(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
                    Iterator i = agent.getTypeDataBase().getTypes();
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1391
                    // Make sure the types are emitted in an order than can be read back in
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1392
                    HashSet emitted = new HashSet();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1393
                    Stack pending = new Stack();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
                    while (i.hasNext()) {
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1395
                        Type n = (Type)i.next();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1396
                        if (emitted.contains(n.getName())) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1397
                            continue;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1398
                        }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1399
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1400
                        while (n != null && !emitted.contains(n.getName())) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1401
                            pending.push(n);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1402
                            n = n.getSuperclass();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1403
                        }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1404
                        while (!pending.empty()) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1405
                            n = (Type)pending.pop();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1406
                            dumpType(n);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1407
                            emitted.add(n.getName());
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1408
                        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
        new Command("source", "source filename", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
                if (t.countTokens() != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
                    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
                String file = t.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
                BufferedReader savedInput = in;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
                try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
                    BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
                    in = input;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
                    run(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
                } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
                    out.println("Error: " + e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
                    if (verboseExceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
                        e.printStackTrace(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
                } finally {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
                    in = savedInput;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
        },
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1437
        new Command("search", "search [ heap | perm | rawheap | codecache | threads ] value", false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
                if (t.countTokens() != 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
                    usage();
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1441
                    return;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1442
                }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1443
                String type = t.nextToken();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1444
                final Address value = VM.getVM().getDebugger().parseAddress(t.nextToken());
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1445
                final long stride = VM.getVM().getAddressSize();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1446
                if (type.equals("threads")) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1447
                    Threads threads = VM.getVM().getThreads();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1448
                    for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1449
                        Address base = thread.getBaseOfStackPointer();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1450
                        Address end = thread.getLastJavaSP();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1451
                        if (end == null) continue;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1452
                        if (end.lessThan(base)) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1453
                            Address tmp = base;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1454
                            base = end;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1455
                            end = tmp;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1456
                        }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1457
                        out.println("Searching " + base + " " + end);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1458
                        while (base != null && base.lessThan(end)) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1459
                            Address val = base.getAddressAt(0);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1460
                            if (AddressOps.equal(val, value)) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1461
                                out.println(base);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1462
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1463
                            base = base.addOffsetTo(stride);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1464
                        }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1465
                    }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1466
                } else if (type.equals("rawheap")) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1467
                    RawHeapVisitor iterator = new RawHeapVisitor() {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1468
                            public void prologue(long used) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
                            }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1470
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1471
                            public void visitAddress(Address addr) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1472
                                Address val = addr.getAddressAt(0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
                                if (AddressOps.equal(val, value)) {
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1474
                                        out.println("found at " + addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
                                }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1476
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1477
                            public void visitCompOopAddress(Address addr) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1478
                                Address val = addr.getCompOopAddressAt(0);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1479
                                if (AddressOps.equal(val, value)) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1480
                                    out.println("found at " + addr);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1481
                                }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
                            }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1483
                            public void epilogue() {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1484
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1485
                        };
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1486
                    VM.getVM().getObjectHeap().iterateRaw(iterator);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
  1487
                } else if (type.equals("heap")) {
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1488
                    HeapVisitor iterator = new DefaultHeapVisitor() {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1489
                            public boolean doObj(Oop obj) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1490
                                int index = 0;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1491
                                Address start = obj.getHandle();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1492
                                long end = obj.getObjectSize();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1493
                                while (index < end) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1494
                                    Address val = start.getAddressAt(index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
                                    if (AddressOps.equal(val, value)) {
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1496
                                        out.println("found in " + obj.getHandle());
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1497
                                        break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
                                    }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1499
                                    index += 4;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
                                }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1501
                                return false;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1502
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1503
                        };
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1504
                        VM.getVM().getObjectHeap().iterate(iterator);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1505
                } else if (type.equals("codecache")) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1506
                    CodeCacheVisitor v = new CodeCacheVisitor() {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1507
                            public void prologue(Address start, Address end) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1508
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1509
                            public void visit(CodeBlob blob) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1510
                                boolean printed = false;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1511
                                Address base = blob.getAddress();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1512
                                Address end = base.addOffsetTo(blob.getSize());
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1513
                                while (base != null && base.lessThan(end)) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1514
                                    Address val = base.getAddressAt(0);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1515
                                    if (AddressOps.equal(val, value)) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1516
                                        if (!printed) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1517
                                            printed = true;
9946
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 8921
diff changeset
  1518
                                            try {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 8921
diff changeset
  1519
                                                blob.printOn(out);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 8921
diff changeset
  1520
                                            } catch (Exception e) {
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 8921
diff changeset
  1521
                                                out.println("Exception printing blob at " + base);
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 8921
diff changeset
  1522
                                                e.printStackTrace();
b3d5b50e2289 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 8921
diff changeset
  1523
                                            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
                                        }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1525
                                        out.println("found at " + base + "\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
                                    }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1527
                                    base = base.addOffsetTo(stride);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
                                }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1529
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1530
                            public void epilogue() {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1531
                            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1534
                        };
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1535
                    VM.getVM().getCodeCache().iterate(v);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
        },
4095
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1540
        new Command("dumpcodecache", "dumpcodecache", false) {
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1541
            public void doit(Tokens t) {
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1542
                if (t.countTokens() != 0) {
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1543
                    usage();
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1544
                } else {
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1545
                    final PrintStream fout = out;
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1546
                    final HTMLGenerator gen = new HTMLGenerator(false);
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1547
                    CodeCacheVisitor v = new CodeCacheVisitor() {
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1548
                            public void prologue(Address start, Address end) {
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1549
                            }
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1550
                            public void visit(CodeBlob blob) {
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5547
diff changeset
  1551
                                fout.println(gen.genHTML(blob.contentBegin()));
4095
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1552
                            }
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1553
                            public void epilogue() {
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1554
                            }
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1555
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1556
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1557
                        };
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1558
                    VM.getVM().getCodeCache().iterate(v);
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1559
                }
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1560
            }
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 670
diff changeset
  1561
        },
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
        new Command("where", "where { -a | id }", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
                if (t.countTokens() != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
                    String name = t.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
                    Threads threads = VM.getVM().getThreads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
                    boolean all = name.equals("-a");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
                    for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
                        thread.printThreadIDOn(new PrintStream(bos));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
                        if (all || bos.toString().equals(name)) {
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 14477
diff changeset
  1574
                            out.println("Thread " + bos.toString() + " Address: " + thread.getAddress());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
                            HTMLGenerator gen = new HTMLGenerator(false);
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1576
                            try {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1577
                                out.println(gen.genHTMLForJavaStackTrace(thread));
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1578
                            } catch (Exception e) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1579
                                err.println("Error: " + e);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1580
                                if (verboseExceptions) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1581
                                    e.printStackTrace(err);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1582
                                }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1583
                            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
                            if (!all) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
                    if (!all) out.println("Couldn't find thread " + name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
        },
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1591
        new Command("thread", "thread { -a | id }", false) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1592
            public void doit(Tokens t) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1593
                if (t.countTokens() != 1) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1594
                    usage();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1595
                } else {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1596
                    String name = t.nextToken();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1597
                    Threads threads = VM.getVM().getThreads();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1598
                    boolean all = name.equals("-a");
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1599
                    for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1600
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1601
                        thread.printThreadIDOn(new PrintStream(bos));
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1602
                        if (all || bos.toString().equals(name)) {
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 14477
diff changeset
  1603
                            out.println("Thread " + bos.toString() + " Address " + thread.getAddress());
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1604
                            if (!all) return;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1605
                        }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1606
                    }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1607
                    out.println("Couldn't find thread " + name);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1608
                }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1609
            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1610
        },
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
        new Command("threads", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
                if (t.countTokens() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
                    Threads threads = VM.getVM().getThreads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
                    for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
                        thread.printThreadIDOn(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
                        out.println(" " + thread.getThreadName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
        new Command("livenmethods", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
                if (t.countTokens() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
                    ArrayList nmethods = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
                    Threads threads = VM.getVM().getThreads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
                    HTMLGenerator gen = new HTMLGenerator(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
                    for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
                        try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
                            for (JavaVFrame vf = thread.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
                                if (vf instanceof CompiledVFrame) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
                                    NMethod c = ((CompiledVFrame)vf).getCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
                                    if (!nmethods.contains(c)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
                                        nmethods.add(c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
                                        out.println(gen.genHTML(c));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
                                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
                                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
                        } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
                            e.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
        new Command("universe", false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
                if (t.countTokens() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
                    Universe u = VM.getVM().getUniverse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
                    out.println("Heap Parameters:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
                    u.heap().printOn(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
        new Command("verbose", "verbose true | false", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
                if (t.countTokens() != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
                    verboseExceptions = Boolean.valueOf(t.nextToken()).booleanValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
        new Command("assert", "assert true | false", true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
            public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
                if (t.countTokens() != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
                    usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
                    Assert.ASSERTS_ENABLED = Boolean.valueOf(t.nextToken()).booleanValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
        },
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
    private boolean verboseExceptions = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
    private ArrayList history = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
    private HashMap commands = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
    private boolean doEcho = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
    private Command findCommand(String key) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
        return (Command)commands.get(key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
    public void printPrompt() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
        out.print("hsdb> ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
    private DebuggerInterface debugger;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
    private HotSpotAgent agent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
    private JSJavaScriptEngine jsengine;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
    private BufferedReader in;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
    private PrintStream out;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
    private PrintStream err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
    // called before debuggee attach
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
    private void preAttach() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
        // nothing for now..
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
    // called after debuggee attach
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
    private void postAttach() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
        // create JavaScript engine and start it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
        jsengine = new JSJavaScriptEngine() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
                        private ObjectReader reader = new ObjectReader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
                        private JSJavaFactory factory = new JSJavaFactoryImpl();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
                        public ObjectReader getObjectReader() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
                            return reader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
                        public JSJavaFactory getJSJavaFactory() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
                            return factory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
                        protected void quit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
                            debugger.detach();
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 16357
diff changeset
  1722
                            quit = true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
                        protected BufferedReader getInputReader() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
                            return in;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
                        protected PrintStream getOutputStream() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
                            return out;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
                        protected PrintStream getErrorStream() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
                            return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
                   };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
        try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
            jsengine.defineFunction(this,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
                     this.getClass().getMethod("registerCommand",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
                                new Class[] {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
                                     String.class, String.class, String.class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
                                }));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
        } catch (NoSuchMethodException exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
            // should not happen, see below...!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
            exp.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
        jsengine.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
    public void registerCommand(String cmd, String usage, final String func) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
        commands.put(cmd, new Command(cmd, usage, false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
                              public void doit(Tokens t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
                                  final int len = t.countTokens();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
                                  Object[] args = new Object[len];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
                                  for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
                                      args[i] = t.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
                                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
                                  jsengine.call(func, args);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
                          });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
    public void setOutput(PrintStream o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
        out = o;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
    public void setErr(PrintStream e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
        err = e;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
    public CommandProcessor(DebuggerInterface debugger, BufferedReader in, PrintStream out, PrintStream err) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
        this.debugger = debugger;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
        this.agent = debugger.getAgent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
        this.in = in;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
        this.out = out;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
        this.err = err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
        for (int i = 0; i < commandList.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
            Command c = commandList[i];
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
  1776
            if (commands.get(c.name) != null) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
  1777
                throw new InternalError(c.name + " has multiple definitions");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 6418
diff changeset
  1778
            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
            commands.put(c.name, c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
        if (debugger.isAttached()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
            postAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
    public void run(boolean prompt) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
        // Process interactive commands.
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 16357
diff changeset
  1789
        while (!quit) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
            if (prompt) printPrompt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
            String ln = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
            try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
                ln = in.readLine();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
            } catch (IOException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
            if (ln == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
                if (prompt) err.println("Input stream closed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
                return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1801
            executeCommand(ln, prompt);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1805
    static Pattern historyPattern = Pattern.compile("((!\\*)|(!\\$)|(!!-?)|(!-?[0-9][0-9]*)|(![a-zA-Z][^ ]*))");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1807
    public void executeCommand(String ln, boolean putInHistory) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
        if (ln.indexOf('!') != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
            int size = history.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
            if (size == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
                ln = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
                err.println("History is empty");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
                StringBuffer result = new StringBuffer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
                Matcher m = historyPattern.matcher(ln);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
                int start = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
                while (m.find()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
                    if (m.start() > start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
                        result.append(ln.substring(start, m.start() - start));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
                    start = m.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
                    String cmd = m.group();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
                    if (cmd.equals("!!")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
                        result.append((String)history.get(history.size() - 1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
                    } else if (cmd.equals("!!-")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
                        Tokens item = new Tokens((String)history.get(history.size() - 1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
                        item.trim(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
                        result.append(item.join(" "));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
                    } else if (cmd.equals("!*")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
                        Tokens item = new Tokens((String)history.get(history.size() - 1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
                        item.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
                        result.append(item.join(" "));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
                    } else if (cmd.equals("!$")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
                        Tokens item = new Tokens((String)history.get(history.size() - 1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
                        result.append(item.at(item.countTokens() - 1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
                    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
                        String tail = cmd.substring(1);
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1839
                        switch (tail.charAt(0)) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1840
                        case '0':
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1841
                        case '1':
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1842
                        case '2':
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1843
                        case '3':
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1844
                        case '4':
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1845
                        case '5':
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1846
                        case '6':
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1847
                        case '7':
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1848
                        case '8':
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1849
                        case '9':
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1850
                        case '-': {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1851
                            int index = Integer.parseInt(tail);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1852
                            if (index < 0) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1853
                                index = history.size() + index;
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1854
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1855
                            if (index > size) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1856
                                err.println("No such history item");
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1857
                            } else {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1858
                                result.append((String)history.get(index));
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1859
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1860
                            break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
                        }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1862
                        default: {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1863
                            for (int i = history.size() - 1; i >= 0; i--) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1864
                                String s = (String)history.get(i);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1865
                                if (s.startsWith(tail)) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1866
                                    result.append(s);
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1867
                                }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1868
                            }
290a02b4adb3 6945219: minor SA fixes
never
parents: 4095
diff changeset
  1869
                        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
                if (result.length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
                    err.println("malformed history reference");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
                    ln = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
                    if (start < ln.length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
                        result.append(ln.substring(start));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
                    ln = result.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
                    if (!doEcho) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
                        out.println(ln);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
        if (doEcho) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
            out.println("+ " + ln);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
        PrintStream redirect = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
        Tokens t = new Tokens(ln);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
        if (t.hasMoreTokens()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
            boolean error = false;
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 9946
diff changeset
  1896
            if (putInHistory) history.add(ln);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
            int len = t.countTokens();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
            if (len > 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
                String r = t.at(len - 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
                if (r.equals(">") || r.equals(">>")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
                    boolean append = r.length() == 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
                    String file = t.at(len - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
                    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
                        redirect = new PrintStream(new BufferedOutputStream(new FileOutputStream(file, append)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
                        t.trim(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
                    } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
                        out.println("Error: " + e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
                        if (verboseExceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
                            e.printStackTrace(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
                        error = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
            if (!error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
                PrintStream savedout = out;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
                if (redirect != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
                    out = redirect;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
                try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
                    executeCommand(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
                } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
                    err.println("Error: " + e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
                    if (verboseExceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
                        e.printStackTrace(err);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
                } finally {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
                    if (redirect != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
                        out = savedout;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
                        redirect.close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
    void executeCommand(Tokens args) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
        String cmd = args.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
        Command doit = findCommand(cmd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
        /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
         * Check for an unknown command
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
         */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
        if (doit == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
            out.println("Unrecognized command.  Try help...");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
        } else if (!debugger.isAttached() && !doit.okIfDisconnected) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
            out.println("Command not valid until the attached to a VM");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
            try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
                doit.doit(args);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
            } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
                out.println("Error: " + e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
                if (verboseExceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
                    e.printStackTrace(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
}