Mercurial > hg > graal-compiler
comparison src/share/vm/memory/metaspace.cpp @ 13000:209aa13ab8c0
8024927: Nashorn performance regression with CompressedOops
Summary: Allocate compressed class space at end of Java heap. For small heap sizes, without CDS, save some space so compressed classes can have the same favorable compression as oops
Reviewed-by: stefank, hseigel, goetz
author | coleenp |
---|---|
date | Fri, 25 Oct 2013 15:19:29 -0400 |
parents | a6177f601c64 |
children | b4aa8fc5d0d5 |
comparison
equal
deleted
inserted
replaced
12999:634715d59d9e | 13000:209aa13ab8c0 |
---|---|
54 | 54 |
55 size_t const allocation_from_dictionary_limit = 4 * K; | 55 size_t const allocation_from_dictionary_limit = 4 * K; |
56 | 56 |
57 MetaWord* last_allocated = 0; | 57 MetaWord* last_allocated = 0; |
58 | 58 |
59 size_t Metaspace::_class_metaspace_size; | 59 size_t Metaspace::_compressed_class_space_size; |
60 | 60 |
61 // Used in declarations in SpaceManager and ChunkManager | 61 // Used in declarations in SpaceManager and ChunkManager |
62 enum ChunkIndex { | 62 enum ChunkIndex { |
63 ZeroIndex = 0, | 63 ZeroIndex = 0, |
64 SpecializedIndex = ZeroIndex, | 64 SpecializedIndex = ZeroIndex, |
2797 ChunkManager* Metaspace::_chunk_manager_class = NULL; | 2797 ChunkManager* Metaspace::_chunk_manager_class = NULL; |
2798 | 2798 |
2799 #define VIRTUALSPACEMULTIPLIER 2 | 2799 #define VIRTUALSPACEMULTIPLIER 2 |
2800 | 2800 |
2801 #ifdef _LP64 | 2801 #ifdef _LP64 |
2802 static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1); | |
2803 | |
2802 void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) { | 2804 void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) { |
2803 // Figure out the narrow_klass_base and the narrow_klass_shift. The | 2805 // Figure out the narrow_klass_base and the narrow_klass_shift. The |
2804 // narrow_klass_base is the lower of the metaspace base and the cds base | 2806 // narrow_klass_base is the lower of the metaspace base and the cds base |
2805 // (if cds is enabled). The narrow_klass_shift depends on the distance | 2807 // (if cds is enabled). The narrow_klass_shift depends on the distance |
2806 // between the lower base and higher address. | 2808 // between the lower base and higher address. |
2807 address lower_base; | 2809 address lower_base; |
2808 address higher_address; | 2810 address higher_address; |
2809 if (UseSharedSpaces) { | 2811 if (UseSharedSpaces) { |
2810 higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()), | 2812 higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()), |
2811 (address)(metaspace_base + class_metaspace_size())); | 2813 (address)(metaspace_base + compressed_class_space_size())); |
2812 lower_base = MIN2(metaspace_base, cds_base); | 2814 lower_base = MIN2(metaspace_base, cds_base); |
2813 } else { | 2815 } else { |
2814 higher_address = metaspace_base + class_metaspace_size(); | 2816 higher_address = metaspace_base + compressed_class_space_size(); |
2815 lower_base = metaspace_base; | 2817 lower_base = metaspace_base; |
2816 } | 2818 |
2819 uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes; | |
2820 // If compressed class space fits in lower 32G, we don't need a base. | |
2821 if (higher_address <= (address)klass_encoding_max) { | |
2822 lower_base = 0; // effectively lower base is zero. | |
2823 } | |
2824 } | |
2825 | |
2817 Universe::set_narrow_klass_base(lower_base); | 2826 Universe::set_narrow_klass_base(lower_base); |
2818 if ((uint64_t)(higher_address - lower_base) < (uint64_t)max_juint) { | 2827 |
2828 if ((uint64_t)(higher_address - lower_base) < UnscaledClassSpaceMax) { | |
2819 Universe::set_narrow_klass_shift(0); | 2829 Universe::set_narrow_klass_shift(0); |
2820 } else { | 2830 } else { |
2821 assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces"); | 2831 assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces"); |
2822 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes); | 2832 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes); |
2823 } | 2833 } |
2828 bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base) { | 2838 bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base) { |
2829 assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS"); | 2839 assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS"); |
2830 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs"); | 2840 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs"); |
2831 address lower_base = MIN2((address)metaspace_base, cds_base); | 2841 address lower_base = MIN2((address)metaspace_base, cds_base); |
2832 address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()), | 2842 address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()), |
2833 (address)(metaspace_base + class_metaspace_size())); | 2843 (address)(metaspace_base + compressed_class_space_size())); |
2834 return ((uint64_t)(higher_address - lower_base) < (uint64_t)max_juint); | 2844 return ((uint64_t)(higher_address - lower_base) < UnscaledClassSpaceMax); |
2835 } | 2845 } |
2836 | 2846 |
2837 // Try to allocate the metaspace at the requested addr. | 2847 // Try to allocate the metaspace at the requested addr. |
2838 void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) { | 2848 void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) { |
2839 assert(using_class_space(), "called improperly"); | 2849 assert(using_class_space(), "called improperly"); |
2840 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs"); | 2850 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs"); |
2841 assert(class_metaspace_size() < KlassEncodingMetaspaceMax, | 2851 assert(compressed_class_space_size() < KlassEncodingMetaspaceMax, |
2842 "Metaspace size is too big"); | 2852 "Metaspace size is too big"); |
2843 assert_is_ptr_aligned(requested_addr, _reserve_alignment); | 2853 assert_is_ptr_aligned(requested_addr, _reserve_alignment); |
2844 assert_is_ptr_aligned(cds_base, _reserve_alignment); | 2854 assert_is_ptr_aligned(cds_base, _reserve_alignment); |
2845 assert_is_size_aligned(class_metaspace_size(), _reserve_alignment); | 2855 assert_is_size_aligned(compressed_class_space_size(), _reserve_alignment); |
2846 | 2856 |
2847 // Don't use large pages for the class space. | 2857 // Don't use large pages for the class space. |
2848 bool large_pages = false; | 2858 bool large_pages = false; |
2849 | 2859 |
2850 ReservedSpace metaspace_rs = ReservedSpace(class_metaspace_size(), | 2860 ReservedSpace metaspace_rs = ReservedSpace(compressed_class_space_size(), |
2851 _reserve_alignment, | 2861 _reserve_alignment, |
2852 large_pages, | 2862 large_pages, |
2853 requested_addr, 0); | 2863 requested_addr, 0); |
2854 if (!metaspace_rs.is_reserved()) { | 2864 if (!metaspace_rs.is_reserved()) { |
2855 if (UseSharedSpaces) { | 2865 if (UseSharedSpaces) { |
2860 // use of CDS with compressed klass pointers. | 2870 // use of CDS with compressed klass pointers. |
2861 char *addr = requested_addr; | 2871 char *addr = requested_addr; |
2862 while (!metaspace_rs.is_reserved() && (addr + increment > addr) && | 2872 while (!metaspace_rs.is_reserved() && (addr + increment > addr) && |
2863 can_use_cds_with_metaspace_addr(addr + increment, cds_base)) { | 2873 can_use_cds_with_metaspace_addr(addr + increment, cds_base)) { |
2864 addr = addr + increment; | 2874 addr = addr + increment; |
2865 metaspace_rs = ReservedSpace(class_metaspace_size(), | 2875 metaspace_rs = ReservedSpace(compressed_class_space_size(), |
2866 _reserve_alignment, large_pages, addr, 0); | 2876 _reserve_alignment, large_pages, addr, 0); |
2867 } | 2877 } |
2868 } | 2878 } |
2869 | 2879 |
2870 // If no successful allocation then try to allocate the space anywhere. If | 2880 // If no successful allocation then try to allocate the space anywhere. If |
2871 // that fails then OOM doom. At this point we cannot try allocating the | 2881 // that fails then OOM doom. At this point we cannot try allocating the |
2872 // metaspace as if UseCompressedClassPointers is off because too much | 2882 // metaspace as if UseCompressedClassPointers is off because too much |
2873 // initialization has happened that depends on UseCompressedClassPointers. | 2883 // initialization has happened that depends on UseCompressedClassPointers. |
2874 // So, UseCompressedClassPointers cannot be turned off at this point. | 2884 // So, UseCompressedClassPointers cannot be turned off at this point. |
2875 if (!metaspace_rs.is_reserved()) { | 2885 if (!metaspace_rs.is_reserved()) { |
2876 metaspace_rs = ReservedSpace(class_metaspace_size(), | 2886 metaspace_rs = ReservedSpace(compressed_class_space_size(), |
2877 _reserve_alignment, large_pages); | 2887 _reserve_alignment, large_pages); |
2878 if (!metaspace_rs.is_reserved()) { | 2888 if (!metaspace_rs.is_reserved()) { |
2879 vm_exit_during_initialization(err_msg("Could not allocate metaspace: %d bytes", | 2889 vm_exit_during_initialization(err_msg("Could not allocate metaspace: %d bytes", |
2880 class_metaspace_size())); | 2890 compressed_class_space_size())); |
2881 } | 2891 } |
2882 } | 2892 } |
2883 } | 2893 } |
2884 | 2894 |
2885 // If we got here then the metaspace got allocated. | 2895 // If we got here then the metaspace got allocated. |
2897 initialize_class_space(metaspace_rs); | 2907 initialize_class_space(metaspace_rs); |
2898 | 2908 |
2899 if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) { | 2909 if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) { |
2900 gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: " SIZE_FORMAT, | 2910 gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: " SIZE_FORMAT, |
2901 Universe::narrow_klass_base(), Universe::narrow_klass_shift()); | 2911 Universe::narrow_klass_base(), Universe::narrow_klass_shift()); |
2902 gclog_or_tty->print_cr("Metaspace Size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT, | 2912 gclog_or_tty->print_cr("Compressed class space size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT, |
2903 class_metaspace_size(), metaspace_rs.base(), requested_addr); | 2913 compressed_class_space_size(), metaspace_rs.base(), requested_addr); |
2904 } | 2914 } |
2905 } | 2915 } |
2906 | 2916 |
2907 // For UseCompressedClassPointers the class space is reserved above the top of | 2917 // For UseCompressedClassPointers the class space is reserved above the top of |
2908 // the Java heap. The argument passed in is at the base of the compressed space. | 2918 // the Java heap. The argument passed in is at the base of the compressed space. |
2964 | 2974 |
2965 MinMetaspaceExpansion = restricted_align_down(MinMetaspaceExpansion, _commit_alignment); | 2975 MinMetaspaceExpansion = restricted_align_down(MinMetaspaceExpansion, _commit_alignment); |
2966 MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, _commit_alignment); | 2976 MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, _commit_alignment); |
2967 | 2977 |
2968 CompressedClassSpaceSize = restricted_align_down(CompressedClassSpaceSize, _reserve_alignment); | 2978 CompressedClassSpaceSize = restricted_align_down(CompressedClassSpaceSize, _reserve_alignment); |
2969 set_class_metaspace_size(CompressedClassSpaceSize); | 2979 set_compressed_class_space_size(CompressedClassSpaceSize); |
2970 } | 2980 } |
2971 | 2981 |
2972 void Metaspace::global_initialize() { | 2982 void Metaspace::global_initialize() { |
2973 // Initialize the alignment for shared spaces. | 2983 // Initialize the alignment for shared spaces. |
2974 int max_alignment = os::vm_page_size(); | 2984 int max_alignment = os::vm_page_size(); |
2993 if (!_space_list->initialization_succeeded()) { | 3003 if (!_space_list->initialization_succeeded()) { |
2994 vm_exit_during_initialization("Unable to dump shared archive.", NULL); | 3004 vm_exit_during_initialization("Unable to dump shared archive.", NULL); |
2995 } | 3005 } |
2996 | 3006 |
2997 #ifdef _LP64 | 3007 #ifdef _LP64 |
2998 if (cds_total + class_metaspace_size() > (uint64_t)max_juint) { | 3008 if (cds_total + compressed_class_space_size() > UnscaledClassSpaceMax) { |
2999 vm_exit_during_initialization("Unable to dump shared archive.", | 3009 vm_exit_during_initialization("Unable to dump shared archive.", |
3000 err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space (" | 3010 err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space (" |
3001 SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed " | 3011 SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed " |
3002 "klass limit: " SIZE_FORMAT, cds_total, class_metaspace_size(), | 3012 "klass limit: " SIZE_FORMAT, cds_total, compressed_class_space_size(), |
3003 cds_total + class_metaspace_size(), (size_t)max_juint)); | 3013 cds_total + compressed_class_space_size(), UnscaledClassSpaceMax)); |
3004 } | 3014 } |
3005 | 3015 |
3006 // Set the compressed klass pointer base so that decoding of these pointers works | 3016 // Set the compressed klass pointer base so that decoding of these pointers works |
3007 // properly when creating the shared archive. | 3017 // properly when creating the shared archive. |
3008 assert(UseCompressedOops && UseCompressedClassPointers, | 3018 assert(UseCompressedOops && UseCompressedClassPointers, |
3046 if (UseSharedSpaces) { | 3056 if (UseSharedSpaces) { |
3047 char* cds_end = (char*)(cds_address + cds_total); | 3057 char* cds_end = (char*)(cds_address + cds_total); |
3048 cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment); | 3058 cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment); |
3049 allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address); | 3059 allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address); |
3050 } else { | 3060 } else { |
3051 allocate_metaspace_compressed_klass_ptrs((char *)CompressedKlassPointersBase, 0); | 3061 char* base = (char*)align_ptr_up(Universe::heap()->reserved_region().end(), _reserve_alignment); |
3062 allocate_metaspace_compressed_klass_ptrs(base, 0); | |
3052 } | 3063 } |
3053 } | 3064 } |
3054 #endif | 3065 #endif |
3055 | 3066 |
3056 // Initialize these before initializing the VirtualSpaceList | 3067 // Initialize these before initializing the VirtualSpaceList |