8076267: Remove n_gens()

Reviewed-by: jprovino, kbarrett, jmasa
This commit is contained in:
Jesper Wilhelmsson 2015-04-02 16:37:29 +02:00
parent d2f816a875
commit 8e5f94bf08
8 changed files with 20 additions and 46 deletions

View File

@ -34,7 +34,6 @@ import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.*; import sun.jvm.hotspot.utilities.*;
public class GenCollectedHeap extends CollectedHeap { public class GenCollectedHeap extends CollectedHeap {
private static CIntegerField nGensField;
private static AddressField youngGenField; private static AddressField youngGenField;
private static AddressField oldGenField; private static AddressField oldGenField;
@ -54,7 +53,6 @@ public class GenCollectedHeap extends CollectedHeap {
private static synchronized void initialize(TypeDataBase db) { private static synchronized void initialize(TypeDataBase db) {
Type type = db.lookupType("GenCollectedHeap"); Type type = db.lookupType("GenCollectedHeap");
nGensField = type.getCIntegerField("_n_gens");
youngGenField = type.getAddressField("_young_gen"); youngGenField = type.getAddressField("_young_gen");
oldGenField = type.getAddressField("_old_gen"); oldGenField = type.getAddressField("_old_gen");
@ -70,7 +68,7 @@ public class GenCollectedHeap extends CollectedHeap {
} }
public int nGens() { public int nGens() {
return (int) nGensField.getValue(addr); return 2; // Young + Old
} }
public Generation getGen(int i) { public Generation getGen(int i) {

View File

@ -596,8 +596,6 @@ void ParNewGenTask::work(uint worker_id) {
// and handle marks. // and handle marks.
ResourceMark rm; ResourceMark rm;
HandleMark hm; HandleMark hm;
// We would need multiple old-gen queues otherwise.
assert(gch->n_gens() == 2, "Par young collection currently only works with one older gen.");
ParScanThreadState& par_scan_state = _state_set->thread_state(worker_id); ParScanThreadState& par_scan_state = _state_set->thread_state(worker_id);
assert(_state_set->is_valid(worker_id), "Should not have been called"); assert(_state_set->is_valid(worker_id), "Should not have been called");
@ -922,8 +920,6 @@ void ParNewGeneration::collect(bool full,
workers->active_workers(), workers->active_workers(),
Threads::number_of_non_daemon_threads()); Threads::number_of_non_daemon_threads());
workers->set_active_workers(active_workers); workers->set_active_workers(active_workers);
assert(gch->n_gens() == 2,
"Par collection currently only works with single older gen.");
_old_gen = gch->old_gen(); _old_gen = gch->old_gen();
// If the next generation is too full to accommodate worst-case promotion // If the next generation is too full to accommodate worst-case promotion

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -42,12 +42,15 @@ CardTableRS::CardTableRS(MemRegion whole_heap) :
_ct_bs = new CardTableModRefBSForCTRS(whole_heap); _ct_bs = new CardTableModRefBSForCTRS(whole_heap);
_ct_bs->initialize(); _ct_bs->initialize();
set_bs(_ct_bs); set_bs(_ct_bs);
_last_cur_val_in_gen = NEW_C_HEAP_ARRAY3(jbyte, GenCollectedHeap::max_gens + 1, // max_gens is really GenCollectedHeap::heap()->gen_policy()->number_of_generations()
// (which is always 2, young & old), but GenCollectedHeap has not been initialized yet.
uint max_gens = 2;
_last_cur_val_in_gen = NEW_C_HEAP_ARRAY3(jbyte, max_gens + 1,
mtGC, CURRENT_PC, AllocFailStrategy::RETURN_NULL); mtGC, CURRENT_PC, AllocFailStrategy::RETURN_NULL);
if (_last_cur_val_in_gen == NULL) { if (_last_cur_val_in_gen == NULL) {
vm_exit_during_initialization("Could not create last_cur_val_in_gen array."); vm_exit_during_initialization("Could not create last_cur_val_in_gen array.");
} }
for (int i = 0; i < GenCollectedHeap::max_gens + 1; i++) { for (uint i = 0; i < max_gens + 1; i++) {
_last_cur_val_in_gen[i] = clean_card_val(); _last_cur_val_in_gen[i] = clean_card_val();
} }
_ct_bs->set_CTRS(this); _ct_bs->set_CTRS(this);

View File

@ -381,8 +381,7 @@ void DefNewGeneration::compute_new_size() {
int next_level = level() + 1; int next_level = level() + 1;
GenCollectedHeap* gch = GenCollectedHeap::heap(); GenCollectedHeap* gch = GenCollectedHeap::heap();
assert(next_level < gch->n_gens(), assert(next_level == 1, "DefNewGeneration must be a young gen");
"DefNewGeneration cannot be an oldest gen");
Generation* old_gen = gch->old_gen(); Generation* old_gen = gch->old_gen();
size_t old_size = old_gen->capacity(); size_t old_size = old_gen->capacity();

View File

@ -99,9 +99,6 @@ GenCollectedHeap::GenCollectedHeap(GenCollectorPolicy *policy) :
jint GenCollectedHeap::initialize() { jint GenCollectedHeap::initialize() {
CollectedHeap::pre_initialize(); CollectedHeap::pre_initialize();
_n_gens = gen_policy()->number_of_generations();
assert(_n_gens == 2, "There is no support for more than two generations");
// While there are no constraints in the GC code that HeapWordSize // While there are no constraints in the GC code that HeapWordSize
// be any particular value, there are multiple other areas in the // be any particular value, there are multiple other areas in the
// system which believe this to be true (e.g. oop->object_size in some // system which believe this to be true (e.g. oop->object_size in some
@ -209,8 +206,7 @@ size_t GenCollectedHeap::used() const {
// Save the "used_region" for generations level and lower. // Save the "used_region" for generations level and lower.
void GenCollectedHeap::save_used_regions(int level) { void GenCollectedHeap::save_used_regions(int level) {
assert(level >= 0, "Illegal level parameter"); assert(level == 0 || level == 1, "Illegal level parameter");
assert(level < _n_gens, "Illegal level parameter");
if (level == 1) { if (level == 1) {
_old_gen->save_used_region(); _old_gen->save_used_region();
} }
@ -426,7 +422,6 @@ void GenCollectedHeap::do_collection(bool full,
assert(Heap_lock->is_locked(), assert(Heap_lock->is_locked(),
"the requesting thread should have the Heap_lock"); "the requesting thread should have the Heap_lock");
guarantee(!is_gc_active(), "collection is not reentrant"); guarantee(!is_gc_active(), "collection is not reentrant");
assert(max_level < n_gens(), "sanity check");
if (GC_locker::check_active_before_gc()) { if (GC_locker::check_active_before_gc()) {
return; // GC is disabled (e.g. JNI GetXXXCritical operation) return; // GC is disabled (e.g. JNI GetXXXCritical operation)
@ -444,7 +439,7 @@ void GenCollectedHeap::do_collection(bool full,
{ {
FlagSetting fl(_is_gc_active, true); FlagSetting fl(_is_gc_active, true);
bool complete = full && (max_level == (n_gens()-1)); bool complete = full && (max_level == 1 /* old */);
const char* gc_cause_prefix = complete ? "Full GC" : "GC"; const char* gc_cause_prefix = complete ? "Full GC" : "GC";
TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
// The PrintGCDetails logging starts before we have incremented the GC id. We will do that later // The PrintGCDetails logging starts before we have incremented the GC id. We will do that later
@ -516,7 +511,7 @@ void GenCollectedHeap::do_collection(bool full,
// Update "complete" boolean wrt what actually transpired -- // Update "complete" boolean wrt what actually transpired --
// for instance, a promotion failure could have led to // for instance, a promotion failure could have led to
// a whole heap collection. // a whole heap collection.
complete = complete || (max_level_collected == n_gens() - 1); complete = complete || (max_level_collected == 1 /* old */);
if (complete) { // We did a "major" collection if (complete) { // We did a "major" collection
// FIXME: See comment at pre_full_gc_dump call // FIXME: See comment at pre_full_gc_dump call
@ -533,7 +528,7 @@ void GenCollectedHeap::do_collection(bool full,
} }
// Adjust generation sizes. // Adjust generation sizes.
if (max_level_collected == 1) { if (max_level_collected == 1 /* old */) {
_old_gen->compute_new_size(); _old_gen->compute_new_size();
} }
_young_gen->compute_new_size(); _young_gen->compute_new_size();
@ -782,19 +777,19 @@ void GenCollectedHeap::collect(GCCause::Cause cause) {
#endif // INCLUDE_ALL_GCS #endif // INCLUDE_ALL_GCS
} else if (cause == GCCause::_wb_young_gc) { } else if (cause == GCCause::_wb_young_gc) {
// minor collection for WhiteBox API // minor collection for WhiteBox API
collect(cause, 0); collect(cause, 0 /* young */);
} else { } else {
#ifdef ASSERT #ifdef ASSERT
if (cause == GCCause::_scavenge_alot) { if (cause == GCCause::_scavenge_alot) {
// minor collection only // minor collection only
collect(cause, 0); collect(cause, 0 /* young */);
} else { } else {
// Stop-the-world full collection // Stop-the-world full collection
collect(cause, n_gens() - 1); collect(cause, 1 /* old */);
} }
#else #else
// Stop-the-world full collection // Stop-the-world full collection
collect(cause, n_gens() - 1); collect(cause, 1 /* old */);
#endif #endif
} }
} }
@ -809,7 +804,7 @@ void GenCollectedHeap::collect(GCCause::Cause cause, int max_level) {
void GenCollectedHeap::collect_locked(GCCause::Cause cause) { void GenCollectedHeap::collect_locked(GCCause::Cause cause) {
// The caller has the Heap_lock // The caller has the Heap_lock
assert(Heap_lock->owned_by_self(), "this thread should own the Heap_lock"); assert(Heap_lock->owned_by_self(), "this thread should own the Heap_lock");
collect_locked(cause, n_gens() - 1); collect_locked(cause, 1 /* old */);
} }
// this is the private collection interface // this is the private collection interface
@ -865,7 +860,7 @@ void GenCollectedHeap::collect_mostly_concurrent(GCCause::Cause cause) {
#endif // INCLUDE_ALL_GCS #endif // INCLUDE_ALL_GCS
void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs) { void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs) {
do_full_collection(clear_all_soft_refs, _n_gens - 1); do_full_collection(clear_all_soft_refs, 1 /* old */);
} }
void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs, void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs,
@ -897,7 +892,7 @@ void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs,
clear_all_soft_refs /* clear_all_soft_refs */, clear_all_soft_refs /* clear_all_soft_refs */,
0 /* size */, 0 /* size */,
false /* is_tlab */, false /* is_tlab */,
n_gens() - 1 /* max_level */); 1 /* old */ /* max_level */);
} }
} }
@ -1123,9 +1118,7 @@ GenCollectedHeap* GenCollectedHeap::heap() {
return _gch; return _gch;
} }
void GenCollectedHeap::prepare_for_compaction() { void GenCollectedHeap::prepare_for_compaction() {
guarantee(_n_gens = 2, "Wrong number of generations");
// Start by compacting into same gen. // Start by compacting into same gen.
CompactPoint cp(_old_gen); CompactPoint cp(_old_gen);
_old_gen->prepare_for_compaction(&cp); _old_gen->prepare_for_compaction(&cp);

View File

@ -52,10 +52,6 @@ class GenCollectedHeap : public CollectedHeap {
friend class GCCauseSetter; friend class GCCauseSetter;
friend class VMStructs; friend class VMStructs;
public: public:
enum SomeConstants {
max_gens = 10
};
friend class VM_PopulateDumpSharedSpace; friend class VM_PopulateDumpSharedSpace;
protected: protected:
@ -63,8 +59,6 @@ public:
static GenCollectedHeap* _gch; static GenCollectedHeap* _gch;
private: private:
int _n_gens;
Generation* _young_gen; Generation* _young_gen;
Generation* _old_gen; Generation* _old_gen;
@ -373,11 +367,6 @@ public:
// collection. // collection.
virtual bool is_maximal_no_gc() const; virtual bool is_maximal_no_gc() const;
int n_gens() const {
assert(_n_gens == gen_policy()->number_of_generations(), "Sanity");
return _n_gens;
}
// This function returns the "GenRemSet" object that allows us to scan // This function returns the "GenRemSet" object that allows us to scan
// generations in a fully generational heap. // generations in a fully generational heap.
GenRemSet* rem_set() { return _rem_set; } GenRemSet* rem_set() { return _rem_set; }

View File

@ -558,7 +558,6 @@ typedef CompactHashtable<Symbol*, char> SymbolCompactHashTable;
static_field(GenCollectedHeap, _gch, GenCollectedHeap*) \ static_field(GenCollectedHeap, _gch, GenCollectedHeap*) \
nonstatic_field(GenCollectedHeap, _young_gen, Generation*) \ nonstatic_field(GenCollectedHeap, _young_gen, Generation*) \
nonstatic_field(GenCollectedHeap, _old_gen, Generation*) \ nonstatic_field(GenCollectedHeap, _old_gen, Generation*) \
nonstatic_field(GenCollectedHeap, _n_gens, int) \
\ \
nonstatic_field(GenCollectorPolicy, _young_gen_spec, GenerationSpec*) \ nonstatic_field(GenCollectorPolicy, _young_gen_spec, GenerationSpec*) \
nonstatic_field(GenCollectorPolicy, _old_gen_spec, GenerationSpec*) \ nonstatic_field(GenCollectorPolicy, _old_gen_spec, GenerationSpec*) \
@ -2256,8 +2255,6 @@ typedef CompactHashtable<Symbol*, char> SymbolCompactHashTable;
declare_constant(CollectedHeap::ParallelScavengeHeap) \ declare_constant(CollectedHeap::ParallelScavengeHeap) \
declare_constant(CollectedHeap::G1CollectedHeap) \ declare_constant(CollectedHeap::G1CollectedHeap) \
\ \
declare_constant(GenCollectedHeap::max_gens) \
\
/* constants from Generation::Name enum */ \ /* constants from Generation::Name enum */ \
\ \
declare_constant(Generation::DefNew) \ declare_constant(Generation::DefNew) \

View File

@ -126,9 +126,8 @@ void MemoryService::add_gen_collected_heap_info(GenCollectedHeap* heap) {
CollectorPolicy* policy = heap->collector_policy(); CollectorPolicy* policy = heap->collector_policy();
assert(policy->is_generation_policy(), "Only support two generations"); assert(policy->is_generation_policy(), "Only support two generations");
guarantee(heap->n_gens() == 2, "Only support two-generation heap");
GenCollectorPolicy* gen_policy = policy->as_generation_policy(); GenCollectorPolicy* gen_policy = policy->as_generation_policy();
guarantee(gen_policy->number_of_generations() == 2, "Only support two-generation heap");
if (gen_policy != NULL) { if (gen_policy != NULL) {
Generation::Name kind = gen_policy->young_gen_spec()->name(); Generation::Name kind = gen_policy->young_gen_spec()->name();
switch (kind) { switch (kind) {