176
177 private:
178
179 #ifdef _LP64
180 static void set_narrow_klass_base_and_shift(address metaspace_base, address cds_base);
181
182 // Returns true if can use CDS with metaspace allocated as specified address.
183 static bool can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base);
184
185 static void initialize_class_space(ReservedSpace rs);
186 #endif
187
188 public:
189
190 static void ergo_initialize();
191 static void global_initialize();
192 static void post_initialize();
193
194 static void verify_global_initialization();
195
196 static size_t first_chunk_word_size() { return _first_chunk_word_size; }
197 static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; }
198
199 static size_t reserve_alignment() { return _reserve_alignment; }
200 static size_t reserve_alignment_words() { return _reserve_alignment / BytesPerWord; }
201 static size_t commit_alignment() { return _commit_alignment; }
202 static size_t commit_alignment_words() { return _commit_alignment / BytesPerWord; }
203
204 static MetaWord* allocate(ClassLoaderData* loader_data, size_t word_size,
205 MetaspaceObj::Type type, TRAPS);
206
207 static bool contains(const void* ptr);
208 static bool contains_non_shared(const void* ptr);
209
210 // Free empty virtualspaces
211 static void purge(MetadataType mdtype);
212 static void purge();
213
214 static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,
215 MetaspaceObj::Type type, MetadataType mdtype, TRAPS);
216
217 static const char* metadata_type_name(Metaspace::MetadataType mdtype);
218
219 static void print_compressed_class_space(outputStream* st, const char* requested_addr = 0) NOT_LP64({});
220
221 // Return TRUE only if UseCompressedClassPointers is True.
222 static bool using_class_space() {
223 return NOT_LP64(false) LP64_ONLY(UseCompressedClassPointers);
224 }
225
226 static bool is_class_space_allocation(MetadataType mdType) {
227 return mdType == ClassType && using_class_space();
228 }
229
230 static bool initialized() { return _initialized; }
231
232 };
233
234 // Manages the metaspace portion belonging to a class loader
235 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
236 friend class CollectedHeap; // For expand_and_allocate()
237 friend class ZCollectedHeap; // For expand_and_allocate()
238 friend class ShenandoahHeap; // For expand_and_allocate()
239 friend class Metaspace;
240 friend class MetaspaceUtils;
241 friend class metaspace::PrintCLDMetaspaceInfoClosure;
242 friend class VM_CollectForMetadataAllocation; // For expand_and_allocate()
243
244 private:
245
246 void initialize(Mutex* lock, Metaspace::MetaspaceType type);
247
248 // Initialize the first chunk for a Metaspace. Used for
249 // special cases such as the boot class loader, reflection
250 // class loader and anonymous class loader.
251 void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
252 metaspace::Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
253
254 const Metaspace::MetaspaceType _space_type;
255 Mutex* const _lock;
256 metaspace::SpaceManager* _vsm;
257 metaspace::SpaceManager* _class_vsm;
258
259 metaspace::SpaceManager* vsm() const { return _vsm; }
260 metaspace::SpaceManager* class_vsm() const { return _class_vsm; }
261 metaspace::SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) {
262 assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
263 return mdtype == Metaspace::ClassType ? class_vsm() : vsm();
264 }
265
266 Mutex* lock() const { return _lock; }
267
268 MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype);
269
270 size_t class_chunk_size(size_t word_size);
271
272 // Adds to the given statistic object. Must be locked with CLD metaspace lock.
273 void add_to_statistics_locked(metaspace::ClassLoaderMetaspaceStatistics* out) const;
274
275 Metaspace::MetaspaceType space_type() const { return _space_type; }
276
277 public:
278
279 ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType type);
280 ~ClassLoaderMetaspace();
281
282 // Allocate space for metadata of type mdtype. This is space
283 // within a Metachunk and is used by
284 // allocate(ClassLoaderData*, size_t, bool, MetadataType, TRAPS)
285 MetaWord* allocate(size_t word_size, Metaspace::MetadataType mdtype);
286
287 size_t allocated_blocks_bytes() const;
288 size_t allocated_chunks_bytes() const;
289
290 void deallocate(MetaWord* ptr, size_t byte_size, bool is_class);
291
292 void print_on(outputStream* st) const;
293 // Debugging support
294 void verify();
295
296 // Adds to the given statistic object. Will lock with CLD metaspace lock.
297 void add_to_statistics(metaspace::ClassLoaderMetaspaceStatistics* out) const;
298
299 }; // ClassLoaderMetaspace
300
301 class MetaspaceUtils : AllStatic {
302
303 // Spacemanager updates running counters.
304 friend class metaspace::SpaceManager;
305
306 // Special access for error reporting (checks without locks).
307 friend class oopDesc;
308 friend class Klass;
309
310 // Running counters for statistics concerning in-use chunks.
311 // Note: capacity = used + free + waste + overhead. Note that we do not
312 // count free and waste. Their sum can be deduces from the three other values.
313 // For more details, one should call print_report() from within a safe point.
314 static size_t _capacity_words [Metaspace:: MetadataTypeCount];
315 static size_t _overhead_words [Metaspace:: MetadataTypeCount];
316 static volatile size_t _used_words [Metaspace:: MetadataTypeCount];
317
318 // Atomically decrement or increment in-use statistic counters
319 static void dec_capacity(Metaspace::MetadataType mdtype, size_t words);
|
176
177 private:
178
179 #ifdef _LP64
180 static void set_narrow_klass_base_and_shift(address metaspace_base, address cds_base);
181
182 // Returns true if can use CDS with metaspace allocated as specified address.
183 static bool can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base);
184
185 static void initialize_class_space(ReservedSpace rs);
186 #endif
187
188 public:
189
190 static void ergo_initialize();
191 static void global_initialize();
192 static void post_initialize();
193
194 static void verify_global_initialization();
195
196 static size_t reserve_alignment() { return _reserve_alignment; }
197 static size_t reserve_alignment_words() { return _reserve_alignment / BytesPerWord; }
198 static size_t commit_alignment() { return _commit_alignment; }
199 static size_t commit_alignment_words() { return _commit_alignment / BytesPerWord; }
200
201 static MetaWord* allocate(ClassLoaderData* loader_data, size_t word_size,
202 MetaspaceObj::Type type, TRAPS);
203
204 static bool contains(const void* ptr);
205 static bool contains_non_shared(const void* ptr);
206
207 // Free empty virtualspaces
208 static void purge(MetadataType mdtype);
209 static void purge();
210
211 static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,
212 MetaspaceObj::Type type, MetadataType mdtype, TRAPS);
213
214 static const char* metadata_type_name(Metaspace::MetadataType mdtype);
215
216 static void print_compressed_class_space(outputStream* st, const char* requested_addr = 0) NOT_LP64({});
217
218 // Return TRUE only if UseCompressedClassPointers is True.
219 static bool using_class_space() {
220 return NOT_LP64(false) LP64_ONLY(UseCompressedClassPointers);
221 }
222
223 static bool is_class_space_allocation(MetadataType mdType) {
224 return mdType == ClassType && using_class_space();
225 }
226
227 static bool initialized() { return _initialized; }
228
229 };
230
231 class MetaspaceUtils : AllStatic {
232
233 // Spacemanager updates running counters.
234 friend class metaspace::SpaceManager;
235
236 // Special access for error reporting (checks without locks).
237 friend class oopDesc;
238 friend class Klass;
239
240 // Running counters for statistics concerning in-use chunks.
241 // Note: capacity = used + free + waste + overhead. Note that we do not
242 // count free and waste. Their sum can be deduces from the three other values.
243 // For more details, one should call print_report() from within a safe point.
244 static size_t _capacity_words [Metaspace:: MetadataTypeCount];
245 static size_t _overhead_words [Metaspace:: MetadataTypeCount];
246 static volatile size_t _used_words [Metaspace:: MetadataTypeCount];
247
248 // Atomically decrement or increment in-use statistic counters
249 static void dec_capacity(Metaspace::MetadataType mdtype, size_t words);
|