Path: blob/master/src/hotspot/share/memory/metaspace/commitMask.cpp
40957 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2020 SAP SE. All rights reserved.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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "memory/metaspace/commitMask.hpp"27#include "memory/metaspace/metaspaceCommon.hpp"28#include "memory/metaspace/metaspaceSettings.hpp"29#include "runtime/stubRoutines.hpp"30#include "utilities/align.hpp"31#include "utilities/debug.hpp"3233namespace metaspace {3435CommitMask::CommitMask(const MetaWord* start, size_t word_size) :36CHeapBitMap(mask_size(word_size, Settings::commit_granule_words())),37_base(start),38_word_size(word_size),39_words_per_bit(Settings::commit_granule_words())40{41assert(_word_size > 0 && _words_per_bit > 0 &&42is_aligned(_word_size, _words_per_bit), "Sanity");43}4445#ifdef ASSERT4647// Given a pointer, check if it points into the range this bitmap covers.48bool CommitMask::is_pointer_valid(const MetaWord* p) const {49return p >= _base && p < _base + _word_size;50}5152// Given a pointer, check if it points into the range this bitmap covers.53void CommitMask::check_pointer(const MetaWord* p) const {54assert(is_pointer_valid(p),55"Pointer " PTR_FORMAT " not in range of this bitmap [" PTR_FORMAT ", " PTR_FORMAT ").",56p2i(p), p2i(_base), p2i(_base + _word_size));57}58// Given a pointer, check if it points into the range this bitmap covers,59// and if it is aligned to commit granule border.60void CommitMask::check_pointer_aligned(const MetaWord* p) const {61check_pointer(p);62assert(is_aligned(p, _words_per_bit * BytesPerWord),63"Pointer " PTR_FORMAT " should be aligned to commit granule size " SIZE_FORMAT ".",64p2i(p), _words_per_bit * BytesPerWord);65}66// Given a range, check if it points into the range this bitmap covers,67// and if its borders are aligned to commit granule border.68void CommitMask::check_range(const MetaWord* start, size_t word_size) const {69check_pointer_aligned(start);70assert(is_aligned(word_size, _words_per_bit),71"Range " SIZE_FORMAT " should be aligned to commit granule size " SIZE_FORMAT ".",72word_size, _words_per_bit);73check_pointer(start + word_size - 1);74}7576void CommitMask::verify() const {77// Walk the whole commit mask.78// For each 1 bit, check if the associated granule is accessible.79// For each 0 bit, check if the associated granule is not accessible. Slow mode only.80assert(_base != NULL && _word_size > 0 && _words_per_bit > 0, "Sanity");81assert_is_aligned(_base, _words_per_bit * BytesPerWord);82assert_is_aligned(_word_size, _words_per_bit);83}8485#endif // ASSERT8687void CommitMask::print_on(outputStream* st) const {88st->print("commit mask, base " PTR_FORMAT ":", p2i(base()));89for (idx_t i = 0; i < size(); i++) {90st->print("%c", at(i) ? 'X' : '-');91}92st->cr();93}9495} // namespace metaspace96979899