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 char *buffer
= (char *) JvMalloc (strlen (LTDL_SHLIBPATH_VAR
)
105 + strlen (newpath
) + 2);
106 strcpy (buffer
, LTDL_SHLIBPATH_VAR
);
107 strcat (buffer
, "=");
108 strcat (buffer
, newpath
);
112 int error_code
= execvp (argv
[0], (char* const*) argv
);
114 fprintf (stderr
, "error re-spawning gij with new "
115 LTDL_SHLIBPATH_VAR
" value: %s\n", strerror (error_code
));
121 JvVMInitArgs vm_args
;
122 bool jar_mode
= false;
124 vm_args
.options
= NULL
;
125 vm_args
.nOptions
= 0;
126 vm_args
.ignoreUnrecognized
= true;
128 // Command-line options always override the CLASSPATH environment
130 char *classpath
= getenv("CLASSPATH");
134 char* darg
= (char*) JvMalloc (strlen (classpath
)
135 + sizeof ("-Djava.class.path="));
136 sprintf (darg
, "-Djava.class.path=%s", classpath
);
137 add_option (vm_args
, darg
, NULL
);
140 // Handle arguments to the java command. Store in vm_args arguments
141 // handled by the invocation API.
143 for (i
= 1; i
< argc
; ++i
)
145 char* arg
= const_cast<char*> (argv
[i
]);
147 // A non-option stops processing.
151 // A "--" stops processing.
152 if (! strcmp (arg
, "--"))
158 // Allow both single or double hyphen for all options.
162 // Ignore JIT options
163 if (! strcmp (arg
, "-client"))
165 else if (! strcmp (arg
, "-server"))
167 else if (! strcmp (arg
, "-hotspot"))
169 else if (! strcmp (arg
, "-jrockit"))
171 // Ignore JVM Tool Interface options
172 else if (! strncmp (arg
, "-agentlib:", sizeof ("-agentlib:") - 1))
174 else if (! strncmp (arg
, "-agentpath:", sizeof ("-agentpath:") - 1))
176 else if (! strcmp (arg
, "-classpath") || ! strcmp (arg
, "-cp"))
181 fprintf (stderr
, "gij: option requires an argument -- `%s'\n",
183 fprintf (stderr
, "Try `gij --help' for more information.\n");
187 // Sun seems to translate the -classpath option into
188 // -Djava.class.path because if both -classpath and
189 // -Djava.class.path are specified on the java command line,
190 // the last one always wins.
191 char* darg
= (char*) JvMalloc (strlen (argv
[++i
])
192 + sizeof ("-Djava.class.path="));
193 sprintf (darg
, "-Djava.class.path=%s", argv
[i
]);
194 add_option (vm_args
, darg
, NULL
);
196 else if (! strcmp (arg
, "-debug"))
198 char* xarg
= strdup ("-Xdebug");
199 add_option (vm_args
, xarg
, NULL
);
201 else if (! strncmp (arg
, "-D", sizeof ("-D") - 1))
202 add_option (vm_args
, arg
, NULL
);
203 // Ignore 32/64-bit JIT options
204 else if (! strcmp (arg
, "-d32") || ! strcmp (arg
, "-d64"))
206 else if (! strncmp (arg
, "-enableassertions", sizeof ("-enableassertions") - 1)
207 || ! strncmp (arg
, "-ea", sizeof ("-ea") - 1))
209 // FIXME: hook up assertion support
212 else if (! strncmp (arg
, "-disableassertions", sizeof ("-disableassertions") - 1)
213 || ! strncmp (arg
, "-da", sizeof ("-da") - 1))
215 // FIXME: hook up assertion support
218 else if (! strcmp (arg
, "-enablesystemassertions")
219 || ! strcmp (arg
, "-esa"))
221 // FIXME: hook up system assertion support
224 else if (! strcmp (arg
, "-disablesystemassertions")
225 || ! strcmp (arg
, "-dsa"))
230 else if (! strcmp (arg
, "-jar"))
235 // Ignore java.lang.instrument option
236 else if (! strncmp (arg
, "-javaagent:", sizeof ("-javaagent:") - 1))
238 else if (! strcmp (arg
, "-noclassgc"))
240 char* xarg
= strdup ("-Xnoclassgc");
241 add_option (vm_args
, xarg
, NULL
);
244 else if (! strncmp (arg
, "-ms=", sizeof ("-ms=") - 1))
249 add_option (vm_args
, arg
, NULL
);
252 else if (! strcmp (arg
, "-ms"))
257 char* xarg
= (char*) JvMalloc (strlen (argv
[++i
])
259 sprintf (xarg
, "-Xms%s", argv
[i
]);
260 add_option (vm_args
, xarg
, NULL
);
263 else if (! strncmp (arg
, "-ms", sizeof ("-ms") - 1))
265 char* xarg
= (char*) JvMalloc (strlen (arg
) + sizeof ("X"));
266 sprintf (xarg
, "-Xms%s", arg
+ sizeof ("-Xms") - 1);
267 add_option (vm_args
, xarg
, NULL
);
270 else if (! strncmp (arg
, "-mx=", sizeof ("-mx=") - 1))
275 add_option (vm_args
, arg
, NULL
);
278 else if (! strcmp (arg
, "-mx"))
283 char* xarg
= (char*) JvMalloc (strlen (argv
[++i
])
285 sprintf (xarg
, "-Xmx%s", argv
[i
]);
286 add_option (vm_args
, xarg
, NULL
);
289 else if (! strncmp (arg
, "-mx", sizeof ("-mx") - 1))
291 char* xarg
= (char*) JvMalloc (strlen (arg
) + sizeof ("X"));
292 sprintf (xarg
, "-Xmx%s", arg
+ sizeof ("-Xmx") - 1);
293 add_option (vm_args
, xarg
, NULL
);
296 else if (! strncmp (arg
, "-ss=", sizeof ("-ss=") - 1))
301 add_option (vm_args
, arg
, NULL
);
304 else if (! strcmp (arg
, "-ss"))
309 char* xarg
= (char*) JvMalloc (strlen (argv
[++i
])
311 sprintf (xarg
, "-Xss%s", argv
[i
]);
312 add_option (vm_args
, xarg
, NULL
);
315 else if (! strncmp (arg
, "-ss", sizeof ("-ss") - 1))
317 char* xarg
= (char*) JvMalloc (strlen (arg
) + sizeof ("X"));
318 sprintf (xarg
, "-Xss%s", arg
+ sizeof ("-Xss") - 1);
319 add_option (vm_args
, xarg
, NULL
);
321 // This handles all the option variants that begin with
323 else if (! strncmp (arg
, "-verbose", 8))
324 add_option (vm_args
, arg
, NULL
);
325 else if (! strcmp (arg
, "-version"))
330 else if (! strcmp (arg
, "-fullversion"))
332 printf ("java full version \"gcj-" JV_VERSION
"\"\n");
335 else if (! strcmp (arg
, "-showversion"))
337 else if (! strcmp (arg
, "-help") || ! strcmp (arg
, "-?"))
339 else if (! strcmp (arg
, "-X"))
340 nonstandard_opts_help ();
341 else if (! strncmp (arg
, "-X", 2))
342 add_option (vm_args
, arg
, NULL
);
343 // Obsolete options recognized for backwards-compatibility.
344 else if (! strcmp (arg
, "-verify")
345 || ! strcmp (arg
, "-verifyremote"))
347 else if (! strcmp (arg
, "-noverify"))
349 gcj::verifyClasses
= false;
353 fprintf (stderr
, "gij: unrecognized option -- `%s'\n", argv
[i
]);
354 fprintf (stderr
, "Try `gij --help' for more information.\n");
361 fprintf (stderr
, "Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
362 fprintf (stderr
, " to invoke CLASS.main, or\n");
363 fprintf (stderr
, " gij -jar [OPTION] ... JARFILE [ARGS] ...\n");
364 fprintf (stderr
, " to execute a jar file\n");
365 fprintf (stderr
, "Try `gij --help' for more information.\n");
369 // -jar mode overrides all other modes of specifying class path:
370 // CLASSPATH, -Djava.class.path, -classpath and -cp.
373 char* darg
= (char*) JvMalloc (strlen (argv
[i
])
374 + sizeof ("-Djava.class.path="));
375 sprintf (darg
, "-Djava.class.path=%s", argv
[i
]);
376 add_option (vm_args
, darg
, NULL
);
379 _Jv_RunMain (&vm_args
, NULL
, argv
[i
], argc
- i
,
380 (char const**) (argv
+ i
), jar_mode
);