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