461 if (!t.hasMoreTokens()) {
462 printThreadGroup(ThreadInfo.group());
463 return;
464 }
465 String name = t.nextToken();
466 ThreadGroupReference tg = ThreadGroupIterator.find(name);
467 if (tg == null) {
468 MessageOutput.println("is not a valid threadgroup name", name);
469 } else {
470 printThreadGroup(tg);
471 }
472 }
473
474 void commandThreadGroups() {
475 ThreadGroupIterator it = new ThreadGroupIterator();
476 int cnt = 0;
477 while (it.hasNext()) {
478 ThreadGroupReference tg = it.nextThreadGroup();
479 ++cnt;
480 MessageOutput.println("thread group number description name",
481 new Object [] { new Integer (cnt),
482 Env.description(tg),
483 tg.name()});
484 }
485 }
486
487 void commandThread(StringTokenizer t) {
488 if (!t.hasMoreTokens()) {
489 MessageOutput.println("Thread number not specified.");
490 return;
491 }
492 ThreadInfo threadInfo = doGetThread(t.nextToken());
493 if (threadInfo != null) {
494 ThreadInfo.setCurrentThreadInfo(threadInfo);
495 }
496 }
497
498 void commandThreadGroup(StringTokenizer t) {
499 if (!t.hasMoreTokens()) {
500 MessageOutput.println("Threadgroup name not specified.");
501 return;
997 }
998 }
999 }
1000
1001 void commandMemory() {
1002 MessageOutput.println("The memory command is no longer supported.");
1003 }
1004
1005 void commandGC() {
1006 MessageOutput.println("The gc command is no longer necessary.");
1007 }
1008
1009 /*
1010 * The next two methods are used by this class and by EventHandler
1011 * to print consistent locations and error messages.
1012 */
1013 static String locationString(Location loc) {
1014 return MessageOutput.format("locationString",
1015 new Object [] {loc.declaringType().name(),
1016 loc.method().name(),
1017 new Integer (loc.lineNumber()),
1018 Long.valueOf(loc.codeIndex())});
1019 }
1020
1021 void listBreakpoints() {
1022 boolean noBreakpoints = true;
1023
1024 // Print set breakpoints
1025 for (EventRequestSpec spec : Env.specList.eventRequestSpecs()) {
1026 if (spec instanceof BreakpointSpec) {
1027 if (noBreakpoints) {
1028 noBreakpoints = false;
1029 MessageOutput.println("Breakpoints set:");
1030 }
1031 MessageOutput.println("tab", spec.toString());
1032 }
1033 }
1034 if (noBreakpoints) {
1035 MessageOutput.println("No breakpoints set.");
1036 }
1037 }
1450 List<Method> meths = refType.methodsByName(id);
1451 if (meths == null || meths.size() == 0) {
1452 MessageOutput.println("is not a valid line number or method name for",
1453 new Object [] {id, refType.name()});
1454 return;
1455 } else if (meths.size() > 1) {
1456 MessageOutput.println("is an ambiguous method name in",
1457 new Object [] {id, refType.name()});
1458 return;
1459 }
1460 loc = meths.get(0).location();
1461 lineno = loc.lineNumber();
1462 }
1463 }
1464 int startLine = Math.max(lineno - 4, 1);
1465 int endLine = startLine + 9;
1466 if (lineno < 0) {
1467 MessageOutput.println("Line number information not available for");
1468 } else if (Env.sourceLine(loc, lineno) == null) {
1469 MessageOutput.println("is an invalid line number for",
1470 new Object [] {new Integer (lineno),
1471 refType.name()});
1472 } else {
1473 for (int i = startLine; i <= endLine; i++) {
1474 String sourceLine = Env.sourceLine(loc, i);
1475 if (sourceLine == null) {
1476 break;
1477 }
1478 if (i == lineno) {
1479 MessageOutput.println("source line number current line and line",
1480 new Object [] {new Integer (i),
1481 sourceLine});
1482 } else {
1483 MessageOutput.println("source line number and line",
1484 new Object [] {new Integer (i),
1485 sourceLine});
1486 }
1487 }
1488 }
1489 } catch (AbsentInformationException e) {
1490 MessageOutput.println("No source information available for:", loc.toString());
1491 } catch(FileNotFoundException exc) {
1492 MessageOutput.println("Source file not found:", sourceFileName);
1493 } catch(IOException exc) {
1494 MessageOutput.println("I/O exception occurred:", exc.toString());
1495 }
1496 }
1497
1498 void commandLines(StringTokenizer t) { // Undocumented command: useful for testing
1499 if (!t.hasMoreTokens()) {
1500 MessageOutput.println("Specify class and method");
1501 } else {
1502 String idClass = t.nextToken();
1503 String idMethod = t.hasMoreTokens() ? t.nextToken() : null;
1504 try {
1708 }
1709
1710 String expr = t.nextToken("");
1711 Value val = evaluate(expr);
1712
1713 try {
1714 if ((val != null) && (val instanceof ObjectReference)) {
1715 ObjectReference object = (ObjectReference)val;
1716 String strVal = getStringValue();
1717 if (strVal != null) {
1718 MessageOutput.println("Monitor information for expr",
1719 new Object [] {expr.trim(),
1720 strVal});
1721 }
1722 ThreadReference owner = object.owningThread();
1723 if (owner == null) {
1724 MessageOutput.println("Not owned");
1725 } else {
1726 MessageOutput.println("Owned by:",
1727 new Object [] {owner.name(),
1728 new Integer (object.entryCount())});
1729 }
1730 List<ThreadReference> waiters = object.waitingThreads();
1731 if (waiters.size() == 0) {
1732 MessageOutput.println("No waiters");
1733 } else {
1734 for (ThreadReference waiter : waiters) {
1735 MessageOutput.println("Waiting thread:", waiter.name());
1736 }
1737 }
1738 } else {
1739 MessageOutput.println("Expression must evaluate to an object");
1740 }
1741 } catch (IncompatibleThreadStateException e) {
1742 MessageOutput.println("Threads must be suspended");
1743 }
1744 }
1745
1746 void commandLock(final StringTokenizer t) {
1747 new AsyncExecution() {
1748 @Override
|
461 if (!t.hasMoreTokens()) {
462 printThreadGroup(ThreadInfo.group());
463 return;
464 }
465 String name = t.nextToken();
466 ThreadGroupReference tg = ThreadGroupIterator.find(name);
467 if (tg == null) {
468 MessageOutput.println("is not a valid threadgroup name", name);
469 } else {
470 printThreadGroup(tg);
471 }
472 }
473
474 void commandThreadGroups() {
475 ThreadGroupIterator it = new ThreadGroupIterator();
476 int cnt = 0;
477 while (it.hasNext()) {
478 ThreadGroupReference tg = it.nextThreadGroup();
479 ++cnt;
480 MessageOutput.println("thread group number description name",
481 new Object [] { Integer.valueOf(cnt),
482 Env.description(tg),
483 tg.name()});
484 }
485 }
486
487 void commandThread(StringTokenizer t) {
488 if (!t.hasMoreTokens()) {
489 MessageOutput.println("Thread number not specified.");
490 return;
491 }
492 ThreadInfo threadInfo = doGetThread(t.nextToken());
493 if (threadInfo != null) {
494 ThreadInfo.setCurrentThreadInfo(threadInfo);
495 }
496 }
497
498 void commandThreadGroup(StringTokenizer t) {
499 if (!t.hasMoreTokens()) {
500 MessageOutput.println("Threadgroup name not specified.");
501 return;
997 }
998 }
999 }
1000
1001 void commandMemory() {
1002 MessageOutput.println("The memory command is no longer supported.");
1003 }
1004
1005 void commandGC() {
1006 MessageOutput.println("The gc command is no longer necessary.");
1007 }
1008
1009 /*
1010 * The next two methods are used by this class and by EventHandler
1011 * to print consistent locations and error messages.
1012 */
1013 static String locationString(Location loc) {
1014 return MessageOutput.format("locationString",
1015 new Object [] {loc.declaringType().name(),
1016 loc.method().name(),
1017 Integer.valueOf(loc.lineNumber()),
1018 Long.valueOf(loc.codeIndex())});
1019 }
1020
1021 void listBreakpoints() {
1022 boolean noBreakpoints = true;
1023
1024 // Print set breakpoints
1025 for (EventRequestSpec spec : Env.specList.eventRequestSpecs()) {
1026 if (spec instanceof BreakpointSpec) {
1027 if (noBreakpoints) {
1028 noBreakpoints = false;
1029 MessageOutput.println("Breakpoints set:");
1030 }
1031 MessageOutput.println("tab", spec.toString());
1032 }
1033 }
1034 if (noBreakpoints) {
1035 MessageOutput.println("No breakpoints set.");
1036 }
1037 }
1450 List<Method> meths = refType.methodsByName(id);
1451 if (meths == null || meths.size() == 0) {
1452 MessageOutput.println("is not a valid line number or method name for",
1453 new Object [] {id, refType.name()});
1454 return;
1455 } else if (meths.size() > 1) {
1456 MessageOutput.println("is an ambiguous method name in",
1457 new Object [] {id, refType.name()});
1458 return;
1459 }
1460 loc = meths.get(0).location();
1461 lineno = loc.lineNumber();
1462 }
1463 }
1464 int startLine = Math.max(lineno - 4, 1);
1465 int endLine = startLine + 9;
1466 if (lineno < 0) {
1467 MessageOutput.println("Line number information not available for");
1468 } else if (Env.sourceLine(loc, lineno) == null) {
1469 MessageOutput.println("is an invalid line number for",
1470 new Object [] {Integer.valueOf(lineno),
1471 refType.name()});
1472 } else {
1473 for (int i = startLine; i <= endLine; i++) {
1474 String sourceLine = Env.sourceLine(loc, i);
1475 if (sourceLine == null) {
1476 break;
1477 }
1478 if (i == lineno) {
1479 MessageOutput.println("source line number current line and line",
1480 new Object [] {Integer.valueOf(i),
1481 sourceLine});
1482 } else {
1483 MessageOutput.println("source line number and line",
1484 new Object [] {Integer.valueOf(i),
1485 sourceLine});
1486 }
1487 }
1488 }
1489 } catch (AbsentInformationException e) {
1490 MessageOutput.println("No source information available for:", loc.toString());
1491 } catch(FileNotFoundException exc) {
1492 MessageOutput.println("Source file not found:", sourceFileName);
1493 } catch(IOException exc) {
1494 MessageOutput.println("I/O exception occurred:", exc.toString());
1495 }
1496 }
1497
1498 void commandLines(StringTokenizer t) { // Undocumented command: useful for testing
1499 if (!t.hasMoreTokens()) {
1500 MessageOutput.println("Specify class and method");
1501 } else {
1502 String idClass = t.nextToken();
1503 String idMethod = t.hasMoreTokens() ? t.nextToken() : null;
1504 try {
1708 }
1709
1710 String expr = t.nextToken("");
1711 Value val = evaluate(expr);
1712
1713 try {
1714 if ((val != null) && (val instanceof ObjectReference)) {
1715 ObjectReference object = (ObjectReference)val;
1716 String strVal = getStringValue();
1717 if (strVal != null) {
1718 MessageOutput.println("Monitor information for expr",
1719 new Object [] {expr.trim(),
1720 strVal});
1721 }
1722 ThreadReference owner = object.owningThread();
1723 if (owner == null) {
1724 MessageOutput.println("Not owned");
1725 } else {
1726 MessageOutput.println("Owned by:",
1727 new Object [] {owner.name(),
1728 Integer.valueOf(object.entryCount())});
1729 }
1730 List<ThreadReference> waiters = object.waitingThreads();
1731 if (waiters.size() == 0) {
1732 MessageOutput.println("No waiters");
1733 } else {
1734 for (ThreadReference waiter : waiters) {
1735 MessageOutput.println("Waiting thread:", waiter.name());
1736 }
1737 }
1738 } else {
1739 MessageOutput.println("Expression must evaluate to an object");
1740 }
1741 } catch (IncompatibleThreadStateException e) {
1742 MessageOutput.println("Threads must be suspended");
1743 }
1744 }
1745
1746 void commandLock(final StringTokenizer t) {
1747 new AsyncExecution() {
1748 @Override
|