1 /* 2 * Copyright (c) 2012, 2020, Oracle and/or its affiliates. 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 it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 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 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_MEMORY_METASPACE_METABASE_HPP 26 #define SHARE_MEMORY_METASPACE_METABASE_HPP 27 28 #include "utilities/globalDefinitions.hpp" 29 30 namespace metaspace { 31 32 // Super class of Metablock and Metachunk to allow them to 33 // be put on the FreeList and in the BinaryTreeDictionary. 34 template <class T> 35 class Metabase { 36 size_t _word_size; 37 T* _next; 38 T* _prev; 39 40 protected: 41 Metabase(size_t word_size) : _word_size(word_size), _next(NULL), _prev(NULL) {} 42 43 public: 44 T* next() const { return _next; } 45 T* prev() const { return _prev; } 46 void set_next(T* v) { _next = v; assert(v != this, "Boom");} 47 void set_prev(T* v) { _prev = v; assert(v != this, "Boom");} 48 void clear_next() { set_next(NULL); } 49 void clear_prev() { set_prev(NULL); } 50 51 size_t size() const { return _word_size; } 52 53 void link_next(T* ptr) { set_next(ptr); } 54 void link_prev(T* ptr) { set_prev(ptr); } 55 void link_after(T* ptr) { 56 link_next(ptr); 57 if (ptr != NULL) ptr->link_prev((T*)this); 58 } 59 60 uintptr_t* end() const { return ((uintptr_t*) this) + size(); } 61 62 bool cantCoalesce() const { return false; } 63 64 // Debug support 65 #ifdef ASSERT 66 void* prev_addr() const { return (void*)&_prev; } 67 void* next_addr() const { return (void*)&_next; } 68 void* size_addr() const { return (void*)&_word_size; } 69 #endif 70 bool verify_chunk_in_free_list(T* tc) const { return true; } 71 bool verify_par_locked() { return true; } 72 73 void assert_is_mangled() const {/* Don't check "\*/} 74 75 bool is_free() { return true; } 76 }; 77 78 } // namespace metaspace 79 80 #endif // SHARE_MEMORY_METASPACE_METABASE_HPP