1 /* Copyright (C) 1999-2005 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
21 printf ("Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
22 printf (" to interpret Java bytecodes, or\n");
23 printf (" gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
24 printf (" to execute a jar file\n\n");
25 printf (" --cp LIST set class path\n");
26 printf (" --classpath LIST set class path\n");
27 printf (" -DVAR=VAL define property VAR with value VAL\n");
28 printf (" -?, --help print this help, then exit\n");
29 printf (" -X print help on supported -X options, then exit\n");
30 printf (" --ms=NUMBER set initial heap size\n");
31 printf (" --mx=NUMBER set maximum heap size\n");
32 printf (" --verbose[:class] print information about class loading\n");
33 printf (" --showversion print version number, then keep going\n");
34 printf (" --version print version number, then exit\n");
35 printf ("\nOptions can be specified with `-' or `--'.\n");
36 printf ("\nSee http://gcc.gnu.org/java/ for information on reporting bugs\n");
43 printf ("java version \"" JV_VERSION
"\"\n");
44 printf ("gij (GNU libgcj) version %s\n\n", __VERSION__
);
45 printf ("Copyright (C) 2005 Free Software Foundation, Inc.\n");
46 printf ("This is free software; see the source for copying conditions. There is NO\n");
47 printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
51 nonstandard_opts_help ()
53 printf (" -Xms<size> set initial heap size\n");
54 printf (" -Xmx<size> set maximum heap size\n");
59 add_option (JvVMInitArgs
& vm_args
, char const* option
, void const* extra
)
62 (JvVMOption
*) JvRealloc (vm_args
.options
,
63 (vm_args
.nOptions
+ 1) * sizeof (JvVMOption
));
65 vm_args
.options
[vm_args
.nOptions
].optionString
= const_cast<char*> (option
);
66 vm_args
.options
[vm_args
.nOptions
].extraInfo
= const_cast<void*> (extra
);
71 main (int argc
, char const** argv
)
74 bool jar_mode
= false;
76 vm_args
.options
= NULL
;
78 vm_args
.ignoreUnrecognized
= true;
80 // Command-line options always override the CLASSPATH environment
82 char *classpath
= getenv("CLASSPATH");
86 char* darg
= (char*) JvMalloc (strlen (classpath
)
87 + sizeof ("-Djava.class.path="));
88 sprintf (darg
, "-Djava.class.path=%s", classpath
);
89 add_option (vm_args
, darg
, NULL
);
92 // Handle arguments to the java command. Store in vm_args arguments
93 // handled by the invocation API.
95 for (i
= 1; i
< argc
; ++i
)
97 char* arg
= const_cast<char*> (argv
[i
]);
99 // A non-option stops processing.
103 // A "--" stops processing.
104 if (! strcmp (arg
, "--"))
110 // Allow both single or double hyphen for all options.
114 // Ignore JIT options
115 if (! strcmp (arg
, "-client"))
117 else if (! strcmp (arg
, "-server"))
119 else if (! strcmp (arg
, "-hotspot"))
121 else if (! strcmp (arg
, "-jrockit"))
123 // Ignore JVM Tool Interface options
124 else if (! strncmp (arg
, "-agentlib:", sizeof ("-agentlib:") - 1))
126 else if (! strncmp (arg
, "-agentpath:", sizeof ("-agentpath:") - 1))
128 else if (! strcmp (arg
, "-classpath") || ! strcmp (arg
, "-cp"))
133 fprintf (stderr
, "gij: option requires an argument -- `%s'\n",
135 fprintf (stderr
, "Try `gij --help' for more information.\n");
139 // Sun seems to translate the -classpath option into
140 // -Djava.class.path because if both -classpath and
141 // -Djava.class.path are specified on the java command line,
142 // the last one always wins.
143 char* darg
= (char*) JvMalloc (strlen (argv
[++i
])
144 + sizeof ("-Djava.class.path="));
145 sprintf (darg
, "-Djava.class.path=%s", argv
[i
]);
146 add_option (vm_args
, darg
, NULL
);
148 else if (! strcmp (arg
, "-debug"))
150 char* xarg
= strdup ("-Xdebug");
151 add_option (vm_args
, xarg
, NULL
);
153 else if (! strncmp (arg
, "-D", sizeof ("-D") - 1))
154 add_option (vm_args
, arg
, NULL
);
155 // Ignore 32/64-bit JIT options
156 else if (! strcmp (arg
, "-d32") || ! strcmp (arg
, "-d64"))
158 else if (! strcmp (arg
, "-enableassertions") || ! strcmp (arg
, "-ea"))
162 // FIXME: hook up assertion support
166 else if (! strcmp (arg
, "-disableassertions") || ! strcmp (arg
, "-da"))
174 else if (! strcmp (arg
, "-enablesystemassertions")
175 || ! strcmp (arg
, "-esa"))
177 // FIXME: hook up system assertion support
180 else if (! strcmp (arg
, "-disablesystemassertions")
181 || ! strcmp (arg
, "-dsa"))
186 else if (! strcmp (arg
, "-jar"))
191 // Ignore java.lang.instrument option
192 else if (! strncmp (arg
, "-javaagent:", sizeof ("-javaagent:") - 1))
194 else if (! strcmp (arg
, "-noclassgc"))
196 char* xarg
= strdup ("-Xnoclassgc");
197 add_option (vm_args
, xarg
, NULL
);
200 else if (! strncmp (arg
, "-ms=", sizeof ("-ms=") - 1))
205 add_option (vm_args
, arg
, NULL
);
208 else if (! strcmp (arg
, "-ms"))
213 char* xarg
= (char*) JvMalloc (strlen (argv
[++i
])
215 sprintf (xarg
, "-Xms%s", argv
[i
]);
216 add_option (vm_args
, xarg
, NULL
);
219 else if (! strncmp (arg
, "-ms", sizeof ("-ms") - 1))
221 char* xarg
= (char*) JvMalloc (strlen (arg
) + sizeof ("X"));
222 sprintf (xarg
, "-Xms%s", arg
+ sizeof ("-Xms") - 1);
223 add_option (vm_args
, xarg
, NULL
);
226 else if (! strncmp (arg
, "-mx=", sizeof ("-mx=") - 1))
231 add_option (vm_args
, arg
, NULL
);
234 else if (! strcmp (arg
, "-mx"))
239 char* xarg
= (char*) JvMalloc (strlen (argv
[++i
])
241 sprintf (xarg
, "-Xmx%s", argv
[i
]);
242 add_option (vm_args
, xarg
, NULL
);
245 else if (! strncmp (arg
, "-mx", sizeof ("-mx") - 1))
247 char* xarg
= (char*) JvMalloc (strlen (arg
) + sizeof ("X"));
248 sprintf (xarg
, "-Xmx%s", arg
+ sizeof ("-Xmx") - 1);
249 add_option (vm_args
, xarg
, NULL
);
252 else if (! strncmp (arg
, "-ss=", sizeof ("-ss=") - 1))
257 add_option (vm_args
, arg
, NULL
);
260 else if (! strcmp (arg
, "-ss"))
265 char* xarg
= (char*) JvMalloc (strlen (argv
[++i
])
267 sprintf (xarg
, "-Xss%s", argv
[i
]);
268 add_option (vm_args
, xarg
, NULL
);
271 else if (! strncmp (arg
, "-ss", sizeof ("-ss") - 1))
273 char* xarg
= (char*) JvMalloc (strlen (arg
) + sizeof ("X"));
274 sprintf (xarg
, "-Xss%s", arg
+ sizeof ("-Xss") - 1);
275 add_option (vm_args
, xarg
, NULL
);
277 // This handles all the option variants that begin with
279 else if (! strncmp (arg
, "-verbose", 8))
280 add_option (vm_args
, arg
, NULL
);
281 else if (! strcmp (arg
, "-version"))
286 else if (! strcmp (arg
, "-fullversion"))
288 printf ("java full version \"gcj-" JV_VERSION
"\"\n");
291 else if (! strcmp (arg
, "-showversion"))
293 else if (! strcmp (arg
, "-help") || ! strcmp (arg
, "-?"))
295 else if (! strcmp (arg
, "-X"))
296 nonstandard_opts_help ();
297 else if (! strncmp (arg
, "-X", 2))
298 add_option (vm_args
, arg
, NULL
);
299 // Obsolete options recognized for backwards-compatibility.
300 else if (! strcmp (arg
, "-verify")
301 || ! strcmp (arg
, "-verifyremote"))
303 else if (! strcmp (arg
, "-noverify"))
305 gcj::verifyClasses
= false;
309 fprintf (stderr
, "gij: unrecognized option -- `%s'\n", argv
[i
]);
310 fprintf (stderr
, "Try `gij --help' for more information.\n");
317 fprintf (stderr
, "Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
318 fprintf (stderr
, " to invoke CLASS.main, or\n");
319 fprintf (stderr
, " gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
320 fprintf (stderr
, " to execute a jar file\n");
321 fprintf (stderr
, "Try `gij --help' for more information.\n");
325 // -jar mode overrides all other modes of specifying class path:
326 // CLASSPATH, -Djava.class.path, -classpath and -cp.
329 char* darg
= (char*) JvMalloc (strlen (argv
[i
])
330 + sizeof ("-Djava.class.path="));
331 sprintf (darg
, "-Djava.class.path=%s", argv
[i
]);
332 add_option (vm_args
, darg
, NULL
);
335 _Jv_RunMain (&vm_args
, NULL
, argv
[i
], argc
- i
,
336 (char const**) (argv
+ i
), jar_mode
);