Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/memory/metaspace/metaspaceSettings.cpp
40957 views
1
/*
2
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 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
#include "precompiled.hpp"
27
#include "logging/log.hpp"
28
#include "logging/logStream.hpp"
29
#include "memory/metaspace/metaspaceSettings.hpp"
30
#include "runtime/globals.hpp"
31
#include "runtime/java.hpp"
32
#include "runtime/os.hpp"
33
#include "utilities/debug.hpp"
34
#include "utilities/globalDefinitions.hpp"
35
#include "utilities/powerOfTwo.hpp"
36
37
namespace metaspace {
38
39
size_t Settings::_commit_granule_bytes = 0;
40
size_t Settings::_commit_granule_words = 0;
41
42
bool Settings::_new_chunks_are_fully_committed = false;
43
bool Settings::_uncommit_free_chunks = false;
44
45
DEBUG_ONLY(bool Settings::_use_allocation_guard = false;)
46
DEBUG_ONLY(bool Settings::_handle_deallocations = true;)
47
48
void Settings::ergo_initialize() {
49
if (strcmp(MetaspaceReclaimPolicy, "none") == 0) {
50
log_info(metaspace)("Initialized with strategy: no reclaim.");
51
_commit_granule_bytes = MAX2((size_t)os::vm_page_size(), 64 * K);
52
_commit_granule_words = _commit_granule_bytes / BytesPerWord;
53
// In "none" reclamation mode, we do not uncommit, and we commit new chunks fully;
54
// that very closely mimicks the behaviour of old Metaspace.
55
_new_chunks_are_fully_committed = true;
56
_uncommit_free_chunks = false;
57
} else if (strcmp(MetaspaceReclaimPolicy, "aggressive") == 0) {
58
log_info(metaspace)("Initialized with strategy: aggressive reclaim.");
59
// Set the granule size rather small; may increase
60
// mapping fragmentation but also increase chance to uncommit.
61
_commit_granule_bytes = MAX2((size_t)os::vm_page_size(), 16 * K);
62
_commit_granule_words = _commit_granule_bytes / BytesPerWord;
63
_new_chunks_are_fully_committed = false;
64
_uncommit_free_chunks = true;
65
} else if (strcmp(MetaspaceReclaimPolicy, "balanced") == 0) {
66
log_info(metaspace)("Initialized with strategy: balanced reclaim.");
67
_commit_granule_bytes = MAX2((size_t)os::vm_page_size(), 64 * K);
68
_commit_granule_words = _commit_granule_bytes / BytesPerWord;
69
_new_chunks_are_fully_committed = false;
70
_uncommit_free_chunks = true;
71
} else {
72
vm_exit_during_initialization("Invalid value for MetaspaceReclaimPolicy: \"%s\".", MetaspaceReclaimPolicy);
73
}
74
75
// Sanity checks.
76
assert(commit_granule_words() <= chunklevel::MAX_CHUNK_WORD_SIZE, "Too large granule size");
77
assert(is_power_of_2(commit_granule_words()), "granule size must be a power of 2");
78
79
#ifdef ASSERT
80
// Off for release builds, and by default for debug builds, but can be switched on manually to aid
81
// error analysis.
82
_use_allocation_guard = MetaspaceGuardAllocations;
83
84
// Deallocations can be manually switched off to aid error analysis, since this removes one layer of complexity
85
// from allocation.
86
_handle_deallocations = MetaspaceHandleDeallocations;
87
88
// We also switch it off automatically if we use allocation guards. This is to keep prefix handling in MetaspaceArena simple.
89
if (_use_allocation_guard) {
90
_handle_deallocations = false;
91
}
92
#endif
93
LogStream ls(Log(metaspace)::info());
94
Settings::print_on(&ls);
95
}
96
97
void Settings::print_on(outputStream* st) {
98
st->print_cr(" - commit_granule_bytes: " SIZE_FORMAT ".", commit_granule_bytes());
99
st->print_cr(" - commit_granule_words: " SIZE_FORMAT ".", commit_granule_words());
100
st->print_cr(" - virtual_space_node_default_size: " SIZE_FORMAT ".", virtual_space_node_default_word_size());
101
st->print_cr(" - enlarge_chunks_in_place: %d.", (int)enlarge_chunks_in_place());
102
st->print_cr(" - new_chunks_are_fully_committed: %d.", (int)new_chunks_are_fully_committed());
103
st->print_cr(" - uncommit_free_chunks: %d.", (int)uncommit_free_chunks());
104
st->print_cr(" - use_allocation_guard: %d.", (int)use_allocation_guard());
105
st->print_cr(" - handle_deallocations: %d.", (int)handle_deallocations());
106
}
107
108
} // namespace metaspace
109
110
111