src/hotspot/share/memory/metaspace/settings.cpp
branchstuefe-new-metaspace-branch
changeset 58063 bdf136b8ae0e
child 58067 b83deb51ea70
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  * 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 
       
    27 #include <memory/metaspace/settings.hpp>
       
    28 #include "precompiled.hpp"
       
    29 
       
    30 #include "logging/log.hpp"
       
    31 #include "logging/logStream.hpp"
       
    32 
       
    33 #include "memory/metaspace/chunkLevel.hpp"
       
    34 
       
    35 #include "utilities/globalDefinitions.hpp"
       
    36 #include "utilities/debug.hpp"
       
    37 
       
    38 namespace metaspace {
       
    39 
       
    40 size_t Settings::_commit_granule_bytes = 0;
       
    41 size_t Settings::_commit_granule_words = 0;
       
    42 bool Settings::_newborn_root_chunks_are_fully_committed = false;
       
    43 size_t Settings::_committed_words_on_fresh_chunks = 0;
       
    44 
       
    45 bool Settings::_enlarge_chunks_in_place = false;
       
    46 size_t Settings::_enlarge_chunks_in_place_max_word_size = 0;
       
    47 
       
    48 bool Settings::_uncommit_on_return = false;
       
    49 size_t Settings::_uncommit_on_return_min_word_size = 0;
       
    50 
       
    51 bool Settings::_delete_nodes_on_purge = false;
       
    52 bool Settings::_uncommit_on_purge = false;
       
    53 size_t Settings::_uncommit_on_purge_min_word_size = 0;
       
    54 
       
    55 bool Settings::_always_use_class_space = false;
       
    56 
       
    57 void Settings::initialize(strategy_t strat, bool always_use_class_space) {
       
    58 
       
    59   switch (strat) {
       
    60   case strategy_no_reclaim:
       
    61 
       
    62     log_info(metaspace)("Initialized with strategy: no reclaim.");
       
    63 
       
    64     _commit_granule_bytes = 64 * K;
       
    65     _commit_granule_words = _commit_granule_bytes / BytesPerWord;
       
    66 
       
    67     _newborn_root_chunks_are_fully_committed = true;
       
    68 
       
    69     _committed_words_on_fresh_chunks = chklvl::MAX_CHUNK_WORD_SIZE;
       
    70 
       
    71     _uncommit_on_return = false;
       
    72     _uncommit_on_return_min_word_size = 3; // does not matter; should not be used resp. assert when used.
       
    73 
       
    74     _delete_nodes_on_purge = false;
       
    75     _uncommit_on_purge = false;
       
    76     _uncommit_on_purge_min_word_size = 3; // does not matter; should not be used resp. assert when used.
       
    77 
       
    78     break;
       
    79 
       
    80   case strategy_aggressive_reclaim:
       
    81 
       
    82     log_info(metaspace)("Initialized with strategy: aggressive reclaim.");
       
    83 
       
    84     // Set the granule size rather small; may increase
       
    85     // mapping fragmentation but also increase chance to uncommit.
       
    86     _commit_granule_bytes = 16 * K;
       
    87     _commit_granule_words = _commit_granule_bytes / BytesPerWord;
       
    88 
       
    89     _newborn_root_chunks_are_fully_committed = false;
       
    90 
       
    91     // When handing out fresh chunks, only commit the minimum sensible amount (0 would be possible
       
    92     // but not make sense since the chunk is immediately used for allocation after being handed out, so the
       
    93     // first granule would be committed right away anyway).
       
    94     _committed_words_on_fresh_chunks = _commit_granule_words;
       
    95 
       
    96     _uncommit_on_return = true;
       
    97     _uncommit_on_return_min_word_size = _commit_granule_words;
       
    98 
       
    99     _delete_nodes_on_purge = true;
       
   100     _uncommit_on_purge = true;
       
   101     _uncommit_on_purge_min_word_size = _commit_granule_words; // does not matter; should not be used resp. assert when used.
       
   102 
       
   103     break;
       
   104 
       
   105   case strategy_balanced_reclaim:
       
   106 
       
   107     log_info(metaspace)("Initialized with strategy: balanced reclaim.");
       
   108 
       
   109     _commit_granule_bytes = 64 * K;
       
   110     _commit_granule_words = _commit_granule_bytes / BytesPerWord;
       
   111 
       
   112     _newborn_root_chunks_are_fully_committed = false;
       
   113 
       
   114     // When handing out fresh chunks, only commit the minimum sensible amount (0 would be possible
       
   115     // but not make sense since the chunk is immediately used for allocation after being handed out, so the
       
   116     // first granule would be committed right away anyway).
       
   117     _committed_words_on_fresh_chunks = _commit_granule_words;
       
   118 
       
   119     _uncommit_on_return = true;
       
   120     _uncommit_on_return_min_word_size = _commit_granule_words;
       
   121 
       
   122     _delete_nodes_on_purge = true;
       
   123     _uncommit_on_purge = true;
       
   124     _uncommit_on_purge_min_word_size = _commit_granule_words;
       
   125 
       
   126     break;
       
   127 
       
   128   }
       
   129 
       
   130   // Since this has nothing to do with reclaiming, set it independently from the
       
   131   // strategy. This is rather arbitrarily choosen.
       
   132   _enlarge_chunks_in_place = true;
       
   133   _enlarge_chunks_in_place_max_word_size = 256 * K;
       
   134   _always_use_class_space = always_use_class_space;
       
   135 
       
   136 
       
   137   // Sanity checks.
       
   138   guarantee(commit_granule_words() <= chklvl::MAX_CHUNK_WORD_SIZE, "Too large granule size");
       
   139   guarantee(is_power_of_2(commit_granule_words()), "granule size must be a power of 2");
       
   140 
       
   141   LogStream ls(Log(metaspace)::info());
       
   142   Settings::print_on(&ls);
       
   143 
       
   144 }
       
   145 
       
   146 void Settings::print_on(outputStream* st) {
       
   147 
       
   148   st->print_cr(" - commit_granule_bytes: " SIZE_FORMAT ".", commit_granule_bytes());
       
   149   st->print_cr(" - commit_granule_words: " SIZE_FORMAT ".", commit_granule_words());
       
   150 
       
   151   st->print_cr(" - newborn_root_chunks_are_fully_committed: %d.", (int)newborn_root_chunks_are_fully_committed());
       
   152   st->print_cr(" - committed_words_on_fresh_chunks: " SIZE_FORMAT ".", committed_words_on_fresh_chunks());
       
   153 
       
   154   st->print_cr(" - virtual_space_node_default_size: " SIZE_FORMAT ".", virtual_space_node_default_word_size());
       
   155   st->print_cr(" - allocation_from_dictionary_limit: " SIZE_FORMAT ".", allocation_from_dictionary_limit());
       
   156 
       
   157   st->print_cr(" - enlarge_chunks_in_place: %d.", (int)enlarge_chunks_in_place());
       
   158   st->print_cr(" - enlarge_chunks_in_place_max_word_size: " SIZE_FORMAT ".", enlarge_chunks_in_place_max_word_size());
       
   159 
       
   160   st->print_cr(" - uncommit_on_return: %d.", (int)uncommit_on_return());
       
   161   st->print_cr(" - uncommit_on_return_min_word_size: " SIZE_FORMAT ".", uncommit_on_return_min_word_size());
       
   162 
       
   163   st->print_cr(" - delete_nodes_on_purge: %d.", (int)delete_nodes_on_purge());
       
   164 
       
   165   st->print_cr(" - uncommit_on_purge: %d.", (int)uncommit_on_purge());
       
   166   st->print_cr(" - uncommit_on_purge_min_word_size: " SIZE_FORMAT ".", uncommit_on_purge_min_word_size());
       
   167 
       
   168   st->print_cr(" - always_use_class_space: %d.", always_use_class_space());
       
   169 
       
   170 }
       
   171 
       
   172 } // namespace metaspace
       
   173