1274 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype); 1275 1276 if (result == NULL) { 1277 tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype); 1278 1279 // Allocation failed. 1280 if (is_init_completed() && !(DumpSharedSpaces && THREAD->is_VM_thread())) { 1281 // Only start a GC if the bootstrapping has completed. 1282 // Also, we cannot GC if we are at the end of the CDS dumping stage which runs inside 1283 // the VM thread. 1284 1285 // Try to clean out some memory and retry. 1286 result = Universe::heap()->satisfy_failed_metadata_allocation(loader_data, word_size, mdtype); 1287 } 1288 } 1289 1290 if (result == NULL) { 1291 if (DumpSharedSpaces) { 1292 // CDS dumping keeps loading classes, so if we hit an OOM we probably will keep hitting OOM. 1293 // We should abort to avoid generating a potentially bad archive. 1294 tty->print_cr("Failed allocating metaspace object type %s of size " SIZE_FORMAT ". CDS dump aborted.", 1295 MetaspaceObj::type_name(type), word_size * BytesPerWord); 1296 tty->print_cr("Please increase MaxMetaspaceSize (currently " SIZE_FORMAT " bytes).", MaxMetaspaceSize); 1297 vm_exit(1); 1298 } 1299 report_metadata_oome(loader_data, word_size, type, mdtype, THREAD); 1300 assert(HAS_PENDING_EXCEPTION, "sanity"); 1301 return NULL; 1302 } 1303 1304 // Zero initialize. 1305 Copy::fill_to_words((HeapWord*)result, word_size, 0); 1306 1307 return result; 1308 } 1309 1310 void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetaspaceObj::Type type, MetadataType mdtype, TRAPS) { 1311 tracer()->report_metadata_oom(loader_data, word_size, type, mdtype); 1312 1313 // If result is still null, we are out of memory. 1314 Log(gc, metaspace, freelist, oom) log; 1315 if (log.is_info()) { 1316 log.info("Metaspace (%s) allocation failed for size " SIZE_FORMAT, | 1274 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype); 1275 1276 if (result == NULL) { 1277 tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype); 1278 1279 // Allocation failed. 1280 if (is_init_completed() && !(DumpSharedSpaces && THREAD->is_VM_thread())) { 1281 // Only start a GC if the bootstrapping has completed. 1282 // Also, we cannot GC if we are at the end of the CDS dumping stage which runs inside 1283 // the VM thread. 1284 1285 // Try to clean out some memory and retry. 1286 result = Universe::heap()->satisfy_failed_metadata_allocation(loader_data, word_size, mdtype); 1287 } 1288 } 1289 1290 if (result == NULL) { 1291 if (DumpSharedSpaces) { 1292 // CDS dumping keeps loading classes, so if we hit an OOM we probably will keep hitting OOM. 1293 // We should abort to avoid generating a potentially bad archive. 1294 log_error(cds)("Failed allocating metaspace object type %s of size " SIZE_FORMAT ". CDS dump aborted.", 1295 MetaspaceObj::type_name(type), word_size * BytesPerWord); 1296 log_error(cds)("Please increase MaxMetaspaceSize (currently " SIZE_FORMAT " bytes).", MaxMetaspaceSize); 1297 vm_exit(1); 1298 } 1299 report_metadata_oome(loader_data, word_size, type, mdtype, THREAD); 1300 assert(HAS_PENDING_EXCEPTION, "sanity"); 1301 return NULL; 1302 } 1303 1304 // Zero initialize. 1305 Copy::fill_to_words((HeapWord*)result, word_size, 0); 1306 1307 return result; 1308 } 1309 1310 void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetaspaceObj::Type type, MetadataType mdtype, TRAPS) { 1311 tracer()->report_metadata_oom(loader_data, word_size, type, mdtype); 1312 1313 // If result is still null, we are out of memory. 1314 Log(gc, metaspace, freelist, oom) log; 1315 if (log.is_info()) { 1316 log.info("Metaspace (%s) allocation failed for size " SIZE_FORMAT, |