1 /*
   2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2020 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "memory/metaspace/counter.hpp"
  28 #include "memory/metaspace/runningCounters.hpp"
  29 #include "memory/metaspace/virtualSpaceList.hpp"
  30 #include "memory/metaspace/chunkManager.hpp"
  31 
  32 namespace metaspace {
  33 
  34 SizeAtomicCounter RunningCounters::_used_class_counter;
  35 SizeAtomicCounter RunningCounters::_used_nonclass_counter;
  36 
  37 // Return reserved size, in words, for Metaspace
  38 size_t RunningCounters::reserved_words() {
  39   return reserved_words_class() + reserved_words_nonclass();
  40 }
  41 
  42 size_t RunningCounters::reserved_words_class() {
  43   VirtualSpaceList* vs = VirtualSpaceList::vslist_class();
  44   return vs != NULL ? vs->reserved_words() : 0;
  45 }
  46 
  47 size_t RunningCounters::reserved_words_nonclass() {
  48   return VirtualSpaceList::vslist_nonclass()->reserved_words();
  49 }
  50 
  51 // Return total committed size, in words, for Metaspace
  52 size_t RunningCounters::committed_words() {
  53   return committed_words_class() + committed_words_nonclass();
  54 }
  55 
  56 size_t RunningCounters::committed_words_class() {
  57   VirtualSpaceList* vs = VirtualSpaceList::vslist_class();
  58   return vs != NULL ? vs->committed_words() : 0;
  59 }
  60 
  61 size_t RunningCounters::committed_words_nonclass() {
  62   return VirtualSpaceList::vslist_nonclass()->committed_words();
  63 }
  64 
  65 
  66 // ---- used chunks -----
  67 
  68 // Returns size, in words, used for metadata.
  69 size_t RunningCounters::used_words() {
  70   return used_words_class() + used_words_nonclass();
  71 }
  72 
  73 size_t RunningCounters::used_words_class() {
  74   return _used_class_counter.get();
  75 }
  76 
  77 size_t RunningCounters::used_words_nonclass() {
  78   return _used_nonclass_counter.get();
  79 }
  80 
  81 // ---- free chunks -----
  82 
  83 // Returns size, in words, of all chunks in all freelists.
  84 size_t RunningCounters::free_chunks_words() {
  85   return free_chunks_words_class() + free_chunks_words_nonclass();
  86 }
  87 
  88 size_t RunningCounters::free_chunks_words_class() {
  89   ChunkManager* cm = ChunkManager::chunkmanager_class();
  90   return cm != NULL ? cm->total_word_size() : 0;
  91 }
  92 
  93 size_t RunningCounters::free_chunks_words_nonclass() {
  94   return ChunkManager::chunkmanager_nonclass()->total_word_size();
  95 }
  96 
  97 } // namespace metaspace
  98 
  99