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_RUNNINGCOUNTERS_HPP
  26 #define SHARE_MEMORY_METASPACE_RUNNINGCOUNTERS_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/metaspace/counter.hpp"
  30 
  31 namespace metaspace {
  32 
  33 class ClassLoaderMetaspace;
  34 
  35 // These are running counters for some basic Metaspace statistics.
  36 // Their value can be obtained quickly without locking.
  37 
  38 class RunningCounters : public AllStatic {
  39 
  40   friend class ClassLoaderMetaspace;
  41 
  42   // ---- in-use chunks ----
  43 
  44   // Used space, in words.
  45   // (Note that the used counter is on the hot path of Metaspace allocation.
  46   //  Do we really need it? We may get by with capacity only and get more details
  47   //  with get_statistics_slow().)
  48   static SizeAtomicCounter _used_class;
  49   static SizeAtomicCounter _used_nonclass;
  50 
  51 public:
  52 
  53   // ---- virtual memory -----
  54 
  55   // Return reserved size, in words, for Metaspace
  56   static size_t reserved_words();
  57   static size_t reserved_words_class();
  58   static size_t reserved_words_nonclass();
  59 
  60   // Return total committed size, in words, for Metaspace
  61   static size_t committed_words();
  62   static size_t committed_words_class();
  63   static size_t committed_words_nonclass();
  64 
  65 
  66   // ---- used chunks -----
  67 
  68   // Returns size, in words, used for metadata.
  69   static size_t used_words();
  70   static size_t used_words_class();
  71   static size_t used_words_nonclass();
  72 
  73   // ---- free chunks -----
  74 
  75   // Returns size, in words, of all chunks in all freelists.
  76   static size_t free_chunks_words();
  77   static size_t free_chunks_words_class();
  78   static size_t free_chunks_words_nonclass();
  79 
  80 
  81 };
  82 
  83 } // namespace metaspace
  84 
  85 #endif // SHARE_MEMORY_METASPACE_RUNNINGCOUNTERS_HPP
  86 
  87