Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/memory/metaspace/chunkHeaderPool.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/chunkHeaderPool.hpp"
28
#include "runtime/os.hpp"
29
#include "utilities/debug.hpp"
30
#include "utilities/globalDefinitions.hpp"
31
32
namespace metaspace {
33
34
// Returns reference to the one global chunk header pool.
35
ChunkHeaderPool* ChunkHeaderPool::_chunkHeaderPool = NULL;
36
37
ChunkHeaderPool::ChunkHeaderPool() :
38
_num_slabs(),
39
_first_slab(NULL),
40
_current_slab(NULL)
41
{}
42
43
// Note: the global chunk header pool gets never deleted; so this destructor only
44
// exists for the sake of tests.
45
ChunkHeaderPool::~ChunkHeaderPool() {
46
Slab* s = _first_slab;
47
while (s != NULL) {
48
Slab* next_slab = s->_next;
49
os::free(s);
50
s = next_slab;
51
}
52
}
53
54
void ChunkHeaderPool::allocate_new_slab() {
55
Slab* slab = new Slab();
56
if (_current_slab != NULL) {
57
_current_slab->_next = slab;
58
}
59
_current_slab = slab;
60
if (_first_slab == NULL) {
61
_first_slab = slab;
62
}
63
_num_slabs.increment();
64
}
65
66
// Returns size of memory used.
67
size_t ChunkHeaderPool::memory_footprint_words() const {
68
return (_num_slabs.get() * sizeof(Slab)) / BytesPerWord;
69
}
70
71
void ChunkHeaderPool::initialize() {
72
assert(_chunkHeaderPool == NULL, "only once");
73
_chunkHeaderPool = new ChunkHeaderPool();
74
}
75
76
#ifdef ASSERT
77
void ChunkHeaderPool::verify() const {
78
const Slab* s = _first_slab;
79
int num = 0;
80
while (s != NULL) {
81
assert(s->_top >= 0 && s->_top <= SlabCapacity,
82
"invalid slab at " PTR_FORMAT ", top: %d, slab cap: %d",
83
p2i(s), s->_top, SlabCapacity );
84
s = s->_next;
85
num++;
86
}
87
_num_slabs.check(num);
88
}
89
#endif
90
91
} // namespace metaspace
92
93
94