1 /* 2 * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2020 SAP SE. 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 #include "precompiled.hpp" 27 28 #include "memory/metaspace/metachunkList.hpp" 29 #include "utilities/debug.hpp" 30 #include "utilities/globalDefinitions.hpp" 31 #include "utilities/ostream.hpp" 32 33 34 namespace metaspace { 35 36 #ifdef ASSERT 37 38 bool MetachunkList::contains(const Metachunk* c) const { 39 for (Metachunk* c2 = _first; c2 != NULL; c2 = c2->next()) { 40 if (c == c2) { 41 return true; 42 } 43 } 44 return false; 45 } 46 47 void MetachunkList::verify() const { 48 int num = 0; 49 const Metachunk* last_c = NULL; 50 for (const Metachunk* c = _first; c != NULL; c = c->next()) { 51 num ++; 52 assert(c->prev() != c && c->next() != c, "circularity"); 53 assert(c->prev() == last_c, 54 "Broken link to predecessor. Chunk " METACHUNK_FULL_FORMAT ".", 55 METACHUNK_FULL_FORMAT_ARGS(c)); 56 c->verify(false); 57 last_c = c; 58 } 59 _num_chunks.check(num); 60 } 61 62 #endif // ASSERT 63 64 65 size_t MetachunkList::calc_committed_word_size() const { 66 67 if (_first != NULL && _first->is_dead()) { 68 // list used for chunk header pool; dead chunks have no size. 69 return 0; 70 } 71 72 size_t s = 0; 73 for (Metachunk* c = _first; c != NULL; c = c->next()) { 74 assert(c->is_dead() == false, "Sanity"); 75 s += c->committed_words(); 76 } 77 return s; 78 } 79 80 size_t MetachunkList::calc_word_size() const { 81 82 if (_first != NULL && _first->is_dead()) { 83 // list used for chunk header pool; dead chunks have no size. 84 return 0; 85 } 86 87 size_t s = 0; 88 for (Metachunk* c = _first; c != NULL; c = c->next()) { 89 assert(c->is_dead() == false, "Sanity"); 90 s += c->committed_words(); 91 } 92 return s; 93 94 } 95 96 void MetachunkList::print_on(outputStream* st) const { 97 98 if (_num_chunks.get() > 0) { 99 for (const Metachunk* c = _first; c != NULL; c = c->next()) { 100 st->print(" - <"); 101 c->print_on(st); 102 st->print(">"); 103 } 104 st->print(" - total : %d chunks.", _num_chunks.get()); 105 } else { 106 st->print("empty"); 107 } 108 109 } 110 111 112 } // namespace metaspace 113