--- old/src/share/vm/runtime/arguments.cpp 2013-06-04 17:03:30.151740809 +0200 +++ new/src/share/vm/runtime/arguments.cpp 2013-06-04 17:03:29.979740804 +0200 @@ -52,7 +52,10 @@ #ifdef TARGET_OS_FAMILY_bsd # include "os_bsd.inline.hpp" #endif +#include "memory/genCollectedHeap.hpp" #if INCLUDE_ALL_GCS +#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" +#include "gc_implementation/g1/g1CollectedHeap.inline.hpp" #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp" #endif // INCLUDE_ALL_GCS @@ -69,6 +72,7 @@ const char* Arguments::_gc_log_filename = NULL; bool Arguments::_has_profile = false; bool Arguments::_has_alloc_profile = false; +size_t Arguments::_max_heap_alignment = 0; uintx Arguments::_min_heap_size = 0; Arguments::Mode Arguments::_mode = _mixed; bool Arguments::_java_compiler = false; @@ -1358,12 +1362,32 @@ return true; } -inline uintx max_heap_for_compressed_oops() { +bool Arguments::apply_ergonomics_on_classmetaspacesize() { + return FLAG_IS_DEFAULT(ClassMetaspaceSize); +} + +size_t Arguments::max_heap_for_compressed_oops() { + // determine the maximum heap size that allows compressed oops. Use the theoretical + // maximum (OopEncodingHeapMax) and subtract the sizes of other areas that need + // to be below that maximum. Use a conservative estimate on the alignment returned + // by max_heap_alignment() to calculate these estimates for the other areas. + // We need to apply the alignment on all areas separately to make sure that later, + // when aligning the final heap size up, all sizes fit below the absolute maximum. + + // the absolute theoretical maximum for the heap with compressed oops + size_t max_total_heap = OopEncodingHeapMax; + + size_t max_class_metaspace_size = ClassMetaspaceSize; + if (apply_ergonomics_on_classmetaspacesize()) { + max_class_metaspace_size = MAX2(max_class_metaspace_size, ErgoClassMetaspaceSize); + } + size_t aligned_metaspace_size = align_size_up_(max_class_metaspace_size, max_heap_alignment()); + size_t aligned_page_size = align_size_up_(os::vm_page_size(), max_heap_alignment()); // Avoid sign flip. - if (OopEncodingHeapMax < ClassMetaspaceSize + os::vm_page_size()) { + if (max_total_heap < aligned_metaspace_size + aligned_page_size) { return 0; } - LP64_ONLY(return OopEncodingHeapMax - ClassMetaspaceSize - os::vm_page_size()); + LP64_ONLY(return max_total_heap - aligned_metaspace_size - aligned_page_size); NOT_LP64(ShouldNotReachHere(); return 0); } @@ -1415,6 +1439,23 @@ #endif // ZERO } +void Arguments::set_max_heap_alignment() { + size_t gc_alignment; +#if INCLUDE_ALL_GCS + if (UseParallelGC) { + gc_alignment = ParallelScavengeHeap::max_heap_alignment(); + } else if (UseG1GC) { + gc_alignment = G1CollectedHeap::max_heap_alignment(); + } else { +#endif // INCLUDE_ALL_GCS + gc_alignment = GenCollectedHeap::max_heap_alignment(); +#if INCLUDE_ALL_GCS + } +#endif // INCLUDE_ALL_GCS + _max_heap_alignment = MAX3(gc_alignment, os::max_page_size(), + CollectorPolicy::compute_max_alignment()); +} + void Arguments::set_ergonomics_flags() { if (os::is_server_class_machine()) { @@ -1442,6 +1483,8 @@ } } + set_max_heap_alignment(); + #ifndef ZERO #ifdef _LP64 set_use_compressed_oops(); @@ -1462,13 +1505,8 @@ if (ClassMetaspaceSize > KlassEncodingMetaspaceMax) { warning("Class metaspace size is too large for UseCompressedKlassPointers"); FLAG_SET_DEFAULT(UseCompressedKlassPointers, false); - } else if (FLAG_IS_DEFAULT(ClassMetaspaceSize)) { - // 100,000 classes seems like a good size, so 100M assumes around 1K - // per klass. The vtable and oopMap is embedded so we don't have a fixed - // size per klass. Eventually, this will be parameterized because it - // would also be useful to determine the optimal size of the - // systemDictionary. - FLAG_SET_ERGO(uintx, ClassMetaspaceSize, 100*M); + } else if (apply_ergonomics_on_classmetaspacesize()) { + FLAG_SET_ERGO(uintx, ClassMetaspaceSize, ErgoClassMetaspaceSize); } } } @@ -3501,6 +3539,11 @@ no_shared_spaces(); #endif // INCLUDE_CDS + // We need to initialize large page support here because ergonomics takes some + // decisions depending on large page support and the calculated large page size. + // Ergonomics may turn off large page support off later again. + os::large_page_init(); + // Set flags based on ergonomics. set_ergonomics_flags();