< prev index next >

src/java.base/share/native/libjli/java.c

Print this page




 418 
 419     if (JLI_IsTraceLauncher()) {
 420         end = CounterGet();
 421         JLI_TraceLauncher("%ld micro seconds to InitializeJVM\n",
 422                (long)(jint)Counter2Micros(end-start));
 423     }
 424 
 425     /* At this stage, argc/argv have the application's arguments */
 426     if (JLI_IsTraceLauncher()){
 427         int i;
 428         printf("%s is '%s'\n", launchModeNames[mode], what);
 429         printf("App's argc is %d\n", argc);
 430         for (i=0; i < argc; i++) {
 431             printf("    argv[%2d] = '%s'\n", i, argv[i]);
 432         }
 433     }
 434 
 435     ret = 1;
 436 
 437     /*
 438      * Get the application's main class.

 439      *
 440      * See bugid 5030265.  The Main-Class name has already been parsed
 441      * from the manifest, but not parsed properly for UTF-8 support.
 442      * Hence the code here ignores the value previously extracted and
 443      * uses the pre-existing code to reextract the value.  This is
 444      * possibly an end of release cycle expedient.  However, it has
 445      * also been discovered that passing some character sets through
 446      * the environment has "strange" behavior on some variants of
 447      * Windows.  Hence, maybe the manifest parsing code local to the
 448      * launcher should never be enhanced.
 449      *
 450      * Hence, future work should either:
 451      *     1)   Correct the local parsing code and verify that the
 452      *          Main-Class attribute gets properly passed through
 453      *          all environments,
 454      *     2)   Remove the vestages of maintaining main_class through
 455      *          the environment (and remove these comments).
 456      *
 457      * This method also correctly handles launching existing JavaFX
 458      * applications that may or may not have a Main-Class manifest entry.
 459      */
 460     mainClass = LoadMainClass(env, mode, what);
 461     CHECK_EXCEPTION_NULL_LEAVE(mainClass);
 462     /*
 463      * In some cases when launching an application that needs a helper, e.g., a
 464      * JavaFX application with no main method, the mainClass will not be the
 465      * applications own main class but rather a helper class. To keep things
 466      * consistent in the UI we need to track and report the application main class.
 467      */
 468     appClass = GetApplicationClass(env);
 469     NULL_CHECK_RETURN_VALUE(appClass, -1);










 470     /*
 471      * PostJVMInit uses the class name as the application name for GUI purposes,
 472      * for example, on OSX this sets the application name in the menu bar for
 473      * both SWT and JavaFX. So we'll pass the actual application class here
 474      * instead of mainClass as that may be a launcher or helper class instead
 475      * of the application class.
 476      */
 477     PostJVMInit(env, appClass, vm);
 478     CHECK_EXCEPTION_LEAVE(1);

 479     /*
 480      * The LoadMainClass not only loads the main class, it will also ensure
 481      * that the main method's signature is correct, therefore further checking
 482      * is not required. The main method is invoked here so that extraneous java
 483      * stacks are not in the application stack trace.
 484      */
 485     mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
 486                                        "([Ljava/lang/String;)V");
 487     CHECK_EXCEPTION_NULL_LEAVE(mainID);
 488 
 489     /* Build platform specific argument array */
 490     mainArgs = CreateApplicationArgs(env, argv, argc);
 491     CHECK_EXCEPTION_NULL_LEAVE(mainArgs);
 492 
 493     if (dryRun) {
 494         ret = 0;
 495     } else {
 496         /* Invoke main method. */
 497         (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs);
 498 
 499         /*
 500          * The launcher's exit code (in the absence of calls to
 501          * System.exit) will be non-zero if main threw an exception.
 502          */
 503         ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1;
 504     }
 505     LEAVE();
 506 }
 507 
 508 /*
 509  * Test if the given option name has a whitespace separated argument.
 510  */
 511 jboolean
 512 IsWhiteSpaceOptionArgument(const char* name) {
 513     return JLI_StrCmp(name, "-classpath") == 0 ||
 514            JLI_StrCmp(name, "-cp") == 0 ||
 515            JLI_StrCmp(name, "-modulepath") == 0 ||
 516            JLI_StrCmp(name, "-mp") == 0 ||
 517            JLI_StrCmp(name, "-upgrademodulepath") == 0 ||
 518            JLI_StrCmp(name, "-addmods") == 0 ||
 519            JLI_StrCmp(name, "-limitmods") == 0;
 520 }
 521 
 522 /*
 523  * Checks the command line options to find which JVM type was
 524  * specified.  If no command line option was given for the JVM type,




 418 
 419     if (JLI_IsTraceLauncher()) {
 420         end = CounterGet();
 421         JLI_TraceLauncher("%ld micro seconds to InitializeJVM\n",
 422                (long)(jint)Counter2Micros(end-start));
 423     }
 424 
 425     /* At this stage, argc/argv have the application's arguments */
 426     if (JLI_IsTraceLauncher()){
 427         int i;
 428         printf("%s is '%s'\n", launchModeNames[mode], what);
 429         printf("App's argc is %d\n", argc);
 430         for (i=0; i < argc; i++) {
 431             printf("    argv[%2d] = '%s'\n", i, argv[i]);
 432         }
 433     }
 434 
 435     ret = 1;
 436 
 437     /*
 438      * Get the application's main class. It also checks if the main
 439      * method exists.
 440      *
 441      * See bugid 5030265.  The Main-Class name has already been parsed
 442      * from the manifest, but not parsed properly for UTF-8 support.
 443      * Hence the code here ignores the value previously extracted and
 444      * uses the pre-existing code to reextract the value.  This is
 445      * possibly an end of release cycle expedient.  However, it has
 446      * also been discovered that passing some character sets through
 447      * the environment has "strange" behavior on some variants of
 448      * Windows.  Hence, maybe the manifest parsing code local to the
 449      * launcher should never be enhanced.
 450      *
 451      * Hence, future work should either:
 452      *     1)   Correct the local parsing code and verify that the
 453      *          Main-Class attribute gets properly passed through
 454      *          all environments,
 455      *     2)   Remove the vestages of maintaining main_class through
 456      *          the environment (and remove these comments).
 457      *
 458      * This method also correctly handles launching existing JavaFX
 459      * applications that may or may not have a Main-Class manifest entry.
 460      */
 461     mainClass = LoadMainClass(env, mode, what);
 462     CHECK_EXCEPTION_NULL_LEAVE(mainClass);
 463     /*
 464      * In some cases when launching an application that needs a helper, e.g., a
 465      * JavaFX application with no main method, the mainClass will not be the
 466      * applications own main class but rather a helper class. To keep things
 467      * consistent in the UI we need to track and report the application main class.
 468      */
 469     appClass = GetApplicationClass(env);
 470     NULL_CHECK_RETURN_VALUE(appClass, -1);
 471 
 472     /* Build platform specific argument array */
 473     mainArgs = CreateApplicationArgs(env, argv, argc);
 474     CHECK_EXCEPTION_NULL_LEAVE(mainArgs);
 475 
 476     if (dryRun) {
 477         ret = 0;
 478         LEAVE();
 479     }
 480 
 481     /*
 482      * PostJVMInit uses the class name as the application name for GUI purposes,
 483      * for example, on OSX this sets the application name in the menu bar for
 484      * both SWT and JavaFX. So we'll pass the actual application class here
 485      * instead of mainClass as that may be a launcher or helper class instead
 486      * of the application class.
 487      */
 488     PostJVMInit(env, appClass, vm);
 489     CHECK_EXCEPTION_LEAVE(1);
 490 
 491     /*
 492      * The LoadMainClass not only loads the main class, it will also ensure
 493      * that the main method's signature is correct, therefore further checking
 494      * is not required. The main method is invoked here so that extraneous java
 495      * stacks are not in the application stack trace.
 496      */
 497     mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
 498                                        "([Ljava/lang/String;)V");
 499     CHECK_EXCEPTION_NULL_LEAVE(mainID);
 500 







 501     /* Invoke main method. */
 502     (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs);
 503 
 504     /*
 505      * The launcher's exit code (in the absence of calls to
 506      * System.exit) will be non-zero if main threw an exception.
 507      */
 508     ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1;
 509 
 510     LEAVE();
 511 }
 512 
 513 /*
 514  * Test if the given option name has a whitespace separated argument.
 515  */
 516 jboolean
 517 IsWhiteSpaceOptionArgument(const char* name) {
 518     return JLI_StrCmp(name, "-classpath") == 0 ||
 519            JLI_StrCmp(name, "-cp") == 0 ||
 520            JLI_StrCmp(name, "-modulepath") == 0 ||
 521            JLI_StrCmp(name, "-mp") == 0 ||
 522            JLI_StrCmp(name, "-upgrademodulepath") == 0 ||
 523            JLI_StrCmp(name, "-addmods") == 0 ||
 524            JLI_StrCmp(name, "-limitmods") == 0;
 525 }
 526 
 527 /*
 528  * Checks the command line options to find which JVM type was
 529  * specified.  If no command line option was given for the JVM type,


< prev index next >