提交 de9072f9 编写于 作者: B brutisso

8022800: Use specific generations rather than generation iteration

Reviewed-by: jmasa, ehelin
上级 cf130033
...@@ -927,11 +927,9 @@ void ParNewGeneration::collect(bool full, ...@@ -927,11 +927,9 @@ 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);
_next_gen = gch->next_gen(this);
assert(_next_gen != NULL,
"This must be the youngest gen, and not the only gen");
assert(gch->n_gens() == 2, assert(gch->n_gens() == 2,
"Par collection currently only works with single older gen."); "Par collection currently only works with single older gen.");
_next_gen = gch->next_gen(this);
// Do we have to avoid promotion_undo? // Do we have to avoid promotion_undo?
if (gch->collector_policy()->is_concurrent_mark_sweep_policy()) { if (gch->collector_policy()->is_concurrent_mark_sweep_policy()) {
set_avoid_promotion_undo(true); set_avoid_promotion_undo(true);
......
...@@ -321,35 +321,25 @@ void CardTableRS::clear_into_younger(Generation* gen) { ...@@ -321,35 +321,25 @@ void CardTableRS::clear_into_younger(Generation* gen) {
// below to avoid missing cards at the fringes. If clear() or // below to avoid missing cards at the fringes. If clear() or
// invalidate() are changed in the future, this code should // invalidate() are changed in the future, this code should
// be revisited. 20040107.ysr // be revisited. 20040107.ysr
Generation* g = gen; Generation* old_gen = gen;
for(Generation* prev_gen = gch->prev_gen(g); clear(old_gen->prev_used_region());
prev_gen != NULL; Generation* young_gen = gch->prev_gen(old_gen);
g = prev_gen, prev_gen = gch->prev_gen(g)) { clear(young_gen->prev_used_region());
MemRegion to_be_cleared_mr = g->prev_used_region();
clear(to_be_cleared_mr);
}
} }
void CardTableRS::invalidate_or_clear(Generation* gen, bool younger) { void CardTableRS::invalidate_or_clear(Generation* gen) {
GenCollectedHeap* gch = GenCollectedHeap::heap(); // For generation gen invalidate the cards for the currently
// For each generation gen (and younger) // occupied part of that generation and clear the cards for the
// invalidate the cards for the currently occupied part
// of that generation and clear the cards for the
// unoccupied part of the generation (if any, making use // unoccupied part of the generation (if any, making use
// of that generation's prev_used_region to determine that // of that generation's prev_used_region to determine that
// region). No need to do anything for the youngest // region). No need to do anything for the youngest
// generation. Also see note#20040107.ysr above. // generation. Also see note#20040107.ysr above.
Generation* g = gen; MemRegion used_mr = gen->used_region();
for(Generation* prev_gen = gch->prev_gen(g); prev_gen != NULL; MemRegion to_be_cleared_mr = gen->prev_used_region().minus(used_mr);
g = prev_gen, prev_gen = gch->prev_gen(g)) {
MemRegion used_mr = g->used_region();
MemRegion to_be_cleared_mr = g->prev_used_region().minus(used_mr);
if (!to_be_cleared_mr.is_empty()) { if (!to_be_cleared_mr.is_empty()) {
clear(to_be_cleared_mr); clear(to_be_cleared_mr);
} }
invalidate(used_mr); invalidate(used_mr);
if (!younger) break;
}
} }
......
...@@ -147,7 +147,7 @@ public: ...@@ -147,7 +147,7 @@ public:
void invalidate(MemRegion mr, bool whole_heap = false) { void invalidate(MemRegion mr, bool whole_heap = false) {
_ct_bs->invalidate(mr, whole_heap); _ct_bs->invalidate(mr, whole_heap);
} }
void invalidate_or_clear(Generation* gen, bool younger); void invalidate_or_clear(Generation* gen);
static uintx ct_max_alignment_constraint() { static uintx ct_max_alignment_constraint() {
return CardTableModRefBS::ct_max_alignment_constraint(); return CardTableModRefBS::ct_max_alignment_constraint();
......
...@@ -567,8 +567,6 @@ void DefNewGeneration::collect(bool full, ...@@ -567,8 +567,6 @@ void DefNewGeneration::collect(bool full,
gc_tracer.report_gc_start(gch->gc_cause(), _gc_timer->gc_start()); gc_tracer.report_gc_start(gch->gc_cause(), _gc_timer->gc_start());
_next_gen = gch->next_gen(this); _next_gen = gch->next_gen(this);
assert(_next_gen != NULL,
"This must be the youngest gen, and not the only gen");
// If the next generation is too full to accommodate promotion // If the next generation is too full to accommodate promotion
// from this generation, pass on collection; let the next generation // from this generation, pass on collection; let the next generation
...@@ -901,8 +899,6 @@ bool DefNewGeneration::collection_attempt_is_safe() { ...@@ -901,8 +899,6 @@ bool DefNewGeneration::collection_attempt_is_safe() {
if (_next_gen == NULL) { if (_next_gen == NULL) {
GenCollectedHeap* gch = GenCollectedHeap::heap(); GenCollectedHeap* gch = GenCollectedHeap::heap();
_next_gen = gch->next_gen(this); _next_gen = gch->next_gen(this);
assert(_next_gen != NULL,
"This must be the youngest gen, and not the only gen");
} }
return _next_gen->promotion_attempt_is_safe(used()); return _next_gen->promotion_attempt_is_safe(used());
} }
......
...@@ -1070,13 +1070,13 @@ GenCollectedHeap* GenCollectedHeap::heap() { ...@@ -1070,13 +1070,13 @@ GenCollectedHeap* GenCollectedHeap::heap() {
void GenCollectedHeap::prepare_for_compaction() { void GenCollectedHeap::prepare_for_compaction() {
Generation* scanning_gen = _gens[_n_gens-1]; guarantee(_n_gens = 2, "Wrong number of generations");
Generation* old_gen = _gens[1];
// Start by compacting into same gen. // Start by compacting into same gen.
CompactPoint cp(scanning_gen, NULL, NULL); CompactPoint cp(old_gen, NULL, NULL);
while (scanning_gen != NULL) { old_gen->prepare_for_compaction(&cp);
scanning_gen->prepare_for_compaction(&cp); Generation* young_gen = _gens[0];
scanning_gen = prev_gen(scanning_gen); young_gen->prepare_for_compaction(&cp);
}
} }
GCStats* GenCollectedHeap::gc_stats(int level) const { GCStats* GenCollectedHeap::gc_stats(int level) const {
...@@ -1245,27 +1245,14 @@ void GenCollectedHeap::ensure_parsability(bool retire_tlabs) { ...@@ -1245,27 +1245,14 @@ void GenCollectedHeap::ensure_parsability(bool retire_tlabs) {
generation_iterate(&ep_cl, false); generation_iterate(&ep_cl, false);
} }
oop GenCollectedHeap::handle_failed_promotion(Generation* gen, oop GenCollectedHeap::handle_failed_promotion(Generation* old_gen,
oop obj, oop obj,
size_t obj_size) { size_t obj_size) {
guarantee(old_gen->level() == 1, "We only get here with an old generation");
assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); assert(obj_size == (size_t)obj->size(), "bad obj_size passed in");
HeapWord* result = NULL; HeapWord* result = NULL;
// First give each higher generation a chance to allocate the promoted object. result = old_gen->expand_and_allocate(obj_size, false);
Generation* allocator = next_gen(gen);
if (allocator != NULL) {
do {
result = allocator->allocate(obj_size, false);
} while (result == NULL && (allocator = next_gen(allocator)) != NULL);
}
if (result == NULL) {
// Then give gen and higher generations a chance to expand and allocate the
// object.
do {
result = gen->expand_and_allocate(obj_size, false);
} while (result == NULL && (gen = next_gen(gen)) != NULL);
}
if (result != NULL) { if (result != NULL) {
Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size); Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size);
......
...@@ -368,25 +368,23 @@ public: ...@@ -368,25 +368,23 @@ public:
// collection. // collection.
virtual bool is_maximal_no_gc() const; virtual bool is_maximal_no_gc() const;
// Return the generation before "gen", or else NULL. // Return the generation before "gen".
Generation* prev_gen(Generation* gen) const { Generation* prev_gen(Generation* gen) const {
int l = gen->level(); int l = gen->level();
if (l == 0) return NULL; guarantee(l > 0, "Out of bounds");
else return _gens[l-1]; return _gens[l-1];
} }
// Return the generation after "gen", or else NULL. // Return the generation after "gen".
Generation* next_gen(Generation* gen) const { Generation* next_gen(Generation* gen) const {
int l = gen->level() + 1; int l = gen->level() + 1;
if (l == _n_gens) return NULL; guarantee(l < _n_gens, "Out of bounds");
else return _gens[l]; return _gens[l];
} }
Generation* get_gen(int i) const { Generation* get_gen(int i) const {
if (i >= 0 && i < _n_gens) guarantee(i >= 0 && i < _n_gens, "Out of bounds");
return _gens[i]; return _gens[i];
else
return NULL;
} }
int n_gens() const { int n_gens() const {
...@@ -485,9 +483,9 @@ public: ...@@ -485,9 +483,9 @@ public:
// Promotion of obj into gen failed. Try to promote obj to higher // Promotion of obj into gen failed. Try to promote obj to higher
// gens in ascending order; return the new location of obj if successful. // gens in ascending order; return the new location of obj if successful.
// Otherwise, try expand-and-allocate for obj in each generation starting at // Otherwise, try expand-and-allocate for obj in both the young and old
// gen; return the new location of obj if successful. Otherwise, return NULL. // generation; return the new location of obj if successful. Otherwise, return NULL.
oop handle_failed_promotion(Generation* gen, oop handle_failed_promotion(Generation* old_gen,
oop obj, oop obj,
size_t obj_size); size_t obj_size);
......
...@@ -52,8 +52,8 @@ ...@@ -52,8 +52,8 @@
#include "utilities/copy.hpp" #include "utilities/copy.hpp"
#include "utilities/events.hpp" #include "utilities/events.hpp"
void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp, void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp, bool clear_all_softrefs) {
bool clear_all_softrefs) { guarantee(level == 1, "We always collect both old and young.");
assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
GenCollectedHeap* gch = GenCollectedHeap::heap(); GenCollectedHeap* gch = GenCollectedHeap::heap();
...@@ -84,11 +84,6 @@ void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp, ...@@ -84,11 +84,6 @@ void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp,
// Capture heap size before collection for printing. // Capture heap size before collection for printing.
size_t gch_prev_used = gch->used(); size_t gch_prev_used = gch->used();
// Some of the card table updates below assume that the perm gen is
// also being collected.
assert(level == gch->n_gens() - 1,
"All generations are being collected, ergo perm gen too.");
// Capture used regions for each generation that will be // Capture used regions for each generation that will be
// subject to collection, so that card table adjustments can // subject to collection, so that card table adjustments can
// be made intelligently (see clear / invalidate further below). // be made intelligently (see clear / invalidate further below).
...@@ -134,9 +129,9 @@ void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp, ...@@ -134,9 +129,9 @@ void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp,
} else { } else {
// Invalidate the cards corresponding to the currently used // Invalidate the cards corresponding to the currently used
// region and clear those corresponding to the evacuated region // region and clear those corresponding to the evacuated region
// of all generations just collected (i.e. level and younger). // of all generations just collected.
rs->invalidate_or_clear(gch->get_gen(level), rs->invalidate_or_clear(gch->get_gen(1));
true /* younger */); rs->invalidate_or_clear(gch->get_gen(0));
} }
Threads::gc_epilogue(); Threads::gc_epilogue();
......
...@@ -146,11 +146,8 @@ public: ...@@ -146,11 +146,8 @@ public:
// Informs the RS that refs in this generation // Informs the RS that refs in this generation
// may have changed arbitrarily, and therefore may contain // may have changed arbitrarily, and therefore may contain
// old-to-young pointers in arbitrary locations. The parameter // old-to-young pointers in arbitrary locations.
// younger indicates if the same should be done for younger generations virtual void invalidate_or_clear(Generation* gen) = 0;
// as well. The parameter perm indicates if the same should be done for
// perm gen as well.
virtual void invalidate_or_clear(Generation* gen, bool younger) = 0;
}; };
#endif // SHARE_VM_MEMORY_GENREMSET_HPP #endif // SHARE_VM_MEMORY_GENREMSET_HPP
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册