< prev index next >

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

Print this page
rev 56236 : 8241638: launcher time metrics always report 1 on Linux when _JAVA_LAUNCHER_DEBUG set
Reviewed-by: alanb, dholmes
Contributed-by: linzang@tencent.com


 221  */
 222 JNIEXPORT int JNICALL
 223 JLI_Launch(int argc, char ** argv,              /* main argc, argv */
 224         int jargc, const char** jargv,          /* java args */
 225         int appclassc, const char** appclassv,  /* app classpath */
 226         const char* fullversion,                /* full version defined */
 227         const char* dotversion,                 /* UNUSED dot version defined */
 228         const char* pname,                      /* program name */
 229         const char* lname,                      /* launcher name */
 230         jboolean javaargs,                      /* JAVA_ARGS */
 231         jboolean cpwildcard,                    /* classpath wildcard*/
 232         jboolean javaw,                         /* windows-only javaw */
 233         jint ergo                               /* unused */
 234 )
 235 {
 236     int mode = LM_UNKNOWN;
 237     char *what = NULL;
 238     char *main_class = NULL;
 239     int ret;
 240     InvocationFunctions ifn;
 241     jlong start, end;
 242     char jvmpath[MAXPATHLEN];
 243     char jrepath[MAXPATHLEN];
 244     char jvmcfg[MAXPATHLEN];
 245 
 246     _fVersion = fullversion;
 247     _launcher_name = lname;
 248     _program_name = pname;
 249     _is_java_args = javaargs;
 250     _wc_enabled = cpwildcard;
 251 
 252     InitLauncher(javaw);
 253     DumpState();
 254     if (JLI_IsTraceLauncher()) {
 255         int i;
 256         printf("Java args:\n");
 257         for (i = 0; i < jargc ; i++) {
 258             printf("jargv[%d] = %s\n", i, jargv[i]);
 259         }
 260         printf("Command line args:\n");
 261         for (i = 0; i < argc ; i++) {


 391     } while (JNI_FALSE)
 392 
 393 
 394 int
 395 JavaMain(void* _args)
 396 {
 397     JavaMainArgs *args = (JavaMainArgs *)_args;
 398     int argc = args->argc;
 399     char **argv = args->argv;
 400     int mode = args->mode;
 401     char *what = args->what;
 402     InvocationFunctions ifn = args->ifn;
 403 
 404     JavaVM *vm = 0;
 405     JNIEnv *env = 0;
 406     jclass mainClass = NULL;
 407     jclass appClass = NULL; // actual application class being launched
 408     jmethodID mainID;
 409     jobjectArray mainArgs;
 410     int ret = 0;
 411     jlong start, end;
 412 
 413     RegisterThread();
 414 
 415     /* Initialize the virtual machine */
 416     start = CounterGet();
 417     if (!InitializeJVM(&vm, &env, &ifn)) {
 418         JLI_ReportErrorMessage(JVM_ERROR1);
 419         exit(1);
 420     }
 421 
 422     if (showSettings != NULL) {
 423         ShowSettings(env, showSettings);
 424         CHECK_EXCEPTION_LEAVE(1);
 425     }
 426 
 427     // show resolved modules and continue
 428     if (showResolvedModules) {
 429         ShowResolvedModules(env);
 430         CHECK_EXCEPTION_LEAVE(1);
 431     }


1602     CHECK_EXCEPTION_RETURN_VALUE(0);
1603     for (i = 0; i < strc; i++) {
1604         jstring str = NewPlatformString(env, *strv++);
1605         NULL_CHECK0(str);
1606         (*env)->SetObjectArrayElement(env, ary, i, str);
1607         (*env)->DeleteLocalRef(env, str);
1608     }
1609     return ary;
1610 }
1611 
1612 /*
1613  * Loads a class and verifies that the main class is present and it is ok to
1614  * call it for more details refer to the java implementation.
1615  */
1616 static jclass
1617 LoadMainClass(JNIEnv *env, int mode, char *name)
1618 {
1619     jmethodID mid;
1620     jstring str;
1621     jobject result;
1622     jlong start, end;
1623     jclass cls = GetLauncherHelperClass(env);
1624     NULL_CHECK0(cls);
1625     if (JLI_IsTraceLauncher()) {
1626         start = CounterGet();
1627     }
1628     NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
1629                 "checkAndLoadMain",
1630                 "(ZILjava/lang/String;)Ljava/lang/Class;"));
1631 
1632     NULL_CHECK0(str = NewPlatformString(env, name));
1633     NULL_CHECK0(result = (*env)->CallStaticObjectMethod(env, cls, mid,
1634                                                         USE_STDERR, mode, str));
1635 
1636     if (JLI_IsTraceLauncher()) {
1637         end   = CounterGet();
1638         printf("%ld micro seconds to load main class\n",
1639                (long)(jint)Counter2Micros(end-start));
1640         printf("----%s----\n", JLDEBUG_ENV_ENTRY);
1641     }
1642 


2065  *   otherwise the identifier of the first flag is used as the name of the JVM.
2066  * If no flag is given on the command line, the first vmLine of the jvm.cfg
2067  * file determines the name of the JVM.
2068  * PredicateLines are only interpreted on first vmLine of a jvm.cfg file,
2069  * since they only make sense if someone hasn't specified the name of the
2070  * JVM on the command line.
2071  *
2072  * The intent of the jvm.cfg file is to allow several JVM libraries to
2073  * be installed in different subdirectories of a single JRE installation,
2074  * for space-savings and convenience in testing.
2075  * The intent is explicitly not to provide a full aliasing or predicate
2076  * mechanism.
2077  */
2078 jint
2079 ReadKnownVMs(const char *jvmCfgName, jboolean speculative)
2080 {
2081     FILE *jvmCfg;
2082     char line[MAXPATHLEN+20];
2083     int cnt = 0;
2084     int lineno = 0;
2085     jlong start, end;
2086     int vmType;
2087     char *tmpPtr;
2088     char *altVMName = NULL;
2089     char *serverClassVMName = NULL;
2090     static char *whiteSpace = " \t";
2091     if (JLI_IsTraceLauncher()) {
2092         start = CounterGet();
2093     }
2094 
2095     jvmCfg = fopen(jvmCfgName, "r");
2096     if (jvmCfg == NULL) {
2097       if (!speculative) {
2098         JLI_ReportErrorMessage(CFG_ERROR6, jvmCfgName);
2099         exit(1);
2100       } else {
2101         return -1;
2102       }
2103     }
2104     while (fgets(line, sizeof(line), jvmCfg) != NULL) {
2105         vmType = VM_UNKNOWN;




 221  */
 222 JNIEXPORT int JNICALL
 223 JLI_Launch(int argc, char ** argv,              /* main argc, argv */
 224         int jargc, const char** jargv,          /* java args */
 225         int appclassc, const char** appclassv,  /* app classpath */
 226         const char* fullversion,                /* full version defined */
 227         const char* dotversion,                 /* UNUSED dot version defined */
 228         const char* pname,                      /* program name */
 229         const char* lname,                      /* launcher name */
 230         jboolean javaargs,                      /* JAVA_ARGS */
 231         jboolean cpwildcard,                    /* classpath wildcard*/
 232         jboolean javaw,                         /* windows-only javaw */
 233         jint ergo                               /* unused */
 234 )
 235 {
 236     int mode = LM_UNKNOWN;
 237     char *what = NULL;
 238     char *main_class = NULL;
 239     int ret;
 240     InvocationFunctions ifn;
 241     jlong start = 0, end = 0;
 242     char jvmpath[MAXPATHLEN];
 243     char jrepath[MAXPATHLEN];
 244     char jvmcfg[MAXPATHLEN];
 245 
 246     _fVersion = fullversion;
 247     _launcher_name = lname;
 248     _program_name = pname;
 249     _is_java_args = javaargs;
 250     _wc_enabled = cpwildcard;
 251 
 252     InitLauncher(javaw);
 253     DumpState();
 254     if (JLI_IsTraceLauncher()) {
 255         int i;
 256         printf("Java args:\n");
 257         for (i = 0; i < jargc ; i++) {
 258             printf("jargv[%d] = %s\n", i, jargv[i]);
 259         }
 260         printf("Command line args:\n");
 261         for (i = 0; i < argc ; i++) {


 391     } while (JNI_FALSE)
 392 
 393 
 394 int
 395 JavaMain(void* _args)
 396 {
 397     JavaMainArgs *args = (JavaMainArgs *)_args;
 398     int argc = args->argc;
 399     char **argv = args->argv;
 400     int mode = args->mode;
 401     char *what = args->what;
 402     InvocationFunctions ifn = args->ifn;
 403 
 404     JavaVM *vm = 0;
 405     JNIEnv *env = 0;
 406     jclass mainClass = NULL;
 407     jclass appClass = NULL; // actual application class being launched
 408     jmethodID mainID;
 409     jobjectArray mainArgs;
 410     int ret = 0;
 411     jlong start = 0, end = 0;
 412 
 413     RegisterThread();
 414 
 415     /* Initialize the virtual machine */
 416     start = CounterGet();
 417     if (!InitializeJVM(&vm, &env, &ifn)) {
 418         JLI_ReportErrorMessage(JVM_ERROR1);
 419         exit(1);
 420     }
 421 
 422     if (showSettings != NULL) {
 423         ShowSettings(env, showSettings);
 424         CHECK_EXCEPTION_LEAVE(1);
 425     }
 426 
 427     // show resolved modules and continue
 428     if (showResolvedModules) {
 429         ShowResolvedModules(env);
 430         CHECK_EXCEPTION_LEAVE(1);
 431     }


1602     CHECK_EXCEPTION_RETURN_VALUE(0);
1603     for (i = 0; i < strc; i++) {
1604         jstring str = NewPlatformString(env, *strv++);
1605         NULL_CHECK0(str);
1606         (*env)->SetObjectArrayElement(env, ary, i, str);
1607         (*env)->DeleteLocalRef(env, str);
1608     }
1609     return ary;
1610 }
1611 
1612 /*
1613  * Loads a class and verifies that the main class is present and it is ok to
1614  * call it for more details refer to the java implementation.
1615  */
1616 static jclass
1617 LoadMainClass(JNIEnv *env, int mode, char *name)
1618 {
1619     jmethodID mid;
1620     jstring str;
1621     jobject result;
1622     jlong start = 0, end = 0;
1623     jclass cls = GetLauncherHelperClass(env);
1624     NULL_CHECK0(cls);
1625     if (JLI_IsTraceLauncher()) {
1626         start = CounterGet();
1627     }
1628     NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
1629                 "checkAndLoadMain",
1630                 "(ZILjava/lang/String;)Ljava/lang/Class;"));
1631 
1632     NULL_CHECK0(str = NewPlatformString(env, name));
1633     NULL_CHECK0(result = (*env)->CallStaticObjectMethod(env, cls, mid,
1634                                                         USE_STDERR, mode, str));
1635 
1636     if (JLI_IsTraceLauncher()) {
1637         end = CounterGet();
1638         printf("%ld micro seconds to load main class\n",
1639                (long)(jint)Counter2Micros(end-start));
1640         printf("----%s----\n", JLDEBUG_ENV_ENTRY);
1641     }
1642 


2065  *   otherwise the identifier of the first flag is used as the name of the JVM.
2066  * If no flag is given on the command line, the first vmLine of the jvm.cfg
2067  * file determines the name of the JVM.
2068  * PredicateLines are only interpreted on first vmLine of a jvm.cfg file,
2069  * since they only make sense if someone hasn't specified the name of the
2070  * JVM on the command line.
2071  *
2072  * The intent of the jvm.cfg file is to allow several JVM libraries to
2073  * be installed in different subdirectories of a single JRE installation,
2074  * for space-savings and convenience in testing.
2075  * The intent is explicitly not to provide a full aliasing or predicate
2076  * mechanism.
2077  */
2078 jint
2079 ReadKnownVMs(const char *jvmCfgName, jboolean speculative)
2080 {
2081     FILE *jvmCfg;
2082     char line[MAXPATHLEN+20];
2083     int cnt = 0;
2084     int lineno = 0;
2085     jlong start = 0, end = 0;
2086     int vmType;
2087     char *tmpPtr;
2088     char *altVMName = NULL;
2089     char *serverClassVMName = NULL;
2090     static char *whiteSpace = " \t";
2091     if (JLI_IsTraceLauncher()) {
2092         start = CounterGet();
2093     }
2094 
2095     jvmCfg = fopen(jvmCfgName, "r");
2096     if (jvmCfg == NULL) {
2097       if (!speculative) {
2098         JLI_ReportErrorMessage(CFG_ERROR6, jvmCfgName);
2099         exit(1);
2100       } else {
2101         return -1;
2102       }
2103     }
2104     while (fgets(line, sizeof(line), jvmCfg) != NULL) {
2105         vmType = VM_UNKNOWN;


< prev index next >