1 /* Copyright (C) 1999-2007 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) 2007 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");
55 printf (" -Xss<size> set thread stack size\n");
60 add_option (JvVMInitArgs& vm_args, char const* option, void const* extra)
63 (JvVMOption*) JvRealloc (vm_args.options,
64 (vm_args.nOptions + 1) * sizeof (JvVMOption));
66 vm_args.options[vm_args.nOptions].optionString = const_cast<char*> (option);
67 vm_args.options[vm_args.nOptions].extraInfo = const_cast<void*> (extra);
72 main (int argc, char const** argv)
75 bool jar_mode = false;
77 vm_args.options = NULL;
79 vm_args.ignoreUnrecognized = true;
81 // Command-line options always override the CLASSPATH environment
83 char *classpath = getenv("CLASSPATH");
87 char* darg = (char*) JvMalloc (strlen (classpath)
88 + sizeof ("-Djava.class.path="));
89 sprintf (darg, "-Djava.class.path=%s", classpath);
90 add_option (vm_args, darg, NULL);
93 // Handle arguments to the java command. Store in vm_args arguments
94 // handled by the invocation API.
96 for (i = 1; i < argc; ++i)
98 char* arg = const_cast<char*> (argv[i]);
100 // A non-option stops processing.
104 // A "--" stops processing.
105 if (! strcmp (arg, "--"))
111 // Allow both single or double hyphen for all options.
115 // Ignore JIT options
116 if (! strcmp (arg, "-client"))
118 else if (! strcmp (arg, "-server"))
120 else if (! strcmp (arg, "-hotspot"))
122 else if (! strcmp (arg, "-jrockit"))
124 // JVM Tool Interface options.
125 else if (! strncmp (arg, "-agentlib:", sizeof ("-agentlib:") - 1))
126 add_option (vm_args, arg, NULL);
127 else if (! strncmp (arg, "-agentpath:", sizeof ("-agentpath:") - 1))
128 add_option (vm_args, arg, NULL);
129 else if (! strcmp (arg, "-classpath") || ! strcmp (arg, "-cp"))
134 fprintf (stderr, "gij: option requires an argument -- `%s'\n",
136 fprintf (stderr, "Try `gij --help' for more information.\n");
140 // Sun seems to translate the -classpath option into
141 // -Djava.class.path because if both -classpath and
142 // -Djava.class.path are specified on the java command line,
143 // the last one always wins.
144 char* darg = (char*) JvMalloc (strlen (argv[++i])
145 + sizeof ("-Djava.class.path="));
146 sprintf (darg, "-Djava.class.path=%s", argv[i]);
147 add_option (vm_args, darg, NULL);
149 else if (! strcmp (arg, "-debug"))
151 char* xarg = strdup ("-Xdebug");
152 add_option (vm_args, xarg, NULL);
154 else if (! strncmp (arg, "-D", sizeof ("-D") - 1))
155 add_option (vm_args, arg, NULL);
156 // Ignore 32/64-bit JIT options
157 else if (! strcmp (arg, "-d32") || ! strcmp (arg, "-d64"))
159 else if (! strncmp (arg, "-enableassertions", sizeof ("-enableassertions") - 1)
160 || ! strncmp (arg, "-ea", sizeof ("-ea") - 1))
162 // FIXME: hook up assertion support
165 else if (! strncmp (arg, "-disableassertions", sizeof ("-disableassertions") - 1)
166 || ! strncmp (arg, "-da", sizeof ("-da") - 1))
168 // FIXME: hook up assertion support
171 else if (! strcmp (arg, "-enablesystemassertions")
172 || ! strcmp (arg, "-esa"))
174 // FIXME: hook up system assertion support
177 else if (! strcmp (arg, "-disablesystemassertions")
178 || ! strcmp (arg, "-dsa"))
183 else if (! strcmp (arg, "-jar"))
188 // Ignore java.lang.instrument option
189 else if (! strncmp (arg, "-javaagent:", sizeof ("-javaagent:") - 1))
191 else if (! strcmp (arg, "-noclassgc"))
193 char* xarg = strdup ("-Xnoclassgc");
194 add_option (vm_args, xarg, NULL);
197 else if (! strncmp (arg, "-ms=", sizeof ("-ms=") - 1))
202 add_option (vm_args, arg, NULL);
205 else if (! strcmp (arg, "-ms"))
210 char* xarg = (char*) JvMalloc (strlen (argv[++i])
212 sprintf (xarg, "-Xms%s", argv[i]);
213 add_option (vm_args, xarg, NULL);
216 else if (! strncmp (arg, "-ms", sizeof ("-ms") - 1))
218 char* xarg = (char*) JvMalloc (strlen (arg) + sizeof ("X"));
219 sprintf (xarg, "-Xms%s", arg + sizeof ("-Xms") - 1);
220 add_option (vm_args, xarg, NULL);
223 else if (! strncmp (arg, "-mx=", sizeof ("-mx=") - 1))
228 add_option (vm_args, arg, NULL);
231 else if (! strcmp (arg, "-mx"))
236 char* xarg = (char*) JvMalloc (strlen (argv[++i])
238 sprintf (xarg, "-Xmx%s", argv[i]);
239 add_option (vm_args, xarg, NULL);
242 else if (! strncmp (arg, "-mx", sizeof ("-mx") - 1))
244 char* xarg = (char*) JvMalloc (strlen (arg) + sizeof ("X"));
245 sprintf (xarg, "-Xmx%s", arg + sizeof ("-Xmx") - 1);
246 add_option (vm_args, xarg, NULL);
249 else if (! strncmp (arg, "-ss=", sizeof ("-ss=") - 1))
254 add_option (vm_args, arg, NULL);
257 else if (! strcmp (arg, "-ss"))
262 char* xarg = (char*) JvMalloc (strlen (argv[++i])
264 sprintf (xarg, "-Xss%s", argv[i]);
265 add_option (vm_args, xarg, NULL);
268 else if (! strncmp (arg, "-ss", sizeof ("-ss") - 1))
270 char* xarg = (char*) JvMalloc (strlen (arg) + sizeof ("X"));
271 sprintf (xarg, "-Xss%s", arg + sizeof ("-Xss") - 1);
272 add_option (vm_args, xarg, NULL);
274 // This handles all the option variants that begin with
276 else if (! strncmp (arg, "-verbose", 8))
277 add_option (vm_args, arg, NULL);
278 else if (! strcmp (arg, "-version"))
283 else if (! strcmp (arg, "-fullversion"))
285 printf ("java full version \"gcj-" JV_VERSION "\"\n");
288 else if (! strcmp (arg, "-showversion"))
290 else if (! strcmp (arg, "-help") || ! strcmp (arg, "-?"))
292 else if (! strcmp (arg, "-X"))
293 nonstandard_opts_help ();
294 else if (! strncmp (arg, "-X", 2))
295 add_option (vm_args, arg, NULL);
296 // Obsolete options recognized for backwards-compatibility.
297 else if (! strcmp (arg, "-verify")
298 || ! strcmp (arg, "-verifyremote"))
300 else if (! strcmp (arg, "-noverify"))
302 gcj::verifyClasses = false;
306 fprintf (stderr, "gij: unrecognized option -- `%s'\n", argv[i]);
307 fprintf (stderr, "Try `gij --help' for more information.\n");
314 fprintf (stderr, "Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
315 fprintf (stderr, " to invoke CLASS.main, or\n");
316 fprintf (stderr, " gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
317 fprintf (stderr, " to execute a jar file\n");
318 fprintf (stderr, "Try `gij --help' for more information.\n");
322 // -jar mode overrides all other modes of specifying class path:
323 // CLASSPATH, -Djava.class.path, -classpath and -cp.
326 char* darg = (char*) JvMalloc (strlen (argv[i])
327 + sizeof ("-Djava.class.path="));
328 sprintf (darg, "-Djava.class.path=%s", argv[i]);
329 add_option (vm_args, darg, NULL);
332 _Jv_RunMain (&vm_args, NULL, argv[i], argc - i,
333 (char const**) (argv + i), jar_mode);