Skip to content

Commit cc96b0a

Browse files
author
Kim Barrett
committed
8256813: Simplify WeakProcessor counting of OopStorage entries
Reviewed-by: sjohanss, stefank
1 parent 67a9590 commit cc96b0a

File tree

3 files changed

+27
-43
lines changed

3 files changed

+27
-43
lines changed

src/hotspot/share/gc/shared/weakProcessor.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ void WeakProcessor::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_a
6565
OopStorageSet::Iterator it = OopStorageSet::weak_iterator();
6666
for ( ; !it.is_end(); ++it) {
6767
if (it->should_report_num_dead()) {
68-
CountingSkippedIsAliveClosure<BoolObjectClosure, OopClosure> cl(is_alive, keep_alive);
68+
CountingClosure<BoolObjectClosure, OopClosure> cl(is_alive, keep_alive);
6969
it->oops_do(&cl);
70-
it->report_num_dead(cl.num_skipped() + cl.num_dead());
70+
it->report_num_dead(cl.dead());
7171
} else {
7272
it->weak_oops_do(is_alive, keep_alive);
7373
}
@@ -91,12 +91,6 @@ uint WeakProcessor::ergo_workers(uint max_workers) {
9191

9292
// One thread per ReferencesPerThread references (or fraction thereof)
9393
// in the various OopStorage objects, bounded by max_threads.
94-
//
95-
// Serial phases are ignored in this calculation, because of the
96-
// cost of running unnecessary threads. These phases are normally
97-
// small or empty (assuming they are configured to exist at all),
98-
// and development oriented, so not allocating any threads
99-
// specifically for them is okay.
10094
size_t ref_count = 0;
10195
OopStorageSet::Iterator it = OopStorageSet::weak_iterator();
10296
for ( ; !it.is_end(); ++it) {

src/hotspot/share/gc/shared/weakProcessor.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class WeakProcessor : AllStatic {
7171
class Task;
7272

7373
private:
74+
template<typename IsAlive, typename KeepAlive>
75+
class CountingClosure;
76+
7477
class GangTask;
7578
};
7679

src/hotspot/share/gc/shared/weakProcessor.inline.hpp

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,52 +38,39 @@
3838
class BoolObjectClosure;
3939
class OopClosure;
4040

41-
template<typename IsAlive>
42-
class CountingIsAliveClosure : public BoolObjectClosure {
43-
IsAlive* _inner;
44-
45-
size_t _num_dead;
46-
size_t _num_total;
47-
48-
public:
49-
CountingIsAliveClosure(IsAlive* cl) : _inner(cl), _num_dead(0), _num_total(0) { }
50-
51-
virtual bool do_object_b(oop obj) {
52-
bool result = _inner->do_object_b(obj);
53-
_num_dead += !result;
54-
_num_total++;
55-
return result;
56-
}
57-
58-
size_t num_dead() const { return _num_dead; }
59-
size_t num_total() const { return _num_total; }
60-
};
61-
6241
template <typename IsAlive, typename KeepAlive>
63-
class CountingSkippedIsAliveClosure : public Closure {
64-
CountingIsAliveClosure<IsAlive> _counting_is_alive;
42+
class WeakProcessor::CountingClosure : public Closure {
43+
IsAlive* _is_alive;
6544
KeepAlive* _keep_alive;
66-
67-
size_t _num_skipped;
45+
size_t _old_dead;
46+
size_t _new_dead;
47+
size_t _live;
6848

6949
public:
70-
CountingSkippedIsAliveClosure(IsAlive* is_alive, KeepAlive* keep_alive) :
71-
_counting_is_alive(is_alive), _keep_alive(keep_alive), _num_skipped(0) { }
50+
CountingClosure(IsAlive* is_alive, KeepAlive* keep_alive) :
51+
_is_alive(is_alive),
52+
_keep_alive(keep_alive),
53+
_old_dead(0),
54+
_new_dead(0),
55+
_live(0)
56+
{}
7257

7358
void do_oop(oop* p) {
7459
oop obj = *p;
7560
if (obj == NULL) {
76-
_num_skipped++;
77-
} else if (_counting_is_alive.do_object_b(obj)) {
61+
++_old_dead;
62+
} else if (_is_alive->do_object_b(obj)) {
7863
_keep_alive->do_oop(p);
64+
++_live;
7965
} else {
8066
*p = NULL;
67+
++_new_dead;
8168
}
8269
}
8370

84-
size_t num_dead() const { return _counting_is_alive.num_dead(); }
85-
size_t num_skipped() const { return _num_skipped; }
86-
size_t num_total() const { return _counting_is_alive.num_total() + num_skipped(); }
71+
size_t dead() const { return _old_dead + _new_dead; }
72+
size_t new_dead() const { return _new_dead; }
73+
size_t total() const { return dead() + _live; }
8774
};
8875

8976
template<typename IsAlive, typename KeepAlive>
@@ -98,13 +85,13 @@ void WeakProcessor::Task::work(uint worker_id,
9885

9986
for (Iterator it = WeakProcessorPhases::oopstorage_iterator(); !it.is_end(); ++it) {
10087
WeakProcessorPhase phase = *it;
101-
CountingSkippedIsAliveClosure<IsAlive, KeepAlive> cl(is_alive, keep_alive);
88+
CountingClosure<IsAlive, KeepAlive> cl(is_alive, keep_alive);
10289
WeakProcessorPhaseTimeTracker pt(_phase_times, phase, worker_id);
10390
StorageState* cur_state = _storage_states.par_state(phase);
10491
cur_state->oops_do(&cl);
105-
cur_state->increment_num_dead(cl.num_skipped() + cl.num_dead());
92+
cur_state->increment_num_dead(cl.dead());
10693
if (_phase_times != NULL) {
107-
_phase_times->record_worker_items(worker_id, phase, cl.num_dead(), cl.num_total());
94+
_phase_times->record_worker_items(worker_id, phase, cl.new_dead(), cl.total());
10895
}
10996
}
11097
}

0 commit comments

Comments
 (0)