src/share/vm/memory/metaspace.cpp

changeset 6086
610be0309a79
parent 6083
3aee6bc29547
parent 6030
b4aa8fc5d0d5
child 6093
11b116661830
equal deleted inserted replaced
6085:8f07aa079343 6086:610be0309a79
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,
2841 ChunkManager* Metaspace::_chunk_manager_class = NULL; 2841 ChunkManager* Metaspace::_chunk_manager_class = NULL;
2842 2842
2843 #define VIRTUALSPACEMULTIPLIER 2 2843 #define VIRTUALSPACEMULTIPLIER 2
2844 2844
2845 #ifdef _LP64 2845 #ifdef _LP64
2846 static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
2847
2846 void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) { 2848 void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) {
2847 // Figure out the narrow_klass_base and the narrow_klass_shift. The 2849 // Figure out the narrow_klass_base and the narrow_klass_shift. The
2848 // narrow_klass_base is the lower of the metaspace base and the cds base 2850 // narrow_klass_base is the lower of the metaspace base and the cds base
2849 // (if cds is enabled). The narrow_klass_shift depends on the distance 2851 // (if cds is enabled). The narrow_klass_shift depends on the distance
2850 // between the lower base and higher address. 2852 // between the lower base and higher address.
2851 address lower_base; 2853 address lower_base;
2852 address higher_address; 2854 address higher_address;
2853 if (UseSharedSpaces) { 2855 if (UseSharedSpaces) {
2854 higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()), 2856 higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
2855 (address)(metaspace_base + class_metaspace_size())); 2857 (address)(metaspace_base + compressed_class_space_size()));
2856 lower_base = MIN2(metaspace_base, cds_base); 2858 lower_base = MIN2(metaspace_base, cds_base);
2857 } else { 2859 } else {
2858 higher_address = metaspace_base + class_metaspace_size(); 2860 higher_address = metaspace_base + compressed_class_space_size();
2859 lower_base = metaspace_base; 2861 lower_base = metaspace_base;
2860 } 2862
2863 uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes;
2864 // If compressed class space fits in lower 32G, we don't need a base.
2865 if (higher_address <= (address)klass_encoding_max) {
2866 lower_base = 0; // effectively lower base is zero.
2867 }
2868 }
2869
2861 Universe::set_narrow_klass_base(lower_base); 2870 Universe::set_narrow_klass_base(lower_base);
2862 if ((uint64_t)(higher_address - lower_base) < (uint64_t)max_juint) { 2871
2872 if ((uint64_t)(higher_address - lower_base) < UnscaledClassSpaceMax) {
2863 Universe::set_narrow_klass_shift(0); 2873 Universe::set_narrow_klass_shift(0);
2864 } else { 2874 } else {
2865 assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces"); 2875 assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces");
2866 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes); 2876 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
2867 } 2877 }
2872 bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base) { 2882 bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base) {
2873 assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS"); 2883 assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS");
2874 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs"); 2884 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
2875 address lower_base = MIN2((address)metaspace_base, cds_base); 2885 address lower_base = MIN2((address)metaspace_base, cds_base);
2876 address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()), 2886 address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
2877 (address)(metaspace_base + class_metaspace_size())); 2887 (address)(metaspace_base + compressed_class_space_size()));
2878 return ((uint64_t)(higher_address - lower_base) < (uint64_t)max_juint); 2888 return ((uint64_t)(higher_address - lower_base) < UnscaledClassSpaceMax);
2879 } 2889 }
2880 2890
2881 // Try to allocate the metaspace at the requested addr. 2891 // Try to allocate the metaspace at the requested addr.
2882 void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) { 2892 void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) {
2883 assert(using_class_space(), "called improperly"); 2893 assert(using_class_space(), "called improperly");
2884 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs"); 2894 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
2885 assert(class_metaspace_size() < KlassEncodingMetaspaceMax, 2895 assert(compressed_class_space_size() < KlassEncodingMetaspaceMax,
2886 "Metaspace size is too big"); 2896 "Metaspace size is too big");
2887 assert_is_ptr_aligned(requested_addr, _reserve_alignment); 2897 assert_is_ptr_aligned(requested_addr, _reserve_alignment);
2888 assert_is_ptr_aligned(cds_base, _reserve_alignment); 2898 assert_is_ptr_aligned(cds_base, _reserve_alignment);
2889 assert_is_size_aligned(class_metaspace_size(), _reserve_alignment); 2899 assert_is_size_aligned(compressed_class_space_size(), _reserve_alignment);
2890 2900
2891 // Don't use large pages for the class space. 2901 // Don't use large pages for the class space.
2892 bool large_pages = false; 2902 bool large_pages = false;
2893 2903
2894 ReservedSpace metaspace_rs = ReservedSpace(class_metaspace_size(), 2904 ReservedSpace metaspace_rs = ReservedSpace(compressed_class_space_size(),
2895 _reserve_alignment, 2905 _reserve_alignment,
2896 large_pages, 2906 large_pages,
2897 requested_addr, 0); 2907 requested_addr, 0);
2898 if (!metaspace_rs.is_reserved()) { 2908 if (!metaspace_rs.is_reserved()) {
2899 if (UseSharedSpaces) { 2909 if (UseSharedSpaces) {
2904 // use of CDS with compressed klass pointers. 2914 // use of CDS with compressed klass pointers.
2905 char *addr = requested_addr; 2915 char *addr = requested_addr;
2906 while (!metaspace_rs.is_reserved() && (addr + increment > addr) && 2916 while (!metaspace_rs.is_reserved() && (addr + increment > addr) &&
2907 can_use_cds_with_metaspace_addr(addr + increment, cds_base)) { 2917 can_use_cds_with_metaspace_addr(addr + increment, cds_base)) {
2908 addr = addr + increment; 2918 addr = addr + increment;
2909 metaspace_rs = ReservedSpace(class_metaspace_size(), 2919 metaspace_rs = ReservedSpace(compressed_class_space_size(),
2910 _reserve_alignment, large_pages, addr, 0); 2920 _reserve_alignment, large_pages, addr, 0);
2911 } 2921 }
2912 } 2922 }
2913 2923
2914 // If no successful allocation then try to allocate the space anywhere. If 2924 // If no successful allocation then try to allocate the space anywhere. If
2915 // that fails then OOM doom. At this point we cannot try allocating the 2925 // that fails then OOM doom. At this point we cannot try allocating the
2916 // metaspace as if UseCompressedClassPointers is off because too much 2926 // metaspace as if UseCompressedClassPointers is off because too much
2917 // initialization has happened that depends on UseCompressedClassPointers. 2927 // initialization has happened that depends on UseCompressedClassPointers.
2918 // So, UseCompressedClassPointers cannot be turned off at this point. 2928 // So, UseCompressedClassPointers cannot be turned off at this point.
2919 if (!metaspace_rs.is_reserved()) { 2929 if (!metaspace_rs.is_reserved()) {
2920 metaspace_rs = ReservedSpace(class_metaspace_size(), 2930 metaspace_rs = ReservedSpace(compressed_class_space_size(),
2921 _reserve_alignment, large_pages); 2931 _reserve_alignment, large_pages);
2922 if (!metaspace_rs.is_reserved()) { 2932 if (!metaspace_rs.is_reserved()) {
2923 vm_exit_during_initialization(err_msg("Could not allocate metaspace: %d bytes", 2933 vm_exit_during_initialization(err_msg("Could not allocate metaspace: %d bytes",
2924 class_metaspace_size())); 2934 compressed_class_space_size()));
2925 } 2935 }
2926 } 2936 }
2927 } 2937 }
2928 2938
2929 // If we got here then the metaspace got allocated. 2939 // If we got here then the metaspace got allocated.
2941 initialize_class_space(metaspace_rs); 2951 initialize_class_space(metaspace_rs);
2942 2952
2943 if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) { 2953 if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) {
2944 gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: " SIZE_FORMAT, 2954 gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: " SIZE_FORMAT,
2945 Universe::narrow_klass_base(), Universe::narrow_klass_shift()); 2955 Universe::narrow_klass_base(), Universe::narrow_klass_shift());
2946 gclog_or_tty->print_cr("Metaspace Size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT, 2956 gclog_or_tty->print_cr("Compressed class space size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT,
2947 class_metaspace_size(), metaspace_rs.base(), requested_addr); 2957 compressed_class_space_size(), metaspace_rs.base(), requested_addr);
2948 } 2958 }
2949 } 2959 }
2950 2960
2951 // For UseCompressedClassPointers the class space is reserved above the top of 2961 // For UseCompressedClassPointers the class space is reserved above the top of
2952 // the Java heap. The argument passed in is at the base of the compressed space. 2962 // the Java heap. The argument passed in is at the base of the compressed space.
3003 3013
3004 MinMetaspaceExpansion = align_size_down_bounded(MinMetaspaceExpansion, _commit_alignment); 3014 MinMetaspaceExpansion = align_size_down_bounded(MinMetaspaceExpansion, _commit_alignment);
3005 MaxMetaspaceExpansion = align_size_down_bounded(MaxMetaspaceExpansion, _commit_alignment); 3015 MaxMetaspaceExpansion = align_size_down_bounded(MaxMetaspaceExpansion, _commit_alignment);
3006 3016
3007 CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment); 3017 CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
3008 set_class_metaspace_size(CompressedClassSpaceSize); 3018 set_compressed_class_space_size(CompressedClassSpaceSize);
3009 } 3019 }
3010 3020
3011 void Metaspace::global_initialize() { 3021 void Metaspace::global_initialize() {
3012 // Initialize the alignment for shared spaces. 3022 // Initialize the alignment for shared spaces.
3013 int max_alignment = os::vm_page_size(); 3023 int max_alignment = os::vm_page_size();
3032 if (!_space_list->initialization_succeeded()) { 3042 if (!_space_list->initialization_succeeded()) {
3033 vm_exit_during_initialization("Unable to dump shared archive.", NULL); 3043 vm_exit_during_initialization("Unable to dump shared archive.", NULL);
3034 } 3044 }
3035 3045
3036 #ifdef _LP64 3046 #ifdef _LP64
3037 if (cds_total + class_metaspace_size() > (uint64_t)max_juint) { 3047 if (cds_total + compressed_class_space_size() > UnscaledClassSpaceMax) {
3038 vm_exit_during_initialization("Unable to dump shared archive.", 3048 vm_exit_during_initialization("Unable to dump shared archive.",
3039 err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space (" 3049 err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space ("
3040 SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed " 3050 SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed "
3041 "klass limit: " SIZE_FORMAT, cds_total, class_metaspace_size(), 3051 "klass limit: " SIZE_FORMAT, cds_total, compressed_class_space_size(),
3042 cds_total + class_metaspace_size(), (size_t)max_juint)); 3052 cds_total + compressed_class_space_size(), UnscaledClassSpaceMax));
3043 } 3053 }
3044 3054
3045 // Set the compressed klass pointer base so that decoding of these pointers works 3055 // Set the compressed klass pointer base so that decoding of these pointers works
3046 // properly when creating the shared archive. 3056 // properly when creating the shared archive.
3047 assert(UseCompressedOops && UseCompressedClassPointers, 3057 assert(UseCompressedOops && UseCompressedClassPointers,
3085 if (UseSharedSpaces) { 3095 if (UseSharedSpaces) {
3086 char* cds_end = (char*)(cds_address + cds_total); 3096 char* cds_end = (char*)(cds_address + cds_total);
3087 cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment); 3097 cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment);
3088 allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address); 3098 allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address);
3089 } else { 3099 } else {
3090 allocate_metaspace_compressed_klass_ptrs((char *)CompressedKlassPointersBase, 0); 3100 char* base = (char*)align_ptr_up(Universe::heap()->reserved_region().end(), _reserve_alignment);
3101 allocate_metaspace_compressed_klass_ptrs(base, 0);
3091 } 3102 }
3092 } 3103 }
3093 #endif 3104 #endif
3094 3105
3095 // Initialize these before initializing the VirtualSpaceList 3106 // Initialize these before initializing the VirtualSpaceList
3347 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0); 3358 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
3348 3359
3349 return result; 3360 return result;
3350 } 3361 }
3351 3362
3363 size_t Metaspace::class_chunk_size(size_t word_size) {
3364 assert(using_class_space(), "Has to use class space");
3365 return class_vsm()->calc_chunk_size(word_size);
3366 }
3367
3352 void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetadataType mdtype, TRAPS) { 3368 void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetadataType mdtype, TRAPS) {
3353 // If result is still null, we are out of memory. 3369 // If result is still null, we are out of memory.
3354 if (Verbose && TraceMetadataChunkAllocation) { 3370 if (Verbose && TraceMetadataChunkAllocation) {
3355 gclog_or_tty->print_cr("Metaspace allocation failed for size " 3371 gclog_or_tty->print_cr("Metaspace allocation failed for size "
3356 SIZE_FORMAT, word_size); 3372 SIZE_FORMAT, word_size);
3358 loader_data->dump(gclog_or_tty); 3374 loader_data->dump(gclog_or_tty);
3359 } 3375 }
3360 MetaspaceAux::dump(gclog_or_tty); 3376 MetaspaceAux::dump(gclog_or_tty);
3361 } 3377 }
3362 3378
3379 bool out_of_compressed_class_space = false;
3380 if (is_class_space_allocation(mdtype)) {
3381 Metaspace* metaspace = loader_data->metaspace_non_null();
3382 out_of_compressed_class_space =
3383 MetaspaceAux::committed_bytes(Metaspace::ClassType) +
3384 (metaspace->class_chunk_size(word_size) * BytesPerWord) >
3385 CompressedClassSpaceSize;
3386 }
3387
3363 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support 3388 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
3364 const char* space_string = is_class_space_allocation(mdtype) ? "Compressed class space" : 3389 const char* space_string = out_of_compressed_class_space ?
3365 "Metadata space"; 3390 "Compressed class space" : "Metaspace";
3391
3366 report_java_out_of_memory(space_string); 3392 report_java_out_of_memory(space_string);
3367 3393
3368 if (JvmtiExport::should_post_resource_exhausted()) { 3394 if (JvmtiExport::should_post_resource_exhausted()) {
3369 JvmtiExport::post_resource_exhausted( 3395 JvmtiExport::post_resource_exhausted(
3370 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR, 3396 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
3373 3399
3374 if (!is_init_completed()) { 3400 if (!is_init_completed()) {
3375 vm_exit_during_initialization("OutOfMemoryError", space_string); 3401 vm_exit_during_initialization("OutOfMemoryError", space_string);
3376 } 3402 }
3377 3403
3378 if (is_class_space_allocation(mdtype)) { 3404 if (out_of_compressed_class_space) {
3379 THROW_OOP(Universe::out_of_memory_error_class_metaspace()); 3405 THROW_OOP(Universe::out_of_memory_error_class_metaspace());
3380 } else { 3406 } else {
3381 THROW_OOP(Universe::out_of_memory_error_metaspace()); 3407 THROW_OOP(Universe::out_of_memory_error_metaspace());
3382 } 3408 }
3383 } 3409 }

mercurial