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

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

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

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