1 /*
2 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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;
237 static bool initialized() { return _initialized; }
238
239 };
240
241 // Manages the metaspace portion belonging to a class loader
242 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
243 friend class CollectedHeap; // For expand_and_allocate()
244 friend class ZCollectedHeap; // For expand_and_allocate()
245 friend class ShenandoahHeap; // For expand_and_allocate()
246 friend class Metaspace;
247 friend class MetaspaceUtils;
248 friend class metaspace::PrintCLDMetaspaceInfoClosure;
249 friend class VM_CollectForMetadataAllocation; // For expand_and_allocate()
250
251 private:
252
253 void initialize(Mutex* lock, Metaspace::MetaspaceType type);
254
255 // Initialize the first chunk for a Metaspace. Used for
256 // special cases such as the boot class loader, reflection
257 // class loader and anonymous class loader.
258 void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
259 metaspace::Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
260
261 const Metaspace::MetaspaceType _space_type;
262 Mutex* const _lock;
263 metaspace::SpaceManager* _vsm;
264 metaspace::SpaceManager* _class_vsm;
265
266 metaspace::SpaceManager* vsm() const { return _vsm; }
267 metaspace::SpaceManager* class_vsm() const { return _class_vsm; }
268 metaspace::SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) {
269 assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
270 return mdtype == Metaspace::ClassType ? class_vsm() : vsm();
271 }
272
273 Mutex* lock() const { return _lock; }
274
275 MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype);
276
277 size_t class_chunk_size(size_t word_size);
382 static size_t reserved_bytes(Metaspace::MetadataType mdtype);
383 static size_t reserved_bytes() {
384 return reserved_bytes(Metaspace::ClassType) +
385 reserved_bytes(Metaspace::NonClassType);
386 }
387
388 static size_t committed_bytes(Metaspace::MetadataType mdtype);
389 static size_t committed_bytes() {
390 return committed_bytes(Metaspace::ClassType) +
391 committed_bytes(Metaspace::NonClassType);
392 }
393
394 static size_t min_chunk_size_words();
395
396 // Flags for print_report().
397 enum ReportFlag {
398 // Show usage by class loader.
399 rf_show_loaders = (1 << 0),
400 // Breaks report down by chunk type (small, medium, ...).
401 rf_break_down_by_chunktype = (1 << 1),
402 // Breaks report down by space type (anonymous, reflection, ...).
403 rf_break_down_by_spacetype = (1 << 2),
404 // Print details about the underlying virtual spaces.
405 rf_show_vslist = (1 << 3),
406 // Print metaspace map.
407 rf_show_vsmap = (1 << 4),
408 // If show_loaders: show loaded classes for each loader.
409 rf_show_classes = (1 << 5)
410 };
411
412 // This will print out a basic metaspace usage report but
413 // unlike print_report() is guaranteed not to lock or to walk the CLDG.
414 static void print_basic_report(outputStream* st, size_t scale);
415
416 // Prints a report about the current metaspace state.
417 // Optional parts can be enabled via flags.
418 // Function will walk the CLDG and will lock the expand lock; if that is not
419 // convenient, use print_basic_report() instead.
420 static void print_report(outputStream* out, size_t scale = 0, int flags = 0);
421
422 static bool has_chunk_free_list(Metaspace::MetadataType mdtype);
|
1 /*
2 * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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 ClassMirrorHolderMetaspaceType = BootMetaspaceType + 1,
108 ReflectionMetaspaceType = ClassMirrorHolderMetaspaceType + 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;
237 static bool initialized() { return _initialized; }
238
239 };
240
241 // Manages the metaspace portion belonging to a class loader
242 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
243 friend class CollectedHeap; // For expand_and_allocate()
244 friend class ZCollectedHeap; // For expand_and_allocate()
245 friend class ShenandoahHeap; // For expand_and_allocate()
246 friend class Metaspace;
247 friend class MetaspaceUtils;
248 friend class metaspace::PrintCLDMetaspaceInfoClosure;
249 friend class VM_CollectForMetadataAllocation; // For expand_and_allocate()
250
251 private:
252
253 void initialize(Mutex* lock, Metaspace::MetaspaceType type);
254
255 // Initialize the first chunk for a Metaspace. Used for
256 // special cases such as the boot class loader, reflection
257 // class loader and hidden class loader.
258 void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
259 metaspace::Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
260
261 const Metaspace::MetaspaceType _space_type;
262 Mutex* const _lock;
263 metaspace::SpaceManager* _vsm;
264 metaspace::SpaceManager* _class_vsm;
265
266 metaspace::SpaceManager* vsm() const { return _vsm; }
267 metaspace::SpaceManager* class_vsm() const { return _class_vsm; }
268 metaspace::SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) {
269 assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
270 return mdtype == Metaspace::ClassType ? class_vsm() : vsm();
271 }
272
273 Mutex* lock() const { return _lock; }
274
275 MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype);
276
277 size_t class_chunk_size(size_t word_size);
382 static size_t reserved_bytes(Metaspace::MetadataType mdtype);
383 static size_t reserved_bytes() {
384 return reserved_bytes(Metaspace::ClassType) +
385 reserved_bytes(Metaspace::NonClassType);
386 }
387
388 static size_t committed_bytes(Metaspace::MetadataType mdtype);
389 static size_t committed_bytes() {
390 return committed_bytes(Metaspace::ClassType) +
391 committed_bytes(Metaspace::NonClassType);
392 }
393
394 static size_t min_chunk_size_words();
395
396 // Flags for print_report().
397 enum ReportFlag {
398 // Show usage by class loader.
399 rf_show_loaders = (1 << 0),
400 // Breaks report down by chunk type (small, medium, ...).
401 rf_break_down_by_chunktype = (1 << 1),
402 // Breaks report down by space type (hidden, reflection, ...).
403 rf_break_down_by_spacetype = (1 << 2),
404 // Print details about the underlying virtual spaces.
405 rf_show_vslist = (1 << 3),
406 // Print metaspace map.
407 rf_show_vsmap = (1 << 4),
408 // If show_loaders: show loaded classes for each loader.
409 rf_show_classes = (1 << 5)
410 };
411
412 // This will print out a basic metaspace usage report but
413 // unlike print_report() is guaranteed not to lock or to walk the CLDG.
414 static void print_basic_report(outputStream* st, size_t scale);
415
416 // Prints a report about the current metaspace state.
417 // Optional parts can be enabled via flags.
418 // Function will walk the CLDG and will lock the expand lock; if that is not
419 // convenient, use print_basic_report() instead.
420 static void print_report(outputStream* out, size_t scale = 0, int flags = 0);
421
422 static bool has_chunk_free_list(Metaspace::MetadataType mdtype);
|