2377
2378 if (current_chunk() != NULL) {
2379 result = current_chunk()->allocate(word_size);
2380 }
2381
2382 if (result == NULL) {
2383 result = grow_and_allocate(word_size);
2384 }
2385
2386 if (result != NULL) {
2387 inc_used_metrics(word_size);
2388 assert(result != (MetaWord*) chunks_in_use(MediumIndex),
2389 "Head of the list is being allocated");
2390 }
2391
2392 return result;
2393 }
2394
2395 void SpaceManager::verify() {
2396 // If there are blocks in the dictionary, then
2397 // verfication of chunks does not work since
2398 // being in the dictionary alters a chunk.
2399 if (block_freelists()->total_size() == 0) {
2400 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
2401 Metachunk* curr = chunks_in_use(i);
2402 while (curr != NULL) {
2403 curr->verify();
2404 verify_chunk_size(curr);
2405 curr = curr->next();
2406 }
2407 }
2408 }
2409 }
2410
2411 void SpaceManager::verify_chunk_size(Metachunk* chunk) {
2412 assert(is_humongous(chunk->word_size()) ||
2413 chunk->word_size() == medium_chunk_size() ||
2414 chunk->word_size() == small_chunk_size() ||
2415 chunk->word_size() == specialized_chunk_size(),
2416 "Chunk size is wrong");
2417 return;
2846 static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
2847
2848 void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) {
2849 // Figure out the narrow_klass_base and the narrow_klass_shift. The
2850 // narrow_klass_base is the lower of the metaspace base and the cds base
2851 // (if cds is enabled). The narrow_klass_shift depends on the distance
2852 // between the lower base and higher address.
2853 address lower_base;
2854 address higher_address;
2855 if (UseSharedSpaces) {
2856 higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
2857 (address)(metaspace_base + compressed_class_space_size()));
2858 lower_base = MIN2(metaspace_base, cds_base);
2859 } else {
2860 higher_address = metaspace_base + compressed_class_space_size();
2861 lower_base = metaspace_base;
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
2870 Universe::set_narrow_klass_base(lower_base);
2871
2872 if ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax) {
2873 Universe::set_narrow_klass_shift(0);
2874 } else {
2875 assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces");
2876 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
2877 }
2878 }
2879
2880 // Return TRUE if the specified metaspace_base and cds_base are close enough
2881 // to work with compressed klass pointers.
2882 bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base) {
2883 assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS");
2884 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
2885 address lower_base = MIN2((address)metaspace_base, cds_base);
2886 address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
|
2377
2378 if (current_chunk() != NULL) {
2379 result = current_chunk()->allocate(word_size);
2380 }
2381
2382 if (result == NULL) {
2383 result = grow_and_allocate(word_size);
2384 }
2385
2386 if (result != NULL) {
2387 inc_used_metrics(word_size);
2388 assert(result != (MetaWord*) chunks_in_use(MediumIndex),
2389 "Head of the list is being allocated");
2390 }
2391
2392 return result;
2393 }
2394
2395 void SpaceManager::verify() {
2396 // If there are blocks in the dictionary, then
2397 // verification of chunks does not work since
2398 // being in the dictionary alters a chunk.
2399 if (block_freelists()->total_size() == 0) {
2400 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
2401 Metachunk* curr = chunks_in_use(i);
2402 while (curr != NULL) {
2403 curr->verify();
2404 verify_chunk_size(curr);
2405 curr = curr->next();
2406 }
2407 }
2408 }
2409 }
2410
2411 void SpaceManager::verify_chunk_size(Metachunk* chunk) {
2412 assert(is_humongous(chunk->word_size()) ||
2413 chunk->word_size() == medium_chunk_size() ||
2414 chunk->word_size() == small_chunk_size() ||
2415 chunk->word_size() == specialized_chunk_size(),
2416 "Chunk size is wrong");
2417 return;
2846 static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
2847
2848 void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) {
2849 // Figure out the narrow_klass_base and the narrow_klass_shift. The
2850 // narrow_klass_base is the lower of the metaspace base and the cds base
2851 // (if cds is enabled). The narrow_klass_shift depends on the distance
2852 // between the lower base and higher address.
2853 address lower_base;
2854 address higher_address;
2855 if (UseSharedSpaces) {
2856 higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
2857 (address)(metaspace_base + compressed_class_space_size()));
2858 lower_base = MIN2(metaspace_base, cds_base);
2859 } else {
2860 higher_address = metaspace_base + compressed_class_space_size();
2861 lower_base = metaspace_base;
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
2870 Universe::set_narrow_klass_base(lower_base);
2871
2872 if ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax) {
2873 Universe::set_narrow_klass_shift(0);
2874 } else {
2875 assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces");
2876 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
2877 }
2878 }
2879
2880 // Return TRUE if the specified metaspace_base and cds_base are close enough
2881 // to work with compressed klass pointers.
2882 bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base) {
2883 assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS");
2884 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
2885 address lower_base = MIN2((address)metaspace_base, cds_base);
2886 address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
|