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_METASPACESTATISTICS_HPP
  27 #define SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP
  28 
  29 #include "memory/metaspace.hpp"             // for MetadataType enum
  30 #include "memory/metaspace/chunkLevel.hpp"
  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 cm_stats_t {
  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   cm_stats_t() : num_chunks(), committed_word_size() {}
  54 
  55   void add(const cm_stats_t& 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 in_use_chunk_stats_t {
  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   in_use_chunk_stats_t()
  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 in_use_chunk_stats_t& 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  arena_stats_t {
 118 
 119   // chunk statistics by chunk level
 120   in_use_chunk_stats_t stats[chunklevel::NUM_CHUNK_LEVELS];
 121   uintx free_blocks_num;
 122   size_t free_blocks_word_size;
 123 
 124   arena_stats_t()
 125     : stats(),
 126       free_blocks_num(0),
 127       free_blocks_word_size(0)
 128   {}
 129 
 130   void add(const arena_stats_t& other);
 131 
 132   void print_on(outputStream* st, size_t scale = K,  bool detailed = true) const;
 133 
 134   in_use_chunk_stats_t totals() const;
 135 
 136   DEBUG_ONLY(void verify() const;)
 137 
 138 };
 139 
 140 // Statistics for one or multiple ClassLoaderMetaspace objects
 141 struct clms_stats_t {
 142 
 143   arena_stats_t arena_stats_nonclass;
 144   arena_stats_t arena_stats_class;
 145 
 146   clms_stats_t() : arena_stats_nonclass(), arena_stats_class() {}
 147 
 148   void add(const clms_stats_t& 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   arena_stats_t totals() const;
 157 
 158 
 159   DEBUG_ONLY(void verify() const;)
 160 
 161 };
 162 
 163 } // namespace metaspace
 164 
 165 #endif // SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP
 166