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 def = JLI_MemAlloc(sizeof(format) 743 - 2 /* strlen("%s") */ 744 + JLI_StrLen(s)); 745 sprintf(def, format, s); 746 AddOption(def, NULL); 747 if (s != orig) 748 JLI_MemFree((char *) s); 749 } 750 751 /* 752 * The SelectVersion() routine ensures that an appropriate version of 753 * the JRE is running. The specification for the appropriate version 754 * is obtained from either the manifest of a jar file (preferred) or 755 * from command line options. 756 * The routine also parses splash screen command line options and 757 * passes on their values in private environment variables. 758 */ 759 static void 760 SelectVersion(int argc, char **argv, char **main_class) 761 { 762 char *arg; 763 char **new_argv; 764 char **new_argp; 765 char *operand; 766 char *version = NULL; 767 char *jre = NULL; 768 int jarflag = 0; 769 int headlessflag = 0; 770 int restrict_search = -1; /* -1 implies not known */ 771 manifest_info info; 772 char env_entry[MAXNAMELEN + 24] = ENV_ENTRY "="; 773 char *splash_file_name = NULL; 774 char *splash_jar_name = NULL; 775 char *env_in; 776 int res; 777 778 /* 779 * If the version has already been selected, set *main_class 780 * with the value passed through the environment (if any) and 781 * simply return. 782 */ 783 if ((env_in = getenv(ENV_ENTRY)) != NULL) { 784 if (*env_in != '\0') 785 *main_class = JLI_StringDup(env_in); 786 return; 787 } 788 789 /* 790 * Scan through the arguments for options relevant to multiple JRE 791 * support. For reference, the command line syntax is defined as: 792 * 793 * SYNOPSIS 794 * java [options] class [argument...] 795 * 796 * java [options] -jar file.jar [argument...] 797 * 798 * As the scan is performed, make a copy of the argument list with 799 * the version specification options (new to 1.5) removed, so that 800 * a version less than 1.5 can be exec'd. 801 * 802 * Note that due to the syntax of the native Windows interface 803 * CreateProcess(), processing similar to the following exists in 804 * the Windows platform specific routine ExecJRE (in java_md.c). 805 * Changes here should be reproduced there. 806 */ 807 new_argv = JLI_MemAlloc((argc + 1) * sizeof(char*)); 808 new_argv[0] = argv[0]; 809 new_argp = &new_argv[1]; 810 argc--; 811 argv++; 812 while ((arg = *argv) != 0 && *arg == '-') { 813 if (JLI_StrCCmp(arg, "-version:") == 0) { 814 version = arg + 9; 815 } else if (JLI_StrCmp(arg, "-jre-restrict-search") == 0) { 816 restrict_search = 1; 817 } else if (JLI_StrCmp(arg, "-no-jre-restrict-search") == 0) { 818 restrict_search = 0; 819 } else { 820 if (JLI_StrCmp(arg, "-jar") == 0) 821 jarflag = 1; 822 /* deal with "unfortunate" classpath syntax */ 823 if ((JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) && 824 (argc >= 2)) { 825 *new_argp++ = arg; 826 argc--; 827 argv++; 828 arg = *argv; 829 } 830 831 /* 832 * Checking for headless toolkit option in the some way as AWT does: 833 * "true" means true and any other value means false 834 */ 835 if (JLI_StrCmp(arg, "-Djava.awt.headless=true") == 0) { 836 headlessflag = 1; 837 } else if (JLI_StrCCmp(arg, "-Djava.awt.headless=") == 0) { 838 headlessflag = 0; 839 } else if (JLI_StrCCmp(arg, "-splash:") == 0) { 840 splash_file_name = arg+8; 841 } 842 *new_argp++ = arg; 843 } 844 argc--; 845 argv++; 846 } 847 if (argc <= 0) { /* No operand? Possibly legit with -[full]version */ 848 operand = NULL; 849 } else { 850 argc--; 851 *new_argp++ = operand = *argv++; 852 } 853 while (argc-- > 0) /* Copy over [argument...] */ 854 *new_argp++ = *argv++; 855 *new_argp = NULL; 856 857 /* 858 * If there is a jar file, read the manifest. If the jarfile can't be 859 * read, the manifest can't be read from the jar file, or the manifest 860 * is corrupt, issue the appropriate error messages and exit. 861 * 862 * Even if there isn't a jar file, construct a manifest_info structure 863 * containing the command line information. It's a convenient way to carry 864 * this data around. 865 */ 866 if (jarflag && operand) { 867 if ((res = JLI_ParseManifest(operand, &info)) != 0) { 868 if (res == -1) 869 JLI_ReportErrorMessage(JAR_ERROR2, operand); 870 else 871 JLI_ReportErrorMessage(JAR_ERROR3, operand); 872 exit(1); 873 } 874 875 /* 876 * Command line splash screen option should have precedence 877 * over the manifest, so the manifest data is used only if 878 * splash_file_name has not been initialized above during command 879 * line parsing 880 */ 881 if (!headlessflag && !splash_file_name && info.splashscreen_image_file_name) { 882 splash_file_name = info.splashscreen_image_file_name; 883 splash_jar_name = operand; 884 } 885 } else { 886 info.manifest_version = NULL; 887 info.main_class = NULL; 888 info.jre_version = NULL; 889 info.jre_restrict_search = 0; 890 } 891 892 /* 893 * Passing on splash screen info in environment variables 894 */ 895 if (splash_file_name && !headlessflag) { 896 char* splash_file_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_FILE_ENV_ENTRY "=")+JLI_StrLen(splash_file_name)+1); 897 JLI_StrCpy(splash_file_entry, SPLASH_FILE_ENV_ENTRY "="); 898 JLI_StrCat(splash_file_entry, splash_file_name); 899 putenv(splash_file_entry); 900 } 901 if (splash_jar_name && !headlessflag) { 902 char* splash_jar_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_JAR_ENV_ENTRY "=")+JLI_StrLen(splash_jar_name)+1); 903 JLI_StrCpy(splash_jar_entry, SPLASH_JAR_ENV_ENTRY "="); 904 JLI_StrCat(splash_jar_entry, splash_jar_name); 905 putenv(splash_jar_entry); 906 } 907 908 /* 909 * The JRE-Version and JRE-Restrict-Search values (if any) from the 910 * manifest are overwritten by any specified on the command line. 911 */ 912 if (version != NULL) 913 info.jre_version = version; 914 if (restrict_search != -1) 915 info.jre_restrict_search = restrict_search; 916 917 /* 918 * "Valid" returns (other than unrecoverable errors) follow. Set 919 * main_class as a side-effect of this routine. 920 */ 921 if (info.main_class != NULL) 922 *main_class = JLI_StringDup(info.main_class); 923 924 /* 925 * If no version selection information is found either on the command 926 * line or in the manifest, simply return. 927 */ 928 if (info.jre_version == NULL) { 929 JLI_FreeManifest(); 930 JLI_MemFree(new_argv); 931 return; 932 } 933 934 /* 935 * Check for correct syntax of the version specification (JSR 56). 936 */ 937 if (!JLI_ValidVersionString(info.jre_version)) { 938 JLI_ReportErrorMessage(SPC_ERROR1, info.jre_version); 939 exit(1); 940 } 941 942 /* 943 * Find the appropriate JVM on the system. Just to be as forgiving as 944 * possible, if the standard algorithms don't locate an appropriate 945 * jre, check to see if the one running will satisfy the requirements. 946 * This can happen on systems which haven't been set-up for multiple 947 * JRE support. 948 */ 949 jre = LocateJRE(&info); 950 JLI_TraceLauncher("JRE-Version = %s, JRE-Restrict-Search = %s Selected = %s\n", 951 (info.jre_version?info.jre_version:"null"), 952 (info.jre_restrict_search?"true":"false"), (jre?jre:"null")); 953 954 if (jre == NULL) { 955 if (JLI_AcceptableRelease(GetFullVersion(), info.jre_version)) { 956 JLI_FreeManifest(); 957 JLI_MemFree(new_argv); 958 return; 959 } else { 960 JLI_ReportErrorMessage(CFG_ERROR4, info.jre_version); 961 exit(1); 962 } 963 } 964 965 /* 966 * If I'm not the chosen one, exec the chosen one. Returning from 967 * ExecJRE indicates that I am indeed the chosen one. 968 * 969 * The private environment variable _JAVA_VERSION_SET is used to 970 * prevent the chosen one from re-reading the manifest file and 971 * using the values found within to override the (potential) command 972 * line flags stripped from argv (because the target may not 973 * understand them). Passing the MainClass value is an optimization 974 * to avoid locating, expanding and parsing the manifest extra 975 * times. 976 */ 977 if (info.main_class != NULL) { 978 if (JLI_StrLen(info.main_class) <= MAXNAMELEN) { 979 (void)JLI_StrCat(env_entry, info.main_class); 980 } else { 981 JLI_ReportErrorMessage(CLS_ERROR5, MAXNAMELEN); 982 exit(1); 983 } 984 } 985 (void)putenv(env_entry); 986 ExecJRE(jre, new_argv); 987 JLI_FreeManifest(); 988 JLI_MemFree(new_argv); 989 return; 990 } 991 992 /* 993 * Parses command line arguments. Returns JNI_FALSE if launcher 994 * should exit without starting vm, returns JNI_TRUE if vm needs 995 * to be started to process given options. *pret (the launcher 996 * process return value) is set to 0 for a normal exit. 997 */ 998 static jboolean 999 ParseArguments(int *pargc, char ***pargv, 1000 int *pmode, char **pwhat, 1001 int *pret, const char *jrepath) 1002 { 1003 int argc = *pargc; 1004 char **argv = *pargv; 1005 int mode = LM_UNKNOWN; 1006 char *arg; 1007 1008 *pret = 0; 1009 1010 while ((arg = *argv) != 0 && *arg == '-') { 1011 argv++; --argc; 1012 if (JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) { 1013 ARG_CHECK (argc, ARG_ERROR1, arg); 1014 SetClassPath(*argv); 1015 mode = LM_CLASS; 1016 argv++; --argc; 1017 } else if (JLI_StrCmp(arg, "-jar") == 0) { 1018 ARG_CHECK (argc, ARG_ERROR2, arg); 1019 mode = LM_JAR; 1020 } else if (JLI_StrCmp(arg, "-help") == 0 || 1021 JLI_StrCmp(arg, "-h") == 0 || 1022 JLI_StrCmp(arg, "-?") == 0) { 1023 printUsage = JNI_TRUE; 1024 return JNI_TRUE; 1025 } else if (JLI_StrCmp(arg, "-version") == 0) { 1026 printVersion = JNI_TRUE; 1027 return JNI_TRUE; 1028 } else if (JLI_StrCmp(arg, "-showversion") == 0) { 1029 showVersion = JNI_TRUE; 1030 } else if (JLI_StrCmp(arg, "-X") == 0) { 1031 printXUsage = JNI_TRUE; 1032 return JNI_TRUE; 1033 /* 1034 * The following case checks for -XshowSettings OR -XshowSetting:SUBOPT. 1035 * In the latter case, any SUBOPT value not recognized will default to "all" 1036 */ 1037 } else if (JLI_StrCmp(arg, "-XshowSettings") == 0 || 1038 JLI_StrCCmp(arg, "-XshowSettings:") == 0) { 1039 showSettings = arg; 1040 } else if (JLI_StrCmp(arg, "-Xdiag") == 0) { 1041 AddOption("-Dsun.java.launcher.diag=true", NULL); 1042 /* 1043 * The following case provide backward compatibility with old-style 1044 * command line options. 1045 */ 1046 } else if (JLI_StrCmp(arg, "-fullversion") == 0) { 1047 JLI_ReportMessage("%s full version \"%s\"", _launcher_name, GetFullVersion()); 1048 return JNI_FALSE; 1049 } else if (JLI_StrCmp(arg, "-verbosegc") == 0) { 1050 AddOption("-verbose:gc", NULL); 1051 } else if (JLI_StrCmp(arg, "-t") == 0) { 1052 AddOption("-Xt", NULL); 1053 } else if (JLI_StrCmp(arg, "-tm") == 0) { 1054 AddOption("-Xtm", NULL); 1055 } else if (JLI_StrCmp(arg, "-debug") == 0) { 1056 AddOption("-Xdebug", NULL); 1057 } else if (JLI_StrCmp(arg, "-noclassgc") == 0) { 1058 AddOption("-Xnoclassgc", NULL); 1059 } else if (JLI_StrCmp(arg, "-Xfuture") == 0) { 1060 AddOption("-Xverify:all", NULL); 1061 } else if (JLI_StrCmp(arg, "-verify") == 0) { 1062 AddOption("-Xverify:all", NULL); 1063 } else if (JLI_StrCmp(arg, "-verifyremote") == 0) { 1064 AddOption("-Xverify:remote", NULL); 1065 } else if (JLI_StrCmp(arg, "-noverify") == 0) { 1066 AddOption("-Xverify:none", NULL); 1067 } else if (JLI_StrCCmp(arg, "-prof") == 0) { 1068 char *p = arg + 5; 1069 char *tmp = JLI_MemAlloc(JLI_StrLen(arg) + 50); 1070 if (*p) { 1071 sprintf(tmp, "-Xrunhprof:cpu=old,file=%s", p + 1); 1072 } else { 1073 sprintf(tmp, "-Xrunhprof:cpu=old,file=java.prof"); 1074 } 1075 AddOption(tmp, NULL); 1076 } else if (JLI_StrCCmp(arg, "-ss") == 0 || 1077 JLI_StrCCmp(arg, "-oss") == 0 || 1078 JLI_StrCCmp(arg, "-ms") == 0 || 1079 JLI_StrCCmp(arg, "-mx") == 0) { 1080 char *tmp = JLI_MemAlloc(JLI_StrLen(arg) + 6); 1081 sprintf(tmp, "-X%s", arg + 1); /* skip '-' */ 1082 AddOption(tmp, NULL); 1083 } else if (JLI_StrCmp(arg, "-checksource") == 0 || 1084 JLI_StrCmp(arg, "-cs") == 0 || 1085 JLI_StrCmp(arg, "-noasyncgc") == 0) { 1086 /* No longer supported */ 1087 JLI_ReportErrorMessage(ARG_WARN, arg); 1088 } else if (JLI_StrCCmp(arg, "-version:") == 0 || 1089 JLI_StrCmp(arg, "-no-jre-restrict-search") == 0 || 1090 JLI_StrCmp(arg, "-jre-restrict-search") == 0 || 1091 JLI_StrCCmp(arg, "-splash:") == 0) { 1092 ; /* Ignore machine independent options already handled */ 1093 } else if (ProcessPlatformOption(arg)) { 1094 ; /* Processing of platform dependent options */ 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 *pwhat = *argv++; 1104 } 1105 1106 if (*pwhat == NULL) { 1107 *pret = 1; 1108 } else if (mode == LM_UNKNOWN) { 1109 /* default to LM_CLASS if -jar and -cp option are 1110 * not specified */ 1111 mode = LM_CLASS; 1112 } 1113 1114 if (argc >= 0) { 1115 *pargc = argc; 1116 *pargv = argv; 1117 } 1118 1119 *pmode = mode; 1120 1121 return JNI_TRUE; 1122 } 1123 1124 /* 1125 * Initializes the Java Virtual Machine. Also frees options array when 1126 * finished. 1127 */ 1128 static jboolean 1129 InitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn) 1130 { 1131 JavaVMInitArgs args; 1132 jint r; 1133 1134 memset(&args, 0, sizeof(args)); 1135 args.version = JNI_VERSION_1_2; 1136 args.nOptions = numOptions; 1137 args.options = options; 1138 args.ignoreUnrecognized = JNI_FALSE; 1139 1140 if (JLI_IsTraceLauncher()) { 1141 int i = 0; 1142 printf("JavaVM args:\n "); 1143 printf("version 0x%08lx, ", (long)args.version); 1144 printf("ignoreUnrecognized is %s, ", 1145 args.ignoreUnrecognized ? "JNI_TRUE" : "JNI_FALSE"); 1146 printf("nOptions is %ld\n", (long)args.nOptions); 1147 for (i = 0; i < numOptions; i++) 1148 printf(" option[%2d] = '%s'\n", 1149 i, args.options[i].optionString); 1150 } 1151 1152 r = ifn->CreateJavaVM(pvm, (void **)penv, &args); 1153 JLI_MemFree(options); 1154 return r == JNI_OK; 1155 } 1156 1157 static jclass helperClass = NULL; 1158 1159 jclass 1160 GetLauncherHelperClass(JNIEnv *env) 1161 { 1162 if (helperClass == NULL) { 1163 NULL_CHECK0(helperClass = FindBootStrapClass(env, 1164 "sun/launcher/LauncherHelper")); 1165 } 1166 return helperClass; 1167 } 1168 1169 static jmethodID makePlatformStringMID = NULL; 1170 /* 1171 * Returns a new Java string object for the specified platform string. 1172 */ 1173 static jstring 1174 NewPlatformString(JNIEnv *env, char *s) 1175 { 1176 int len = (int)JLI_StrLen(s); 1177 jbyteArray ary; 1178 jclass cls = GetLauncherHelperClass(env); 1179 NULL_CHECK0(cls); 1180 if (s == NULL) 1181 return 0; 1182 1183 ary = (*env)->NewByteArray(env, len); 1184 if (ary != 0) { 1185 jstring str = 0; 1186 (*env)->SetByteArrayRegion(env, ary, 0, len, (jbyte *)s); 1187 if (!(*env)->ExceptionOccurred(env)) { 1188 if (makePlatformStringMID == NULL) { 1189 NULL_CHECK0(makePlatformStringMID = (*env)->GetStaticMethodID(env, 1190 cls, "makePlatformString", "(Z[B)Ljava/lang/String;")); 1191 } 1192 str = (*env)->CallStaticObjectMethod(env, cls, 1193 makePlatformStringMID, USE_STDERR, ary); 1194 (*env)->DeleteLocalRef(env, ary); 1195 return str; 1196 } 1197 } 1198 return 0; 1199 } 1200 1201 /* 1202 * Returns a new array of Java string objects for the specified 1203 * array of platform strings. 1204 */ 1205 jobjectArray 1206 NewPlatformStringArray(JNIEnv *env, char **strv, int strc) 1207 { 1208 jarray cls; 1209 jarray ary; 1210 int i; 1211 1212 NULL_CHECK0(cls = FindBootStrapClass(env, "java/lang/String")); 1213 NULL_CHECK0(ary = (*env)->NewObjectArray(env, strc, cls, 0)); 1214 for (i = 0; i < strc; i++) { 1215 jstring str = NewPlatformString(env, *strv++); 1216 NULL_CHECK0(str); 1217 (*env)->SetObjectArrayElement(env, ary, i, str); 1218 (*env)->DeleteLocalRef(env, str); 1219 } 1220 return ary; 1221 } 1222 1223 /* 1224 * Loads a class and verifies that the main class is present and it is ok to 1225 * call it for more details refer to the java implementation. 1226 */ 1227 static jclass 1228 LoadMainClass(JNIEnv *env, int mode, char *name) 1229 { 1230 jmethodID mid; 1231 jstring str; 1232 jobject result; 1233 jlong start, end; 1234 jclass cls = GetLauncherHelperClass(env); 1235 NULL_CHECK0(cls); 1236 if (JLI_IsTraceLauncher()) { 1237 start = CounterGet(); 1238 } 1239 NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls, 1240 "checkAndLoadMain", 1241 "(ZILjava/lang/String;)Ljava/lang/Class;")); 1242 1243 NULL_CHECK0(str = NewPlatformString(env, name)); 1244 NULL_CHECK0(result = (*env)->CallStaticObjectMethod(env, cls, mid, 1245 USE_STDERR, mode, str)); 1246 1247 if (JLI_IsTraceLauncher()) { 1248 end = CounterGet(); 1249 printf("%ld micro seconds to load main class\n", 1250 (long)(jint)Counter2Micros(end-start)); 1251 printf("----%s----\n", JLDEBUG_ENV_ENTRY); 1252 } 1253 1254 return (jclass)result; 1255 } 1256 1257 static jclass 1258 GetApplicationClass(JNIEnv *env) 1259 { 1260 jmethodID mid; 1261 jclass cls = GetLauncherHelperClass(env); 1262 NULL_CHECK0(cls); 1263 NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls, 1264 "getApplicationClass", 1265 "()Ljava/lang/Class;")); 1266 1267 return (*env)->CallStaticObjectMethod(env, cls, mid); 1268 } 1269 1270 /* 1271 * For tools, convert command line args thus: 1272 * javac -cp foo:foo/"*" -J-ms32m ... 1273 * java -ms32m -cp JLI_WildcardExpandClasspath(foo:foo/"*") ... 1274 * 1275 * Takes 4 parameters, and returns the populated arguments 1276 */ 1277 static void 1278 TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv) 1279 { 1280 int argc = *pargc; 1281 char **argv = *pargv; 1282 int nargc = argc + jargc; 1283 char **nargv = JLI_MemAlloc((nargc + 1) * sizeof(char *)); 1284 int i; 1285 1286 *pargc = nargc; 1287 *pargv = nargv; 1288 1289 /* Copy the VM arguments (i.e. prefixed with -J) */ 1290 for (i = 0; i < jargc; i++) { 1291 const char *arg = jargv[i]; 1292 if (arg[0] == '-' && arg[1] == 'J') { 1293 *nargv++ = ((arg + 2) == NULL) ? NULL : JLI_StringDup(arg + 2); 1294 } 1295 } 1296 1297 for (i = 0; i < argc; i++) { 1298 char *arg = argv[i]; 1299 if (arg[0] == '-' && arg[1] == 'J') { 1300 if (arg[2] == '\0') { 1301 JLI_ReportErrorMessage(ARG_ERROR3); 1302 exit(1); 1303 } 1304 *nargv++ = arg + 2; 1305 } 1306 } 1307 1308 /* Copy the rest of the arguments */ 1309 for (i = 0; i < jargc ; i++) { 1310 const char *arg = jargv[i]; 1311 if (arg[0] != '-' || arg[1] != 'J') { 1312 *nargv++ = (arg == NULL) ? NULL : JLI_StringDup(arg); 1313 } 1314 } 1315 for (i = 0; i < argc; i++) { 1316 char *arg = argv[i]; 1317 if (arg[0] == '-') { 1318 if (arg[1] == 'J') 1319 continue; 1320 if (IsWildCardEnabled() && arg[1] == 'c' 1321 && (JLI_StrCmp(arg, "-cp") == 0 || 1322 JLI_StrCmp(arg, "-classpath") == 0) 1323 && i < argc - 1) { 1324 *nargv++ = arg; 1325 *nargv++ = (char *) JLI_WildcardExpandClasspath(argv[i+1]); 1326 i++; 1327 continue; 1328 } 1329 } 1330 *nargv++ = arg; 1331 } 1332 *nargv = 0; 1333 } 1334 1335 /* 1336 * For our tools, we try to add 3 VM options: 1337 * -Denv.class.path=<envcp> 1338 * -Dapplication.home=<apphome> 1339 * -Djava.class.path=<appcp> 1340 * <envcp> is the user's setting of CLASSPATH -- for instance the user 1341 * tells javac where to find binary classes through this environment 1342 * variable. Notice that users will be able to compile against our 1343 * tools classes (sun.tools.javac.Main) only if they explicitly add 1344 * tools.jar to CLASSPATH. 1345 * <apphome> is the directory where the application is installed. 1346 * <appcp> is the classpath to where our apps' classfiles are. 1347 */ 1348 static jboolean 1349 AddApplicationOptions(int cpathc, const char **cpathv) 1350 { 1351 char *envcp, *appcp, *apphome; 1352 char home[MAXPATHLEN]; /* application home */ 1353 char separator[] = { PATH_SEPARATOR, '\0' }; 1354 int size, i; 1355 1356 { 1357 const char *s = getenv("CLASSPATH"); 1358 if (s) { 1359 s = (char *) JLI_WildcardExpandClasspath(s); 1360 /* 40 for -Denv.class.path= */ 1361 envcp = (char *)JLI_MemAlloc(JLI_StrLen(s) + 40); 1362 sprintf(envcp, "-Denv.class.path=%s", s); 1363 AddOption(envcp, NULL); 1364 } 1365 } 1366 1367 if (!GetApplicationHome(home, sizeof(home))) { 1368 JLI_ReportErrorMessage(CFG_ERROR5); 1369 return JNI_FALSE; 1370 } 1371 1372 /* 40 for '-Dapplication.home=' */ 1373 apphome = (char *)JLI_MemAlloc(JLI_StrLen(home) + 40); 1374 sprintf(apphome, "-Dapplication.home=%s", home); 1375 AddOption(apphome, NULL); 1376 1377 /* How big is the application's classpath? */ 1378 size = 40; /* 40: "-Djava.class.path=" */ 1379 for (i = 0; i < cpathc; i++) { 1380 size += (int)JLI_StrLen(home) + (int)JLI_StrLen(cpathv[i]) + 1; /* 1: separator */ 1381 } 1382 appcp = (char *)JLI_MemAlloc(size + 1); 1383 JLI_StrCpy(appcp, "-Djava.class.path="); 1384 for (i = 0; i < cpathc; i++) { 1385 JLI_StrCat(appcp, home); /* c:\program files\myapp */ 1386 JLI_StrCat(appcp, cpathv[i]); /* \lib\myapp.jar */ 1387 JLI_StrCat(appcp, separator); /* ; */ 1388 } 1389 appcp[JLI_StrLen(appcp)-1] = '\0'; /* remove trailing path separator */ 1390 AddOption(appcp, NULL); 1391 return JNI_TRUE; 1392 } 1393 1394 /* 1395 * inject the -Dsun.java.command pseudo property into the args structure 1396 * this pseudo property is used in the HotSpot VM to expose the 1397 * Java class name and arguments to the main method to the VM. The 1398 * HotSpot VM uses this pseudo property to store the Java class name 1399 * (or jar file name) and the arguments to the class's main method 1400 * to the instrumentation memory region. The sun.java.command pseudo 1401 * property is not exported by HotSpot to the Java layer. 1402 */ 1403 void 1404 SetJavaCommandLineProp(char *what, int argc, char **argv) 1405 { 1406 1407 int i = 0; 1408 size_t len = 0; 1409 char* javaCommand = NULL; 1410 char* dashDstr = "-Dsun.java.command="; 1411 1412 if (what == NULL) { 1413 /* unexpected, one of these should be set. just return without 1414 * setting the property 1415 */ 1416 return; 1417 } 1418 1419 /* determine the amount of memory to allocate assuming 1420 * the individual components will be space separated 1421 */ 1422 len = JLI_StrLen(what); 1423 for (i = 0; i < argc; i++) { 1424 len += JLI_StrLen(argv[i]) + 1; 1425 } 1426 1427 /* allocate the memory */ 1428 javaCommand = (char*) JLI_MemAlloc(len + JLI_StrLen(dashDstr) + 1); 1429 1430 /* build the -D string */ 1431 *javaCommand = '\0'; 1432 JLI_StrCat(javaCommand, dashDstr); 1433 JLI_StrCat(javaCommand, what); 1434 1435 for (i = 0; i < argc; i++) { 1436 /* the components of the string are space separated. In 1437 * the case of embedded white space, the relationship of 1438 * the white space separated components to their true 1439 * positional arguments will be ambiguous. This issue may 1440 * be addressed in a future release. 1441 */ 1442 JLI_StrCat(javaCommand, " "); 1443 JLI_StrCat(javaCommand, argv[i]); 1444 } 1445 1446 AddOption(javaCommand, NULL); 1447 } 1448 1449 /* 1450 * JVM would like to know if it's created by a standard Sun launcher, or by 1451 * user native application, the following property indicates the former. 1452 */ 1453 void 1454 SetJavaLauncherProp() { 1455 AddOption("-Dsun.java.launcher=SUN_STANDARD", NULL); 1456 } 1457 1458 /* 1459 * Prints the version information from the java.version and other properties. 1460 */ 1461 static void 1462 PrintJavaVersion(JNIEnv *env, jboolean extraLF) 1463 { 1464 jclass ver; 1465 jmethodID print; 1466 1467 NULL_CHECK(ver = FindBootStrapClass(env, "sun/misc/Version")); 1468 NULL_CHECK(print = (*env)->GetStaticMethodID(env, 1469 ver, 1470 (extraLF == JNI_TRUE) ? "println" : "print", 1471 "()V" 1472 ) 1473 ); 1474 1475 (*env)->CallStaticVoidMethod(env, ver, print); 1476 } 1477 1478 /* 1479 * Prints all the Java settings, see the java implementation for more details. 1480 */ 1481 static void 1482 ShowSettings(JNIEnv *env, char *optString) 1483 { 1484 jmethodID showSettingsID; 1485 jstring joptString; 1486 jclass cls = GetLauncherHelperClass(env); 1487 NULL_CHECK(cls); 1488 NULL_CHECK(showSettingsID = (*env)->GetStaticMethodID(env, cls, 1489 "showSettings", "(ZLjava/lang/String;JJJZ)V")); 1490 NULL_CHECK(joptString = (*env)->NewStringUTF(env, optString)); 1491 (*env)->CallStaticVoidMethod(env, cls, showSettingsID, 1492 USE_STDERR, 1493 joptString, 1494 (jlong)initialHeapSize, 1495 (jlong)maxHeapSize, 1496 (jlong)threadStackSize, 1497 ServerClassMachine()); 1498 } 1499 1500 /* 1501 * Prints default usage or the Xusage message, see sun.launcher.LauncherHelper.java 1502 */ 1503 static void 1504 PrintUsage(JNIEnv* env, jboolean doXUsage) 1505 { 1506 jmethodID initHelp, vmSelect, vmSynonym, vmErgo, printHelp, printXUsageMessage; 1507 jstring jprogname, vm1, vm2; 1508 int i; 1509 jclass cls = GetLauncherHelperClass(env); 1510 NULL_CHECK(cls); 1511 if (doXUsage) { 1512 NULL_CHECK(printXUsageMessage = (*env)->GetStaticMethodID(env, cls, 1513 "printXUsageMessage", "(Z)V")); 1514 (*env)->CallStaticVoidMethod(env, cls, printXUsageMessage, USE_STDERR); 1515 } else { 1516 NULL_CHECK(initHelp = (*env)->GetStaticMethodID(env, cls, 1517 "initHelpMessage", "(Ljava/lang/String;)V")); 1518 1519 NULL_CHECK(vmSelect = (*env)->GetStaticMethodID(env, cls, "appendVmSelectMessage", 1520 "(Ljava/lang/String;Ljava/lang/String;)V")); 1521 1522 NULL_CHECK(vmSynonym = (*env)->GetStaticMethodID(env, cls, 1523 "appendVmSynonymMessage", 1524 "(Ljava/lang/String;Ljava/lang/String;)V")); 1525 NULL_CHECK(vmErgo = (*env)->GetStaticMethodID(env, cls, 1526 "appendVmErgoMessage", "(ZLjava/lang/String;)V")); 1527 1528 NULL_CHECK(printHelp = (*env)->GetStaticMethodID(env, cls, 1529 "printHelpMessage", "(Z)V")); 1530 1531 NULL_CHECK(jprogname = (*env)->NewStringUTF(env, _program_name)); 1532 1533 /* Initialize the usage message with the usual preamble */ 1534 (*env)->CallStaticVoidMethod(env, cls, initHelp, jprogname); 1535 CHECK_EXCEPTION_RETURN(); 1536 1537 1538 /* Assemble the other variant part of the usage */ 1539 if ((knownVMs[0].flag == VM_KNOWN) || 1540 (knownVMs[0].flag == VM_IF_SERVER_CLASS)) { 1541 NULL_CHECK(vm1 = (*env)->NewStringUTF(env, knownVMs[0].name)); 1542 NULL_CHECK(vm2 = (*env)->NewStringUTF(env, knownVMs[0].name+1)); 1543 (*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2); 1544 CHECK_EXCEPTION_RETURN(); 1545 } 1546 for (i=1; i<knownVMsCount; i++) { 1547 if (knownVMs[i].flag == VM_KNOWN) { 1548 NULL_CHECK(vm1 = (*env)->NewStringUTF(env, knownVMs[i].name)); 1549 NULL_CHECK(vm2 = (*env)->NewStringUTF(env, knownVMs[i].name+1)); 1550 (*env)->CallStaticVoidMethod(env, cls, vmSelect, vm1, vm2); 1551 CHECK_EXCEPTION_RETURN(); 1552 } 1553 } 1554 for (i=1; i<knownVMsCount; i++) { 1555 if (knownVMs[i].flag == VM_ALIASED_TO) { 1556 NULL_CHECK(vm1 = (*env)->NewStringUTF(env, knownVMs[i].name)); 1557 NULL_CHECK(vm2 = (*env)->NewStringUTF(env, knownVMs[i].alias+1)); 1558 (*env)->CallStaticVoidMethod(env, cls, vmSynonym, vm1, vm2); 1559 CHECK_EXCEPTION_RETURN(); 1560 } 1561 } 1562 1563 /* The first known VM is the default */ 1564 { 1565 jboolean isServerClassMachine = ServerClassMachine(); 1566 1567 const char* defaultVM = knownVMs[0].name+1; 1568 if ((knownVMs[0].flag == VM_IF_SERVER_CLASS) && isServerClassMachine) { 1569 defaultVM = knownVMs[0].server_class+1; 1570 } 1571 1572 NULL_CHECK(vm1 = (*env)->NewStringUTF(env, defaultVM)); 1573 (*env)->CallStaticVoidMethod(env, cls, vmErgo, isServerClassMachine, vm1); 1574 CHECK_EXCEPTION_RETURN(); 1575 } 1576 1577 /* Complete the usage message and print to stderr*/ 1578 (*env)->CallStaticVoidMethod(env, cls, printHelp, USE_STDERR); 1579 } 1580 return; 1581 } 1582 1583 /* 1584 * Read the jvm.cfg file and fill the knownJVMs[] array. 1585 * 1586 * The functionality of the jvm.cfg file is subject to change without 1587 * notice and the mechanism will be removed in the future. 1588 * 1589 * The lexical structure of the jvm.cfg file is as follows: 1590 * 1591 * jvmcfg := { vmLine } 1592 * vmLine := knownLine 1593 * | aliasLine 1594 * | warnLine 1595 * | ignoreLine 1596 * | errorLine 1597 * | predicateLine 1598 * | commentLine 1599 * knownLine := flag "KNOWN" EOL 1600 * warnLine := flag "WARN" EOL 1601 * ignoreLine := flag "IGNORE" EOL 1602 * errorLine := flag "ERROR" EOL 1603 * aliasLine := flag "ALIASED_TO" flag EOL 1604 * predicateLine := flag "IF_SERVER_CLASS" flag EOL 1605 * commentLine := "#" text EOL 1606 * flag := "-" identifier 1607 * 1608 * The semantics are that when someone specifies a flag on the command line: 1609 * - if the flag appears on a knownLine, then the identifier is used as 1610 * the name of the directory holding the JVM library (the name of the JVM). 1611 * - if the flag appears as the first flag on an aliasLine, the identifier 1612 * of the second flag is used as the name of the JVM. 1613 * - if the flag appears on a warnLine, the identifier is used as the 1614 * name of the JVM, but a warning is generated. 1615 * - if the flag appears on an ignoreLine, the identifier is recognized as the 1616 * name of a JVM, but the identifier is ignored and the default vm used 1617 * - if the flag appears on an errorLine, an error is generated. 1618 * - if the flag appears as the first flag on a predicateLine, and 1619 * the machine on which you are running passes the predicate indicated, 1620 * then the identifier of the second flag is used as the name of the JVM, 1621 * otherwise the identifier of the first flag is used as the name of the JVM. 1622 * If no flag is given on the command line, the first vmLine of the jvm.cfg 1623 * file determines the name of the JVM. 1624 * PredicateLines are only interpreted on first vmLine of a jvm.cfg file, 1625 * since they only make sense if someone hasn't specified the name of the 1626 * JVM on the command line. 1627 * 1628 * The intent of the jvm.cfg file is to allow several JVM libraries to 1629 * be installed in different subdirectories of a single JRE installation, 1630 * for space-savings and convenience in testing. 1631 * The intent is explicitly not to provide a full aliasing or predicate 1632 * mechanism. 1633 */ 1634 jint 1635 ReadKnownVMs(const char *jvmCfgName, jboolean speculative) 1636 { 1637 FILE *jvmCfg; 1638 char line[MAXPATHLEN+20]; 1639 int cnt = 0; 1640 int lineno = 0; 1641 jlong start, end; 1642 int vmType; 1643 char *tmpPtr; 1644 char *altVMName = NULL; 1645 char *serverClassVMName = NULL; 1646 static char *whiteSpace = " \t"; 1647 if (JLI_IsTraceLauncher()) { 1648 start = CounterGet(); 1649 } 1650 1651 jvmCfg = fopen(jvmCfgName, "r"); 1652 if (jvmCfg == NULL) { 1653 if (!speculative) { 1654 JLI_ReportErrorMessage(CFG_ERROR6, jvmCfgName); 1655 exit(1); 1656 } else { 1657 return -1; 1658 } 1659 } 1660 while (fgets(line, sizeof(line), jvmCfg) != NULL) { 1661 vmType = VM_UNKNOWN; 1662 lineno++; 1663 if (line[0] == '#') 1664 continue; 1665 if (line[0] != '-') { 1666 JLI_ReportErrorMessage(CFG_WARN2, lineno, jvmCfgName); 1667 } 1668 if (cnt >= knownVMsLimit) { 1669 GrowKnownVMs(cnt); 1670 } 1671 line[JLI_StrLen(line)-1] = '\0'; /* remove trailing newline */ 1672 tmpPtr = line + JLI_StrCSpn(line, whiteSpace); 1673 if (*tmpPtr == 0) { 1674 JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName); 1675 } else { 1676 /* Null-terminate this string for JLI_StringDup below */ 1677 *tmpPtr++ = 0; 1678 tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace); 1679 if (*tmpPtr == 0) { 1680 JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName); 1681 } else { 1682 if (!JLI_StrCCmp(tmpPtr, "KNOWN")) { 1683 vmType = VM_KNOWN; 1684 } else if (!JLI_StrCCmp(tmpPtr, "ALIASED_TO")) { 1685 tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace); 1686 if (*tmpPtr != 0) { 1687 tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace); 1688 } 1689 if (*tmpPtr == 0) { 1690 JLI_ReportErrorMessage(CFG_WARN3, lineno, jvmCfgName); 1691 } else { 1692 /* Null terminate altVMName */ 1693 altVMName = tmpPtr; 1694 tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace); 1695 *tmpPtr = 0; 1696 vmType = VM_ALIASED_TO; 1697 } 1698 } else if (!JLI_StrCCmp(tmpPtr, "WARN")) { 1699 vmType = VM_WARN; 1700 } else if (!JLI_StrCCmp(tmpPtr, "IGNORE")) { 1701 vmType = VM_IGNORE; 1702 } else if (!JLI_StrCCmp(tmpPtr, "ERROR")) { 1703 vmType = VM_ERROR; 1704 } else if (!JLI_StrCCmp(tmpPtr, "IF_SERVER_CLASS")) { 1705 tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace); 1706 if (*tmpPtr != 0) { 1707 tmpPtr += JLI_StrSpn(tmpPtr, whiteSpace); 1708 } 1709 if (*tmpPtr == 0) { 1710 JLI_ReportErrorMessage(CFG_WARN4, lineno, jvmCfgName); 1711 } else { 1712 /* Null terminate server class VM name */ 1713 serverClassVMName = tmpPtr; 1714 tmpPtr += JLI_StrCSpn(tmpPtr, whiteSpace); 1715 *tmpPtr = 0; 1716 vmType = VM_IF_SERVER_CLASS; 1717 } 1718 } else { 1719 JLI_ReportErrorMessage(CFG_WARN5, lineno, &jvmCfgName[0]); 1720 vmType = VM_KNOWN; 1721 } 1722 } 1723 } 1724 1725 JLI_TraceLauncher("jvm.cfg[%d] = ->%s<-\n", cnt, line); 1726 if (vmType != VM_UNKNOWN) { 1727 knownVMs[cnt].name = JLI_StringDup(line); 1728 knownVMs[cnt].flag = vmType; 1729 switch (vmType) { 1730 default: 1731 break; 1732 case VM_ALIASED_TO: 1733 knownVMs[cnt].alias = JLI_StringDup(altVMName); 1734 JLI_TraceLauncher(" name: %s vmType: %s alias: %s\n", 1735 knownVMs[cnt].name, "VM_ALIASED_TO", knownVMs[cnt].alias); 1736 break; 1737 case VM_IF_SERVER_CLASS: 1738 knownVMs[cnt].server_class = JLI_StringDup(serverClassVMName); 1739 JLI_TraceLauncher(" name: %s vmType: %s server_class: %s\n", 1740 knownVMs[cnt].name, "VM_IF_SERVER_CLASS", knownVMs[cnt].server_class); 1741 break; 1742 } 1743 cnt++; 1744 } 1745 } 1746 fclose(jvmCfg); 1747 knownVMsCount = cnt; 1748 1749 if (JLI_IsTraceLauncher()) { 1750 end = CounterGet(); 1751 printf("%ld micro seconds to parse jvm.cfg\n", 1752 (long)(jint)Counter2Micros(end-start)); 1753 } 1754 1755 return cnt; 1756 } 1757 1758 1759 static void 1760 GrowKnownVMs(int minimum) 1761 { 1762 struct vmdesc* newKnownVMs; 1763 int newMax; 1764 1765 newMax = (knownVMsLimit == 0 ? INIT_MAX_KNOWN_VMS : (2 * knownVMsLimit)); 1766 if (newMax <= minimum) { 1767 newMax = minimum; 1768 } 1769 newKnownVMs = (struct vmdesc*) JLI_MemAlloc(newMax * sizeof(struct vmdesc)); 1770 if (knownVMs != NULL) { 1771 memcpy(newKnownVMs, knownVMs, knownVMsLimit * sizeof(struct vmdesc)); 1772 } 1773 JLI_MemFree(knownVMs); 1774 knownVMs = newKnownVMs; 1775 knownVMsLimit = newMax; 1776 } 1777 1778 1779 /* Returns index of VM or -1 if not found */ 1780 static int 1781 KnownVMIndex(const char* name) 1782 { 1783 int i; 1784 if (JLI_StrCCmp(name, "-J") == 0) name += 2; 1785 for (i = 0; i < knownVMsCount; i++) { 1786 if (!JLI_StrCmp(name, knownVMs[i].name)) { 1787 return i; 1788 } 1789 } 1790 return -1; 1791 } 1792 1793 static void 1794 FreeKnownVMs() 1795 { 1796 int i; 1797 for (i = 0; i < knownVMsCount; i++) { 1798 JLI_MemFree(knownVMs[i].name); 1799 knownVMs[i].name = NULL; 1800 } 1801 JLI_MemFree(knownVMs); 1802 } 1803 1804 /* 1805 * Displays the splash screen according to the jar file name 1806 * and image file names stored in environment variables 1807 */ 1808 void 1809 ShowSplashScreen() 1810 { 1811 const char *jar_name = getenv(SPLASH_JAR_ENV_ENTRY); 1812 const char *file_name = getenv(SPLASH_FILE_ENV_ENTRY); 1813 int data_size; 1814 void *image_data; 1815 if (jar_name) { 1816 image_data = JLI_JarUnpackFile(jar_name, file_name, &data_size); 1817 if (image_data) { 1818 DoSplashInit(); 1819 DoSplashLoadMemory(image_data, data_size); 1820 JLI_MemFree(image_data); 1821 } 1822 } else if (file_name) { 1823 DoSplashInit(); 1824 DoSplashLoadFile(file_name); 1825 } else { 1826 return; 1827 } 1828 DoSplashSetFileJarName(file_name, jar_name); 1829 1830 /* 1831 * Done with all command line processing and potential re-execs so 1832 * clean up the environment. 1833 */ 1834 (void)UnsetEnv(ENV_ENTRY); 1835 (void)UnsetEnv(SPLASH_FILE_ENV_ENTRY); 1836 (void)UnsetEnv(SPLASH_JAR_ENV_ENTRY); 1837 1838 JLI_MemFree(splash_jar_entry); 1839 JLI_MemFree(splash_file_entry); 1840 1841 } 1842 1843 const char* 1844 GetDotVersion() 1845 { 1846 return _dVersion; 1847 } 1848 1849 const char* 1850 GetFullVersion() 1851 { 1852 return _fVersion; 1853 } 1854 1855 const char* 1856 GetProgramName() 1857 { 1858 return _program_name; 1859 } 1860 1861 const char* 1862 GetLauncherName() 1863 { 1864 return _launcher_name; 1865 } 1866 1867 jint 1868 GetErgoPolicy() 1869 { 1870 return _ergo_policy; 1871 } 1872 1873 jboolean 1874 IsJavaArgs() 1875 { 1876 return _is_java_args; 1877 } 1878 1879 static jboolean 1880 IsWildCardEnabled() 1881 { 1882 return _wc_enabled; 1883 } 1884 1885 int 1886 ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize, 1887 int argc, char **argv, 1888 int mode, char *what, int ret) 1889 { 1890 1891 /* 1892 * If user doesn't specify stack size, check if VM has a preference. 1893 * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will 1894 * return its default stack size through the init args structure. 1895 */ 1896 if (threadStackSize == 0) { 1897 struct JDK1_1InitArgs args1_1; 1898 memset((void*)&args1_1, 0, sizeof(args1_1)); 1899 args1_1.version = JNI_VERSION_1_1; 1900 ifn->GetDefaultJavaVMInitArgs(&args1_1); /* ignore return value */ 1901 if (args1_1.javaStackSize > 0) { 1902 threadStackSize = args1_1.javaStackSize; 1903 } 1904 } 1905 1906 { /* Create a new thread to create JVM and invoke main method */ 1907 JavaMainArgs args; 1908 int rslt; 1909 1910 args.argc = argc; 1911 args.argv = argv; 1912 args.mode = mode; 1913 args.what = what; 1914 args.ifn = *ifn; 1915 1916 rslt = ContinueInNewThread0(JavaMain, threadStackSize, (void*)&args); 1917 /* If the caller has deemed there is an error we 1918 * simply return that, otherwise we return the value of 1919 * the callee 1920 */ 1921 return (ret != 0) ? ret : rslt; 1922 } 1923 } 1924 1925 static void 1926 DumpState() 1927 { 1928 if (!JLI_IsTraceLauncher()) return ; 1929 printf("Launcher state:\n"); 1930 printf("\tdebug:%s\n", (JLI_IsTraceLauncher() == JNI_TRUE) ? "on" : "off"); 1931 printf("\tjavargs:%s\n", (_is_java_args == JNI_TRUE) ? "on" : "off"); 1932 printf("\tprogram name:%s\n", GetProgramName()); 1933 printf("\tlauncher name:%s\n", GetLauncherName()); 1934 printf("\tjavaw:%s\n", (IsJavaw() == JNI_TRUE) ? "on" : "off"); 1935 printf("\tfullversion:%s\n", GetFullVersion()); 1936 printf("\tdotversion:%s\n", GetDotVersion()); 1937 printf("\tergo_policy:"); 1938 switch(GetErgoPolicy()) { 1939 case NEVER_SERVER_CLASS: 1940 printf("NEVER_ACT_AS_A_SERVER_CLASS_MACHINE\n"); 1941 break; 1942 case ALWAYS_SERVER_CLASS: 1943 printf("ALWAYS_ACT_AS_A_SERVER_CLASS_MACHINE\n"); 1944 break; 1945 default: 1946 printf("DEFAULT_ERGONOMICS_POLICY\n"); 1947 } 1948 } 1949 1950 /* 1951 * Return JNI_TRUE for an option string that has no effect but should 1952 * _not_ be passed on to the vm; return JNI_FALSE otherwise. On 1953 * Solaris SPARC, this screening needs to be done if: 1954 * -d32 or -d64 is passed to a binary with an unmatched data model 1955 * (the exec in CreateExecutionEnvironment removes -d<n> options and points the 1956 * exec to the proper binary). In the case of when the data model and the 1957 * requested version is matched, an exec would not occur, and these options 1958 * were erroneously passed to the vm. 1959 */ 1960 jboolean 1961 RemovableOption(char * option) 1962 { 1963 /* 1964 * Unconditionally remove both -d32 and -d64 options since only 1965 * the last such options has an effect; e.g. 1966 * java -d32 -d64 -d32 -version 1967 * is equivalent to 1968 * java -d32 -version 1969 */ 1970 1971 if( (JLI_StrCCmp(option, "-d32") == 0 ) || 1972 (JLI_StrCCmp(option, "-d64") == 0 ) ) 1973 return JNI_TRUE; 1974 else 1975 return JNI_FALSE; 1976 } 1977 1978 /* 1979 * A utility procedure to always print to stderr 1980 */ 1981 void 1982 JLI_ReportMessage(const char* fmt, ...) 1983 { 1984 va_list vl; 1985 va_start(vl, fmt); 1986 vfprintf(stderr, fmt, vl); 1987 fprintf(stderr, "\n"); 1988 va_end(vl); 1989 }