src/hotspot/share/memory/metaspace/chunkLevel.cpp
branchstuefe-new-metaspace-branch
changeset 58063 bdf136b8ae0e
equal deleted inserted replaced
58062:65cad575ace3 58063:bdf136b8ae0e
       
     1 /*
       
     2  * Copyright (c) 2019, SAP SE. All rights reserved.
       
     3  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     4 
       
     5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     6  *
       
     7  * This code is free software; you can redistribute it and/or modify it
       
     8  * under the terms of the GNU General Public License version 2 only, as
       
     9  * published by the Free Software Foundation.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  *
       
    25  */
       
    26 #include <memory/metaspace/settings.hpp>
       
    27 #include "precompiled.hpp"
       
    28 #include "memory/metaspace/chunkLevel.hpp"
       
    29 #include "utilities/debug.hpp"
       
    30 #include "utilities/globalDefinitions.hpp"
       
    31 #include "utilities/ostream.hpp"
       
    32 
       
    33 namespace metaspace {
       
    34 
       
    35 chklvl_t chklvl::level_fitting_word_size(size_t word_size) {
       
    36 
       
    37   assert(chklvl::MAX_CHUNK_WORD_SIZE >= word_size,
       
    38          "too large allocation size (" SIZE_FORMAT ")", word_size * BytesPerWord);
       
    39 
       
    40   // TODO: This can be done much better.
       
    41   chklvl_t l = chklvl::HIGHEST_CHUNK_LEVEL;
       
    42   while (l >= chklvl::LOWEST_CHUNK_LEVEL &&
       
    43          word_size > chklvl::word_size_for_level(l)) {
       
    44     l --;
       
    45   }
       
    46 
       
    47   return l;
       
    48 }
       
    49 
       
    50 void chklvl::print_chunk_size(outputStream* st, chklvl_t lvl) {
       
    51   if (chklvl::is_valid_level(lvl)) {
       
    52     const size_t s = chklvl::word_size_for_level(lvl) * BytesPerWord;
       
    53     if (s < 1 * M) {
       
    54       st->print("%3uk", (unsigned)(s / K));
       
    55     } else {
       
    56       st->print("%3um", (unsigned)(s / M));
       
    57     }
       
    58   } else {
       
    59     st->print("?-?");
       
    60   }
       
    61 
       
    62 }
       
    63 
       
    64 } // namespace metaspace
       
    65 
       
    66