src/share/vm/runtime/arguments.cpp

Print this page
rev 4560 : 8006088: Incompatible heap size flags accepted by VM
Summary: Make processing of minimum, initial and maximum heap size more intiutive by removing previous limitations on allowed values, and make error reporting consistent. Further, fix errors in ergonomic heap sizing.
Reviewed-by: johnc, jwilhelm, tamao


1600       }
1601       reasonable_max = MIN2(reasonable_max, max_coop_heap);
1602     }
1603     reasonable_max = limit_by_allocatable_memory(reasonable_max);
1604 
1605     if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
1606       // An initial heap size was specified on the command line,
1607       // so be sure that the maximum size is consistent.  Done
1608       // after call to limit_by_allocatable_memory because that
1609       // method might reduce the allocation size.
1610       reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
1611     }
1612 
1613     if (PrintGCDetails && Verbose) {
1614       // Cannot use gclog_or_tty yet.
1615       tty->print_cr("  Maximum heap size " SIZE_FORMAT, reasonable_max);
1616     }
1617     FLAG_SET_ERGO(uintx, MaxHeapSize, (uintx)reasonable_max);
1618   }
1619 
1620   // If the initial_heap_size has not been set with InitialHeapSize
1621   // or -Xms, then set it as fraction of the size of physical memory,
1622   // respecting the maximum and minimum sizes of the heap.
1623   if (FLAG_IS_DEFAULT(InitialHeapSize)) {
1624     julong reasonable_minimum = (julong)(OldSize + NewSize);
1625 
1626     reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
1627 
1628     reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
1629 

1630     julong reasonable_initial = phys_mem / InitialRAMFraction;
1631 
1632     reasonable_initial = MAX2(reasonable_initial, reasonable_minimum);
1633     reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
1634 
1635     reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
1636 
1637     if (PrintGCDetails && Verbose) {
1638       // Cannot use gclog_or_tty yet.
1639       tty->print_cr("  Initial heap size " SIZE_FORMAT, (uintx)reasonable_initial);
1640       tty->print_cr("  Minimum heap size " SIZE_FORMAT, (uintx)reasonable_minimum);
1641     }
1642     FLAG_SET_ERGO(uintx, InitialHeapSize, (uintx)reasonable_initial);
1643     set_min_heap_size((uintx)reasonable_minimum);









1644   }
1645 }
1646 
1647 // This must be called after ergonomics because we want bytecode rewriting
1648 // if the server compiler is used, or if UseSharedSpaces is disabled.
1649 void Arguments::set_bytecode_flags() {
1650   // Better not attempt to store into a read-only space.
1651   if (UseSharedSpaces) {
1652     FLAG_SET_DEFAULT(RewriteBytecodes, false);
1653     FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
1654   }
1655 
1656   if (!RewriteBytecodes) {
1657     FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
1658   }
1659 }
1660 
1661 // Aggressive optimization flags  -XX:+AggressiveOpts
1662 void Arguments::set_aggressive_opts_flags() {
1663 #ifdef COMPILER2


2360     } else if (match_option(option, "-Xnoconcgc", &tail)) {
2361       FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
2362     // -Xbatch
2363     } else if (match_option(option, "-Xbatch", &tail)) {
2364       FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
2365     // -Xmn for compatibility with other JVM vendors
2366     } else if (match_option(option, "-Xmn", &tail)) {
2367       julong long_initial_eden_size = 0;
2368       ArgsRange errcode = parse_memory_size(tail, &long_initial_eden_size, 1);
2369       if (errcode != arg_in_range) {
2370         jio_fprintf(defaultStream::error_stream(),
2371                     "Invalid initial eden size: %s\n", option->optionString);
2372         describe_range_error(errcode);
2373         return JNI_EINVAL;
2374       }
2375       FLAG_SET_CMDLINE(uintx, MaxNewSize, (uintx)long_initial_eden_size);
2376       FLAG_SET_CMDLINE(uintx, NewSize, (uintx)long_initial_eden_size);
2377     // -Xms
2378     } else if (match_option(option, "-Xms", &tail)) {
2379       julong long_initial_heap_size = 0;
2380       ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 1);

2381       if (errcode != arg_in_range) {
2382         jio_fprintf(defaultStream::error_stream(),
2383                     "Invalid initial heap size: %s\n", option->optionString);
2384         describe_range_error(errcode);
2385         return JNI_EINVAL;
2386       }
2387       FLAG_SET_CMDLINE(uintx, InitialHeapSize, (uintx)long_initial_heap_size);
2388       // Currently the minimum size and the initial heap sizes are the same.
2389       set_min_heap_size(InitialHeapSize);
2390     // -Xmx
2391     } else if (match_option(option, "-Xmx", &tail)) {
2392       julong long_max_heap_size = 0;
2393       ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
2394       if (errcode != arg_in_range) {
2395         jio_fprintf(defaultStream::error_stream(),
2396                     "Invalid maximum heap size: %s\n", option->optionString);
2397         describe_range_error(errcode);
2398         return JNI_EINVAL;
2399       }
2400       FLAG_SET_CMDLINE(uintx, MaxHeapSize, (uintx)long_max_heap_size);
2401     // Xmaxf
2402     } else if (match_option(option, "-Xmaxf", &tail)) {
2403       int maxf = (int)(atof(tail) * 100);
2404       if (maxf < 0 || maxf > 100) {
2405         jio_fprintf(defaultStream::error_stream(),
2406                     "Bad max heap free percentage size: %s\n",
2407                     option->optionString);
2408         return JNI_EINVAL;
2409       } else {
2410         FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf);
2411       }




1600       }
1601       reasonable_max = MIN2(reasonable_max, max_coop_heap);
1602     }
1603     reasonable_max = limit_by_allocatable_memory(reasonable_max);
1604 
1605     if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
1606       // An initial heap size was specified on the command line,
1607       // so be sure that the maximum size is consistent.  Done
1608       // after call to limit_by_allocatable_memory because that
1609       // method might reduce the allocation size.
1610       reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
1611     }
1612 
1613     if (PrintGCDetails && Verbose) {
1614       // Cannot use gclog_or_tty yet.
1615       tty->print_cr("  Maximum heap size " SIZE_FORMAT, reasonable_max);
1616     }
1617     FLAG_SET_ERGO(uintx, MaxHeapSize, (uintx)reasonable_max);
1618   }
1619 
1620   // If the minimum or initial heap_size have not been set or requested to be set
1621   // ergonomically, set them accordingly.
1622   if (InitialHeapSize == 0 || min_heap_size() == 0) {

1623     julong reasonable_minimum = (julong)(OldSize + NewSize);
1624 
1625     reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
1626 
1627     reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
1628 
1629     if (InitialHeapSize == 0) {
1630       julong reasonable_initial = phys_mem / InitialRAMFraction;
1631 
1632       reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size());
1633       reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
1634 
1635       reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
1636 
1637       if (PrintGCDetails && Verbose) {
1638         // Cannot use gclog_or_tty yet.
1639         tty->print_cr("  Initial heap size " SIZE_FORMAT, (uintx)reasonable_initial);

1640       }
1641       FLAG_SET_ERGO(uintx, InitialHeapSize, (uintx)reasonable_initial);
1642     }
1643     // If the minimum heap size has not been set (via -Xms),
1644     // synchronize with InitialHeapSize to avoid errors with the default value.
1645     if (min_heap_size() == 0) {
1646       set_min_heap_size(MIN2((uintx)reasonable_minimum, InitialHeapSize));
1647       if (PrintGCDetails && Verbose) {
1648         // Cannot use gclog_or_tty yet.
1649         tty->print_cr("  Minimum heap size " SIZE_FORMAT, min_heap_size());
1650       }
1651     }
1652   }
1653 }
1654 
1655 // This must be called after ergonomics because we want bytecode rewriting
1656 // if the server compiler is used, or if UseSharedSpaces is disabled.
1657 void Arguments::set_bytecode_flags() {
1658   // Better not attempt to store into a read-only space.
1659   if (UseSharedSpaces) {
1660     FLAG_SET_DEFAULT(RewriteBytecodes, false);
1661     FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
1662   }
1663 
1664   if (!RewriteBytecodes) {
1665     FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
1666   }
1667 }
1668 
1669 // Aggressive optimization flags  -XX:+AggressiveOpts
1670 void Arguments::set_aggressive_opts_flags() {
1671 #ifdef COMPILER2


2368     } else if (match_option(option, "-Xnoconcgc", &tail)) {
2369       FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
2370     // -Xbatch
2371     } else if (match_option(option, "-Xbatch", &tail)) {
2372       FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
2373     // -Xmn for compatibility with other JVM vendors
2374     } else if (match_option(option, "-Xmn", &tail)) {
2375       julong long_initial_eden_size = 0;
2376       ArgsRange errcode = parse_memory_size(tail, &long_initial_eden_size, 1);
2377       if (errcode != arg_in_range) {
2378         jio_fprintf(defaultStream::error_stream(),
2379                     "Invalid initial eden size: %s\n", option->optionString);
2380         describe_range_error(errcode);
2381         return JNI_EINVAL;
2382       }
2383       FLAG_SET_CMDLINE(uintx, MaxNewSize, (uintx)long_initial_eden_size);
2384       FLAG_SET_CMDLINE(uintx, NewSize, (uintx)long_initial_eden_size);
2385     // -Xms
2386     } else if (match_option(option, "-Xms", &tail)) {
2387       julong long_initial_heap_size = 0;
2388       // an initial heap size of 0 means automatically determine
2389       ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 0);
2390       if (errcode != arg_in_range) {
2391         jio_fprintf(defaultStream::error_stream(),
2392                     "Invalid initial heap size: %s\n", option->optionString);
2393         describe_range_error(errcode);
2394         return JNI_EINVAL;
2395       }
2396       FLAG_SET_CMDLINE(uintx, InitialHeapSize, (uintx)long_initial_heap_size);
2397       // Currently the minimum size and the initial heap sizes are the same.
2398       set_min_heap_size(InitialHeapSize);
2399     // -Xmx
2400     } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) {
2401       julong long_max_heap_size = 0;
2402       ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
2403       if (errcode != arg_in_range) {
2404         jio_fprintf(defaultStream::error_stream(),
2405                     "Invalid maximum heap size: %s\n", option->optionString);
2406         describe_range_error(errcode);
2407         return JNI_EINVAL;
2408       }
2409       FLAG_SET_CMDLINE(uintx, MaxHeapSize, (uintx)long_max_heap_size);
2410     // Xmaxf
2411     } else if (match_option(option, "-Xmaxf", &tail)) {
2412       int maxf = (int)(atof(tail) * 100);
2413       if (maxf < 0 || maxf > 100) {
2414         jio_fprintf(defaultStream::error_stream(),
2415                     "Bad max heap free percentage size: %s\n",
2416                     option->optionString);
2417         return JNI_EINVAL;
2418       } else {
2419         FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf);
2420       }