< prev index next >

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

Print this page




 187             return JNI_FALSE; \
 188         } \
 189     } while (JNI_FALSE)
 190 
 191 #define ARG_CHECK(AC_arg_count, AC_failure_message, AC_questionable_arg) \
 192     do { \
 193         if (AC_arg_count < 1) { \
 194             JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \
 195             printUsage = JNI_TRUE; \
 196             *pret = 1; \
 197             return JNI_TRUE; \
 198         } \
 199     } while (JNI_FALSE)
 200 
 201 /*
 202  * Running Java code in primordial thread caused many problems. We will
 203  * create a new thread to invoke JVM. See 6316197 for more information.
 204  */
 205 static jlong threadStackSize    = 0;  /* stack size of the new thread */
 206 static jlong maxHeapSize        = 0;  /* max heap size */
 207 static jlong initialHeapSize    = 0;  /* initial heap size */
 208 
 209 /*
 210  * A minimum initial-thread stack size suitable for most platforms.
 211  * This is the minimum amount of stack needed to load the JVM such
 212  * that it can reject a too small -Xss value. If this is too small
 213  * JVM initialization would cause a StackOverflowError.
 214   */
 215 #ifndef STACK_SIZE_MINIMUM
 216 #define STACK_SIZE_MINIMUM (64 * KB)
 217 #endif
 218 
 219 /*
 220  * Entry point.
 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 )


 920     /*
 921      * Expand options array if needed to accommodate at least one more
 922      * VM option.
 923      */
 924     if (numOptions >= maxOptions) {
 925         if (options == 0) {
 926             maxOptions = 4;
 927             options = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
 928         } else {
 929             JavaVMOption *tmp;
 930             maxOptions *= 2;
 931             tmp = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
 932             memcpy(tmp, options, numOptions * sizeof(JavaVMOption));
 933             JLI_MemFree(options);
 934             options = tmp;
 935         }
 936     }
 937     options[numOptions].optionString = str;
 938     options[numOptions++].extraInfo = info;
 939 
 940     /*
 941      * -Xss is used both by the JVM and here to establish the stack size of the thread
 942      * created to launch the JVM. In the latter case we need to ensure we don't go
 943      * below the minimum stack size allowed. If -Xss is zero that tells the JVM to use
 944      * 'default' sizes (either from JVM or system configuration, e.g. 'ulimit -s' on linux),
 945      * and is not itself a small stack size that will be rejected. So we ignore -Xss0 here.
 946      */
 947     if (JLI_StrCCmp(str, "-Xss") == 0) {
 948         jlong tmp;
 949         if (parse_size(str + 4, &tmp)) {
 950             threadStackSize = tmp;
 951             if (threadStackSize > 0 && threadStackSize < (jlong)STACK_SIZE_MINIMUM) {





 952                 threadStackSize = STACK_SIZE_MINIMUM;
 953             }
 954         }
 955     }
 956 
 957     if (JLI_StrCCmp(str, "-Xmx") == 0) {
 958         jlong tmp;
 959         if (parse_size(str + 4, &tmp)) {
 960             maxHeapSize = tmp;
 961         }
 962     }
 963 
 964     if (JLI_StrCCmp(str, "-Xms") == 0) {
 965         jlong tmp;
 966         if (parse_size(str + 4, &tmp)) {
 967            initialHeapSize = tmp;
 968         }
 969     }
 970 }
 971 


2310     return _launcher_name;
2311 }
2312 
2313 jboolean
2314 IsJavaArgs()
2315 {
2316     return _is_java_args;
2317 }
2318 
2319 static jboolean
2320 IsWildCardEnabled()
2321 {
2322     return _wc_enabled;
2323 }
2324 
2325 int
2326 ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
2327                     int argc, char **argv,
2328                     int mode, char *what, int ret)
2329 {






2330     if (threadStackSize == 0) {
2331         /*
2332          * If the user hasn't specified a non-zero stack size ask the JVM for its default.
2333          * A returned 0 means 'use the system default' for a platform, e.g., Windows.
2334          * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will
2335          * return its default stack size through the init args structure.
2336          */
2337         struct JDK1_1InitArgs args1_1;
2338         memset((void*)&args1_1, 0, sizeof(args1_1));
2339         args1_1.version = JNI_VERSION_1_1;
2340         ifn->GetDefaultJavaVMInitArgs(&args1_1);  /* ignore return value */
2341         if (args1_1.javaStackSize > 0) {
2342             threadStackSize = args1_1.javaStackSize;
2343         }
2344     }
2345 
2346     { /* Create a new thread to create JVM and invoke main method */
2347         JavaMainArgs args;
2348         int rslt;
2349 
2350         args.argc = argc;
2351         args.argv = argv;
2352         args.mode = mode;
2353         args.what = what;
2354         args.ifn = *ifn;
2355 
2356         rslt = CallJavaMainInNewThread(threadStackSize, (void*)&args);
2357         /* If the caller has deemed there is an error we
2358          * simply return that, otherwise we return the value of
2359          * the callee
2360          */
2361         return (ret != 0) ? ret : rslt;
2362     }
2363 }
2364 
2365 static void
2366 DumpState()
2367 {
2368     if (!JLI_IsTraceLauncher()) return ;
2369     printf("Launcher state:\n");
2370     printf("\tFirst application arg index: %d\n", JLI_GetAppArgIndex());
2371     printf("\tdebug:%s\n", (JLI_IsTraceLauncher() == JNI_TRUE) ? "on" : "off");
2372     printf("\tjavargs:%s\n", (_is_java_args == JNI_TRUE) ? "on" : "off");
2373     printf("\tprogram name:%s\n", GetProgramName());
2374     printf("\tlauncher name:%s\n", GetLauncherName());
2375     printf("\tjavaw:%s\n", (IsJavaw() == JNI_TRUE) ? "on" : "off");
2376     printf("\tfullversion:%s\n", GetFullVersion());
2377 }
2378 
2379 /*
2380  * A utility procedure to always print to stderr
2381  */




 187             return JNI_FALSE; \
 188         } \
 189     } while (JNI_FALSE)
 190 
 191 #define ARG_CHECK(AC_arg_count, AC_failure_message, AC_questionable_arg) \
 192     do { \
 193         if (AC_arg_count < 1) { \
 194             JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \
 195             printUsage = JNI_TRUE; \
 196             *pret = 1; \
 197             return JNI_TRUE; \
 198         } \
 199     } while (JNI_FALSE)
 200 
 201 /*
 202  * Running Java code in primordial thread caused many problems. We will
 203  * create a new thread to invoke JVM. See 6316197 for more information.
 204  */
 205 static jlong threadStackSize    = 0;  /* stack size of the new thread */
 206 static jlong maxHeapSize        = 0;  /* max heap size */
 207 static jlong initialHeapSize    = 0;  /* inital heap size */
 208 
 209 /*
 210  * A minimum -Xss stack size suitable for all platforms.
 211  */



 212 #ifndef STACK_SIZE_MINIMUM
 213 #define STACK_SIZE_MINIMUM (64 * KB)
 214 #endif
 215 
 216 /*
 217  * Entry point.
 218  */
 219 JNIEXPORT int JNICALL
 220 JLI_Launch(int argc, char ** argv,              /* main argc, argv */
 221         int jargc, const char** jargv,          /* java args */
 222         int appclassc, const char** appclassv,  /* app classpath */
 223         const char* fullversion,                /* full version defined */
 224         const char* dotversion,                 /* UNUSED dot version defined */
 225         const char* pname,                      /* program name */
 226         const char* lname,                      /* launcher name */
 227         jboolean javaargs,                      /* JAVA_ARGS */
 228         jboolean cpwildcard,                    /* classpath wildcard*/
 229         jboolean javaw,                         /* windows-only javaw */
 230         jint ergo                               /* unused */
 231 )


 917     /*
 918      * Expand options array if needed to accommodate at least one more
 919      * VM option.
 920      */
 921     if (numOptions >= maxOptions) {
 922         if (options == 0) {
 923             maxOptions = 4;
 924             options = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
 925         } else {
 926             JavaVMOption *tmp;
 927             maxOptions *= 2;
 928             tmp = JLI_MemAlloc(maxOptions * sizeof(JavaVMOption));
 929             memcpy(tmp, options, numOptions * sizeof(JavaVMOption));
 930             JLI_MemFree(options);
 931             options = tmp;
 932         }
 933     }
 934     options[numOptions].optionString = str;
 935     options[numOptions++].extraInfo = info;
 936 







 937     if (JLI_StrCCmp(str, "-Xss") == 0) {
 938         jlong tmp;
 939         if (parse_size(str + 4, &tmp)) {
 940             threadStackSize = tmp;
 941             /*
 942              * Make sure the thread stack size is big enough that we won't get a stack
 943              * overflow before the JVM startup code can check to make sure the stack
 944              * is big enough.
 945              */
 946             if (threadStackSize < (jlong)STACK_SIZE_MINIMUM) {
 947                 threadStackSize = STACK_SIZE_MINIMUM;
 948             }
 949         }
 950     }
 951 
 952     if (JLI_StrCCmp(str, "-Xmx") == 0) {
 953         jlong tmp;
 954         if (parse_size(str + 4, &tmp)) {
 955             maxHeapSize = tmp;
 956         }
 957     }
 958 
 959     if (JLI_StrCCmp(str, "-Xms") == 0) {
 960         jlong tmp;
 961         if (parse_size(str + 4, &tmp)) {
 962            initialHeapSize = tmp;
 963         }
 964     }
 965 }
 966 


2305     return _launcher_name;
2306 }
2307 
2308 jboolean
2309 IsJavaArgs()
2310 {
2311     return _is_java_args;
2312 }
2313 
2314 static jboolean
2315 IsWildCardEnabled()
2316 {
2317     return _wc_enabled;
2318 }
2319 
2320 int
2321 ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
2322                     int argc, char **argv,
2323                     int mode, char *what, int ret)
2324 {
2325 
2326     /*
2327      * If user doesn't specify stack size, check if VM has a preference.
2328      * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will
2329      * return its default stack size through the init args structure.
2330      */
2331     if (threadStackSize == 0) {
2332       struct JDK1_1InitArgs args1_1;
2333       memset((void*)&args1_1, 0, sizeof(args1_1));
2334       args1_1.version = JNI_VERSION_1_1;
2335       ifn->GetDefaultJavaVMInitArgs(&args1_1);  /* ignore return value */
2336       if (args1_1.javaStackSize > 0) {
2337          threadStackSize = args1_1.javaStackSize;
2338       }






2339     }
2340 
2341     { /* Create a new thread to create JVM and invoke main method */
2342       JavaMainArgs args;
2343       int rslt;
2344 
2345       args.argc = argc;
2346       args.argv = argv;
2347       args.mode = mode;
2348       args.what = what;
2349       args.ifn = *ifn;
2350 
2351       rslt = CallJavaMainInNewThread(threadStackSize, (void*)&args);
2352       /* If the caller has deemed there is an error we
2353        * simply return that, otherwise we return the value of
2354        * the callee
2355        */
2356       return (ret != 0) ? ret : rslt;
2357     }
2358 }
2359 
2360 static void
2361 DumpState()
2362 {
2363     if (!JLI_IsTraceLauncher()) return ;
2364     printf("Launcher state:\n");
2365     printf("\tFirst application arg index: %d\n", JLI_GetAppArgIndex());
2366     printf("\tdebug:%s\n", (JLI_IsTraceLauncher() == JNI_TRUE) ? "on" : "off");
2367     printf("\tjavargs:%s\n", (_is_java_args == JNI_TRUE) ? "on" : "off");
2368     printf("\tprogram name:%s\n", GetProgramName());
2369     printf("\tlauncher name:%s\n", GetLauncherName());
2370     printf("\tjavaw:%s\n", (IsJavaw() == JNI_TRUE) ? "on" : "off");
2371     printf("\tfullversion:%s\n", GetFullVersion());
2372 }
2373 
2374 /*
2375  * A utility procedure to always print to stderr
2376  */


< prev index next >