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