< prev index next >

src/hotspot/share/memory/metaspace.cpp

Print this page

 700   // Set MetaspaceSize, MinMetaspaceExpansion and MaxMetaspaceExpansion
 701   if (MetaspaceSize > MaxMetaspaceSize) {
 702     MetaspaceSize = MaxMetaspaceSize;
 703   }
 704 
 705   MetaspaceSize = align_down_bounded(MetaspaceSize, commit_alignment());
 706 
 707   assert(MetaspaceSize <= MaxMetaspaceSize, "MetaspaceSize should be limited by MaxMetaspaceSize");
 708 
 709   MinMetaspaceExpansion = align_down_bounded(MinMetaspaceExpansion, commit_alignment());
 710   MaxMetaspaceExpansion = align_down_bounded(MaxMetaspaceExpansion, commit_alignment());
 711 
 712 }
 713 
 714 void Metaspace::global_initialize() {
 715   MetaspaceGC::initialize(); // <- since we do not prealloc init chunks anymore is this still needed?
 716 
 717   metaspace::ChunkHeaderPool::initialize();
 718 
 719   if (CDSConfig::is_dumping_static_archive()) {
 720     assert(!CDSConfig::is_using_archive(), "sanity");


 721     MetaspaceShared::initialize_for_static_dump();
 722   }
 723 
 724   // If UseCompressedClassPointers=1, we have two cases:
 725   // a) if CDS is active (runtime, Xshare=on), it will create the class space
 726   //    for us, initialize it and set up CompressedKlassPointers encoding.
 727   //    Class space will be reserved above the mapped archives.
 728   // b) if CDS either deactivated (Xshare=off) or a static dump is to be done (Xshare:dump),
 729   //    we will create the class space on our own. It will be placed above the java heap,
 730   //    since we assume it has been placed in low
 731   //    address regions. We may rethink this (see JDK-8244943). Failing that,
 732   //    it will be placed anywhere.
 733 
 734 #if INCLUDE_CDS
 735   // case (a)
 736   if (CDSConfig::is_using_archive()) {
 737     if (!FLAG_IS_DEFAULT(CompressedClassSpaceBaseAddress)) {
 738       log_warning(metaspace)("CDS active - ignoring CompressedClassSpaceBaseAddress.");
 739     }
 740     MetaspaceShared::initialize_runtime_shared_and_meta_spaces();

 880     } else {
 881       assert((is_in_class_space(result) || is_in_nonclass_metaspace(result)) &&
 882              is_aligned(result, Metaspace::min_allocation_alignment_bytes), "Sanity");
 883     }
 884 #endif
 885     // Zero initialize.
 886     Copy::fill_to_words((HeapWord*)result, word_size, 0);
 887     log_trace(metaspace)("Metaspace::allocate: type %d return " PTR_FORMAT ".", (int)type, p2i(result));
 888   }
 889 
 890   return result;
 891 }
 892 
 893 MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
 894                               MetaspaceObj::Type type, bool use_class_space, TRAPS) {
 895 
 896   if (HAS_PENDING_EXCEPTION) {
 897     assert(false, "Should not allocate with exception pending");
 898     return nullptr;  // caller does a CHECK_NULL too
 899   }

 900   assert(!THREAD->owns_locks(), "allocating metaspace while holding mutex");
 901 
 902   MetaWord* result = allocate(loader_data, word_size, type, use_class_space);
 903 
 904   if (result == nullptr) {
 905     MetadataType mdtype = use_class_space ? ClassType : NonClassType;
 906     tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
 907 
 908     // Allocation failed.
 909     if (is_init_completed()) {
 910       // Only start a GC if the bootstrapping has completed.
 911       // Try to clean out some heap memory and retry. This can prevent premature
 912       // expansion of the metaspace.
 913       result = Universe::heap()->satisfy_failed_metadata_allocation(loader_data, word_size, mdtype);
 914     }
 915 
 916     if (result == nullptr) {
 917       report_metadata_oome(loader_data, word_size, type, mdtype, THREAD);
 918       assert(HAS_PENDING_EXCEPTION, "sanity");
 919       return nullptr;

 700   // Set MetaspaceSize, MinMetaspaceExpansion and MaxMetaspaceExpansion
 701   if (MetaspaceSize > MaxMetaspaceSize) {
 702     MetaspaceSize = MaxMetaspaceSize;
 703   }
 704 
 705   MetaspaceSize = align_down_bounded(MetaspaceSize, commit_alignment());
 706 
 707   assert(MetaspaceSize <= MaxMetaspaceSize, "MetaspaceSize should be limited by MaxMetaspaceSize");
 708 
 709   MinMetaspaceExpansion = align_down_bounded(MinMetaspaceExpansion, commit_alignment());
 710   MaxMetaspaceExpansion = align_down_bounded(MaxMetaspaceExpansion, commit_alignment());
 711 
 712 }
 713 
 714 void Metaspace::global_initialize() {
 715   MetaspaceGC::initialize(); // <- since we do not prealloc init chunks anymore is this still needed?
 716 
 717   metaspace::ChunkHeaderPool::initialize();
 718 
 719   if (CDSConfig::is_dumping_static_archive()) {
 720     if (!CDSConfig::is_dumping_final_static_archive()) {
 721       assert(!CDSConfig::is_using_archive(), "sanity");
 722     }
 723     MetaspaceShared::initialize_for_static_dump();
 724   }
 725 
 726   // If UseCompressedClassPointers=1, we have two cases:
 727   // a) if CDS is active (runtime, Xshare=on), it will create the class space
 728   //    for us, initialize it and set up CompressedKlassPointers encoding.
 729   //    Class space will be reserved above the mapped archives.
 730   // b) if CDS either deactivated (Xshare=off) or a static dump is to be done (Xshare:dump),
 731   //    we will create the class space on our own. It will be placed above the java heap,
 732   //    since we assume it has been placed in low
 733   //    address regions. We may rethink this (see JDK-8244943). Failing that,
 734   //    it will be placed anywhere.
 735 
 736 #if INCLUDE_CDS
 737   // case (a)
 738   if (CDSConfig::is_using_archive()) {
 739     if (!FLAG_IS_DEFAULT(CompressedClassSpaceBaseAddress)) {
 740       log_warning(metaspace)("CDS active - ignoring CompressedClassSpaceBaseAddress.");
 741     }
 742     MetaspaceShared::initialize_runtime_shared_and_meta_spaces();

 882     } else {
 883       assert((is_in_class_space(result) || is_in_nonclass_metaspace(result)) &&
 884              is_aligned(result, Metaspace::min_allocation_alignment_bytes), "Sanity");
 885     }
 886 #endif
 887     // Zero initialize.
 888     Copy::fill_to_words((HeapWord*)result, word_size, 0);
 889     log_trace(metaspace)("Metaspace::allocate: type %d return " PTR_FORMAT ".", (int)type, p2i(result));
 890   }
 891 
 892   return result;
 893 }
 894 
 895 MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
 896                               MetaspaceObj::Type type, bool use_class_space, TRAPS) {
 897 
 898   if (HAS_PENDING_EXCEPTION) {
 899     assert(false, "Should not allocate with exception pending");
 900     return nullptr;  // caller does a CHECK_NULL too
 901   }
 902   //leyden/premain: temporarily disabled due to JDK-8327737
 903   assert(!THREAD->owns_locks(), "allocating metaspace while holding mutex");
 904 
 905   MetaWord* result = allocate(loader_data, word_size, type, use_class_space);
 906 
 907   if (result == nullptr) {
 908     MetadataType mdtype = use_class_space ? ClassType : NonClassType;
 909     tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
 910 
 911     // Allocation failed.
 912     if (is_init_completed()) {
 913       // Only start a GC if the bootstrapping has completed.
 914       // Try to clean out some heap memory and retry. This can prevent premature
 915       // expansion of the metaspace.
 916       result = Universe::heap()->satisfy_failed_metadata_allocation(loader_data, word_size, mdtype);
 917     }
 918 
 919     if (result == nullptr) {
 920       report_metadata_oome(loader_data, word_size, type, mdtype, THREAD);
 921       assert(HAS_PENDING_EXCEPTION, "sanity");
 922       return nullptr;
< prev index next >