author | redestad |
Thu, 14 Nov 2019 15:24:35 +0100 | |
changeset 59081 | 95a99e617f28 |
parent 53961 | e5b461681b88 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
51078 | 2 |
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "memory/allocation.inline.hpp" |
|
27 |
#include "opto/chaitin.hpp" |
|
28 |
#include "opto/compile.hpp" |
|
29 |
#include "opto/indexSet.hpp" |
|
30 |
#include "opto/regmask.hpp" |
|
31 |
||
1 | 32 |
// This file defines the IndexSet class, a set of sparse integer indices. |
33 |
// This data structure is used by the compiler in its liveness analysis and |
|
34 |
// during register allocation. It also defines an iterator for this class. |
|
35 |
||
36 |
//-------------------------------- Initializations ------------------------------ |
|
37 |
||
38 |
IndexSet::BitBlock IndexSet::_empty_block = IndexSet::BitBlock(); |
|
39 |
||
40 |
#ifdef ASSERT |
|
41 |
// Initialize statistics counters |
|
8320 | 42 |
julong IndexSet::_alloc_new = 0; |
43 |
julong IndexSet::_alloc_total = 0; |
|
1 | 44 |
|
8320 | 45 |
julong IndexSet::_total_bits = 0; |
46 |
julong IndexSet::_total_used_blocks = 0; |
|
47 |
julong IndexSet::_total_unused_blocks = 0; |
|
1 | 48 |
|
49 |
// Per set, or all sets operation tracing |
|
50 |
int IndexSet::_serial_count = 1; |
|
51 |
#endif |
|
52 |
||
53 |
//---------------------------- IndexSet::populate_free_list() ----------------------------- |
|
54 |
// Populate the free BitBlock list with a batch of BitBlocks. The BitBlocks |
|
55 |
// are 32 bit aligned. |
|
56 |
||
57 |
void IndexSet::populate_free_list() { |
|
58 |
Compile *compile = Compile::current(); |
|
59 |
BitBlock *free = (BitBlock*)compile->indexSet_free_block_list(); |
|
60 |
||
61 |
char *mem = (char*)arena()->Amalloc_4(sizeof(BitBlock) * |
|
62 |
bitblock_alloc_chunk_size + 32); |
|
63 |
||
64 |
// Align the pointer to a 32 bit boundary. |
|
65 |
BitBlock *new_blocks = (BitBlock*)(((uintptr_t)mem + 32) & ~0x001F); |
|
66 |
||
67 |
// Add the new blocks to the free list. |
|
68 |
for (int i = 0; i < bitblock_alloc_chunk_size; i++) { |
|
69 |
new_blocks->set_next(free); |
|
70 |
free = new_blocks; |
|
71 |
new_blocks++; |
|
72 |
} |
|
73 |
||
74 |
compile->set_indexSet_free_block_list(free); |
|
75 |
||
76 |
#ifdef ASSERT |
|
77 |
if (CollectIndexSetStatistics) { |
|
8320 | 78 |
inc_stat_counter(&_alloc_new, bitblock_alloc_chunk_size); |
1 | 79 |
} |
80 |
#endif |
|
81 |
} |
|
82 |
||
83 |
||
84 |
//---------------------------- IndexSet::alloc_block() ------------------------ |
|
85 |
// Allocate a BitBlock from the free list. If the free list is empty, |
|
86 |
// prime it. |
|
87 |
||
88 |
IndexSet::BitBlock *IndexSet::alloc_block() { |
|
89 |
#ifdef ASSERT |
|
90 |
if (CollectIndexSetStatistics) { |
|
8320 | 91 |
inc_stat_counter(&_alloc_total, 1); |
1 | 92 |
} |
93 |
#endif |
|
94 |
Compile *compile = Compile::current(); |
|
95 |
BitBlock* free_list = (BitBlock*)compile->indexSet_free_block_list(); |
|
96 |
if (free_list == NULL) { |
|
97 |
populate_free_list(); |
|
98 |
free_list = (BitBlock*)compile->indexSet_free_block_list(); |
|
99 |
} |
|
100 |
BitBlock *block = free_list; |
|
101 |
compile->set_indexSet_free_block_list(block->next()); |
|
102 |
||
103 |
block->clear(); |
|
104 |
return block; |
|
105 |
} |
|
106 |
||
107 |
//---------------------------- IndexSet::alloc_block_containing() ------------- |
|
108 |
// Allocate a new BitBlock and put it into the position in the _blocks array |
|
109 |
// corresponding to element. |
|
110 |
||
111 |
IndexSet::BitBlock *IndexSet::alloc_block_containing(uint element) { |
|
112 |
BitBlock *block = alloc_block(); |
|
113 |
uint bi = get_block_index(element); |
|
59081 | 114 |
if (bi >= _current_block_limit) { |
115 |
_current_block_limit = bi + 1; |
|
116 |
} |
|
1 | 117 |
_blocks[bi] = block; |
118 |
return block; |
|
119 |
} |
|
120 |
||
121 |
//---------------------------- IndexSet::free_block() ------------------------- |
|
122 |
// Add a BitBlock to the free list. |
|
123 |
||
124 |
void IndexSet::free_block(uint i) { |
|
125 |
debug_only(check_watch("free block", i)); |
|
126 |
assert(i < _max_blocks, "block index too large"); |
|
127 |
BitBlock *block = _blocks[i]; |
|
128 |
assert(block != &_empty_block, "cannot free the empty block"); |
|
129 |
block->set_next((IndexSet::BitBlock*)Compile::current()->indexSet_free_block_list()); |
|
130 |
Compile::current()->set_indexSet_free_block_list(block); |
|
59081 | 131 |
set_block(i, &_empty_block); |
1 | 132 |
} |
133 |
||
134 |
//------------------------------lrg_union-------------------------------------- |
|
135 |
// Compute the union of all elements of one and two which interfere with |
|
136 |
// the RegMask mask. If the degree of the union becomes exceeds |
|
137 |
// fail_degree, the union bails out. The underlying set is cleared before |
|
138 |
// the union is performed. |
|
139 |
||
140 |
uint IndexSet::lrg_union(uint lr1, uint lr2, |
|
141 |
const uint fail_degree, |
|
142 |
const PhaseIFG *ifg, |
|
143 |
const RegMask &mask ) { |
|
144 |
IndexSet *one = ifg->neighbors(lr1); |
|
145 |
IndexSet *two = ifg->neighbors(lr2); |
|
146 |
LRG &lrg1 = ifg->lrgs(lr1); |
|
147 |
LRG &lrg2 = ifg->lrgs(lr2); |
|
148 |
#ifdef ASSERT |
|
149 |
assert(_max_elements == one->_max_elements, "max element mismatch"); |
|
150 |
check_watch("union destination"); |
|
151 |
one->check_watch("union source"); |
|
152 |
two->check_watch("union source"); |
|
153 |
#endif |
|
154 |
||
155 |
// Compute the degree of the combined live-range. The combined |
|
156 |
// live-range has the union of the original live-ranges' neighbors set as |
|
157 |
// well as the neighbors of all intermediate copies, minus those neighbors |
|
158 |
// that can not use the intersected allowed-register-set. |
|
159 |
||
160 |
// Copy the larger set. Insert the smaller set into the larger. |
|
161 |
if (two->count() > one->count()) { |
|
162 |
IndexSet *temp = one; |
|
163 |
one = two; |
|
164 |
two = temp; |
|
165 |
} |
|
166 |
||
167 |
clear(); |
|
168 |
||
169 |
// Used to compute degree of register-only interferences. Infinite-stack |
|
170 |
// neighbors do not alter colorability, as they can always color to some |
|
171 |
// other color. (A variant of the Briggs assertion) |
|
172 |
uint reg_degree = 0; |
|
173 |
||
59081 | 174 |
uint element = 0; |
1 | 175 |
// Load up the combined interference set with the neighbors of one |
59081 | 176 |
if (!one->is_empty()) { |
177 |
IndexSetIterator elements(one); |
|
178 |
while ((element = elements.next()) != 0) { |
|
179 |
LRG &lrg = ifg->lrgs(element); |
|
180 |
if (mask.overlap(lrg.mask())) { |
|
181 |
insert(element); |
|
182 |
if (!lrg.mask().is_AllStack()) { |
|
183 |
reg_degree += lrg1.compute_degree(lrg); |
|
184 |
if (reg_degree >= fail_degree) return reg_degree; |
|
185 |
} else { |
|
186 |
// !!!!! Danger! No update to reg_degree despite having a neighbor. |
|
187 |
// A variant of the Briggs assertion. |
|
188 |
// Not needed if I simplify during coalesce, ala George/Appel. |
|
189 |
assert(lrg.lo_degree(), ""); |
|
190 |
} |
|
1 | 191 |
} |
192 |
} |
|
193 |
} |
|
194 |
// Add neighbors of two as well |
|
59081 | 195 |
|
196 |
if (!two->is_empty()) { |
|
197 |
IndexSetIterator elements2(two); |
|
198 |
while ((element = elements2.next()) != 0) { |
|
199 |
LRG &lrg = ifg->lrgs(element); |
|
200 |
if (mask.overlap(lrg.mask())) { |
|
201 |
if (insert(element)) { |
|
202 |
if (!lrg.mask().is_AllStack()) { |
|
203 |
reg_degree += lrg2.compute_degree(lrg); |
|
204 |
if (reg_degree >= fail_degree) return reg_degree; |
|
205 |
} else { |
|
206 |
// !!!!! Danger! No update to reg_degree despite having a neighbor. |
|
207 |
// A variant of the Briggs assertion. |
|
208 |
// Not needed if I simplify during coalesce, ala George/Appel. |
|
209 |
assert(lrg.lo_degree(), ""); |
|
210 |
} |
|
1 | 211 |
} |
212 |
} |
|
213 |
} |
|
214 |
} |
|
215 |
||
216 |
return reg_degree; |
|
217 |
} |
|
218 |
||
219 |
//---------------------------- IndexSet() ----------------------------- |
|
220 |
// A deep copy constructor. This is used when you need a scratch copy of this set. |
|
221 |
||
222 |
IndexSet::IndexSet (IndexSet *set) { |
|
223 |
#ifdef ASSERT |
|
224 |
_serial_number = _serial_count++; |
|
225 |
set->check_watch("copied", _serial_number); |
|
226 |
check_watch("initialized by copy", set->_serial_number); |
|
227 |
_max_elements = set->_max_elements; |
|
228 |
#endif |
|
229 |
_count = set->_count; |
|
59081 | 230 |
_current_block_limit = set->_current_block_limit; |
1 | 231 |
_max_blocks = set->_max_blocks; |
232 |
if (_max_blocks <= preallocated_block_list_size) { |
|
233 |
_blocks = _preallocated_block_list; |
|
234 |
} else { |
|
235 |
_blocks = |
|
236 |
(IndexSet::BitBlock**) arena()->Amalloc_4(sizeof(IndexSet::BitBlock**) * _max_blocks); |
|
237 |
} |
|
238 |
for (uint i = 0; i < _max_blocks; i++) { |
|
239 |
BitBlock *block = set->_blocks[i]; |
|
240 |
if (block == &_empty_block) { |
|
241 |
set_block(i, &_empty_block); |
|
242 |
} else { |
|
243 |
BitBlock *new_block = alloc_block(); |
|
24425 | 244 |
memcpy(new_block->words(), block->words(), sizeof(uint32_t) * words_per_block); |
1 | 245 |
set_block(i, new_block); |
246 |
} |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
//---------------------------- IndexSet::initialize() ----------------------------- |
|
251 |
// Prepare an IndexSet for use. |
|
252 |
||
253 |
void IndexSet::initialize(uint max_elements) { |
|
254 |
#ifdef ASSERT |
|
255 |
_serial_number = _serial_count++; |
|
256 |
check_watch("initialized", max_elements); |
|
257 |
_max_elements = max_elements; |
|
258 |
#endif |
|
259 |
_count = 0; |
|
59081 | 260 |
_current_block_limit = 0; |
1 | 261 |
_max_blocks = (max_elements + bits_per_block - 1) / bits_per_block; |
262 |
||
263 |
if (_max_blocks <= preallocated_block_list_size) { |
|
264 |
_blocks = _preallocated_block_list; |
|
265 |
} else { |
|
51078 | 266 |
_blocks = (IndexSet::BitBlock**) arena()->Amalloc_4(sizeof(IndexSet::BitBlock*) * _max_blocks); |
1 | 267 |
} |
268 |
for (uint i = 0; i < _max_blocks; i++) { |
|
269 |
set_block(i, &_empty_block); |
|
270 |
} |
|
271 |
} |
|
272 |
||
273 |
//---------------------------- IndexSet::initialize()------------------------------ |
|
274 |
// Prepare an IndexSet for use. If it needs to allocate its _blocks array, it does |
|
275 |
// so from the Arena passed as a parameter. BitBlock allocation is still done from |
|
276 |
// the static Arena which was set with reset_memory(). |
|
277 |
||
278 |
void IndexSet::initialize(uint max_elements, Arena *arena) { |
|
279 |
#ifdef ASSERT |
|
280 |
_serial_number = _serial_count++; |
|
281 |
check_watch("initialized2", max_elements); |
|
282 |
_max_elements = max_elements; |
|
283 |
#endif // ASSERT |
|
284 |
_count = 0; |
|
59081 | 285 |
_current_block_limit = 0; |
1 | 286 |
_max_blocks = (max_elements + bits_per_block - 1) / bits_per_block; |
287 |
||
288 |
if (_max_blocks <= preallocated_block_list_size) { |
|
289 |
_blocks = _preallocated_block_list; |
|
290 |
} else { |
|
51078 | 291 |
_blocks = (IndexSet::BitBlock**) arena->Amalloc_4(sizeof(IndexSet::BitBlock*) * _max_blocks); |
1 | 292 |
} |
293 |
for (uint i = 0; i < _max_blocks; i++) { |
|
294 |
set_block(i, &_empty_block); |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
//---------------------------- IndexSet::swap() ----------------------------- |
|
299 |
// Exchange two IndexSets. |
|
300 |
||
301 |
void IndexSet::swap(IndexSet *set) { |
|
302 |
#ifdef ASSERT |
|
303 |
assert(_max_elements == set->_max_elements, "must have same universe size to swap"); |
|
304 |
check_watch("swap", set->_serial_number); |
|
305 |
set->check_watch("swap", _serial_number); |
|
306 |
#endif |
|
307 |
||
59081 | 308 |
uint max = MAX2(_current_block_limit, set->_current_block_limit); |
309 |
for (uint i = 0; i < max; i++) { |
|
1 | 310 |
BitBlock *temp = _blocks[i]; |
311 |
set_block(i, set->_blocks[i]); |
|
312 |
set->set_block(i, temp); |
|
313 |
} |
|
314 |
uint temp = _count; |
|
315 |
_count = set->_count; |
|
316 |
set->_count = temp; |
|
59081 | 317 |
|
318 |
temp = _current_block_limit; |
|
319 |
_current_block_limit = set->_current_block_limit; |
|
320 |
set->_current_block_limit = temp; |
|
321 |
||
1 | 322 |
} |
323 |
||
324 |
//---------------------------- IndexSet::dump() ----------------------------- |
|
325 |
// Print this set. Used for debugging. |
|
326 |
||
327 |
#ifndef PRODUCT |
|
328 |
void IndexSet::dump() const { |
|
329 |
IndexSetIterator elements(this); |
|
330 |
||
331 |
tty->print("{"); |
|
332 |
uint i; |
|
333 |
while ((i = elements.next()) != 0) { |
|
334 |
tty->print("L%d ", i); |
|
335 |
} |
|
336 |
tty->print_cr("}"); |
|
337 |
} |
|
338 |
#endif |
|
339 |
||
340 |
#ifdef ASSERT |
|
341 |
//---------------------------- IndexSet::tally_iteration_statistics() ----------------------------- |
|
342 |
// Update block/bit counts to reflect that this set has been iterated over. |
|
343 |
||
344 |
void IndexSet::tally_iteration_statistics() const { |
|
8320 | 345 |
inc_stat_counter(&_total_bits, count()); |
1 | 346 |
|
347 |
for (uint i = 0; i < _max_blocks; i++) { |
|
348 |
if (_blocks[i] != &_empty_block) { |
|
8320 | 349 |
inc_stat_counter(&_total_used_blocks, 1); |
1 | 350 |
} else { |
8320 | 351 |
inc_stat_counter(&_total_unused_blocks, 1); |
1 | 352 |
} |
353 |
} |
|
354 |
} |
|
355 |
||
356 |
//---------------------------- IndexSet::print_statistics() ----------------------------- |
|
357 |
// Print statistics about IndexSet usage. |
|
358 |
||
359 |
void IndexSet::print_statistics() { |
|
8320 | 360 |
julong total_blocks = _total_used_blocks + _total_unused_blocks; |
1 | 361 |
tty->print_cr ("Accumulated IndexSet usage statistics:"); |
362 |
tty->print_cr ("--------------------------------------"); |
|
363 |
tty->print_cr (" Iteration:"); |
|
8320 | 364 |
tty->print_cr (" blocks visited: " UINT64_FORMAT, total_blocks); |
365 |
tty->print_cr (" blocks empty: %4.2f%%", 100.0*(double)_total_unused_blocks/total_blocks); |
|
366 |
tty->print_cr (" bit density (bits/used blocks): %4.2f", (double)_total_bits/_total_used_blocks); |
|
367 |
tty->print_cr (" bit density (bits/all blocks): %4.2f", (double)_total_bits/total_blocks); |
|
1 | 368 |
tty->print_cr (" Allocation:"); |
8320 | 369 |
tty->print_cr (" blocks allocated: " UINT64_FORMAT, _alloc_new); |
370 |
tty->print_cr (" blocks used/reused: " UINT64_FORMAT, _alloc_total); |
|
1 | 371 |
} |
372 |
||
373 |
//---------------------------- IndexSet::verify() ----------------------------- |
|
374 |
// Expensive test of IndexSet sanity. Ensure that the count agrees with the |
|
375 |
// number of bits in the blocks. Make sure the iterator is seeing all elements |
|
376 |
// of the set. Meant for use during development. |
|
377 |
||
378 |
void IndexSet::verify() const { |
|
379 |
assert(!member(0), "zero cannot be a member"); |
|
380 |
uint count = 0; |
|
381 |
uint i; |
|
382 |
for (i = 1; i < _max_elements; i++) { |
|
383 |
if (member(i)) { |
|
384 |
count++; |
|
385 |
assert(count <= _count, "_count is messed up"); |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
IndexSetIterator elements(this); |
|
390 |
count = 0; |
|
391 |
while ((i = elements.next()) != 0) { |
|
392 |
count++; |
|
393 |
assert(member(i), "returned a non member"); |
|
394 |
assert(count <= _count, "iterator returned wrong number of elements"); |
|
395 |
} |
|
396 |
} |
|
397 |
#endif |
|
398 |
||
399 |
//---------------------------- IndexSetIterator() ----------------------------- |
|
400 |
// Create an iterator for a set. If empty blocks are detected when iterating |
|
401 |
// over the set, these blocks are replaced. |
|
402 |
||
403 |
//---------------------------- List16Iterator::advance_and_next() ----------------------------- |
|
404 |
// Advance to the next non-empty word in the set being iterated over. Return the next element |
|
405 |
// if there is one. If we are done, return 0. This method is called from the next() method |
|
406 |
// when it gets done with a word. |
|
407 |
||
408 |
uint IndexSetIterator::advance_and_next() { |
|
409 |
// See if there is another non-empty word in the current block. |
|
410 |
for (uint wi = _next_word; wi < (unsigned)IndexSet::words_per_block; wi++) { |
|
411 |
if (_words[wi] != 0) { |
|
412 |
// Found a non-empty word. |
|
413 |
_value = ((_next_block - 1) * IndexSet::bits_per_block) + (wi * IndexSet::bits_per_word); |
|
414 |
_current = _words[wi]; |
|
59081 | 415 |
_next_word = wi + 1; |
416 |
return next_value(); |
|
1 | 417 |
} |
418 |
} |
|
419 |
||
420 |
// We ran out of words in the current block. Advance to next non-empty block. |
|
421 |
for (uint bi = _next_block; bi < _max_blocks; bi++) { |
|
422 |
if (_blocks[bi] != &IndexSet::_empty_block) { |
|
423 |
// Found a non-empty block. |
|
424 |
||
425 |
_words = _blocks[bi]->words(); |
|
426 |
for (uint wi = 0; wi < (unsigned)IndexSet::words_per_block; wi++) { |
|
427 |
if (_words[wi] != 0) { |
|
428 |
// Found a non-empty word. |
|
429 |
_value = (bi * IndexSet::bits_per_block) + (wi * IndexSet::bits_per_word); |
|
430 |
_current = _words[wi]; |
|
431 |
||
432 |
_next_block = bi+1; |
|
433 |
_next_word = wi+1; |
|
59081 | 434 |
return next_value(); |
1 | 435 |
} |
436 |
} |
|
437 |
||
438 |
// All of the words in the block were empty. Replace |
|
439 |
// the block with the empty block. |
|
440 |
if (_set) { |
|
441 |
_set->free_block(bi); |
|
442 |
} |
|
443 |
} |
|
444 |
} |
|
445 |
||
446 |
// No more words. |
|
447 |
return 0; |
|
448 |
} |