aboutsummaryrefslogtreecommitdiff
path: root/src/share
diff options
context:
space:
mode:
authorcoleenp <none@none>2013-10-25 15:19:29 -0400
committercoleenp <none@none>2013-10-25 15:19:29 -0400
commit8906b7dc3d05ac00610cfeaf1e8d2b2d0acb2856 (patch)
tree77253ea44eacbff340c9055650529b82a7540d89 /src/share
parente8a807938ef75372d2f2c3315fa304f0d4fc14e5 (diff)
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
Diffstat (limited to 'src/share')
-rw-r--r--src/share/vm/memory/metaspace.cpp53
-rw-r--r--src/share/vm/memory/metaspace.hpp10
-rw-r--r--src/share/vm/memory/universe.cpp38
-rw-r--r--src/share/vm/utilities/globalDefinitions.hpp2
4 files changed, 66 insertions, 37 deletions
diff --git a/src/share/vm/memory/metaspace.cpp b/src/share/vm/memory/metaspace.cpp
index c87ecf81f..ba2806d84 100644
--- a/src/share/vm/memory/metaspace.cpp
+++ b/src/share/vm/memory/metaspace.cpp
@@ -56,7 +56,7 @@ size_t const allocation_from_dictionary_limit = 4 * K;
MetaWord* last_allocated = 0;
-size_t Metaspace::_class_metaspace_size;
+size_t Metaspace::_compressed_class_space_size;
// Used in declarations in SpaceManager and ChunkManager
enum ChunkIndex {
@@ -2799,6 +2799,8 @@ ChunkManager* Metaspace::_chunk_manager_class = NULL;
#define VIRTUALSPACEMULTIPLIER 2
#ifdef _LP64
+static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
+
void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) {
// Figure out the narrow_klass_base and the narrow_klass_shift. The
// narrow_klass_base is the lower of the metaspace base and the cds base
@@ -2808,14 +2810,22 @@ void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address
address higher_address;
if (UseSharedSpaces) {
higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
- (address)(metaspace_base + class_metaspace_size()));
+ (address)(metaspace_base + compressed_class_space_size()));
lower_base = MIN2(metaspace_base, cds_base);
} else {
- higher_address = metaspace_base + class_metaspace_size();
+ higher_address = metaspace_base + compressed_class_space_size();
lower_base = metaspace_base;
+
+ uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes;
+ // If compressed class space fits in lower 32G, we don't need a base.
+ if (higher_address <= (address)klass_encoding_max) {
+ lower_base = 0; // effectively lower base is zero.
+ }
}
+
Universe::set_narrow_klass_base(lower_base);
- if ((uint64_t)(higher_address - lower_base) < (uint64_t)max_juint) {
+
+ if ((uint64_t)(higher_address - lower_base) < UnscaledClassSpaceMax) {
Universe::set_narrow_klass_shift(0);
} else {
assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces");
@@ -2830,24 +2840,24 @@ bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cd
assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
address lower_base = MIN2((address)metaspace_base, cds_base);
address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
- (address)(metaspace_base + class_metaspace_size()));
- return ((uint64_t)(higher_address - lower_base) < (uint64_t)max_juint);
+ (address)(metaspace_base + compressed_class_space_size()));
+ return ((uint64_t)(higher_address - lower_base) < UnscaledClassSpaceMax);
}
// Try to allocate the metaspace at the requested addr.
void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) {
assert(using_class_space(), "called improperly");
assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
- assert(class_metaspace_size() < KlassEncodingMetaspaceMax,
+ assert(compressed_class_space_size() < KlassEncodingMetaspaceMax,
"Metaspace size is too big");
- assert_is_ptr_aligned(requested_addr, _reserve_alignment);
- assert_is_ptr_aligned(cds_base, _reserve_alignment);
- assert_is_size_aligned(class_metaspace_size(), _reserve_alignment);
+ assert_is_ptr_aligned(requested_addr, _reserve_alignment);
+ assert_is_ptr_aligned(cds_base, _reserve_alignment);
+ assert_is_size_aligned(compressed_class_space_size(), _reserve_alignment);
// Don't use large pages for the class space.
bool large_pages = false;
- ReservedSpace metaspace_rs = ReservedSpace(class_metaspace_size(),
+ ReservedSpace metaspace_rs = ReservedSpace(compressed_class_space_size(),
_reserve_alignment,
large_pages,
requested_addr, 0);
@@ -2862,7 +2872,7 @@ void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, a
while (!metaspace_rs.is_reserved() && (addr + increment > addr) &&
can_use_cds_with_metaspace_addr(addr + increment, cds_base)) {
addr = addr + increment;
- metaspace_rs = ReservedSpace(class_metaspace_size(),
+ metaspace_rs = ReservedSpace(compressed_class_space_size(),
_reserve_alignment, large_pages, addr, 0);
}
}
@@ -2873,11 +2883,11 @@ void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, a
// initialization has happened that depends on UseCompressedClassPointers.
// So, UseCompressedClassPointers cannot be turned off at this point.
if (!metaspace_rs.is_reserved()) {
- metaspace_rs = ReservedSpace(class_metaspace_size(),
+ metaspace_rs = ReservedSpace(compressed_class_space_size(),
_reserve_alignment, large_pages);
if (!metaspace_rs.is_reserved()) {
vm_exit_during_initialization(err_msg("Could not allocate metaspace: %d bytes",
- class_metaspace_size()));
+ compressed_class_space_size()));
}
}
}
@@ -2899,8 +2909,8 @@ void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, a
if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) {
gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: " SIZE_FORMAT,
Universe::narrow_klass_base(), Universe::narrow_klass_shift());
- gclog_or_tty->print_cr("Metaspace Size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT,
- class_metaspace_size(), metaspace_rs.base(), requested_addr);
+ gclog_or_tty->print_cr("Compressed class space size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT,
+ compressed_class_space_size(), metaspace_rs.base(), requested_addr);
}
}
@@ -2966,7 +2976,7 @@ void Metaspace::ergo_initialize() {
MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, _commit_alignment);
CompressedClassSpaceSize = restricted_align_down(CompressedClassSpaceSize, _reserve_alignment);
- set_class_metaspace_size(CompressedClassSpaceSize);
+ set_compressed_class_space_size(CompressedClassSpaceSize);
}
void Metaspace::global_initialize() {
@@ -2995,12 +3005,12 @@ void Metaspace::global_initialize() {
}
#ifdef _LP64
- if (cds_total + class_metaspace_size() > (uint64_t)max_juint) {
+ if (cds_total + compressed_class_space_size() > UnscaledClassSpaceMax) {
vm_exit_during_initialization("Unable to dump shared archive.",
err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space ("
SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed "
- "klass limit: " SIZE_FORMAT, cds_total, class_metaspace_size(),
- cds_total + class_metaspace_size(), (size_t)max_juint));
+ "klass limit: " SIZE_FORMAT, cds_total, compressed_class_space_size(),
+ cds_total + compressed_class_space_size(), UnscaledClassSpaceMax));
}
// Set the compressed klass pointer base so that decoding of these pointers works
@@ -3048,7 +3058,8 @@ void Metaspace::global_initialize() {
cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment);
allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address);
} else {
- allocate_metaspace_compressed_klass_ptrs((char *)CompressedKlassPointersBase, 0);
+ char* base = (char*)align_ptr_up(Universe::heap()->reserved_region().end(), _reserve_alignment);
+ allocate_metaspace_compressed_klass_ptrs(base, 0);
}
}
#endif
diff --git a/src/share/vm/memory/metaspace.hpp b/src/share/vm/memory/metaspace.hpp
index 925c2177a..c22d21707 100644
--- a/src/share/vm/memory/metaspace.hpp
+++ b/src/share/vm/memory/metaspace.hpp
@@ -115,13 +115,13 @@ class Metaspace : public CHeapObj<mtClass> {
static size_t align_word_size_up(size_t);
// Aligned size of the metaspace.
- static size_t _class_metaspace_size;
+ static size_t _compressed_class_space_size;
- static size_t class_metaspace_size() {
- return _class_metaspace_size;
+ static size_t compressed_class_space_size() {
+ return _compressed_class_space_size;
}
- static void set_class_metaspace_size(size_t metaspace_size) {
- _class_metaspace_size = metaspace_size;
+ static void set_compressed_class_space_size(size_t size) {
+ _compressed_class_space_size = size;
}
static size_t _first_chunk_word_size;
diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
index 63775ae1d..043962c63 100644
--- a/src/share/vm/memory/universe.cpp
+++ b/src/share/vm/memory/universe.cpp
@@ -677,13 +677,13 @@ jint universe_init() {
// HeapBased - Use compressed oops with heap base + encoding.
// 4Gb
-static const uint64_t NarrowOopHeapMax = (uint64_t(max_juint) + 1);
+static const uint64_t UnscaledOopHeapMax = (uint64_t(max_juint) + 1);
// 32Gb
-// OopEncodingHeapMax == NarrowOopHeapMax << LogMinObjAlignmentInBytes;
+// OopEncodingHeapMax == UnscaledOopHeapMax << LogMinObjAlignmentInBytes;
char* Universe::preferred_heap_base(size_t heap_size, size_t alignment, NARROW_OOP_MODE mode) {
assert(is_size_aligned((size_t)OopEncodingHeapMax, alignment), "Must be");
- assert(is_size_aligned((size_t)NarrowOopHeapMax, alignment), "Must be");
+ assert(is_size_aligned((size_t)UnscaledOopHeapMax, alignment), "Must be");
assert(is_size_aligned(heap_size, alignment), "Must be");
uintx heap_base_min_address_aligned = align_size_up(HeapBaseMinAddress, alignment);
@@ -702,20 +702,40 @@ char* Universe::preferred_heap_base(size_t heap_size, size_t alignment, NARROW_O
// If the total size is small enough to allow UnscaledNarrowOop then
// just use UnscaledNarrowOop.
} else if ((total_size <= OopEncodingHeapMax) && (mode != HeapBasedNarrowOop)) {
- if ((total_size <= NarrowOopHeapMax) && (mode == UnscaledNarrowOop) &&
+ if ((total_size <= UnscaledOopHeapMax) && (mode == UnscaledNarrowOop) &&
(Universe::narrow_oop_shift() == 0)) {
// Use 32-bits oops without encoding and
// place heap's top on the 4Gb boundary
- base = (NarrowOopHeapMax - heap_size);
+ base = (UnscaledOopHeapMax - heap_size);
} else {
// Can't reserve with NarrowOopShift == 0
Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
+
if (mode == UnscaledNarrowOop ||
- mode == ZeroBasedNarrowOop && total_size <= NarrowOopHeapMax) {
+ mode == ZeroBasedNarrowOop && total_size <= UnscaledOopHeapMax) {
+
// Use zero based compressed oops with encoding and
// place heap's top on the 32Gb boundary in case
// total_size > 4Gb or failed to reserve below 4Gb.
- base = (OopEncodingHeapMax - heap_size);
+ uint64_t heap_top = OopEncodingHeapMax;
+
+ // For small heaps, save some space for compressed class pointer
+ // space so it can be decoded with no base.
+ if (UseCompressedClassPointers && !UseSharedSpaces &&
+ OopEncodingHeapMax <= 32*G) {
+
+ uint64_t class_space = align_size_up(CompressedClassSpaceSize, alignment);
+ assert(is_size_aligned((size_t)OopEncodingHeapMax-class_space,
+ alignment), "difference must be aligned too");
+ uint64_t new_top = OopEncodingHeapMax-class_space;
+
+ if (total_size <= new_top) {
+ heap_top = new_top;
+ }
+ }
+
+ // Align base to the adjusted top of the heap
+ base = heap_top - heap_size;
}
}
} else {
@@ -737,7 +757,7 @@ char* Universe::preferred_heap_base(size_t heap_size, size_t alignment, NARROW_O
// Set to a non-NULL value so the ReservedSpace ctor computes
// the correct no-access prefix.
// The final value will be set in initialize_heap() below.
- Universe::set_narrow_oop_base((address)NarrowOopHeapMax);
+ Universe::set_narrow_oop_base((address)UnscaledOopHeapMax);
#ifdef _WIN64
if (UseLargePages) {
// Cannot allocate guard pages for implicit checks in indexed
@@ -833,7 +853,7 @@ jint Universe::initialize_heap() {
Universe::set_narrow_oop_use_implicit_null_checks(true);
}
#endif // _WIN64
- if((uint64_t)Universe::heap()->reserved_region().end() > NarrowOopHeapMax) {
+ if((uint64_t)Universe::heap()->reserved_region().end() > UnscaledOopHeapMax) {
// Can't reserve heap below 4Gb.
Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
} else {
diff --git a/src/share/vm/utilities/globalDefinitions.hpp b/src/share/vm/utilities/globalDefinitions.hpp
index 06a32dc90..7806cdc08 100644
--- a/src/share/vm/utilities/globalDefinitions.hpp
+++ b/src/share/vm/utilities/globalDefinitions.hpp
@@ -368,8 +368,6 @@ const int KlassAlignment = KlassAlignmentInBytes / HeapWordSize;
// Klass encoding metaspace max size
const uint64_t KlassEncodingMetaspaceMax = (uint64_t(max_juint) + 1) << LogKlassAlignmentInBytes;
-const jlong CompressedKlassPointersBase = NOT_LP64(0) LP64_ONLY(CONST64(0x800000000)); // 32*G
-
// Machine dependent stuff
#ifdef TARGET_ARCH_x86