/* * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_MEMORY_METASPACE_VIRTUALSPACELIST_HPP #define SHARE_MEMORY_METASPACE_VIRTUALSPACELIST_HPP #include "memory/allocation.hpp" #include "memory/metaspace/counter.hpp" #include "memory/metaspace/commitLimiter.hpp" #include "memory/metaspace/virtualSpaceNode.hpp" #include "memory/virtualspace.hpp" #include "utilities/globalDefinitions.hpp" class outputStream; namespace metaspace { class Metachunk; class VirtualSpaceList : public CHeapObj { // Name const char* const _name; // Head of the list. VirtualSpaceNode* _first_node; // Node currently being used for allocations. VirtualSpaceNode* _current_node; // Whether this list can expand by allocating new nodes. const bool _can_expand; // Used to check limits before committing memory. CommitLimiter* const _commit_limiter; // Statistics // Holds sum of reserved space, in words, over all list nodes. SizeCounter _reserved_words_counter; // Holds sum of committed space, in words, over all list nodes. SizeCounter _committed_words_counter; // Create a new node and append it to the list. After // this function, _current_node shall point to a new empty node. // List must be expandable for this to work. void create_new_node(); public: // Create a new, empty, expandable list. VirtualSpaceList(const char* name, CommitLimiter* commit_limiter); // Create a new list. The list will contain one node only, which uses the given ReservedSpace. // It will be not expandable beyond that first node. VirtualSpaceList(const char* name, ReservedSpace rs, CommitLimiter* commit_limiter); virtual ~VirtualSpaceList(); // Allocate a root chunk from this list. // Note: this just returns a chunk whose memory is reserved; no memory is committed yet. // Hence, before using this chunk, it must be committed. // Also, no limits are checked, since no committing takes place. Metachunk* allocate_root_chunk(); //// Statistics //// // Return sum of reserved words in all nodes. size_t reserved_words() const { return _reserved_words_counter.get(); } // Return sum of committed words in all nodes. size_t committed_words() const { return _committed_words_counter.get(); } //// Debug stuff //// DEBUG_ONLY(void verify(bool slow) const;) // Print all nodes in this space list. void print_on(outputStream* st) const { print_on(st, K); } void print_on(outputStream* st, size_t scale) const; // Returns true if this pointer is contained in one of our nodes. bool contains(const MetaWord* p) const; private: static VirtualSpaceList* _vslist_class; static VirtualSpaceList* _vslist_nonclass; public: static VirtualSpaceList* vslist_class() { return _vslist_class; } static VirtualSpaceList* vslist_nonclass() { return _vslist_nonclass; } static void set_vslist_class(VirtualSpaceList* vslist_class); static void set_vslist_nonclass(VirtualSpaceList* vslist_class); }; } // namespace metaspace #endif // SHARE_MEMORY_METASPACE_VIRTUALSPACELIST_HPP