149 size_t Universe::_heap_capacity_at_last_gc; |
149 size_t Universe::_heap_capacity_at_last_gc; |
150 size_t Universe::_heap_used_at_last_gc = 0; |
150 size_t Universe::_heap_used_at_last_gc = 0; |
151 |
151 |
152 CollectedHeap* Universe::_collectedHeap = NULL; |
152 CollectedHeap* Universe::_collectedHeap = NULL; |
153 |
153 |
154 NarrowOopStruct Universe::_narrow_oop = { NULL, 0, true }; |
154 NarrowPtrStruct Universe::_narrow_oop = { NULL, 0, true }; |
|
155 NarrowPtrStruct Universe::_narrow_klass = { NULL, 0, true }; |
|
156 address Universe::_narrow_ptrs_base; |
155 |
157 |
156 |
158 |
157 void Universe::basic_type_classes_do(void f(Klass*)) { |
159 void Universe::basic_type_classes_do(void f(Klass*)) { |
158 f(boolArrayKlassObj()); |
160 f(boolArrayKlassObj()); |
159 f(byteArrayKlassObj()); |
161 f(byteArrayKlassObj()); |
805 tty->print("heap address: " PTR_FORMAT ", size: " SIZE_FORMAT " MB", |
807 tty->print("heap address: " PTR_FORMAT ", size: " SIZE_FORMAT " MB", |
806 Universe::heap()->base(), Universe::heap()->reserved_region().byte_size()/M); |
808 Universe::heap()->base(), Universe::heap()->reserved_region().byte_size()/M); |
807 } |
809 } |
808 if ((uint64_t)Universe::heap()->reserved_region().end() > OopEncodingHeapMax) { |
810 if ((uint64_t)Universe::heap()->reserved_region().end() > OopEncodingHeapMax) { |
809 // Can't reserve heap below 32Gb. |
811 // Can't reserve heap below 32Gb. |
810 Universe::set_narrow_oop_base(Universe::heap()->base() - os::vm_page_size()); |
812 // keep the Universe::narrow_oop_base() set in Universe::reserve_heap() |
811 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); |
813 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); |
812 if (verbose) { |
814 if (verbose) { |
813 tty->print(", Compressed Oops with base: "PTR_FORMAT, Universe::narrow_oop_base()); |
815 tty->print(", Compressed Oops with base: "PTR_FORMAT, Universe::narrow_oop_base()); |
814 } |
816 } |
815 } else { |
817 } else { |
836 } |
838 } |
837 if (verbose) { |
839 if (verbose) { |
838 tty->cr(); |
840 tty->cr(); |
839 tty->cr(); |
841 tty->cr(); |
840 } |
842 } |
841 } |
843 if (UseCompressedKlassPointers) { |
842 assert(Universe::narrow_oop_base() == (Universe::heap()->base() - os::vm_page_size()) || |
844 Universe::set_narrow_klass_base(Universe::narrow_oop_base()); |
|
845 Universe::set_narrow_klass_shift(MIN2(Universe::narrow_oop_shift(), LogKlassAlignmentInBytes)); |
|
846 } |
|
847 Universe::set_narrow_ptrs_base(Universe::narrow_oop_base()); |
|
848 } |
|
849 // Universe::narrow_oop_base() is one page below the metaspace |
|
850 // base. The actual metaspace base depends on alignment constraints |
|
851 // so we don't know its exact location here. |
|
852 assert((intptr_t)Universe::narrow_oop_base() <= (intptr_t)(Universe::heap()->base() - os::vm_page_size() - ClassMetaspaceSize) || |
843 Universe::narrow_oop_base() == NULL, "invalid value"); |
853 Universe::narrow_oop_base() == NULL, "invalid value"); |
844 assert(Universe::narrow_oop_shift() == LogMinObjAlignmentInBytes || |
854 assert(Universe::narrow_oop_shift() == LogMinObjAlignmentInBytes || |
845 Universe::narrow_oop_shift() == 0, "invalid value"); |
855 Universe::narrow_oop_shift() == 0, "invalid value"); |
846 #endif |
856 #endif |
847 |
857 |
859 |
869 |
860 // Reserve the Java heap, which is now the same for all GCs. |
870 // Reserve the Java heap, which is now the same for all GCs. |
861 ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { |
871 ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { |
862 // Add in the class metaspace area so the classes in the headers can |
872 // Add in the class metaspace area so the classes in the headers can |
863 // be compressed the same as instances. |
873 // be compressed the same as instances. |
864 size_t total_reserved = align_size_up(heap_size + ClassMetaspaceSize, alignment); |
874 // Need to round class space size up because it's below the heap and |
|
875 // the actual alignment depends on its size. |
|
876 size_t metaspace_size = align_size_up(ClassMetaspaceSize, alignment); |
|
877 size_t total_reserved = align_size_up(heap_size + metaspace_size, alignment); |
865 char* addr = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop); |
878 char* addr = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop); |
866 |
879 |
867 ReservedHeapSpace total_rs(total_reserved, alignment, UseLargePages, addr); |
880 ReservedHeapSpace total_rs(total_reserved, alignment, UseLargePages, addr); |
868 |
881 |
869 if (UseCompressedOops) { |
882 if (UseCompressedOops) { |
893 if (!total_rs.is_reserved()) { |
906 if (!total_rs.is_reserved()) { |
894 vm_exit_during_initialization(err_msg("Could not reserve enough space for object heap %d bytes", total_reserved)); |
907 vm_exit_during_initialization(err_msg("Could not reserve enough space for object heap %d bytes", total_reserved)); |
895 return total_rs; |
908 return total_rs; |
896 } |
909 } |
897 |
910 |
898 // Split the reserved space into main Java heap and a space for classes |
911 // Split the reserved space into main Java heap and a space for |
899 // so that they can be compressed using the same algorithm as compressed oops |
912 // classes so that they can be compressed using the same algorithm |
900 ReservedSpace heap_rs = total_rs.first_part(heap_size); |
913 // as compressed oops. If compress oops and compress klass ptrs are |
901 ReservedSpace class_rs = total_rs.last_part(heap_size, alignment); |
914 // used we need the meta space first: if the alignment used for |
|
915 // compressed oops is greater than the one used for compressed klass |
|
916 // ptrs, a metadata space on top of the heap could become |
|
917 // unreachable. |
|
918 ReservedSpace class_rs = total_rs.first_part(metaspace_size); |
|
919 ReservedSpace heap_rs = total_rs.last_part(metaspace_size, alignment); |
902 Metaspace::initialize_class_space(class_rs); |
920 Metaspace::initialize_class_space(class_rs); |
|
921 |
|
922 if (UseCompressedOops) { |
|
923 // Universe::initialize_heap() will reset this to NULL if unscaled |
|
924 // or zero-based narrow oops are actually used. |
|
925 address base = (address)(total_rs.base() - os::vm_page_size()); |
|
926 Universe::set_narrow_oop_base(base); |
|
927 } |
903 return heap_rs; |
928 return heap_rs; |
904 } |
929 } |
905 |
930 |
906 |
931 |
907 // It's the caller's repsonsibility to ensure glitch-freedom |
932 // It's the caller's repsonsibility to ensure glitch-freedom |