blob: b351fe3aa83ee6a4d83cbd1a1ab8d79acee09bed [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001/*
ksrini16238472008-04-10 09:02:22 -07002 * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved.
duke6e45e102007-12-01 00:00:00 +00003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26/*
27 * Shared source for 'java' command line tool.
28 *
29 * If JAVA_ARGS is defined, then acts as a launcher for applications. For
30 * instance, the JDK command line tools such as javac and javadoc (see
31 * makefiles for more details) are built with this program. Any arguments
32 * prefixed with '-J' will be passed directly to the 'java' command.
33 */
34
35/*
36 * One job of the launcher is to remove command line options which the
37 * vm does not understand and will not process. These options include
38 * options which select which style of vm is run (e.g. -client and
39 * -server) as well as options which select the data model to use.
40 * Additionally, for tools which invoke an underlying vm "-J-foo"
41 * options are turned into "-foo" options to the vm. This option
42 * filtering is handled in a number of places in the launcher, some of
43 * it in machine-dependent code. In this file, the function
44 * CheckJVMType removes vm style options and TranslateApplicationArgs
45 * removes "-J" prefixes. On unix platforms, the
46 * CreateExecutionEnvironment function from the unix java_md.c file
47 * processes and removes -d<n> options. However, in case
48 * CreateExecutionEnvironment does not need to exec because
49 * LD_LIBRARY_PATH is set acceptably and the data model does not need
50 * to be changed, ParseArguments will screen out the redundant -d<n>
51 * options and prevent them from being passed to the vm; this is done
52 * by RemovableOption.
53 */
54
55
56#include "java.h"
57
58/*
59 * A NOTE TO DEVELOPERS: For performance reasons it is important that
60 * the program image remain relatively small until after SelectVersion
61 * CreateExecutionEnvironment have finished their possibly recursive
62 * processing. Watch everything, but resist all temptations to use Java
63 * interfaces.
64 */
65
66static jboolean printVersion = JNI_FALSE; /* print and exit */
67static jboolean showVersion = JNI_FALSE; /* print but continue */
68static jboolean printUsage = JNI_FALSE; /* print and exit*/
69static jboolean printXUsage = JNI_FALSE; /* print and exit*/
70
71static const char *_program_name;
72static const char *_launcher_name;
73static jboolean _is_java_args = JNI_FALSE;
74static const char *_fVersion;
75static const char *_dVersion;
76static jboolean _wc_enabled = JNI_FALSE;
77static jint _ergo_policy = DEFAULT_POLICY;
78
79/*
80 * Entries for splash screen environment variables.
81 * putenv is performed in SelectVersion. We need
82 * them in memory until UnsetEnv, so they are made static
83 * global instead of auto local.
84 */
85static char* splash_file_entry = NULL;
86static char* splash_jar_entry = NULL;
87
88/*
89 * List of VM options to be specified when the VM is created.
90 */
91static JavaVMOption *options;
92static int numOptions, maxOptions;
93
94/*
95 * Prototypes for functions internal to launcher.
96 */
97static void SetClassPath(const char *s);
98static void SelectVersion(int argc, char **argv, char **main_class);
99static jboolean ParseArguments(int *pargc, char ***pargv, char **pjarfile,
100 char **pclassname, int *pret, const char *jvmpath);
101static jboolean InitializeJVM(JavaVM **pvm, JNIEnv **penv,
102 InvocationFunctions *ifn);
103static jstring NewPlatformString(JNIEnv *env, char *s);
104static jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc);
105static jclass LoadClass(JNIEnv *env, char *name);
106static jstring GetMainClassName(JNIEnv *env, char *jarname);
107
108static void TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv);
109static jboolean AddApplicationOptions(int cpathc, const char **cpathv);
110static void SetApplicationClassPath(const char**);
111
112static void PrintJavaVersion(JNIEnv *env, jboolean extraLF);
113static void PrintUsage(JNIEnv* env, jboolean doXUsage);
114
115static void SetPaths(int argc, char **argv);
116
117static void DumpState();
118static jboolean RemovableOption(char *option);
119
120/* Maximum supported entries from jvm.cfg. */
121#define INIT_MAX_KNOWN_VMS 10
122
123/* Values for vmdesc.flag */
124enum vmdesc_flag {
125 VM_UNKNOWN = -1,
126 VM_KNOWN,
127 VM_ALIASED_TO,
128 VM_WARN,
129 VM_ERROR,
130 VM_IF_SERVER_CLASS,
131 VM_IGNORE
132};
133
134struct vmdesc {
135 char *name;
136 int flag;
137 char *alias;
138 char *server_class;
139};
140static struct vmdesc *knownVMs = NULL;
141static int knownVMsCount = 0;
142static int knownVMsLimit = 0;
143
144static void GrowKnownVMs();
145static int KnownVMIndex(const char* name);
146static void FreeKnownVMs();
147static void ShowSplashScreen();
148static jboolean IsWildCardEnabled();
149
150#define ARG_CHECK(n, f, a) if (n < 1) { \
151 ReportErrorMessage(f, a); \
152 printUsage = JNI_TRUE; \
153 *pret = 1; \
154 return JNI_TRUE; \
155}
156
157/*
158 * Running Java code in primordial thread caused many problems. We will
159 * create a new thread to invoke JVM. See 6316197 for more information.
160 */
161static jlong threadStackSize = 0; /* stack size of the new thread */
162
163int JNICALL JavaMain(void * args); /* entry point */
164
165typedef struct {
166 int argc;
167 char ** argv;
168 char * jarfile;
169 char * classname;
170 InvocationFunctions ifn;
171} JavaMainArgs;
172
173/*
174 * Entry point.
175 */
176int
177JLI_Launch(int argc, char ** argv, /* main argc, argc */
178 int jargc, const char** jargv, /* java args */
179 int appclassc, const char** appclassv, /* app classpath */
180 const char* fullversion, /* full version defined */
181 const char* dotversion, /* dot version defined */
182 const char* pname, /* program name */
183 const char* lname, /* launcher name */
184 jboolean javaargs, /* JAVA_ARGS */
185 jboolean cpwildcard, /* classpath wildcard*/
186 jboolean javaw, /* windows-only javaw */
187 jint ergo /* ergonomics class policy */
188)
189{
190 char *jarfile = 0;
191 char *classname = 0;
192 char *cpath = 0;
193 char *main_class = NULL;
194 int ret;
195 InvocationFunctions ifn;
196 jlong start, end;
197 char jrepath[MAXPATHLEN], jvmpath[MAXPATHLEN];
198 char ** original_argv = argv;
199
200 _fVersion = fullversion;
201 _dVersion = dotversion;
202 _launcher_name = lname;
203 _program_name = pname;
204 _is_java_args = javaargs;
205 _wc_enabled = cpwildcard;
206 _ergo_policy = ergo;
207
ksrini52cded22008-03-06 07:51:28 -0800208 InitLauncher(javaw);
duke6e45e102007-12-01 00:00:00 +0000209 DumpState();
210
211 /*
212 * Make sure the specified version of the JRE is running.
213 *
214 * There are three things to note about the SelectVersion() routine:
215 * 1) If the version running isn't correct, this routine doesn't
216 * return (either the correct version has been exec'd or an error
217 * was issued).
218 * 2) Argc and Argv in this scope are *not* altered by this routine.
219 * It is the responsibility of subsequent code to ignore the
220 * arguments handled by this routine.
221 * 3) As a side-effect, the variable "main_class" is guaranteed to
222 * be set (if it should ever be set). This isn't exactly the
223 * poster child for structured programming, but it is a small
224 * price to pay for not processing a jar file operand twice.
225 * (Note: This side effect has been disabled. See comment on
226 * bugid 5030265 below.)
227 */
228 SelectVersion(argc, argv, &main_class);
229
230 /* copy original argv */
231 JLI_TraceLauncher("Command line Args:\n");
232 original_argv = (JLI_CopyArgs(argc, (const char**)argv));
233
234 CreateExecutionEnvironment(&argc, &argv,
235 jrepath, sizeof(jrepath),
236 jvmpath, sizeof(jvmpath),
237 original_argv);
238
239 ifn.CreateJavaVM = 0;
240 ifn.GetDefaultJavaVMInitArgs = 0;
241
242 if (JLI_IsTraceLauncher()) {
243 start = CounterGet();
244 }
245
246 if (!LoadJavaVM(jvmpath, &ifn)) {
247 return(6);
248 }
249
250 if (JLI_IsTraceLauncher()) {
251 end = CounterGet();
252 }
253
254 JLI_TraceLauncher("%ld micro seconds to LoadJavaVM\n",
255 (long)(jint)Counter2Micros(end-start));
256
257 ++argv;
258 --argc;
259
260 if (IsJavaArgs()) {
261 /* Preprocess wrapper arguments */
262 TranslateApplicationArgs(jargc, jargv, &argc, &argv);
263 if (!AddApplicationOptions(appclassc, appclassv)) {
264 return(1);
265 }
266 } else {
267 /* Set default CLASSPATH */
268 cpath = getenv("CLASSPATH");
269 if (cpath == NULL) {
270 cpath = ".";
271 }
272 SetClassPath(cpath);
273 }
274
275 /*
276 * Parse command line options; if the return value of
277 * ParseArguments is false, the program should exit.
278 */
279 if (!ParseArguments(&argc, &argv, &jarfile, &classname, &ret, jvmpath)) {
280 return(ret);
281 }
282
283 /* Override class path if -jar flag was specified */
284 if (jarfile != 0) {
285 SetClassPath(jarfile);
286 }
287
288 /* set the -Dsun.java.command pseudo property */
289 SetJavaCommandLineProp(classname, jarfile, argc, argv);
290
291 /* Set the -Dsun.java.launcher pseudo property */
292 SetJavaLauncherProp();
293
294 /* set the -Dsun.java.launcher.* platform properties */
295 SetJavaLauncherPlatformProps();
296
297 /* Show the splash screen if needed */
298 ShowSplashScreen();
299
300 return ContinueInNewThread(&ifn, argc, argv, jarfile, classname, ret);
301
302}
303
304
305int JNICALL
306JavaMain(void * _args)
307{
308 JavaMainArgs *args = (JavaMainArgs *)_args;
309 int argc = args->argc;
310 char **argv = args->argv;
311 char *jarfile = args->jarfile;
312 char *classname = args->classname;
313 InvocationFunctions ifn = args->ifn;
314
315 JavaVM *vm = 0;
316 JNIEnv *env = 0;
317 jstring mainClassName;
318 jclass mainClass;
319 jmethodID mainID;
320 jobjectArray mainArgs;
321 int ret = 0;
322 jlong start, end;
323
324
325 /* Initialize the virtual machine */
326
327 start = CounterGet();
328 if (!InitializeJVM(&vm, &env, &ifn)) {
329 ReportErrorMessage(JVM_ERROR1);
330 exit(1);
331 }
332
333 if (printVersion || showVersion) {
334 PrintJavaVersion(env, showVersion);
335 if ((*env)->ExceptionOccurred(env)) {
336 ReportExceptionDescription(env);
337 ReportErrorMessage(JNI_ERROR);
338 goto leave;
339 }
340 if (printVersion) {
341 ret = 0;
342 goto leave;
343 }
344 }
345
346 /* If the user specified neither a class name nor a JAR file */
347 if (printXUsage || printUsage || (jarfile == 0 && classname == 0)) {
348 PrintUsage(env, printXUsage);
349 if ((*env)->ExceptionOccurred(env)) {
350 ReportExceptionDescription(env);
351 ReportErrorMessage(JNI_ERROR);
352 ret=1;
353 }
354 goto leave;
355 }
356
357 FreeKnownVMs(); /* after last possible PrintUsage() */
358
359 if (JLI_IsTraceLauncher()) {
360 end = CounterGet();
361 JLI_TraceLauncher("%ld micro seconds to InitializeJVM\n",
362 (long)(jint)Counter2Micros(end-start));
363 }
364
365 /* At this stage, argc/argv have the applications' arguments */
366 if (JLI_IsTraceLauncher()){
367 int i;
368 printf("Main-Class is '%s'\n", classname ? classname : "");
369 printf("Apps' argc is %d\n", argc);
370 for (i=0; i < argc; i++) {
371 printf(" argv[%2d] = '%s'\n", i, argv[i]);
372 }
373 }
374
375 ret = 1;
376
377 /*
378 * Get the application's main class.
379 *
380 * See bugid 5030265. The Main-Class name has already been parsed
381 * from the manifest, but not parsed properly for UTF-8 support.
382 * Hence the code here ignores the value previously extracted and
383 * uses the pre-existing code to reextract the value. This is
384 * possibly an end of release cycle expedient. However, it has
385 * also been discovered that passing some character sets through
386 * the environment has "strange" behavior on some variants of
387 * Windows. Hence, maybe the manifest parsing code local to the
388 * launcher should never be enhanced.
389 *
390 * Hence, future work should either:
391 * 1) Correct the local parsing code and verify that the
392 * Main-Class attribute gets properly passed through
393 * all environments,
394 * 2) Remove the vestages of maintaining main_class through
395 * the environment (and remove these comments).
396 */
397 if (jarfile != 0) {
398 mainClassName = GetMainClassName(env, jarfile);
399 if ((*env)->ExceptionOccurred(env)) {
400 ReportExceptionDescription(env);
401 ReportErrorMessage(JNI_ERROR);
402 goto leave;
403 }
404 if (mainClassName == NULL) {
405 ReportErrorMessage(JAR_ERROR1,jarfile, GEN_ERROR);
406 goto leave;
407 }
408 classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0);
409 if (classname == NULL) {
410 ReportExceptionDescription(env);
411 ReportErrorMessage(JNI_ERROR);
412 goto leave;
413 }
414 mainClass = LoadClass(env, classname);
415 if(mainClass == NULL) { /* exception occured */
416 ReportExceptionDescription(env);
ksrini16238472008-04-10 09:02:22 -0700417 ReportErrorMessage(CLS_ERROR1, classname);
duke6e45e102007-12-01 00:00:00 +0000418 goto leave;
419 }
420 (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
421 } else {
422 mainClassName = NewPlatformString(env, classname);
423 if (mainClassName == NULL) {
424 ReportErrorMessage(CLS_ERROR2, classname, GEN_ERROR);
425 goto leave;
426 }
427 classname = (char *)(*env)->GetStringUTFChars(env, mainClassName, 0);
428 if (classname == NULL) {
429 ReportExceptionDescription(env);
430 ReportErrorMessage(JNI_ERROR);
431 goto leave;
432 }
433 mainClass = LoadClass(env, classname);
434 if(mainClass == NULL) { /* exception occured */
435 ReportExceptionDescription(env);
ksrini16238472008-04-10 09:02:22 -0700436 ReportErrorMessage(CLS_ERROR1, classname);
duke6e45e102007-12-01 00:00:00 +0000437 goto leave;
438 }
439 (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
440 }
441
442 /* Get the application's main method */
443 mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
444 "([Ljava/lang/String;)V");
445 if (mainID == NULL) {
446 if ((*env)->ExceptionOccurred(env)) {
447 ReportExceptionDescription(env);
448 ReportErrorMessage(JNI_ERROR);
449 } else {
450 ReportErrorMessage(CLS_ERROR3);
451 }
452 goto leave;
453 }
454
455 { /* Make sure the main method is public */
456 jint mods;
457 jmethodID mid;
458 jobject obj = (*env)->ToReflectedMethod(env, mainClass,
459 mainID, JNI_TRUE);
460
461 if( obj == NULL) { /* exception occurred */
462 ReportExceptionDescription(env);
463 ReportErrorMessage(JNI_ERROR);
464 goto leave;
465 }
466
467 mid =
468 (*env)->GetMethodID(env,
469 (*env)->GetObjectClass(env, obj),
470 "getModifiers", "()I");
471 if ((*env)->ExceptionOccurred(env)) {
472 ReportExceptionDescription(env);
473 ReportErrorMessage(JNI_ERROR);
474 goto leave;
475 }
476
477 mods = (*env)->CallIntMethod(env, obj, mid);
478 if ((mods & 1) == 0) { /* if (!Modifier.isPublic(mods)) ... */
479 ReportErrorMessage(CLS_ERROR4);
480 goto leave;
481 }
482 }
483
484 /* Build argument array */
485 mainArgs = NewPlatformStringArray(env, argv, argc);
486 if (mainArgs == NULL) {
487 ReportExceptionDescription(env);
488 ReportErrorMessage(JNI_ERROR);
489 goto leave;
490 }
491
492 /* Invoke main method. */
493 (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs);
494
495 /*
496 * The launcher's exit code (in the absence of calls to
497 * System.exit) will be non-zero if main threw an exception.
498 */
499 ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1;
500
501 /*
502 * Detach the main thread so that it appears to have ended when
503 * the application's main method exits. This will invoke the
504 * uncaught exception handler machinery if main threw an
505 * exception. An uncaught exception handler cannot change the
506 * launcher's return code except by calling System.exit.
507 */
508 if ((*vm)->DetachCurrentThread(vm) != 0) {
509 ReportErrorMessage(JVM_ERROR2);
510 ret = 1;
511 goto leave;
512 }
513
514 leave:
515 /*
516 * Wait for all non-daemon threads to end, then destroy the VM.
517 * This will actually create a trivial new Java waiter thread
518 * named "DestroyJavaVM", but this will be seen as a different
519 * thread from the one that executed main, even though they are
520 * the same C thread. This allows mainThread.join() and
521 * mainThread.isAlive() to work as expected.
522 */
523 (*vm)->DestroyJavaVM(vm);
524
525 return ret;
526}
527
528
529/*
530 * Checks the command line options to find which JVM type was
531 * specified. If no command line option was given for the JVM type,
532 * the default type is used. The environment variable
533 * JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also
534 * checked as ways of specifying which JVM type to invoke.
535 */
536char *
537CheckJvmType(int *pargc, char ***argv, jboolean speculative) {
538 int i, argi;
539 int argc;
540 char **newArgv;
541 int newArgvIdx = 0;
542 int isVMType;
543 int jvmidx = -1;
544 char *jvmtype = getenv("JDK_ALTERNATE_VM");
545
546 argc = *pargc;
547
548 /* To make things simpler we always copy the argv array */
549 newArgv = JLI_MemAlloc((argc + 1) * sizeof(char *));
550
551 /* The program name is always present */
552 newArgv[newArgvIdx++] = (*argv)[0];
553
554 for (argi = 1; argi < argc; argi++) {
555 char *arg = (*argv)[argi];
556 isVMType = 0;
557
558 if (IsJavaArgs()) {
559 if (arg[0] != '-') {
560 newArgv[newArgvIdx++] = arg;
561 continue;
562 }
563 } else {
564 if (JLI_StrCmp(arg, "-classpath") == 0 ||
565 JLI_StrCmp(arg, "-cp") == 0) {
566 newArgv[newArgvIdx++] = arg;
567 argi++;
568 if (argi < argc) {
569 newArgv[newArgvIdx++] = (*argv)[argi];
570 }
571 continue;
572 }
573 if (arg[0] != '-') break;
574 }
575
576 /* Did the user pass an explicit VM type? */
577 i = KnownVMIndex(arg);
578 if (i >= 0) {
579 jvmtype = knownVMs[jvmidx = i].name + 1; /* skip the - */
580 isVMType = 1;
581 *pargc = *pargc - 1;
582 }
583
584 /* Did the user specify an "alternate" VM? */
585 else if (JLI_StrCCmp(arg, "-XXaltjvm=") == 0 || JLI_StrCCmp(arg, "-J-XXaltjvm=") == 0) {
586 isVMType = 1;
587 jvmtype = arg+((arg[1]=='X')? 10 : 12);
588 jvmidx = -1;
589 }
590
591 if (!isVMType) {
592 newArgv[newArgvIdx++] = arg;
593 }
594 }
595
596 /*
597 * Finish copying the arguments if we aborted the above loop.
598 * NOTE that if we aborted via "break" then we did NOT copy the
599 * last argument above, and in addition argi will be less than
600 * argc.
601 */
602 while (argi < argc) {
603 newArgv[newArgvIdx++] = (*argv)[argi];
604 argi++;
605 }
606
607 /* argv is null-terminated */
608 newArgv[newArgvIdx] = 0;
609
610 /* Copy back argv */
611 *argv = newArgv;
612 *pargc = newArgvIdx;
613
614 /* use the default VM type if not specified (no alias processing) */
615 if (jvmtype == NULL) {
616 char* result = knownVMs[0].name+1;
617 /* Use a different VM type if we are on a server class machine? */
618 if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) &&
619 (ServerClassMachine() == JNI_TRUE)) {
620 result = knownVMs[0].server_class+1;
621 }
622 JLI_TraceLauncher("Default VM: %s\n", result);
623 return result;
624 }
625
626 /* if using an alternate VM, no alias processing */
627 if (jvmidx < 0)
628 return jvmtype;
629
630 /* Resolve aliases first */
631 {
632 int loopCount = 0;
633 while (knownVMs[jvmidx].flag == VM_ALIASED_TO) {
634 int nextIdx = KnownVMIndex(knownVMs[jvmidx].alias);
635
636 if (loopCount > knownVMsCount) {
637 if (!speculative) {
638 ReportErrorMessage(CFG_ERROR1);
639 exit(1);
640 } else {
641 return "ERROR";
642 /* break; */
643 }
644 }
645
646 if (nextIdx < 0) {
647 if (!speculative) {
648 ReportErrorMessage(CFG_ERROR2, knownVMs[jvmidx].alias);
649 exit(1);
650 } else {
651 return "ERROR";
652 }
653 }
654 jvmidx = nextIdx;
655 jvmtype = knownVMs[jvmidx].name+1;
656 loopCount++;
657 }
658 }
659
660 switch (knownVMs[jvmidx].flag) {
661 case VM_WARN:
662 if (!speculative) {
663 ReportErrorMessage(CFG_WARN1, jvmtype, knownVMs[0].name + 1);
664 }
665 /* fall through */
666 case VM_IGNORE:
667 jvmtype = knownVMs[jvmidx=0].name + 1;
668 /* fall through */
669 case VM_KNOWN:
670 break;
671 case VM_ERROR:
672 if (!speculative) {
673 ReportErrorMessage(CFG_ERROR3, jvmtype);
674 exit(1);
675 } else {
676 return "ERROR";
677 }
678 }
679
680 return jvmtype;
681}
682
683/* copied from HotSpot function "atomll()" */
684static int
685parse_stack_size(const char *s, jlong *result) {
686 jlong n = 0;
687 int args_read = sscanf(s, jlong_format_specifier(), &n);
688 if (args_read != 1) {
689 return 0;
690 }
691 while (*s != '\0' && *s >= '0' && *s <= '9') {
692 s++;
693 }
694 // 4705540: illegal if more characters are found after the first non-digit
695 if (JLI_StrLen(s) > 1) {
696 return 0;
697 }
698 switch (*s) {
699 case 'T': case 't':
700 *result = n * GB * KB;
701 return 1;
702 case 'G': case 'g':
703 *result = n * GB;
704 return 1;
705 case 'M': case 'm':
706 *result = n * MB;
707 return 1;
708 case 'K': case 'k':
709 *result = n * KB;
710 return 1;
711 case '\0':
712 *result = n;
713 return 1;
714 default:
715 /* Create JVM with default stack and let VM handle malformed -Xss string*/
716 return 0;
717 }
718}
719
720/*
721 * Adds a new VM option with the given given name and value.
722 */
723void
724AddOption(char *str, void *info)
725{
726 /*
727 * Expand options array if needed to accommodate at least one more
728 * VM option.
729 */
730 if (numOptions >= maxOptions) {
731 if (options == 0) {
732 maxOptions = 4;
733 options = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
734 } else {
735 JavaVMOption *tmp;
736 maxOptions *= 2;
737 tmp = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
738 memcpy(tmp, options, numOptions * sizeof(JavaVMOption));
739 JLI_MemFree(options);
740 options = tmp;
741 }
742 }
743 options[numOptions].optionString = str;
744 options[numOptions++].extraInfo = info;
745
746 if (JLI_StrCCmp(str, "-Xss") == 0) {
747 jlong tmp;
748 if (parse_stack_size(str + 4, &tmp)) {
749 threadStackSize = tmp;
750 }
751 }
752}
753
754static void
755SetClassPath(const char *s)
756{
757 char *def;
758 s = JLI_WildcardExpandClasspath(s);
759 def = JLI_MemAlloc(JLI_StrLen(s) + 40);
760 sprintf(def, "-Djava.class.path=%s", s);
761 AddOption(def, NULL);
762}
763
764/*
765 * The SelectVersion() routine ensures that an appropriate version of
766 * the JRE is running. The specification for the appropriate version
767 * is obtained from either the manifest of a jar file (preferred) or
768 * from command line options.
769 * The routine also parses splash screen command line options and
770 * passes on their values in private environment variables.
771 */
772static void
773SelectVersion(int argc, char **argv, char **main_class)
774{
775 char *arg;
776 char **new_argv;
777 char **new_argp;
778 char *operand;
779 char *version = NULL;
780 char *jre = NULL;
781 int jarflag = 0;
782 int headlessflag = 0;
783 int restrict_search = -1; /* -1 implies not known */
784 manifest_info info;
785 char env_entry[MAXNAMELEN + 24] = ENV_ENTRY "=";
786 char *splash_file_name = NULL;
787 char *splash_jar_name = NULL;
788 char *env_in;
789 int res;
790
791 /*
792 * If the version has already been selected, set *main_class
793 * with the value passed through the environment (if any) and
794 * simply return.
795 */
796 if ((env_in = getenv(ENV_ENTRY)) != NULL) {
797 if (*env_in != '\0')
798 *main_class = JLI_StringDup(env_in);
799 return;
800 }
801
802 /*
803 * Scan through the arguments for options relevant to multiple JRE
804 * support. For reference, the command line syntax is defined as:
805 *
806 * SYNOPSIS
807 * java [options] class [argument...]
808 *
809 * java [options] -jar file.jar [argument...]
810 *
811 * As the scan is performed, make a copy of the argument list with
812 * the version specification options (new to 1.5) removed, so that
813 * a version less than 1.5 can be exec'd.
814 *
815 * Note that due to the syntax of the native Windows interface
816 * CreateProcess(), processing similar to the following exists in
817 * the Windows platform specific routine ExecJRE (in java_md.c).
818 * Changes here should be reproduced there.
819 */
820 new_argv = JLI_MemAlloc((argc + 1) * sizeof(char*));
821 new_argv[0] = argv[0];
822 new_argp = &new_argv[1];
823 argc--;
824 argv++;
825 while ((arg = *argv) != 0 && *arg == '-') {
826 if (JLI_StrCCmp(arg, "-version:") == 0) {
827 version = arg + 9;
828 } else if (JLI_StrCmp(arg, "-jre-restrict-search") == 0) {
829 restrict_search = 1;
830 } else if (JLI_StrCmp(arg, "-no-jre-restrict-search") == 0) {
831 restrict_search = 0;
832 } else {
833 if (JLI_StrCmp(arg, "-jar") == 0)
834 jarflag = 1;
835 /* deal with "unfortunate" classpath syntax */
836 if ((JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) &&
837 (argc >= 2)) {
838 *new_argp++ = arg;
839 argc--;
840 argv++;
841 arg = *argv;
842 }
843
844 /*
845 * Checking for headless toolkit option in the some way as AWT does:
846 * "true" means true and any other value means false
847 */
848 if (JLI_StrCmp(arg, "-Djava.awt.headless=true") == 0) {
849 headlessflag = 1;
850 } else if (JLI_StrCCmp(arg, "-Djava.awt.headless=") == 0) {
851 headlessflag = 0;
852 } else if (JLI_StrCCmp(arg, "-splash:") == 0) {
853 splash_file_name = arg+8;
854 }
855 *new_argp++ = arg;
856 }
857 argc--;
858 argv++;
859 }
860 if (argc <= 0) { /* No operand? Possibly legit with -[full]version */
861 operand = NULL;
862 } else {
863 argc--;
864 *new_argp++ = operand = *argv++;
865 }
866 while (argc-- > 0) /* Copy over [argument...] */
867 *new_argp++ = *argv++;
868 *new_argp = NULL;
869
870 /*
871 * If there is a jar file, read the manifest. If the jarfile can't be
872 * read, the manifest can't be read from the jar file, or the manifest
873 * is corrupt, issue the appropriate error messages and exit.
874 *
875 * Even if there isn't a jar file, construct a manifest_info structure
876 * containing the command line information. It's a convenient way to carry
877 * this data around.
878 */
879 if (jarflag && operand) {
880 if ((res = JLI_ParseManifest(operand, &info)) != 0) {
881 if (res == -1)
882 ReportErrorMessage(JAR_ERROR2, operand);
883 else
884 ReportErrorMessage(JAR_ERROR3, operand);
885 exit(1);
886 }
887
888 /*
889 * Command line splash screen option should have precedence
890 * over the manifest, so the manifest data is used only if
891 * splash_file_name has not been initialized above during command
892 * line parsing
893 */
894 if (!headlessflag && !splash_file_name && info.splashscreen_image_file_name) {
895 splash_file_name = info.splashscreen_image_file_name;
896 splash_jar_name = operand;
897 }
898 } else {
899 info.manifest_version = NULL;
900 info.main_class = NULL;
901 info.jre_version = NULL;
902 info.jre_restrict_search = 0;
903 }
904
905 /*
906 * Passing on splash screen info in environment variables
907 */
908 if (splash_file_name && !headlessflag) {
909 char* splash_file_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_FILE_ENV_ENTRY "=")+JLI_StrLen(splash_file_name)+1);
910 JLI_StrCpy(splash_file_entry, SPLASH_FILE_ENV_ENTRY "=");
911 JLI_StrCat(splash_file_entry, splash_file_name);
912 putenv(splash_file_entry);
913 }
914 if (splash_jar_name && !headlessflag) {
915 char* splash_jar_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_JAR_ENV_ENTRY "=")+JLI_StrLen(splash_jar_name)+1);
916 JLI_StrCpy(splash_jar_entry, SPLASH_JAR_ENV_ENTRY "=");
917 JLI_StrCat(splash_jar_entry, splash_jar_name);
918 putenv(splash_jar_entry);
919 }
920
921 /*
922 * The JRE-Version and JRE-Restrict-Search values (if any) from the
923 * manifest are overwritten by any specified on the command line.
924 */
925 if (version != NULL)
926 info.jre_version = version;
927 if (restrict_search != -1)
928 info.jre_restrict_search = restrict_search;
929
930 /*
931 * "Valid" returns (other than unrecoverable errors) follow. Set
932 * main_class as a side-effect of this routine.
933 */
934 if (info.main_class != NULL)
935 *main_class = JLI_StringDup(info.main_class);
936
937 /*
938 * If no version selection information is found either on the command
939 * line or in the manifest, simply return.
940 */
941 if (info.jre_version == NULL) {
942 JLI_FreeManifest();
943 JLI_MemFree(new_argv);
944 return;
945 }
946
947 /*
948 * Check for correct syntax of the version specification (JSR 56).
949 */
950 if (!JLI_ValidVersionString(info.jre_version)) {
951 ReportErrorMessage(SPC_ERROR1, info.jre_version);
952 exit(1);
953 }
954
955 /*
956 * Find the appropriate JVM on the system. Just to be as forgiving as
957 * possible, if the standard algorithms don't locate an appropriate
958 * jre, check to see if the one running will satisfy the requirements.
959 * This can happen on systems which haven't been set-up for multiple
960 * JRE support.
961 */
962 jre = LocateJRE(&info);
963 JLI_TraceLauncher("JRE-Version = %s, JRE-Restrict-Search = %s Selected = %s\n",
964 (info.jre_version?info.jre_version:"null"),
965 (info.jre_restrict_search?"true":"false"), (jre?jre:"null"));
966
967 if (jre == NULL) {
968 if (JLI_AcceptableRelease(GetFullVersion(), info.jre_version)) {
969 JLI_FreeManifest();
970 JLI_MemFree(new_argv);
971 return;
972 } else {
973 ReportErrorMessage(CFG_ERROR4, info.jre_version);
974 exit(1);
975 }
976 }
977
978 /*
979 * If I'm not the chosen one, exec the chosen one. Returning from
980 * ExecJRE indicates that I am indeed the chosen one.
981 *
982 * The private environment variable _JAVA_VERSION_SET is used to
983 * prevent the chosen one from re-reading the manifest file and
984 * using the values found within to override the (potential) command
985 * line flags stripped from argv (because the target may not
986 * understand them). Passing the MainClass value is an optimization
987 * to avoid locating, expanding and parsing the manifest extra
988 * times.
989 */
ksrini8760ca92008-09-04 09:43:32 -0700990 if (info.main_class != NULL) {
991 if (JLI_StrLen(info.main_class) <= MAXNAMELEN) {
992 (void)JLI_StrCat(env_entry, info.main_class);
993 } else {
994 ReportErrorMessage(CLS_ERROR5, MAXNAMELEN);
995 exit(1);
996 }
997 }
duke6e45e102007-12-01 00:00:00 +0000998 (void)putenv(env_entry);
999 ExecJRE(jre, new_argv);
1000 JLI_FreeManifest();
1001 JLI_MemFree(new_argv);
1002 return;
1003}
1004
1005/*
1006 * Parses command line arguments. Returns JNI_FALSE if launcher
1007 * should exit without starting vm, returns JNI_TRUE if vm needs
1008 * to be started to process given options. *pret (the launcher
1009 * process return value) is set to 0 for a normal exit.
1010 */
1011static jboolean
1012ParseArguments(int *pargc, char ***pargv, char **pjarfile,
1013 char **pclassname, int *pret, const char *jvmpath)
1014{
1015 int argc = *pargc;
1016 char **argv = *pargv;
1017 jboolean jarflag = JNI_FALSE;
1018 char *arg;
1019
1020 *pret = 0;
1021
1022 while ((arg = *argv) != 0 && *arg == '-') {
1023 argv++; --argc;
1024 if (JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) {
1025 ARG_CHECK (argc, ARG_ERROR1, arg);
1026 SetClassPath(*argv);
1027 argv++; --argc;
1028 } else if (JLI_StrCmp(arg, "-jar") == 0) {
1029 ARG_CHECK (argc, ARG_ERROR2, arg);
1030 jarflag = JNI_TRUE;
1031 } else if (JLI_StrCmp(arg, "-help") == 0 ||
1032 JLI_StrCmp(arg, "-h") == 0 ||
1033 JLI_StrCmp(arg, "-?") == 0) {
1034 printUsage = JNI_TRUE;
1035 return JNI_TRUE;
1036 } else if (JLI_StrCmp(arg, "-version") == 0) {
1037 printVersion = JNI_TRUE;
1038 return JNI_TRUE;
1039 } else if (JLI_StrCmp(arg, "-showversion") == 0) {
1040 showVersion = JNI_TRUE;
1041 } else if (JLI_StrCmp(arg, "-X") == 0) {
1042 printXUsage = JNI_TRUE;
1043 return JNI_TRUE;
1044/*
1045 * The following case provide backward compatibility with old-style
1046 * command line options.
1047 */
1048 } else if (JLI_StrCmp(arg, "-fullversion") == 0) {
1049 ReportMessage("%s full version \"%s\"", _launcher_name, GetFullVersion());
1050 return JNI_FALSE;
1051 } else if (JLI_StrCmp(arg, "-verbosegc") == 0) {
1052 AddOption("-verbose:gc", NULL);
1053 } else if (JLI_StrCmp(arg, "-t") == 0) {
1054 AddOption("-Xt", NULL);
1055 } else if (JLI_StrCmp(arg, "-tm") == 0) {
1056 AddOption("-Xtm", NULL);
1057 } else if (JLI_StrCmp(arg, "-debug") == 0) {
1058 AddOption("-Xdebug", NULL);
1059 } else if (JLI_StrCmp(arg, "-noclassgc") == 0) {
1060 AddOption("-Xnoclassgc", NULL);
1061 } else if (JLI_StrCmp(arg, "-Xfuture") == 0) {
1062 AddOption("-Xverify:all", NULL);
1063 } else if (JLI_StrCmp(arg, "-verify") == 0) {
1064 AddOption("-Xverify:all", NULL);
1065 } else if (JLI_StrCmp(arg, "-verifyremote") == 0) {
1066 AddOption("-Xverify:remote", NULL);
1067 } else if (JLI_StrCmp(arg, "-noverify") == 0) {
1068 AddOption("-Xverify:none", NULL);
1069 } else if (JLI_StrCCmp(arg, "-prof") == 0) {
1070 char *p = arg + 5;
1071 char *tmp = JLI_MemAlloc(JLI_StrLen(arg) + 50);
1072 if (*p) {
1073 sprintf(tmp, "-Xrunhprof:cpu=old,file=%s", p + 1);
1074 } else {
1075 sprintf(tmp, "-Xrunhprof:cpu=old,file=java.prof");
1076 }
1077 AddOption(tmp, NULL);
1078 } else if (JLI_StrCCmp(arg, "-ss") == 0 ||
1079 JLI_StrCCmp(arg, "-oss") == 0 ||
1080 JLI_StrCCmp(arg, "-ms") == 0 ||
1081 JLI_StrCCmp(arg, "-mx") == 0) {
1082 char *tmp = JLI_MemAlloc(JLI_StrLen(arg) + 6);
1083 sprintf(tmp, "-X%s", arg + 1); /* skip '-' */
1084 AddOption(tmp, NULL);
1085 } else if (JLI_StrCmp(arg, "-checksource") == 0 ||
1086 JLI_StrCmp(arg, "-cs") == 0 ||
1087 JLI_StrCmp(arg, "-noasyncgc") == 0) {
1088 /* No longer supported */
1089 ReportErrorMessage(ARG_WARN, arg);
1090 } else if (JLI_StrCCmp(arg, "-version:") == 0 ||
1091 JLI_StrCmp(arg, "-no-jre-restrict-search") == 0 ||
1092 JLI_StrCmp(arg, "-jre-restrict-search") == 0 ||
1093 JLI_StrCCmp(arg, "-splash:") == 0) {
1094 ; /* Ignore machine independent options already handled */
1095 } else if (RemovableOption(arg) ) {
1096 ; /* Do not pass option to vm. */
1097 } else {
1098 AddOption(arg, NULL);
1099 }
1100 }
1101
1102 if (--argc >= 0) {
1103 if (jarflag) {
1104 *pjarfile = *argv++;
1105 *pclassname = 0;
1106 } else {
1107 *pjarfile = 0;
1108 *pclassname = *argv++;
1109 }
1110 *pargc = argc;
1111 *pargv = argv;
1112 }
1113
1114 return JNI_TRUE;
1115}
1116
1117/*
1118 * Initializes the Java Virtual Machine. Also frees options array when
1119 * finished.
1120 */
1121static jboolean
1122InitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn)
1123{
1124 JavaVMInitArgs args;
1125 jint r;
1126
1127 memset(&args, 0, sizeof(args));
1128 args.version = JNI_VERSION_1_2;
1129 args.nOptions = numOptions;
1130 args.options = options;
1131 args.ignoreUnrecognized = JNI_FALSE;
1132
1133 if (JLI_IsTraceLauncher()) {
1134 int i = 0;
1135 printf("JavaVM args:\n ");
1136 printf("version 0x%08lx, ", (long)args.version);
1137 printf("ignoreUnrecognized is %s, ",
1138 args.ignoreUnrecognized ? "JNI_TRUE" : "JNI_FALSE");
1139 printf("nOptions is %ld\n", (long)args.nOptions);
1140 for (i = 0; i < numOptions; i++)
1141 printf(" option[%2d] = '%s'\n",
1142 i, args.options[i].optionString);
1143 }
1144
1145 r = ifn->CreateJavaVM(pvm, (void **)penv, &args);
1146 JLI_MemFree(options);
1147 return r == JNI_OK;
1148}
1149
1150
1151#define NULL_CHECK0(e) if ((e) == 0) { \
1152 ReportErrorMessage(JNI_ERROR); \
1153 return 0; \
1154 }
1155
1156#define NULL_CHECK(e) if ((e) == 0) { \
1157 ReportErrorMessage(JNI_ERROR); \
1158 return; \
1159 }
1160
1161static jstring platformEncoding = NULL;
1162static jstring getPlatformEncoding(JNIEnv *env) {
1163 if (platformEncoding == NULL) {
1164 jstring propname = (*env)->NewStringUTF(env, "sun.jnu.encoding");
1165 if (propname) {
1166 jclass cls;
1167 jmethodID mid;
1168 NULL_CHECK0 (cls = (*env)->FindClass(env, "java/lang/System"));
1169 NULL_CHECK0 (mid = (*env)->GetStaticMethodID(
1170 env, cls,
1171 "getProperty",
1172 "(Ljava/lang/String;)Ljava/lang/String;"));
1173 platformEncoding = (*env)->CallStaticObjectMethod (
1174 env, cls, mid, propname);
1175 }
1176 }
1177 return platformEncoding;
1178}
1179
1180static jboolean isEncodingSupported(JNIEnv *env, jstring enc) {
1181 jclass cls;
1182 jmethodID mid;
1183 NULL_CHECK0 (cls = (*env)->FindClass(env, "java/nio/charset/Charset"));
1184 NULL_CHECK0 (mid = (*env)->GetStaticMethodID(
1185 env, cls,
1186 "isSupported",
1187 "(Ljava/lang/String;)Z"));
1188 return (*env)->CallStaticBooleanMethod(env, cls, mid, enc);
1189}
1190
1191/*
1192 * Returns a new Java string object for the specified platform string.
1193 */
1194static jstring
1195NewPlatformString(JNIEnv *env, char *s)
1196{
1197 int len = (int)JLI_StrLen(s);
1198 jclass cls;
1199 jmethodID mid;
1200 jbyteArray ary;
1201 jstring enc;
1202
1203 if (s == NULL)
1204 return 0;
1205 enc = getPlatformEncoding(env);
1206
1207 ary = (*env)->NewByteArray(env, len);
1208 if (ary != 0) {
1209 jstring str = 0;
1210 (*env)->SetByteArrayRegion(env, ary, 0, len, (jbyte *)s);
1211 if (!(*env)->ExceptionOccurred(env)) {
1212 if (isEncodingSupported(env, enc) == JNI_TRUE) {
1213 NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String"));
1214 NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
1215 "([BLjava/lang/String;)V"));
1216 str = (*env)->NewObject(env, cls, mid, ary, enc);
1217 } else {
1218 /*If the encoding specified in sun.jnu.encoding is not
1219 endorsed by "Charset.isSupported" we have to fall back
1220 to use String(byte[]) explicitly here without specifying
1221 the encoding name, in which the StringCoding class will
1222 pickup the iso-8859-1 as the fallback converter for us.
1223 */
1224 NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String"));
1225 NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
1226 "([B)V"));
1227 str = (*env)->NewObject(env, cls, mid, ary);
1228 }
1229 (*env)->DeleteLocalRef(env, ary);
1230 return str;
1231 }
1232 }
1233 return 0;
1234}
1235
1236/*
1237 * Returns a new array of Java string objects for the specified
1238 * array of platform strings.
1239 */
1240static jobjectArray
1241NewPlatformStringArray(JNIEnv *env, char **strv, int strc)
1242{
1243 jarray cls;
1244 jarray ary;
1245 int i;
1246
1247 NULL_CHECK0(cls = (*env)->FindClass(env, "java/lang/String"));
1248 NULL_CHECK0(ary = (*env)->NewObjectArray(env, strc, cls, 0));
1249 for (i = 0; i < strc; i++) {
1250 jstring str = NewPlatformString(env, *strv++);
1251 NULL_CHECK0(str);
1252 (*env)->SetObjectArrayElement(env, ary, i, str);
1253 (*env)->DeleteLocalRef(env, str);
1254 }
1255 return ary;
1256}
1257
1258/*
1259 * Loads a class, convert the '.' to '/'.
1260 */
1261static jclass
1262LoadClass(JNIEnv *env, char *name)
1263{
1264 char *buf = JLI_MemAlloc(JLI_StrLen(name) + 1);
1265 char *s = buf, *t = name, c;
1266 jclass cls;
1267 jlong start, end;
1268
1269 if (JLI_IsTraceLauncher())
1270 start = CounterGet();
1271
1272 do {
1273 c = *t++;
1274 *s++ = (c == '.') ? '/' : c;
1275 } while (c != '\0');
1276 cls = (*env)->FindClass(env, buf);
1277 JLI_MemFree(buf);
1278
1279 if (JLI_IsTraceLauncher()) {
1280 end = CounterGet();
1281 printf("%ld micro seconds to load main class\n",
1282 (long)(jint)Counter2Micros(end-start));
1283 printf("----_JAVA_LAUNCHER_DEBUG----\n");
1284 }
1285
1286 return cls;
1287}
1288
1289
1290/*
1291 * Returns the main class name for the specified jar file.
1292 */
1293static jstring
1294GetMainClassName(JNIEnv *env, char *jarname)
1295{
1296#define MAIN_CLASS "Main-Class"
1297 jclass cls;
1298 jmethodID mid;
1299 jobject jar, man, attr;
1300 jstring str, result = 0;
1301
1302 NULL_CHECK0(cls = (*env)->FindClass(env, "java/util/jar/JarFile"));
1303 NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
1304 "(Ljava/lang/String;)V"));
1305 NULL_CHECK0(str = NewPlatformString(env, jarname));
1306 NULL_CHECK0(jar = (*env)->NewObject(env, cls, mid, str));
1307 NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "getManifest",
1308 "()Ljava/util/jar/Manifest;"));
1309 man = (*env)->CallObjectMethod(env, jar, mid);
1310 if (man != 0) {
1311 NULL_CHECK0(mid = (*env)->GetMethodID(env,
1312 (*env)->GetObjectClass(env, man),
1313 "getMainAttributes",
1314 "()Ljava/util/jar/Attributes;"));
1315 attr = (*env)->CallObjectMethod(env, man, mid);
1316 if (attr != 0) {
1317 NULL_CHECK0(mid = (*env)->GetMethodID(env,
1318 (*env)->GetObjectClass(env, attr),
1319 "getValue",
1320 "(Ljava/lang/String;)Ljava/lang/String;"));
1321 NULL_CHECK0(str = NewPlatformString(env, MAIN_CLASS));
1322 result = (*env)->CallObjectMethod(env, attr, mid, str);
1323 }
1324 }
1325 return result;
1326}
1327
1328
1329/*
1330 * For tools, convert command line args thus:
1331 * javac -cp foo:foo/"*" -J-ms32m ...
1332 * java -ms32m -cp JLI_WildcardExpandClasspath(foo:foo/"*") ...
1333 *
1334 * Takes 4 parameters, and returns the populated arguments
1335 */
1336static void
1337TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv)
1338{
1339 int argc = *pargc;
1340 char **argv = *pargv;
1341 int nargc = argc + jargc;
1342 char **nargv = JLI_MemAlloc((nargc + 1) * sizeof(char *));
1343 int i;
1344
1345 *pargc = nargc;
1346 *pargv = nargv;
1347
1348 /* Copy the VM arguments (i.e. prefixed with -J) */
1349 for (i = 0; i < jargc; i++) {
1350 const char *arg = jargv[i];
1351 if (arg[0] == '-' && arg[1] == 'J') {
1352 *nargv++ = ((arg + 2) == NULL) ? NULL : JLI_StringDup(arg + 2);
1353 }
1354 }
1355
1356 for (i = 0; i < argc; i++) {
1357 char *arg = argv[i];
1358 if (arg[0] == '-' && arg[1] == 'J') {
1359 if (arg[2] == '\0') {
1360 ReportErrorMessage(ARG_ERROR3);
1361 exit(1);
1362 }
1363 *nargv++ = arg + 2;
1364 }
1365 }
1366
1367 /* Copy the rest of the arguments */
1368 for (i = 0; i < jargc ; i++) {
1369 const char *arg = jargv[i];
1370 if (arg[0] != '-' || arg[1] != 'J') {
1371 *nargv++ = (arg == NULL) ? NULL : JLI_StringDup(arg);
1372 }
1373 }
1374 for (i = 0; i < argc; i++) {
1375 char *arg = argv[i];
1376 if (arg[0] == '-') {
1377 if (arg[1] == 'J')
1378 continue;
1379 if (IsWildCardEnabled() && arg[1] == 'c'
1380 && (JLI_StrCmp(arg, "-cp") == 0 ||
1381 JLI_StrCmp(arg, "-classpath") == 0)
1382 && i < argc - 1) {
1383 *nargv++ = arg;
1384 *nargv++ = (char *) JLI_WildcardExpandClasspath(argv[i+1]);
1385 i++;
1386 continue;
1387 }
1388 }
1389 *nargv++ = arg;
1390 }
1391 *nargv = 0;
1392}
1393
1394/*
1395 * For our tools, we try to add 3 VM options:
1396 * -Denv.class.path=<envcp>
1397 * -Dapplication.home=<apphome>
1398 * -Djava.class.path=<appcp>
1399 * <envcp> is the user's setting of CLASSPATH -- for instance the user
1400 * tells javac where to find binary classes through this environment
1401 * variable. Notice that users will be able to compile against our
1402 * tools classes (sun.tools.javac.Main) only if they explicitly add
1403 * tools.jar to CLASSPATH.
1404 * <apphome> is the directory where the application is installed.
1405 * <appcp> is the classpath to where our apps' classfiles are.
1406 */
1407static jboolean
1408AddApplicationOptions(int cpathc, const char **cpathv)
1409{
1410 char *envcp, *appcp, *apphome;
1411 char home[MAXPATHLEN]; /* application home */
1412 char separator[] = { PATH_SEPARATOR, '\0' };
1413 int size, i;
1414
1415 {
1416 const char *s = getenv("CLASSPATH");
1417 if (s) {
1418 s = (char *) JLI_WildcardExpandClasspath(s);
1419 /* 40 for -Denv.class.path= */
1420 envcp = (char *)JLI_MemAlloc(JLI_StrLen(s) + 40);
1421 sprintf(envcp, "-Denv.class.path=%s", s);
1422 AddOption(envcp, NULL);
1423 }
1424 }
1425
1426 if (!GetApplicationHome(home, sizeof(home))) {
1427 ReportErrorMessage(CFG_ERROR5);
1428 return JNI_FALSE;
1429 }
1430
1431 /* 40 for '-Dapplication.home=' */
1432 apphome = (char *)JLI_MemAlloc(JLI_StrLen(home) + 40);
1433 sprintf(apphome, "-Dapplication.home=%s", home);
1434 AddOption(apphome, NULL);
1435
1436 /* How big is the application's classpath? */
1437 size = 40; /* 40: "-Djava.class.path=" */
1438 for (i = 0; i < cpathc; i++) {
1439 size += (int)JLI_StrLen(home) + (int)JLI_StrLen(cpathv[i]) + 1; /* 1: separator */
1440 }
1441 appcp = (char *)JLI_MemAlloc(size + 1);
1442 JLI_StrCpy(appcp, "-Djava.class.path=");
1443 for (i = 0; i < cpathc; i++) {
1444 JLI_StrCat(appcp, home); /* c:\program files\myapp */
1445 JLI_StrCat(appcp, cpathv[i]); /* \lib\myapp.jar */
1446 JLI_StrCat(appcp, separator); /* ; */
1447 }
1448 appcp[JLI_StrLen(appcp)-1] = '\0'; /* remove trailing path separator */
1449 AddOption(appcp, NULL);
1450 return JNI_TRUE;
1451}
1452
1453/*
1454 * inject the -Dsun.java.command pseudo property into the args structure
1455 * this pseudo property is used in the HotSpot VM to expose the
1456 * Java class name and arguments to the main method to the VM. The
1457 * HotSpot VM uses this pseudo property to store the Java class name
1458 * (or jar file name) and the arguments to the class's main method
1459 * to the instrumentation memory region. The sun.java.command pseudo
1460 * property is not exported by HotSpot to the Java layer.
1461 */
1462void
1463SetJavaCommandLineProp(char *classname, char *jarfile,
1464 int argc, char **argv)
1465{
1466
1467 int i = 0;
1468 size_t len = 0;
1469 char* javaCommand = NULL;
1470 char* dashDstr = "-Dsun.java.command=";
1471
1472 if (classname == NULL && jarfile == NULL) {
1473 /* unexpected, one of these should be set. just return without
1474 * setting the property
1475 */
1476 return;
1477 }
1478
1479 /* if the class name is not set, then use the jarfile name */
1480 if (classname == NULL) {
1481 classname = jarfile;
1482 }
1483
1484 /* determine the amount of memory to allocate assuming
1485 * the individual components will be space separated
1486 */
1487 len = JLI_StrLen(classname);
1488 for (i = 0; i < argc; i++) {
1489 len += JLI_StrLen(argv[i]) + 1;
1490 }
1491
1492 /* allocate the memory */
1493 javaCommand = (char*) JLI_MemAlloc(len + JLI_StrLen(dashDstr) + 1);
1494
1495 /* build the -D string */
1496 *javaCommand = '\0';
1497 JLI_StrCat(javaCommand, dashDstr);
1498 JLI_StrCat(javaCommand, classname);
1499
1500 for (i = 0; i < argc; i++) {
1501 /* the components of the string are space separated. In
1502 * the case of embedded white space, the relationship of
1503 * the white space separated components to their true
1504 * positional arguments will be ambiguous. This issue may
1505 * be addressed in a future release.
1506 */
1507 JLI_StrCat(javaCommand, " ");
1508 JLI_StrCat(javaCommand, argv[i]);
1509 }
1510
1511 AddOption(javaCommand, NULL);
1512}
1513
1514/*
1515 * JVM would like to know if it's created by a standard Sun launcher, or by
1516 * user native application, the following property indicates the former.
1517 */
1518void SetJavaLauncherProp() {
1519 AddOption("-Dsun.java.launcher=SUN_STANDARD", NULL);
1520}
1521
1522/*
1523 * Prints the version information from the java.version and other properties.
1524 */
1525static void
1526PrintJavaVersion(JNIEnv *env, jboolean extraLF)
1527{
1528 jclass ver;
1529 jmethodID print;
1530
1531 NULL_CHECK(ver = (*env)->FindClass(env, "sun/misc/Version"));
1532 NULL_CHECK(print = (*env)->GetStaticMethodID(env,
1533 ver,
1534 (extraLF == JNI_TRUE) ? "println" : "print",
1535 "()V"
1536 )
1537 );
1538
1539 (*env)->CallStaticVoidMethod(env, ver, print);
1540}
1541
1542/*
1543 * Prints default usage or the Xusage message, see sun.launcher.LauncherHelp.java
1544 */
1545static void
1546PrintUsage(JNIEnv* env, jboolean doXUsage)
1547{
1548 jclass cls;
1549 jmethodID initHelp, vmSelect, vmSynonym, vmErgo, printHelp, printXUsageMessage;
1550 jstring jprogname, vm1, vm2;
1551 int i;
1552
1553 NULL_CHECK(cls = (*env)->FindClass(env, "sun/launcher/LauncherHelp"));
1554
1555
1556 if (doXUsage) {
1557 NULL_CHECK(printXUsageMessage = (*env)->GetStaticMethodID(env, cls,
1558 "printXUsageMessage", "(Z)V"));
1559 (*env)->CallStaticVoidMethod(env, cls, printXUsageMessage, JNI_TRUE);
1560 } else {
1561 NULL_CHECK(initHelp = (*env)->GetStaticMethodID(env, cls,
1562 "initHelpMessage", "(Ljava/lang/String;)V"));
1563
1564 NULL_CHECK(vmSelect = (*env)->GetStaticMethodID(env, cls, "appendVmSelectMessage",
1565 "(Ljava/lang/String;Ljava/lang/String;)V"));
1566
1567 NULL_CHECK(vmSynonym = (*env)->GetStaticMethodID(env, cls,
1568 "appendVmSynonymMessage",
1569 "(Ljava/lang/String;Ljava/lang/String;)V"));
1570 NULL_CHECK(vmErgo = (*env)->GetStaticMethodID(env, cls,
1571 "appendVmErgoMessage", "(ZLjava/lang/String;)V"));
1572
1573 NULL_CHECK(printHelp = (*env)->GetStaticMethodID(env, cls,
1574 "printHelpMessage", "(Z)V"));
1575
1576 jprogname = (*env)->NewStringUTF(env, _program_name);
1577
1578 /* Initialize the usage message with the usual preamble */
1579 (*env)->CallStaticVoidMethod(env, cls, initHelp, jprogname);
1580
1581
1582 /* Assemble the other variant part of the usage */
1583 if ((knownVMs[0].flag == VM_KNOWN) ||
1584 (knownVMs[0].flag == VM_IF_SERVER_CLASS)) {
1585 vm1 = (*env)->NewStringUTF(env, knownVMs[0].name);
1586 vm2 = (*env)->NewStringUTF(env, knownVMs[0].name+1);
1587 (*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2);
1588 }
1589 for (i=1; i<knownVMsCount; i++) {
1590 if (knownVMs[i].flag == VM_KNOWN) {
1591 vm1 = (*env)->NewStringUTF(env, knownVMs[i].name);
1592 vm2 = (*env)->NewStringUTF(env, knownVMs[i].name+1);
1593 (*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2);
1594 }
1595 }
1596 for (i=1; i<knownVMsCount; i++) {
1597 if (knownVMs[i].flag == VM_ALIASED_TO) {
1598 vm1 = (*env)->NewStringUTF(env, knownVMs[i].name);
1599 vm2 = (*env)->NewStringUTF(env, knownVMs[i].alias+1);
1600 (*env)->CallStaticVoidMethod(env, cls, vmSynonym, vm1, vm2);
1601 }
1602 }
1603
1604 /* The first known VM is the default */
1605 {
1606 jboolean isServerClassMachine = ServerClassMachine();
1607
1608 const char* defaultVM = knownVMs[0].name+1;
1609 if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) && isServerClassMachine) {
1610 defaultVM = knownVMs[0].server_class+1;
1611 }
1612
1613 vm1 = (*env)->NewStringUTF(env, defaultVM);
1614 (*env)->CallStaticVoidMethod(env, cls, vmErgo, isServerClassMachine, vm1);
1615 }
1616
1617 /* Complete the usage message and print to stderr*/
1618 (*env)->CallStaticVoidMethod(env, cls, printHelp, JNI_TRUE);
1619 }
1620 return;
1621}
1622
1623/*
1624 * Read the jvm.cfg file and fill the knownJVMs[] array.
1625 *
1626 * The functionality of the jvm.cfg file is subject to change without
1627 * notice and the mechanism will be removed in the future.
1628 *
1629 * The lexical structure of the jvm.cfg file is as follows:
1630 *
1631 * jvmcfg := { vmLine }
1632 * vmLine := knownLine
1633 * | aliasLine
1634 * | warnLine
1635 * | ignoreLine
1636 * | errorLine
1637 * | predicateLine
1638 * | commentLine
1639 * knownLine := flag "KNOWN" EOL
1640 * warnLine := flag "WARN" EOL
1641 * ignoreLine := flag "IGNORE" EOL
1642 * errorLine := flag "ERROR" EOL
1643 * aliasLine := flag "ALIASED_TO" flag EOL
1644 * predicateLine := flag "IF_SERVER_CLASS" flag EOL
1645 * commentLine := "#" text EOL
1646 * flag := "-" identifier
1647 *
1648 * The semantics are that when someone specifies a flag on the command line:
1649 * - if the flag appears on a knownLine, then the identifier is used as
1650 * the name of the directory holding the JVM library (the name of the JVM).
1651 * - if the flag appears as the first flag on an aliasLine, the identifier
1652 * of the second flag is used as the name of the JVM.
1653 * - if the flag appears on a warnLine, the identifier is used as the
1654 * name of the JVM, but a warning is generated.
1655 * - if the flag appears on an ignoreLine, the identifier is recognized as the
1656 * name of a JVM, but the identifier is ignored and the default vm used
1657 * - if the flag appears on an errorLine, an error is generated.
1658 * - if the flag appears as the first flag on a predicateLine, and
1659 * the machine on which you are running passes the predicate indicated,
1660 * then the identifier of the second flag is used as the name of the JVM,
1661 * otherwise the identifier of the first flag is used as the name of the JVM.
1662 * If no flag is given on the command line, the first vmLine of the jvm.cfg
1663 * file determines the name of the JVM.
1664 * PredicateLines are only interpreted on first vmLine of a jvm.cfg file,
1665 * since they only make sense if someone hasn't specified the name of the
1666 * JVM on the command line.
1667 *
1668 * The intent of the jvm.cfg file is to allow several JVM libraries to
1669 * be installed in different subdirectories of a single JRE installation,
1670 * for space-savings and convenience in testing.
1671 * The intent is explicitly not to provide a full aliasing or predicate
1672 * mechanism.
1673 */
1674jint
1675ReadKnownVMs(const char *jrepath, const char * arch, jboolean speculative)
1676{
1677 FILE *jvmCfg;
1678 char jvmCfgName[MAXPATHLEN+20];
1679 char line[MAXPATHLEN+20];
1680 int cnt = 0;
1681 int lineno = 0;
1682 jlong start, end;
1683 int vmType;
1684 char *tmpPtr;
1685 char *altVMName = NULL;
1686 char *serverClassVMName = NULL;
1687 static char *whiteSpace = " \t";
1688 if (JLI_IsTraceLauncher()) {
1689 start = CounterGet();
1690 }
1691
1692 JLI_StrCpy(jvmCfgName, jrepath);
1693 JLI_StrCat(jvmCfgName, FILESEP "lib" FILESEP);
1694 JLI_StrCat(jvmCfgName, arch);
1695 JLI_StrCat(jvmCfgName, FILESEP "jvm.cfg");
1696
1697 jvmCfg = fopen(jvmCfgName, "r");
1698 if (jvmCfg == NULL) {
1699 if (!speculative) {
1700 ReportErrorMessage(CFG_ERROR6, jvmCfgName);
1701 exit(1);
1702 } else {
1703 return -1;
1704 }
1705 }
1706 while (fgets(line, sizeof(line), jvmCfg) != NULL) {
1707 vmType = VM_UNKNOWN;
1708 lineno++;
1709 if (line[0] == '#')
1710 continue;
1711 if (line[0] != '-') {
1712 ReportErrorMessage(CFG_WARN2, lineno, jvmCfgName);
1713 }
1714 if (cnt >= knownVMsLimit) {
1715 GrowKnownVMs(cnt);
1716 }
1717 line[JLI_StrLen(line)-1] = '\0'; /* remove trailing newline */
1718 tmpPtr = line + JLI_StrCSpn(line, whiteSpace);
1719 if (*tmpPtr == 0) {
1720 ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
1721 } else {
1722 /* Null-terminate this string for JLI_StringDup below */
1723 *tmpPtr++ = 0;
1724 tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
1725 if (*tmpPtr == 0) {
1726 ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
1727 } else {
1728 if (!JLI_StrCCmp(tmpPtr, "KNOWN")) {
1729 vmType = VM_KNOWN;
1730 } else if (!JLI_StrCCmp(tmpPtr, "ALIASED_TO")) {
1731 tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
1732 if (*tmpPtr != 0) {
1733 tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
1734 }
1735 if (*tmpPtr == 0) {
1736 ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName);
1737 } else {
1738 /* Null terminate altVMName */
1739 altVMName = tmpPtr;
1740 tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
1741 *tmpPtr = 0;
1742 vmType = VM_ALIASED_TO;
1743 }
1744 } else if (!JLI_StrCCmp(tmpPtr, "WARN")) {
1745 vmType = VM_WARN;
1746 } else if (!JLI_StrCCmp(tmpPtr, "IGNORE")) {
1747 vmType = VM_IGNORE;
1748 } else if (!JLI_StrCCmp(tmpPtr, "ERROR")) {
1749 vmType = VM_ERROR;
1750 } else if (!JLI_StrCCmp(tmpPtr, "IF_SERVER_CLASS")) {
1751 tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
1752 if (*tmpPtr != 0) {
1753 tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace);
1754 }
1755 if (*tmpPtr == 0) {
1756 ReportErrorMessage(CFG_WARN4, lineno, jvmCfgName);
1757 } else {
1758 /* Null terminate server class VM name */
1759 serverClassVMName = tmpPtr;
1760 tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace);
1761 *tmpPtr = 0;
1762 vmType = VM_IF_SERVER_CLASS;
1763 }
1764 } else {
1765 ReportErrorMessage(CFG_WARN5, lineno, &jvmCfgName[0]);
1766 vmType = VM_KNOWN;
1767 }
1768 }
1769 }
1770
1771 JLI_TraceLauncher("jvm.cfg[%d] = ->%s<-\n", cnt, line);
1772 if (vmType != VM_UNKNOWN) {
1773 knownVMs[cnt].name = JLI_StringDup(line);
1774 knownVMs[cnt].flag = vmType;
1775 switch (vmType) {
1776 default:
1777 break;
1778 case VM_ALIASED_TO:
1779 knownVMs[cnt].alias = JLI_StringDup(altVMName);
1780 JLI_TraceLauncher(" name: %s vmType: %s alias: %s\n",
1781 knownVMs[cnt].name, "VM_ALIASED_TO", knownVMs[cnt].alias);
1782 break;
1783 case VM_IF_SERVER_CLASS:
1784 knownVMs[cnt].server_class = JLI_StringDup(serverClassVMName);
1785 JLI_TraceLauncher(" name: %s vmType: %s server_class: %s\n",
1786 knownVMs[cnt].name, "VM_IF_SERVER_CLASS", knownVMs[cnt].server_class);
1787 break;
1788 }
1789 cnt++;
1790 }
1791 }
1792 fclose(jvmCfg);
1793 knownVMsCount = cnt;
1794
1795 if (JLI_IsTraceLauncher()) {
1796 end = CounterGet();
1797 printf("%ld micro seconds to parse jvm.cfg\n",
1798 (long)(jint)Counter2Micros(end-start));
1799 }
1800
1801 return cnt;
1802}
1803
1804
1805static void
1806GrowKnownVMs(int minimum)
1807{
1808 struct vmdesc* newKnownVMs;
1809 int newMax;
1810
1811 newMax = (knownVMsLimit == 0 ? INIT_MAX_KNOWN_VMS : (2 * knownVMsLimit));
1812 if (newMax <= minimum) {
1813 newMax = minimum;
1814 }
1815 newKnownVMs = (struct vmdesc*) JLI_MemAlloc(newMax * sizeof(struct vmdesc));
1816 if (knownVMs != NULL) {
1817 memcpy(newKnownVMs, knownVMs, knownVMsLimit * sizeof(struct vmdesc));
1818 }
1819 JLI_MemFree(knownVMs);
1820 knownVMs = newKnownVMs;
1821 knownVMsLimit = newMax;
1822}
1823
1824
1825/* Returns index of VM or -1 if not found */
1826static int
1827KnownVMIndex(const char* name)
1828{
1829 int i;
1830 if (JLI_StrCCmp(name, "-J") == 0) name += 2;
1831 for (i = 0; i < knownVMsCount; i++) {
1832 if (!JLI_StrCmp(name, knownVMs[i].name)) {
1833 return i;
1834 }
1835 }
1836 return -1;
1837}
1838
1839static void
1840FreeKnownVMs()
1841{
1842 int i;
1843 for (i = 0; i < knownVMsCount; i++) {
1844 JLI_MemFree(knownVMs[i].name);
1845 knownVMs[i].name = NULL;
1846 }
1847 JLI_MemFree(knownVMs);
1848}
1849
1850
1851/*
1852 * Displays the splash screen according to the jar file name
1853 * and image file names stored in environment variables
1854 */
1855static void
1856ShowSplashScreen()
1857{
1858 const char *jar_name = getenv(SPLASH_JAR_ENV_ENTRY);
1859 const char *file_name = getenv(SPLASH_FILE_ENV_ENTRY);
1860 int data_size;
1861 void *image_data;
1862 if (jar_name) {
1863 image_data = JLI_JarUnpackFile(jar_name, file_name, &data_size);
1864 if (image_data) {
1865 DoSplashInit();
1866 DoSplashLoadMemory(image_data, data_size);
1867 JLI_MemFree(image_data);
1868 }
1869 } else if (file_name) {
1870 DoSplashInit();
1871 DoSplashLoadFile(file_name);
1872 } else {
1873 return;
1874 }
1875 DoSplashSetFileJarName(file_name, jar_name);
1876
1877 /*
1878 * Done with all command line processing and potential re-execs so
1879 * clean up the environment.
1880 */
1881 (void)UnsetEnv(ENV_ENTRY);
1882 (void)UnsetEnv(SPLASH_FILE_ENV_ENTRY);
1883 (void)UnsetEnv(SPLASH_JAR_ENV_ENTRY);
1884
1885 JLI_MemFree(splash_jar_entry);
1886 JLI_MemFree(splash_file_entry);
1887
1888}
1889
1890const char*
1891GetDotVersion()
1892{
1893 return _dVersion;
1894}
1895
1896const char*
1897GetFullVersion()
1898{
1899 return _fVersion;
1900}
1901
1902const char*
1903GetProgramName()
1904{
1905 return _program_name;
1906}
1907
1908const char*
1909GetLauncherName()
1910{
1911 return _launcher_name;
1912}
1913
1914jint
1915GetErgoPolicy()
1916{
1917 return _ergo_policy;
1918}
1919
1920jboolean
1921IsJavaArgs()
1922{
1923 return _is_java_args;
1924}
1925
1926static jboolean
1927IsWildCardEnabled()
1928{
1929 return _wc_enabled;
1930}
1931
1932static int
1933ContinueInNewThread(InvocationFunctions* ifn, int argc,
1934 char **argv, char *jarfile, char *classname, int ret)
1935{
1936
1937 /*
1938 * If user doesn't specify stack size, check if VM has a preference.
1939 * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will
1940 * return its default stack size through the init args structure.
1941 */
1942 if (threadStackSize == 0) {
1943 struct JDK1_1InitArgs args1_1;
1944 memset((void*)&args1_1, 0, sizeof(args1_1));
1945 args1_1.version = JNI_VERSION_1_1;
1946 ifn->GetDefaultJavaVMInitArgs(&args1_1); /* ignore return value */
1947 if (args1_1.javaStackSize > 0) {
1948 threadStackSize = args1_1.javaStackSize;
1949 }
1950 }
1951
1952 { /* Create a new thread to create JVM and invoke main method */
1953 JavaMainArgs args;
1954 int rslt;
1955
1956 args.argc = argc;
1957 args.argv = argv;
1958 args.jarfile = jarfile;
1959 args.classname = classname;
1960 args.ifn = *ifn;
1961
1962 rslt = ContinueInNewThread0(JavaMain, threadStackSize, (void*)&args);
1963 /* If the caller has deemed there is an error we
1964 * simply return that, otherwise we return the value of
1965 * the callee
1966 */
1967 return (ret != 0) ? ret : rslt;
1968 }
1969}
1970
1971static void
1972DumpState()
1973{
1974 if (!JLI_IsTraceLauncher()) return ;
1975 printf("Launcher state:\n");
1976 printf("\tdebug:%s\n", (JLI_IsTraceLauncher() == JNI_TRUE) ? "on" : "off");
1977 printf("\tjavargs:%s\n", (_is_java_args == JNI_TRUE) ? "on" : "off");
1978 printf("\tprogram name:%s\n", GetProgramName());
1979 printf("\tlauncher name:%s\n", GetLauncherName());
1980 printf("\tjavaw:%s\n", (IsJavaw() == JNI_TRUE) ? "on" : "off");
1981 printf("\tfullversion:%s\n", GetFullVersion());
1982 printf("\tdotversion:%s\n", GetDotVersion());
1983 printf("\tergo_policy:");
1984 switch(GetErgoPolicy()) {
1985 case NEVER_SERVER_CLASS:
1986 printf("NEVER_ACT_AS_A_SERVER_CLASS_MACHINE\n");
1987 break;
1988 case ALWAYS_SERVER_CLASS:
1989 printf("ALWAYS_ACT_AS_A_SERVER_CLASS_MACHINE\n");
1990 break;
1991 default:
1992 printf("DEFAULT_ERGONOMICS_POLICY\n");
1993 }
1994}
1995
1996/*
1997 * Return JNI_TRUE for an option string that has no effect but should
1998 * _not_ be passed on to the vm; return JNI_FALSE otherwise. On
1999 * Solaris SPARC, this screening needs to be done if:
2000 * 1) LD_LIBRARY_PATH does _not_ need to be reset and
2001 * 2) -d32 or -d64 is passed to a binary with a matching data model
2002 * (the exec in SetLibraryPath removes -d<n> options and points the
2003 * exec to the proper binary). When this exec is not done, these options
2004 * would end up getting passed onto the vm.
2005 */
2006jboolean
2007RemovableOption(char * option)
2008{
2009 /*
2010 * Unconditionally remove both -d32 and -d64 options since only
2011 * the last such options has an effect; e.g.
2012 * java -d32 -d64 -d32 -version
2013 * is equivalent to
2014 * java -d32 -version
2015 */
2016
2017 if( (JLI_StrCCmp(option, "-d32") == 0 ) ||
2018 (JLI_StrCCmp(option, "-d64") == 0 ) )
2019 return JNI_TRUE;
2020 else
2021 return JNI_FALSE;
2022}
2023
2024/*
2025 * A utility procedure to always print to stderr
2026 */
2027void
2028ReportMessage(const char* fmt, ...)
2029{
2030 va_list vl;
2031 va_start(vl, fmt);
2032 vfprintf(stderr, fmt, vl);
2033 fprintf(stderr, "\n");
2034 va_end(vl);
2035}