24 */ |
24 */ |
25 |
25 |
26 #ifndef SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP |
26 #ifndef SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP |
27 #define SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP |
27 #define SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP |
28 |
28 |
|
29 #include "memory/metaspace.hpp" // for MetadataType enum |
|
30 #include "memory/metaspace/chunkLevel.hpp" |
29 #include "utilities/globalDefinitions.hpp" |
31 #include "utilities/globalDefinitions.hpp" |
30 #include "memory/metaspace.hpp" // for MetadataType enum |
|
31 #include "memory/metaspace/metachunk.hpp" // for ChunkIndex enum |
|
32 |
32 |
33 class outputStream; |
33 class outputStream; |
34 |
34 |
35 namespace metaspace { |
35 namespace metaspace { |
36 |
36 |
37 // Contains statistics for a number of free chunks. |
|
38 class FreeChunksStatistics { |
|
39 uintx _num; // Number of chunks |
|
40 size_t _cap; // Total capacity, in words |
|
41 |
37 |
42 public: |
38 // Contains statistics for one or multiple ChunkManager. |
43 FreeChunksStatistics(); |
39 struct cm_stats_t { |
44 |
40 |
45 void reset(); |
41 // How many chunks per level are checked in. |
|
42 int num_chunks[chklvl::NUM_CHUNK_LEVELS]; |
46 |
43 |
47 uintx num() const { return _num; } |
44 // Size, in words, of the sum of all committed areas in this chunk manager, per level. |
48 size_t cap() const { return _cap; } |
45 size_t committed_word_size[chklvl::NUM_CHUNK_LEVELS]; |
49 |
46 |
50 void add(uintx n, size_t s); |
47 cm_stats_t() : num_chunks(), committed_word_size() {} |
51 void add(const FreeChunksStatistics& other); |
|
52 void print_on(outputStream* st, size_t scale) const; |
|
53 |
48 |
54 }; // end: FreeChunksStatistics |
49 void add(const cm_stats_t& other); |
55 |
50 |
|
51 // Returns total word size of all chunks in this manager. |
|
52 size_t total_word_size() const; |
56 |
53 |
57 // Contains statistics for a ChunkManager. |
54 // Returns total committed word size of all chunks in this manager. |
58 class ChunkManagerStatistics { |
55 size_t total_committed_word_size() const; |
59 |
|
60 FreeChunksStatistics _chunk_stats[NumberOfInUseLists]; |
|
61 |
|
62 public: |
|
63 |
|
64 // Free chunk statistics, by chunk index. |
|
65 const FreeChunksStatistics& chunk_stats(ChunkIndex index) const { return _chunk_stats[index]; } |
|
66 FreeChunksStatistics& chunk_stats(ChunkIndex index) { return _chunk_stats[index]; } |
|
67 |
|
68 void reset(); |
|
69 size_t total_capacity() const; |
|
70 |
56 |
71 void print_on(outputStream* st, size_t scale) const; |
57 void print_on(outputStream* st, size_t scale) const; |
72 |
58 |
|
59 DEBUG_ONLY(void verify() const;) |
|
60 |
73 }; // ChunkManagerStatistics |
61 }; // ChunkManagerStatistics |
74 |
62 |
75 // Contains statistics for a number of chunks in use. |
63 // Contains statistics for one or multiple chunks in use. |
76 // Each chunk has a used and free portion; however, there are current chunks (serving |
64 struct in_use_chunk_stats_t { |
77 // potential future metaspace allocations) and non-current chunks. Unused portion of the |
|
78 // former is counted as free, unused portion of the latter counts as waste. |
|
79 class UsedChunksStatistics { |
|
80 uintx _num; // Number of chunks |
|
81 size_t _cap; // Total capacity in words. |
|
82 size_t _used; // Total used area, in words |
|
83 size_t _free; // Total free area (unused portions of current chunks), in words |
|
84 size_t _waste; // Total waste area (unused portions of non-current chunks), in words |
|
85 size_t _overhead; // Total sum of chunk overheads, in words. |
|
86 |
65 |
87 public: |
66 // Number of chunks |
|
67 int num; |
88 |
68 |
89 UsedChunksStatistics(); |
69 // Note: |
|
70 // capacity = committed + uncommitted |
|
71 // committed = used + free + waste |
90 |
72 |
91 void reset(); |
73 // Capacity (total sum of all chunk sizes) in words. |
|
74 // May contain committed and uncommitted space. |
|
75 size_t word_size; |
92 |
76 |
93 uintx num() const { return _num; } |
77 // Total committed area, in words. |
|
78 size_t committed_words; |
94 |
79 |
95 // Total capacity, in words |
80 // Total used area, in words. |
96 size_t cap() const { return _cap; } |
81 size_t used_words; |
97 |
82 |
98 // Total used area, in words |
83 // Total free committed area, in words. |
99 size_t used() const { return _used; } |
84 size_t free_words; |
100 |
85 |
101 // Total free area (unused portions of current chunks), in words |
86 // Total waste committed area, in words. |
102 size_t free() const { return _free; } |
87 size_t waste_words; |
103 |
88 |
104 // Total waste area (unused portions of non-current chunks), in words |
89 in_use_chunk_stats_t() |
105 size_t waste() const { return _waste; } |
90 : num(0), word_size(0), committed_words(0), |
|
91 used_words(0), free_words(0), waste_words(0) |
|
92 {} |
106 |
93 |
107 // Total area spent in overhead (chunk headers), in words |
94 void add(const in_use_chunk_stats_t& other) { |
108 size_t overhead() const { return _overhead; } |
95 num += other.num; |
|
96 word_size += other.word_size; |
|
97 committed_words += other.committed_words; |
|
98 used_words += other.used_words; |
|
99 free_words += other.free_words; |
|
100 waste_words += other.waste_words; |
109 |
101 |
110 void add_num(uintx n) { _num += n; } |
102 } |
111 void add_cap(size_t s) { _cap += s; } |
|
112 void add_used(size_t s) { _used += s; } |
|
113 void add_free(size_t s) { _free += s; } |
|
114 void add_waste(size_t s) { _waste += s; } |
|
115 void add_overhead(size_t s) { _overhead += s; } |
|
116 |
|
117 void add(const UsedChunksStatistics& other); |
|
118 |
103 |
119 void print_on(outputStream* st, size_t scale) const; |
104 void print_on(outputStream* st, size_t scale) const; |
120 |
105 |
121 #ifdef ASSERT |
106 DEBUG_ONLY(void verify() const;) |
122 void check_sanity() const; |
|
123 #endif |
|
124 |
107 |
125 }; // UsedChunksStatistics |
108 }; // UsedChunksStatistics |
126 |
109 |
127 // Class containing statistics for one or more space managers. |
110 // Class containing statistics for one or more space managers. |
128 class SpaceManagerStatistics { |
111 struct sm_stats_t { |
129 |
112 |
130 UsedChunksStatistics _chunk_stats[NumberOfInUseLists]; |
113 // chunk statistics by chunk level |
131 uintx _free_blocks_num; |
114 in_use_chunk_stats_t stats[chklvl::NUM_CHUNK_LEVELS]; |
132 size_t _free_blocks_cap_words; |
115 uintx free_blocks_num; |
|
116 size_t free_blocks_word_size; |
133 |
117 |
134 public: |
118 sm_stats_t() |
|
119 : stats(), |
|
120 free_blocks_num(0), |
|
121 free_blocks_word_size(0) |
|
122 {} |
135 |
123 |
136 SpaceManagerStatistics(); |
124 void add(const sm_stats_t& other); |
137 |
125 |
138 // Chunk statistics by chunk index |
126 void print_on(outputStream* st, size_t scale = K, bool detailed = true) const; |
139 const UsedChunksStatistics& chunk_stats(ChunkIndex index) const { return _chunk_stats[index]; } |
|
140 UsedChunksStatistics& chunk_stats(ChunkIndex index) { return _chunk_stats[index]; } |
|
141 |
127 |
142 uintx free_blocks_num () const { return _free_blocks_num; } |
128 in_use_chunk_stats_t totals() const; |
143 size_t free_blocks_cap_words () const { return _free_blocks_cap_words; } |
|
144 |
129 |
145 void reset(); |
130 DEBUG_ONLY(void verify() const;) |
146 |
|
147 void add_free_blocks_info(uintx num, size_t cap); |
|
148 |
|
149 // Returns total chunk statistics over all chunk types. |
|
150 UsedChunksStatistics totals() const; |
|
151 |
|
152 void add(const SpaceManagerStatistics& other); |
|
153 |
|
154 void print_on(outputStream* st, size_t scale, bool detailed) const; |
|
155 |
131 |
156 }; // SpaceManagerStatistics |
132 }; // SpaceManagerStatistics |
157 |
133 |
158 class ClassLoaderMetaspaceStatistics { |
134 // Statistics for one or multiple ClassLoaderMetaspace objects |
|
135 struct clms_stats_t { |
159 |
136 |
160 SpaceManagerStatistics _sm_stats[Metaspace::MetadataTypeCount]; |
137 sm_stats_t sm_stats_nonclass; |
|
138 sm_stats_t sm_stats_class; |
161 |
139 |
162 public: |
140 clms_stats_t() : sm_stats_nonclass(), sm_stats_class() {} |
163 |
141 |
164 ClassLoaderMetaspaceStatistics(); |
142 void add(const clms_stats_t& other) { |
|
143 sm_stats_nonclass.add(other.sm_stats_nonclass); |
|
144 sm_stats_class.add(other.sm_stats_class); |
|
145 } |
165 |
146 |
166 const SpaceManagerStatistics& sm_stats(Metaspace::MetadataType mdType) const { return _sm_stats[mdType]; } |
147 void print_on(outputStream* st, size_t scale, bool detailed) const; |
167 SpaceManagerStatistics& sm_stats(Metaspace::MetadataType mdType) { return _sm_stats[mdType]; } |
|
168 |
|
169 const SpaceManagerStatistics& nonclass_sm_stats() const { return sm_stats(Metaspace::NonClassType); } |
|
170 SpaceManagerStatistics& nonclass_sm_stats() { return sm_stats(Metaspace::NonClassType); } |
|
171 const SpaceManagerStatistics& class_sm_stats() const { return sm_stats(Metaspace::ClassType); } |
|
172 SpaceManagerStatistics& class_sm_stats() { return sm_stats(Metaspace::ClassType); } |
|
173 |
|
174 void reset(); |
|
175 |
|
176 void add(const ClassLoaderMetaspaceStatistics& other); |
|
177 |
148 |
178 // Returns total space manager statistics for both class and non-class metaspace |
149 // Returns total space manager statistics for both class and non-class metaspace |
179 SpaceManagerStatistics totals() const; |
150 sm_stats_t totals() const; |
180 |
151 |
181 void print_on(outputStream* st, size_t scale, bool detailed) const; |
152 |
|
153 DEBUG_ONLY(void verify() const;) |
182 |
154 |
183 }; // ClassLoaderMetaspaceStatistics |
155 }; // ClassLoaderMetaspaceStatistics |
184 |
156 |
185 } // namespace metaspace |
157 } // namespace metaspace |
186 |
158 |
187 #endif // SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP |
159 #endif // SHARE_MEMORY_METASPACE_METASPACESTATISTICS_HPP |
|
160 |