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/virtualSpaceNode.hpp"
  30 #include "utilities/globalDefinitions.hpp"
  31 
  32 
  33 namespace metaspace {
  34 
  35 class Metachunk;
  36 
  37 class VirtualSpaceList : public public CHeapObj<mtClass> {
  38 
  39   // Name
  40   const char* const _name;
  41 
  42   // Head of the list.
  43   VirtualSpaceNode* _nodes;
  44 
  45   // Node currently being used for allocations.
  46   VirtualSpaceNode* _current_node;
  47 
  48   // Whether this list can expand by allocating new nodes.
  49   const bool _can_expand;
  50 
  51   // Statistics:
  52 
  53   // Sum of reserved and committed words in all nodes
  54   size_t _reserved_words;
  55   size_t _committed_words;
  56 
  57   // Number of virtual spaces
  58   int _count;
  59 
  60 public:
  61 
  62   // Create a new, empty, expandable list.
  63   VirtualSpaceList(const char* name);
  64 
  65   // Create a new list. The list will contain one node, which uses the given ReservedSpace.
  66   // It will be not expandable beyond that first node.
  67   VirtualSpaceList(const char* name, ReservedSpace* rs);
  68 
  69   ~VirtualSpaceList();
  70 
  71   // Allocate a root chunk from the current node in this list.
  72   // - If the node is full and the list is expandable, a new node may be created.
  73   // - This may fail if we either hit the GC threshold or the metaspace limits.
  74   // Returns NULL if it failed.
  75   Metachunk* allocate_root_chunk();
  76 
  77   // Remove all nodes which only contain empty chunks from the list,
  78   // remove the chunks from the ChunkManager, and unmap those nodes.
  79   void purge();
  80 
  81   DEBUG_ONLY(void verify(bool slow);)
  82 
  83 };
  84 
  85 } // namespace metaspace
  86 
  87 #endif // SHARE_MEMORY_METASPACE_VIRTUALSPACELIST_HPP