3338 Metaspace* space = read_only ? loader_data->ro_metaspace() : loader_data->rw_metaspace();
3339 MetaWord* result = space->allocate(word_size, NonClassType);
3340 if (result == NULL) {
3341 report_out_of_shared_space(read_only ? SharedReadOnly : SharedReadWrite);
3342 }
3343
3344 space->record_allocation(result, type, space->vsm()->get_raw_word_size(word_size));
3345
3346 // Zero initialize.
3347 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
3348
3349 return result;
3350 }
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 // Allocation failed.
3359 if (is_init_completed()) {
3360 // Only start a GC if the bootstrapping has completed.
3361
3362 // Try to clean out some memory and retry.
3363 result = Universe::heap()->collector_policy()->satisfy_failed_metadata_allocation(
3364 loader_data, word_size, mdtype);
3365 }
3366 }
3367
3368 if (result == NULL) {
3369 report_metadata_oome(loader_data, word_size, mdtype, CHECK_NULL);
3370 }
3371
3372 // Zero initialize.
3373 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
3374
3375 return result;
3376 }
3377
3403 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
3404 const char* space_string = out_of_compressed_class_space ?
3405 "Compressed class space" : "Metaspace";
3406
3407 report_java_out_of_memory(space_string);
3408
3409 if (JvmtiExport::should_post_resource_exhausted()) {
3410 JvmtiExport::post_resource_exhausted(
3411 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
3412 space_string);
3413 }
3414
3415 if (!is_init_completed()) {
3416 vm_exit_during_initialization("OutOfMemoryError", space_string);
3417 }
3418
3419 if (out_of_compressed_class_space) {
3420 THROW_OOP(Universe::out_of_memory_error_class_metaspace());
3421 } else {
3422 THROW_OOP(Universe::out_of_memory_error_metaspace());
3423 }
3424 }
3425
3426 void Metaspace::record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size) {
3427 assert(DumpSharedSpaces, "sanity");
3428
3429 AllocRecord *rec = new AllocRecord((address)ptr, type, (int)word_size * HeapWordSize);
3430 if (_alloc_record_head == NULL) {
3431 _alloc_record_head = _alloc_record_tail = rec;
3432 } else {
3433 _alloc_record_tail->_next = rec;
3434 _alloc_record_tail = rec;
3435 }
3436 }
3437
3438 void Metaspace::iterate(Metaspace::AllocRecordClosure *closure) {
3439 assert(DumpSharedSpaces, "unimplemented for !DumpSharedSpaces");
3440
3441 address last_addr = (address)bottom();
3442
|
3338 Metaspace* space = read_only ? loader_data->ro_metaspace() : loader_data->rw_metaspace();
3339 MetaWord* result = space->allocate(word_size, NonClassType);
3340 if (result == NULL) {
3341 report_out_of_shared_space(read_only ? SharedReadOnly : SharedReadWrite);
3342 }
3343
3344 space->record_allocation(result, type, space->vsm()->get_raw_word_size(word_size));
3345
3346 // Zero initialize.
3347 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
3348
3349 return result;
3350 }
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
3405 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
3406 const char* space_string = out_of_compressed_class_space ?
3407 "Compressed class space" : "Metaspace";
3408
3409 report_java_out_of_memory(space_string);
3410
3411 if (JvmtiExport::should_post_resource_exhausted()) {
3412 JvmtiExport::post_resource_exhausted(
3413 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
3414 space_string);
3415 }
3416
3417 if (!is_init_completed()) {
3418 vm_exit_during_initialization("OutOfMemoryError", space_string);
3419 }
3420
3421 if (out_of_compressed_class_space) {
3422 THROW_OOP(Universe::out_of_memory_error_class_metaspace());
3423 } else {
3424 THROW_OOP(Universe::out_of_memory_error_metaspace());
3425 }
3426 }
3427
3428 const char* Metaspace::metadata_type_name(Metaspace::MetadataType mdtype) {
3429 switch (mdtype) {
3430 case Metaspace::ClassType: return "Class Type";
3431 case Metaspace::NonClassType: return "Non Class Type";
3432 default:
3433 assert(false, err_msg("Got bad mdtype: %d", (int) mdtype));
3434 return NULL;
3435 }
3436 }
3437
3438 void Metaspace::record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size) {
3439 assert(DumpSharedSpaces, "sanity");
3440
3441 AllocRecord *rec = new AllocRecord((address)ptr, type, (int)word_size * HeapWordSize);
3442 if (_alloc_record_head == NULL) {
3443 _alloc_record_head = _alloc_record_tail = rec;
3444 } else {
3445 _alloc_record_tail->_next = rec;
3446 _alloc_record_tail = rec;
3447 }
3448 }
3449
3450 void Metaspace::iterate(Metaspace::AllocRecordClosure *closure) {
3451 assert(DumpSharedSpaces, "unimplemented for !DumpSharedSpaces");
3452
3453 address last_addr = (address)bottom();
3454
|