< prev index next >

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

Print this page
rev 54472 : 8222334: java -Xss0 triggers StackOverflowError
Summary: Launcher to use the ThreadStackSize decided by hotpot or system if input is 0
Reviewed-by: dholmes


 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 


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     }




 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              * If the input thread stack size is 0, try to ask HotSpot to determine
 946              * a proper value later when creating thread for JavaMain, or use the
 947              * system default stack size. VM would create inner threads using its
 948              * calculated sizes, forced STACK_SIZE_MINIMUM here may trigger
 949              * StackOverflowError in HotSpot. See JDK-8222334 for details.
 950              */
 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 


2323 }
2324 
2325 int
2326 ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
2327                     int argc, char **argv,
2328                     int mode, char *what, int ret)
2329 {
2330 
2331     /*
2332      * If user doesn't specify stack size, check if VM has a preference.
2333      * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will
2334      * return its default stack size through the init args structure.
2335      */
2336     if (threadStackSize == 0) {
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       } else {
2344         /*
2345          * pthread_create would use system default stack size, e.g.,
2346          * ulimit -s shows:
2347          * stack size (kbytes, -s) 8192
2348          */
2349       }
2350     }
2351 
2352     { /* Create a new thread to create JVM and invoke main method */
2353       JavaMainArgs args;
2354       int rslt;
2355 
2356       args.argc = argc;
2357       args.argv = argv;
2358       args.mode = mode;
2359       args.what = what;
2360       args.ifn = *ifn;
2361 
2362       rslt = CallJavaMainInNewThread(threadStackSize, (void*)&args);
2363       /* If the caller has deemed there is an error we
2364        * simply return that, otherwise we return the value of
2365        * the callee
2366        */
2367       return (ret != 0) ? ret : rslt;
2368     }


< prev index next >