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