From: <cr...@us...> - 2008-04-08 13:49:44
|
Revision: 3944 http://jnode.svn.sourceforge.net/jnode/?rev=3944&view=rev Author: crawley Date: 2008-04-08 06:49:41 -0700 (Tue, 08 Apr 2008) Log Message: ----------- Converted 'disasm' command to use new syntax mechanism Use camel-case for argument labels in syntaxes, etc Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-08 13:49:41 UTC (rev 3944) @@ -53,28 +53,40 @@ <option argLabel="remove" shortName="r" description="remove an alias"/> <sequence description="create or update an alias"> <argument argLabel="alias"/> - <argument argLabel="classname"/> + <argument argLabel="className"/> </sequence> </syntax> <syntax alias="class"> - <argument argLabel="classname" description="list details of a Java class"/> + <argument argLabel="className" description="list details of a Java class"/> </syntax> <syntax alias="classpath"> <empty description="print the current classpath"/> - <option argLabel="addurl" longName="add" description="add a URL to the classpath"/> + <option argLabel="addUrl" longName="add" description="add a URL to the classpath"/> <option argLabel="clear" longName="clear" description="remove all URLs from the classpath"/> <option argLabel="refresh" longName="refresh" description="refresh the loaded classes on next use"/> </syntax> <syntax alias="compile"> - <sequence description="print the current classpath"> + <sequence description="compile a class to native code"> <optionSet> <option argLabel="test" longName="test"/> <option argLabel="level" longName="level"/> </optionSet> - <argument argLabel="classname"/> + <argument argLabel="className"/> </sequence> </syntax> <syntax alias="date" description="print the current date"/> + <syntax alias="disasm"> + <sequence description="disassemble a native code class"> + <optionSet> + <option argLabel="test" longName="test"/> + <option argLabel="level" longName="level"/> + </optionSet> + <argument argLabel="className"/> + <repeat minCount="0" maxCount="1"> + <argument argLabel="methodName"/> + </repeat> + </sequence> + </syntax> <syntax alias="set"> <sequence description="set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-04-08 13:49:41 UTC (rev 3944) @@ -52,7 +52,7 @@ public AliasCommand() { super("list, add or remove JNode command aliases"); ARG_ALIAS = new AliasArgument("alias", Argument.OPTIONAL, "the alias to be added"); - ARG_CLASS = new ClassNameArgument("classname", Argument.OPTIONAL, "the classname"); + ARG_CLASS = new ClassNameArgument("className", Argument.OPTIONAL, "the classname"); ARG_REMOVE = new AliasArgument("remove", Argument.OPTIONAL, "the alias to be removed"); registerArguments(ARG_ALIAS, ARG_CLASS, ARG_REMOVE); } Modified: trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java 2008-04-08 13:49:41 UTC (rev 3944) @@ -41,7 +41,7 @@ public class ClassCommand extends AbstractCommand { private final ClassNameArgument ARG_CLASS = - new ClassNameArgument("classname", Argument.SINGLE | Argument.MANDATORY, + new ClassNameArgument("className", Argument.SINGLE | Argument.MANDATORY, "the fully qualified Java name of the class to be viewed"); public ClassCommand() { Modified: trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-04-08 13:49:41 UTC (rev 3944) @@ -40,7 +40,7 @@ public class ClasspathCommand extends AbstractCommand { private final URLArgument ARG_ADD = - new URLArgument("addurl", Argument.OPTIONAL, "the URL to be added to the classpath"); + new URLArgument("addUrl", Argument.OPTIONAL, "the URL to be added to the classpath"); private final FlagArgument ARG_CLEAR = new FlagArgument("clear", Argument.OPTIONAL, "when set, clear the classpath"); Modified: trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-04-08 13:49:41 UTC (rev 3944) @@ -45,7 +45,7 @@ private final int maxLevel = Math.max(maxTestLevel, maxNontestLevel); private final ClassNameArgument ARG_CLASS = - new ClassNameArgument("classname", Argument.MANDATORY, "the class file to compile"); + new ClassNameArgument("className", Argument.MANDATORY, "the class file to compile"); private final IntegerArgument ARG_LEVEL = new IntegerArgument("level", Argument.OPTIONAL, 0, maxLevel, "the optimization level"); private final FlagArgument ARG_TEST = Modified: trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java 2008-04-08 13:47:57 UTC (rev 3943) +++ trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java 2008-04-08 13:49:41 UTC (rev 3944) @@ -21,48 +21,86 @@ package org.jnode.shell.command; +import java.io.InputStream; import java.io.OutputStreamWriter; +import java.io.PrintStream; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.ClassNameArgument; -import org.jnode.shell.help.argument.IntegerArgument; -import org.jnode.shell.help.argument.StringArgument; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.ClassNameArgument; +import org.jnode.shell.syntax.FlagArgument; +import org.jnode.shell.syntax.IntegerArgument; +import org.jnode.shell.syntax.StringArgument; +import org.jnode.vm.LoadCompileService; import org.jnode.vm.classmgr.VmType; /** * @author Levente S\u00e1ntha + * @author cl...@jn... */ -public class DisassembleCommand { +public class DisassembleCommand extends AbstractCommand { + private final int maxTestLevel = + LoadCompileService.getHighestOptimizationLevel(true); + private final int maxNontestLevel = + LoadCompileService.getHighestOptimizationLevel(false); + private final int maxLevel = Math.max(maxTestLevel, maxNontestLevel); + + private final ClassNameArgument ARG_CLASS = + new ClassNameArgument("className", Argument.MANDATORY, "the class to disassemble"); + private final StringArgument ARG_METHOD = + new StringArgument("methodName", Argument.OPTIONAL, "the method to disassemble"); + private final IntegerArgument ARG_LEVEL = + new IntegerArgument("level", Argument.OPTIONAL, 0, maxLevel, "the optimization level"); + private final FlagArgument ARG_TEST = + new FlagArgument("test", Argument.OPTIONAL, "If set, the test compilers are used"); + + public DisassembleCommand() { + super("disassemble a Java class or method"); + registerArguments(ARG_CLASS, ARG_METHOD, ARG_LEVEL, ARG_TEST); + } - static final ClassNameArgument ARG_CLASS = new ClassNameArgument("className", "the class to disassemble"); - static final StringArgument ARG_METHOD = new StringArgument("methodName", "the method to disassemble"); - static final IntegerArgument ARG_LEVEL = new IntegerArgument("level", "the optimization level"); - static final IntegerArgument ARG_TEST = new IntegerArgument("test", "If 1, the test compilers are used"); - static final Parameter PARAM_LEVEL = new Parameter(ARG_LEVEL, Parameter.OPTIONAL); - static final Parameter PARAM_TEST = new Parameter(ARG_TEST, Parameter.OPTIONAL); - - public static Help.Info HELP_INFO = new Help.Info("disasm", "Disassemble a Java class or method", - new Parameter[] { - new Parameter(ARG_CLASS, Parameter.MANDATORY), - new Parameter(ARG_METHOD, Parameter.OPTIONAL), - PARAM_LEVEL, PARAM_TEST}); + public static void main(String[] args) throws Exception { + new DisassembleCommand().execute(args); + } - public static void main(String[] args) throws Exception { - final ParsedArguments cmdLine = HELP_INFO.parse(args); - - final String className = ARG_CLASS.getValue(cmdLine); - final String methodName = ARG_METHOD.getValue(cmdLine); - final int level = PARAM_LEVEL.isSet(cmdLine) ? ARG_LEVEL.getInteger(cmdLine) : 0; - final boolean test = PARAM_TEST.isSet(cmdLine) ? (ARG_TEST.getInteger(cmdLine) != 0) : false; - - final ClassLoader cl = Thread.currentThread().getContextClassLoader(); - final Class<?> cls = cl.loadClass(className); - final VmType<?> type = cls.getVmClass(); - final long start = System.currentTimeMillis(); - final int count = type.disassemble(methodName, level, test, new OutputStreamWriter(System.out)); - final long end = System.currentTimeMillis(); - System.out.println("Disassembling " + count + " methods took " + (end - start) + "ms"); - } + @Override + public void execute(CommandLine commandLine, InputStream in, + PrintStream out, PrintStream err) throws Exception { + final String className = ARG_CLASS.getValue(); + final String methodName = ARG_METHOD.isSet() ? ARG_METHOD.getValue() : null; + final int level = ARG_LEVEL.isSet() ? ARG_LEVEL.getValue() : 0; + final boolean test = ARG_TEST.isSet(); + + final ClassLoader cl = Thread.currentThread().getContextClassLoader(); + Class<?> cls; + try { + cls = cl.loadClass(className); + } + catch (ClassNotFoundException ex) { + err.println("Class '" + className + "' not found"); + exit(1); + // not reached + return; + } + final VmType<?> type = cls.getVmClass(); + if (test) { + if (maxTestLevel == -1) { + err.println("No test compilers are currently registered"); + exit(1); + } + else if (maxTestLevel < level) { + err.println("The highest (test) optimization level is " + maxTestLevel); + exit(1); + } + } + else if (maxNontestLevel < level) { + err.println("The highest optimization level is " + maxNontestLevel); + exit(1); + } + final long start = System.currentTimeMillis(); + final int count = type.disassemble(methodName, level, test, new OutputStreamWriter(out)); + final long end = System.currentTimeMillis(); + out.println("Disassembling " + count + " methods took " + (end - start) + "ms"); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |