comparison agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java @ 3939:f6f3bb0ee072

7088955: add C2 IR support to the SA Reviewed-by: kvn
author never
date Sun, 11 Sep 2011 14:48:24 -0700
parents a80577f854f9
children da91efe96a93
comparison
equal deleted inserted replaced
3938:e6b1331a51d2 3939:f6f3bb0ee072
38 import sun.jvm.hotspot.compiler.*; 38 import sun.jvm.hotspot.compiler.*;
39 import sun.jvm.hotspot.debugger.*; 39 import sun.jvm.hotspot.debugger.*;
40 import sun.jvm.hotspot.interpreter.*; 40 import sun.jvm.hotspot.interpreter.*;
41 import sun.jvm.hotspot.memory.*; 41 import sun.jvm.hotspot.memory.*;
42 import sun.jvm.hotspot.oops.*; 42 import sun.jvm.hotspot.oops.*;
43 import sun.jvm.hotspot.opto.*;
44 import sun.jvm.hotspot.ci.*;
43 import sun.jvm.hotspot.runtime.*; 45 import sun.jvm.hotspot.runtime.*;
44 import sun.jvm.hotspot.utilities.*; 46 import sun.jvm.hotspot.utilities.*;
45 import sun.jvm.hotspot.utilities.soql.*; 47 import sun.jvm.hotspot.utilities.soql.*;
46 import sun.jvm.hotspot.ui.classbrowser.*; 48 import sun.jvm.hotspot.ui.classbrowser.*;
47 import sun.jvm.hotspot.ui.tree.*; 49 import sun.jvm.hotspot.ui.tree.*;
48 import sun.jvm.hotspot.tools.*; 50 import sun.jvm.hotspot.tools.*;
49 import sun.jvm.hotspot.tools.ObjectHistogram; 51 import sun.jvm.hotspot.tools.ObjectHistogram;
50 import sun.jvm.hotspot.tools.StackTrace; 52 import sun.jvm.hotspot.tools.StackTrace;
53 import sun.jvm.hotspot.tools.jcore.ClassDump;
54 import sun.jvm.hotspot.tools.jcore.ClassFilter;
51 55
52 public class CommandProcessor { 56 public class CommandProcessor {
53 public abstract static class DebuggerInterface { 57 public abstract static class DebuggerInterface {
54 public abstract HotSpotAgent getAgent(); 58 public abstract HotSpotAgent getAgent();
55 public abstract boolean isAttached(); 59 public abstract boolean isAttached();
56 public abstract void attach(String pid); 60 public abstract void attach(String pid);
57 public abstract void attach(String java, String core); 61 public abstract void attach(String java, String core);
58 public abstract void detach(); 62 public abstract void detach();
59 public abstract void reattach(); 63 public abstract void reattach();
64 }
65
66 public static class BootFilter implements ClassFilter {
67 public boolean canInclude(InstanceKlass kls) {
68 return kls.getClassLoader() == null;
69 }
70 }
71
72 public static class NonBootFilter implements ClassFilter {
73 private HashMap emitted = new HashMap();
74 public boolean canInclude(InstanceKlass kls) {
75 if (kls.getClassLoader() == null) return false;
76 if (emitted.get(kls.getName()) != null) {
77 // Since multiple class loaders are being shoved
78 // together duplicate classes are a possibilty. For
79 // now just ignore them.
80 return false;
81 }
82 emitted.put(kls.getName(), kls);
83 return true;
84 }
60 } 85 }
61 86
62 static class Tokens { 87 static class Tokens {
63 final String input; 88 final String input;
64 int i; 89 int i;
256 out.print(type.getSize()); 281 out.print(type.getSize());
257 out.println(); 282 out.println();
258 } 283 }
259 284
260 void dumpFields(Type type) { 285 void dumpFields(Type type) {
286 dumpFields(type, true);
287 }
288
289 void dumpFields(Type type, boolean allowStatic) {
261 Iterator i = type.getFields(); 290 Iterator i = type.getFields();
262 while (i.hasNext()) { 291 while (i.hasNext()) {
263 Field f = (Field) i.next(); 292 Field f = (Field) i.next();
293 if (!allowStatic && f.isStatic()) continue;
264 out.print("field "); 294 out.print("field ");
265 quote(type.getName()); 295 quote(type.getName());
266 out.print(" "); 296 out.print(" ");
267 out.print(f.getName()); 297 out.print(f.getName());
268 out.print(" "); 298 out.print(" ");
456 out.println(); 486 out.println();
457 } 487 }
458 }); 488 });
459 } 489 }
460 }, 490 },
461 new Command("flags", "flags [ flag ]", false) { 491 new Command("flags", "flags [ flag | -nd ]", false) {
462 public void doit(Tokens t) { 492 public void doit(Tokens t) {
463 int tokens = t.countTokens(); 493 int tokens = t.countTokens();
464 if (tokens != 0 && tokens != 1) { 494 if (tokens != 0 && tokens != 1) {
465 usage(); 495 usage();
466 } else { 496 } else {
467 String name = tokens > 0 ? t.nextToken() : null; 497 String name = tokens > 0 ? t.nextToken() : null;
498 boolean nonDefault = false;
499 if (name != null && name.equals("-nd")) {
500 name = null;
501 nonDefault = true;
502 }
468 503
469 VM.Flag[] flags = VM.getVM().getCommandLineFlags(); 504 VM.Flag[] flags = VM.getVM().getCommandLineFlags();
470 if (flags == null) { 505 if (flags == null) {
471 out.println("Command Flag info not available (use 1.4.1_03 or later)!"); 506 out.println("Command Flag info not available (use 1.4.1_03 or later)!");
472 } else { 507 } else {
473 boolean printed = false; 508 boolean printed = false;
474 for (int f = 0; f < flags.length; f++) { 509 for (int f = 0; f < flags.length; f++) {
475 VM.Flag flag = flags[f]; 510 VM.Flag flag = flags[f];
476 if (name == null || flag.getName().equals(name)) { 511 if (name == null || flag.getName().equals(name)) {
477 out.println(flag.getName() + " = " + flag.getValue()); 512
513 if (nonDefault && flag.getOrigin() == 0) {
514 // only print flags which aren't their defaults
515 continue;
516 }
517 out.println(flag.getName() + " = " + flag.getValue() + " " + flag.getOrigin());
478 printed = true; 518 printed = true;
479 } 519 }
480 } 520 }
481 if (name != null && !printed) { 521 if (name != null && !printed) {
482 out.println("Couldn't find flag: " + name); 522 out.println("Couldn't find flag: " + name);
584 } 624 }
585 } 625 }
586 } 626 }
587 } 627 }
588 }, 628 },
629 new Command("printmdo", "printmdo [ -a | expression ]", false) {
630 // Print every MDO in the heap or the one referenced by expression.
631 public void doit(Tokens t) {
632 if (t.countTokens() != 1) {
633 usage();
634 } else {
635 String s = t.nextToken();
636 if (s.equals("-a")) {
637 HeapVisitor iterator = new DefaultHeapVisitor() {
638 public boolean doObj(Oop obj) {
639 if (obj instanceof MethodData) {
640 Method m = ((MethodData)obj).getMethod();
641 out.println("MethodData " + obj.getHandle() + " for " +
642 "method " + m.getMethodHolder().getName().asString() + "." +
643 m.getName().asString() +
644 m.getSignature().asString() + "@" + m.getHandle());
645 ((MethodData)obj).printDataOn(out);
646 }
647 return false;
648 }
649 };
650 VM.getVM().getObjectHeap().iteratePerm(iterator);
651 } else {
652 Address a = VM.getVM().getDebugger().parseAddress(s);
653 OopHandle handle = a.addOffsetToAsOopHandle(0);
654 MethodData mdo = (MethodData)VM.getVM().getObjectHeap().newOop(handle);
655 mdo.printDataOn(out);
656 }
657 }
658 }
659 },
660 new Command("dumpideal", "dumpideal { -a | id }", false) {
661 // Do a full dump of the nodes reachabile from root in each compiler thread.
662 public void doit(Tokens t) {
663 if (t.countTokens() != 1) {
664 usage();
665 } else {
666 String name = t.nextToken();
667 boolean all = name.equals("-a");
668 Threads threads = VM.getVM().getThreads();
669 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
670 ByteArrayOutputStream bos = new ByteArrayOutputStream();
671 thread.printThreadIDOn(new PrintStream(bos));
672 if (all || bos.toString().equals(name)) {
673 if (thread instanceof CompilerThread) {
674 CompilerThread ct = (CompilerThread)thread;
675 out.println(ct);
676 ciEnv env = ct.env();
677 if (env != null) {
678 Compile c = env.compilerData();
679 c.root().dump(9999, out);
680 } else {
681 out.println(" not compiling");
682 }
683 }
684 }
685 }
686 }
687 }
688 },
689 new Command("dumpcfg", "dumpcfg { -a | id }", false) {
690 // Dump the PhaseCFG for every compiler thread that has one live.
691 public void doit(Tokens t) {
692 if (t.countTokens() != 1) {
693 usage();
694 } else {
695 String name = t.nextToken();
696 boolean all = name.equals("-a");
697 Threads threads = VM.getVM().getThreads();
698 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
699 ByteArrayOutputStream bos = new ByteArrayOutputStream();
700 thread.printThreadIDOn(new PrintStream(bos));
701 if (all || bos.toString().equals(name)) {
702 if (thread instanceof CompilerThread) {
703 CompilerThread ct = (CompilerThread)thread;
704 out.println(ct);
705 ciEnv env = ct.env();
706 if (env != null) {
707 Compile c = env.compilerData();
708 c.cfg().dump(out);
709 }
710 }
711 }
712 }
713 }
714 }
715 },
716 new Command("dumpilt", "dumpilt { -a | id }", false) {
717 // dumps the InlineTree of a C2 compile
718 public void doit(Tokens t) {
719 if (t.countTokens() != 1) {
720 usage();
721 } else {
722 String name = t.nextToken();
723 boolean all = name.equals("-a");
724 Threads threads = VM.getVM().getThreads();
725 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
726 ByteArrayOutputStream bos = new ByteArrayOutputStream();
727 thread.printThreadIDOn(new PrintStream(bos));
728 if (all || bos.toString().equals(name)) {
729 if (thread instanceof CompilerThread) {
730 CompilerThread ct = (CompilerThread)thread;
731 ciEnv env = ct.env();
732 if (env != null) {
733 Compile c = env.compilerData();
734 InlineTree ilt = c.ilt();
735 if (ilt != null) {
736 ilt.print(out);
737 }
738 }
739 }
740 }
741 }
742 }
743 }
744 },
745 new Command("vmstructsdump", "vmstructsdump", false) {
746 public void doit(Tokens t) {
747 if (t.countTokens() != 0) {
748 usage();
749 return;
750 }
751
752 // Dump a copy of the type database in a form that can
753 // be read back.
754 Iterator i = agent.getTypeDataBase().getTypes();
755 // Make sure the types are emitted in an order than can be read back in
756 HashSet emitted = new HashSet();
757 Stack pending = new Stack();
758 while (i.hasNext()) {
759 Type n = (Type)i.next();
760 if (emitted.contains(n.getName())) {
761 continue;
762 }
763
764 while (n != null && !emitted.contains(n.getName())) {
765 pending.push(n);
766 n = n.getSuperclass();
767 }
768 while (!pending.empty()) {
769 n = (Type)pending.pop();
770 dumpType(n);
771 emitted.add(n.getName());
772 }
773 }
774 i = agent.getTypeDataBase().getTypes();
775 while (i.hasNext()) {
776 dumpFields((Type)i.next(), false);
777 }
778 }
779 },
780
589 new Command("inspect", "inspect expression", false) { 781 new Command("inspect", "inspect expression", false) {
590 public void doit(Tokens t) { 782 public void doit(Tokens t) {
591 if (t.countTokens() != 1) { 783 if (t.countTokens() != 1) {
592 usage(); 784 usage();
593 } else { 785 } else {
755 ex.printStackTrace(); 947 ex.printStackTrace();
756 } 948 }
757 } 949 }
758 base = base.addOffsetTo(step); 950 base = base.addOffsetTo(step);
759 } 951 }
952 }
953 }
954 },
955 new Command("intConstant", "intConstant [ name [ value ] ]", true) {
956 public void doit(Tokens t) {
957 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 2) {
958 usage();
959 return;
960 }
961 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
962 if (t.countTokens() == 1) {
963 out.println("intConstant " + name + " " + db.lookupIntConstant(name));
964 } else if (t.countTokens() == 0) {
965 Iterator i = db.getIntConstants();
966 while (i.hasNext()) {
967 String name = (String)i.next();
968 out.println("intConstant " + name + " " + db.lookupIntConstant(name));
969 }
970 } else if (t.countTokens() == 2) {
971 String name = t.nextToken();
972 Integer value = Integer.valueOf(t.nextToken());
973 db.addIntConstant(name, value);
974 }
975 }
976 },
977 new Command("longConstant", "longConstant [ name [ value ] ]", true) {
978 public void doit(Tokens t) {
979 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 2) {
980 usage();
981 return;
982 }
983 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
984 if (t.countTokens() == 1) {
985 out.println("longConstant " + name + " " + db.lookupLongConstant(name));
986 } else if (t.countTokens() == 0) {
987 Iterator i = db.getLongConstants();
988 while (i.hasNext()) {
989 String name = (String)i.next();
990 out.println("longConstant " + name + " " + db.lookupLongConstant(name));
991 }
992 } else if (t.countTokens() == 2) {
993 String name = t.nextToken();
994 Long value = Long.valueOf(t.nextToken());
995 db.addLongConstant(name, value);
760 } 996 }
761 } 997 }
762 }, 998 },
763 new Command("field", "field [ type [ name fieldtype isStatic offset address ] ]", true) { 999 new Command("field", "field [ type [ name fieldtype isStatic offset address ] ]", true) {
764 public void doit(Tokens t) { 1000 public void doit(Tokens t) {
1309 if (ln == null) { 1545 if (ln == null) {
1310 if (prompt) err.println("Input stream closed."); 1546 if (prompt) err.println("Input stream closed.");
1311 return; 1547 return;
1312 } 1548 }
1313 1549
1314 executeCommand(ln); 1550 executeCommand(ln, prompt);
1315 } 1551 }
1316 } 1552 }
1317 1553
1318 static Pattern historyPattern = Pattern.compile("((!\\*)|(!\\$)|(!!-?)|(!-?[0-9][0-9]*)|(![a-zA-Z][^ ]*))"); 1554 static Pattern historyPattern = Pattern.compile("((!\\*)|(!\\$)|(!!-?)|(!-?[0-9][0-9]*)|(![a-zA-Z][^ ]*))");
1319 1555
1320 public void executeCommand(String ln) { 1556 public void executeCommand(String ln, boolean putInHistory) {
1321 if (ln.indexOf('!') != -1) { 1557 if (ln.indexOf('!') != -1) {
1322 int size = history.size(); 1558 int size = history.size();
1323 if (size == 0) { 1559 if (size == 0) {
1324 ln = ""; 1560 ln = "";
1325 err.println("History is empty"); 1561 err.println("History is empty");
1404 1640
1405 PrintStream redirect = null; 1641 PrintStream redirect = null;
1406 Tokens t = new Tokens(ln); 1642 Tokens t = new Tokens(ln);
1407 if (t.hasMoreTokens()) { 1643 if (t.hasMoreTokens()) {
1408 boolean error = false; 1644 boolean error = false;
1409 history.add(ln); 1645 if (putInHistory) history.add(ln);
1410 int len = t.countTokens(); 1646 int len = t.countTokens();
1411 if (len > 2) { 1647 if (len > 2) {
1412 String r = t.at(len - 2); 1648 String r = t.at(len - 2);
1413 if (r.equals(">") || r.equals(">>")) { 1649 if (r.equals(">") || r.equals(">>")) {
1414 boolean append = r.length() == 2; 1650 boolean append = r.length() == 2;