]>
Commit | Line | Data |
---|---|---|
b6121641 | 1 | /* Copyright (C) 1999-2005 Free Software Foundation |
58eb6e7c AG |
2 | |
3 | This file is part of libgcj. | |
4 | ||
b6121641 TF |
5 | This software is copyrighted work licensed under the terms of the |
6 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for | |
7 | details. */ | |
58eb6e7c | 8 | |
b8c3c4f0 TT |
9 | #include <config.h> |
10 | ||
58eb6e7c | 11 | #include <jvm.h> |
27e934d8 | 12 | #include <gcj/cni.h> |
b8c3c4f0 | 13 | |
58eb6e7c | 14 | #include <stdio.h> |
b8c3c4f0 | 15 | #include <string.h> |
f1aa7a52 | 16 | #include <stdlib.h> |
58eb6e7c | 17 | |
b8c3c4f0 TT |
18 | static void |
19 | help () | |
20 | { | |
1a558147 AG |
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"); | |
2263ca09 TT |
25 | printf (" --cp LIST set class path\n"); |
26 | printf (" --classpath LIST set class path\n"); | |
b8c3c4f0 | 27 | printf (" -DVAR=VAL define property VAR with value VAL\n"); |
bc5ad3e6 TT |
28 | printf (" -?, --help print this help, then exit\n"); |
29 | printf (" -X print help on supported -X options, then exit\n"); | |
b8c3c4f0 TT |
30 | printf (" --ms=NUMBER set initial heap size\n"); |
31 | printf (" --mx=NUMBER set maximum heap size\n"); | |
36739040 | 32 | printf (" --verbose[:class] print information about class loading\n"); |
ca7c2b85 | 33 | printf (" --showversion print version number, then keep going\n"); |
b8c3c4f0 | 34 | printf (" --version print version number, then exit\n"); |
2263ca09 | 35 | printf ("\nOptions can be specified with `-' or `--'.\n"); |
7e5fd99f | 36 | printf ("\nSee http://gcc.gnu.org/java/ for information on reporting bugs\n"); |
b8c3c4f0 TT |
37 | exit (0); |
38 | } | |
39 | ||
40 | static void | |
41 | version () | |
76ed0c0a | 42 | { |
03ae9e88 | 43 | printf ("java version \"" JV_VERSION "\"\n"); |
fc04b455 | 44 | printf ("gij (GNU libgcj) version %s\n\n", __VERSION__); |
0ae65c91 | 45 | printf ("Copyright (C) 2005 Free Software Foundation, Inc.\n"); |
b8c3c4f0 TT |
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"); | |
b8c3c4f0 | 48 | } |
76ed0c0a | 49 | |
b6121641 TF |
50 | static void |
51 | nonstandard_opts_help () | |
52 | { | |
53 | printf (" -Xms<size> set initial heap size\n"); | |
54 | printf (" -Xmx<size> set maximum heap size\n"); | |
55 | exit (0); | |
56 | } | |
57 | ||
58 | static void | |
59 | add_option (JvVMInitArgs& vm_args, char const* option, void const* extra) | |
60 | { | |
61 | vm_args.options = | |
62 | (JvVMOption*) JvRealloc (vm_args.options, | |
63 | (vm_args.nOptions + 1) * sizeof (JvVMOption)); | |
64 | ||
65 | vm_args.options[vm_args.nOptions].optionString = const_cast<char*> (option); | |
66 | vm_args.options[vm_args.nOptions].extraInfo = const_cast<void*> (extra); | |
67 | ++vm_args.nOptions; | |
68 | } | |
69 | ||
76ed0c0a | 70 | int |
b6121641 | 71 | main (int argc, char const** argv) |
58eb6e7c | 72 | { |
b6121641 | 73 | JvVMInitArgs vm_args; |
1a558147 | 74 | bool jar_mode = false; |
b8c3c4f0 | 75 | |
b6121641 TF |
76 | vm_args.options = NULL; |
77 | vm_args.nOptions = 0; | |
78 | vm_args.ignoreUnrecognized = true; | |
79 | ||
80 | // Command-line options always override the CLASSPATH environment | |
81 | // variable. | |
82 | char *classpath = getenv("CLASSPATH"); | |
83 | ||
84 | if (classpath) | |
85 | { | |
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); | |
90 | } | |
91 | ||
92 | // Handle arguments to the java command. Store in vm_args arguments | |
93 | // handled by the invocation API. | |
b8c3c4f0 TT |
94 | int i; |
95 | for (i = 1; i < argc; ++i) | |
96 | { | |
b6121641 | 97 | char* arg = const_cast<char*> (argv[i]); |
b8c3c4f0 | 98 | |
b6121641 | 99 | // A non-option stops processing. |
b8c3c4f0 TT |
100 | if (arg[0] != '-') |
101 | break; | |
b6121641 TF |
102 | |
103 | // A "--" stops processing. | |
b8c3c4f0 TT |
104 | if (! strcmp (arg, "--")) |
105 | { | |
106 | ++i; | |
107 | break; | |
108 | } | |
109 | ||
b6121641 | 110 | // Allow both single or double hyphen for all options. |
b8c3c4f0 TT |
111 | if (arg[1] == '-') |
112 | ++arg; | |
113 | ||
b6121641 TF |
114 | // Ignore JIT options |
115 | if (! strcmp (arg, "-client")) | |
116 | continue; | |
117 | else if (! strcmp (arg, "-server")) | |
118 | continue; | |
119 | else if (! strcmp (arg, "-hotspot")) | |
120 | continue; | |
121 | else if (! strcmp (arg, "-jrockit")) | |
122 | continue; | |
123 | // Ignore JVM Tool Interface options | |
124 | else if (! strncmp (arg, "-agentlib:", sizeof ("-agentlib:") - 1)) | |
125 | continue; | |
126 | else if (! strncmp (arg, "-agentpath:", sizeof ("-agentpath:") - 1)) | |
127 | continue; | |
128 | else if (! strcmp (arg, "-classpath") || ! strcmp (arg, "-cp")) | |
129 | { | |
130 | if (i >= argc - 1) | |
131 | { | |
3cf88fb4 | 132 | no_arg: |
b8c3c4f0 TT |
133 | fprintf (stderr, "gij: option requires an argument -- `%s'\n", |
134 | argv[i]); | |
135 | fprintf (stderr, "Try `gij --help' for more information.\n"); | |
136 | exit (1); | |
b6121641 TF |
137 | } |
138 | ||
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); | |
147 | } | |
148 | else if (! strcmp (arg, "-debug")) | |
149 | { | |
150 | char* xarg = strdup ("-Xdebug"); | |
151 | add_option (vm_args, xarg, NULL); | |
152 | } | |
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")) | |
157 | continue; | |
158 | else if (! strcmp (arg, "-enableassertions") || ! strcmp (arg, "-ea")) | |
159 | { | |
160 | if (i >= argc - 1) | |
161 | goto no_arg; | |
162 | // FIXME: hook up assertion support | |
163 | ++i; | |
164 | continue; | |
165 | } | |
166 | else if (! strcmp (arg, "-disableassertions") || ! strcmp (arg, "-da")) | |
167 | { | |
168 | if (i >= argc - 1) | |
169 | goto no_arg; | |
170 | // FIXME | |
171 | ++i; | |
172 | continue; | |
173 | } | |
174 | else if (! strcmp (arg, "-enablesystemassertions") | |
175 | || ! strcmp (arg, "-esa")) | |
176 | { | |
177 | // FIXME: hook up system assertion support | |
178 | continue; | |
179 | } | |
180 | else if (! strcmp (arg, "-disablesystemassertions") | |
181 | || ! strcmp (arg, "-dsa")) | |
182 | { | |
183 | // FIXME | |
184 | continue; | |
185 | } | |
186 | else if (! strcmp (arg, "-jar")) | |
187 | { | |
188 | jar_mode = true; | |
189 | continue; | |
190 | } | |
191 | // Ignore java.lang.instrument option | |
192 | else if (! strncmp (arg, "-javaagent:", sizeof ("-javaagent:") - 1)) | |
193 | continue; | |
194 | else if (! strcmp (arg, "-noclassgc")) | |
195 | { | |
196 | char* xarg = strdup ("-Xnoclassgc"); | |
197 | add_option (vm_args, xarg, NULL); | |
198 | } | |
199 | // -ms=n | |
200 | else if (! strncmp (arg, "-ms=", sizeof ("-ms=") - 1)) | |
201 | { | |
202 | arg[1] = 'X'; | |
203 | arg[2] = 'm'; | |
204 | arg[3] = 's'; | |
205 | add_option (vm_args, arg, NULL); | |
206 | } | |
207 | // -ms n | |
208 | else if (! strcmp (arg, "-ms")) | |
209 | { | |
210 | if (i >= argc - 1) | |
211 | goto no_arg; | |
212 | ||
213 | char* xarg = (char*) JvMalloc (strlen (argv[++i]) | |
214 | + sizeof ("-Xms")); | |
215 | sprintf (xarg, "-Xms%s", argv[i]); | |
216 | add_option (vm_args, xarg, NULL); | |
217 | } | |
218 | // -msn | |
219 | else if (! strncmp (arg, "-ms", sizeof ("-ms") - 1)) | |
220 | { | |
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); | |
b8c3c4f0 | 224 | } |
b6121641 TF |
225 | // -mx=n |
226 | else if (! strncmp (arg, "-mx=", sizeof ("-mx=") - 1)) | |
227 | { | |
228 | arg[1] = 'X'; | |
229 | arg[2] = 'm'; | |
230 | arg[3] = 'x'; | |
231 | add_option (vm_args, arg, NULL); | |
232 | } | |
233 | // -mx n | |
b8c3c4f0 TT |
234 | else if (! strcmp (arg, "-mx")) |
235 | { | |
236 | if (i >= argc - 1) | |
b6121641 TF |
237 | goto no_arg; |
238 | ||
239 | char* xarg = (char*) JvMalloc (strlen (argv[++i]) | |
240 | + sizeof ("-Xmx")); | |
241 | sprintf (xarg, "-Xmx%s", argv[i]); | |
242 | add_option (vm_args, xarg, NULL); | |
243 | } | |
244 | // -mxn | |
245 | else if (! strncmp (arg, "-mx", sizeof ("-mx") - 1)) | |
246 | { | |
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); | |
b8c3c4f0 | 250 | } |
b6121641 TF |
251 | // -ss=n |
252 | else if (! strncmp (arg, "-ss=", sizeof ("-ss=") - 1)) | |
253 | { | |
254 | arg[1] = 'X'; | |
255 | arg[2] = 's'; | |
256 | arg[3] = 's'; | |
257 | add_option (vm_args, arg, NULL); | |
258 | } | |
259 | // -ss n | |
260 | else if (! strcmp (arg, "-ss")) | |
2263ca09 TT |
261 | { |
262 | if (i >= argc - 1) | |
b6121641 TF |
263 | goto no_arg; |
264 | ||
265 | char* xarg = (char*) JvMalloc (strlen (argv[++i]) | |
266 | + sizeof ("-Xss")); | |
267 | sprintf (xarg, "-Xss%s", argv[i]); | |
268 | add_option (vm_args, xarg, NULL); | |
2263ca09 | 269 | } |
b6121641 TF |
270 | // -ssn |
271 | else if (! strncmp (arg, "-ss", sizeof ("-ss") - 1)) | |
35e6511a | 272 | { |
b6121641 TF |
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); | |
35e6511a | 276 | } |
b6121641 TF |
277 | // This handles all the option variants that begin with |
278 | // -verbose. | |
279 | else if (! strncmp (arg, "-verbose", 8)) | |
280 | add_option (vm_args, arg, NULL); | |
281 | else if (! strcmp (arg, "-version")) | |
282 | { | |
283 | version (); | |
284 | exit (0); | |
285 | } | |
286 | else if (! strcmp (arg, "-fullversion")) | |
287 | { | |
288 | printf ("java full version \"gcj-" JV_VERSION "\"\n"); | |
289 | exit (0); | |
290 | } | |
291 | else if (! strcmp (arg, "-showversion")) | |
292 | version (); | |
293 | else if (! strcmp (arg, "-help") || ! strcmp (arg, "-?")) | |
294 | help (); | |
295 | else if (! strcmp (arg, "-X")) | |
296 | nonstandard_opts_help (); | |
297 | else if (! strncmp (arg, "-X", 2)) | |
298 | add_option (vm_args, arg, NULL); | |
b8c3c4f0 TT |
299 | else |
300 | { | |
301 | fprintf (stderr, "gij: unrecognized option -- `%s'\n", argv[i]); | |
302 | fprintf (stderr, "Try `gij --help' for more information.\n"); | |
303 | exit (1); | |
304 | } | |
305 | } | |
306 | ||
b8c3c4f0 | 307 | if (argc - i < 1) |
58eb6e7c | 308 | { |
b8c3c4f0 | 309 | fprintf (stderr, "Usage: gij [OPTION] ... CLASS [ARGS] ...\n"); |
242f4945 | 310 | fprintf (stderr, " to invoke CLASS.main, or\n"); |
1a558147 AG |
311 | fprintf (stderr, " gij -jar [OPTION] ... JARFILE [ARGS] ...\n"); |
312 | fprintf (stderr, " to execute a jar file\n"); | |
b8c3c4f0 | 313 | fprintf (stderr, "Try `gij --help' for more information.\n"); |
58eb6e7c AG |
314 | exit (1); |
315 | } | |
316 | ||
b6121641 | 317 | // -jar mode overrides all other modes of specifying class path: |
03ae9e88 | 318 | // CLASSPATH, -Djava.class.path, -classpath and -cp. |
b6121641 TF |
319 | if (jar_mode) |
320 | { | |
321 | char* darg = (char*) JvMalloc (strlen (argv[i]) | |
322 | + sizeof ("-Djava.class.path=")); | |
323 | sprintf (darg, "-Djava.class.path=%s", argv[i]); | |
324 | add_option (vm_args, darg, NULL); | |
325 | } | |
326 | ||
327 | _Jv_RunMain (&vm_args, NULL, argv[i], argc - i, | |
328 | (char const**) (argv + i), jar_mode); | |
58eb6e7c | 329 | } |