32 import java.io.IOException;
33 import java.io.InputStreamReader;
34 import java.io.PrintStream;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.Comparator;
38 import java.util.HashMap;
39 import java.util.HashSet;
40 import java.util.Iterator;
41 import java.util.Stack;
42 import java.util.regex.Matcher;
43 import java.util.regex.Pattern;
44
45 import sun.jvm.hotspot.ci.ciEnv;
46 import sun.jvm.hotspot.code.CodeBlob;
47 import sun.jvm.hotspot.code.CodeCacheVisitor;
48 import sun.jvm.hotspot.code.NMethod;
49 import sun.jvm.hotspot.debugger.Address;
50 import sun.jvm.hotspot.debugger.OopHandle;
51 import sun.jvm.hotspot.classfile.ClassLoaderDataGraph;
52 import sun.jvm.hotspot.memory.SymbolTable;
53 import sun.jvm.hotspot.memory.SystemDictionary;
54 import sun.jvm.hotspot.memory.Universe;
55 import sun.jvm.hotspot.gc.shared.CollectedHeap;
56 import sun.jvm.hotspot.gc.g1.G1CollectedHeap;
57 import sun.jvm.hotspot.oops.DefaultHeapVisitor;
58 import sun.jvm.hotspot.oops.HeapVisitor;
59 import sun.jvm.hotspot.oops.InstanceKlass;
60 import sun.jvm.hotspot.oops.Klass;
61 import sun.jvm.hotspot.oops.Metadata;
62 import sun.jvm.hotspot.oops.Method;
63 import sun.jvm.hotspot.oops.MethodData;
64 import sun.jvm.hotspot.oops.Oop;
65 import sun.jvm.hotspot.oops.RawHeapVisitor;
66 import sun.jvm.hotspot.oops.Symbol;
67 import sun.jvm.hotspot.oops.UnknownOopException;
68 import sun.jvm.hotspot.opto.Compile;
69 import sun.jvm.hotspot.opto.InlineTree;
70 import sun.jvm.hotspot.runtime.CompiledVFrame;
71 import sun.jvm.hotspot.runtime.CompilerThread;
72 import sun.jvm.hotspot.runtime.JavaThread;
73 import sun.jvm.hotspot.runtime.JavaVFrame;
74 import sun.jvm.hotspot.runtime.Threads;
75 import sun.jvm.hotspot.runtime.VM;
76 import sun.jvm.hotspot.tools.ObjectHistogram;
77 import sun.jvm.hotspot.tools.PMap;
78 import sun.jvm.hotspot.tools.PStack;
79 import sun.jvm.hotspot.tools.StackTrace;
80 import sun.jvm.hotspot.tools.jcore.ClassDump;
81 import sun.jvm.hotspot.tools.jcore.ClassFilter;
82 import sun.jvm.hotspot.types.CIntegerType;
83 import sun.jvm.hotspot.types.Field;
84 import sun.jvm.hotspot.types.Type;
85 import sun.jvm.hotspot.types.basic.BasicType;
86 import sun.jvm.hotspot.ui.classbrowser.HTMLGenerator;
87 import sun.jvm.hotspot.ui.tree.CTypeTreeNodeAdapter;
88 import sun.jvm.hotspot.ui.tree.OopTreeNodeAdapter;
89 import sun.jvm.hotspot.ui.tree.SimpleTreeNode;
90 import sun.jvm.hotspot.utilities.AddressOps;
91 import sun.jvm.hotspot.utilities.Assert;
92 import sun.jvm.hotspot.utilities.HeapProgressThunk;
93 import sun.jvm.hotspot.utilities.LivenessPathElement;
94 import sun.jvm.hotspot.utilities.MethodArray;
95 import sun.jvm.hotspot.utilities.ObjectReader;
96 import sun.jvm.hotspot.utilities.PointerFinder;
97 import sun.jvm.hotspot.utilities.PointerLocation;
98 import sun.jvm.hotspot.utilities.ReversePtrs;
99 import sun.jvm.hotspot.utilities.ReversePtrsAnalysis;
100 import sun.jvm.hotspot.utilities.RobustOopDeterminator;
101 import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
102 import sun.jvm.hotspot.utilities.soql.JSJavaFactory;
103 import sun.jvm.hotspot.utilities.soql.JSJavaFactoryImpl;
104 import sun.jvm.hotspot.utilities.soql.JSJavaScriptEngine;
105
106 public class CommandProcessor {
107
108 volatile boolean quit;
109
110 public abstract static class DebuggerInterface {
111 public abstract HotSpotAgent getAgent();
620 if (t.countTokens() != 1) {
621 usage();
622 } else {
623 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
624 Symbol.create(a).printValueOn(out);
625 out.println();
626 }
627 }
628 },
629 new Command("symboltable", "symboltable name", false) {
630 public void doit(Tokens t) {
631 if (t.countTokens() != 1) {
632 usage();
633 } else {
634 out.println(SymbolTable.getTheTable().probe(t.nextToken()));
635 }
636 }
637 },
638 new Command("symboldump", "symboldump", false) {
639 public void doit(Tokens t) {
640 SymbolTable.getTheTable().symbolsDo(new SymbolTable.SymbolVisitor() {
641 public void visit(Symbol sym) {
642 sym.printValueOn(out);
643 out.println();
644 }
645 });
646 }
647 },
648 new Command("flags", "flags [ flag | -nd ]", false) {
649 public void doit(Tokens t) {
650 int tokens = t.countTokens();
651 if (tokens != 0 && tokens != 1) {
652 usage();
653 } else {
654 String name = tokens > 0 ? t.nextToken() : null;
655 boolean nonDefault = false;
656 if (name != null && name.equals("-nd")) {
657 name = null;
658 nonDefault = true;
659 }
660
661 VM.Flag[] flags = VM.getVM().getCommandLineFlags();
662 if (flags == null) {
663 out.println("Command Flag info not available (use 1.4.1_03 or later)!");
664 } else {
665 boolean printed = false;
666 for (int f = 0; f < flags.length; f++) {
1031 new Command("inspect", "inspect expression", false) {
1032 public void doit(Tokens t) {
1033 if (t.countTokens() != 1) {
1034 usage();
1035 } else {
1036 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
1037 SimpleTreeNode node = null;
1038 if (VM.getVM().getUniverse().heap().isInReserved(a)) {
1039 OopHandle handle = a.addOffsetToAsOopHandle(0);
1040 Oop oop = VM.getVM().getObjectHeap().newOop(handle);
1041 node = new OopTreeNodeAdapter(oop, null);
1042
1043 out.println("instance of " + node.getValue() + " @ " + a +
1044 " (size = " + oop.getObjectSize() + ")");
1045 } else if (VM.getVM().getCodeCache().contains(a)) {
1046 CodeBlob blob = VM.getVM().getCodeCache().findBlobUnsafe(a);
1047 a = blob.headerBegin();
1048 }
1049 if (node == null) {
1050 Type type = VM.getVM().getTypeDataBase().guessTypeForAddress(a);
1051 if (type != null) {
1052 out.println("Type is " + type.getName() + " (size of " + type.getSize() + ")");
1053 node = new CTypeTreeNodeAdapter(a, type, null);
1054 }
1055 }
1056 if (node != null) {
1057 printNode(node);
1058 }
1059 }
1060 }
1061 },
1062 new Command("jhisto", "jhisto", false) {
1063 public void doit(Tokens t) {
1064 ObjectHistogram histo = new ObjectHistogram();
1065 histo.run(out, err);
1066 }
1067 },
1068 new Command("jstack", "jstack [-v]", false) {
1069 public void doit(Tokens t) {
1070 boolean verbose = false;
|
32 import java.io.IOException;
33 import java.io.InputStreamReader;
34 import java.io.PrintStream;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.Comparator;
38 import java.util.HashMap;
39 import java.util.HashSet;
40 import java.util.Iterator;
41 import java.util.Stack;
42 import java.util.regex.Matcher;
43 import java.util.regex.Pattern;
44
45 import sun.jvm.hotspot.ci.ciEnv;
46 import sun.jvm.hotspot.code.CodeBlob;
47 import sun.jvm.hotspot.code.CodeCacheVisitor;
48 import sun.jvm.hotspot.code.NMethod;
49 import sun.jvm.hotspot.debugger.Address;
50 import sun.jvm.hotspot.debugger.OopHandle;
51 import sun.jvm.hotspot.classfile.ClassLoaderDataGraph;
52 import sun.jvm.hotspot.memory.FileMapInfo;
53 import sun.jvm.hotspot.memory.SymbolTable;
54 import sun.jvm.hotspot.memory.SystemDictionary;
55 import sun.jvm.hotspot.memory.Universe;
56 import sun.jvm.hotspot.gc.shared.CollectedHeap;
57 import sun.jvm.hotspot.gc.g1.G1CollectedHeap;
58 import sun.jvm.hotspot.oops.DefaultHeapVisitor;
59 import sun.jvm.hotspot.oops.HeapVisitor;
60 import sun.jvm.hotspot.oops.InstanceKlass;
61 import sun.jvm.hotspot.oops.Klass;
62 import sun.jvm.hotspot.oops.Metadata;
63 import sun.jvm.hotspot.oops.Method;
64 import sun.jvm.hotspot.oops.MethodData;
65 import sun.jvm.hotspot.oops.Oop;
66 import sun.jvm.hotspot.oops.RawHeapVisitor;
67 import sun.jvm.hotspot.oops.Symbol;
68 import sun.jvm.hotspot.oops.UnknownOopException;
69 import sun.jvm.hotspot.opto.Compile;
70 import sun.jvm.hotspot.opto.InlineTree;
71 import sun.jvm.hotspot.runtime.CompiledVFrame;
72 import sun.jvm.hotspot.runtime.CompilerThread;
73 import sun.jvm.hotspot.runtime.JavaThread;
74 import sun.jvm.hotspot.runtime.JavaVFrame;
75 import sun.jvm.hotspot.runtime.Threads;
76 import sun.jvm.hotspot.runtime.VM;
77 import sun.jvm.hotspot.tools.ObjectHistogram;
78 import sun.jvm.hotspot.tools.PMap;
79 import sun.jvm.hotspot.tools.PStack;
80 import sun.jvm.hotspot.tools.StackTrace;
81 import sun.jvm.hotspot.tools.jcore.ClassDump;
82 import sun.jvm.hotspot.tools.jcore.ClassFilter;
83 import sun.jvm.hotspot.types.CIntegerType;
84 import sun.jvm.hotspot.types.Field;
85 import sun.jvm.hotspot.types.Type;
86 import sun.jvm.hotspot.types.basic.BasicType;
87 import sun.jvm.hotspot.ui.classbrowser.HTMLGenerator;
88 import sun.jvm.hotspot.ui.tree.CTypeTreeNodeAdapter;
89 import sun.jvm.hotspot.ui.tree.OopTreeNodeAdapter;
90 import sun.jvm.hotspot.ui.tree.SimpleTreeNode;
91 import sun.jvm.hotspot.utilities.AddressOps;
92 import sun.jvm.hotspot.utilities.Assert;
93 import sun.jvm.hotspot.utilities.CompactHashTable;
94 import sun.jvm.hotspot.utilities.HeapProgressThunk;
95 import sun.jvm.hotspot.utilities.LivenessPathElement;
96 import sun.jvm.hotspot.utilities.MethodArray;
97 import sun.jvm.hotspot.utilities.ObjectReader;
98 import sun.jvm.hotspot.utilities.PointerFinder;
99 import sun.jvm.hotspot.utilities.PointerLocation;
100 import sun.jvm.hotspot.utilities.ReversePtrs;
101 import sun.jvm.hotspot.utilities.ReversePtrsAnalysis;
102 import sun.jvm.hotspot.utilities.RobustOopDeterminator;
103 import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
104 import sun.jvm.hotspot.utilities.soql.JSJavaFactory;
105 import sun.jvm.hotspot.utilities.soql.JSJavaFactoryImpl;
106 import sun.jvm.hotspot.utilities.soql.JSJavaScriptEngine;
107
108 public class CommandProcessor {
109
110 volatile boolean quit;
111
112 public abstract static class DebuggerInterface {
113 public abstract HotSpotAgent getAgent();
622 if (t.countTokens() != 1) {
623 usage();
624 } else {
625 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
626 Symbol.create(a).printValueOn(out);
627 out.println();
628 }
629 }
630 },
631 new Command("symboltable", "symboltable name", false) {
632 public void doit(Tokens t) {
633 if (t.countTokens() != 1) {
634 usage();
635 } else {
636 out.println(SymbolTable.getTheTable().probe(t.nextToken()));
637 }
638 }
639 },
640 new Command("symboldump", "symboldump", false) {
641 public void doit(Tokens t) {
642 SymbolTable theTable = SymbolTable.getTheTable();
643 theTable.symbolsDo(new SymbolTable.SymbolVisitor() {
644 public void visit(Symbol sym) {
645 sym.printValueOn(out);
646 out.println();
647 }
648 });
649 CompactHashTable sharedTable = theTable.getSharedTable();
650 if (sharedTable != null) {
651 sharedTable.symbolsDo(new CompactHashTable.SymbolVisitor() {
652 public void visit(Symbol sym) {
653 sym.printValueOn(out);
654 out.println();
655 }
656 });
657 }
658 }
659 },
660 new Command("flags", "flags [ flag | -nd ]", false) {
661 public void doit(Tokens t) {
662 int tokens = t.countTokens();
663 if (tokens != 0 && tokens != 1) {
664 usage();
665 } else {
666 String name = tokens > 0 ? t.nextToken() : null;
667 boolean nonDefault = false;
668 if (name != null && name.equals("-nd")) {
669 name = null;
670 nonDefault = true;
671 }
672
673 VM.Flag[] flags = VM.getVM().getCommandLineFlags();
674 if (flags == null) {
675 out.println("Command Flag info not available (use 1.4.1_03 or later)!");
676 } else {
677 boolean printed = false;
678 for (int f = 0; f < flags.length; f++) {
1043 new Command("inspect", "inspect expression", false) {
1044 public void doit(Tokens t) {
1045 if (t.countTokens() != 1) {
1046 usage();
1047 } else {
1048 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
1049 SimpleTreeNode node = null;
1050 if (VM.getVM().getUniverse().heap().isInReserved(a)) {
1051 OopHandle handle = a.addOffsetToAsOopHandle(0);
1052 Oop oop = VM.getVM().getObjectHeap().newOop(handle);
1053 node = new OopTreeNodeAdapter(oop, null);
1054
1055 out.println("instance of " + node.getValue() + " @ " + a +
1056 " (size = " + oop.getObjectSize() + ")");
1057 } else if (VM.getVM().getCodeCache().contains(a)) {
1058 CodeBlob blob = VM.getVM().getCodeCache().findBlobUnsafe(a);
1059 a = blob.headerBegin();
1060 }
1061 if (node == null) {
1062 Type type = VM.getVM().getTypeDataBase().guessTypeForAddress(a);
1063 if (type == null && VM.getVM().isSharingEnabled()) {
1064 // Check if the value falls in the _md_region
1065 Address loc1 = a.getAddressAt(0);
1066 FileMapInfo cdsFileMapInfo = VM.getVM().getFileMapInfo();
1067 if (cdsFileMapInfo.inCopiedVtableSpace(loc1)) {
1068 type = cdsFileMapInfo.getTypeForVptrAddress(loc1);
1069 }
1070
1071 }
1072 if (type != null) {
1073 out.println("Type is " + type.getName() + " (size of " + type.getSize() + ")");
1074 node = new CTypeTreeNodeAdapter(a, type, null);
1075 }
1076 }
1077 if (node != null) {
1078 printNode(node);
1079 }
1080 }
1081 }
1082 },
1083 new Command("jhisto", "jhisto", false) {
1084 public void doit(Tokens t) {
1085 ObjectHistogram histo = new ObjectHistogram();
1086 histo.run(out, err);
1087 }
1088 },
1089 new Command("jstack", "jstack [-v]", false) {
1090 public void doit(Tokens t) {
1091 boolean verbose = false;
|