24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "classfile/stringTable.hpp" |
26 #include "classfile/stringTable.hpp" |
27 #include "gc/shared/oopStorage.inline.hpp" |
27 #include "gc/shared/oopStorage.inline.hpp" |
28 #include "gc/shared/oopStorageParState.inline.hpp" |
28 #include "gc/shared/oopStorageParState.inline.hpp" |
|
29 #include "gc/shared/oopStorageSet.hpp" |
29 #include "gc/shared/weakProcessor.inline.hpp" |
30 #include "gc/shared/weakProcessor.inline.hpp" |
30 #include "gc/shared/weakProcessorPhases.hpp" |
31 #include "gc/shared/weakProcessorPhases.hpp" |
31 #include "gc/shared/weakProcessorPhaseTimes.hpp" |
32 #include "gc/shared/weakProcessorPhaseTimes.hpp" |
32 #include "memory/allocation.inline.hpp" |
33 #include "memory/allocation.inline.hpp" |
33 #include "memory/iterator.hpp" |
34 #include "memory/iterator.hpp" |
36 #include "utilities/macros.hpp" |
37 #include "utilities/macros.hpp" |
37 |
38 |
38 template <typename Container> |
39 template <typename Container> |
39 class OopsDoAndReportCounts { |
40 class OopsDoAndReportCounts { |
40 public: |
41 public: |
41 void operator()(BoolObjectClosure* is_alive, OopClosure* keep_alive, WeakProcessorPhase phase) { |
42 void operator()(BoolObjectClosure* is_alive, OopClosure* keep_alive, OopStorage* storage) { |
42 Container::reset_dead_counter(); |
43 Container::reset_dead_counter(); |
43 |
44 |
44 CountingSkippedIsAliveClosure<BoolObjectClosure, OopClosure> cl(is_alive, keep_alive); |
45 CountingSkippedIsAliveClosure<BoolObjectClosure, OopClosure> cl(is_alive, keep_alive); |
45 WeakProcessorPhases::oop_storage(phase)->oops_do(&cl); |
46 storage->oops_do(&cl); |
46 |
47 |
47 Container::inc_dead_counter(cl.num_dead() + cl.num_skipped()); |
48 Container::inc_dead_counter(cl.num_dead() + cl.num_skipped()); |
48 Container::finish_dead_counter(); |
49 Container::finish_dead_counter(); |
49 } |
50 } |
50 }; |
51 }; |
51 |
52 |
52 void WeakProcessor::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive) { |
53 void WeakProcessor::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive) { |
53 FOR_EACH_WEAK_PROCESSOR_PHASE(phase) { |
54 WeakProcessorPhases::Iterator pit = WeakProcessorPhases::serial_iterator(); |
54 if (WeakProcessorPhases::is_serial(phase)) { |
55 for ( ; !pit.is_end(); ++pit) { |
55 WeakProcessorPhases::processor(phase)(is_alive, keep_alive); |
56 WeakProcessorPhases::processor(*pit)(is_alive, keep_alive); |
|
57 } |
|
58 |
|
59 OopStorageSet::Iterator it = OopStorageSet::weak_iterator(); |
|
60 for ( ; !it.is_end(); ++it) { |
|
61 if (OopStorageSet::string_table_weak() == *it) { |
|
62 OopsDoAndReportCounts<StringTable>()(is_alive, keep_alive, *it); |
|
63 } else if (OopStorageSet::resolved_method_table_weak() == *it) { |
|
64 OopsDoAndReportCounts<ResolvedMethodTable>()(is_alive, keep_alive, *it); |
56 } else { |
65 } else { |
57 if (WeakProcessorPhases::is_stringtable(phase)) { |
66 it->weak_oops_do(is_alive, keep_alive); |
58 OopsDoAndReportCounts<StringTable>()(is_alive, keep_alive, phase); |
|
59 } else if (WeakProcessorPhases::is_resolved_method_table(phase)){ |
|
60 OopsDoAndReportCounts<ResolvedMethodTable>()(is_alive, keep_alive, phase); |
|
61 } else { |
|
62 WeakProcessorPhases::oop_storage(phase)->weak_oops_do(is_alive, keep_alive); |
|
63 } |
|
64 } |
67 } |
65 } |
68 } |
66 } |
69 } |
67 |
70 |
68 void WeakProcessor::oops_do(OopClosure* closure) { |
71 void WeakProcessor::oops_do(OopClosure* closure) { |
84 // cost of running unnecessary threads. These phases are normally |
87 // cost of running unnecessary threads. These phases are normally |
85 // small or empty (assuming they are configured to exist at all), |
88 // small or empty (assuming they are configured to exist at all), |
86 // and development oriented, so not allocating any threads |
89 // and development oriented, so not allocating any threads |
87 // specifically for them is okay. |
90 // specifically for them is okay. |
88 size_t ref_count = 0; |
91 size_t ref_count = 0; |
89 FOR_EACH_WEAK_PROCESSOR_OOP_STORAGE_PHASE(phase) { |
92 OopStorageSet::Iterator it = OopStorageSet::weak_iterator(); |
90 ref_count += WeakProcessorPhases::oop_storage(phase)->allocation_count(); |
93 for ( ; !it.is_end(); ++it) { |
|
94 ref_count += it->allocation_count(); |
91 } |
95 } |
92 |
96 |
93 // +1 to (approx) round up the ref per thread division. |
97 // +1 to (approx) round up the ref per thread division. |
94 size_t nworkers = 1 + (ref_count / ReferencesPerThread); |
98 size_t nworkers = 1 + (ref_count / ReferencesPerThread); |
95 nworkers = MIN2(nworkers, static_cast<size_t>(max_workers)); |
99 nworkers = MIN2(nworkers, static_cast<size_t>(max_workers)); |
104 |
108 |
105 if (_phase_times) { |
109 if (_phase_times) { |
106 _phase_times->set_active_workers(_nworkers); |
110 _phase_times->set_active_workers(_nworkers); |
107 } |
111 } |
108 |
112 |
109 uint storage_count = WeakProcessorPhases::oop_storage_phase_count; |
113 uint storage_count = WeakProcessorPhases::oopstorage_phase_count; |
110 _storage_states = NEW_C_HEAP_ARRAY(StorageState, storage_count, mtGC); |
114 _storage_states = NEW_C_HEAP_ARRAY(StorageState, storage_count, mtGC); |
111 |
115 |
112 StorageState* states = _storage_states; |
116 StorageState* cur_state = _storage_states; |
113 FOR_EACH_WEAK_PROCESSOR_OOP_STORAGE_PHASE(phase) { |
117 OopStorageSet::Iterator it = OopStorageSet::weak_iterator(); |
114 OopStorage* storage = WeakProcessorPhases::oop_storage(phase); |
118 for ( ; !it.is_end(); ++it, ++cur_state) { |
115 new (states++) StorageState(storage, _nworkers); |
119 assert(pointer_delta(cur_state, _storage_states, sizeof(StorageState)) < storage_count, "invariant"); |
|
120 new (cur_state) StorageState(*it, _nworkers); |
116 } |
121 } |
|
122 assert(pointer_delta(cur_state, _storage_states, sizeof(StorageState)) == storage_count, "invariant"); |
117 StringTable::reset_dead_counter(); |
123 StringTable::reset_dead_counter(); |
118 ResolvedMethodTable::reset_dead_counter(); |
124 ResolvedMethodTable::reset_dead_counter(); |
119 } |
125 } |
120 |
126 |
121 WeakProcessor::Task::Task(uint nworkers) : |
127 WeakProcessor::Task::Task(uint nworkers) : |
137 } |
143 } |
138 |
144 |
139 WeakProcessor::Task::~Task() { |
145 WeakProcessor::Task::~Task() { |
140 if (_storage_states != NULL) { |
146 if (_storage_states != NULL) { |
141 StorageState* states = _storage_states; |
147 StorageState* states = _storage_states; |
142 FOR_EACH_WEAK_PROCESSOR_OOP_STORAGE_PHASE(phase) { |
148 for (uint i = 0; i < WeakProcessorPhases::oopstorage_phase_count; ++i) { |
143 states->StorageState::~StorageState(); |
149 states->StorageState::~StorageState(); |
144 ++states; |
150 ++states; |
145 } |
151 } |
146 FREE_C_HEAP_ARRAY(StorageState, _storage_states); |
152 FREE_C_HEAP_ARRAY(StorageState, _storage_states); |
147 } |
153 } |