< prev index next >

src/hotspot/share/memory/metaspace/metaspaceCommon.cpp

Print this page
rev 50068 : [mq]: metaspace-split


   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 
  28 #include "memory/metaspace/metaspaceCommon.hpp"


  29 #include "utilities/globalDefinitions.hpp"
  30 #include "utilities/ostream.hpp"
  31 
  32 namespace metaspace {
  33 namespace internals {
  34 


  35 // Print a size, in words, scaled.
  36 void print_scaled_words(outputStream* st, size_t word_size, size_t scale, int width) {
  37   print_human_readable_size(st, word_size * sizeof(MetaWord), scale, width);
  38 }
  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, int width) {
  42   print_scaled_words(st, word_size, scale, width);
  43   st->print(" (");
  44   print_percentage(st, compare_word_size, word_size);
  45   st->print(")");
  46 }
  47 
  48 
  49 // Print a human readable size.
  50 // byte_size: size, in bytes, to be printed.
  51 // scale: one of 1 (byte-wise printing), sizeof(word) (word-size printing), K, M, G (scaled by KB, MB, GB respectively,
  52 //         or 0, which means the best scale is choosen dynamically.
  53 // width: printing width.
  54 void print_human_readable_size(outputStream* st, size_t byte_size, size_t scale, int width)  {


 110 // larger than 99% but not 100% are displayed as ">100%".
 111 void print_percentage(outputStream* st, size_t total, size_t part) {
 112   if (total == 0) {
 113     st->print("  ?%%");
 114   } else if (part == 0) {
 115     st->print("  0%%");
 116   } else if (part == total) {
 117     st->print("100%%");
 118   } else {
 119     // Note: clearly print very-small-but-not-0% and very-large-but-not-100% percentages.
 120     float p = ((float)part / total) * 100.0f;
 121     if (p < 1.0f) {
 122       st->print(" <1%%");
 123     } else if (p > 99.0f){
 124       st->print(">99%%");
 125     } else {
 126       st->print("%3.0f%%", p);
 127     }
 128   }
 129 }

































































 130 
 131 } // namespace internals
 132 } // namespace metaspace


   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 
  28 #include "memory/metaspace/metaspaceCommon.hpp"
  29 #include "memory/metaspace/virtualSpaceNode.hpp"
  30 #include "utilities/debug.hpp"
  31 #include "utilities/globalDefinitions.hpp"
  32 #include "utilities/ostream.hpp"
  33 
  34 namespace metaspace {
  35 namespace internals {
  36 
  37 DEBUG_ONLY(internal_statistics_t g_internal_statistics;)
  38 
  39 // Print a size, in words, scaled.
  40 void print_scaled_words(outputStream* st, size_t word_size, size_t scale, int width) {
  41   print_human_readable_size(st, word_size * sizeof(MetaWord), scale, width);
  42 }
  43 
  44 // Convenience helper: prints a size value and a percentage.
  45 void print_scaled_words_and_percentage(outputStream* st, size_t word_size, size_t compare_word_size, size_t scale, int width) {
  46   print_scaled_words(st, word_size, scale, width);
  47   st->print(" (");
  48   print_percentage(st, compare_word_size, word_size);
  49   st->print(")");
  50 }
  51 
  52 
  53 // Print a human readable size.
  54 // byte_size: size, in bytes, to be printed.
  55 // scale: one of 1 (byte-wise printing), sizeof(word) (word-size printing), K, M, G (scaled by KB, MB, GB respectively,
  56 //         or 0, which means the best scale is choosen dynamically.
  57 // width: printing width.
  58 void print_human_readable_size(outputStream* st, size_t byte_size, size_t scale, int width)  {


 114 // larger than 99% but not 100% are displayed as ">100%".
 115 void print_percentage(outputStream* st, size_t total, size_t part) {
 116   if (total == 0) {
 117     st->print("  ?%%");
 118   } else if (part == 0) {
 119     st->print("  0%%");
 120   } else if (part == total) {
 121     st->print("100%%");
 122   } else {
 123     // Note: clearly print very-small-but-not-0% and very-large-but-not-100% percentages.
 124     float p = ((float)part / total) * 100.0f;
 125     if (p < 1.0f) {
 126       st->print(" <1%%");
 127     } else if (p > 99.0f){
 128       st->print(">99%%");
 129     } else {
 130       st->print("%3.0f%%", p);
 131     }
 132   }
 133 }
 134 
 135 // Returns size of this chunk type.
 136 size_t get_size_for_nonhumongous_chunktype(ChunkIndex chunktype, bool is_class) {
 137   assert(is_valid_nonhumongous_chunktype(chunktype), "invalid chunk type.");
 138   size_t size = 0;
 139   if (is_class) {
 140     switch(chunktype) {
 141       case SpecializedIndex: size = ClassSpecializedChunk; break;
 142       case SmallIndex: size = ClassSmallChunk; break;
 143       case MediumIndex: size = ClassMediumChunk; break;
 144       default:
 145         ShouldNotReachHere();
 146     }
 147   } else {
 148     switch(chunktype) {
 149       case SpecializedIndex: size = SpecializedChunk; break;
 150       case SmallIndex: size = SmallChunk; break;
 151       case MediumIndex: size = MediumChunk; break;
 152       default:
 153         ShouldNotReachHere();
 154     }
 155   }
 156   return size;
 157 }
 158 
 159 ChunkIndex get_chunk_type_by_size(size_t size, bool is_class) {
 160   if (is_class) {
 161     if (size == ClassSpecializedChunk) {
 162       return SpecializedIndex;
 163     } else if (size == ClassSmallChunk) {
 164       return SmallIndex;
 165     } else if (size == ClassMediumChunk) {
 166       return MediumIndex;
 167     } else if (size > ClassMediumChunk) {
 168       // A valid humongous chunk size is a multiple of the smallest chunk size.
 169       assert(is_aligned(size, ClassSpecializedChunk), "Invalid chunk size");
 170       return HumongousIndex;
 171     }
 172   } else {
 173     if (size == SpecializedChunk) {
 174       return SpecializedIndex;
 175     } else if (size == SmallChunk) {
 176       return SmallIndex;
 177     } else if (size == MediumChunk) {
 178       return MediumIndex;
 179     } else if (size > MediumChunk) {
 180       // A valid humongous chunk size is a multiple of the smallest chunk size.
 181       assert(is_aligned(size, SpecializedChunk), "Invalid chunk size");
 182       return HumongousIndex;
 183     }
 184   }
 185   ShouldNotReachHere();
 186   return (ChunkIndex)-1;
 187 }
 188 
 189 ChunkIndex next_chunk_index(ChunkIndex i) {
 190   assert(i < NumberOfInUseLists, "Out of bound");
 191   return (ChunkIndex) (i+1);
 192 }
 193 
 194 ChunkIndex prev_chunk_index(ChunkIndex i) {
 195   assert(i > ZeroIndex, "Out of bound");
 196   return (ChunkIndex) (i-1);
 197 }
 198 
 199 
 200 } // namespace internals
 201 } // namespace metaspace
< prev index next >