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