Skip to content

Commit

Permalink
8331557: Serial: Refactor SerialHeap::do_collection
Browse files Browse the repository at this point in the history
Reviewed-by: gli, iwalulya
  • Loading branch information
albertnetymk committed May 17, 2024
1 parent 14198f5 commit f1ce9b0
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 439 deletions.
17 changes: 3 additions & 14 deletions src/hotspot/share/gc/serial/defNewGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,22 +641,9 @@ void DefNewGeneration::adjust_desired_tenuring_threshold() {
age_table()->print_age_table();
}

void DefNewGeneration::collect(bool full,
bool clear_all_soft_refs,
size_t size,
bool is_tlab) {
assert(full || size > 0, "otherwise we don't want to collect");

bool DefNewGeneration::collect(bool clear_all_soft_refs) {
SerialHeap* heap = SerialHeap::heap();

// If the next generation is too full to accommodate promotion
// from this generation, pass on collection; let the next generation
// do it.
if (!collection_attempt_is_safe()) {
log_trace(gc)(":: Collection attempt not safe ::");
heap->set_incremental_collection_failed(); // Slight lie: we did not even attempt one
return;
}
assert(to()->is_empty(), "Else not collection_attempt_is_safe");
_gc_timer->register_gc_start();
_gc_tracer->report_gc_start(heap->gc_cause(), _gc_timer->gc_start());
Expand Down Expand Up @@ -774,6 +761,8 @@ void DefNewGeneration::collect(bool full,
_gc_timer->register_gc_end();

_gc_tracer->report_gc_end(_gc_timer->gc_end(), _gc_timer->time_partitions());

return !_promotion_failed;
}

void DefNewGeneration::init_assuming_no_promotion_failure() {
Expand Down
10 changes: 3 additions & 7 deletions src/hotspot/share/gc/serial/defNewGeneration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,18 @@ class DefNewGeneration: public Generation {
HeapWord* block_start(const void* p) const;

// Allocation support
virtual bool should_allocate(size_t word_size, bool is_tlab) {
bool should_allocate(size_t word_size, bool is_tlab) {
assert(UseTLAB || !is_tlab, "Should not allocate tlab");
assert(word_size != 0, "precondition");

size_t overflow_limit = (size_t)1 << (BitsPerSize_t - LogHeapWordSize);

const bool non_zero = word_size > 0;
const bool overflows = word_size >= overflow_limit;
const bool check_too_big = _pretenure_size_threshold_words > 0;
const bool not_too_big = word_size < _pretenure_size_threshold_words;
const bool size_ok = is_tlab || !check_too_big || not_too_big;

bool result = !overflows &&
non_zero &&
size_ok;

return result;
Expand Down Expand Up @@ -253,10 +252,7 @@ class DefNewGeneration: public Generation {
// at some additional cost.
bool collection_attempt_is_safe();

virtual void collect(bool full,
bool clear_all_soft_refs,
size_t size,
bool is_tlab);
bool collect(bool clear_all_soft_refs);

HeapWord* expand_and_allocate(size_t size, bool is_tlab);

Expand Down
11 changes: 0 additions & 11 deletions src/hotspot/share/gc/serial/generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,3 @@ void Generation::print_on(outputStream* st) const {
p2i(_virtual_space.high()),
p2i(_virtual_space.high_boundary()));
}

void Generation::print_summary_info_on(outputStream* st) {
StatRecord* sr = stat_record();
double time = sr->accumulated_time.seconds();
st->print_cr("Accumulated %s generation GC time %3.7f secs, "
"%u GC's, avg GC time %3.7f",
SerialHeap::heap()->is_young_gen(this) ? "young" : "old" ,
time,
sr->invocations,
sr->invocations > 0 ? time / sr->invocations : 0.0);
}
52 changes: 0 additions & 52 deletions src/hotspot/share/gc/serial/generation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,6 @@ class Generation: public CHeapObj<mtGC> {
return _reserved.contains(p);
}

// Returns "true" iff this generation should be used to allocate an
// object of the given size. Young generations might
// wish to exclude very large objects, for example, since, if allocated
// often, they would greatly increase the frequency of young-gen
// collection.
virtual bool should_allocate(size_t word_size, bool is_tlab) {
bool result = false;
size_t overflow_limit = (size_t)1 << (BitsPerSize_t - LogHeapWordSize);
if (!is_tlab || supports_tlab_allocation()) {
result = (word_size > 0) && (word_size < overflow_limit);
}
return result;
}

// Allocate and returns a block of the requested size, or returns "null".
// Assumes the caller has done any necessary locking.
virtual HeapWord* allocate(size_t word_size, bool is_tlab) = 0;
Expand All @@ -131,31 +117,6 @@ class Generation: public CHeapObj<mtGC> {
// Thread-local allocation buffers
virtual bool supports_tlab_allocation() const { return false; }

// Returns "true" iff collect() should subsequently be called on this
// this generation. See comment below.
// This is a generic implementation which can be overridden.
//
// Note: in the current (1.4) implementation, when serialHeap's
// incremental_collection_will_fail flag is set, all allocations are
// slow path (the only fast-path place to allocate is DefNew, which
// will be full if the flag is set).
// Thus, older generations which collect younger generations should
// test this flag and collect if it is set.
virtual bool should_collect(bool full,
size_t word_size,
bool is_tlab) {
return (full || should_allocate(word_size, is_tlab));
}

// Perform a garbage collection.
// If full is true attempt a full garbage collection of this generation.
// Otherwise, attempting to (at least) free enough space to support an
// allocation of the given "word_size".
virtual void collect(bool full,
bool clear_all_soft_refs,
size_t word_size,
bool is_tlab) = 0;

// Perform a heap collection, attempting to create (at least) enough
// space to support an allocation of the given "word_size". If
// successful, perform the allocation and return the resulting
Expand All @@ -172,20 +133,7 @@ class Generation: public CHeapObj<mtGC> {

virtual void verify() = 0;

struct StatRecord {
int invocations;
elapsedTimer accumulated_time;
StatRecord() :
invocations(0),
accumulated_time(elapsedTimer()) {}
};
private:
StatRecord _stat_record;
public:
StatRecord* stat_record() { return &_stat_record; }

virtual void print_summary_info_on(outputStream* st);

// Performance Counter support
virtual void update_counters() = 0;
virtual CollectorCounters* counters() { return _gc_counters; }
Expand Down
Loading

1 comment on commit f1ce9b0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.