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