679 // 4Gb |
679 // 4Gb |
680 static const uint64_t NarrowOopHeapMax = (uint64_t(max_juint) + 1); |
680 static const uint64_t NarrowOopHeapMax = (uint64_t(max_juint) + 1); |
681 // 32Gb |
681 // 32Gb |
682 // OopEncodingHeapMax == NarrowOopHeapMax << LogMinObjAlignmentInBytes; |
682 // OopEncodingHeapMax == NarrowOopHeapMax << LogMinObjAlignmentInBytes; |
683 |
683 |
684 char* Universe::preferred_heap_base(size_t heap_size, NARROW_OOP_MODE mode) { |
684 char* Universe::preferred_heap_base(size_t heap_size, size_t alignment, NARROW_OOP_MODE mode) { |
|
685 assert(is_size_aligned((size_t)OopEncodingHeapMax, alignment), "Must be"); |
|
686 assert(is_size_aligned((size_t)NarrowOopHeapMax, alignment), "Must be"); |
|
687 assert(is_size_aligned(heap_size, alignment), "Must be"); |
|
688 |
|
689 uintx heap_base_min_address_aligned = align_size_up(HeapBaseMinAddress, alignment); |
|
690 |
685 size_t base = 0; |
691 size_t base = 0; |
686 #ifdef _LP64 |
692 #ifdef _LP64 |
687 if (UseCompressedOops) { |
693 if (UseCompressedOops) { |
688 assert(mode == UnscaledNarrowOop || |
694 assert(mode == UnscaledNarrowOop || |
689 mode == ZeroBasedNarrowOop || |
695 mode == ZeroBasedNarrowOop || |
690 mode == HeapBasedNarrowOop, "mode is invalid"); |
696 mode == HeapBasedNarrowOop, "mode is invalid"); |
691 const size_t total_size = heap_size + HeapBaseMinAddress; |
697 const size_t total_size = heap_size + heap_base_min_address_aligned; |
692 // Return specified base for the first request. |
698 // Return specified base for the first request. |
693 if (!FLAG_IS_DEFAULT(HeapBaseMinAddress) && (mode == UnscaledNarrowOop)) { |
699 if (!FLAG_IS_DEFAULT(HeapBaseMinAddress) && (mode == UnscaledNarrowOop)) { |
694 base = HeapBaseMinAddress; |
700 base = heap_base_min_address_aligned; |
695 |
701 |
696 // If the total size is small enough to allow UnscaledNarrowOop then |
702 // If the total size is small enough to allow UnscaledNarrowOop then |
697 // just use UnscaledNarrowOop. |
703 // just use UnscaledNarrowOop. |
698 } else if ((total_size <= OopEncodingHeapMax) && (mode != HeapBasedNarrowOop)) { |
704 } else if ((total_size <= OopEncodingHeapMax) && (mode != HeapBasedNarrowOop)) { |
699 if ((total_size <= NarrowOopHeapMax) && (mode == UnscaledNarrowOop) && |
705 if ((total_size <= NarrowOopHeapMax) && (mode == UnscaledNarrowOop) && |
865 // Reserve the Java heap, which is now the same for all GCs. |
873 // Reserve the Java heap, which is now the same for all GCs. |
866 ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { |
874 ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { |
867 size_t total_reserved = align_size_up(heap_size, alignment); |
875 size_t total_reserved = align_size_up(heap_size, alignment); |
868 assert(!UseCompressedOops || (total_reserved <= (OopEncodingHeapMax - os::vm_page_size())), |
876 assert(!UseCompressedOops || (total_reserved <= (OopEncodingHeapMax - os::vm_page_size())), |
869 "heap size is too big for compressed oops"); |
877 "heap size is too big for compressed oops"); |
870 char* addr = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop); |
878 |
871 |
879 bool use_large_pages = UseLargePages && is_size_aligned(alignment, os::large_page_size()); |
872 ReservedHeapSpace total_rs(total_reserved, alignment, UseLargePages, addr); |
880 assert(!UseLargePages |
|
881 || UseParallelOldGC |
|
882 || use_large_pages, "Wrong alignment to use large pages"); |
|
883 |
|
884 char* addr = Universe::preferred_heap_base(total_reserved, alignment, Universe::UnscaledNarrowOop); |
|
885 |
|
886 ReservedHeapSpace total_rs(total_reserved, alignment, use_large_pages, addr); |
873 |
887 |
874 if (UseCompressedOops) { |
888 if (UseCompressedOops) { |
875 if (addr != NULL && !total_rs.is_reserved()) { |
889 if (addr != NULL && !total_rs.is_reserved()) { |
876 // Failed to reserve at specified address - the requested memory |
890 // Failed to reserve at specified address - the requested memory |
877 // region is taken already, for example, by 'java' launcher. |
891 // region is taken already, for example, by 'java' launcher. |
878 // Try again to reserver heap higher. |
892 // Try again to reserver heap higher. |
879 addr = Universe::preferred_heap_base(total_reserved, Universe::ZeroBasedNarrowOop); |
893 addr = Universe::preferred_heap_base(total_reserved, alignment, Universe::ZeroBasedNarrowOop); |
880 |
894 |
881 ReservedHeapSpace total_rs0(total_reserved, alignment, |
895 ReservedHeapSpace total_rs0(total_reserved, alignment, |
882 UseLargePages, addr); |
896 use_large_pages, addr); |
883 |
897 |
884 if (addr != NULL && !total_rs0.is_reserved()) { |
898 if (addr != NULL && !total_rs0.is_reserved()) { |
885 // Failed to reserve at specified address again - give up. |
899 // Failed to reserve at specified address again - give up. |
886 addr = Universe::preferred_heap_base(total_reserved, Universe::HeapBasedNarrowOop); |
900 addr = Universe::preferred_heap_base(total_reserved, alignment, Universe::HeapBasedNarrowOop); |
887 assert(addr == NULL, ""); |
901 assert(addr == NULL, ""); |
888 |
902 |
889 ReservedHeapSpace total_rs1(total_reserved, alignment, |
903 ReservedHeapSpace total_rs1(total_reserved, alignment, |
890 UseLargePages, addr); |
904 use_large_pages, addr); |
891 total_rs = total_rs1; |
905 total_rs = total_rs1; |
892 } else { |
906 } else { |
893 total_rs = total_rs0; |
907 total_rs = total_rs0; |
894 } |
908 } |
895 } |
909 } |