< prev index next >

src/hotspot/share/memory/metaspace.cpp

Print this page

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


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

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

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

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

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