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_METASPACECOMMON_HPP
  26 #define SHARE_MEMORY_METASPACE_METASPACECOMMON_HPP
  27 
  28 #include "utilities/align.hpp"
  29 #include "utilities/debug.hpp"
  30 #include "utilities/globalDefinitions.hpp"
  31 
  32 class outputStream;
  33 
  34 namespace metaspace {
  35 
  36 
  37 // Print a size, in words, scaled.
  38 void print_scaled_words(outputStream* st, size_t word_size, size_t scale = 0, int width = -1);
  39 
  40 // Convenience helper: prints a size value and a percentage.
  41 void print_scaled_words_and_percentage(outputStream* st, size_t word_size, size_t compare_word_size, size_t scale = 0, int width = -1);
  42 
  43 // Print a human readable size.
  44 // byte_size: size, in bytes, to be printed.
  45 // scale: one of 1 (byte-wise printing), sizeof(word) (word-size printing), K, M, G (scaled by KB, MB, GB respectively,
  46 //         or 0, which means the best scale is choosen dynamically.
  47 // width: printing width.
  48 void print_human_readable_size(outputStream* st, size_t byte_size, size_t scale = 0, int width = -1);
  49 
  50 // Prints a percentage value. Values smaller than 1% but not 0 are displayed as "<1%", values
  51 // larger than 99% but not 100% are displayed as ">100%".
  52 void print_percentage(outputStream* st, size_t total, size_t part);
  53 
  54 
  55 #define assert_is_aligned(value, alignment)                  \
  56   assert(is_aligned((value), (alignment)),                   \
  57          SIZE_FORMAT_HEX " is not aligned to "               \
  58          SIZE_FORMAT, (size_t)(uintptr_t)value, (alignment))
  59 
  60 // Internal statistics.
  61 #ifdef ASSERT
  62 struct  internal_statistics_t {
  63   // Number of allocations.
  64   uintx num_allocs;
  65   // Number of times a ClassLoaderMetaspace was born...
  66   uintx num_metaspace_births;
  67   // ... and died.
  68   uintx num_metaspace_deaths;
  69   // Number of times VirtualSpaceListNodes were created...
  70   uintx num_vsnodes_created;
  71   // ... and purged.
  72   uintx num_vsnodes_purged;
  73   // Number of times we expanded the committed section of the space.
  74   uintx num_committed_space_expanded;
  75   // Number of deallocations
  76   uintx num_deallocs;
  77   // Number of deallocations triggered from outside ("real" deallocations).
  78   uintx num_external_deallocs;
  79   // Number of times an allocation was satisfied from deallocated blocks.
  80   uintx num_allocs_from_deallocated_blocks;
  81   // Number of times a chunk was added to the freelist
  82   uintx num_chunks_added_to_freelist;
  83   // Number of times a chunk was removed from the freelist
  84   uintx num_chunks_removed_from_freelist;
  85   // Number of chunk merges
  86   uintx num_chunk_merges;
  87   // Number of chunk splits
  88   uintx num_chunk_splits;
  89 };
  90 extern internal_statistics_t g_internal_statistics;
  91 #endif
  92 
  93 // Pretty printing helpers
  94 const char* classes_plural(uintx num);
  95 const char* loaders_plural(uintx num);
  96 void print_number_of_classes(outputStream* out, uintx classes, uintx classes_shared);
  97 
  98 } // namespace metaspace
  99 
 100 #endif // SHARE_MEMORY_METASPACE_METASPACECOMMON_HPP