src/share/vm/memory/metaspace.cpp

Print this page
rev 7258 : 8064611: AARCH64: Changes to HotSpot shared code
Summary: Everything except cpu/ and os_cpu/.
Reviewed-by: kvn


3003   address lower_base = MIN2((address)metaspace_base, cds_base);
3004   address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
3005                                 (address)(metaspace_base + compressed_class_space_size()));
3006   return ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax);
3007 }
3008 #endif
3009 
3010 // Try to allocate the metaspace at the requested addr.
3011 void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) {
3012   assert(using_class_space(), "called improperly");
3013   assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
3014   assert(compressed_class_space_size() < KlassEncodingMetaspaceMax,
3015          "Metaspace size is too big");
3016   assert_is_ptr_aligned(requested_addr, _reserve_alignment);
3017   assert_is_ptr_aligned(cds_base, _reserve_alignment);
3018   assert_is_size_aligned(compressed_class_space_size(), _reserve_alignment);
3019 
3020   // Don't use large pages for the class space.
3021   bool large_pages = false;
3022 

3023   ReservedSpace metaspace_rs = ReservedSpace(compressed_class_space_size(),
3024                                              _reserve_alignment,
3025                                              large_pages,
3026                                              requested_addr, 0);












































3027   if (!metaspace_rs.is_reserved()) {
3028 #if INCLUDE_CDS
3029     if (UseSharedSpaces) {
3030       size_t increment = align_size_up(1*G, _reserve_alignment);
3031 
3032       // Keep trying to allocate the metaspace, increasing the requested_addr
3033       // by 1GB each time, until we reach an address that will no longer allow
3034       // use of CDS with compressed klass pointers.
3035       char *addr = requested_addr;
3036       while (!metaspace_rs.is_reserved() && (addr + increment > addr) &&
3037              can_use_cds_with_metaspace_addr(addr + increment, cds_base)) {
3038         addr = addr + increment;
3039         metaspace_rs = ReservedSpace(compressed_class_space_size(),
3040                                      _reserve_alignment, large_pages, addr, 0);
3041       }
3042     }
3043 #endif
3044     // If no successful allocation then try to allocate the space anywhere.  If
3045     // that fails then OOM doom.  At this point we cannot try allocating the
3046     // metaspace as if UseCompressedClassPointers is off because too much




3003   address lower_base = MIN2((address)metaspace_base, cds_base);
3004   address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
3005                                 (address)(metaspace_base + compressed_class_space_size()));
3006   return ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax);
3007 }
3008 #endif
3009 
3010 // Try to allocate the metaspace at the requested addr.
3011 void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) {
3012   assert(using_class_space(), "called improperly");
3013   assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
3014   assert(compressed_class_space_size() < KlassEncodingMetaspaceMax,
3015          "Metaspace size is too big");
3016   assert_is_ptr_aligned(requested_addr, _reserve_alignment);
3017   assert_is_ptr_aligned(cds_base, _reserve_alignment);
3018   assert_is_size_aligned(compressed_class_space_size(), _reserve_alignment);
3019 
3020   // Don't use large pages for the class space.
3021   bool large_pages = false;
3022 
3023 #ifndef AARCH64
3024   ReservedSpace metaspace_rs = ReservedSpace(compressed_class_space_size(),
3025                                              _reserve_alignment,
3026                                              large_pages,
3027                                              requested_addr, 0);
3028 #else // AARCH64
3029   ReservedSpace metaspace_rs;
3030 
3031   // Our compressed klass pointers may fit nicely into the lower 32
3032   // bits.
3033   if ((uint64_t)requested_addr + compressed_class_space_size() < 4*G) {
3034     metaspace_rs = ReservedSpace(compressed_class_space_size(),
3035                                              _reserve_alignment,
3036                                              large_pages,
3037                                              requested_addr, 0);
3038   }
3039 
3040   if (! metaspace_rs.is_reserved()) {
3041     // Try to align metaspace so that we can decode a compressed klass
3042     // with a single MOVK instruction.  We can do this iff the
3043     // compressed class base is a multiple of 4G.
3044     for (char *a = (char*)align_ptr_up(requested_addr, 4*G);
3045          a < (char*)(1024*G);
3046          a += 4*G) {
3047 
3048 #if INCLUDE_CDS
3049       if (UseSharedSpaces
3050           && ! can_use_cds_with_metaspace_addr(a, cds_base)) {
3051         // We failed to find an aligned base that will reach.  Fall
3052         // back to using our requested addr.
3053         metaspace_rs = ReservedSpace(compressed_class_space_size(),
3054                                      _reserve_alignment,
3055                                      large_pages,
3056                                      requested_addr, 0);
3057         break;
3058       }
3059 #endif
3060 
3061       metaspace_rs = ReservedSpace(compressed_class_space_size(),
3062                                    _reserve_alignment,
3063                                    large_pages,
3064                                    a, 0);
3065       if (metaspace_rs.is_reserved())
3066         break;
3067     }
3068   }
3069 
3070 #endif // AARCH64
3071 
3072   if (!metaspace_rs.is_reserved()) {
3073 #if INCLUDE_CDS
3074     if (UseSharedSpaces) {
3075       size_t increment = align_size_up(1*G, _reserve_alignment);
3076 
3077       // Keep trying to allocate the metaspace, increasing the requested_addr
3078       // by 1GB each time, until we reach an address that will no longer allow
3079       // use of CDS with compressed klass pointers.
3080       char *addr = requested_addr;
3081       while (!metaspace_rs.is_reserved() && (addr + increment > addr) &&
3082              can_use_cds_with_metaspace_addr(addr + increment, cds_base)) {
3083         addr = addr + increment;
3084         metaspace_rs = ReservedSpace(compressed_class_space_size(),
3085                                      _reserve_alignment, large_pages, addr, 0);
3086       }
3087     }
3088 #endif
3089     // If no successful allocation then try to allocate the space anywhere.  If
3090     // that fails then OOM doom.  At this point we cannot try allocating the
3091     // metaspace as if UseCompressedClassPointers is off because too much