1 /* 2 * Copyright (c) 2018, 2019, 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_VIRTUALSPACELIST_HPP 26 #define SHARE_MEMORY_METASPACE_VIRTUALSPACELIST_HPP 27 28 #include "memory/allocation.hpp" 29 #include "memory/metaspace/counter.hpp" 30 #include "memory/metaspace/commitLimiter.hpp" 31 #include "memory/metaspace/virtualSpaceNode.hpp" 32 #include "memory/virtualspace.hpp" 33 #include "utilities/globalDefinitions.hpp" 34 35 class outputStream; 36 37 namespace metaspace { 38 39 class Metachunk; 40 41 class VirtualSpaceList : public CHeapObj<mtClass> { 42 43 // Name 44 const char* const _name; 45 46 // Head of the list. 47 VirtualSpaceNode* _first_node; 48 49 // Node currently being used for allocations. 50 VirtualSpaceNode* _current_node; 51 52 // Whether this list can expand by allocating new nodes. 53 const bool _can_expand; 54 55 // Used to check limits before committing memory. 56 CommitLimiter* const _commit_limiter; 57 58 // Statistics 59 60 // Holds sum of reserved space, in words, over all list nodes. 61 SizeCounter _reserved_words_counter; 62 63 // Holds sum of committed space, in words, over all list nodes. 64 SizeCounter _committed_words_counter; 65 66 // Create a new node and append it to the list. After 67 // this function, _current_node shall point to a new empty node. 68 // List must be expandable for this to work. 69 void create_new_node(); 70 71 public: 72 73 // Create a new, empty, expandable list. 74 VirtualSpaceList(const char* name, CommitLimiter* commit_limiter); 75 76 // Create a new list. The list will contain one node only, which uses the given ReservedSpace. 77 // It will be not expandable beyond that first node. 78 VirtualSpaceList(const char* name, ReservedSpace rs, CommitLimiter* commit_limiter); 79 80 virtual ~VirtualSpaceList(); 81 82 // Allocate a root chunk from this list. 83 // Note: this just returns a chunk whose memory is reserved; no memory is committed yet. 84 // Hence, before using this chunk, it must be committed. 85 // Also, no limits are checked, since no committing takes place. 86 Metachunk* allocate_root_chunk(); 87 88 //// Statistics //// 89 90 // Return sum of reserved words in all nodes. 91 size_t reserved_words() const { return _reserved_words_counter.get(); } 92 93 // Return sum of committed words in all nodes. 94 size_t committed_words() const { return _committed_words_counter.get(); } 95 96 //// Debug stuff //// 97 DEBUG_ONLY(void verify(bool slow) const;) 98 99 // Print all nodes in this space list. 100 void print_on(outputStream* st) const { print_on(st, K); } 101 void print_on(outputStream* st, size_t scale) const; 102 103 // Returns true if this pointer is contained in one of our nodes. 104 bool contains(const MetaWord* p) const; 105 106 private: 107 108 static VirtualSpaceList* _vslist_class; 109 static VirtualSpaceList* _vslist_nonclass; 110 111 public: 112 113 static VirtualSpaceList* vslist_class() { return _vslist_class; } 114 static VirtualSpaceList* vslist_nonclass() { return _vslist_nonclass; } 115 116 static void set_vslist_class(VirtualSpaceList* vslist_class); 117 static void set_vslist_nonclass(VirtualSpaceList* vslist_class); 118 119 120 }; 121 122 } // namespace metaspace 123 124 #endif // SHARE_MEMORY_METASPACE_VIRTUALSPACELIST_HPP