3351
3352 MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
3353
3354 // Try to allocate metadata.
3355 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
3356
3357 if (result == NULL) {
3358 tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
3359
3360 // Allocation failed.
3361 if (is_init_completed()) {
3362 // Only start a GC if the bootstrapping has completed.
3363
3364 // Try to clean out some memory and retry.
3365 result = Universe::heap()->collector_policy()->satisfy_failed_metadata_allocation(
3366 loader_data, word_size, mdtype);
3367 }
3368 }
3369
3370 if (result == NULL) {
3371 report_metadata_oome(loader_data, word_size, mdtype, CHECK_NULL);
3372 }
3373
3374 // Zero initialize.
3375 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
3376
3377 return result;
3378 }
3379
3380 size_t Metaspace::class_chunk_size(size_t word_size) {
3381 assert(using_class_space(), "Has to use class space");
3382 return class_vsm()->calc_chunk_size(word_size);
3383 }
3384
3385 void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetadataType mdtype, TRAPS) {
3386 // If result is still null, we are out of memory.
3387 if (Verbose && TraceMetadataChunkAllocation) {
3388 gclog_or_tty->print_cr("Metaspace allocation failed for size "
3389 SIZE_FORMAT, word_size);
3390 if (loader_data->metaspace_or_null() != NULL) {
3391 loader_data->dump(gclog_or_tty);
3392 }
3393 MetaspaceAux::dump(gclog_or_tty);
3394 }
3395
3396 bool out_of_compressed_class_space = false;
3397 if (is_class_space_allocation(mdtype)) {
3398 Metaspace* metaspace = loader_data->metaspace_non_null();
3399 out_of_compressed_class_space =
3400 MetaspaceAux::committed_bytes(Metaspace::ClassType) +
3401 (metaspace->class_chunk_size(word_size) * BytesPerWord) >
3402 CompressedClassSpaceSize;
3403 }
3404
3405 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
|
3351
3352 MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
3353
3354 // Try to allocate metadata.
3355 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
3356
3357 if (result == NULL) {
3358 tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
3359
3360 // Allocation failed.
3361 if (is_init_completed()) {
3362 // Only start a GC if the bootstrapping has completed.
3363
3364 // Try to clean out some memory and retry.
3365 result = Universe::heap()->collector_policy()->satisfy_failed_metadata_allocation(
3366 loader_data, word_size, mdtype);
3367 }
3368 }
3369
3370 if (result == NULL) {
3371 report_metadata_oome(loader_data, word_size, type, mdtype, CHECK_NULL);
3372 }
3373
3374 // Zero initialize.
3375 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
3376
3377 return result;
3378 }
3379
3380 size_t Metaspace::class_chunk_size(size_t word_size) {
3381 assert(using_class_space(), "Has to use class space");
3382 return class_vsm()->calc_chunk_size(word_size);
3383 }
3384
3385 void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetaspaceObj::Type type, MetadataType mdtype, TRAPS) {
3386 tracer()->report_metadata_oom(loader_data, word_size, type, mdtype);
3387
3388 // If result is still null, we are out of memory.
3389 if (Verbose && TraceMetadataChunkAllocation) {
3390 gclog_or_tty->print_cr("Metaspace allocation failed for size "
3391 SIZE_FORMAT, word_size);
3392 if (loader_data->metaspace_or_null() != NULL) {
3393 loader_data->dump(gclog_or_tty);
3394 }
3395 MetaspaceAux::dump(gclog_or_tty);
3396 }
3397
3398 bool out_of_compressed_class_space = false;
3399 if (is_class_space_allocation(mdtype)) {
3400 Metaspace* metaspace = loader_data->metaspace_non_null();
3401 out_of_compressed_class_space =
3402 MetaspaceAux::committed_bytes(Metaspace::ClassType) +
3403 (metaspace->class_chunk_size(word_size) * BytesPerWord) >
3404 CompressedClassSpaceSize;
3405 }
3406
3407 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
|