--- old/src/hotspot/os/aix/os_aix.cpp 2017-10-31 15:49:40.708728521 -0700 +++ new/src/hotspot/os/aix/os_aix.cpp 2017-10-31 15:49:40.483730226 -0700 @@ -2491,9 +2491,25 @@ return false; } +char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { + assert(file_desc >= 0, "file_desc is not valid"); + char* result = NULL; + + // Always round to os::vm_page_size(), which may be larger than 4K. + bytes = align_up(bytes, os::vm_page_size()); + result = reserve_mmaped_memory(bytes, requested_addr, 0); + + if (result != NULL) { + if (replace_existing_mapping_with_dax_file_mapping(result, bytes, file_desc) == NULL) { + vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory")); + } + } + return result; +} + // Reserve memory at an arbitrary address, only if that area is // available (and not reserved for something else). -char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, bool use_SHM) { +char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { char* addr = NULL; // Always round to os::vm_page_size(), which may be larger than 4K. @@ -2504,7 +2520,7 @@ if (os::vm_page_size() == 4*K) { return reserve_mmaped_memory(bytes, requested_addr, 0); } else { - if (use_SHM && bytes >= Use64KPagesThreshold) { + if (bytes >= Use64KPagesThreshold) { return reserve_shmated_memory(bytes, requested_addr, 0); } else { return reserve_mmaped_memory(bytes, requested_addr, 0); --- old/src/hotspot/os/bsd/os_bsd.cpp 2017-10-31 15:49:41.234724534 -0700 +++ new/src/hotspot/os/bsd/os_bsd.cpp 2017-10-31 15:49:40.971726528 -0700 @@ -2351,6 +2351,17 @@ return UseHugeTLBFS; } +char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { + assert(file_desc >= 0, "file_desc is not valid"); + char* result = pd_attempt_reserve_memory_at(bytes, requested_addr); + if (result != NULL) { + if (replace_existing_mapping_with_dax_file_mapping(result, bytes, file_desc) == NULL) { + vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory")); + } + } + return result; +} + // Reserve memory at an arbitrary address, only if that area is // available (and not reserved for something else). --- old/src/hotspot/os/linux/os_linux.cpp 2017-10-31 15:49:41.806720200 -0700 +++ new/src/hotspot/os/linux/os_linux.cpp 2017-10-31 15:49:41.588721852 -0700 @@ -3791,6 +3791,17 @@ return UseTransparentHugePages || UseHugeTLBFS; } +char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { + assert(file_desc >= 0, "file_desc is not valid"); + char* result = pd_attempt_reserve_memory_at(bytes, requested_addr); + if (result != NULL) { + if (replace_existing_mapping_with_dax_file_mapping(result, bytes, file_desc) == NULL) { + vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory")); + } + } + return result; +} + // Reserve memory at an arbitrary address, only if that area is // available (and not reserved for something else). --- old/src/hotspot/os/posix/os_posix.cpp 2017-10-31 15:49:42.420715547 -0700 +++ new/src/hotspot/os/posix/os_posix.cpp 2017-10-31 15:49:42.150717592 -0700 @@ -53,6 +53,10 @@ #endif #define IS_VALID_PID(p) (p > 0 && p < MAX_PID) +#ifndef MAP_ANONYMOUS + #define MAP_ANONYMOUS MAP_ANON +#endif + #define check_with_errno(check_type, cond, msg) \ do { \ int err = errno; \ @@ -174,10 +178,6 @@ int ret = sigfillset(&set); assert_with_errno(ret == 0, "sigfillset returned error"); - // block all signals while we do the file operation. - ret = pthread_sigmask(SIG_BLOCK, &set, &oldset); - assert_with_errno(ret == 0, "pthread_sigmask returned error"); - // set the file creation mask. mode_t file_mode = S_IRUSR | S_IWUSR; @@ -185,10 +185,7 @@ int fd = mkstemp(fullname); if (fd < 0) { - // reset the signal mask. - ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL); - assert_with_errno(ret == 0, "pthread_sigmask returned error"); - warning("Could not create file for heap"); + warning("Could not create file for heap with template %s", fullname); os::free(fullname); return -1; } @@ -197,10 +194,6 @@ ret = unlink(fullname); assert_with_errno(ret == 0, "unlink returned error"); - // reset the signal mask. - ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL); - assert_with_errno(ret == 0, "pthread_sigmask returned error"); - os::free(fullname); return fd; } @@ -281,31 +274,6 @@ return map_memory_to_dax_file(base, size, fd); } -char* os::attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc) { - - // We would want to use the complex logic in pd_attempt_reserve_memory_at(), especially in Linux. - // So we call pd_attempt_reserve_memory_at() to purely reserve memory - // and then replace the anonymous mapping with file mapping. - // Unfortunately for AIX, we need to pass new bool parameter to pd_attempt_reserve_memory_at() - // to indicate not to use SHM -#if defined(AIX) - char* result = pd_attempt_reserve_memory_at(bytes, addr, file_desc == -1 /*use_SHM*/); -#else - char* result = pd_attempt_reserve_memory_at(bytes, addr); -#endif - if (result != NULL) { - if (file_desc != -1) { - if (replace_existing_mapping_with_dax_file_mapping(result, bytes, file_desc) == NULL) { - vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory")); - } - MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, CALLER_PC); - } else { - MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); - } - } - return result; -} - // Multiple threads can race in this code, and can remap over each other with MAP_FIXED, // so on posix, unmap the section at the start and at the end of the chunk that we mapped // rather than unmapping and remapping the whole chunk to get requested alignment. --- old/src/hotspot/os/solaris/os_solaris.cpp 2017-10-31 15:49:42.996711181 -0700 +++ new/src/hotspot/os/solaris/os_solaris.cpp 2017-10-31 15:49:42.726713227 -0700 @@ -2582,6 +2582,17 @@ return addr; } +char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { + assert(file_desc >= 0, "file_desc is not valid"); + char* result = pd_attempt_reserve_memory_at(bytes, requested_addr); + if (result != NULL) { + if (replace_existing_mapping_with_dax_file_mapping(result, bytes, file_desc) == NULL) { + vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory")); + } + } + return result; +} + // Reserve memory at an arbitrary address, only if that area is // available (and not reserved for something else). --- old/src/hotspot/os/windows/os_windows.cpp 2017-10-31 15:49:43.545707021 -0700 +++ new/src/hotspot/os/windows/os_windows.cpp 2017-10-31 15:49:43.280709029 -0700 @@ -2892,13 +2892,13 @@ } (void)strncpy(fullname, dir, strlen(dir)+1); - (void)strncat(fullname, name_template, strlen(name_template); + (void)strncat(fullname, name_template, strlen(name_template)); os::native_path(fullname); char *path = _mktemp(fullname); if (path == NULL) { - warning("_mktemp could not create file name from template (%s)", os::strerror(errno)); + warning("_mktemp could not create file name from template %s (%s)", fullname, os::strerror(errno)); os::free(fullname); return -1; } @@ -2946,22 +2946,6 @@ return map_memory_to_dax_file(base, size, fd); } -char* os::attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc) { - char* result = NULL; - if (file_desc != -1) { - result = map_memory_to_dax_file(addr, bytes, file_desc); - if (result != NULL) { - MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, CALLER_PC); - } - } else { - result = pd_attempt_reserve_memory_at(bytes, addr); - if (result != NULL) { - MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); - } - } - return result; -} - // On win32, one cannot release just a part of reserved memory, it's an // all or nothing deal. When we split a reservation, we must break the // reservation into two reservations. @@ -3051,6 +3035,11 @@ return reserve_memory(bytes, requested_addr); } +char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { + assert(file_desc >= 0, "file_desc is not valid"); + return map_memory_to_dax_file(requested_addr, bytes, file_desc); +} + size_t os::large_page_size() { return _large_page_size; } --- old/src/hotspot/share/memory/virtualspace.cpp 2017-10-31 15:49:44.219701913 -0700 +++ new/src/hotspot/share/memory/virtualspace.cpp 2017-10-31 15:49:43.969703807 -0700 @@ -69,9 +69,8 @@ initialize(size, alignment, large, NULL, executable); } -//Healper method - -static void unmap_or_release_memory(const char* base, size_t size, bool is_file_mapped) { +// Helper method +static void unmap_or_release_memory(char* base, size_t size, bool is_file_mapped) { if (is_file_mapped) { if (!os::unmap_memory(base, size)) { fatal("os::unmap_memory failed"); --- old/src/hotspot/share/runtime/arguments.cpp 2017-10-31 15:49:44.775697699 -0700 +++ new/src/hotspot/share/runtime/arguments.cpp 2017-10-31 15:49:44.551699397 -0700 @@ -2533,6 +2533,11 @@ FLAG_SET_CMDLINE(bool, PostLoopMultiversioning, false); } #endif + if (!FLAG_IS_DEFAULT(AllocateHeapAt)) { + if (!FLAG_IS_DEFAULT(UseNUMAInterleaving) || !FLAG_IS_DEFAULT(UseNUMA)) { + log_warning(arguments) ("NUMA support for Heap depends on the file system when AllocateHeapAt option is used.\n"); + } + } return status; } @@ -3721,12 +3726,6 @@ return JNI_ERR; } - if (!FLAG_IS_DEFAULT(AllocateHeapAt)) { - if (!FLAG_IS_DEFAULT(UseNUMAInterleaving) || !FLAG_IS_DEFAULT(UseNUMA)) { - log_warning(arguments) ("NUMA support for Heap depends on the file system when AllocateHeapAt option is used.\n"); - } - } - #if INCLUDE_JVMCI if (UseJVMCICompiler) { Compilation_mode = CompMode_server; --- old/src/hotspot/share/runtime/os.cpp 2017-10-31 15:49:45.386693069 -0700 +++ new/src/hotspot/share/runtime/os.cpp 2017-10-31 15:49:45.110695160 -0700 @@ -1705,6 +1705,22 @@ return result; } +char* os::attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc) { + char* result = NULL; + if (file_desc != -1) { + result = pd_attempt_reserve_memory_at(bytes, addr, file_desc); + if (result != NULL) { + MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, CALLER_PC); + } + } else { + result = pd_attempt_reserve_memory_at(bytes, addr); + if (result != NULL) { + MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, CALLER_PC); + } + } + return result; +} + void os::split_reserved_memory(char *base, size_t size, size_t split, bool realloc) { pd_split_reserved_memory(base, size, split, realloc); --- old/src/hotspot/share/runtime/os.hpp 2017-10-31 15:49:45.965688681 -0700 +++ new/src/hotspot/share/runtime/os.hpp 2017-10-31 15:49:45.690690765 -0700 @@ -109,11 +109,8 @@ static char* pd_reserve_memory(size_t bytes, char* addr = 0, size_t alignment_hint = 0); -#if defined(AIX) - static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr, bool use_SHM = true); -#else static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr); -#endif + static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc); static void pd_split_reserved_memory(char *base, size_t size, size_t split, bool realloc); static bool pd_commit_memory(char* addr, size_t bytes, bool executable); --- old/test/hotspot/jtreg/gc/TestAllocateHeapAt.java 2017-10-31 15:49:46.541684316 -0700 +++ new/test/hotspot/jtreg/gc/TestAllocateHeapAt.java 2017-10-31 15:49:46.279686301 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, xxx Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,6 @@ /* @test TestAllocateHeapAt.java * @key gc - * @bug 8171181 * @summary Test to check allocation of Java Heap with AllocateHeapAt option * @library /test/lib * @modules java.base/jdk.internal.misc @@ -44,11 +43,11 @@ String[] testVmOpts = testVmOptsStr.split(" "); Collections.addAll(vmOpts, testVmOpts); } - String test_dir = System.getProperty("test.dir", "."); - Collections.addAll(vmOpts, new String[] {"-XX:AllocateHeapAt=\""+test_dir+"\"", - "-Xlog:gc+heap+coops=info", - "-Xmx200m", - "-Xms200m", + String test_dir = System.getProperty("test.dir", "."); + Collections.addAll(vmOpts, new String[] {"-XX:AllocateHeapAt="+test_dir, + "-Xlog:gc+heap=info", + "-Xmx50m", + "-Xms50m", "-version"}); System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java"));