Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/memory/metaspaceUtils.hpp
40949 views
1
/*
2
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2021 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
#ifndef SHARE_MEMORY_METASPACEUTILS_HPP
26
#define SHARE_MEMORY_METASPACEUTILS_HPP
27
28
#include "memory/metaspace.hpp"
29
#include "memory/metaspaceChunkFreeListSummary.hpp"
30
#include "memory/metaspaceStats.hpp"
31
32
class outputStream;
33
34
// Metaspace are deallocated when their class loader are GC'ed.
35
// This class implements a policy for inducing GC's to recover
36
// Metaspaces.
37
38
class MetaspaceGCThresholdUpdater : public AllStatic {
39
public:
40
enum Type {
41
ComputeNewSize,
42
ExpandAndAllocate,
43
Last
44
};
45
46
static const char* to_string(MetaspaceGCThresholdUpdater::Type updater) {
47
switch (updater) {
48
case ComputeNewSize:
49
return "compute_new_size";
50
case ExpandAndAllocate:
51
return "expand_and_allocate";
52
default:
53
assert(false, "Got bad updater: %d", (int) updater);
54
return NULL;
55
};
56
}
57
};
58
59
class MetaspaceGC : public AllStatic {
60
61
// The current high-water-mark for inducing a GC.
62
// When committed memory of all metaspaces reaches this value,
63
// a GC is induced and the value is increased. Size is in bytes.
64
static volatile size_t _capacity_until_GC;
65
static uint _shrink_factor;
66
67
static size_t shrink_factor() { return _shrink_factor; }
68
void set_shrink_factor(uint v) { _shrink_factor = v; }
69
70
public:
71
72
static void initialize();
73
static void post_initialize();
74
75
static size_t capacity_until_GC();
76
static bool inc_capacity_until_GC(size_t v,
77
size_t* new_cap_until_GC = NULL,
78
size_t* old_cap_until_GC = NULL,
79
bool* can_retry = NULL);
80
static size_t dec_capacity_until_GC(size_t v);
81
82
// The amount to increase the high-water-mark (_capacity_until_GC)
83
static size_t delta_capacity_until_GC(size_t bytes);
84
85
// Tells if we have can expand metaspace without hitting set limits.
86
static bool can_expand(size_t words, bool is_class);
87
88
// Returns amount that we can expand without hitting a GC,
89
// measured in words.
90
static size_t allowed_expansion();
91
92
// Calculate the new high-water mark at which to induce
93
// a GC.
94
static void compute_new_size();
95
};
96
97
class MetaspaceUtils : AllStatic {
98
public:
99
100
// Committed space actually in use by Metadata
101
static size_t used_words();
102
static size_t used_words(Metaspace::MetadataType mdtype);
103
104
// Space committed for Metaspace
105
static size_t committed_words();
106
static size_t committed_words(Metaspace::MetadataType mdtype);
107
108
// Space reserved for Metaspace
109
static size_t reserved_words();
110
static size_t reserved_words(Metaspace::MetadataType mdtype);
111
112
// _bytes() variants for convenience...
113
static size_t used_bytes() { return used_words() * BytesPerWord; }
114
static size_t used_bytes(Metaspace::MetadataType mdtype) { return used_words(mdtype) * BytesPerWord; }
115
static size_t committed_bytes() { return committed_words() * BytesPerWord; }
116
static size_t committed_bytes(Metaspace::MetadataType mdtype) { return committed_words(mdtype) * BytesPerWord; }
117
static size_t reserved_bytes() { return reserved_words() * BytesPerWord; }
118
static size_t reserved_bytes(Metaspace::MetadataType mdtype) { return reserved_words(mdtype) * BytesPerWord; }
119
120
// Retrieve all statistics in one go; make sure the values are consistent.
121
static MetaspaceStats get_statistics(Metaspace::MetadataType mdtype);
122
static MetaspaceCombinedStats get_combined_statistics();
123
124
// (See JDK-8251342). Implement or Consolidate.
125
static MetaspaceChunkFreeListSummary chunk_free_list_summary(Metaspace::MetadataType mdtype) {
126
return MetaspaceChunkFreeListSummary(0,0,0,0,0,0,0,0);
127
}
128
129
// Log change in used metadata.
130
static void print_metaspace_change(const MetaspaceCombinedStats& pre_meta_values);
131
132
// This will print out a basic metaspace usage report but
133
// unlike print_report() is guaranteed not to lock or to walk the CLDG.
134
static void print_basic_report(outputStream* st, size_t scale = 0);
135
136
// Prints a report about the current metaspace state.
137
// Function will walk the CLDG and will lock the expand lock; if that is not
138
// convenient, use print_basic_report() instead.
139
static void print_report(outputStream* out, size_t scale = 0);
140
141
static void print_on(outputStream * out);
142
143
DEBUG_ONLY(static void verify();)
144
145
};
146
147
#endif // SHARE_MEMORY_METASPACEUTILS_HPP
148
149