24 #ifndef SHARE_MEMORY_METASPACE_HPP
25 #define SHARE_MEMORY_METASPACE_HPP
26
27 #include "memory/allocation.hpp"
28 #include "memory/memRegion.hpp"
29 #include "memory/metaspaceChunkFreeListSummary.hpp"
30 #include "memory/virtualspace.hpp"
31 #include "runtime/globals.hpp"
32 #include "utilities/exceptions.hpp"
33 #include "utilities/globalDefinitions.hpp"
34
35 class ClassLoaderData;
36 class MetaspaceShared;
37 class MetaspaceTracer;
38 class Mutex;
39 class outputStream;
40
41 namespace metaspace {
42 class MetaspaceArena;
43 class MetaspaceSizesSnapshot;
44 struct clms_stats_t;
45 }
46
47 ////////////////// Metaspace ///////////////////////
48
49 // Namespace for important central static functions
50 // (auxiliary stuff goes into MetaspaceUtils)
51 class Metaspace : public AllStatic {
52
53 friend class MetaspaceShared;
54
55 public:
56 enum MetadataType {
57 ClassType,
58 NonClassType,
59 MetadataTypeCount
60 };
61 enum MetaspaceType {
62 ZeroMetaspaceType = 0,
63 StandardMetaspaceType = ZeroMetaspaceType,
64 BootMetaspaceType = StandardMetaspaceType + 1,
120 // The granularity at which Metaspace is committed and uncommitted.
121 // (Todo: Why does this have to be exposed?)
122 static size_t commit_alignment() { return commit_alignment_words() * BytesPerWord; }
123 static size_t commit_alignment_words();
124
125 // The largest possible single allocation
126 static size_t max_allocation_word_size();
127
128 static MetaWord* allocate(ClassLoaderData* loader_data, size_t word_size,
129 MetaspaceObj::Type type, TRAPS);
130
131 static bool contains(const void* ptr);
132 static bool contains_non_shared(const void* ptr);
133
134 // Free empty virtualspaces
135 static void purge();
136
137 static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,
138 MetaspaceObj::Type type, Metaspace::MetadataType mdtype, TRAPS);
139
140 static void print_compressed_class_space(outputStream* st) NOT_LP64({});
141
142 // Return TRUE only if UseCompressedClassPointers is True.
143 static bool using_class_space() {
144 return NOT_LP64(false) LP64_ONLY(UseCompressedClassPointers);
145 }
146
147 static bool initialized();
148
149 };
150
151 // ClassLoaderMetaspace is an inbetween-object between a CLD and its MetaspaceArena(s).
152 //
153 // A CLD owns one MetaspaceArena if compressed class space is off, two if its one
154 // (one for allocations of Klass* structures from class space, one for the rest from
155 // non-class space).
156 //
157 // ClassLoaderMetaspace only exists to hide this logic from upper layers:
158 //
159 // +------+ +----------------------+ +-------------------+
160 // | CLD | ---> | ClassLoaderMetaspace | ----> | (non class) Arena |
161 // +------+ +----------------------+ | +-------------------+ allocation top
162 // | | v
163 // | + chunk -- chunk ... -- chunk
164 // |
165 // | +-------------------+
166 // +--> | (class) Arena |
196 public:
197
198 ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType space_type);
199
200 ~ClassLoaderMetaspace();
201
202 Metaspace::MetaspaceType space_type() const { return _space_type; }
203
204 // Allocate word_size words from Metaspace.
205 MetaWord* allocate(size_t word_size, Metaspace::MetadataType mdType);
206
207 // Attempt to expand the GC threshold to be good for at least another word_size words
208 // and allocate. Returns NULL if failure. Used during Metaspace GC.
209 MetaWord* expand_and_allocate(size_t word_size, Metaspace::MetadataType mdType);
210
211 // Prematurely returns a metaspace allocation to the _block_freelists
212 // because it is not needed anymore.
213 void deallocate(MetaWord* ptr, size_t word_size, bool is_class);
214
215 // Update statistics. This walks all in-use chunks.
216 void add_to_statistics(metaspace::clms_stats_t* out) const;
217
218 DEBUG_ONLY(void verify() const;)
219
220 // This only exists for JFR and jcmd VM.classloader_stats. We may want to
221 // change this. Capacity as a stat is of questionable use since it may
222 // contain committed and uncommitted areas. For now we do this to maintain
223 // backward compatibility with JFR.
224 void calculate_jfr_stats(size_t* p_used_bytes, size_t* p_capacity_bytes) const;
225
226 }; // end: ClassLoaderMetaspace
227
228
229 ////////////////// MetaspaceGC ///////////////////////
230
231 // Metaspace are deallocated when their class loader are GC'ed.
232 // This class implements a policy for inducing GC's to recover
233 // Metaspaces.
234
235 class MetaspaceGCThresholdUpdater : public AllStatic {
236 public:
319
320 // (See JDK-8251342). Implement or Consolidate.
321 static MetaspaceChunkFreeListSummary chunk_free_list_summary(Metaspace::MetadataType mdtype) {
322 return MetaspaceChunkFreeListSummary(0,0,0,0,0,0,0,0);
323 }
324
325 // Log change in used metadata.
326 static void print_metaspace_change(const metaspace::MetaspaceSizesSnapshot& pre_meta_values);
327
328 // This will print out a basic metaspace usage report but
329 // unlike print_report() is guaranteed not to lock or to walk the CLDG.
330 static void print_basic_report(outputStream* st, size_t scale = 0);
331
332 // Prints a report about the current metaspace state.
333 // Function will walk the CLDG and will lock the expand lock; if that is not
334 // convenient, use print_basic_report() instead.
335 static void print_report(outputStream* out, size_t scale = 0);
336
337 static void print_on(outputStream * out);
338
339 DEBUG_ONLY(static void verify(bool slow);)
340
341 };
342
343 #endif // SHARE_MEMORY_METASPACE_HPP
|
24 #ifndef SHARE_MEMORY_METASPACE_HPP
25 #define SHARE_MEMORY_METASPACE_HPP
26
27 #include "memory/allocation.hpp"
28 #include "memory/memRegion.hpp"
29 #include "memory/metaspaceChunkFreeListSummary.hpp"
30 #include "memory/virtualspace.hpp"
31 #include "runtime/globals.hpp"
32 #include "utilities/exceptions.hpp"
33 #include "utilities/globalDefinitions.hpp"
34
35 class ClassLoaderData;
36 class MetaspaceShared;
37 class MetaspaceTracer;
38 class Mutex;
39 class outputStream;
40
41 namespace metaspace {
42 class MetaspaceArena;
43 class MetaspaceSizesSnapshot;
44 struct ClmsStats;
45 }
46
47 ////////////////// Metaspace ///////////////////////
48
49 // Namespace for important central static functions
50 // (auxiliary stuff goes into MetaspaceUtils)
51 class Metaspace : public AllStatic {
52
53 friend class MetaspaceShared;
54
55 public:
56 enum MetadataType {
57 ClassType,
58 NonClassType,
59 MetadataTypeCount
60 };
61 enum MetaspaceType {
62 ZeroMetaspaceType = 0,
63 StandardMetaspaceType = ZeroMetaspaceType,
64 BootMetaspaceType = StandardMetaspaceType + 1,
120 // The granularity at which Metaspace is committed and uncommitted.
121 // (Todo: Why does this have to be exposed?)
122 static size_t commit_alignment() { return commit_alignment_words() * BytesPerWord; }
123 static size_t commit_alignment_words();
124
125 // The largest possible single allocation
126 static size_t max_allocation_word_size();
127
128 static MetaWord* allocate(ClassLoaderData* loader_data, size_t word_size,
129 MetaspaceObj::Type type, TRAPS);
130
131 static bool contains(const void* ptr);
132 static bool contains_non_shared(const void* ptr);
133
134 // Free empty virtualspaces
135 static void purge();
136
137 static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,
138 MetaspaceObj::Type type, Metaspace::MetadataType mdtype, TRAPS);
139
140 static const char* metadata_type_name(Metaspace::MetadataType mdtype);
141
142 static void print_compressed_class_space(outputStream* st) NOT_LP64({});
143
144 // Return TRUE only if UseCompressedClassPointers is True.
145 static bool using_class_space() {
146 return NOT_LP64(false) LP64_ONLY(UseCompressedClassPointers);
147 }
148
149 static bool is_class_space_allocation(MetadataType mdType) {
150 return mdType == ClassType && using_class_space();
151 }
152
153 static bool initialized();
154
155 };
156
157 // ClassLoaderMetaspace is an inbetween-object between a CLD and its MetaspaceArena(s).
158 //
159 // A CLD owns one MetaspaceArena if compressed class space is off, two if its one
160 // (one for allocations of Klass* structures from class space, one for the rest from
161 // non-class space).
162 //
163 // ClassLoaderMetaspace only exists to hide this logic from upper layers:
164 //
165 // +------+ +----------------------+ +-------------------+
166 // | CLD | ---> | ClassLoaderMetaspace | ----> | (non class) Arena |
167 // +------+ +----------------------+ | +-------------------+ allocation top
168 // | | v
169 // | + chunk -- chunk ... -- chunk
170 // |
171 // | +-------------------+
172 // +--> | (class) Arena |
202 public:
203
204 ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType space_type);
205
206 ~ClassLoaderMetaspace();
207
208 Metaspace::MetaspaceType space_type() const { return _space_type; }
209
210 // Allocate word_size words from Metaspace.
211 MetaWord* allocate(size_t word_size, Metaspace::MetadataType mdType);
212
213 // Attempt to expand the GC threshold to be good for at least another word_size words
214 // and allocate. Returns NULL if failure. Used during Metaspace GC.
215 MetaWord* expand_and_allocate(size_t word_size, Metaspace::MetadataType mdType);
216
217 // Prematurely returns a metaspace allocation to the _block_freelists
218 // because it is not needed anymore.
219 void deallocate(MetaWord* ptr, size_t word_size, bool is_class);
220
221 // Update statistics. This walks all in-use chunks.
222 void add_to_statistics(metaspace::ClmsStats* out) const;
223
224 DEBUG_ONLY(void verify() const;)
225
226 // This only exists for JFR and jcmd VM.classloader_stats. We may want to
227 // change this. Capacity as a stat is of questionable use since it may
228 // contain committed and uncommitted areas. For now we do this to maintain
229 // backward compatibility with JFR.
230 void calculate_jfr_stats(size_t* p_used_bytes, size_t* p_capacity_bytes) const;
231
232 }; // end: ClassLoaderMetaspace
233
234
235 ////////////////// MetaspaceGC ///////////////////////
236
237 // Metaspace are deallocated when their class loader are GC'ed.
238 // This class implements a policy for inducing GC's to recover
239 // Metaspaces.
240
241 class MetaspaceGCThresholdUpdater : public AllStatic {
242 public:
325
326 // (See JDK-8251342). Implement or Consolidate.
327 static MetaspaceChunkFreeListSummary chunk_free_list_summary(Metaspace::MetadataType mdtype) {
328 return MetaspaceChunkFreeListSummary(0,0,0,0,0,0,0,0);
329 }
330
331 // Log change in used metadata.
332 static void print_metaspace_change(const metaspace::MetaspaceSizesSnapshot& pre_meta_values);
333
334 // This will print out a basic metaspace usage report but
335 // unlike print_report() is guaranteed not to lock or to walk the CLDG.
336 static void print_basic_report(outputStream* st, size_t scale = 0);
337
338 // Prints a report about the current metaspace state.
339 // Function will walk the CLDG and will lock the expand lock; if that is not
340 // convenient, use print_basic_report() instead.
341 static void print_report(outputStream* out, size_t scale = 0);
342
343 static void print_on(outputStream * out);
344
345 DEBUG_ONLY(static void verify();)
346
347 };
348
349 #endif // SHARE_MEMORY_METASPACE_HPP
|