comparison src/share/vm/runtime/arguments.cpp @ 489:2494ab195856

6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes. Reviewed-by: ysr, mchung
author swamyv
date Mon, 15 Dec 2008 13:58:57 -0800
parents 0f773163217d
children 2328d1d3f8cf 323728917cf4
comparison
equal deleted inserted replaced
487:80206b8a9128 489:2494ab195856
442 os::closedir(dir); 442 os::closedir(dir);
443 return path; 443 return path;
444 } 444 }
445 445
446 // Parses a memory size specification string. 446 // Parses a memory size specification string.
447 static bool atomll(const char *s, jlong* result) { 447 static bool atomull(const char *s, julong* result) {
448 jlong n = 0; 448 julong n = 0;
449 int args_read = sscanf(s, os::jlong_format_specifier(), &n); 449 int args_read = sscanf(s, os::julong_format_specifier(), &n);
450 if (args_read != 1) { 450 if (args_read != 1) {
451 return false; 451 return false;
452 } 452 }
453 while (*s != '\0' && isdigit(*s)) { 453 while (*s != '\0' && isdigit(*s)) {
454 s++; 454 s++;
458 return false; 458 return false;
459 } 459 }
460 switch (*s) { 460 switch (*s) {
461 case 'T': case 't': 461 case 'T': case 't':
462 *result = n * G * K; 462 *result = n * G * K;
463 // Check for overflow.
464 if (*result/((julong)G * K) != n) return false;
463 return true; 465 return true;
464 case 'G': case 'g': 466 case 'G': case 'g':
465 *result = n * G; 467 *result = n * G;
468 if (*result/G != n) return false;
466 return true; 469 return true;
467 case 'M': case 'm': 470 case 'M': case 'm':
468 *result = n * M; 471 *result = n * M;
472 if (*result/M != n) return false;
469 return true; 473 return true;
470 case 'K': case 'k': 474 case 'K': case 'k':
471 *result = n * K; 475 *result = n * K;
476 if (*result/K != n) return false;
472 return true; 477 return true;
473 case '\0': 478 case '\0':
474 *result = n; 479 *result = n;
475 return true; 480 return true;
476 default: 481 default:
477 return false; 482 return false;
478 } 483 }
479 } 484 }
480 485
481 Arguments::ArgsRange Arguments::check_memory_size(jlong size, jlong min_size) { 486 Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size) {
482 if (size < min_size) return arg_too_small; 487 if (size < min_size) return arg_too_small;
483 // Check that size will fit in a size_t (only relevant on 32-bit) 488 // Check that size will fit in a size_t (only relevant on 32-bit)
484 if ((julong) size > max_uintx) return arg_too_big; 489 if (size > max_uintx) return arg_too_big;
485 return arg_in_range; 490 return arg_in_range;
486 } 491 }
487 492
488 // Describe an argument out of range error 493 // Describe an argument out of range error
489 void Arguments::describe_range_error(ArgsRange errcode) { 494 void Arguments::describe_range_error(ArgsRange errcode) {
520 return false; 525 return false;
521 } 526 }
522 527
523 528
524 static bool set_numeric_flag(char* name, char* value, FlagValueOrigin origin) { 529 static bool set_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
525 jlong v; 530 julong v;
526 intx intx_v; 531 intx intx_v;
527 bool is_neg = false; 532 bool is_neg = false;
528 // Check the sign first since atomll() parses only unsigned values. 533 // Check the sign first since atomull() parses only unsigned values.
529 if (*value == '-') { 534 if (*value == '-') {
530 if (!CommandLineFlags::intxAt(name, &intx_v)) { 535 if (!CommandLineFlags::intxAt(name, &intx_v)) {
531 return false; 536 return false;
532 } 537 }
533 value++; 538 value++;
534 is_neg = true; 539 is_neg = true;
535 } 540 }
536 if (!atomll(value, &v)) { 541 if (!atomull(value, &v)) {
537 return false; 542 return false;
538 } 543 }
539 intx_v = (intx) v; 544 intx_v = (intx) v;
540 if (is_neg) { 545 if (is_neg) {
541 intx_v = -intx_v; 546 intx_v = -intx_v;
1675 } 1680 }
1676 return false; 1681 return false;
1677 } 1682 }
1678 1683
1679 Arguments::ArgsRange Arguments::parse_memory_size(const char* s, 1684 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
1680 jlong* long_arg, 1685 julong* long_arg,
1681 jlong min_size) { 1686 julong min_size) {
1682 if (!atomll(s, long_arg)) return arg_unreadable; 1687 if (!atomull(s, long_arg)) return arg_unreadable;
1683 return check_memory_size(*long_arg, min_size); 1688 return check_memory_size(*long_arg, min_size);
1684 } 1689 }
1685 1690
1686 // Parse JavaVMInitArgs structure 1691 // Parse JavaVMInitArgs structure
1687 1692
1855 // -Xbatch 1860 // -Xbatch
1856 } else if (match_option(option, "-Xbatch", &tail)) { 1861 } else if (match_option(option, "-Xbatch", &tail)) {
1857 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false); 1862 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
1858 // -Xmn for compatibility with other JVM vendors 1863 // -Xmn for compatibility with other JVM vendors
1859 } else if (match_option(option, "-Xmn", &tail)) { 1864 } else if (match_option(option, "-Xmn", &tail)) {
1860 jlong long_initial_eden_size = 0; 1865 julong long_initial_eden_size = 0;
1861 ArgsRange errcode = parse_memory_size(tail, &long_initial_eden_size, 1); 1866 ArgsRange errcode = parse_memory_size(tail, &long_initial_eden_size, 1);
1862 if (errcode != arg_in_range) { 1867 if (errcode != arg_in_range) {
1863 jio_fprintf(defaultStream::error_stream(), 1868 jio_fprintf(defaultStream::error_stream(),
1864 "Invalid initial eden size: %s\n", option->optionString); 1869 "Invalid initial eden size: %s\n", option->optionString);
1865 describe_range_error(errcode); 1870 describe_range_error(errcode);
1867 } 1872 }
1868 FLAG_SET_CMDLINE(uintx, MaxNewSize, (size_t) long_initial_eden_size); 1873 FLAG_SET_CMDLINE(uintx, MaxNewSize, (size_t) long_initial_eden_size);
1869 FLAG_SET_CMDLINE(uintx, NewSize, (size_t) long_initial_eden_size); 1874 FLAG_SET_CMDLINE(uintx, NewSize, (size_t) long_initial_eden_size);
1870 // -Xms 1875 // -Xms
1871 } else if (match_option(option, "-Xms", &tail)) { 1876 } else if (match_option(option, "-Xms", &tail)) {
1872 jlong long_initial_heap_size = 0; 1877 julong long_initial_heap_size = 0;
1873 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 1); 1878 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 1);
1874 if (errcode != arg_in_range) { 1879 if (errcode != arg_in_range) {
1875 jio_fprintf(defaultStream::error_stream(), 1880 jio_fprintf(defaultStream::error_stream(),
1876 "Invalid initial heap size: %s\n", option->optionString); 1881 "Invalid initial heap size: %s\n", option->optionString);
1877 describe_range_error(errcode); 1882 describe_range_error(errcode);
1880 set_initial_heap_size((size_t) long_initial_heap_size); 1885 set_initial_heap_size((size_t) long_initial_heap_size);
1881 // Currently the minimum size and the initial heap sizes are the same. 1886 // Currently the minimum size and the initial heap sizes are the same.
1882 set_min_heap_size(initial_heap_size()); 1887 set_min_heap_size(initial_heap_size());
1883 // -Xmx 1888 // -Xmx
1884 } else if (match_option(option, "-Xmx", &tail)) { 1889 } else if (match_option(option, "-Xmx", &tail)) {
1885 jlong long_max_heap_size = 0; 1890 julong long_max_heap_size = 0;
1886 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1); 1891 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
1887 if (errcode != arg_in_range) { 1892 if (errcode != arg_in_range) {
1888 jio_fprintf(defaultStream::error_stream(), 1893 jio_fprintf(defaultStream::error_stream(),
1889 "Invalid maximum heap size: %s\n", option->optionString); 1894 "Invalid maximum heap size: %s\n", option->optionString);
1890 describe_range_error(errcode); 1895 describe_range_error(errcode);
1913 } else { 1918 } else {
1914 FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf); 1919 FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf);
1915 } 1920 }
1916 // -Xss 1921 // -Xss
1917 } else if (match_option(option, "-Xss", &tail)) { 1922 } else if (match_option(option, "-Xss", &tail)) {
1918 jlong long_ThreadStackSize = 0; 1923 julong long_ThreadStackSize = 0;
1919 ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000); 1924 ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000);
1920 if (errcode != arg_in_range) { 1925 if (errcode != arg_in_range) {
1921 jio_fprintf(defaultStream::error_stream(), 1926 jio_fprintf(defaultStream::error_stream(),
1922 "Invalid thread stack size: %s\n", option->optionString); 1927 "Invalid thread stack size: %s\n", option->optionString);
1923 describe_range_error(errcode); 1928 describe_range_error(errcode);
1929 // -Xoss 1934 // -Xoss
1930 } else if (match_option(option, "-Xoss", &tail)) { 1935 } else if (match_option(option, "-Xoss", &tail)) {
1931 // HotSpot does not have separate native and Java stacks, ignore silently for compatibility 1936 // HotSpot does not have separate native and Java stacks, ignore silently for compatibility
1932 // -Xmaxjitcodesize 1937 // -Xmaxjitcodesize
1933 } else if (match_option(option, "-Xmaxjitcodesize", &tail)) { 1938 } else if (match_option(option, "-Xmaxjitcodesize", &tail)) {
1934 jlong long_ReservedCodeCacheSize = 0; 1939 julong long_ReservedCodeCacheSize = 0;
1935 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1940 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize,
1936 InitialCodeCacheSize); 1941 (size_t)InitialCodeCacheSize);
1937 if (errcode != arg_in_range) { 1942 if (errcode != arg_in_range) {
1938 jio_fprintf(defaultStream::error_stream(), 1943 jio_fprintf(defaultStream::error_stream(),
1939 "Invalid maximum code cache size: %s\n", 1944 "Invalid maximum code cache size: %s\n",
1940 option->optionString); 1945 option->optionString);
1941 describe_range_error(errcode); 1946 describe_range_error(errcode);
2236 } else if (match_option(option, "-XX:-PrintTLE", &tail)) { 2241 } else if (match_option(option, "-XX:-PrintTLE", &tail)) {
2237 FLAG_SET_CMDLINE(bool, PrintTLAB, false); 2242 FLAG_SET_CMDLINE(bool, PrintTLAB, false);
2238 } else if (match_option(option, "-XX:TLEFragmentationRatio=", &tail)) { 2243 } else if (match_option(option, "-XX:TLEFragmentationRatio=", &tail)) {
2239 // No longer used. 2244 // No longer used.
2240 } else if (match_option(option, "-XX:TLESize=", &tail)) { 2245 } else if (match_option(option, "-XX:TLESize=", &tail)) {
2241 jlong long_tlab_size = 0; 2246 julong long_tlab_size = 0;
2242 ArgsRange errcode = parse_memory_size(tail, &long_tlab_size, 1); 2247 ArgsRange errcode = parse_memory_size(tail, &long_tlab_size, 1);
2243 if (errcode != arg_in_range) { 2248 if (errcode != arg_in_range) {
2244 jio_fprintf(defaultStream::error_stream(), 2249 jio_fprintf(defaultStream::error_stream(),
2245 "Invalid TLAB size: %s\n", option->optionString); 2250 "Invalid TLAB size: %s\n", option->optionString);
2246 describe_range_error(errcode); 2251 describe_range_error(errcode);
2291 jio_fprintf(defaultStream::error_stream(), 2296 jio_fprintf(defaultStream::error_stream(),
2292 "Please use -XX:CMSParPromoteBlocksToClaim in place of " 2297 "Please use -XX:CMSParPromoteBlocksToClaim in place of "
2293 "-XX:ParCMSPromoteBlocksToClaim in the future\n"); 2298 "-XX:ParCMSPromoteBlocksToClaim in the future\n");
2294 } else 2299 } else
2295 if (match_option(option, "-XX:ParallelGCOldGenAllocBufferSize=", &tail)) { 2300 if (match_option(option, "-XX:ParallelGCOldGenAllocBufferSize=", &tail)) {
2296 jlong old_plab_size = 0; 2301 julong old_plab_size = 0;
2297 ArgsRange errcode = parse_memory_size(tail, &old_plab_size, 1); 2302 ArgsRange errcode = parse_memory_size(tail, &old_plab_size, 1);
2298 if (errcode != arg_in_range) { 2303 if (errcode != arg_in_range) {
2299 jio_fprintf(defaultStream::error_stream(), 2304 jio_fprintf(defaultStream::error_stream(),
2300 "Invalid old PLAB size: %s\n", option->optionString); 2305 "Invalid old PLAB size: %s\n", option->optionString);
2301 describe_range_error(errcode); 2306 describe_range_error(errcode);
2302 return JNI_EINVAL; 2307 return JNI_EINVAL;
2303 } 2308 }
2304 FLAG_SET_CMDLINE(uintx, OldPLABSize, (julong)old_plab_size); 2309 FLAG_SET_CMDLINE(uintx, OldPLABSize, old_plab_size);
2305 jio_fprintf(defaultStream::error_stream(), 2310 jio_fprintf(defaultStream::error_stream(),
2306 "Please use -XX:OldPLABSize in place of " 2311 "Please use -XX:OldPLABSize in place of "
2307 "-XX:ParallelGCOldGenAllocBufferSize in the future\n"); 2312 "-XX:ParallelGCOldGenAllocBufferSize in the future\n");
2308 } else 2313 } else
2309 if (match_option(option, "-XX:ParallelGCToSpaceAllocBufferSize=", &tail)) { 2314 if (match_option(option, "-XX:ParallelGCToSpaceAllocBufferSize=", &tail)) {
2310 jlong young_plab_size = 0; 2315 julong young_plab_size = 0;
2311 ArgsRange errcode = parse_memory_size(tail, &young_plab_size, 1); 2316 ArgsRange errcode = parse_memory_size(tail, &young_plab_size, 1);
2312 if (errcode != arg_in_range) { 2317 if (errcode != arg_in_range) {
2313 jio_fprintf(defaultStream::error_stream(), 2318 jio_fprintf(defaultStream::error_stream(),
2314 "Invalid young PLAB size: %s\n", option->optionString); 2319 "Invalid young PLAB size: %s\n", option->optionString);
2315 describe_range_error(errcode); 2320 describe_range_error(errcode);
2316 return JNI_EINVAL; 2321 return JNI_EINVAL;
2317 } 2322 }
2318 FLAG_SET_CMDLINE(uintx, YoungPLABSize, (julong)young_plab_size); 2323 FLAG_SET_CMDLINE(uintx, YoungPLABSize, young_plab_size);
2319 jio_fprintf(defaultStream::error_stream(), 2324 jio_fprintf(defaultStream::error_stream(),
2320 "Please use -XX:YoungPLABSize in place of " 2325 "Please use -XX:YoungPLABSize in place of "
2321 "-XX:ParallelGCToSpaceAllocBufferSize in the future\n"); 2326 "-XX:ParallelGCToSpaceAllocBufferSize in the future\n");
2322 } else 2327 } else
2323 if (match_option(option, "-XX:", &tail)) { // -XX:xxxx 2328 if (match_option(option, "-XX:", &tail)) { // -XX:xxxx