Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/memory/metaspace/metachunkList.hpp
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
#ifndef SHARE_MEMORY_METASPACE_METACHUNKLIST_HPP
27
#define SHARE_MEMORY_METASPACE_METACHUNKLIST_HPP
28
29
#include "memory/metaspace/counters.hpp"
30
#include "memory/metaspace/metachunk.hpp"
31
#include "utilities/globalDefinitions.hpp"
32
33
class outputStream;
34
35
namespace metaspace {
36
37
// A simple single-linked list of chunks, used in MetaspaceArena to keep
38
// a list of retired chunks, as well as in the ChunkHeaderPool to keep
39
// a cache of unused chunk headers.
40
41
class MetachunkList {
42
43
Metachunk* _first;
44
IntCounter _num_chunks;
45
46
// Note: The chunks inside this list may be dead (->chunk header pool).
47
// So, do not call c->word size on them or anything else which may not
48
// work with dead chunks.
49
50
// Check that list does not contain the given chunk; Note that since that check
51
// is expensive, it is subject to VerifyMetaspaceInterval.
52
DEBUG_ONLY(void verify_does_not_contain(const Metachunk* c) const;)
53
54
public:
55
56
MetachunkList() : _first(NULL), _num_chunks() {}
57
58
int count() const { return _num_chunks.get(); }
59
60
void add(Metachunk* c) {
61
DEBUG_ONLY(verify_does_not_contain(c);)
62
c->set_next(_first);
63
if (_first) {
64
_first->set_prev(c);
65
}
66
_first = c;
67
_num_chunks.increment();
68
}
69
70
Metachunk* remove_first() {
71
if (_first) {
72
Metachunk* c = _first;
73
_first = _first->next();
74
if (_first) {
75
_first->set_prev(NULL);
76
}
77
_num_chunks.decrement();
78
c->set_prev(NULL);
79
c->set_next(NULL);
80
return c;
81
}
82
return NULL;
83
}
84
85
Metachunk* first() { return _first; }
86
const Metachunk* first() const { return _first; }
87
88
#ifdef ASSERT
89
// Note: linear search
90
bool contains(const Metachunk* c) const;
91
void verify() const;
92
#endif
93
94
size_t calc_committed_word_size() const;
95
size_t calc_word_size() const;
96
97
void print_on(outputStream* st) const;
98
99
};
100
101
} // namespace metaspace
102
103
#endif // SHARE_MEMORY_METASPACE_METACHUNKLIST_HPP
104
105