--- old/src/share/vm/memory/virtualspace.cpp 2016-06-03 17:55:53.799363600 -0700 +++ new/src/share/vm/memory/virtualspace.cpp 2016-06-03 17:55:53.454367100 -0700 @@ -120,7 +120,9 @@ // If OS doesn't support demand paging for large page memory, we need // to use reserve_memory_special() to reserve and pin the entire region. - bool special = large && !os::can_commit_large_page_memory(); + // If there is a backing file directory for this VirtualSpace then whether largepages are allocated is upto the filesystem the dir resides in. + // So we ignore the UseLargePages flag in this case. + bool special = (_backingFileDir == NULL) && (large && !os::can_commit_large_page_memory()); char* base = NULL; if (special) { @@ -190,6 +192,13 @@ _base = base; _size = size; _alignment = alignment; + + if (_backingFileDir != NULL) { + // At this point a virtual address range is reserved, now map this memory to a file + os::map_memory_to_file(base, size, _backingFileDir); + // mark this virtual space as _special because the physical memory is committed. + _special = true; + } } @@ -313,7 +322,9 @@ // If OS doesn't support demand paging for large page memory, we need // to use reserve_memory_special() to reserve and pin the entire region. - bool special = large && !os::can_commit_large_page_memory(); + // If there is a backing file directory for this VirtualSpace then whether largepages are allocated is upto the filesystem the dir resides in. + // So we ignore the UseLargePages flag in this case. + bool special = (_backingFileDir == NULL) && (large && !os::can_commit_large_page_memory()); char* base = NULL; log_trace(gc, heap, coops)("Trying to allocate at address " PTR_FORMAT @@ -366,6 +377,15 @@ if ((((size_t)base) & (alignment - 1)) != 0) { // Base not aligned, retry. release(); + return; + } + if (_backingFileDir != NULL) { + // At this point a virtual address range is reserved, now map this memory to a file + if (!os::map_memory_to_file(base, size, _backingFileDir)) { + vm_exit_during_initialization(err_msg("Error in mapping object heap at the given filesystem dir %s", _backingFileDir)); + } + // mark this virtual space as _special because the physical memory is committed. + _special = true; } } @@ -556,12 +576,13 @@ } } -ReservedHeapSpace::ReservedHeapSpace(size_t size, size_t alignment, bool large) : ReservedSpace() { +ReservedHeapSpace::ReservedHeapSpace(size_t size, size_t alignment, bool large, const char* backingFSforHeap) : ReservedSpace() { if (size == 0) { return; } + _backingFileDir= backingFSforHeap; // Heap size should be aligned to alignment, too. guarantee(is_size_aligned(size, alignment), "set by caller");