1 /* 2 * Copyright (c) 2023 Red Hat, Inc. All rights reserved. 3 * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #ifndef SHARE_MEMORY_METASPACE_METABLOCK_HPP 27 #define SHARE_MEMORY_METASPACE_METABLOCK_HPP 28 29 #include "utilities/globalDefinitions.hpp" 30 31 class outputStream; 32 33 namespace metaspace { 34 35 // Tiny structure to be passed by value 36 class MetaBlock { 37 38 MetaWord* _base; 39 size_t _word_size; 40 41 public: 42 43 MetaBlock(MetaWord* p, size_t word_size) : 44 _base(word_size == 0 ? nullptr : p), _word_size(word_size) {} 45 MetaBlock() : MetaBlock(nullptr, 0) {} 46 47 MetaWord* base() const { return _base; } 48 const MetaWord* end() const { return _base + _word_size; } 49 size_t word_size() const { return _word_size; } 50 bool is_empty() const { return _base == nullptr; } 51 bool is_nonempty() const { return _base != nullptr; } 52 void reset() { _base = nullptr; _word_size = 0; } 53 54 bool operator==(const MetaBlock& rhs) const { 55 return base() == rhs.base() && 56 word_size() == rhs.word_size(); 57 } 58 59 // Split off tail block. 60 inline MetaBlock split_off_tail(size_t tailsize); 61 62 DEBUG_ONLY(inline void verify() const;) 63 64 // Convenience functions 65 inline bool is_aligned_base(size_t alignment_words) const; 66 inline bool is_aligned_size(size_t alignment_words) const; 67 68 void print_on(outputStream* st) const; 69 }; 70 71 #define METABLOCKFORMAT "block (@" PTR_FORMAT " word size " SIZE_FORMAT ")" 72 #define METABLOCKFORMATARGS(__block__) p2i((__block__).base()), (__block__).word_size() 73 74 } // namespace metaspace 75 76 #endif // SHARE_MEMORY_METASPACE_METABLOCK_HPP