97 |
97 |
98 size_t Universe::_heap_capacity_at_last_gc; |
98 size_t Universe::_heap_capacity_at_last_gc; |
99 size_t Universe::_heap_used_at_last_gc = 0; |
99 size_t Universe::_heap_used_at_last_gc = 0; |
100 |
100 |
101 CollectedHeap* Universe::_collectedHeap = NULL; |
101 CollectedHeap* Universe::_collectedHeap = NULL; |
102 address Universe::_heap_base = NULL; |
102 |
|
103 NarrowOopStruct Universe::_narrow_oop = { NULL, 0, true }; |
103 |
104 |
104 |
105 |
105 void Universe::basic_type_classes_do(void f(klassOop)) { |
106 void Universe::basic_type_classes_do(void f(klassOop)) { |
106 f(boolArrayKlassObj()); |
107 f(boolArrayKlassObj()); |
107 f(byteArrayKlassObj()); |
108 f(byteArrayKlassObj()); |
727 } |
728 } |
728 |
729 |
729 return JNI_OK; |
730 return JNI_OK; |
730 } |
731 } |
731 |
732 |
|
733 // Choose the heap base address and oop encoding mode |
|
734 // when compressed oops are used: |
|
735 // Unscaled - Use 32-bits oops without encoding when |
|
736 // NarrowOopHeapBaseMin + heap_size < 4Gb |
|
737 // ZeroBased - Use zero based compressed oops with encoding when |
|
738 // NarrowOopHeapBaseMin + heap_size < 32Gb |
|
739 // HeapBased - Use compressed oops with heap base + encoding. |
|
740 |
|
741 // 4Gb |
|
742 static const uint64_t NarrowOopHeapMax = (uint64_t(max_juint) + 1); |
|
743 // 32Gb |
|
744 static const uint64_t OopEncodingHeapMax = NarrowOopHeapMax << LogMinObjAlignmentInBytes; |
|
745 |
|
746 char* Universe::preferred_heap_base(size_t heap_size, NARROW_OOP_MODE mode) { |
|
747 #ifdef _LP64 |
|
748 if (UseCompressedOops) { |
|
749 assert(mode == UnscaledNarrowOop || |
|
750 mode == ZeroBasedNarrowOop || |
|
751 mode == HeapBasedNarrowOop, "mode is invalid"); |
|
752 |
|
753 const size_t total_size = heap_size + HeapBaseMinAddress; |
|
754 if (total_size <= OopEncodingHeapMax && (mode != HeapBasedNarrowOop)) { |
|
755 if (total_size <= NarrowOopHeapMax && (mode == UnscaledNarrowOop) && |
|
756 (Universe::narrow_oop_shift() == 0)) { |
|
757 // Use 32-bits oops without encoding and |
|
758 // place heap's top on the 4Gb boundary |
|
759 return (char*)(NarrowOopHeapMax - heap_size); |
|
760 } else { |
|
761 // Can't reserve with NarrowOopShift == 0 |
|
762 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); |
|
763 if (mode == UnscaledNarrowOop || |
|
764 mode == ZeroBasedNarrowOop && total_size <= NarrowOopHeapMax) { |
|
765 // Use zero based compressed oops with encoding and |
|
766 // place heap's top on the 32Gb boundary in case |
|
767 // total_size > 4Gb or failed to reserve below 4Gb. |
|
768 return (char*)(OopEncodingHeapMax - heap_size); |
|
769 } |
|
770 } |
|
771 } else { |
|
772 // Can't reserve below 32Gb. |
|
773 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); |
|
774 } |
|
775 } |
|
776 #endif |
|
777 return NULL; // also return NULL (don't care) for 32-bit VM |
|
778 } |
|
779 |
732 jint Universe::initialize_heap() { |
780 jint Universe::initialize_heap() { |
733 |
781 |
734 if (UseParallelGC) { |
782 if (UseParallelGC) { |
735 #ifndef SERIALGC |
783 #ifndef SERIALGC |
736 Universe::_collectedHeap = new ParallelScavengeHeap(); |
784 Universe::_collectedHeap = new ParallelScavengeHeap(); |
771 |
819 |
772 jint status = Universe::heap()->initialize(); |
820 jint status = Universe::heap()->initialize(); |
773 if (status != JNI_OK) { |
821 if (status != JNI_OK) { |
774 return status; |
822 return status; |
775 } |
823 } |
|
824 |
|
825 #ifdef _LP64 |
776 if (UseCompressedOops) { |
826 if (UseCompressedOops) { |
777 // Subtract a page because something can get allocated at heap base. |
827 // Subtract a page because something can get allocated at heap base. |
778 // This also makes implicit null checking work, because the |
828 // This also makes implicit null checking work, because the |
779 // memory+1 page below heap_base needs to cause a signal. |
829 // memory+1 page below heap_base needs to cause a signal. |
780 // See needs_explicit_null_check. |
830 // See needs_explicit_null_check. |
781 // Only set the heap base for compressed oops because it indicates |
831 // Only set the heap base for compressed oops because it indicates |
782 // compressed oops for pstack code. |
832 // compressed oops for pstack code. |
783 Universe::_heap_base = Universe::heap()->base() - os::vm_page_size(); |
833 if (PrintCompressedOopsMode) { |
784 } |
834 tty->cr(); |
|
835 tty->print("heap address: "PTR_FORMAT, Universe::heap()->base()); |
|
836 } |
|
837 if ((uint64_t)Universe::heap()->reserved_region().end() > OopEncodingHeapMax) { |
|
838 // Can't reserve heap below 32Gb. |
|
839 Universe::set_narrow_oop_base(Universe::heap()->base() - os::vm_page_size()); |
|
840 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); |
|
841 if (PrintCompressedOopsMode) { |
|
842 tty->print(", Compressed Oops with base: "PTR_FORMAT, Universe::narrow_oop_base()); |
|
843 } |
|
844 } else { |
|
845 Universe::set_narrow_oop_base(0); |
|
846 if (PrintCompressedOopsMode) { |
|
847 tty->print(", zero based Compressed Oops"); |
|
848 } |
|
849 #ifdef _WIN64 |
|
850 if (!Universe::narrow_oop_use_implicit_null_checks()) { |
|
851 // Don't need guard page for implicit checks in indexed addressing |
|
852 // mode with zero based Compressed Oops. |
|
853 Universe::set_narrow_oop_use_implicit_null_checks(true); |
|
854 } |
|
855 #endif // _WIN64 |
|
856 if((uint64_t)Universe::heap()->reserved_region().end() > NarrowOopHeapMax) { |
|
857 // Can't reserve heap below 4Gb. |
|
858 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); |
|
859 } else { |
|
860 assert(Universe::narrow_oop_shift() == 0, "use unscaled narrow oop"); |
|
861 if (PrintCompressedOopsMode) { |
|
862 tty->print(", 32-bits Oops"); |
|
863 } |
|
864 } |
|
865 } |
|
866 if (PrintCompressedOopsMode) { |
|
867 tty->cr(); |
|
868 tty->cr(); |
|
869 } |
|
870 } |
|
871 assert(Universe::narrow_oop_base() == (Universe::heap()->base() - os::vm_page_size()) || |
|
872 Universe::narrow_oop_base() == NULL, "invalid value"); |
|
873 assert(Universe::narrow_oop_shift() == LogMinObjAlignmentInBytes || |
|
874 Universe::narrow_oop_shift() == 0, "invalid value"); |
|
875 #endif |
785 |
876 |
786 // We will never reach the CATCH below since Exceptions::_throw will cause |
877 // We will never reach the CATCH below since Exceptions::_throw will cause |
787 // the VM to exit if an exception is thrown during initialization |
878 // the VM to exit if an exception is thrown during initialization |
788 |
879 |
789 if (UseTLAB) { |
880 if (UseTLAB) { |