704 // Set MetaspaceSize, MinMetaspaceExpansion and MaxMetaspaceExpansion
705 if (MetaspaceSize > MaxMetaspaceSize) {
706 MetaspaceSize = MaxMetaspaceSize;
707 }
708
709 MetaspaceSize = align_down_bounded(MetaspaceSize, commit_alignment());
710
711 assert(MetaspaceSize <= MaxMetaspaceSize, "MetaspaceSize should be limited by MaxMetaspaceSize");
712
713 MinMetaspaceExpansion = align_down_bounded(MinMetaspaceExpansion, commit_alignment());
714 MaxMetaspaceExpansion = align_down_bounded(MaxMetaspaceExpansion, commit_alignment());
715
716 }
717
718 void Metaspace::global_initialize() {
719 MetaspaceGC::initialize(); // <- since we do not prealloc init chunks anymore is this still needed?
720
721 metaspace::ChunkHeaderPool::initialize();
722
723 if (CDSConfig::is_dumping_static_archive()) {
724 MetaspaceShared::initialize_for_static_dump();
725 }
726
727 // If UseCompressedClassPointers=1, we have two cases:
728 // a) if CDS is active (runtime, Xshare=on), it will create the class space
729 // for us, initialize it and set up CompressedKlassPointers encoding.
730 // Class space will be reserved above the mapped archives.
731 // b) if CDS either deactivated (Xshare=off) or a static dump is to be done (Xshare:dump),
732 // we will create the class space on our own. It will be placed above the java heap,
733 // since we assume it has been placed in low
734 // address regions. We may rethink this (see JDK-8244943). Failing that,
735 // it will be placed anywhere.
736
737 #if INCLUDE_CDS
738 // case (a)
739 if (CDSConfig::is_using_archive()) {
740 if (!FLAG_IS_DEFAULT(CompressedClassSpaceBaseAddress)) {
741 log_warning(metaspace)("CDS active - ignoring CompressedClassSpaceBaseAddress.");
742 }
743 MetaspaceShared::initialize_runtime_shared_and_meta_spaces();
891 } else {
892 assert((is_in_class_space(result) || is_in_nonclass_metaspace(result)) &&
893 is_aligned(result, Metaspace::min_allocation_alignment_bytes), "Sanity");
894 }
895 #endif
896 // Zero initialize.
897 Copy::fill_to_words((HeapWord*)result, word_size, 0);
898 log_trace(metaspace)("Metaspace::allocate: type %d return " PTR_FORMAT ".", (int)type, p2i(result));
899 }
900
901 return result;
902 }
903
904 MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
905 MetaspaceObj::Type type, bool use_class_space, TRAPS) {
906
907 if (HAS_PENDING_EXCEPTION) {
908 assert(false, "Should not allocate with exception pending");
909 return nullptr; // caller does a CHECK_NULL too
910 }
911 assert(!THREAD->owns_locks(), "allocating metaspace while holding mutex");
912
913 MetaWord* result = allocate(loader_data, word_size, type, use_class_space);
914
915 if (result == nullptr) {
916 MetadataType mdtype = use_class_space ? ClassType : NonClassType;
917 tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
918
919 // Allocation failed.
920 if (is_init_completed()) {
921 // Only start a GC if the bootstrapping has completed.
922 // Try to clean out some heap memory and retry. This can prevent premature
923 // expansion of the metaspace.
924 result = Universe::heap()->satisfy_failed_metadata_allocation(loader_data, word_size, mdtype);
925 }
926
927 if (result == nullptr) {
928 report_metadata_oome(loader_data, word_size, type, mdtype, THREAD);
929 assert(HAS_PENDING_EXCEPTION, "sanity");
930 return nullptr;
|
704 // Set MetaspaceSize, MinMetaspaceExpansion and MaxMetaspaceExpansion
705 if (MetaspaceSize > MaxMetaspaceSize) {
706 MetaspaceSize = MaxMetaspaceSize;
707 }
708
709 MetaspaceSize = align_down_bounded(MetaspaceSize, commit_alignment());
710
711 assert(MetaspaceSize <= MaxMetaspaceSize, "MetaspaceSize should be limited by MaxMetaspaceSize");
712
713 MinMetaspaceExpansion = align_down_bounded(MinMetaspaceExpansion, commit_alignment());
714 MaxMetaspaceExpansion = align_down_bounded(MaxMetaspaceExpansion, commit_alignment());
715
716 }
717
718 void Metaspace::global_initialize() {
719 MetaspaceGC::initialize(); // <- since we do not prealloc init chunks anymore is this still needed?
720
721 metaspace::ChunkHeaderPool::initialize();
722
723 if (CDSConfig::is_dumping_static_archive()) {
724 if (!CDSConfig::is_dumping_final_static_archive()) {
725 assert(!CDSConfig::is_using_archive(), "sanity");
726 }
727 MetaspaceShared::initialize_for_static_dump();
728 }
729
730 // If UseCompressedClassPointers=1, we have two cases:
731 // a) if CDS is active (runtime, Xshare=on), it will create the class space
732 // for us, initialize it and set up CompressedKlassPointers encoding.
733 // Class space will be reserved above the mapped archives.
734 // b) if CDS either deactivated (Xshare=off) or a static dump is to be done (Xshare:dump),
735 // we will create the class space on our own. It will be placed above the java heap,
736 // since we assume it has been placed in low
737 // address regions. We may rethink this (see JDK-8244943). Failing that,
738 // it will be placed anywhere.
739
740 #if INCLUDE_CDS
741 // case (a)
742 if (CDSConfig::is_using_archive()) {
743 if (!FLAG_IS_DEFAULT(CompressedClassSpaceBaseAddress)) {
744 log_warning(metaspace)("CDS active - ignoring CompressedClassSpaceBaseAddress.");
745 }
746 MetaspaceShared::initialize_runtime_shared_and_meta_spaces();
894 } else {
895 assert((is_in_class_space(result) || is_in_nonclass_metaspace(result)) &&
896 is_aligned(result, Metaspace::min_allocation_alignment_bytes), "Sanity");
897 }
898 #endif
899 // Zero initialize.
900 Copy::fill_to_words((HeapWord*)result, word_size, 0);
901 log_trace(metaspace)("Metaspace::allocate: type %d return " PTR_FORMAT ".", (int)type, p2i(result));
902 }
903
904 return result;
905 }
906
907 MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
908 MetaspaceObj::Type type, bool use_class_space, TRAPS) {
909
910 if (HAS_PENDING_EXCEPTION) {
911 assert(false, "Should not allocate with exception pending");
912 return nullptr; // caller does a CHECK_NULL too
913 }
914 //leyden/premain: temporarily disabled due to JDK-8327737
915 assert(!THREAD->owns_locks(), "allocating metaspace while holding mutex");
916
917 MetaWord* result = allocate(loader_data, word_size, type, use_class_space);
918
919 if (result == nullptr) {
920 MetadataType mdtype = use_class_space ? ClassType : NonClassType;
921 tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
922
923 // Allocation failed.
924 if (is_init_completed()) {
925 // Only start a GC if the bootstrapping has completed.
926 // Try to clean out some heap memory and retry. This can prevent premature
927 // expansion of the metaspace.
928 result = Universe::heap()->satisfy_failed_metadata_allocation(loader_data, word_size, mdtype);
929 }
930
931 if (result == nullptr) {
932 report_metadata_oome(loader_data, word_size, type, mdtype, THREAD);
933 assert(HAS_PENDING_EXCEPTION, "sanity");
934 return nullptr;
|