678 // Set MetaspaceSize, MinMetaspaceExpansion and MaxMetaspaceExpansion
679 if (MetaspaceSize > MaxMetaspaceSize) {
680 MetaspaceSize = MaxMetaspaceSize;
681 }
682
683 MetaspaceSize = align_down_bounded(MetaspaceSize, commit_alignment());
684
685 assert(MetaspaceSize <= MaxMetaspaceSize, "MetaspaceSize should be limited by MaxMetaspaceSize");
686
687 MinMetaspaceExpansion = align_down_bounded(MinMetaspaceExpansion, commit_alignment());
688 MaxMetaspaceExpansion = align_down_bounded(MaxMetaspaceExpansion, commit_alignment());
689
690 }
691
692 void Metaspace::global_initialize() {
693 MetaspaceGC::initialize(); // <- since we do not prealloc init chunks anymore is this still needed?
694
695 metaspace::ChunkHeaderPool::initialize();
696
697 if (CDSConfig::is_dumping_static_archive()) {
698 assert(!CDSConfig::is_using_archive(), "sanity");
699 MetaspaceShared::initialize_for_static_dump();
700 }
701
702 // If UseCompressedClassPointers=1, we have two cases:
703 // a) if CDS is active (runtime, Xshare=on), it will create the class space
704 // for us, initialize it and set up CompressedKlassPointers encoding.
705 // Class space will be reserved above the mapped archives.
706 // b) if CDS either deactivated (Xshare=off) or a static dump is to be done (Xshare:dump),
707 // we will create the class space on our own. It will be placed above the java heap,
708 // since we assume it has been placed in low
709 // address regions. We may rethink this (see JDK-8244943). Failing that,
710 // it will be placed anywhere.
711
712 #if INCLUDE_CDS
713 // case (a)
714 if (CDSConfig::is_using_archive()) {
715 if (!FLAG_IS_DEFAULT(CompressedClassSpaceBaseAddress)) {
716 log_warning(metaspace)("CDS active - ignoring CompressedClassSpaceBaseAddress.");
717 }
718 MetaspaceShared::initialize_runtime_shared_and_meta_spaces();
845 // Try to allocate metadata.
846 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
847
848 if (result != nullptr) {
849 // Zero initialize.
850 Copy::fill_to_words((HeapWord*)result, word_size, 0);
851
852 log_trace(metaspace)("Metaspace::allocate: type %d return " PTR_FORMAT ".", (int)type, p2i(result));
853 }
854
855 return result;
856 }
857
858 MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
859 MetaspaceObj::Type type, bool use_class_space, TRAPS) {
860
861 if (HAS_PENDING_EXCEPTION) {
862 assert(false, "Should not allocate with exception pending");
863 return nullptr; // caller does a CHECK_NULL too
864 }
865 assert(!THREAD->owns_locks(), "allocating metaspace while holding mutex");
866
867 MetaWord* result = allocate(loader_data, word_size, type, use_class_space);
868
869 if (result == nullptr) {
870 MetadataType mdtype = use_class_space ? ClassType : NonClassType;
871 tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
872
873 // Allocation failed.
874 if (is_init_completed()) {
875 // Only start a GC if the bootstrapping has completed.
876 // Try to clean out some heap memory and retry. This can prevent premature
877 // expansion of the metaspace.
878 result = Universe::heap()->satisfy_failed_metadata_allocation(loader_data, word_size, mdtype);
879 }
880
881 if (result == nullptr) {
882 report_metadata_oome(loader_data, word_size, type, mdtype, THREAD);
883 assert(HAS_PENDING_EXCEPTION, "sanity");
884 return nullptr;
|
678 // Set MetaspaceSize, MinMetaspaceExpansion and MaxMetaspaceExpansion
679 if (MetaspaceSize > MaxMetaspaceSize) {
680 MetaspaceSize = MaxMetaspaceSize;
681 }
682
683 MetaspaceSize = align_down_bounded(MetaspaceSize, commit_alignment());
684
685 assert(MetaspaceSize <= MaxMetaspaceSize, "MetaspaceSize should be limited by MaxMetaspaceSize");
686
687 MinMetaspaceExpansion = align_down_bounded(MinMetaspaceExpansion, commit_alignment());
688 MaxMetaspaceExpansion = align_down_bounded(MaxMetaspaceExpansion, commit_alignment());
689
690 }
691
692 void Metaspace::global_initialize() {
693 MetaspaceGC::initialize(); // <- since we do not prealloc init chunks anymore is this still needed?
694
695 metaspace::ChunkHeaderPool::initialize();
696
697 if (CDSConfig::is_dumping_static_archive()) {
698 if (!CDSConfig::is_dumping_final_static_archive()) {
699 assert(!CDSConfig::is_using_archive(), "sanity");
700 }
701 MetaspaceShared::initialize_for_static_dump();
702 }
703
704 // If UseCompressedClassPointers=1, we have two cases:
705 // a) if CDS is active (runtime, Xshare=on), it will create the class space
706 // for us, initialize it and set up CompressedKlassPointers encoding.
707 // Class space will be reserved above the mapped archives.
708 // b) if CDS either deactivated (Xshare=off) or a static dump is to be done (Xshare:dump),
709 // we will create the class space on our own. It will be placed above the java heap,
710 // since we assume it has been placed in low
711 // address regions. We may rethink this (see JDK-8244943). Failing that,
712 // it will be placed anywhere.
713
714 #if INCLUDE_CDS
715 // case (a)
716 if (CDSConfig::is_using_archive()) {
717 if (!FLAG_IS_DEFAULT(CompressedClassSpaceBaseAddress)) {
718 log_warning(metaspace)("CDS active - ignoring CompressedClassSpaceBaseAddress.");
719 }
720 MetaspaceShared::initialize_runtime_shared_and_meta_spaces();
847 // Try to allocate metadata.
848 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
849
850 if (result != nullptr) {
851 // Zero initialize.
852 Copy::fill_to_words((HeapWord*)result, word_size, 0);
853
854 log_trace(metaspace)("Metaspace::allocate: type %d return " PTR_FORMAT ".", (int)type, p2i(result));
855 }
856
857 return result;
858 }
859
860 MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
861 MetaspaceObj::Type type, bool use_class_space, TRAPS) {
862
863 if (HAS_PENDING_EXCEPTION) {
864 assert(false, "Should not allocate with exception pending");
865 return nullptr; // caller does a CHECK_NULL too
866 }
867 //leyden/premain: temporarily disabled due to JDK-8327737
868 assert(!THREAD->owns_locks(), "allocating metaspace while holding mutex");
869
870 MetaWord* result = allocate(loader_data, word_size, type, use_class_space);
871
872 if (result == nullptr) {
873 MetadataType mdtype = use_class_space ? ClassType : NonClassType;
874 tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
875
876 // Allocation failed.
877 if (is_init_completed()) {
878 // Only start a GC if the bootstrapping has completed.
879 // Try to clean out some heap memory and retry. This can prevent premature
880 // expansion of the metaspace.
881 result = Universe::heap()->satisfy_failed_metadata_allocation(loader_data, word_size, mdtype);
882 }
883
884 if (result == nullptr) {
885 report_metadata_oome(loader_data, word_size, type, mdtype, THREAD);
886 assert(HAS_PENDING_EXCEPTION, "sanity");
887 return nullptr;
|