20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 #include <memory/metaspace/settings.hpp> |
|
26 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
27 |
26 |
28 #include "aot/aotLoader.hpp" |
27 #include "aot/aotLoader.hpp" |
29 #include "gc/shared/collectedHeap.hpp" |
28 #include "gc/shared/collectedHeap.hpp" |
30 #include "logging/log.hpp" |
29 #include "logging/log.hpp" |
39 #include "memory/metaspace/metaspaceCommon.hpp" |
38 #include "memory/metaspace/metaspaceCommon.hpp" |
40 #include "memory/metaspace/metaspaceEnums.hpp" |
39 #include "memory/metaspace/metaspaceEnums.hpp" |
41 #include "memory/metaspace/metaspaceReport.hpp" |
40 #include "memory/metaspace/metaspaceReport.hpp" |
42 #include "memory/metaspace/metaspaceSizesSnapshot.hpp" |
41 #include "memory/metaspace/metaspaceSizesSnapshot.hpp" |
43 #include "memory/metaspace/runningCounters.hpp" |
42 #include "memory/metaspace/runningCounters.hpp" |
|
43 #include "memory/metaspace/settings.hpp" |
44 #include "memory/metaspace/virtualSpaceList.hpp" |
44 #include "memory/metaspace/virtualSpaceList.hpp" |
45 #include "memory/universe.hpp" |
45 #include "memory/universe.hpp" |
46 #include "oops/compressedOops.hpp" |
46 #include "oops/compressedOops.hpp" |
47 #include "runtime/init.hpp" |
47 #include "runtime/init.hpp" |
48 #include "runtime/java.hpp" |
48 #include "runtime/java.hpp" |
56 |
56 |
57 using metaspace::ChunkManager; |
57 using metaspace::ChunkManager; |
58 using metaspace::ClassLoaderMetaspace; |
58 using metaspace::ClassLoaderMetaspace; |
59 using metaspace::CommitLimiter; |
59 using metaspace::CommitLimiter; |
60 using metaspace::MetaspaceType; |
60 using metaspace::MetaspaceType; |
61 using metaspace::MetadataType; |
|
62 using metaspace::MetaspaceReporter; |
61 using metaspace::MetaspaceReporter; |
63 using metaspace::RunningCounters; |
62 using metaspace::RunningCounters; |
64 using metaspace::VirtualSpaceList; |
63 using metaspace::VirtualSpaceList; |
65 |
64 |
66 |
65 |
67 // Used by MetaspaceCounters |
66 // Used by MetaspaceCounters |
68 size_t MetaspaceUtils::free_chunks_total_words(MetadataType mdtype) { |
67 size_t MetaspaceUtils::free_chunks_total_words(Metaspace::MetadataType mdtype) { |
69 return is_class(mdtype) ? RunningCounters::free_chunks_words_class() : RunningCounters::free_chunks_words_nonclass(); |
68 return metaspace::is_class(mdtype) ? RunningCounters::free_chunks_words_class() : RunningCounters::free_chunks_words_nonclass(); |
70 } |
69 } |
71 |
70 |
72 size_t MetaspaceUtils::used_words() { |
71 size_t MetaspaceUtils::used_words() { |
73 return RunningCounters::used_words(); |
72 return RunningCounters::used_words(); |
74 } |
73 } |
75 |
74 |
76 size_t MetaspaceUtils::used_words(MetadataType mdtype) { |
75 size_t MetaspaceUtils::used_words(Metaspace::MetadataType mdtype) { |
77 return is_class(mdtype) ? RunningCounters::used_words_class() : RunningCounters::used_words_nonclass(); |
76 return metaspace::is_class(mdtype) ? RunningCounters::used_words_class() : RunningCounters::used_words_nonclass(); |
78 } |
77 } |
79 |
78 |
80 size_t MetaspaceUtils::reserved_words() { |
79 size_t MetaspaceUtils::reserved_words() { |
81 return RunningCounters::reserved_words(); |
80 return RunningCounters::reserved_words(); |
82 } |
81 } |
83 |
82 |
84 size_t MetaspaceUtils::reserved_words(MetadataType mdtype) { |
83 size_t MetaspaceUtils::reserved_words(Metaspace::MetadataType mdtype) { |
85 return is_class(mdtype) ? RunningCounters::reserved_words_class() : RunningCounters::reserved_words_nonclass(); |
84 return metaspace::is_class(mdtype) ? RunningCounters::reserved_words_class() : RunningCounters::reserved_words_nonclass(); |
86 } |
85 } |
87 |
86 |
88 size_t MetaspaceUtils::committed_words() { |
87 size_t MetaspaceUtils::committed_words() { |
89 return RunningCounters::committed_words(); |
88 return RunningCounters::committed_words(); |
90 } |
89 } |
91 |
90 |
92 size_t MetaspaceUtils::committed_words(MetadataType mdtype) { |
91 size_t MetaspaceUtils::committed_words(Metaspace::MetadataType mdtype) { |
93 return is_class(mdtype) ? RunningCounters::committed_words_class() : RunningCounters::committed_words_nonclass(); |
92 return metaspace::is_class(mdtype) ? RunningCounters::committed_words_class() : RunningCounters::committed_words_nonclass(); |
94 } |
93 } |
95 |
94 |
96 |
95 |
97 |
96 |
98 void MetaspaceUtils::print_metaspace_change(const metaspace::MetaspaceSizesSnapshot& pre_meta_values) { |
97 void MetaspaceUtils::print_metaspace_change(const metaspace::MetaspaceSizesSnapshot& pre_meta_values) { |
137 } |
136 } |
138 } |
137 } |
139 |
138 |
140 |
139 |
141 // Prints an ASCII representation of the given space. |
140 // Prints an ASCII representation of the given space. |
142 void MetaspaceUtils::print_metaspace_map(outputStream* out, MetadataType mdtype) { |
141 void MetaspaceUtils::print_metaspace_map(outputStream* out, Metaspace::MetadataType mdtype) { |
143 out->print_cr("-- not yet implemented ---"); |
142 out->print_cr("-- not yet implemented ---"); |
144 } |
143 } |
145 |
144 |
146 // This will print out a basic metaspace usage report but |
145 // This will print out a basic metaspace usage report but |
147 // unlike print_report() is guaranteed not to lock or to walk the CLDG. |
146 // unlike print_report() is guaranteed not to lock or to walk the CLDG. |
172 used_bytes()/K, |
171 used_bytes()/K, |
173 committed_bytes()/K, |
172 committed_bytes()/K, |
174 reserved_bytes()/K); |
173 reserved_bytes()/K); |
175 |
174 |
176 if (Metaspace::using_class_space()) { |
175 if (Metaspace::using_class_space()) { |
177 const MetadataType ct = metaspace::ClassType; |
176 const Metaspace::MetadataType ct = Metaspace::ClassType; |
178 out->print_cr(" class space " |
177 out->print_cr(" class space " |
179 "used " SIZE_FORMAT "K, " |
178 "used " SIZE_FORMAT "K, " |
180 "committed " SIZE_FORMAT "K, " |
179 "committed " SIZE_FORMAT "K, " |
181 "reserved " SIZE_FORMAT "K", |
180 "reserved " SIZE_FORMAT "K", |
182 used_bytes(ct)/K, |
181 used_bytes(ct)/K, |
335 } |
334 } |
336 |
335 |
337 bool MetaspaceGC::can_expand(size_t word_size, bool is_class) { |
336 bool MetaspaceGC::can_expand(size_t word_size, bool is_class) { |
338 // Check if the compressed class space is full. |
337 // Check if the compressed class space is full. |
339 if (is_class && Metaspace::using_class_space()) { |
338 if (is_class && Metaspace::using_class_space()) { |
340 size_t class_committed = MetaspaceUtils::committed_bytes(metaspace::ClassType); |
339 size_t class_committed = MetaspaceUtils::committed_bytes(Metaspace::ClassType); |
341 if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) { |
340 if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) { |
342 log_trace(gc, metaspace, freelist)("Cannot expand %s metaspace by " SIZE_FORMAT " words (CompressedClassSpaceSize = " SIZE_FORMAT " words)", |
341 log_trace(gc, metaspace, freelist)("Cannot expand %s metaspace by " SIZE_FORMAT " words (CompressedClassSpaceSize = " SIZE_FORMAT " words)", |
343 (is_class ? "class" : "non-class"), word_size, CompressedClassSpaceSize / sizeof(MetaWord)); |
342 (is_class ? "class" : "non-class"), word_size, CompressedClassSpaceSize / sizeof(MetaWord)); |
344 return false; |
343 return false; |
345 } |
344 } |
860 } |
859 } |
861 |
860 |
862 assert(loader_data != NULL, "Should never pass around a NULL loader_data. " |
861 assert(loader_data != NULL, "Should never pass around a NULL loader_data. " |
863 "ClassLoaderData::the_null_class_loader_data() should have been used."); |
862 "ClassLoaderData::the_null_class_loader_data() should have been used."); |
864 |
863 |
865 MetadataType mdtype = (type == MetaspaceObj::ClassType) ? metaspace::ClassType : metaspace::NonClassType; |
864 Metaspace::MetadataType mdtype = (type == MetaspaceObj::ClassType) ? Metaspace::ClassType : Metaspace::NonClassType; |
866 |
865 |
867 // Try to allocate metadata. |
866 // Try to allocate metadata. |
868 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype); |
867 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype); |
869 |
868 |
870 if (result == NULL) { |
869 if (result == NULL) { |
905 |
904 |
906 // If result is still null, we are out of memory. |
905 // If result is still null, we are out of memory. |
907 Log(gc, metaspace, freelist, oom) log; |
906 Log(gc, metaspace, freelist, oom) log; |
908 if (log.is_info()) { |
907 if (log.is_info()) { |
909 log.info("Metaspace (%s) allocation failed for size " SIZE_FORMAT, |
908 log.info("Metaspace (%s) allocation failed for size " SIZE_FORMAT, |
910 is_class(mdtype) ? "class" : "data", word_size); |
909 metaspace::is_class(mdtype) ? "class" : "data", word_size); |
911 ResourceMark rm; |
910 ResourceMark rm; |
912 if (log.is_debug()) { |
911 if (log.is_debug()) { |
913 if (loader_data->metaspace_or_null() != NULL) { |
912 if (loader_data->metaspace_or_null() != NULL) { |
914 LogStream ls(log.debug()); |
913 LogStream ls(log.debug()); |
915 loader_data->print_value_on(&ls); |
914 loader_data->print_value_on(&ls); |
920 MetaspaceUtils::print_basic_report(&ls, 0); |
919 MetaspaceUtils::print_basic_report(&ls, 0); |
921 } |
920 } |
922 |
921 |
923 // Which limit did we hit? CompressedClassSpaceSize or MaxMetaspaceSize? |
922 // Which limit did we hit? CompressedClassSpaceSize or MaxMetaspaceSize? |
924 bool out_of_compressed_class_space = false; |
923 bool out_of_compressed_class_space = false; |
925 if (is_class(mdtype)) { |
924 if (metaspace::is_class(mdtype)) { |
926 ClassLoaderMetaspace* metaspace = loader_data->metaspace_non_null(); |
925 ClassLoaderMetaspace* metaspace = loader_data->metaspace_non_null(); |
927 out_of_compressed_class_space = |
926 out_of_compressed_class_space = |
928 MetaspaceUtils::committed_bytes(metaspace::ClassType) + |
927 MetaspaceUtils::committed_bytes(Metaspace::ClassType) + |
929 // TODO: Okay this is just cheesy. |
928 // TODO: Okay this is just cheesy. |
930 // Of course this may fail and return incorrect results. |
929 // Of course this may fail and return incorrect results. |
931 // Think this over - we need some clean way to remember which limit |
930 // Think this over - we need some clean way to remember which limit |
932 // exactly we hit during an allocation. Some sort of allocation context structure? |
931 // exactly we hit during an allocation. Some sort of allocation context structure? |
933 align_up(word_size * BytesPerWord, 4 * M) > |
932 align_up(word_size * BytesPerWord, 4 * M) > |