src/share/vm/memory/metaspace.cpp

Print this page
rev 6083 : 8036699: Add trace event when a metaspace allocation fails


3341     Metaspace* space = read_only ? loader_data->ro_metaspace() : loader_data->rw_metaspace();
3342     MetaWord* result = space->allocate(word_size, NonClassType);
3343     if (result == NULL) {
3344       report_out_of_shared_space(read_only ? SharedReadOnly : SharedReadWrite);
3345     }
3346 
3347     space->record_allocation(result, type, space->vsm()->get_raw_word_size(word_size));
3348 
3349     // Zero initialize.
3350     Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
3351 
3352     return result;
3353   }
3354 
3355   MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
3356 
3357   // Try to allocate metadata.
3358   MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
3359 
3360   if (result == NULL) {


3361     // Allocation failed.
3362     if (is_init_completed()) {
3363       // Only start a GC if the bootstrapping has completed.
3364 
3365       // Try to clean out some memory and retry.
3366       result = Universe::heap()->collector_policy()->satisfy_failed_metadata_allocation(
3367           loader_data, word_size, mdtype);
3368     }
3369   }
3370 
3371   if (result == NULL) {
3372     report_metadata_oome(loader_data, word_size, mdtype, CHECK_NULL);
3373   }
3374 
3375   // Zero initialize.
3376   Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
3377 
3378   return result;
3379 }
3380 


3406   // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
3407   const char* space_string = out_of_compressed_class_space ?
3408     "Compressed class space" : "Metaspace";
3409 
3410   report_java_out_of_memory(space_string);
3411 
3412   if (JvmtiExport::should_post_resource_exhausted()) {
3413     JvmtiExport::post_resource_exhausted(
3414         JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
3415         space_string);
3416   }
3417 
3418   if (!is_init_completed()) {
3419     vm_exit_during_initialization("OutOfMemoryError", space_string);
3420   }
3421 
3422   if (out_of_compressed_class_space) {
3423     THROW_OOP(Universe::out_of_memory_error_class_metaspace());
3424   } else {
3425     THROW_OOP(Universe::out_of_memory_error_metaspace());










3426   }
3427 }
3428 
3429 void Metaspace::record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size) {
3430   assert(DumpSharedSpaces, "sanity");
3431 
3432   AllocRecord *rec = new AllocRecord((address)ptr, type, (int)word_size * HeapWordSize);
3433   if (_alloc_record_head == NULL) {
3434     _alloc_record_head = _alloc_record_tail = rec;
3435   } else {
3436     _alloc_record_tail->_next = rec;
3437     _alloc_record_tail = rec;
3438   }
3439 }
3440 
3441 void Metaspace::iterate(Metaspace::AllocRecordClosure *closure) {
3442   assert(DumpSharedSpaces, "unimplemented for !DumpSharedSpaces");
3443 
3444   address last_addr = (address)bottom();
3445 




3341     Metaspace* space = read_only ? loader_data->ro_metaspace() : loader_data->rw_metaspace();
3342     MetaWord* result = space->allocate(word_size, NonClassType);
3343     if (result == NULL) {
3344       report_out_of_shared_space(read_only ? SharedReadOnly : SharedReadWrite);
3345     }
3346 
3347     space->record_allocation(result, type, space->vsm()->get_raw_word_size(word_size));
3348 
3349     // Zero initialize.
3350     Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
3351 
3352     return result;
3353   }
3354 
3355   MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
3356 
3357   // Try to allocate metadata.
3358   MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
3359 
3360   if (result == NULL) {
3361     tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
3362 
3363     // Allocation failed.
3364     if (is_init_completed()) {
3365       // Only start a GC if the bootstrapping has completed.
3366 
3367       // Try to clean out some memory and retry.
3368       result = Universe::heap()->collector_policy()->satisfy_failed_metadata_allocation(
3369           loader_data, word_size, mdtype);
3370     }
3371   }
3372 
3373   if (result == NULL) {
3374     report_metadata_oome(loader_data, word_size, mdtype, CHECK_NULL);
3375   }
3376 
3377   // Zero initialize.
3378   Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
3379 
3380   return result;
3381 }
3382 


3408   // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
3409   const char* space_string = out_of_compressed_class_space ?
3410     "Compressed class space" : "Metaspace";
3411 
3412   report_java_out_of_memory(space_string);
3413 
3414   if (JvmtiExport::should_post_resource_exhausted()) {
3415     JvmtiExport::post_resource_exhausted(
3416         JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
3417         space_string);
3418   }
3419 
3420   if (!is_init_completed()) {
3421     vm_exit_during_initialization("OutOfMemoryError", space_string);
3422   }
3423 
3424   if (out_of_compressed_class_space) {
3425     THROW_OOP(Universe::out_of_memory_error_class_metaspace());
3426   } else {
3427     THROW_OOP(Universe::out_of_memory_error_metaspace());
3428   }
3429 }
3430 
3431 const char* Metaspace::metadata_type_name(Metaspace::MetadataType mdtype) {
3432   switch (mdtype) {
3433     case Metaspace::ClassType: return "Class Type";
3434     case Metaspace::NonClassType: return "Non Class Type";
3435     default:
3436       assert(false, err_msg("Got bad mdtype: %d", (int) mdtype));
3437       return NULL;
3438   }
3439 }
3440 
3441 void Metaspace::record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size) {
3442   assert(DumpSharedSpaces, "sanity");
3443 
3444   AllocRecord *rec = new AllocRecord((address)ptr, type, (int)word_size * HeapWordSize);
3445   if (_alloc_record_head == NULL) {
3446     _alloc_record_head = _alloc_record_tail = rec;
3447   } else {
3448     _alloc_record_tail->_next = rec;
3449     _alloc_record_tail = rec;
3450   }
3451 }
3452 
3453 void Metaspace::iterate(Metaspace::AllocRecordClosure *closure) {
3454   assert(DumpSharedSpaces, "unimplemented for !DumpSharedSpaces");
3455 
3456   address last_addr = (address)bottom();
3457