author | alitvinov |
Thu, 21 Nov 2019 17:04:27 +0000 | |
changeset 59207 | 7a3218ad8e7c |
parent 59121 | 7cbffba2156b |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53546 | 2 |
* Copyright (c) 1997, 2019, 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 "libadt/vectset.hpp" |
|
27 |
#include "memory/allocation.inline.hpp" |
|
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
28 |
#include "memory/arena.hpp" |
59121 | 29 |
#include "utilities/count_leading_zeros.hpp" |
1 | 30 |
|
59121 | 31 |
VectorSet::VectorSet(Arena *arena) : _size(2), |
32 |
_data(NEW_ARENA_ARRAY(arena, uint32_t, 2)), |
|
33 |
_set_arena(arena) { |
|
34 |
_data[0] = 0; |
|
35 |
_data[1] = 0; |
|
1 | 36 |
} |
37 |
||
38 |
// Expand the existing set to a bigger size |
|
59121 | 39 |
void VectorSet::grow(uint new_size) { |
40 |
new_size = (new_size + bit_mask) >> word_bits; |
|
41 |
assert(new_size != 0 && new_size < (1U << 31), ""); |
|
42 |
uint x = (1U << 31) >> (count_leading_zeros(new_size) - 1); |
|
43 |
_data = REALLOC_ARENA_ARRAY(_set_arena, uint32_t, _data, _size, x); |
|
44 |
Copy::zero_to_bytes(_data + _size, (x - _size) * sizeof(uint32_t)); |
|
45 |
_size = x; |
|
1 | 46 |
} |
47 |
||
48 |
// Insert a member into an existing Set. |
|
58962 | 49 |
void VectorSet::insert(uint elem) { |
59121 | 50 |
uint32_t word = elem >> word_bits; |
51 |
uint32_t mask = 1U << (elem & bit_mask); |
|
52 |
if (word >= _size) { |
|
58962 | 53 |
grow(elem + 1); |
1 | 54 |
} |
59121 | 55 |
_data[word] |= mask; |
1 | 56 |
} |
57 |
||
59121 | 58 |
// Resets the storage |
59 |
void VectorSet::reset_memory() { |
|
60 |
assert(_size >= 2, "_size can never be less than 2"); |
|
61 |
_data = REALLOC_ARENA_ARRAY(_set_arena, uint32_t, _data, _size, 2); |
|
62 |
_size = 2; |
|
63 |
_data[0] = 0; |
|
64 |
_data[1] = 0; |
|
1 | 65 |
} |
66 |
||
58962 | 67 |
// Return true if the set is empty |
68 |
bool VectorSet::is_empty() const { |
|
59121 | 69 |
for (uint32_t i = 0; i < _size; i++) { |
70 |
if (_data[i] != 0) { |
|
58962 | 71 |
return false; |
72 |
} |
|
73 |
} |
|
74 |
return true; |
|
10975 | 75 |
} |