Path: blob/master/src/hotspot/share/libadt/vectset.cpp
40951 views
/*1* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "libadt/vectset.hpp"26#include "memory/arena.hpp"27#include "memory/resourceArea.hpp"28#include "utilities/count_leading_zeros.hpp"29#include "utilities/powerOfTwo.hpp"3031VectorSet::VectorSet() {32init(Thread::current()->resource_area());33}3435VectorSet::VectorSet(Arena* arena) {36init(arena);37}3839void 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}4748// Expand the existing set to a bigger size49void VectorSet::grow(uint new_word_capacity) {50assert(new_word_capacity < (1U << 30), "");51uint x = next_power_of_2(new_word_capacity);52if (x > _data_size) {53_data = REALLOC_ARENA_ARRAY(_set_arena, uint32_t, _data, _size, x);54_data_size = x;55}56Copy::zero_to_bytes(_data + _size, (x - _size) * sizeof(uint32_t));57_size = x;58}5960// Insert a member into an existing Set.61void VectorSet::insert(uint elem) {62uint32_t word = elem >> word_bits;63uint32_t mask = 1U << (elem & bit_mask);64if (word >= _size) {65grow(word);66}67_data[word] |= mask;68}6970// Return true if the set is empty71bool VectorSet::is_empty() const {72for (uint32_t i = 0; i < _size; i++) {73if (_data[i] != 0) {74return false;75}76}77return true;78}798081