org.jikesrvm
Class CommandLineArgs

java.lang.Object
  extended by org.jikesrvm.CommandLineArgs

public class CommandLineArgs
extends Object

Command line option processing iwth arbitrary prefix support.


Nested Class Summary
private static class CommandLineArgs.ArgReader
           
private static class CommandLineArgs.Prefix
          Represent a single command line prefix
private static class CommandLineArgs.PrefixType
          Argument types
 
Field Summary
private static int app_name_pos
          The position of application class name.
private static CommandLineArgs.Prefix app_prefix
          A catch-all prefix to find application name.
private static CommandLineArgs.PrefixType[] arg_types
          The types of each command line argument.
private static String[] args
          The command line arguments.
private static boolean DEBUG
           
private static CommandLineArgs.Prefix[] prefixes
          A list of possible prefixes for command line arguments.
 
Constructor Summary
CommandLineArgs()
           
 
Method Summary
(package private) static void earlyProcessCommandLineArguments()
          Stage1 processing of virtual machine directives appearing in argument list.
(package private) static void fetchCommandLineArguments()
          Fetch arguments from program command line.
private static CommandLineArgs.Prefix findPrefix(CommandLineArgs.PrefixType type)
          Find a Prefix object of a given type.
static String[] getArgs(CommandLineArgs.PrefixType prefix)
          Extract all command line arguments of a particular type.
static String getBootstrapClasses()
          Extract the classes that should go through bootstrap classloader.
private static String getCWD()
           
static String getEnvironmentArg(String variable)
          Extract the first -D... command line argument that matches a given variable, and return it.
static String[] getEnvironmentArgs()
          Get all environment arguments as pairs of string of key followed by value
static String[] getJavaAgentArgs()
          Extract command line arguments for the Java agent
private static String getOsArch()
           
private static String getOsName()
           
private static String getOsVersion()
           
private static String getRvmRoot()
           
private static String getUserHome()
           
(package private) static String[] lateProcessCommandLineArguments()
          Stage2 processing of virtual machine directives appearing in argument list.
private static int length(String p)
          The real length of the prefix.
private static boolean matches(String arg, String p)
          Does the argument match the prefix?
static long parseMemorySize(String sizeName, String sizeFlag, String defaultFactor, int roundTo, String fullArg, String subArg)
          Primitive parsing of memory sizes, with proper error handling, and so on.
static float primitiveParseFloat(String arg)
          Primitive parsing of float/double values.
static int primitiveParseInt(String arg)
          Primitive parsing of byte/integer numeric values.
private static byte[] s2b(String arg)
          Convenience method for calling stringToBytes
private static byte[] stringToBytes(String argName, String arg)
          Convert the string s (the "argument") to a null-terminated byte array.
private static int sysArg(int argno, byte[] buf)
          Read the argno'th command line argument from the C argv
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

app_prefix

private static final CommandLineArgs.Prefix app_prefix
A catch-all prefix to find application name.


prefixes

private static final CommandLineArgs.Prefix[] prefixes
A list of possible prefixes for command line arguments. Each argument will be classified by the prefix it matches. One prefix can contain another.

Prefixes are normally matched with the start of the argument. If the last character of the prefix is a '$', the prefix (without the trailing '$') will be matched with the whole argument. If the last character of the prefix is a ' ' (space), the prefix (without the trailing ' ') will be matched with the whole argument, and the next argument will be appended to the end of the one matching the prefix, with a space in between.

The type will be used to classify the prefix. Multiple entries CAN have the same type.


args

private static String[] args
The command line arguments.


arg_types

private static CommandLineArgs.PrefixType[] arg_types
The types of each command line argument.


app_name_pos

private static int app_name_pos
The position of application class name.

Constructor Detail

CommandLineArgs

public CommandLineArgs()
Method Detail

fetchCommandLineArguments

static void fetchCommandLineArguments()
Fetch arguments from program command line.


matches

private static boolean matches(String arg,
                               String p)
Does the argument match the prefix?

Parameters:
arg - argument
p - prefix
Returns:
true if argument "matches" the prefix, false otherwise

length

private static int length(String p)
The real length of the prefix.

Parameters:
p - prefix
Returns:
real length of prefix

findPrefix

private static CommandLineArgs.Prefix findPrefix(CommandLineArgs.PrefixType type)
Find a Prefix object of a given type.

Parameters:
type - given type
Returns:
prefix if found, null otherwise

getArgs

public static String[] getArgs(CommandLineArgs.PrefixType prefix)
Extract all command line arguments of a particular type. Strips out the prefixes (if any). !!TODO: cache results instead of constructing a new array each time.

Parameters:
prefix - type of arguments to extract
Returns:
array of arguments or null if type is invalid

getJavaAgentArgs

public static String[] getJavaAgentArgs()
Extract command line arguments for the Java agent

Returns:
Java agent arguments

getEnvironmentArgs

public static String[] getEnvironmentArgs()
Get all environment arguments as pairs of string of key followed by value

Returns:
all environment arguments or null, if none were found

getEnvironmentArg

public static String getEnvironmentArg(String variable)
Extract the first -D... command line argument that matches a given variable, and return it.

Parameters:
variable - the non-null variable to match
Returns:
the environment arg, or null if there is none.

getRvmRoot

private static String getRvmRoot()

getUserHome

private static String getUserHome()

getCWD

private static String getCWD()

getOsName

private static String getOsName()

getOsVersion

private static String getOsVersion()

getOsArch

private static String getOsArch()

getBootstrapClasses

public static String getBootstrapClasses()
Extract the classes that should go through bootstrap classloader.

Returns:
null if no such command line argument is given.

earlyProcessCommandLineArguments

static void earlyProcessCommandLineArguments()
Stage1 processing of virtual machine directives appearing in argument list. We try to process as many classes of command line arguments as possible here. Only those command line arguments that require a more or less fully booted VM to handle are delayed until lateProcessCommandLineArguments.


lateProcessCommandLineArguments

static String[] lateProcessCommandLineArguments()
Stage2 processing of virtual machine directives appearing in argument list. This function is responsible for processing the few command line arguments that need to be handled late in booting. It also returns the application's command line arguments.

Returns:
application arguments (first is application class name) If no application arguments are specified on the command line, process commands anyway.

sysArg

private static int sysArg(int argno,
                          byte[] buf)
Read the argno'th command line argument from the C argv

Parameters:
argno - Number of argument sought
buf - Buffer to fill
Returns:
number of bytes placed in buffer. -1 means buffer too small for argument to fit)

primitiveParseFloat

public static float primitiveParseFloat(String arg)
Primitive parsing of float/double values. Done this way to enable us to parse command line arguments early in VM booting before we are able to do the JNI call that using Double.valueOf would require. Does not support the full Java specification.

Parameters:
arg - the float value to parse
Returns:
value as float

primitiveParseInt

public static int primitiveParseInt(String arg)
Primitive parsing of byte/integer numeric values. Done this way to enable us to parse command line arguments early in VM booting before we are able call Byte.parseByte or Integer.parseInt.

Parameters:
arg - the int or byte value to parse
Returns:
value as int

parseMemorySize

public static long parseMemorySize(String sizeName,
                                   String sizeFlag,
                                   String defaultFactor,
                                   int roundTo,
                                   String fullArg,
                                   String subArg)
Primitive parsing of memory sizes, with proper error handling, and so on. Works without needing Byte.parseByte or Integer.parseInt(). At the moment, we have a maximum limit of an unsigned integer. If

Returns:
Negative values on error. Otherwise, positive or zero values as bytes.

s2b

private static byte[] s2b(String arg)
Convenience method for calling stringToBytes


stringToBytes

private static byte[] stringToBytes(String argName,
                                    String arg)
Convert the string s (the "argument") to a null-terminated byte array. This is used for converting arguments and for converting fixed strings we pass down to lower commands.

Parameters:
arg - the argument to convert
argName - text to print for error reporting.
Returns:
a byte array that represents arg as a null-terminated C string. Returns null for a null arg.