src/share/vm/runtime/arguments.cpp

Print this page




  35 #include "runtime/arguments.hpp"
  36 #include "runtime/globals_extension.hpp"
  37 #include "runtime/java.hpp"
  38 #include "services/management.hpp"
  39 #include "services/memTracker.hpp"
  40 #include "utilities/defaultStream.hpp"
  41 #include "utilities/macros.hpp"
  42 #include "utilities/taskqueue.hpp"
  43 #ifdef TARGET_OS_FAMILY_linux
  44 # include "os_linux.inline.hpp"
  45 #endif
  46 #ifdef TARGET_OS_FAMILY_solaris
  47 # include "os_solaris.inline.hpp"
  48 #endif
  49 #ifdef TARGET_OS_FAMILY_windows
  50 # include "os_windows.inline.hpp"
  51 #endif
  52 #ifdef TARGET_OS_FAMILY_bsd
  53 # include "os_bsd.inline.hpp"
  54 #endif

  55 #if INCLUDE_ALL_GCS


  56 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
  57 #endif // INCLUDE_ALL_GCS
  58 
  59 // Note: This is a special bug reporting site for the JVM
  60 #define DEFAULT_VENDOR_URL_BUG "http://bugreport.sun.com/bugreport/crash.jsp"
  61 #define DEFAULT_JAVA_LAUNCHER  "generic"
  62 
  63 char**  Arguments::_jvm_flags_array             = NULL;
  64 int     Arguments::_num_jvm_flags               = 0;
  65 char**  Arguments::_jvm_args_array              = NULL;
  66 int     Arguments::_num_jvm_args                = 0;
  67 char*  Arguments::_java_command                 = NULL;
  68 SystemProperty* Arguments::_system_properties   = NULL;
  69 const char*  Arguments::_gc_log_filename        = NULL;
  70 bool   Arguments::_has_profile                  = false;
  71 bool   Arguments::_has_alloc_profile            = false;

  72 uintx  Arguments::_min_heap_size                = 0;
  73 Arguments::Mode Arguments::_mode                = _mixed;
  74 bool   Arguments::_java_compiler                = false;
  75 bool   Arguments::_xdebug_mode                  = false;
  76 const char*  Arguments::_java_vendor_url_bug    = DEFAULT_VENDOR_URL_BUG;
  77 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  78 int    Arguments::_sun_java_launcher_pid        = -1;
  79 bool   Arguments::_created_by_gamma_launcher    = false;
  80 
  81 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
  82 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
  83 bool   Arguments::_UseOnStackReplacement        = UseOnStackReplacement;
  84 bool   Arguments::_BackgroundCompilation        = BackgroundCompilation;
  85 bool   Arguments::_ClipInlining                 = ClipInlining;
  86 
  87 char*  Arguments::SharedArchivePath             = NULL;
  88 
  89 AgentLibraryList Arguments::_libraryList;
  90 AgentLibraryList Arguments::_agentList;
  91 


1341   }
1342   // It does not make sense to have big object alignment
1343   // since a space lost due to alignment will be greater
1344   // then a saved space from compressed oops.
1345   if ((int)ObjectAlignmentInBytes > 256) {
1346     jio_fprintf(defaultStream::error_stream(),
1347                 "error: ObjectAlignmentInBytes=%d must not be greater than 256\n",
1348                 (int)ObjectAlignmentInBytes);
1349     return false;
1350   }
1351   // In case page size is very small.
1352   if ((int)ObjectAlignmentInBytes >= os::vm_page_size()) {
1353     jio_fprintf(defaultStream::error_stream(),
1354                 "error: ObjectAlignmentInBytes=%d must be less than page size %d\n",
1355                 (int)ObjectAlignmentInBytes, os::vm_page_size());
1356     return false;
1357   }
1358   return true;
1359 }
1360 
1361 inline uintx max_heap_for_compressed_oops() {




















1362   // Avoid sign flip.
1363   if (OopEncodingHeapMax < ClassMetaspaceSize + os::vm_page_size()) {
1364     return 0;
1365   }
1366   LP64_ONLY(return OopEncodingHeapMax - ClassMetaspaceSize - os::vm_page_size());
1367   NOT_LP64(ShouldNotReachHere(); return 0);
1368 }
1369 
1370 bool Arguments::should_auto_select_low_pause_collector() {
1371   if (UseAutoGCSelectPolicy &&
1372       !FLAG_IS_DEFAULT(MaxGCPauseMillis) &&
1373       (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) {
1374     if (PrintGCDetails) {
1375       // Cannot use gclog_or_tty yet.
1376       tty->print_cr("Automatic selection of the low pause collector"
1377        " based on pause goal of %d (ms)", MaxGCPauseMillis);
1378     }
1379     return true;
1380   }
1381   return false;
1382 }
1383 
1384 void Arguments::set_use_compressed_oops() {
1385 #ifndef ZERO
1386 #ifdef _LP64


1398 #ifdef _WIN64
1399     if (UseLargePages && UseCompressedOops) {
1400       // Cannot allocate guard pages for implicit checks in indexed addressing
1401       // mode, when large pages are specified on windows.
1402       // This flag could be switched ON if narrow oop base address is set to 0,
1403       // see code in Universe::initialize_heap().
1404       Universe::set_narrow_oop_use_implicit_null_checks(false);
1405     }
1406 #endif //  _WIN64
1407   } else {
1408     if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
1409       warning("Max heap size too large for Compressed Oops");
1410       FLAG_SET_DEFAULT(UseCompressedOops, false);
1411       FLAG_SET_DEFAULT(UseCompressedKlassPointers, false);
1412     }
1413   }
1414 #endif // _LP64
1415 #endif // ZERO
1416 }
1417 

















1418 void Arguments::set_ergonomics_flags() {
1419 
1420   if (os::is_server_class_machine()) {
1421     // If no other collector is requested explicitly,
1422     // let the VM select the collector based on
1423     // machine class and automatic selection policy.
1424     if (!UseSerialGC &&
1425         !UseConcMarkSweepGC &&
1426         !UseG1GC &&
1427         !UseParNewGC &&
1428         FLAG_IS_DEFAULT(UseParallelGC)) {
1429       if (should_auto_select_low_pause_collector()) {
1430         FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
1431       } else {
1432         FLAG_SET_ERGO(bool, UseParallelGC, true);
1433       }
1434     }
1435     // Shared spaces work fine with other GCs but causes bytecode rewriting
1436     // to be disabled, which hurts interpreter performance and decreases
1437     // server performance.   On server class machines, keep the default
1438     // off unless it is asked for.  Future work: either add bytecode rewriting
1439     // at link time, or rewrite bytecodes in non-shared methods.
1440     if (!DumpSharedSpaces && !RequireSharedSpaces) {
1441       no_shared_spaces();
1442     }
1443   }
1444 


1445 #ifndef ZERO
1446 #ifdef _LP64
1447   set_use_compressed_oops();
1448   // UseCompressedOops must be on for UseCompressedKlassPointers to be on.
1449   if (!UseCompressedOops) {
1450     if (UseCompressedKlassPointers) {
1451       warning("UseCompressedKlassPointers requires UseCompressedOops");
1452     }
1453     FLAG_SET_DEFAULT(UseCompressedKlassPointers, false);
1454   } else {
1455     // Turn on UseCompressedKlassPointers too
1456     if (FLAG_IS_DEFAULT(UseCompressedKlassPointers)) {
1457       FLAG_SET_ERGO(bool, UseCompressedKlassPointers, true);
1458     }
1459     // Set the ClassMetaspaceSize to something that will not need to be
1460     // expanded, since it cannot be expanded.
1461     if (UseCompressedKlassPointers) {
1462       if (ClassMetaspaceSize > KlassEncodingMetaspaceMax) {
1463         warning("Class metaspace size is too large for UseCompressedKlassPointers");
1464         FLAG_SET_DEFAULT(UseCompressedKlassPointers, false);
1465       } else if (FLAG_IS_DEFAULT(ClassMetaspaceSize)) {
1466         // 100,000 classes seems like a good size, so 100M assumes around 1K
1467         // per klass.   The vtable and oopMap is embedded so we don't have a fixed
1468         // size per klass.   Eventually, this will be parameterized because it
1469         // would also be useful to determine the optimal size of the
1470         // systemDictionary.
1471         FLAG_SET_ERGO(uintx, ClassMetaspaceSize, 100*M);
1472       }
1473     }
1474   }
1475   // Also checks that certain machines are slower with compressed oops
1476   // in vm_version initialization code.
1477 #endif // _LP64
1478 #endif // !ZERO
1479 }
1480 
1481 void Arguments::set_parallel_gc_flags() {
1482   assert(UseParallelGC || UseParallelOldGC, "Error");
1483   // Enable ParallelOld unless it was explicitly disabled (cmd line or rc file).
1484   if (FLAG_IS_DEFAULT(UseParallelOldGC)) {
1485     FLAG_SET_DEFAULT(UseParallelOldGC, true);
1486   }
1487   FLAG_SET_DEFAULT(UseParallelGC, true);
1488 
1489   // If no heap maximum was requested explicitly, use some reasonable fraction
1490   // of the physical memory, up to a maximum of 1GB.
1491   FLAG_SET_DEFAULT(ParallelGCThreads,


3483 
3484   // Set object alignment values.
3485   set_object_alignment();
3486 
3487 #if !INCLUDE_ALL_GCS
3488   force_serial_gc();
3489 #endif // INCLUDE_ALL_GCS
3490 #if !INCLUDE_CDS
3491   if (DumpSharedSpaces || RequireSharedSpaces) {
3492     jio_fprintf(defaultStream::error_stream(),
3493       "Shared spaces are not supported in this VM\n");
3494     return JNI_ERR;
3495   }
3496   if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) {
3497     warning("Shared spaces are not supported in this VM");
3498     FLAG_SET_DEFAULT(UseSharedSpaces, false);
3499     FLAG_SET_DEFAULT(PrintSharedSpaces, false);
3500   }
3501   no_shared_spaces();
3502 #endif // INCLUDE_CDS





3503 
3504   // Set flags based on ergonomics.
3505   set_ergonomics_flags();
3506 
3507   set_shared_spaces_flags();
3508 
3509   // Check the GC selections again.
3510   if (!check_gc_consistency()) {
3511     return JNI_EINVAL;
3512   }
3513 
3514   if (TieredCompilation) {
3515     set_tiered_flags();
3516   } else {
3517     // Check if the policy is valid. Policies 0 and 1 are valid for non-tiered setup.
3518     if (CompilationPolicyChoice >= 2) {
3519       vm_exit_during_initialization(
3520         "Incompatible compilation policy selected", NULL);
3521     }
3522   }




  35 #include "runtime/arguments.hpp"
  36 #include "runtime/globals_extension.hpp"
  37 #include "runtime/java.hpp"
  38 #include "services/management.hpp"
  39 #include "services/memTracker.hpp"
  40 #include "utilities/defaultStream.hpp"
  41 #include "utilities/macros.hpp"
  42 #include "utilities/taskqueue.hpp"
  43 #ifdef TARGET_OS_FAMILY_linux
  44 # include "os_linux.inline.hpp"
  45 #endif
  46 #ifdef TARGET_OS_FAMILY_solaris
  47 # include "os_solaris.inline.hpp"
  48 #endif
  49 #ifdef TARGET_OS_FAMILY_windows
  50 # include "os_windows.inline.hpp"
  51 #endif
  52 #ifdef TARGET_OS_FAMILY_bsd
  53 # include "os_bsd.inline.hpp"
  54 #endif
  55 #include "memory/genCollectedHeap.hpp"
  56 #if INCLUDE_ALL_GCS
  57 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  58 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  59 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
  60 #endif // INCLUDE_ALL_GCS
  61 
  62 // Note: This is a special bug reporting site for the JVM
  63 #define DEFAULT_VENDOR_URL_BUG "http://bugreport.sun.com/bugreport/crash.jsp"
  64 #define DEFAULT_JAVA_LAUNCHER  "generic"
  65 
  66 char**  Arguments::_jvm_flags_array             = NULL;
  67 int     Arguments::_num_jvm_flags               = 0;
  68 char**  Arguments::_jvm_args_array              = NULL;
  69 int     Arguments::_num_jvm_args                = 0;
  70 char*  Arguments::_java_command                 = NULL;
  71 SystemProperty* Arguments::_system_properties   = NULL;
  72 const char*  Arguments::_gc_log_filename        = NULL;
  73 bool   Arguments::_has_profile                  = false;
  74 bool   Arguments::_has_alloc_profile            = false;
  75 size_t Arguments::_max_heap_alignment           = 0;
  76 uintx  Arguments::_min_heap_size                = 0;
  77 Arguments::Mode Arguments::_mode                = _mixed;
  78 bool   Arguments::_java_compiler                = false;
  79 bool   Arguments::_xdebug_mode                  = false;
  80 const char*  Arguments::_java_vendor_url_bug    = DEFAULT_VENDOR_URL_BUG;
  81 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  82 int    Arguments::_sun_java_launcher_pid        = -1;
  83 bool   Arguments::_created_by_gamma_launcher    = false;
  84 
  85 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
  86 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
  87 bool   Arguments::_UseOnStackReplacement        = UseOnStackReplacement;
  88 bool   Arguments::_BackgroundCompilation        = BackgroundCompilation;
  89 bool   Arguments::_ClipInlining                 = ClipInlining;
  90 
  91 char*  Arguments::SharedArchivePath             = NULL;
  92 
  93 AgentLibraryList Arguments::_libraryList;
  94 AgentLibraryList Arguments::_agentList;
  95 


1345   }
1346   // It does not make sense to have big object alignment
1347   // since a space lost due to alignment will be greater
1348   // then a saved space from compressed oops.
1349   if ((int)ObjectAlignmentInBytes > 256) {
1350     jio_fprintf(defaultStream::error_stream(),
1351                 "error: ObjectAlignmentInBytes=%d must not be greater than 256\n",
1352                 (int)ObjectAlignmentInBytes);
1353     return false;
1354   }
1355   // In case page size is very small.
1356   if ((int)ObjectAlignmentInBytes >= os::vm_page_size()) {
1357     jio_fprintf(defaultStream::error_stream(),
1358                 "error: ObjectAlignmentInBytes=%d must be less than page size %d\n",
1359                 (int)ObjectAlignmentInBytes, os::vm_page_size());
1360     return false;
1361   }
1362   return true;
1363 }
1364 
1365 bool Arguments::apply_ergonomics_on_classmetaspacesize() {
1366   return FLAG_IS_DEFAULT(ClassMetaspaceSize);
1367 }
1368 
1369 size_t Arguments::max_heap_for_compressed_oops() {
1370   // determine the maximum heap size that allows compressed oops. Use the theoretical
1371   // maximum (OopEncodingHeapMax) and subtract the sizes of other areas that need
1372   // to be below that maximum. Use a conservative estimate on the alignment returned
1373   // by max_heap_alignment() to calculate these estimates for the other areas.
1374   // We need to apply the alignment on all areas separately to make sure that later,
1375   // when aligning the final heap size up, all sizes fit below the absolute maximum.
1376 
1377   // the absolute theoretical maximum for the heap with compressed oops
1378   size_t max_total_heap = OopEncodingHeapMax;
1379 
1380   size_t max_class_metaspace_size = ClassMetaspaceSize;
1381   if (apply_ergonomics_on_classmetaspacesize()) {
1382     max_class_metaspace_size = MAX2(max_class_metaspace_size, ErgoClassMetaspaceSize);
1383   }
1384   size_t aligned_metaspace_size = align_size_up_(max_class_metaspace_size, max_heap_alignment());
1385   size_t aligned_page_size = align_size_up_(os::vm_page_size(), max_heap_alignment());
1386   // Avoid sign flip.
1387   if (max_total_heap < aligned_metaspace_size + aligned_page_size) {
1388     return 0;
1389   }
1390   LP64_ONLY(return max_total_heap - aligned_metaspace_size - aligned_page_size);
1391   NOT_LP64(ShouldNotReachHere(); return 0);
1392 }
1393 
1394 bool Arguments::should_auto_select_low_pause_collector() {
1395   if (UseAutoGCSelectPolicy &&
1396       !FLAG_IS_DEFAULT(MaxGCPauseMillis) &&
1397       (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) {
1398     if (PrintGCDetails) {
1399       // Cannot use gclog_or_tty yet.
1400       tty->print_cr("Automatic selection of the low pause collector"
1401        " based on pause goal of %d (ms)", MaxGCPauseMillis);
1402     }
1403     return true;
1404   }
1405   return false;
1406 }
1407 
1408 void Arguments::set_use_compressed_oops() {
1409 #ifndef ZERO
1410 #ifdef _LP64


1422 #ifdef _WIN64
1423     if (UseLargePages && UseCompressedOops) {
1424       // Cannot allocate guard pages for implicit checks in indexed addressing
1425       // mode, when large pages are specified on windows.
1426       // This flag could be switched ON if narrow oop base address is set to 0,
1427       // see code in Universe::initialize_heap().
1428       Universe::set_narrow_oop_use_implicit_null_checks(false);
1429     }
1430 #endif //  _WIN64
1431   } else {
1432     if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
1433       warning("Max heap size too large for Compressed Oops");
1434       FLAG_SET_DEFAULT(UseCompressedOops, false);
1435       FLAG_SET_DEFAULT(UseCompressedKlassPointers, false);
1436     }
1437   }
1438 #endif // _LP64
1439 #endif // ZERO
1440 }
1441 
1442 void Arguments::set_max_heap_alignment() {
1443   size_t gc_alignment;
1444 #if INCLUDE_ALL_GCS
1445   if (UseParallelGC) {
1446     gc_alignment = ParallelScavengeHeap::max_heap_alignment();
1447   } else if (UseG1GC) {
1448     gc_alignment = G1CollectedHeap::max_heap_alignment();
1449   } else {
1450 #endif // INCLUDE_ALL_GCS
1451     gc_alignment = GenCollectedHeap::max_heap_alignment();
1452 #if INCLUDE_ALL_GCS
1453   }
1454 #endif // INCLUDE_ALL_GCS
1455   _max_heap_alignment = MAX3(gc_alignment, os::max_page_size(),
1456     CollectorPolicy::compute_max_alignment());
1457 }
1458 
1459 void Arguments::set_ergonomics_flags() {
1460 
1461   if (os::is_server_class_machine()) {
1462     // If no other collector is requested explicitly,
1463     // let the VM select the collector based on
1464     // machine class and automatic selection policy.
1465     if (!UseSerialGC &&
1466         !UseConcMarkSweepGC &&
1467         !UseG1GC &&
1468         !UseParNewGC &&
1469         FLAG_IS_DEFAULT(UseParallelGC)) {
1470       if (should_auto_select_low_pause_collector()) {
1471         FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
1472       } else {
1473         FLAG_SET_ERGO(bool, UseParallelGC, true);
1474       }
1475     }
1476     // Shared spaces work fine with other GCs but causes bytecode rewriting
1477     // to be disabled, which hurts interpreter performance and decreases
1478     // server performance.   On server class machines, keep the default
1479     // off unless it is asked for.  Future work: either add bytecode rewriting
1480     // at link time, or rewrite bytecodes in non-shared methods.
1481     if (!DumpSharedSpaces && !RequireSharedSpaces) {
1482       no_shared_spaces();
1483     }
1484   }
1485 
1486   set_max_heap_alignment();
1487 
1488 #ifndef ZERO
1489 #ifdef _LP64
1490   set_use_compressed_oops();
1491   // UseCompressedOops must be on for UseCompressedKlassPointers to be on.
1492   if (!UseCompressedOops) {
1493     if (UseCompressedKlassPointers) {
1494       warning("UseCompressedKlassPointers requires UseCompressedOops");
1495     }
1496     FLAG_SET_DEFAULT(UseCompressedKlassPointers, false);
1497   } else {
1498     // Turn on UseCompressedKlassPointers too
1499     if (FLAG_IS_DEFAULT(UseCompressedKlassPointers)) {
1500       FLAG_SET_ERGO(bool, UseCompressedKlassPointers, true);
1501     }
1502     // Set the ClassMetaspaceSize to something that will not need to be
1503     // expanded, since it cannot be expanded.
1504     if (UseCompressedKlassPointers) {
1505       if (ClassMetaspaceSize > KlassEncodingMetaspaceMax) {
1506         warning("Class metaspace size is too large for UseCompressedKlassPointers");
1507         FLAG_SET_DEFAULT(UseCompressedKlassPointers, false);
1508       } else if (apply_ergonomics_on_classmetaspacesize()) {
1509         FLAG_SET_ERGO(uintx, ClassMetaspaceSize, ErgoClassMetaspaceSize);





1510       }
1511     }
1512   }
1513   // Also checks that certain machines are slower with compressed oops
1514   // in vm_version initialization code.
1515 #endif // _LP64
1516 #endif // !ZERO
1517 }
1518 
1519 void Arguments::set_parallel_gc_flags() {
1520   assert(UseParallelGC || UseParallelOldGC, "Error");
1521   // Enable ParallelOld unless it was explicitly disabled (cmd line or rc file).
1522   if (FLAG_IS_DEFAULT(UseParallelOldGC)) {
1523     FLAG_SET_DEFAULT(UseParallelOldGC, true);
1524   }
1525   FLAG_SET_DEFAULT(UseParallelGC, true);
1526 
1527   // If no heap maximum was requested explicitly, use some reasonable fraction
1528   // of the physical memory, up to a maximum of 1GB.
1529   FLAG_SET_DEFAULT(ParallelGCThreads,


3521 
3522   // Set object alignment values.
3523   set_object_alignment();
3524 
3525 #if !INCLUDE_ALL_GCS
3526   force_serial_gc();
3527 #endif // INCLUDE_ALL_GCS
3528 #if !INCLUDE_CDS
3529   if (DumpSharedSpaces || RequireSharedSpaces) {
3530     jio_fprintf(defaultStream::error_stream(),
3531       "Shared spaces are not supported in this VM\n");
3532     return JNI_ERR;
3533   }
3534   if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) {
3535     warning("Shared spaces are not supported in this VM");
3536     FLAG_SET_DEFAULT(UseSharedSpaces, false);
3537     FLAG_SET_DEFAULT(PrintSharedSpaces, false);
3538   }
3539   no_shared_spaces();
3540 #endif // INCLUDE_CDS
3541 
3542   // We need to initialize large page support here because ergonomics takes some
3543   // decisions depending on large page support and the calculated large page size.
3544   // Ergonomics may turn off large page support off later again.
3545   os::large_page_init();
3546 
3547   // Set flags based on ergonomics.
3548   set_ergonomics_flags();
3549 
3550   set_shared_spaces_flags();
3551 
3552   // Check the GC selections again.
3553   if (!check_gc_consistency()) {
3554     return JNI_EINVAL;
3555   }
3556 
3557   if (TieredCompilation) {
3558     set_tiered_flags();
3559   } else {
3560     // Check if the policy is valid. Policies 0 and 1 are valid for non-tiered setup.
3561     if (CompilationPolicyChoice >= 2) {
3562       vm_exit_during_initialization(
3563         "Incompatible compilation policy selected", NULL);
3564     }
3565   }