30
31 VectorSet::VectorSet() {
32 init(Thread::current()->resource_area());
33 }
34
35 VectorSet::VectorSet(Arena* arena) {
36 init(arena);
37 }
38
39 void VectorSet::init(Arena* arena) {
40 _size = 2;
41 _data = NEW_ARENA_ARRAY(arena, uint32_t, 2);
42 _data_size = 2;
43 _set_arena = arena;
44 _data[0] = 0;
45 _data[1] = 0;
46 }
47
48 // Expand the existing set to a bigger size
49 void VectorSet::grow(uint new_word_capacity) {
50 _nesting.check(_set_arena); // Check if a potential reallocation in the arena is safe
51 assert(new_word_capacity >= _size, "Should have been checked before, use maybe_grow?");
52 assert(new_word_capacity < (1U << 30), "");
53 uint x = next_power_of_2(new_word_capacity);
54 if (x > _data_size) {
55 _data = REALLOC_ARENA_ARRAY(_set_arena, uint32_t, _data, _size, x);
56 _data_size = x;
57 }
58 Copy::zero_to_bytes(_data + _size, (x - _size) * sizeof(uint32_t));
59 _size = x;
60 }
61
62 // Insert a member into an existing Set.
63 void VectorSet::insert(uint elem) {
64 uint32_t word = elem >> word_bits;
65 uint32_t mask = 1U << (elem & bit_mask);
66 maybe_grow(word);
67 _data[word] |= mask;
68 }
69
70 // Return true if the set is empty
|
30
31 VectorSet::VectorSet() {
32 init(Thread::current()->resource_area());
33 }
34
35 VectorSet::VectorSet(Arena* arena) {
36 init(arena);
37 }
38
39 void VectorSet::init(Arena* arena) {
40 _size = 2;
41 _data = NEW_ARENA_ARRAY(arena, uint32_t, 2);
42 _data_size = 2;
43 _set_arena = arena;
44 _data[0] = 0;
45 _data[1] = 0;
46 }
47
48 // Expand the existing set to a bigger size
49 void VectorSet::grow(uint new_word_capacity) {
50 assert(new_word_capacity >= _size, "Should have been checked before, use maybe_grow?");
51 assert(new_word_capacity < (1U << 30), "");
52 uint x = next_power_of_2(new_word_capacity);
53 if (x > _data_size) {
54 _data = REALLOC_ARENA_ARRAY(_set_arena, uint32_t, _data, _size, x);
55 _data_size = x;
56 }
57 Copy::zero_to_bytes(_data + _size, (x - _size) * sizeof(uint32_t));
58 _size = x;
59 }
60
61 // Insert a member into an existing Set.
62 void VectorSet::insert(uint elem) {
63 uint32_t word = elem >> word_bits;
64 uint32_t mask = 1U << (elem & bit_mask);
65 maybe_grow(word);
66 _data[word] |= mask;
67 }
68
69 // Return true if the set is empty
|