1 /*
   2  * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018, 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 #ifndef SHARE_MEMORY_METASPACE_MSSTATISTICS_HPP
  27 #define SHARE_MEMORY_METASPACE_MSSTATISTICS_HPP
  28 
  29 #include "memory/metaspace/msChunklevel.hpp"
  30 #include "memory/metaspace.hpp"             // for MetadataType enum
  31 #include "utilities/globalDefinitions.hpp"
  32 
  33 class outputStream;
  34 
  35 namespace metaspace {
  36 
  37 // Contains a number of data output structures:
  38 //
  39 // - cm_stats_t
  40 // - clms_stats_t -> arena_stats_t -> in_use_chunk_stats_t
  41 //
  42 // used for the various XXXX::add_to_statistic() methods in MetaspaceArena, ClassLoaderMetaspace
  43 //  and ChunkManager, respectively.
  44 
  45 struct ChunkManagerStats {
  46 
  47   // How many chunks per level are checked in.
  48   int _num_chunks[chunklevel::NUM_CHUNK_LEVELS];
  49 
  50   // Size, in words, of the sum of all committed areas in this chunk manager, per level.
  51   size_t _committed_word_size[chunklevel::NUM_CHUNK_LEVELS];
  52 
  53   ChunkManagerStats() : _num_chunks(), _committed_word_size() {}
  54 
  55   void add(const ChunkManagerStats& other);
  56 
  57   // Returns total word size of all chunks in this manager.
  58   size_t total_word_size() const;
  59 
  60   // Returns total committed word size of all chunks in this manager.
  61   size_t total_committed_word_size() const;
  62 
  63   void print_on(outputStream* st, size_t scale) const;
  64 
  65   DEBUG_ONLY(void verify() const;)
  66 
  67 };
  68 
  69 // Contains statistics for one or multiple chunks in use.
  70 struct InUseChunkStats {
  71 
  72   // Number of chunks
  73   int _num;
  74 
  75   // Note:
  76   // capacity = committed + uncommitted
  77   //            committed = used + free + waste
  78 
  79   // Capacity (total sum of all chunk sizes) in words.
  80   // May contain committed and uncommitted space.
  81   size_t _word_size;
  82 
  83   // Total committed area, in words.
  84   size_t _committed_words;
  85 
  86   // Total used area, in words.
  87   size_t _used_words;
  88 
  89   // Total free committed area, in words.
  90   size_t _free_words;
  91 
  92   // Total waste committed area, in words.
  93   size_t _waste_words;
  94 
  95   InUseChunkStats()
  96     : _num(0), _word_size(0), _committed_words(0),
  97       _used_words(0), _free_words(0), _waste_words(0)
  98   {}
  99 
 100   void add(const InUseChunkStats& other) {
 101     _num += other._num;
 102     _word_size += other._word_size;
 103     _committed_words += other._committed_words;
 104     _used_words += other._used_words;
 105     _free_words += other._free_words;
 106     _waste_words += other._waste_words;
 107 
 108   }
 109 
 110   void print_on(outputStream* st, size_t scale) const;
 111 
 112   DEBUG_ONLY(void verify() const;)
 113 
 114 };
 115 
 116 // Class containing statistics for one or more MetaspaceArena objects.
 117 struct  ArenaStats {
 118 
 119   // chunk statistics by chunk level
 120   InUseChunkStats _stats[chunklevel::NUM_CHUNK_LEVELS];
 121   uintx _free_blocks_num;
 122   size_t _free_blocks_word_size;
 123 
 124   ArenaStats()
 125     : _stats(),
 126       _free_blocks_num(0),
 127       _free_blocks_word_size(0)
 128   {}
 129 
 130   void add(const ArenaStats& other);
 131 
 132   void print_on(outputStream* st, size_t scale = K,  bool detailed = true) const;
 133 
 134   InUseChunkStats totals() const;
 135 
 136   DEBUG_ONLY(void verify() const;)
 137 
 138 };
 139 
 140 // Statistics for one or multiple ClassLoaderMetaspace objects
 141 struct ClmsStats {
 142 
 143   ArenaStats _arena_stats_nonclass;
 144   ArenaStats _arena_stats_class;
 145 
 146   ClmsStats() : _arena_stats_nonclass(), _arena_stats_class() {}
 147 
 148   void add(const ClmsStats& other) {
 149     _arena_stats_nonclass.add(other._arena_stats_nonclass);
 150     _arena_stats_class.add(other._arena_stats_class);
 151   }
 152 
 153   void print_on(outputStream* st, size_t scale, bool detailed) const;
 154 
 155   // Returns total statistics for both class and non-class metaspace
 156   ArenaStats totals() const;
 157 
 158   DEBUG_ONLY(void verify() const;)
 159 
 160 };
 161 
 162 } // namespace metaspace
 163 
 164 #endif // SHARE_MEMORY_METASPACE_MSSTATISTICS_HPP
 165