87 // virtual spaces and the list of chunks in use. Its
88 // allocate() method returns a block for use as a
89 // quantum of metadata.
90
91 // Namespace for important central static functions
92 // (auxiliary stuff goes into MetaspaceUtils)
93 class Metaspace : public AllStatic {
94
95 friend class MetaspaceShared;
96
97 public:
98 enum MetadataType {
99 ClassType,
100 NonClassType,
101 MetadataTypeCount
102 };
103 enum MetaspaceType {
104 ZeroMetaspaceType = 0,
105 StandardMetaspaceType = ZeroMetaspaceType,
106 BootMetaspaceType = StandardMetaspaceType + 1,
107 UnsafeAnonymousMetaspaceType = BootMetaspaceType + 1,
108 ReflectionMetaspaceType = UnsafeAnonymousMetaspaceType + 1,
109 MetaspaceTypeCount
110 };
111
112 private:
113
114 // Align up the word size to the allocation word size
115 static size_t align_word_size_up(size_t);
116
117 // Aligned size of the metaspace.
118 static size_t _compressed_class_space_size;
119
120 static size_t compressed_class_space_size() {
121 return _compressed_class_space_size;
122 }
123
124 static void set_compressed_class_space_size(size_t size) {
125 _compressed_class_space_size = size;
126 }
127
128 static size_t _first_chunk_word_size;
228 static bool initialized() { return _initialized; }
229
230 };
231
232 // Manages the metaspace portion belonging to a class loader
233 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
234 friend class CollectedHeap; // For expand_and_allocate()
235 friend class ZCollectedHeap; // For expand_and_allocate()
236 friend class ShenandoahHeap; // For expand_and_allocate()
237 friend class Metaspace;
238 friend class MetaspaceUtils;
239 friend class metaspace::PrintCLDMetaspaceInfoClosure;
240 friend class VM_CollectForMetadataAllocation; // For expand_and_allocate()
241
242 private:
243
244 void initialize(Mutex* lock, Metaspace::MetaspaceType type);
245
246 // Initialize the first chunk for a Metaspace. Used for
247 // special cases such as the boot class loader, reflection
248 // class loader and anonymous class loader.
249 void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
250 metaspace::Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
251
252 const Metaspace::MetaspaceType _space_type;
253 Mutex* const _lock;
254 metaspace::SpaceManager* _vsm;
255 metaspace::SpaceManager* _class_vsm;
256
257 metaspace::SpaceManager* vsm() const { return _vsm; }
258 metaspace::SpaceManager* class_vsm() const { return _class_vsm; }
259 metaspace::SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) {
260 assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
261 return mdtype == Metaspace::ClassType ? class_vsm() : vsm();
262 }
263
264 Mutex* lock() const { return _lock; }
265
266 MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype);
267
268 size_t class_chunk_size(size_t word_size);
373 static size_t reserved_bytes(Metaspace::MetadataType mdtype);
374 static size_t reserved_bytes() {
375 return reserved_bytes(Metaspace::ClassType) +
376 reserved_bytes(Metaspace::NonClassType);
377 }
378
379 static size_t committed_bytes(Metaspace::MetadataType mdtype);
380 static size_t committed_bytes() {
381 return committed_bytes(Metaspace::ClassType) +
382 committed_bytes(Metaspace::NonClassType);
383 }
384
385 static size_t min_chunk_size_words();
386
387 // Flags for print_report().
388 enum ReportFlag {
389 // Show usage by class loader.
390 rf_show_loaders = (1 << 0),
391 // Breaks report down by chunk type (small, medium, ...).
392 rf_break_down_by_chunktype = (1 << 1),
393 // Breaks report down by space type (anonymous, reflection, ...).
394 rf_break_down_by_spacetype = (1 << 2),
395 // Print details about the underlying virtual spaces.
396 rf_show_vslist = (1 << 3),
397 // Print metaspace map.
398 rf_show_vsmap = (1 << 4),
399 // If show_loaders: show loaded classes for each loader.
400 rf_show_classes = (1 << 5)
401 };
402
403 // This will print out a basic metaspace usage report but
404 // unlike print_report() is guaranteed not to lock or to walk the CLDG.
405 static void print_basic_report(outputStream* st, size_t scale);
406
407 // Prints a report about the current metaspace state.
408 // Optional parts can be enabled via flags.
409 // Function will walk the CLDG and will lock the expand lock; if that is not
410 // convenient, use print_basic_report() instead.
411 static void print_report(outputStream* out, size_t scale = 0, int flags = 0);
412
413 static bool has_chunk_free_list(Metaspace::MetadataType mdtype);
|
87 // virtual spaces and the list of chunks in use. Its
88 // allocate() method returns a block for use as a
89 // quantum of metadata.
90
91 // Namespace for important central static functions
92 // (auxiliary stuff goes into MetaspaceUtils)
93 class Metaspace : public AllStatic {
94
95 friend class MetaspaceShared;
96
97 public:
98 enum MetadataType {
99 ClassType,
100 NonClassType,
101 MetadataTypeCount
102 };
103 enum MetaspaceType {
104 ZeroMetaspaceType = 0,
105 StandardMetaspaceType = ZeroMetaspaceType,
106 BootMetaspaceType = StandardMetaspaceType + 1,
107 ShortLivedMetaspaceType = BootMetaspaceType + 1,
108 ReflectionMetaspaceType = ShortLivedMetaspaceType + 1,
109 MetaspaceTypeCount
110 };
111
112 private:
113
114 // Align up the word size to the allocation word size
115 static size_t align_word_size_up(size_t);
116
117 // Aligned size of the metaspace.
118 static size_t _compressed_class_space_size;
119
120 static size_t compressed_class_space_size() {
121 return _compressed_class_space_size;
122 }
123
124 static void set_compressed_class_space_size(size_t size) {
125 _compressed_class_space_size = size;
126 }
127
128 static size_t _first_chunk_word_size;
228 static bool initialized() { return _initialized; }
229
230 };
231
232 // Manages the metaspace portion belonging to a class loader
233 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
234 friend class CollectedHeap; // For expand_and_allocate()
235 friend class ZCollectedHeap; // For expand_and_allocate()
236 friend class ShenandoahHeap; // For expand_and_allocate()
237 friend class Metaspace;
238 friend class MetaspaceUtils;
239 friend class metaspace::PrintCLDMetaspaceInfoClosure;
240 friend class VM_CollectForMetadataAllocation; // For expand_and_allocate()
241
242 private:
243
244 void initialize(Mutex* lock, Metaspace::MetaspaceType type);
245
246 // Initialize the first chunk for a Metaspace. Used for
247 // special cases such as the boot class loader, reflection
248 // class loader and hidden class loader.
249 void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
250 metaspace::Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
251
252 const Metaspace::MetaspaceType _space_type;
253 Mutex* const _lock;
254 metaspace::SpaceManager* _vsm;
255 metaspace::SpaceManager* _class_vsm;
256
257 metaspace::SpaceManager* vsm() const { return _vsm; }
258 metaspace::SpaceManager* class_vsm() const { return _class_vsm; }
259 metaspace::SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) {
260 assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
261 return mdtype == Metaspace::ClassType ? class_vsm() : vsm();
262 }
263
264 Mutex* lock() const { return _lock; }
265
266 MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype);
267
268 size_t class_chunk_size(size_t word_size);
373 static size_t reserved_bytes(Metaspace::MetadataType mdtype);
374 static size_t reserved_bytes() {
375 return reserved_bytes(Metaspace::ClassType) +
376 reserved_bytes(Metaspace::NonClassType);
377 }
378
379 static size_t committed_bytes(Metaspace::MetadataType mdtype);
380 static size_t committed_bytes() {
381 return committed_bytes(Metaspace::ClassType) +
382 committed_bytes(Metaspace::NonClassType);
383 }
384
385 static size_t min_chunk_size_words();
386
387 // Flags for print_report().
388 enum ReportFlag {
389 // Show usage by class loader.
390 rf_show_loaders = (1 << 0),
391 // Breaks report down by chunk type (small, medium, ...).
392 rf_break_down_by_chunktype = (1 << 1),
393 // Breaks report down by space type (hidden, reflection, ...).
394 rf_break_down_by_spacetype = (1 << 2),
395 // Print details about the underlying virtual spaces.
396 rf_show_vslist = (1 << 3),
397 // Print metaspace map.
398 rf_show_vsmap = (1 << 4),
399 // If show_loaders: show loaded classes for each loader.
400 rf_show_classes = (1 << 5)
401 };
402
403 // This will print out a basic metaspace usage report but
404 // unlike print_report() is guaranteed not to lock or to walk the CLDG.
405 static void print_basic_report(outputStream* st, size_t scale);
406
407 // Prints a report about the current metaspace state.
408 // Optional parts can be enabled via flags.
409 // Function will walk the CLDG and will lock the expand lock; if that is not
410 // convenient, use print_basic_report() instead.
411 static void print_report(outputStream* out, size_t scale = 0, int flags = 0);
412
413 static bool has_chunk_free_list(Metaspace::MetadataType mdtype);
|