--- old/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp 2013-08-29 11:14:52.000000000 +0200 +++ new/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp 2013-08-29 11:14:52.000000000 +0200 @@ -1989,8 +1989,6 @@ CollectedHeap::pre_initialize(); os::enable_vtime(); - G1Log::init(); - // Necessary to satisfy locking discipline assertions. MutexLocker x(Heap_lock); --- old/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp 2013-08-29 11:14:52.000000000 +0200 +++ new/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp 2013-08-29 11:14:52.000000000 +0200 @@ -165,10 +165,20 @@ _gc_overhead_perc(0.0) { + G1Log::init(); + // Set up the region size and associated fields. Given that the // policy is created before the heap, we have to set this up here, - // so it's done as soon as possible. - HeapRegion::setup_heap_region_size(Arguments::min_heap_size()); + // so it's done as soon as possible + + // It would have been natural to pass initial_heap_byte_size() and + // max_heap_byte_size() to setup_heap_region_size() but those have + // not been set up at this point since they should be aligned with + // the region size. So, there is a circular dependency here. We base + // the region size on the heap size, but the heap size should be + // aligned with the region size. To get around this we use the + // unaligned values for the heap. + HeapRegion::setup_heap_region_size(InitialHeapSize, MaxHeapSize); HeapRegionRemSet::setup_remset_size(); G1ErgoVerbose::initialize(); --- old/src/share/vm/gc_implementation/g1/heapRegion.cpp 2013-08-29 11:14:53.000000000 +0200 +++ new/src/share/vm/gc_implementation/g1/heapRegion.cpp 2013-08-29 11:14:53.000000000 +0200 @@ -26,6 +26,7 @@ #include "code/nmethod.hpp" #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp" #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" +#include "gc_implementation/g1/g1Log.hpp" #include "gc_implementation/g1/g1OopClosures.inline.hpp" #include "gc_implementation/g1/heapRegion.inline.hpp" #include "gc_implementation/g1/heapRegionRemSet.hpp" @@ -149,18 +150,11 @@ // many regions in the heap (based on the min heap size). #define TARGET_REGION_NUMBER 2048 -void HeapRegion::setup_heap_region_size(uintx min_heap_size) { - // region_size in bytes +void HeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) { uintx region_size = G1HeapRegionSize; if (FLAG_IS_DEFAULT(G1HeapRegionSize)) { - // We base the automatic calculation on the min heap size. This - // can be problematic if the spread between min and max is quite - // wide, imagine -Xms128m -Xmx32g. But, if we decided it based on - // the max size, the region size might be way too large for the - // min size. Either way, some users might have to set the region - // size manually for some -Xms / -Xmx combos. - - region_size = MAX2(min_heap_size / TARGET_REGION_NUMBER, + size_t average_heap_size = (initial_heap_size + max_heap_size) / 2; + region_size = MAX2(average_heap_size / TARGET_REGION_NUMBER, (uintx) MIN_REGION_SIZE); } @@ -185,6 +179,10 @@ // And recalculate the log. region_size_log = log2_long((jlong) region_size); + if (G1Log::fine()) { + gclog_or_tty->print_cr("G1 Heap region size: " SIZE_FORMAT "M", region_size / M); + } + // Now, set up the globals. guarantee(LogOfHRGrainBytes == 0, "we should only set it once"); LogOfHRGrainBytes = region_size_log; --- old/src/share/vm/gc_implementation/g1/heapRegion.hpp 2013-08-29 11:14:53.000000000 +0200 +++ new/src/share/vm/gc_implementation/g1/heapRegion.hpp 2013-08-29 11:14:53.000000000 +0200 @@ -361,7 +361,7 @@ // CardsPerRegion). All those fields are considered constant // throughout the JVM's execution, therefore they should only be set // up once during initialization time. - static void setup_heap_region_size(uintx min_heap_size); + static void setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size); enum ClaimValues { InitialClaimValue = 0,