113 void print_percentage(outputStream* st, size_t total, size_t part) {
114 if (total == 0) {
115 st->print(" ?%%");
116 } else if (part == 0) {
117 st->print(" 0%%");
118 } else if (part == total) {
119 st->print("100%%");
120 } else {
121 // Note: clearly print very-small-but-not-0% and very-large-but-not-100% percentages.
122 float p = ((float)part / total) * 100.0f;
123 if (p < 1.0f) {
124 st->print(" <1%%");
125 } else if (p > 99.0f){
126 st->print(">99%%");
127 } else {
128 st->print("%3.0f%%", p);
129 }
130 }
131 }
132
133 // Returns size of this chunk type.
134 size_t get_size_for_nonhumongous_chunktype(ChunkIndex chunktype, bool is_class) {
135 assert(is_valid_nonhumongous_chunktype(chunktype), "invalid chunk type.");
136 size_t size = 0;
137 if (is_class) {
138 switch(chunktype) {
139 case SpecializedIndex: size = ClassSpecializedChunk; break;
140 case SmallIndex: size = ClassSmallChunk; break;
141 case MediumIndex: size = ClassMediumChunk; break;
142 default:
143 ShouldNotReachHere();
144 }
145 } else {
146 switch(chunktype) {
147 case SpecializedIndex: size = SpecializedChunk; break;
148 case SmallIndex: size = SmallChunk; break;
149 case MediumIndex: size = MediumChunk; break;
150 default:
151 ShouldNotReachHere();
152 }
153 }
154 return size;
155 }
156
157 ChunkIndex get_chunk_type_by_size(size_t size, bool is_class) {
158 if (is_class) {
159 if (size == ClassSpecializedChunk) {
160 return SpecializedIndex;
161 } else if (size == ClassSmallChunk) {
162 return SmallIndex;
163 } else if (size == ClassMediumChunk) {
164 return MediumIndex;
165 } else if (size > ClassMediumChunk) {
166 // A valid humongous chunk size is a multiple of the smallest chunk size.
167 assert(is_aligned(size, ClassSpecializedChunk), "Invalid chunk size");
168 return HumongousIndex;
169 }
170 } else {
171 if (size == SpecializedChunk) {
172 return SpecializedIndex;
173 } else if (size == SmallChunk) {
174 return SmallIndex;
175 } else if (size == MediumChunk) {
176 return MediumIndex;
177 } else if (size > MediumChunk) {
178 // A valid humongous chunk size is a multiple of the smallest chunk size.
179 assert(is_aligned(size, SpecializedChunk), "Invalid chunk size");
180 return HumongousIndex;
181 }
182 }
183 ShouldNotReachHere();
184 return (ChunkIndex)-1;
185 }
186
187 ChunkIndex next_chunk_index(ChunkIndex i) {
188 assert(i < NumberOfInUseLists, "Out of bound");
189 return (ChunkIndex) (i+1);
190 }
191
192 ChunkIndex prev_chunk_index(ChunkIndex i) {
193 assert(i > ZeroIndex, "Out of bound");
194 return (ChunkIndex) (i-1);
195 }
196
197 const char* loaders_plural(uintx num) {
198 return num == 1 ? "loader" : "loaders";
199 }
200
201 const char* classes_plural(uintx num) {
202 return num == 1 ? "class" : "classes";
203 }
204
205 void print_number_of_classes(outputStream* out, uintx classes, uintx classes_shared) {
206 out->print(UINTX_FORMAT " %s", classes, classes_plural(classes));
207 if (classes_shared > 0) {
208 out->print(" (" UINTX_FORMAT " shared)", classes_shared);
209 }
210 }
211
212 } // namespace metaspace
213
|
113 void print_percentage(outputStream* st, size_t total, size_t part) {
114 if (total == 0) {
115 st->print(" ?%%");
116 } else if (part == 0) {
117 st->print(" 0%%");
118 } else if (part == total) {
119 st->print("100%%");
120 } else {
121 // Note: clearly print very-small-but-not-0% and very-large-but-not-100% percentages.
122 float p = ((float)part / total) * 100.0f;
123 if (p < 1.0f) {
124 st->print(" <1%%");
125 } else if (p > 99.0f){
126 st->print(">99%%");
127 } else {
128 st->print("%3.0f%%", p);
129 }
130 }
131 }
132
133 const char* loaders_plural(uintx num) {
134 return num == 1 ? "loader" : "loaders";
135 }
136
137 const char* classes_plural(uintx num) {
138 return num == 1 ? "class" : "classes";
139 }
140
141 void print_number_of_classes(outputStream* out, uintx classes, uintx classes_shared) {
142 out->print(UINTX_FORMAT " %s", classes, classes_plural(classes));
143 if (classes_shared > 0) {
144 out->print(" (" UINTX_FORMAT " shared)", classes_shared);
145 }
146 }
147
148 } // namespace metaspace
149
|