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_CLASSLOADERMETASPACE_HPP
  26 #define SHARE_MEMORY_METASPACE_CLASSLOADERMETASPACE_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/metaspace/metaspaceEnums.hpp"
  30 
  31 class Mutex;
  32 
  33 namespace metaspace {
  34 
  35 class SpaceManager;
  36 class ClassLoaderMetaspaceStatistics;
  37 
  38 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
  39 
  40   // The CLD lock.
  41   Mutex* const _lock;
  42 
  43   const MetaspaceType _space_type;
  44 
  45   SpaceManager* _non_class_space_manager;
  46   SpaceManager* _class_space_manager;
  47 
  48   Mutex* lock() const                            { return _lock; }
  49   SpaceManager* non_class_space_manager() const  { return _non_class_space_manager; }
  50   SpaceManager* class_space_manager() const      { return _class_space_manager; }
  51 
  52   SpaceManager* get_space_manager(bool is_class) {
  53     return is_class ? class_space_manager() : non_class_space_manager();
  54   }
  55 
  56 public:
  57 
  58   ClassLoaderMetaspace(Mutex* lock, MetaspaceType space_type);
  59 
  60   ~ClassLoaderMetaspace();
  61 
  62   MetaspaceType space_type() const { return _space_type; }
  63 
  64   // Allocate word_size words from Metaspace.
  65   MetaWord* allocate(size_t word_size, MetadataType mdType);
  66 
  67   // Attempt to expand the GC threshold to be good for at least another word_size words
  68   // and allocate. Returns NULL if failure. Used during Metaspace GC.
  69   MetaWord* expand_and_allocate(size_t word_size, MetadataType mdType);
  70 
  71   // Prematurely returns a metaspace allocation to the _block_freelists
  72   // because it is not needed anymore.
  73   void deallocate(MetaWord* ptr, size_t word_size, bool is_class);
  74 
  75   // Update statistics. This walks all in-use chunks.
  76   void add_to_statistics(ClassLoaderMetaspaceStatistics* out) const;
  77 
  78   DEBUG_ONLY(void verify(bool slow) const;)
  79 
  80   // TODO
  81   size_t allocated_blocks_bytes() const { return 0; }
  82   size_t allocated_chunks_bytes() const { return 0; }
  83 
  84 };
  85 
  86 } // namespace metaspace
  87 
  88 #endif // SHARE_MEMORY_METASPACE_CLASSLOADERMETASPACE_HPP