Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/memory/metaspace/freeChunkList.cpp
40957 views
1
/*
2
* Copyright (c) 2020, 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 "memory/metaspace/freeChunkList.hpp"
28
#include "utilities/debug.hpp"
29
#include "utilities/globalDefinitions.hpp"
30
#include "utilities/ostream.hpp"
31
32
namespace metaspace {
33
34
// Calculates total number of committed words over all chunks (walks chunks).
35
size_t FreeChunkList::calc_committed_word_size() const {
36
size_t s = 0;
37
for (const Metachunk* c = _first; c != NULL; c = c->next()) {
38
s += c->committed_words();
39
}
40
return s;
41
}
42
43
void FreeChunkList::print_on(outputStream* st) const {
44
if (_num_chunks.get() > 0) {
45
for (const Metachunk* c = _first; c != NULL; c = c->next()) {
46
st->print(" - <");
47
c->print_on(st);
48
st->print(">");
49
}
50
st->print(" - total : %d chunks.", _num_chunks.get());
51
} else {
52
st->print("empty");
53
}
54
}
55
56
#ifdef ASSERT
57
58
bool FreeChunkList::contains(const Metachunk* c) const {
59
for (Metachunk* c2 = _first; c2 != NULL; c2 = c2->next()) {
60
if (c2 == c) {
61
return true;
62
}
63
}
64
return false;
65
}
66
67
void FreeChunkList::verify() const {
68
if (_first == NULL) {
69
assert(_last == NULL, "Sanity");
70
} else {
71
assert(_last != NULL, "Sanity");
72
int num = 0;
73
bool uncommitted = (_first->committed_words() == 0);
74
for (Metachunk* c = _first; c != NULL; c = c->next()) {
75
assert(c->is_free(), "Chunks in freelist should be free");
76
assert(c->used_words() == 0, "Chunk in freelist should have not used words.");
77
assert(c->level() == _first->level(), "wrong level");
78
assert(c->next() == NULL || c->next()->prev() == c, "front link broken");
79
assert(c->prev() == NULL || c->prev()->next() == c, "back link broken");
80
assert(c != c->prev() && c != c->next(), "circle");
81
c->verify();
82
num++;
83
}
84
_num_chunks.check(num);
85
}
86
}
87
88
#endif // ASSERT
89
90
// Returns total size in all lists (regardless of commit state of underlying memory)
91
size_t FreeChunkListVector::word_size() const {
92
size_t sum = 0;
93
for (chunklevel_t l = chunklevel::LOWEST_CHUNK_LEVEL; l <= chunklevel::HIGHEST_CHUNK_LEVEL; l++) {
94
sum += list_for_level(l)->num_chunks() * chunklevel::word_size_for_level(l);
95
}
96
return sum;
97
}
98
99
// Calculates total number of committed words over all chunks (walks chunks).
100
size_t FreeChunkListVector::calc_committed_word_size() const {
101
size_t sum = 0;
102
for (chunklevel_t l = chunklevel::LOWEST_CHUNK_LEVEL; l <= chunklevel::HIGHEST_CHUNK_LEVEL; l++) {
103
sum += calc_committed_word_size_at_level(l);
104
}
105
return sum;
106
}
107
108
size_t FreeChunkListVector::calc_committed_word_size_at_level(chunklevel_t lvl) const {
109
return list_for_level(lvl)->calc_committed_word_size();
110
}
111
112
// Returns total committed size in all lists
113
int FreeChunkListVector::num_chunks() const {
114
int n = 0;
115
for (chunklevel_t l = chunklevel::LOWEST_CHUNK_LEVEL; l <= chunklevel::HIGHEST_CHUNK_LEVEL; l++) {
116
n += list_for_level(l)->num_chunks();
117
}
118
return n;
119
}
120
121
// Look for a chunk: starting at level, up to and including max_level,
122
// return the first chunk whose committed words >= min_committed_words.
123
// Return NULL if no such chunk was found.
124
Metachunk* FreeChunkListVector::search_chunk_ascending(chunklevel_t level, chunklevel_t max_level, size_t min_committed_words) {
125
assert(min_committed_words <= chunklevel::word_size_for_level(max_level),
126
"min chunk size too small to hold min_committed_words");
127
for (chunklevel_t l = level; l <= max_level; l++) {
128
FreeChunkList* list = list_for_level(l);
129
Metachunk* c = list->first_minimally_committed(min_committed_words);
130
if (c != NULL) {
131
list->remove(c);
132
return c;
133
}
134
}
135
return NULL;
136
}
137
138
// Look for a chunk: starting at level, down to (including) the root chunk level,
139
// return the first chunk whose committed words >= min_committed_words.
140
// Return NULL if no such chunk was found.
141
Metachunk* FreeChunkListVector::search_chunk_descending(chunklevel_t level, size_t min_committed_words) {
142
for (chunklevel_t l = level; l >= chunklevel::LOWEST_CHUNK_LEVEL; l --) {
143
FreeChunkList* list = list_for_level(l);
144
Metachunk* c = list->first_minimally_committed(min_committed_words);
145
if (c != NULL) {
146
list->remove(c);
147
return c;
148
}
149
}
150
return NULL;
151
}
152
153
void FreeChunkListVector::print_on(outputStream* st) const {
154
for (chunklevel_t l = chunklevel::LOWEST_CHUNK_LEVEL; l <= chunklevel::HIGHEST_CHUNK_LEVEL; l++) {
155
st->print("-- List[" CHKLVL_FORMAT "]: ", l);
156
list_for_level(l)->print_on(st);
157
st->cr();
158
}
159
st->print_cr("total chunks: %d, total word size: " SIZE_FORMAT ".",
160
num_chunks(), word_size());
161
}
162
163
#ifdef ASSERT
164
165
void FreeChunkListVector::verify() const {
166
for (chunklevel_t l = chunklevel::LOWEST_CHUNK_LEVEL; l <= chunklevel::HIGHEST_CHUNK_LEVEL; l++) {
167
list_for_level(l)->verify();
168
}
169
}
170
171
bool FreeChunkListVector::contains(const Metachunk* c) const {
172
for (chunklevel_t l = chunklevel::LOWEST_CHUNK_LEVEL; l <= chunklevel::HIGHEST_CHUNK_LEVEL; l++) {
173
if (list_for_level(l)->contains(c)) {
174
return true;
175
}
176
}
177
return false;
178
}
179
180
#endif // ASSERT
181
182
} // namespace metaspace
183
184
185