* tree-ssa-loop-ivopts.c (ivopts_data): New field
[official-gcc.git] / libjava / gij.cc
blobc04b1d889a8492c3b9739edb842d382b85c074cb
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
7 details. */
9 #include <config.h>
11 #include <jvm.h>
12 #include <gcj/cni.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
18 static void
19 help ()
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");
37 exit (0);
40 static void
41 version ()
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");
50 static void
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");
56 exit (0);
59 static void
60 add_option (JvVMInitArgs& vm_args, char const* option, void const* extra)
62 vm_args.options =
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);
68 ++vm_args.nOptions;
71 int
72 main (int argc, char const** argv)
74 JvVMInitArgs vm_args;
75 bool jar_mode = false;
77 vm_args.options = NULL;
78 vm_args.nOptions = 0;
79 vm_args.ignoreUnrecognized = true;
81 // Command-line options always override the CLASSPATH environment
82 // variable.
83 char *classpath = getenv("CLASSPATH");
85 if (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.
95 int i;
96 for (i = 1; i < argc; ++i)
98 char* arg = const_cast<char*> (argv[i]);
100 // A non-option stops processing.
101 if (arg[0] != '-')
102 break;
104 // A "--" stops processing.
105 if (! strcmp (arg, "--"))
107 ++i;
108 break;
111 // Allow both single or double hyphen for all options.
112 if (arg[1] == '-')
113 ++arg;
115 // Ignore JIT options
116 if (! strcmp (arg, "-client"))
117 continue;
118 else if (! strcmp (arg, "-server"))
119 continue;
120 else if (! strcmp (arg, "-hotspot"))
121 continue;
122 else if (! strcmp (arg, "-jrockit"))
123 continue;
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"))
131 if (i >= argc - 1)
133 no_arg:
134 fprintf (stderr, "gij: option requires an argument -- `%s'\n",
135 argv[i]);
136 fprintf (stderr, "Try `gij --help' for more information.\n");
137 exit (1);
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"))
158 continue;
159 else if (! strncmp (arg, "-enableassertions", sizeof ("-enableassertions") - 1)
160 || ! strncmp (arg, "-ea", sizeof ("-ea") - 1))
162 // FIXME: hook up assertion support
163 continue;
165 else if (! strncmp (arg, "-disableassertions", sizeof ("-disableassertions") - 1)
166 || ! strncmp (arg, "-da", sizeof ("-da") - 1))
168 // FIXME: hook up assertion support
169 continue;
171 else if (! strcmp (arg, "-enablesystemassertions")
172 || ! strcmp (arg, "-esa"))
174 // FIXME: hook up system assertion support
175 continue;
177 else if (! strcmp (arg, "-disablesystemassertions")
178 || ! strcmp (arg, "-dsa"))
180 // FIXME
181 continue;
183 else if (! strcmp (arg, "-jar"))
185 jar_mode = true;
186 continue;
188 // Ignore java.lang.instrument option
189 else if (! strncmp (arg, "-javaagent:", sizeof ("-javaagent:") - 1))
190 continue;
191 else if (! strcmp (arg, "-noclassgc"))
193 char* xarg = strdup ("-Xnoclassgc");
194 add_option (vm_args, xarg, NULL);
196 // -ms=n
197 else if (! strncmp (arg, "-ms=", sizeof ("-ms=") - 1))
199 arg[1] = 'X';
200 arg[2] = 'm';
201 arg[3] = 's';
202 add_option (vm_args, arg, NULL);
204 // -ms n
205 else if (! strcmp (arg, "-ms"))
207 if (i >= argc - 1)
208 goto no_arg;
210 char* xarg = (char*) JvMalloc (strlen (argv[++i])
211 + sizeof ("-Xms"));
212 sprintf (xarg, "-Xms%s", argv[i]);
213 add_option (vm_args, xarg, NULL);
215 // -msn
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);
222 // -mx=n
223 else if (! strncmp (arg, "-mx=", sizeof ("-mx=") - 1))
225 arg[1] = 'X';
226 arg[2] = 'm';
227 arg[3] = 'x';
228 add_option (vm_args, arg, NULL);
230 // -mx n
231 else if (! strcmp (arg, "-mx"))
233 if (i >= argc - 1)
234 goto no_arg;
236 char* xarg = (char*) JvMalloc (strlen (argv[++i])
237 + sizeof ("-Xmx"));
238 sprintf (xarg, "-Xmx%s", argv[i]);
239 add_option (vm_args, xarg, NULL);
241 // -mxn
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);
248 // -ss=n
249 else if (! strncmp (arg, "-ss=", sizeof ("-ss=") - 1))
251 arg[1] = 'X';
252 arg[2] = 's';
253 arg[3] = 's';
254 add_option (vm_args, arg, NULL);
256 // -ss n
257 else if (! strcmp (arg, "-ss"))
259 if (i >= argc - 1)
260 goto no_arg;
262 char* xarg = (char*) JvMalloc (strlen (argv[++i])
263 + sizeof ("-Xss"));
264 sprintf (xarg, "-Xss%s", argv[i]);
265 add_option (vm_args, xarg, NULL);
267 // -ssn
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
275 // -verbose.
276 else if (! strncmp (arg, "-verbose", 8))
277 add_option (vm_args, arg, NULL);
278 else if (! strcmp (arg, "-version"))
280 version ();
281 exit (0);
283 else if (! strcmp (arg, "-fullversion"))
285 printf ("java full version \"gcj-" JV_VERSION "\"\n");
286 exit (0);
288 else if (! strcmp (arg, "-showversion"))
289 version ();
290 else if (! strcmp (arg, "-help") || ! strcmp (arg, "-?"))
291 help ();
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"))
299 continue;
300 else if (! strcmp (arg, "-noverify"))
302 gcj::verifyClasses = false;
304 else
306 fprintf (stderr, "gij: unrecognized option -- `%s'\n", argv[i]);
307 fprintf (stderr, "Try `gij --help' for more information.\n");
308 exit (1);
312 if (argc - i < 1)
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");
319 exit (1);
322 // -jar mode overrides all other modes of specifying class path:
323 // CLASSPATH, -Djava.class.path, -classpath and -cp.
324 if (jar_mode)
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);