Path: blob/master/src/hotspot/share/gc/z/zBitMap.inline.hpp
40961 views
/*1* Copyright (c) 2016, 2017, 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*/2223#ifndef SHARE_GC_Z_ZBITMAP_INLINE_HPP24#define SHARE_GC_Z_ZBITMAP_INLINE_HPP2526#include "gc/z/zBitMap.hpp"2728#include "runtime/atomic.hpp"29#include "utilities/bitMap.inline.hpp"30#include "utilities/debug.hpp"3132inline ZBitMap::ZBitMap(idx_t size_in_bits) :33CHeapBitMap(size_in_bits, mtGC, false /* clear */) {}3435inline BitMap::bm_word_t ZBitMap::bit_mask_pair(idx_t bit) {36assert(bit_in_word(bit) < BitsPerWord - 1, "Invalid bit index");37return (bm_word_t)3 << bit_in_word(bit);38}3940inline bool ZBitMap::par_set_bit_pair_finalizable(idx_t bit, bool& inc_live) {41inc_live = par_set_bit(bit);42return inc_live;43}4445inline bool ZBitMap::par_set_bit_pair_strong(idx_t bit, bool& inc_live) {46verify_index(bit);47volatile bm_word_t* const addr = word_addr(bit);48const bm_word_t pair_mask = bit_mask_pair(bit);49bm_word_t old_val = *addr;5051do {52const bm_word_t new_val = old_val | pair_mask;53if (new_val == old_val) {54// Someone else beat us to it55inc_live = false;56return false;57}58const bm_word_t cur_val = Atomic::cmpxchg(addr, old_val, new_val);59if (cur_val == old_val) {60// Success61const bm_word_t marked_mask = bit_mask(bit);62inc_live = !(old_val & marked_mask);63return true;64}6566// The value changed, retry67old_val = cur_val;68} while (true);69}7071inline bool ZBitMap::par_set_bit_pair(idx_t bit, bool finalizable, bool& inc_live) {72if (finalizable) {73return par_set_bit_pair_finalizable(bit, inc_live);74} else {75return par_set_bit_pair_strong(bit, inc_live);76}77}7879#endif // SHARE_GC_Z_ZBITMAP_INLINE_HPP808182