diff -r 41ed38406633 src/share/vm/memory/universe.cpp --- a/src/share/vm/memory/universe.cpp Tue Nov 18 10:40:53 2014 +0100 +++ b/src/share/vm/memory/universe.cpp Wed Dec 03 14:27:42 2014 +0100 @@ -760,7 +760,7 @@ } // Tell tests in which mode we run. - Arguments::PropertyList_add(new SystemProperty("com.sap.vm.test.compressedOopsMode", + Arguments::PropertyList_add(new SystemProperty("java.vm.compressedOopsMode", narrow_oop_mode_to_string(narrow_oop_mode()), false)); } diff -r 41ed38406633 src/share/vm/runtime/virtualspace.cpp --- a/src/share/vm/runtime/virtualspace.cpp Tue Nov 18 10:40:53 2014 +0100 +++ b/src/share/vm/runtime/virtualspace.cpp Wed Dec 03 14:27:42 2014 +0100 @@ -259,6 +259,7 @@ _base = NULL; _size = 0; _noaccess_prefix = 0; + _alignment = 0; _special = false; _executable = false; } @@ -331,7 +332,7 @@ } } - if (!base) { + if (base == NULL) { // Failed; try to reserve regular memory below if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) || !FLAG_IS_DEFAULT(LargePageSizeInBytes))) { @@ -355,7 +356,7 @@ base = os::reserve_memory(size, NULL, alignment); } } - if (base == NULL) return; + if (base == NULL) { return; } // Done _base = base; @@ -366,7 +367,29 @@ if ((((size_t)base) & (alignment - 1)) != 0) { // Base not aligned, retry. release(); - return; + } +} + +void ReservedHeapSpace::try_reserve_range(char *const highest_start, char *lowest_start, size_t attach_point_alignment, + char *aligned_HBMA, size_t size, size_t alignment, bool large) { + guarantee(HeapSearchSteps > 0, "Don't set HeapSearchSteps to 0"); + + const size_t attach_range = highest_start - lowest_start; + // Cap num_attempts at possible number. + // At least one is possible even for 0 sized attach range. + const uint64_t num_attempts_possible = (attach_range / attach_point_alignment) + 1; + const uint64_t num_attempts_to_try = MIN2(HeapSearchSteps, num_attempts_possible); + + const size_t stepsize = align_size_up(attach_range / num_attempts_to_try, attach_point_alignment); + + // Try attach points from top to bottom. + char* attach_point = highest_start; + while (attach_point >= lowest_start && + attach_point <= highest_start && // Avoid wrap around. + ((_base != NULL) || + (_base < aligned_HBMA || _base + size > (char *)UnscaledOopHeapMax))) { + try_reserve_heap(size, alignment, large, attach_point); + attach_point -= stepsize; } } @@ -391,9 +414,6 @@ NOT_AIX(os::vm_allocation_granularity()); const size_t attach_point_alignment = lcm(alignment, os_attach_point_alignment); - guarantee(HeapSearchSteps > 0, "Don't set HeapSearchSteps to 0"); - const uint64_t num_attempts = HeapSearchSteps; - char *aligned_HBMA = (char *)align_ptr_up((void *)HeapBaseMinAddress, alignment); size_t noaccess_prefix = ((aligned_HBMA + size) > (char*)OopEncodingHeapMax) ? noaccess_prefix_size(alignment) : 0; @@ -409,7 +429,7 @@ } // Keep heap at HeapBaseMinAddress. - if (!_base) { + if (_base == NULL) { if (PrintCompressedOopsMode && Verbose) { tty->print(" == U N S C A L E D ==\n"); @@ -422,24 +442,8 @@ // Calc address range within we try to attach (range of possible start addresses). char* const highest_start = (char *)align_ptr_down((char *)UnscaledOopHeapMax - size, attach_point_alignment); char* const lowest_start = (char *)align_ptr_up ( aligned_HBMA , attach_point_alignment); - const size_t attach_range = highest_start - lowest_start; - - // Cap num_attempts at possible number. - const uint64_t num_attempts_possible = - (attach_range / attach_point_alignment) + 1; // At least one is possible even for 0 sized attach range. - const uint64_t num_attempts_to_try = MIN2(num_attempts, num_attempts_possible); - - const size_t stepsize = align_size_up(attach_range / num_attempts_to_try, attach_point_alignment); - - // Try attach points from top to bottom. - char* attach_point = highest_start; - while (attach_point >= lowest_start && - attach_point <= highest_start && // Avoid wrap around. - (!_base || _base < aligned_HBMA || _base + size > (char *)UnscaledOopHeapMax)) { - try_reserve_heap(size, alignment, large, attach_point); - attach_point -= stepsize; - } - + try_reserve_range(highest_start, lowest_start, attach_point_alignment, + aligned_HBMA, size, alignment, large); } if (PrintCompressedOopsMode && Verbose) { @@ -460,7 +464,7 @@ // Give it several tries from top of range to bottom. if (aligned_HBMA + size <= zerobased_max && // Zerobased theoretical possible. - (!_base || // No previous try succeeded. + ((_base == NULL) || // No previous try succeeded. (_base && _base + size > zerobased_max))) { // Unscaled delivered an arbitrary address. // Calc address range within we try to attach (range of possible start addresses). @@ -471,24 +475,8 @@ unscaled_end -= size; char *lowest_start = (size < UnscaledOopHeapMax) ? MAX2(unscaled_end, aligned_HBMA) : aligned_HBMA; lowest_start = (char *)align_ptr_up(lowest_start, attach_point_alignment); - const size_t attach_range = highest_start - lowest_start; - - // Cap num_attempts at possible number. - const uint64_t num_attempts_possible = - (attach_range / attach_point_alignment) + 1; // At least one is possible even for 0 sized attach range. - const uint64_t num_attempts_to_try = MIN2(num_attempts, num_attempts_possible); - - const size_t stepsize = align_size_up(attach_range / num_attempts_to_try, attach_point_alignment); - - // Try attach points from top to bottom. - char* attach_point = highest_start; - while (attach_point >= lowest_start && - attach_point <= highest_start && // Avoid wrap around. - (!_base || _base < aligned_HBMA || _base + size > zerobased_max)) { - try_reserve_heap(size, alignment, large, attach_point); - attach_point -= stepsize; - } - + try_reserve_range(highest_start, lowest_start, attach_point_alignment, + aligned_HBMA, size, alignment, large); } if (PrintCompressedOopsMode && Verbose) { @@ -503,7 +491,7 @@ char** addresses = Universe::get_attach_addresses_for_disjoint_mode(); int i = 0; while (addresses[i] && - (!_base || + ((_base == NULL) || (_base && _base + size > (char *)OopEncodingHeapMax && !Universe::is_disjoint_heap_base_address((address)_base)))) { char* const attach_point = addresses[i]; @@ -517,7 +505,7 @@ } // Last, desperate try without any placement. - if (!_base) { + if (_base == NULL) { if (PrintCompressedOopsMode && Verbose) { tty->print("Trying to allocate at address NULL size" PTR_FORMAT ".\n", (address)size); } @@ -525,9 +513,9 @@ } } - assert(!_base || markOopDesc::encode_pointer_as_mark(_base)->decode_pointer() == _base, + assert(_base != NULL || markOopDesc::encode_pointer_as_mark(_base)->decode_pointer() == _base, "area must be distinguishable from marks for mark-sweep"); - assert(!_base || markOopDesc::encode_pointer_as_mark(&_base[size])->decode_pointer() == &_base[size], + assert(_base != NULL || markOopDesc::encode_pointer_as_mark(&_base[size])->decode_pointer() == &_base[size], "area must be distinguishable from marks for mark-sweep"); } diff -r 41ed38406633 src/share/vm/runtime/virtualspace.hpp --- a/src/share/vm/runtime/virtualspace.hpp Tue Nov 18 10:40:53 2014 +0100 +++ b/src/share/vm/runtime/virtualspace.hpp Wed Dec 03 14:27:42 2014 +0100 @@ -100,6 +100,8 @@ class ReservedHeapSpace : public ReservedSpace { private: void try_reserve_heap(size_t size, size_t alignment, bool large, char* requested_address); + void try_reserve_range(char *const highest_start, char *lowest_start, size_t attach_point_alignment, + char *aligned_HBMA, size_t size, size_t alignment, bool large); void initialize_compressed_heap(size_t size, size_t alignment, bool large); public: // Constructor. Tries to find a heap that is good for compressed oops.