26 #include "classfile/systemDictionary.hpp"
27 #include "gc/parallel/gcTaskManager.hpp"
28 #include "gc/parallel/objectStartArray.hpp"
29 #include "gc/parallel/parMarkBitMap.hpp"
30 #include "gc/parallel/parallelScavengeHeap.hpp"
31 #include "gc/parallel/psCompactionManager.inline.hpp"
32 #include "gc/parallel/psOldGen.hpp"
33 #include "gc/parallel/psParallelCompact.inline.hpp"
34 #include "gc/shared/taskqueue.inline.hpp"
35 #include "logging/log.hpp"
36 #include "memory/iterator.inline.hpp"
37 #include "oops/instanceKlass.inline.hpp"
38 #include "oops/instanceMirrorKlass.inline.hpp"
39 #include "oops/objArrayKlass.inline.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "runtime/atomic.inline.hpp"
42
43 PSOldGen* ParCompactionManager::_old_gen = NULL;
44 ParCompactionManager** ParCompactionManager::_manager_array = NULL;
45
46 RegionTaskQueue** ParCompactionManager::_region_list = NULL;
47
48 OopTaskQueueSet* ParCompactionManager::_stack_array = NULL;
49 ParCompactionManager::ObjArrayTaskQueueSet*
50 ParCompactionManager::_objarray_queues = NULL;
51 ObjectStartArray* ParCompactionManager::_start_array = NULL;
52 ParMarkBitMap* ParCompactionManager::_mark_bitmap = NULL;
53 RegionTaskQueueSet* ParCompactionManager::_region_array = NULL;
54
55 uint* ParCompactionManager::_recycled_stack_index = NULL;
56 int ParCompactionManager::_recycled_top = -1;
57 int ParCompactionManager::_recycled_bottom = -1;
58
59 ParCompactionManager::ParCompactionManager() :
60 _action(CopyAndUpdate),
61 _region_stack(NULL),
62 _region_stack_index((uint)max_uintx) {
63
64 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
65
66 _old_gen = heap->old_gen();
67 _start_array = old_gen()->start_array();
68
69 marking_stack()->initialize();
70 _objarray_stack.initialize();
71
72 reset_bitmap_query_cache();
73 }
74
75 ParCompactionManager::~ParCompactionManager() {
76 delete _recycled_stack_index;
77 }
78
79 void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
80 assert(PSParallelCompact::gc_task_manager() != NULL,
81 "Needed for initialization");
82
83 _mark_bitmap = mbm;
84
85 uint parallel_gc_threads = PSParallelCompact::gc_task_manager()->workers();
86
87 assert(_manager_array == NULL, "Attempt to initialize twice");
88 _manager_array = NEW_C_HEAP_ARRAY(ParCompactionManager*, parallel_gc_threads+1, mtGC);
89 guarantee(_manager_array != NULL, "Could not allocate manager_array");
90
91 _region_list = NEW_C_HEAP_ARRAY(RegionTaskQueue*,
92 parallel_gc_threads+1, mtGC);
93 guarantee(_region_list != NULL, "Could not initialize promotion manager");
94
95 _recycled_stack_index = NEW_C_HEAP_ARRAY(uint, parallel_gc_threads, mtGC);
96
97 // parallel_gc-threads + 1 to be consistent with the number of
98 // compaction managers.
99 for(uint i=0; i<parallel_gc_threads + 1; i++) {
100 _region_list[i] = new RegionTaskQueue();
101 region_list(i)->initialize();
102 }
103
104 _stack_array = new OopTaskQueueSet(parallel_gc_threads);
105 guarantee(_stack_array != NULL, "Could not allocate stack_array");
106 _objarray_queues = new ObjArrayTaskQueueSet(parallel_gc_threads);
107 guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues");
108 _region_array = new RegionTaskQueueSet(parallel_gc_threads);
109 guarantee(_region_array != NULL, "Could not allocate region_array");
110
111 // Create and register the ParCompactionManager(s) for the worker threads.
112 for(uint i=0; i<parallel_gc_threads; i++) {
113 _manager_array[i] = new ParCompactionManager();
114 guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager");
115 stack_array()->register_queue(i, _manager_array[i]->marking_stack());
116 _objarray_queues->register_queue(i, &_manager_array[i]->_objarray_stack);
117 region_array()->register_queue(i, region_list(i));
118 }
119
120 // The VMThread gets its own ParCompactionManager, which is not available
121 // for work stealing.
122 _manager_array[parallel_gc_threads] = new ParCompactionManager();
123 guarantee(_manager_array[parallel_gc_threads] != NULL,
124 "Could not create ParCompactionManager");
125 assert(PSParallelCompact::gc_task_manager()->workers() != 0,
126 "Not initialized?");
127 }
128
129 void ParCompactionManager::reset_all_bitmap_query_caches() {
130 uint parallel_gc_threads = PSParallelCompact::gc_task_manager()->workers();
131 for (uint i=0; i<=parallel_gc_threads; i++) {
132 _manager_array[i]->reset_bitmap_query_cache();
133 }
134 }
135
136 int ParCompactionManager::pop_recycled_stack_index() {
137 assert(_recycled_bottom <= _recycled_top, "list is empty");
138 // Get the next available index
139 if (_recycled_bottom < _recycled_top) {
140 uint cur, next, last;
141 do {
142 cur = _recycled_bottom;
143 next = cur + 1;
144 last = Atomic::cmpxchg(next, &_recycled_bottom, cur);
145 } while (cur != last);
146 return _recycled_stack_index[next];
147 } else {
148 return -1;
149 }
150 }
151
152 void ParCompactionManager::push_recycled_stack_index(uint v) {
153 // Get the next available index
154 int cur = Atomic::add(1, &_recycled_top);
155 _recycled_stack_index[cur] = v;
156 assert(_recycled_bottom <= _recycled_top, "list top and bottom are wrong");
157 }
158
159 bool ParCompactionManager::should_update() {
160 assert(action() != NotValid, "Action is not set");
161 return (action() == ParCompactionManager::Update) ||
162 (action() == ParCompactionManager::CopyAndUpdate) ||
163 (action() == ParCompactionManager::UpdateAndCopy);
164 }
165
166 bool ParCompactionManager::should_copy() {
167 assert(action() != NotValid, "Action is not set");
168 return (action() == ParCompactionManager::Copy) ||
169 (action() == ParCompactionManager::CopyAndUpdate) ||
170 (action() == ParCompactionManager::UpdateAndCopy);
171 }
172
173 void ParCompactionManager::region_list_push(uint list_index,
174 size_t region_index) {
175 region_list(list_index)->push(region_index);
176 }
177
178 void ParCompactionManager::verify_region_list_empty(uint list_index) {
179 assert(region_list(list_index)->is_empty(), "Not empty");
180 }
181
182 ParCompactionManager*
183 ParCompactionManager::gc_thread_compaction_manager(uint index) {
184 assert(index < ParallelGCThreads, "index out of range");
185 assert(_manager_array != NULL, "Sanity");
186 return _manager_array[index];
187 }
188
189 void InstanceKlass::oop_pc_follow_contents(oop obj, ParCompactionManager* cm) {
190 assert(obj != NULL, "can't follow the content of NULL object");
191
192 cm->follow_klass(this);
193 // Only mark the header and let the scan of the meta-data mark
194 // everything else.
195
196 ParCompactionManager::MarkAndPushClosure cl(cm);
197 InstanceKlass::oop_oop_iterate_oop_maps<true>(obj, &cl);
198 }
199
|
26 #include "classfile/systemDictionary.hpp"
27 #include "gc/parallel/gcTaskManager.hpp"
28 #include "gc/parallel/objectStartArray.hpp"
29 #include "gc/parallel/parMarkBitMap.hpp"
30 #include "gc/parallel/parallelScavengeHeap.hpp"
31 #include "gc/parallel/psCompactionManager.inline.hpp"
32 #include "gc/parallel/psOldGen.hpp"
33 #include "gc/parallel/psParallelCompact.inline.hpp"
34 #include "gc/shared/taskqueue.inline.hpp"
35 #include "logging/log.hpp"
36 #include "memory/iterator.inline.hpp"
37 #include "oops/instanceKlass.inline.hpp"
38 #include "oops/instanceMirrorKlass.inline.hpp"
39 #include "oops/objArrayKlass.inline.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "runtime/atomic.inline.hpp"
42
43 PSOldGen* ParCompactionManager::_old_gen = NULL;
44 ParCompactionManager** ParCompactionManager::_manager_array = NULL;
45
46 OopTaskQueueSet* ParCompactionManager::_stack_array = NULL;
47 ParCompactionManager::ObjArrayTaskQueueSet*
48 ParCompactionManager::_objarray_queues = NULL;
49 ObjectStartArray* ParCompactionManager::_start_array = NULL;
50 ParMarkBitMap* ParCompactionManager::_mark_bitmap = NULL;
51 RegionTaskQueueSet* ParCompactionManager::_region_array = NULL;
52
53 ParCompactionManager::ParCompactionManager() :
54 _action(CopyAndUpdate) {
55
56 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
57
58 _old_gen = heap->old_gen();
59 _start_array = old_gen()->start_array();
60
61 marking_stack()->initialize();
62 _objarray_stack.initialize();
63 _region_stack.initialize();
64
65 reset_bitmap_query_cache();
66 }
67
68 void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
69 assert(PSParallelCompact::gc_task_manager() != NULL,
70 "Needed for initialization");
71
72 _mark_bitmap = mbm;
73
74 uint parallel_gc_threads = PSParallelCompact::gc_task_manager()->workers();
75
76 assert(_manager_array == NULL, "Attempt to initialize twice");
77 _manager_array = NEW_C_HEAP_ARRAY(ParCompactionManager*, parallel_gc_threads+1, mtGC);
78 guarantee(_manager_array != NULL, "Could not allocate manager_array");
79
80 _stack_array = new OopTaskQueueSet(parallel_gc_threads);
81 guarantee(_stack_array != NULL, "Could not allocate stack_array");
82 _objarray_queues = new ObjArrayTaskQueueSet(parallel_gc_threads);
83 guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues");
84 _region_array = new RegionTaskQueueSet(parallel_gc_threads);
85 guarantee(_region_array != NULL, "Could not allocate region_array");
86
87 // Create and register the ParCompactionManager(s) for the worker threads.
88 for(uint i=0; i<parallel_gc_threads; i++) {
89 _manager_array[i] = new ParCompactionManager();
90 guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager");
91 stack_array()->register_queue(i, _manager_array[i]->marking_stack());
92 _objarray_queues->register_queue(i, &_manager_array[i]->_objarray_stack);
93 region_array()->register_queue(i, _manager_array[i]->region_stack());
94 }
95
96 // The VMThread gets its own ParCompactionManager, which is not available
97 // for work stealing.
98 _manager_array[parallel_gc_threads] = new ParCompactionManager();
99 guarantee(_manager_array[parallel_gc_threads] != NULL,
100 "Could not create ParCompactionManager");
101 assert(PSParallelCompact::gc_task_manager()->workers() != 0,
102 "Not initialized?");
103 }
104
105 void ParCompactionManager::reset_all_bitmap_query_caches() {
106 uint parallel_gc_threads = PSParallelCompact::gc_task_manager()->workers();
107 for (uint i=0; i<=parallel_gc_threads; i++) {
108 _manager_array[i]->reset_bitmap_query_cache();
109 }
110 }
111
112 bool ParCompactionManager::should_update() {
113 assert(action() != NotValid, "Action is not set");
114 return (action() == ParCompactionManager::Update) ||
115 (action() == ParCompactionManager::CopyAndUpdate) ||
116 (action() == ParCompactionManager::UpdateAndCopy);
117 }
118
119 bool ParCompactionManager::should_copy() {
120 assert(action() != NotValid, "Action is not set");
121 return (action() == ParCompactionManager::Copy) ||
122 (action() == ParCompactionManager::CopyAndUpdate) ||
123 (action() == ParCompactionManager::UpdateAndCopy);
124 }
125
126 ParCompactionManager*
127 ParCompactionManager::gc_thread_compaction_manager(uint index) {
128 assert(index < ParallelGCThreads, "index out of range");
129 assert(_manager_array != NULL, "Sanity");
130 return _manager_array[index];
131 }
132
133 void InstanceKlass::oop_pc_follow_contents(oop obj, ParCompactionManager* cm) {
134 assert(obj != NULL, "can't follow the content of NULL object");
135
136 cm->follow_klass(this);
137 // Only mark the header and let the scan of the meta-data mark
138 // everything else.
139
140 ParCompactionManager::MarkAndPushClosure cl(cm);
141 InstanceKlass::oop_oop_iterate_oop_maps<true>(obj, &cl);
142 }
143
|