1 /* Copyright (C) 1999-2006 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
22 printf ("Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
23 printf (" to interpret Java bytecodes, or\n");
24 printf (" gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
25 printf (" to execute a jar file\n\n");
26 printf (" --cp LIST set class path\n");
27 printf (" --classpath LIST set class path\n");
28 printf (" -DVAR=VAL define property VAR with value VAL\n");
29 printf (" -?, --help print this help, then exit\n");
30 printf (" -X print help on supported -X options, then exit\n");
31 printf (" --ms=NUMBER set initial heap size\n");
32 printf (" --mx=NUMBER set maximum heap size\n");
33 printf (" --verbose[:class] print information about class loading\n");
34 printf (" --showversion print version number, then keep going\n");
35 printf (" --version print version number, then exit\n");
36 printf ("\nOptions can be specified with `-' or `--'.\n");
37 printf ("\nSee http://gcc.gnu.org/java/ for information on reporting bugs\n");
44 printf ("java version \"" JV_VERSION
"\"\n");
45 printf ("gij (GNU libgcj) version %s\n\n", __VERSION__
);
46 printf ("Copyright (C) 2006 Free Software Foundation, Inc.\n");
47 printf ("This is free software; see the source for copying conditions. There is NO\n");
48 printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
52 nonstandard_opts_help ()
54 printf (" -Xms<size> set initial heap size\n");
55 printf (" -Xmx<size> set maximum heap size\n");
56 printf (" -Xss<size> set thread stack size\n");
61 add_option (JvVMInitArgs
& vm_args
, char const* option
, void const* extra
)
64 (JvVMOption
*) JvRealloc (vm_args
.options
,
65 (vm_args
.nOptions
+ 1) * sizeof (JvVMOption
));
67 vm_args
.options
[vm_args
.nOptions
].optionString
= const_cast<char*> (option
);
68 vm_args
.options
[vm_args
.nOptions
].extraInfo
= const_cast<void*> (extra
);
73 main (int argc
, char const** argv
)
75 // libjawt.so must be installed in GCJ's versioned directory and not
76 // the main library directory so that it doesn't override other
77 // libjawt.so implementations. Programs that use the AWT Native
78 // Interface contain a JNI library that links to libjawt.so. We do
79 // not want to require that users explicitly add GCJ's versioned
80 // directory to LD_LIBRARY_PATH when running such programs.
82 // Simply adding GCJ's versioned directory to the module load path
83 // does not solve this problem since libltdl searches its module
84 // load path only for object that it will dlopen; dependencies of
85 // these dynamically loaded objects are searched for in
88 // In addition, setting LD_LIBRARY_PATH from within the current
89 // process does not alter the dependency search path, since it is
90 // computed on startup. This behaviour makes sense since
91 // LD_LIBRARY_PATH is designed to allow users to override the path
92 // set by a program. This re-spawning trick makes it impossible to
93 // override, using LD_LIBRARY_PATH, the versioned directories
96 // Check if LD_LIBRARY_PATH is already prefixed with
97 // GCJ_VERSIONED_LIBDIR. If not, export LD_LIBRARY_PATH prefixed
98 // with GCJ_VERSIONED_LIBDIR and re-spawn gij.
99 char *libpath
= getenv (LTDL_SHLIBPATH_VAR
);
100 char *newpath
= _Jv_PrependVersionedLibdir (libpath
);
102 if (! libpath
|| strcmp (libpath
, newpath
))
104 setenv (LTDL_SHLIBPATH_VAR
, newpath
, 1);
107 int error_code
= execvp (argv
[0], (char* const*) argv
);
109 fprintf (stderr
, "error re-spawning gij with new "
110 LTDL_SHLIBPATH_VAR
" value: %s\n", strerror (error_code
));
116 JvVMInitArgs vm_args
;
117 bool jar_mode
= false;
119 vm_args
.options
= NULL
;
120 vm_args
.nOptions
= 0;
121 vm_args
.ignoreUnrecognized
= true;
123 // Command-line options always override the CLASSPATH environment
125 char *classpath
= getenv("CLASSPATH");
129 char* darg
= (char*) JvMalloc (strlen (classpath
)
130 + sizeof ("-Djava.class.path="));
131 sprintf (darg
, "-Djava.class.path=%s", classpath
);
132 add_option (vm_args
, darg
, NULL
);
135 // Handle arguments to the java command. Store in vm_args arguments
136 // handled by the invocation API.
138 for (i
= 1; i
< argc
; ++i
)
140 char* arg
= const_cast<char*> (argv
[i
]);
142 // A non-option stops processing.
146 // A "--" stops processing.
147 if (! strcmp (arg
, "--"))
153 // Allow both single or double hyphen for all options.
157 // Ignore JIT options
158 if (! strcmp (arg
, "-client"))
160 else if (! strcmp (arg
, "-server"))
162 else if (! strcmp (arg
, "-hotspot"))
164 else if (! strcmp (arg
, "-jrockit"))
166 // Ignore JVM Tool Interface options
167 else if (! strncmp (arg
, "-agentlib:", sizeof ("-agentlib:") - 1))
169 else if (! strncmp (arg
, "-agentpath:", sizeof ("-agentpath:") - 1))
171 else if (! strcmp (arg
, "-classpath") || ! strcmp (arg
, "-cp"))
176 fprintf (stderr
, "gij: option requires an argument -- `%s'\n",
178 fprintf (stderr
, "Try `gij --help' for more information.\n");
182 // Sun seems to translate the -classpath option into
183 // -Djava.class.path because if both -classpath and
184 // -Djava.class.path are specified on the java command line,
185 // the last one always wins.
186 char* darg
= (char*) JvMalloc (strlen (argv
[++i
])
187 + sizeof ("-Djava.class.path="));
188 sprintf (darg
, "-Djava.class.path=%s", argv
[i
]);
189 add_option (vm_args
, darg
, NULL
);
191 else if (! strcmp (arg
, "-debug"))
193 char* xarg
= strdup ("-Xdebug");
194 add_option (vm_args
, xarg
, NULL
);
196 else if (! strncmp (arg
, "-D", sizeof ("-D") - 1))
197 add_option (vm_args
, arg
, NULL
);
198 // Ignore 32/64-bit JIT options
199 else if (! strcmp (arg
, "-d32") || ! strcmp (arg
, "-d64"))
201 else if (! strncmp (arg
, "-enableassertions", sizeof ("-enableassertions") - 1)
202 || ! strncmp (arg
, "-ea", sizeof ("-ea") - 1))
204 // FIXME: hook up assertion support
207 else if (! strncmp (arg
, "-disableassertions", sizeof ("-disableassertions") - 1)
208 || ! strncmp (arg
, "-da", sizeof ("-da") - 1))
210 // FIXME: hook up assertion support
213 else if (! strcmp (arg
, "-enablesystemassertions")
214 || ! strcmp (arg
, "-esa"))
216 // FIXME: hook up system assertion support
219 else if (! strcmp (arg
, "-disablesystemassertions")
220 || ! strcmp (arg
, "-dsa"))
225 else if (! strcmp (arg
, "-jar"))
230 // Ignore java.lang.instrument option
231 else if (! strncmp (arg
, "-javaagent:", sizeof ("-javaagent:") - 1))
233 else if (! strcmp (arg
, "-noclassgc"))
235 char* xarg
= strdup ("-Xnoclassgc");
236 add_option (vm_args
, xarg
, NULL
);
239 else if (! strncmp (arg
, "-ms=", sizeof ("-ms=") - 1))
244 add_option (vm_args
, arg
, NULL
);
247 else if (! strcmp (arg
, "-ms"))
252 char* xarg
= (char*) JvMalloc (strlen (argv
[++i
])
254 sprintf (xarg
, "-Xms%s", argv
[i
]);
255 add_option (vm_args
, xarg
, NULL
);
258 else if (! strncmp (arg
, "-ms", sizeof ("-ms") - 1))
260 char* xarg
= (char*) JvMalloc (strlen (arg
) + sizeof ("X"));
261 sprintf (xarg
, "-Xms%s", arg
+ sizeof ("-Xms") - 1);
262 add_option (vm_args
, xarg
, NULL
);
265 else if (! strncmp (arg
, "-mx=", sizeof ("-mx=") - 1))
270 add_option (vm_args
, arg
, NULL
);
273 else if (! strcmp (arg
, "-mx"))
278 char* xarg
= (char*) JvMalloc (strlen (argv
[++i
])
280 sprintf (xarg
, "-Xmx%s", argv
[i
]);
281 add_option (vm_args
, xarg
, NULL
);
284 else if (! strncmp (arg
, "-mx", sizeof ("-mx") - 1))
286 char* xarg
= (char*) JvMalloc (strlen (arg
) + sizeof ("X"));
287 sprintf (xarg
, "-Xmx%s", arg
+ sizeof ("-Xmx") - 1);
288 add_option (vm_args
, xarg
, NULL
);
291 else if (! strncmp (arg
, "-ss=", sizeof ("-ss=") - 1))
296 add_option (vm_args
, arg
, NULL
);
299 else if (! strcmp (arg
, "-ss"))
304 char* xarg
= (char*) JvMalloc (strlen (argv
[++i
])
306 sprintf (xarg
, "-Xss%s", argv
[i
]);
307 add_option (vm_args
, xarg
, NULL
);
310 else if (! strncmp (arg
, "-ss", sizeof ("-ss") - 1))
312 char* xarg
= (char*) JvMalloc (strlen (arg
) + sizeof ("X"));
313 sprintf (xarg
, "-Xss%s", arg
+ sizeof ("-Xss") - 1);
314 add_option (vm_args
, xarg
, NULL
);
316 // This handles all the option variants that begin with
318 else if (! strncmp (arg
, "-verbose", 8))
319 add_option (vm_args
, arg
, NULL
);
320 else if (! strcmp (arg
, "-version"))
325 else if (! strcmp (arg
, "-fullversion"))
327 printf ("java full version \"gcj-" JV_VERSION
"\"\n");
330 else if (! strcmp (arg
, "-showversion"))
332 else if (! strcmp (arg
, "-help") || ! strcmp (arg
, "-?"))
334 else if (! strcmp (arg
, "-X"))
335 nonstandard_opts_help ();
336 else if (! strncmp (arg
, "-X", 2))
337 add_option (vm_args
, arg
, NULL
);
338 // Obsolete options recognized for backwards-compatibility.
339 else if (! strcmp (arg
, "-verify")
340 || ! strcmp (arg
, "-verifyremote"))
342 else if (! strcmp (arg
, "-noverify"))
344 gcj::verifyClasses
= false;
348 fprintf (stderr
, "gij: unrecognized option -- `%s'\n", argv
[i
]);
349 fprintf (stderr
, "Try `gij --help' for more information.\n");
356 fprintf (stderr
, "Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
357 fprintf (stderr
, " to invoke CLASS.main, or\n");
358 fprintf (stderr
, " gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
359 fprintf (stderr
, " to execute a jar file\n");
360 fprintf (stderr
, "Try `gij --help' for more information.\n");
364 // -jar mode overrides all other modes of specifying class path:
365 // CLASSPATH, -Djava.class.path, -classpath and -cp.
368 char* darg
= (char*) JvMalloc (strlen (argv
[i
])
369 + sizeof ("-Djava.class.path="));
370 sprintf (darg
, "-Djava.class.path=%s", argv
[i
]);
371 add_option (vm_args
, darg
, NULL
);
374 _Jv_RunMain (&vm_args
, NULL
, argv
[i
], argc
- i
,
375 (char const**) (argv
+ i
), jar_mode
);