提交 5781c5e8 编写于 作者: J jwilhelm

8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking

7057939: jmap shows MaxNewSize=4GB when Java is using parallel collector
Summary: Major cleanup of the collectorpolicy classes
Reviewed-by: tschatzl, jcoomes
上级 c96c3803
......@@ -47,8 +47,9 @@
// ConcurrentMarkSweepPolicy methods
//
ConcurrentMarkSweepPolicy::ConcurrentMarkSweepPolicy() {
initialize_all();
void ConcurrentMarkSweepPolicy::initialize_alignments() {
_space_alignment = _gen_alignment = (uintx)Generation::GenGrain;
_heap_alignment = compute_heap_alignment();
}
void ConcurrentMarkSweepPolicy::initialize_generations() {
......
......@@ -29,10 +29,11 @@
class ConcurrentMarkSweepPolicy : public TwoGenerationCollectorPolicy {
protected:
void initialize_alignments();
void initialize_generations();
public:
ConcurrentMarkSweepPolicy();
ConcurrentMarkSweepPolicy() {}
ConcurrentMarkSweepPolicy* as_concurrent_mark_sweep_policy() { return this; }
......
......@@ -2008,7 +2008,7 @@ jint G1CollectedHeap::initialize() {
size_t init_byte_size = collector_policy()->initial_heap_byte_size();
size_t max_byte_size = collector_policy()->max_heap_byte_size();
size_t heap_alignment = collector_policy()->max_alignment();
size_t heap_alignment = collector_policy()->heap_alignment();
// Ensure that the sizes are properly aligned.
Universe::check_alignment(init_byte_size, HeapRegion::GrainBytes, "g1 heap");
......
......@@ -313,27 +313,38 @@ G1CollectorPolicy::G1CollectorPolicy() :
// for the first time during initialization.
_reserve_regions = 0;
initialize_all();
_collectionSetChooser = new CollectionSetChooser();
_young_gen_sizer = new G1YoungGenSizer(); // Must be after call to initialize_flags
}
void G1CollectorPolicy::initialize_flags() {
_min_alignment = HeapRegion::GrainBytes;
void G1CollectorPolicy::initialize_alignments() {
_space_alignment = HeapRegion::GrainBytes;
size_t card_table_alignment = GenRemSet::max_alignment_constraint(GenRemSet::CardTable);
size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
_max_alignment = MAX3(card_table_alignment, _min_alignment, page_size);
_heap_alignment = MAX3(card_table_alignment, _space_alignment, page_size);
}
void G1CollectorPolicy::initialize_flags() {
if (G1HeapRegionSize != HeapRegion::GrainBytes) {
FLAG_SET_ERGO(uintx, G1HeapRegionSize, HeapRegion::GrainBytes);
}
if (SurvivorRatio < 1) {
vm_exit_during_initialization("Invalid survivor ratio specified");
}
CollectorPolicy::initialize_flags();
_young_gen_sizer = new G1YoungGenSizer(); // Must be after call to initialize_flags
}
G1YoungGenSizer::G1YoungGenSizer() : _sizer_kind(SizerDefaults), _adaptive_size(true) {
assert(G1NewSizePercent <= G1MaxNewSizePercent, "Min larger than max");
assert(G1NewSizePercent > 0 && G1NewSizePercent < 100, "Min out of bounds");
assert(G1MaxNewSizePercent > 0 && G1MaxNewSizePercent < 100, "Max out of bounds");
void G1CollectorPolicy::post_heap_initialize() {
uintx max_regions = G1CollectedHeap::heap()->max_regions();
size_t max_young_size = (size_t)_young_gen_sizer->max_young_length(max_regions) * HeapRegion::GrainBytes;
if (max_young_size != MaxNewSize) {
FLAG_SET_ERGO(uintx, MaxNewSize, max_young_size);
}
}
G1YoungGenSizer::G1YoungGenSizer() : _sizer_kind(SizerDefaults), _adaptive_size(true),
_min_desired_young_length(0), _max_desired_young_length(0) {
if (FLAG_IS_CMDLINE(NewRatio)) {
if (FLAG_IS_CMDLINE(NewSize) || FLAG_IS_CMDLINE(MaxNewSize)) {
warning("-XX:NewSize and -XX:MaxNewSize override -XX:NewRatio");
......@@ -344,8 +355,13 @@ G1YoungGenSizer::G1YoungGenSizer() : _sizer_kind(SizerDefaults), _adaptive_size(
}
}
if (FLAG_IS_CMDLINE(NewSize) && FLAG_IS_CMDLINE(MaxNewSize) && NewSize > MaxNewSize) {
vm_exit_during_initialization("Initial young gen size set larger than the maximum young gen size");
if (NewSize > MaxNewSize) {
if (FLAG_IS_CMDLINE(MaxNewSize)) {
warning("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). "
"A new max generation size of " SIZE_FORMAT "k will be used.",
NewSize/K, MaxNewSize/K, NewSize/K);
}
MaxNewSize = NewSize;
}
if (FLAG_IS_CMDLINE(NewSize)) {
......@@ -378,34 +394,48 @@ uint G1YoungGenSizer::calculate_default_max_length(uint new_number_of_heap_regio
return MAX2(1U, default_value);
}
void G1YoungGenSizer::heap_size_changed(uint new_number_of_heap_regions) {
assert(new_number_of_heap_regions > 0, "Heap must be initialized");
void G1YoungGenSizer::recalculate_min_max_young_length(uint number_of_heap_regions, uint* min_young_length, uint* max_young_length) {
assert(number_of_heap_regions > 0, "Heap must be initialized");
switch (_sizer_kind) {
case SizerDefaults:
_min_desired_young_length = calculate_default_min_length(new_number_of_heap_regions);
_max_desired_young_length = calculate_default_max_length(new_number_of_heap_regions);
*min_young_length = calculate_default_min_length(number_of_heap_regions);
*max_young_length = calculate_default_max_length(number_of_heap_regions);
break;
case SizerNewSizeOnly:
_max_desired_young_length = calculate_default_max_length(new_number_of_heap_regions);
_max_desired_young_length = MAX2(_min_desired_young_length, _max_desired_young_length);
*max_young_length = calculate_default_max_length(number_of_heap_regions);
*max_young_length = MAX2(*min_young_length, *max_young_length);
break;
case SizerMaxNewSizeOnly:
_min_desired_young_length = calculate_default_min_length(new_number_of_heap_regions);
_min_desired_young_length = MIN2(_min_desired_young_length, _max_desired_young_length);
*min_young_length = calculate_default_min_length(number_of_heap_regions);
*min_young_length = MIN2(*min_young_length, *max_young_length);
break;
case SizerMaxAndNewSize:
// Do nothing. Values set on the command line, don't update them at runtime.
break;
case SizerNewRatio:
_min_desired_young_length = new_number_of_heap_regions / (NewRatio + 1);
_max_desired_young_length = _min_desired_young_length;
*min_young_length = number_of_heap_regions / (NewRatio + 1);
*max_young_length = *min_young_length;
break;
default:
ShouldNotReachHere();
}
assert(_min_desired_young_length <= _max_desired_young_length, "Invalid min/max young gen size values");
assert(*min_young_length <= *max_young_length, "Invalid min/max young gen size values");
}
uint G1YoungGenSizer::max_young_length(uint number_of_heap_regions) {
// We need to pass the desired values because recalculation may not update these
// values in some cases.
uint temp = _min_desired_young_length;
uint result = _max_desired_young_length;
recalculate_min_max_young_length(number_of_heap_regions, &temp, &result);
return result;
}
void G1YoungGenSizer::heap_size_changed(uint new_number_of_heap_regions) {
recalculate_min_max_young_length(new_number_of_heap_regions, &_min_desired_young_length,
&_max_desired_young_length);
}
void G1CollectorPolicy::init() {
......
......@@ -136,8 +136,16 @@ private:
uint calculate_default_min_length(uint new_number_of_heap_regions);
uint calculate_default_max_length(uint new_number_of_heap_regions);
// Update the given values for minimum and maximum young gen length in regions
// given the number of heap regions depending on the kind of sizing algorithm.
void recalculate_min_max_young_length(uint number_of_heap_regions, uint* min_young_length, uint* max_young_length);
public:
G1YoungGenSizer();
// Calculate the maximum length of the young gen given the number of regions
// depending on the sizing algorithm.
uint max_young_length(uint number_of_heap_regions);
void heap_size_changed(uint new_number_of_heap_regions);
uint min_desired_young_length() {
return _min_desired_young_length;
......@@ -165,13 +173,9 @@ private:
G1MMUTracker* _mmu_tracker;
void initialize_alignments();
void initialize_flags();
void initialize_all() {
initialize_flags();
initialize_size_info();
}
CollectionSetChooser* _collectionSetChooser;
double _full_collection_start_sec;
......@@ -931,6 +935,7 @@ public:
// Calculates survivor space parameters.
void update_survivors_policy();
virtual void post_heap_initialize();
};
// This should move to some place more general...
......
......@@ -174,11 +174,6 @@ void HeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_hea
region_size = MAX_REGION_SIZE;
}
if (region_size != G1HeapRegionSize) {
// Update the flag to make sure that PrintFlagsFinal logs the correct value
FLAG_SET_ERGO(uintx, G1HeapRegionSize, region_size);
}
// And recalculate the log.
region_size_log = log2_long((jlong) region_size);
......
......@@ -25,6 +25,7 @@
#include "precompiled.hpp"
#include "gc_implementation/parallelScavenge/adjoiningGenerations.hpp"
#include "gc_implementation/parallelScavenge/adjoiningVirtualSpaces.hpp"
#include "gc_implementation/parallelScavenge/generationSizer.hpp"
#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
// If boundary moving is being used, create the young gen and old
......@@ -32,15 +33,17 @@
// the old behavior otherwise (with PSYoungGen and PSOldGen).
AdjoiningGenerations::AdjoiningGenerations(ReservedSpace old_young_rs,
size_t init_low_byte_size,
size_t min_low_byte_size,
size_t max_low_byte_size,
size_t init_high_byte_size,
size_t min_high_byte_size,
size_t max_high_byte_size,
GenerationSizer* policy,
size_t alignment) :
_virtual_spaces(old_young_rs, min_low_byte_size,
min_high_byte_size, alignment) {
_virtual_spaces(old_young_rs, policy->min_gen1_size(),
policy->min_gen0_size(), alignment) {
size_t init_low_byte_size = policy->initial_gen1_size();
size_t min_low_byte_size = policy->min_gen1_size();
size_t max_low_byte_size = policy->max_gen1_size();
size_t init_high_byte_size = policy->initial_gen0_size();
size_t min_high_byte_size = policy->min_gen0_size();
size_t max_high_byte_size = policy->max_gen0_size();
assert(min_low_byte_size <= init_low_byte_size &&
init_low_byte_size <= max_low_byte_size, "Parameter check");
assert(min_high_byte_size <= init_high_byte_size &&
......
......@@ -28,6 +28,7 @@
#include "gc_implementation/parallelScavenge/adjoiningVirtualSpaces.hpp"
#include "gc_implementation/parallelScavenge/asPSOldGen.hpp"
#include "gc_implementation/parallelScavenge/asPSYoungGen.hpp"
#include "gc_implementation/parallelScavenge/generationSizer.hpp"
// Contains two generations that both use an AdjoiningVirtualSpaces.
......@@ -56,14 +57,7 @@ class AdjoiningGenerations : public CHeapObj<mtGC> {
bool request_young_gen_expansion(size_t desired_change_in_bytes);
public:
AdjoiningGenerations(ReservedSpace rs,
size_t init_low_byte_size,
size_t min_low_byte_size,
size_t max_low_byte_size,
size_t init_high_byte_size,
size_t min_high_byte_size,
size_t max_high_bytes_size,
size_t alignment);
AdjoiningGenerations(ReservedSpace rs, GenerationSizer* policy, size_t alignment);
// Accessors
PSYoungGen* young_gen() { return _young_gen; }
......
......@@ -91,7 +91,7 @@ size_t ASPSOldGen::available_for_expansion() {
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
size_t result = gen_size_limit() - virtual_space()->committed_size();
size_t result_aligned = align_size_down(result, heap->old_gen_alignment());
size_t result_aligned = align_size_down(result, heap->generation_alignment());
return result_aligned;
}
......@@ -102,7 +102,7 @@ size_t ASPSOldGen::available_for_contraction() {
}
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
const size_t gen_alignment = heap->old_gen_alignment();
const size_t gen_alignment = heap->generation_alignment();
PSAdaptiveSizePolicy* policy = heap->size_policy();
const size_t working_size =
used_in_bytes() + (size_t) policy->avg_promoted()->padded_average();
......
......@@ -75,7 +75,7 @@ size_t ASPSYoungGen::available_for_expansion() {
"generation size limit is wrong");
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
size_t result = gen_size_limit() - current_committed_size;
size_t result_aligned = align_size_down(result, heap->young_gen_alignment());
size_t result_aligned = align_size_down(result, heap->generation_alignment());
return result_aligned;
}
......@@ -92,8 +92,8 @@ size_t ASPSYoungGen::available_for_contraction() {
if (eden_space()->is_empty()) {
// Respect the minimum size for eden and for the young gen as a whole.
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
const size_t eden_alignment = heap->intra_heap_alignment();
const size_t gen_alignment = heap->young_gen_alignment();
const size_t eden_alignment = heap->space_alignment();
const size_t gen_alignment = heap->generation_alignment();
assert(eden_space()->capacity_in_bytes() >= eden_alignment,
"Alignment is wrong");
......@@ -129,7 +129,7 @@ size_t ASPSYoungGen::available_for_contraction() {
// to_space can be.
size_t ASPSYoungGen::available_to_live() {
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
const size_t alignment = heap->intra_heap_alignment();
const size_t alignment = heap->space_alignment();
// Include any space that is committed but is not in eden.
size_t available = pointer_delta(eden_space()->bottom(),
......@@ -293,7 +293,7 @@ void ASPSYoungGen::resize_spaces(size_t requested_eden_size,
assert(eden_start < from_start, "Cannot push into from_space");
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
const size_t alignment = heap->intra_heap_alignment();
const size_t alignment = heap->space_alignment();
const bool maintain_minimum =
(requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
......
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "gc_implementation/parallelScavenge/generationSizer.hpp"
#include "memory/collectorPolicy.hpp"
void GenerationSizer::trace_gen_sizes(const char* const str) {
if (TracePageSizes) {
tty->print_cr("%s: " SIZE_FORMAT "," SIZE_FORMAT " "
SIZE_FORMAT "," SIZE_FORMAT " "
SIZE_FORMAT,
str,
_min_gen1_size / K, _max_gen1_size / K,
_min_gen0_size / K, _max_gen0_size / K,
_max_heap_byte_size / K);
}
}
void GenerationSizer::initialize_alignments() {
_space_alignment = _gen_alignment = default_gen_alignment();
_heap_alignment = compute_heap_alignment();
}
void GenerationSizer::initialize_flags() {
// Do basic sizing work
TwoGenerationCollectorPolicy::initialize_flags();
assert(UseSerialGC ||
!FLAG_IS_DEFAULT(ParallelGCThreads) ||
(ParallelGCThreads > 0),
"ParallelGCThreads should be set before flag initialization");
// The survivor ratio's are calculated "raw", unlike the
// default gc, which adds 2 to the ratio value. We need to
// make sure the values are valid before using them.
if (MinSurvivorRatio < 3) {
FLAG_SET_ERGO(uintx, MinSurvivorRatio, 3);
}
if (InitialSurvivorRatio < 3) {
FLAG_SET_ERGO(uintx, InitialSurvivorRatio, 3);
}
}
void GenerationSizer::initialize_size_info() {
trace_gen_sizes("ps heap raw");
const size_t page_sz = os::page_size_for_region(_min_heap_byte_size,
_max_heap_byte_size,
8);
// Can a page size be something else than a power of two?
assert(is_power_of_2((intptr_t)page_sz), "must be a power of 2");
size_t new_alignment = round_to(page_sz, _gen_alignment);
if (new_alignment != _gen_alignment) {
_gen_alignment = new_alignment;
// Redo everything from the start
initialize_flags();
}
TwoGenerationCollectorPolicy::initialize_size_info();
trace_gen_sizes("ps heap rnd");
}
......@@ -31,41 +31,17 @@
// TwoGenerationCollectorPolicy. Lets reuse it!
class GenerationSizer : public TwoGenerationCollectorPolicy {
public:
GenerationSizer() {
// Partial init only!
initialize_flags();
initialize_size_info();
}
private:
void initialize_flags() {
// Do basic sizing work
TwoGenerationCollectorPolicy::initialize_flags();
void trace_gen_sizes(const char* const str);
assert(UseSerialGC ||
!FLAG_IS_DEFAULT(ParallelGCThreads) ||
(ParallelGCThreads > 0),
"ParallelGCThreads should be set before flag initialization");
// The alignment used for boundary between young gen and old gen
static size_t default_gen_alignment() { return 64 * K * HeapWordSize; }
// The survivor ratio's are calculated "raw", unlike the
// default gc, which adds 2 to the ratio value. We need to
// make sure the values are valid before using them.
if (MinSurvivorRatio < 3) {
MinSurvivorRatio = 3;
}
protected:
if (InitialSurvivorRatio < 3) {
InitialSurvivorRatio = 3;
}
}
size_t min_young_gen_size() { return _min_gen0_size; }
size_t young_gen_size() { return _initial_gen0_size; }
size_t max_young_gen_size() { return _max_gen0_size; }
size_t min_old_gen_size() { return _min_gen1_size; }
size_t old_gen_size() { return _initial_gen1_size; }
size_t max_old_gen_size() { return _max_gen1_size; }
void initialize_alignments();
void initialize_flags();
void initialize_size_info();
};
#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_GENERATIONSIZER_HPP
......@@ -52,76 +52,20 @@ PSGCAdaptivePolicyCounters* ParallelScavengeHeap::_gc_policy_counters = NULL;
ParallelScavengeHeap* ParallelScavengeHeap::_psh = NULL;
GCTaskManager* ParallelScavengeHeap::_gc_task_manager = NULL;
static void trace_gen_sizes(const char* const str,
size_t og_min, size_t og_max,
size_t yg_min, size_t yg_max)
{
if (TracePageSizes) {
tty->print_cr("%s: " SIZE_FORMAT "," SIZE_FORMAT " "
SIZE_FORMAT "," SIZE_FORMAT " "
SIZE_FORMAT,
str,
og_min / K, og_max / K,
yg_min / K, yg_max / K,
(og_max + yg_max) / K);
}
}
jint ParallelScavengeHeap::initialize() {
CollectedHeap::pre_initialize();
// Cannot be initialized until after the flags are parsed
// GenerationSizer flag_parser;
// Initialize collector policy
_collector_policy = new GenerationSizer();
_collector_policy->initialize_all();
size_t yg_min_size = _collector_policy->min_young_gen_size();
size_t yg_max_size = _collector_policy->max_young_gen_size();
size_t og_min_size = _collector_policy->min_old_gen_size();
size_t og_max_size = _collector_policy->max_old_gen_size();
trace_gen_sizes("ps heap raw",
og_min_size, og_max_size,
yg_min_size, yg_max_size);
const size_t og_page_sz = os::page_size_for_region(yg_min_size + og_min_size,
yg_max_size + og_max_size,
8);
const size_t og_align = set_alignment(_old_gen_alignment, og_page_sz);
const size_t yg_align = set_alignment(_young_gen_alignment, og_page_sz);
// Update sizes to reflect the selected page size(s).
//
// NEEDS_CLEANUP. The default TwoGenerationCollectorPolicy uses NewRatio; it
// should check UseAdaptiveSizePolicy. Changes from generationSizer could
// move to the common code.
yg_min_size = align_size_up(yg_min_size, yg_align);
yg_max_size = align_size_up(yg_max_size, yg_align);
size_t yg_cur_size =
align_size_up(_collector_policy->young_gen_size(), yg_align);
yg_cur_size = MAX2(yg_cur_size, yg_min_size);
og_min_size = align_size_up(og_min_size, og_align);
// Align old gen size down to preserve specified heap size.
assert(og_align == yg_align, "sanity");
og_max_size = align_size_down(og_max_size, og_align);
og_max_size = MAX2(og_max_size, og_min_size);
size_t og_cur_size =
align_size_down(_collector_policy->old_gen_size(), og_align);
og_cur_size = MAX2(og_cur_size, og_min_size);
trace_gen_sizes("ps heap rnd",
og_min_size, og_max_size,
yg_min_size, yg_max_size);
const size_t heap_size = og_max_size + yg_max_size;
ReservedSpace heap_rs = Universe::reserve_heap(heap_size, og_align);
const size_t heap_size = _collector_policy->max_heap_byte_size();
ReservedSpace heap_rs = Universe::reserve_heap(heap_size, _collector_policy->heap_alignment());
MemTracker::record_virtual_memory_type((address)heap_rs.base(), mtJavaHeap);
os::trace_page_sizes("ps main", og_min_size + yg_min_size,
og_max_size + yg_max_size, og_page_sz,
os::trace_page_sizes("ps main", _collector_policy->min_heap_byte_size(),
heap_size, generation_alignment(),
heap_rs.base(),
heap_rs.size());
if (!heap_rs.is_reserved()) {
......@@ -142,12 +86,6 @@ jint ParallelScavengeHeap::initialize() {
return JNI_ENOMEM;
}
// Initial young gen size is 4 Mb
//
// XXX - what about flag_parser.young_gen_size()?
const size_t init_young_size = align_size_up(4 * M, yg_align);
yg_cur_size = MAX2(MIN2(init_young_size, yg_max_size), yg_cur_size);
// Make up the generations
// Calculate the maximum size that a generation can grow. This
// includes growth into the other generation. Note that the
......@@ -157,14 +95,7 @@ jint ParallelScavengeHeap::initialize() {
double max_gc_pause_sec = ((double) MaxGCPauseMillis)/1000.0;
double max_gc_minor_pause_sec = ((double) MaxGCMinorPauseMillis)/1000.0;
_gens = new AdjoiningGenerations(heap_rs,
og_cur_size,
og_min_size,
og_max_size,
yg_cur_size,
yg_min_size,
yg_max_size,
yg_align);
_gens = new AdjoiningGenerations(heap_rs, _collector_policy, generation_alignment());
_old_gen = _gens->old_gen();
_young_gen = _gens->young_gen();
......@@ -176,7 +107,7 @@ jint ParallelScavengeHeap::initialize() {
new PSAdaptiveSizePolicy(eden_capacity,
initial_promo_size,
young_gen()->to_space()->capacity_in_bytes(),
intra_heap_alignment(),
_collector_policy->gen_alignment(),
max_gc_pause_sec,
max_gc_minor_pause_sec,
GCTimeRatio
......
......@@ -25,6 +25,7 @@
#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP
#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP
#include "gc_implementation/parallelScavenge/generationSizer.hpp"
#include "gc_implementation/parallelScavenge/objectStartArray.hpp"
#include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp"
#include "gc_implementation/parallelScavenge/psOldGen.hpp"
......@@ -32,13 +33,12 @@
#include "gc_implementation/shared/gcPolicyCounters.hpp"
#include "gc_implementation/shared/gcWhen.hpp"
#include "gc_interface/collectedHeap.inline.hpp"
#include "memory/collectorPolicy.hpp"
#include "utilities/ostream.hpp"
class AdjoiningGenerations;
class GCHeapSummary;
class GCTaskManager;
class GenerationSizer;
class CollectorPolicy;
class PSAdaptiveSizePolicy;
class PSHeapSummary;
......@@ -54,13 +54,8 @@ class ParallelScavengeHeap : public CollectedHeap {
static ParallelScavengeHeap* _psh;
size_t _young_gen_alignment;
size_t _old_gen_alignment;
GenerationSizer* _collector_policy;
inline size_t set_alignment(size_t& var, size_t val);
// Collection of generations that are adjacent in the
// space reserved for the heap.
AdjoiningGenerations* _gens;
......@@ -80,15 +75,7 @@ class ParallelScavengeHeap : public CollectedHeap {
HeapWord* mem_allocate_old_gen(size_t size);
public:
ParallelScavengeHeap() : CollectedHeap(), _death_march_count(0) {
set_alignment(_young_gen_alignment, intra_heap_alignment());
set_alignment(_old_gen_alignment, intra_heap_alignment());
}
// Return the (conservative) maximum heap alignment
static size_t conservative_max_heap_alignment() {
return GenCollectorPolicy::intra_heap_alignment();
}
ParallelScavengeHeap() : CollectedHeap(), _death_march_count(0) { }
// For use by VM operations
enum CollectionType {
......@@ -120,13 +107,15 @@ class ParallelScavengeHeap : public CollectedHeap {
void post_initialize();
void update_counters();
// The alignment used for the various generations.
size_t young_gen_alignment() const { return _young_gen_alignment; }
size_t old_gen_alignment() const { return _old_gen_alignment; }
// The alignment used for eden and survivors within the young gen
// and for boundary between young gen and old gen.
size_t intra_heap_alignment() { return GenCollectorPolicy::intra_heap_alignment(); }
// The alignment used for the various areas
size_t space_alignment() { return _collector_policy->space_alignment(); }
size_t generation_alignment() { return _collector_policy->gen_alignment(); }
// Return the (conservative) maximum heap alignment
static size_t conservative_max_heap_alignment() {
return CollectorPolicy::compute_heap_alignment();
}
size_t capacity() const;
size_t used() const;
......@@ -261,11 +250,4 @@ class ParallelScavengeHeap : public CollectedHeap {
};
};
inline size_t ParallelScavengeHeap::set_alignment(size_t& var, size_t val)
{
assert(is_power_of_2((intptr_t)val), "must be a power of 2");
var = round_to(val, intra_heap_alignment());
return var;
}
#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP
......@@ -37,7 +37,7 @@
PSAdaptiveSizePolicy::PSAdaptiveSizePolicy(size_t init_eden_size,
size_t init_promo_size,
size_t init_survivor_size,
size_t intra_generation_alignment,
size_t space_alignment,
double gc_pause_goal_sec,
double gc_minor_pause_goal_sec,
uint gc_cost_ratio) :
......@@ -47,7 +47,7 @@ PSAdaptiveSizePolicy::PSAdaptiveSizePolicy(size_t init_eden_size,
gc_pause_goal_sec,
gc_cost_ratio),
_collection_cost_margin_fraction(AdaptiveSizePolicyCollectionCostMargin / 100.0),
_intra_generation_alignment(intra_generation_alignment),
_space_alignment(space_alignment),
_live_at_last_full_gc(init_promo_size),
_gc_minor_pause_goal_sec(gc_minor_pause_goal_sec),
_latest_major_mutator_interval_seconds(0),
......@@ -352,11 +352,10 @@ void PSAdaptiveSizePolicy::compute_eden_space_size(
}
// Align everything and make a final limit check
const size_t alignment = _intra_generation_alignment;
desired_eden_size = align_size_up(desired_eden_size, alignment);
desired_eden_size = MAX2(desired_eden_size, alignment);
desired_eden_size = align_size_up(desired_eden_size, _space_alignment);
desired_eden_size = MAX2(desired_eden_size, _space_alignment);
eden_limit = align_size_down(eden_limit, alignment);
eden_limit = align_size_down(eden_limit, _space_alignment);
// And one last limit check, now that we've aligned things.
if (desired_eden_size > eden_limit) {
......@@ -560,11 +559,10 @@ void PSAdaptiveSizePolicy::compute_old_gen_free_space(
}
// Align everything and make a final limit check
const size_t alignment = _intra_generation_alignment;
desired_promo_size = align_size_up(desired_promo_size, alignment);
desired_promo_size = MAX2(desired_promo_size, alignment);
desired_promo_size = align_size_up(desired_promo_size, _space_alignment);
desired_promo_size = MAX2(desired_promo_size, _space_alignment);
promo_limit = align_size_down(promo_limit, alignment);
promo_limit = align_size_down(promo_limit, _space_alignment);
// And one last limit check, now that we've aligned things.
desired_promo_size = MIN2(desired_promo_size, promo_limit);
......@@ -649,7 +647,7 @@ void PSAdaptiveSizePolicy::adjust_promo_for_minor_pause_time(bool is_full_gc,
}
// If the desired eden size is as small as it will get,
// try to adjust the old gen size.
if (*desired_eden_size_ptr <= _intra_generation_alignment) {
if (*desired_eden_size_ptr <= _space_alignment) {
// Vary the old gen size to reduce the young gen pause. This
// may not be a good idea. This is just a test.
if (minor_pause_old_estimator()->decrement_will_decrease()) {
......@@ -754,7 +752,7 @@ void PSAdaptiveSizePolicy::adjust_eden_for_pause_time(bool is_full_gc,
// If the promo size is at the minimum (i.e., the old gen
// size will not actually decrease), consider changing the
// young gen size.
if (*desired_promo_size_ptr < _intra_generation_alignment) {
if (*desired_promo_size_ptr < _space_alignment) {
// If increasing the young generation will decrease the old gen
// pause, do it.
// During startup there is noise in the statistics for deciding
......@@ -1065,24 +1063,24 @@ size_t PSAdaptiveSizePolicy::eden_increment(size_t cur_eden) {
size_t PSAdaptiveSizePolicy::eden_increment_aligned_up(size_t cur_eden) {
size_t result = eden_increment(cur_eden, YoungGenerationSizeIncrement);
return align_size_up(result, _intra_generation_alignment);
return align_size_up(result, _space_alignment);
}
size_t PSAdaptiveSizePolicy::eden_increment_aligned_down(size_t cur_eden) {
size_t result = eden_increment(cur_eden);
return align_size_down(result, _intra_generation_alignment);
return align_size_down(result, _space_alignment);
}
size_t PSAdaptiveSizePolicy::eden_increment_with_supplement_aligned_up(
size_t cur_eden) {
size_t result = eden_increment(cur_eden,
YoungGenerationSizeIncrement + _young_gen_size_increment_supplement);
return align_size_up(result, _intra_generation_alignment);
return align_size_up(result, _space_alignment);
}
size_t PSAdaptiveSizePolicy::eden_decrement_aligned_down(size_t cur_eden) {
size_t eden_heap_delta = eden_decrement(cur_eden);
return align_size_down(eden_heap_delta, _intra_generation_alignment);
return align_size_down(eden_heap_delta, _space_alignment);
}
size_t PSAdaptiveSizePolicy::eden_decrement(size_t cur_eden) {
......@@ -1104,24 +1102,24 @@ size_t PSAdaptiveSizePolicy::promo_increment(size_t cur_promo) {
size_t PSAdaptiveSizePolicy::promo_increment_aligned_up(size_t cur_promo) {
size_t result = promo_increment(cur_promo, TenuredGenerationSizeIncrement);
return align_size_up(result, _intra_generation_alignment);
return align_size_up(result, _space_alignment);
}
size_t PSAdaptiveSizePolicy::promo_increment_aligned_down(size_t cur_promo) {
size_t result = promo_increment(cur_promo, TenuredGenerationSizeIncrement);
return align_size_down(result, _intra_generation_alignment);
return align_size_down(result, _space_alignment);
}
size_t PSAdaptiveSizePolicy::promo_increment_with_supplement_aligned_up(
size_t cur_promo) {
size_t result = promo_increment(cur_promo,
TenuredGenerationSizeIncrement + _old_gen_size_increment_supplement);
return align_size_up(result, _intra_generation_alignment);
return align_size_up(result, _space_alignment);
}
size_t PSAdaptiveSizePolicy::promo_decrement_aligned_down(size_t cur_promo) {
size_t promo_heap_delta = promo_decrement(cur_promo);
return align_size_down(promo_heap_delta, _intra_generation_alignment);
return align_size_down(promo_heap_delta, _space_alignment);
}
size_t PSAdaptiveSizePolicy::promo_decrement(size_t cur_promo) {
......@@ -1134,9 +1132,9 @@ uint PSAdaptiveSizePolicy::compute_survivor_space_size_and_threshold(
bool is_survivor_overflow,
uint tenuring_threshold,
size_t survivor_limit) {
assert(survivor_limit >= _intra_generation_alignment,
assert(survivor_limit >= _space_alignment,
"survivor_limit too small");
assert((size_t)align_size_down(survivor_limit, _intra_generation_alignment)
assert((size_t)align_size_down(survivor_limit, _space_alignment)
== survivor_limit, "survivor_limit not aligned");
// This method is called even if the tenuring threshold and survivor
......@@ -1200,8 +1198,8 @@ uint PSAdaptiveSizePolicy::compute_survivor_space_size_and_threshold(
// We're trying to pad the survivor size as little as possible without
// overflowing the survivor spaces.
size_t target_size = align_size_up((size_t)_avg_survived->padded_average(),
_intra_generation_alignment);
target_size = MAX2(target_size, _intra_generation_alignment);
_space_alignment);
target_size = MAX2(target_size, _space_alignment);
if (target_size > survivor_limit) {
// Target size is bigger than we can handle. Let's also reduce
......
......@@ -91,7 +91,7 @@ class PSAdaptiveSizePolicy : public AdaptiveSizePolicy {
// for making ergonomic decisions.
double _latest_major_mutator_interval_seconds;
const size_t _intra_generation_alignment; // alignment for eden, survivors
const size_t _space_alignment; // alignment for eden, survivors
const double _gc_minor_pause_goal_sec; // goal for maximum minor gc pause
......@@ -229,7 +229,7 @@ class PSAdaptiveSizePolicy : public AdaptiveSizePolicy {
PSAdaptiveSizePolicy(size_t init_eden_size,
size_t init_promo_size,
size_t init_survivor_size,
size_t intra_generation_alignment,
size_t space_alignment,
double gc_pause_goal_sec,
double gc_minor_pause_goal_sec,
uint gc_time_ratio);
......@@ -378,7 +378,7 @@ class PSAdaptiveSizePolicy : public AdaptiveSizePolicy {
// remain almost full anyway (top() will be near end(), but there will be a
// large filler object at the bottom).
const size_t sz = gen_size / MinSurvivorRatio;
const size_t alignment = _intra_generation_alignment;
const size_t alignment = _space_alignment;
return sz > alignment ? align_size_down(sz, alignment) : alignment;
}
......
......@@ -103,7 +103,7 @@ void PSYoungGen::initialize_work() {
// Compute maximum space sizes for performance counters
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
size_t alignment = heap->intra_heap_alignment();
size_t alignment = heap->space_alignment();
size_t size = virtual_space()->reserved_size();
size_t max_survivor_size;
......@@ -156,8 +156,9 @@ void PSYoungGen::compute_initial_space_boundaries() {
assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
// Compute sizes
size_t alignment = heap->intra_heap_alignment();
size_t alignment = heap->space_alignment();
size_t size = virtual_space()->committed_size();
assert(size >= 3 * alignment, "Young space is not large enough for eden + 2 survivors");
size_t survivor_size = size / InitialSurvivorRatio;
survivor_size = align_size_down(survivor_size, alignment);
......@@ -207,7 +208,7 @@ void PSYoungGen::set_space_boundaries(size_t eden_size, size_t survivor_size) {
#ifndef PRODUCT
void PSYoungGen::space_invariants() {
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
const size_t alignment = heap->intra_heap_alignment();
const size_t alignment = heap->space_alignment();
// Currently, our eden size cannot shrink to zero
guarantee(eden_space()->capacity_in_bytes() >= alignment, "eden too small");
......@@ -491,7 +492,7 @@ void PSYoungGen::resize_spaces(size_t requested_eden_size,
char* to_end = (char*)to_space()->end();
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
const size_t alignment = heap->intra_heap_alignment();
const size_t alignment = heap->space_alignment();
const bool maintain_minimum =
(requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
......@@ -840,8 +841,8 @@ size_t PSYoungGen::available_to_min_gen() {
size_t PSYoungGen::available_to_live() {
size_t delta_in_survivor = 0;
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
const size_t space_alignment = heap->intra_heap_alignment();
const size_t gen_alignment = heap->young_gen_alignment();
const size_t space_alignment = heap->space_alignment();
const size_t gen_alignment = heap->generation_alignment();
MutableSpace* space_shrinking = NULL;
if (from_space()->end() > to_space()->end()) {
......
......@@ -469,6 +469,10 @@ void CollectedHeap::fill_with_objects(HeapWord* start, size_t words, bool zap)
fill_with_object_impl(start, words, zap);
}
void CollectedHeap::post_initialize() {
collector_policy()->post_heap_initialize();
}
HeapWord* CollectedHeap::allocate_new_tlab(size_t size) {
guarantee(false, "thread-local allocation buffers not supported");
return NULL;
......
......@@ -61,17 +61,23 @@ class CollectorPolicy : public CHeapObj<mtGC> {
protected:
GCPolicyCounters* _gc_policy_counters;
// Requires that the concrete subclass sets the alignment constraints
// before calling.
virtual void initialize_alignments() = 0;
virtual void initialize_flags();
virtual void initialize_size_info();
DEBUG_ONLY(virtual void assert_flags();)
DEBUG_ONLY(virtual void assert_size_info();)
size_t _initial_heap_byte_size;
size_t _max_heap_byte_size;
size_t _min_heap_byte_size;
size_t _min_alignment;
size_t _max_alignment;
size_t _space_alignment;
size_t _heap_alignment;
// Needed to keep information if MaxHeapSize was set on the command line
// when the flag value is aligned etc by ergonomics
bool _max_heap_size_cmdline;
// The sizing of the heap are controlled by a sizing policy.
AdaptiveSizePolicy* _size_policy;
......@@ -87,23 +93,20 @@ class CollectorPolicy : public CHeapObj<mtGC> {
// mem_allocate() where it returns op.result()
bool _all_soft_refs_clear;
CollectorPolicy() :
_min_alignment(1),
_max_alignment(1),
_initial_heap_byte_size(0),
_max_heap_byte_size(0),
_min_heap_byte_size(0),
_size_policy(NULL),
_should_clear_all_soft_refs(false),
_all_soft_refs_clear(false)
{}
CollectorPolicy();
public:
virtual void initialize_all() {
initialize_alignments();
initialize_flags();
initialize_size_info();
}
// Return maximum heap alignment that may be imposed by the policy
static size_t compute_max_alignment();
static size_t compute_heap_alignment();
size_t min_alignment() { return _min_alignment; }
size_t max_alignment() { return _max_alignment; }
size_t space_alignment() { return _space_alignment; }
size_t heap_alignment() { return _heap_alignment; }
size_t initial_heap_byte_size() { return _initial_heap_byte_size; }
size_t max_heap_byte_size() { return _max_heap_byte_size; }
......@@ -195,6 +198,9 @@ class CollectorPolicy : public CHeapObj<mtGC> {
return false;
}
// Do any updates required to global flags that are due to heap initialization
// changes
virtual void post_heap_initialize() = 0;
};
class ClearedAllSoftRefs : public StackObj {
......@@ -219,6 +225,10 @@ class GenCollectorPolicy : public CollectorPolicy {
size_t _initial_gen0_size;
size_t _max_gen0_size;
// _gen_alignment and _space_alignment will have the same value most of the
// time. When using large pages they can differ.
size_t _gen_alignment;
GenerationSpec **_generations;
// Return true if an allocation should be attempted in the older
......@@ -229,23 +239,31 @@ class GenCollectorPolicy : public CollectorPolicy {
void initialize_flags();
void initialize_size_info();
DEBUG_ONLY(void assert_flags();)
DEBUG_ONLY(void assert_size_info();)
// Try to allocate space by expanding the heap.
virtual HeapWord* expand_heap_and_allocate(size_t size, bool is_tlab);
// Scale the base_size by NewRation according to
// Compute max heap alignment
size_t compute_max_alignment();
// Scale the base_size by NewRatio according to
// result = base_size / (NewRatio + 1)
// and align by min_alignment()
size_t scale_by_NewRatio_aligned(size_t base_size);
// Bound the value by the given maximum minus the
// min_alignment.
// Bound the value by the given maximum minus the min_alignment
size_t bound_minus_alignment(size_t desired_size, size_t maximum_size);
public:
GenCollectorPolicy();
// Accessors
size_t min_gen0_size() { return _min_gen0_size; }
size_t initial_gen0_size() { return _initial_gen0_size; }
size_t max_gen0_size() { return _max_gen0_size; }
size_t gen_alignment() { return _gen_alignment; }
virtual int number_of_generations() = 0;
......@@ -256,14 +274,15 @@ class GenCollectorPolicy : public CollectorPolicy {
virtual GenCollectorPolicy* as_generation_policy() { return this; }
virtual void initialize_generations() = 0;
virtual void initialize_generations() { };
virtual void initialize_all() {
initialize_flags();
initialize_size_info();
CollectorPolicy::initialize_all();
initialize_generations();
}
size_t young_gen_size_lower_bound();
HeapWord* mem_allocate_work(size_t size,
bool is_tlab,
bool* gc_overhead_limit_was_exceeded);
......@@ -275,10 +294,8 @@ class GenCollectorPolicy : public CollectorPolicy {
size_t init_promo_size,
size_t init_survivor_size);
// The alignment used for eden and survivors within the young gen
// and for boundary between young gen and old gen.
static size_t intra_heap_alignment() {
return 64 * K * HeapWordSize;
virtual void post_heap_initialize() {
assert(_max_gen0_size == MaxNewSize, "Should be taken care of by initialize_size_info");
}
};
......@@ -296,9 +313,14 @@ class TwoGenerationCollectorPolicy : public GenCollectorPolicy {
void initialize_flags();
void initialize_size_info();
void initialize_generations() { ShouldNotReachHere(); }
DEBUG_ONLY(void assert_flags();)
DEBUG_ONLY(void assert_size_info();)
public:
TwoGenerationCollectorPolicy() : GenCollectorPolicy(), _min_gen1_size(0),
_initial_gen1_size(0), _max_gen1_size(0) {}
// Accessors
size_t min_gen1_size() { return _min_gen1_size; }
size_t initial_gen1_size() { return _initial_gen1_size; }
......@@ -321,10 +343,11 @@ class TwoGenerationCollectorPolicy : public GenCollectorPolicy {
class MarkSweepPolicy : public TwoGenerationCollectorPolicy {
protected:
void initialize_alignments();
void initialize_generations();
public:
MarkSweepPolicy();
MarkSweepPolicy() {}
MarkSweepPolicy* as_mark_sweep_policy() { return this; }
......
......@@ -204,7 +204,7 @@ DefNewGeneration::DefNewGeneration(ReservedSpace rs,
// Compute the maximum eden and survivor space sizes. These sizes
// are computed assuming the entire reserved space is committed.
// These values are exported as performance counters.
uintx alignment = GenCollectedHeap::heap()->collector_policy()->min_alignment();
uintx alignment = GenCollectedHeap::heap()->collector_policy()->space_alignment();
uintx size = _virtual_space.reserved_size();
_max_survivor_size = compute_survivor_size(size, alignment);
_max_eden_size = size - (2*_max_survivor_size);
......@@ -235,7 +235,7 @@ void DefNewGeneration::compute_space_boundaries(uintx minimum_eden_size,
bool clear_space,
bool mangle_space) {
uintx alignment =
GenCollectedHeap::heap()->collector_policy()->min_alignment();
GenCollectedHeap::heap()->collector_policy()->space_alignment();
// If the spaces are being cleared (only done at heap initialization
// currently), the survivor spaces need not be empty.
......@@ -473,7 +473,7 @@ size_t DefNewGeneration::free() const {
}
size_t DefNewGeneration::max_capacity() const {
const size_t alignment = GenCollectedHeap::heap()->collector_policy()->min_alignment();
const size_t alignment = GenCollectedHeap::heap()->collector_policy()->space_alignment();
const size_t reserved_bytes = reserved().byte_size();
return reserved_bytes - compute_survivor_size(reserved_bytes, alignment);
}
......
......@@ -111,7 +111,7 @@ jint GenCollectedHeap::initialize() {
int n_covered_regions = 0;
ReservedSpace heap_rs;
size_t heap_alignment = collector_policy()->max_alignment();
size_t heap_alignment = collector_policy()->heap_alignment();
heap_address = allocate(heap_alignment, &total_reserved,
&n_covered_regions, &heap_rs);
......
......@@ -247,6 +247,7 @@ void SharedHeap::set_barrier_set(BarrierSet* bs) {
}
void SharedHeap::post_initialize() {
CollectedHeap::post_initialize();
ref_processing_init();
}
......
......@@ -765,6 +765,7 @@ jint Universe::initialize_heap() {
} else if (UseG1GC) {
#if INCLUDE_ALL_GCS
G1CollectorPolicy* g1p = new G1CollectorPolicy();
g1p->initialize_all();
G1CollectedHeap* g1h = new G1CollectedHeap(g1p);
Universe::_collectedHeap = g1h;
#else // INCLUDE_ALL_GCS
......@@ -789,6 +790,7 @@ jint Universe::initialize_heap() {
} else { // default old generation
gc_policy = new MarkSweepPolicy();
}
gc_policy->initialize_all();
Universe::_collectedHeap = new GenCollectedHeap(gc_policy);
}
......
......@@ -105,7 +105,7 @@ WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) {
gclog_or_tty->print_cr("Minimum heap "SIZE_FORMAT" Initial heap "
SIZE_FORMAT" Maximum heap "SIZE_FORMAT" Min alignment "SIZE_FORMAT" Max alignment "SIZE_FORMAT,
p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(),
p->min_alignment(), p->max_alignment());
p->space_alignment(), p->heap_alignment());
}
WB_END
......
......@@ -1505,7 +1505,7 @@ void Arguments::set_conservative_max_heap_alignment() {
}
#endif // INCLUDE_ALL_GCS
_conservative_max_heap_alignment = MAX3(heap_alignment, os::max_page_size(),
CollectorPolicy::compute_max_alignment());
CollectorPolicy::compute_heap_alignment());
}
void Arguments::set_ergonomics_flags() {
......@@ -2165,6 +2165,10 @@ bool Arguments::check_vm_args_consistency() {
#if INCLUDE_ALL_GCS
if (UseG1GC) {
status = status && verify_percentage(G1NewSizePercent, "G1NewSizePercent");
status = status && verify_percentage(G1MaxNewSizePercent, "G1MaxNewSizePercent");
status = status && verify_interval(G1NewSizePercent, 0, G1MaxNewSizePercent, "G1NewSizePercent");
status = status && verify_percentage(InitiatingHeapOccupancyPercent,
"InitiatingHeapOccupancyPercent");
status = status && verify_min_value(G1RefProcDrainInterval, 1,
......
......@@ -64,32 +64,29 @@ class TestMaxHeapSizeTools {
long newPlusOldSize = values[0] + values[1];
long smallValue = newPlusOldSize / 2;
long largeValue = newPlusOldSize * 2;
long maxHeapSize = largeValue + (2 * 1024 * 1024);
// -Xms is not set
checkErgonomics(new String[] { gcflag, "-Xmx16M" }, values, -1, -1);
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue);
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-XX:InitialHeapSize=0" }, values, -1, -1);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize }, values, -1, -1);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=0" }, values, -1, -1);
// -Xms is set to zero
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms0" }, values, -1, -1);
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms0", "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms0", "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue);
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms0", "-XX:InitialHeapSize=0" }, values, -1, -1);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0" }, values, -1, -1);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=0" }, values, -1, -1);
// -Xms is set to small value
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms" + smallValue }, values, -1, -1);
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue);
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms" + smallValue, "-XX:InitialHeapSize=0" }, values, smallValue, -1);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue }, values, -1, -1);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=0" }, values, smallValue, -1);
// -Xms is set to large value
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms" + largeValue }, values, largeValue, largeValue);
// the next case has already been checked elsewhere and gives an error
// checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms" + largeValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
// the next case has already been checked elsewhere too
// checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms" + largeValue, "-XX:InitialHeapSize=" + largeValue }, values, values[0], largeValue);
checkErgonomics(new String[] { gcflag, "-Xmx16M", "-Xms" + largeValue, "-XX:InitialHeapSize=0" }, values, largeValue, -1);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue }, values, largeValue, largeValue);
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue, "-XX:InitialHeapSize=0" }, values, largeValue, -1);
}
private static long align_up(long value, long alignment) {
......
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test TestMaxNewSize
* @key gc
* @bug 7057939
* @summary Make sure that MaxNewSize always has a useful value after argument
* processing.
* @library /testlibrary
* @build TestMaxNewSize
* @run main TestMaxNewSize -XX:+UseSerialGC
* @run main TestMaxNewSize -XX:+UseParallelGC
* @run main TestMaxNewSize -XX:+UseConcMarkSweepGC
* @run main TestMaxNewSize -XX:+UseG1GC
* @author thomas.schatzl@oracle.com, jesper.wilhelmsson@oracle.com
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import com.oracle.java.testlibrary.*;
public class TestMaxNewSize {
private static void checkMaxNewSize(String[] flags, int heapsize) throws Exception {
BigInteger actual = new BigInteger(getMaxNewSize(flags));
System.out.println(actual);
if (actual.compareTo(new BigInteger((new Long(heapsize)).toString())) == 1) {
throw new RuntimeException("MaxNewSize value set to \"" + actual +
"\", expected otherwise when running with the following flags: " + Arrays.asList(flags).toString());
}
}
private static void checkIncompatibleNewSize(String[] flags) throws Exception {
ArrayList<String> finalargs = new ArrayList<String>();
finalargs.addAll(Arrays.asList(flags));
finalargs.add("-version");
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("Initial young gen size set larger than the maximum young gen size");
}
private static boolean isRunningG1(String[] args) {
for (int i = 0; i < args.length; i++) {
if (args[i].contains("+UseG1GC")) {
return true;
}
}
return false;
}
private static String getMaxNewSize(String[] flags) throws Exception {
ArrayList<String> finalargs = new ArrayList<String>();
finalargs.addAll(Arrays.asList(flags));
if (isRunningG1(flags)) {
finalargs.add("-XX:G1HeapRegionSize=1M");
}
finalargs.add("-XX:+PrintFlagsFinal");
finalargs.add("-version");
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);
String stdout = output.getStdout();
//System.out.println(stdout);
return getFlagValue("MaxNewSize", stdout);
}
private static String getFlagValue(String flag, String where) {
Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
if (!m.find()) {
throw new RuntimeException("Could not find value for flag " + flag + " in output string");
}
String match = m.group();
return match.substring(match.lastIndexOf(" ") + 1, match.length());
}
public static void main(String args[]) throws Exception {
String gcName = args[0];
final int M32 = 32 * 1024 * 1024;
final int M64 = 64 * 1024 * 1024;
final int M96 = 96 * 1024 * 1024;
final int M128 = 128 * 1024 * 1024;
checkMaxNewSize(new String[] { gcName, "-Xmx128M" }, M128);
checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewRatio=5" }, M128);
checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewSize=32M" }, M128);
checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:OldSize=96M" }, M128);
checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:MaxNewSize=32M" }, M32);
checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewSize=32M", "-XX:MaxNewSize=32M" }, M32);
checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewRatio=6", "-XX:MaxNewSize=32M" }, M32);
checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-Xms96M" }, M128);
checkMaxNewSize(new String[] { gcName, "-Xmx96M", "-Xms96M" }, M96);
checkMaxNewSize(new String[] { gcName, "-XX:NewSize=128M", "-XX:MaxNewSize=50M"}, M128);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册