Top


定義場所(file name)

jdk/src/share/bin/java.c

説明(description)

/*
 * Entry point.
 */

名前(function name)

int
JLI_Launch(int argc, char ** argv,              /* main argc, argc */
        int jargc, const char** jargv,          /* java args */
        int appclassc, const char** appclassv,  /* app classpath */
        const char* fullversion,                /* full version defined */
        const char* dotversion,                 /* dot version defined */
        const char* pname,                      /* program name */
        const char* lname,                      /* launcher name */
        jboolean javaargs,                      /* JAVA_ARGS */
        jboolean cpwildcard,                    /* classpath wildcard*/
        jboolean javaw,                         /* windows-only javaw */
        jint ergo                               /* ergonomics class policy */
)
{

本体部(body)

  {- -------------------------------------------
  (1) (変数宣言など)
      ---------------------------------------- -}

        int mode = LM_UNKNOWN;
        char *what = NULL;
        char *cpath = 0;
        char *main_class = NULL;
        int ret;
        InvocationFunctions ifn;
        jlong start, end;
        char jvmpath[MAXPATHLEN];
        char jrepath[MAXPATHLEN];

  {- -------------------------------------------
  (1) (フィールドの初期化)
      ---------------------------------------- -}

        _fVersion = fullversion;
        _dVersion = dotversion;
        _launcher_name = lname;
        _program_name = pname;
        _is_java_args = javaargs;
        _wc_enabled = cpwildcard;
        _ergo_policy = ergo;

  {- -------------------------------------------
  (1) 
      ---------------------------------------- -}

        InitLauncher(javaw);
        DumpState();

  {- -------------------------------------------
  (1) SelectVersion() を呼んで...

      (なお, バージョンがずれていた場合は SelectVersion() 中で呼ばれる ExecJRE() によって適切なバージョンに execve しなおす. 
      このため, その場合には決してリターンしてこない)
      ---------------------------------------- -}

        /*
         * Make sure the specified version of the JRE is running.
         *
         * There are three things to note about the SelectVersion() routine:
         *  1) If the version running isn't correct, this routine doesn't
         *     return (either the correct version has been exec'd or an error
         *     was issued).
         *  2) Argc and Argv in this scope are *not* altered by this routine.
         *     It is the responsibility of subsequent code to ignore the
         *     arguments handled by this routine.
         *  3) As a side-effect, the variable "main_class" is guaranteed to
         *     be set (if it should ever be set).  This isn't exactly the
         *     poster child for structured programming, but it is a small
         *     price to pay for not processing a jar file operand twice.
         *     (Note: This side effect has been disabled.  See comment on
         *     bugid 5030265 below.)
         */
        SelectVersion(argc, argv, &main_class);

  {- -------------------------------------------
  (1) (トレース出力)

      (なお sun.java.launcher.diag とは ...#TODO)
      ---------------------------------------- -}

        if (JLI_IsTraceLauncher()) {
            int i;
            printf("Command line args:\n");
            for (i = 0; i < argc ; i++) {
                printf("argv[%d] = %s\n", i, argv[i]);
            }
            AddOption("-Dsun.java.launcher.diag=true", NULL);
        }

  {- -------------------------------------------
  (1) 
      ---------------------------------------- -}

        CreateExecutionEnvironment(&argc, &argv,
                                   jrepath, sizeof(jrepath),
                                   jvmpath, sizeof(jvmpath));

        ifn.CreateJavaVM = 0;
        ifn.GetDefaultJavaVMInitArgs = 0;

  {- -------------------------------------------
  (1) (トレース出力用の処理)
      ---------------------------------------- -}

        if (JLI_IsTraceLauncher()) {
            start = CounterGet();
        }

  {- -------------------------------------------
  (1) LoadJavaVM() を呼び出して, libjvm をダイナミックロードする.

      (失敗したらここでリターン)
      ---------------------------------------- -}

        if (!LoadJavaVM(jvmpath, &ifn)) {
            return(6);
        }

  {- -------------------------------------------
  (1) (トレース出力)
      ---------------------------------------- -}

        if (JLI_IsTraceLauncher()) {
            end   = CounterGet();
        }

        JLI_TraceLauncher("%ld micro seconds to LoadJavaVM\n",
                 (long)(jint)Counter2Micros(end-start));

  {- -------------------------------------------
  (1) 
      ---------------------------------------- -}

        ++argv;
        --argc;

        if (IsJavaArgs()) {
            /* Preprocess wrapper arguments */
            TranslateApplicationArgs(jargc, jargv, &argc, &argv);
            if (!AddApplicationOptions(appclassc, appclassv)) {
                return(1);
            }
        } else {
            /* Set default CLASSPATH */
            cpath = getenv("CLASSPATH");
            if (cpath == NULL) {
                cpath = ".";
            }
            SetClassPath(cpath);
        }

  {- -------------------------------------------
  (1) ParseArguments() を呼び出して, いくつかのオプションはこの時点で処理してしまう (e.g. -classpath, -version, etc).
      (あるいは, -verify のような簡略型のオプションを -Xverify:all のような形に正規化する作業も行っている模様)

      それ以外のオプションは JavaVMInitArgs で JVM に渡される(??)
      ---------------------------------------- -}

        /* Parse command line options; if the return value of
         * ParseArguments is false, the program should exit.
         */
        if (!ParseArguments(&argc, &argv, &mode, &what, &ret, jrepath))
        {
            return(ret);
        }

  {- -------------------------------------------
  (1) 
      ---------------------------------------- -}

        /* Override class path if -jar flag was specified */
        if (mode == LM_JAR) {
            SetClassPath(what);     /* Override class path */
        }

        /* set the -Dsun.java.command pseudo property */
        SetJavaCommandLineProp(what, argc, argv);

        /* Set the -Dsun.java.launcher pseudo property */
        SetJavaLauncherProp();

        /* set the -Dsun.java.launcher.* platform properties */
        SetJavaLauncherPlatformProps();

        /* Show the splash screen if needed */
        ShowSplashScreen();

  {- -------------------------------------------
  (1) ContinueInNewThread() で新しいスレッドを立ち上げる. 
      エントリポイントは JavaMain(). 
      ---------------------------------------- -}

        return ContinueInNewThread(&ifn, argc, argv, mode, what, ret);

    }

This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.