1 /*
   2  * Copyright (c) 2018, 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 #include "precompiled.hpp"
  26 #include "memory/metaspace/counter.hpp"
  27 #include "memory/metaspace/runningCounters.hpp"
  28 #include "memory/metaspace/virtualSpaceList.hpp"
  29 #include "memory/metaspace/chunkManager.hpp"
  30 
  31 namespace metaspace {
  32 
  33 SizeAtomicCounter RunningCounters::_used_class;
  34 SizeAtomicCounter RunningCounters::_used_nonclass;
  35 
  36 // Return reserved size, in words, for Metaspace
  37 size_t RunningCounters::reserved_words() {
  38   return reserved_words_class() + reserved_words_nonclass();
  39 }
  40 
  41 size_t RunningCounters::reserved_words_class() {
  42   VirtualSpaceList* vs = VirtualSpaceList::vslist_class();
  43   return vs != NULL ? vs->reserved_words() : 0;
  44 }
  45 
  46 size_t RunningCounters::reserved_words_nonclass() {
  47   return VirtualSpaceList::vslist_nonclass()->reserved_words();
  48 }
  49 
  50 // Return total committed size, in words, for Metaspace
  51 size_t RunningCounters::committed_words() {
  52   return committed_words_class() + committed_words_nonclass();
  53 }
  54 
  55 size_t RunningCounters::committed_words_class() {
  56   VirtualSpaceList* vs = VirtualSpaceList::vslist_class();
  57   return vs != NULL ? vs->committed_words() : 0;
  58 }
  59 
  60 size_t RunningCounters::committed_words_nonclass() {
  61   return VirtualSpaceList::vslist_nonclass()->committed_words();
  62 }
  63 
  64 
  65 // ---- used chunks -----
  66 
  67 // Returns size, in words, used for metadata.
  68 size_t RunningCounters::used_words() {
  69   return used_words_class() + used_words_nonclass();
  70 }
  71 
  72 size_t RunningCounters::used_words_class() {
  73   return _used_class.get();
  74 }
  75 
  76 size_t RunningCounters::used_words_nonclass() {
  77   return _used_nonclass.get();
  78 }
  79 
  80 // ---- free chunks -----
  81 
  82 // Returns size, in words, of all chunks in all freelists.
  83 size_t RunningCounters::free_chunks_words() {
  84   return free_chunks_words_class() + free_chunks_words_nonclass();
  85 }
  86 
  87 size_t RunningCounters::free_chunks_words_class() {
  88   ChunkManager* cm = ChunkManager::chunkmanager_class();
  89   return cm != NULL ? cm->total_word_size() : 0;
  90 }
  91 
  92 size_t RunningCounters::free_chunks_words_nonclass() {
  93   return ChunkManager::chunkmanager_nonclass()->total_word_size();
  94 }
  95 
  96 } // namespace metaspace
  97 
  98