1958 snprintf(buf, PATH_MAX + 1, "%s/hs-vm-%d-%d",
1959 os::get_temp_directory(), os::current_process_id(), num);
1960 unlink(buf);
1961
1962 int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);
1963
1964 if (fd != -1) {
1965 off_t rv = ::lseek(fd, size-2, SEEK_SET);
1966 if (rv != (off_t)-1) {
1967 if (::write(fd, "", 1) == 1) {
1968 mmap(base, size,
1969 PROT_READ|PROT_WRITE|PROT_EXEC,
1970 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
1971 }
1972 }
1973 ::close(fd);
1974 unlink(buf);
1975 }
1976 }
1977
1978 // NOTE: Bsd kernel does not really reserve the pages for us.
1979 // All it does is to check if there are enough free pages
1980 // left at the time of mmap(). This could be a potential
1981 // problem.
1982 bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
1983 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
1984 #ifdef __OpenBSD__
1985 // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
1986 return ::mprotect(addr, size, prot) == 0;
1987 #else
1988 uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
1989 MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
1990 return res != (uintptr_t) MAP_FAILED;
1991 #endif
1992 }
1993
1994
1995 bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
1996 bool exec) {
1997 return commit_memory(addr, size, exec);
1998 }
1999
2000 void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
2001 }
2002
2003 void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
2004 ::madvise(addr, bytes, MADV_DONTNEED);
2005 }
2006
2007 void os::numa_make_global(char *addr, size_t bytes) {
2008 }
2009
2010 void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) {
2011 }
2012
2013 bool os::numa_topology_changed() { return false; }
2014
2015 size_t os::numa_get_groups_num() {
2016 return 1;
2017 }
2018
2019 int os::numa_get_group_id() {
2032 return false;
2033 }
2034
2035 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
2036 return end;
2037 }
2038
2039
2040 bool os::pd_uncommit_memory(char* addr, size_t size) {
2041 #ifdef __OpenBSD__
2042 // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
2043 return ::mprotect(addr, size, PROT_NONE) == 0;
2044 #else
2045 uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
2046 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
2047 return res != (uintptr_t) MAP_FAILED;
2048 #endif
2049 }
2050
2051 bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
2052 return os::commit_memory(addr, size);
2053 }
2054
2055 // If this is a growable mapping, remove the guard pages entirely by
2056 // munmap()ping them. If not, just call uncommit_memory().
2057 bool os::remove_stack_guard_pages(char* addr, size_t size) {
2058 return os::uncommit_memory(addr, size);
2059 }
2060
2061 static address _highest_vm_reserved_address = NULL;
2062
2063 // If 'fixed' is true, anon_mmap() will attempt to reserve anonymous memory
2064 // at 'requested_addr'. If there are existing memory mappings at the same
2065 // location, however, they will be overwritten. If 'fixed' is false,
2066 // 'requested_addr' is only treated as a hint, the return value may or
2067 // may not start from the requested address. Unlike Bsd mmap(), this
2068 // function returns NULL to indicate failure.
2069 static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) {
2070 char * addr;
2071 int flags;
2072
3377 perfMemory_exit();
3378 }
3379 }
3380
3381 // this is called _after_ the global arguments have been parsed
3382 jint os::init_2(void)
3383 {
3384 // Allocate a single page and mark it as readable for safepoint polling
3385 address polling_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
3386 guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" );
3387
3388 os::set_polling_page( polling_page );
3389
3390 #ifndef PRODUCT
3391 if(Verbose && PrintMiscellaneous)
3392 tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page);
3393 #endif
3394
3395 if (!UseMembar) {
3396 address mem_serialize_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
3397 guarantee( mem_serialize_page != NULL, "mmap Failed for memory serialize page");
3398 os::set_memory_serialize_page( mem_serialize_page );
3399
3400 #ifndef PRODUCT
3401 if(Verbose && PrintMiscellaneous)
3402 tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page);
3403 #endif
3404 }
3405
3406 os::large_page_init();
3407
3408 // initialize suspend/resume support - must do this before signal_sets_init()
3409 if (SR_initialize() != 0) {
3410 perror("SR_initialize failed");
3411 return JNI_ERR;
3412 }
3413
3414 Bsd::signal_sets_init();
3415 Bsd::install_signal_handlers();
3416
3417 // Check minimum allowable stack size for thread creation and to initialize
|
1958 snprintf(buf, PATH_MAX + 1, "%s/hs-vm-%d-%d",
1959 os::get_temp_directory(), os::current_process_id(), num);
1960 unlink(buf);
1961
1962 int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);
1963
1964 if (fd != -1) {
1965 off_t rv = ::lseek(fd, size-2, SEEK_SET);
1966 if (rv != (off_t)-1) {
1967 if (::write(fd, "", 1) == 1) {
1968 mmap(base, size,
1969 PROT_READ|PROT_WRITE|PROT_EXEC,
1970 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
1971 }
1972 }
1973 ::close(fd);
1974 unlink(buf);
1975 }
1976 }
1977
1978 static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
1979 int err) {
1980 warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
1981 ", %d) failed; error='%s' (errno=%d)", addr, size, exec,
1982 strerror(err), err);
1983 }
1984
1985 // NOTE: Bsd kernel does not really reserve the pages for us.
1986 // All it does is to check if there are enough free pages
1987 // left at the time of mmap(). This could be a potential
1988 // problem.
1989 bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
1990 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
1991 #ifdef __OpenBSD__
1992 // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
1993 if (::mprotect(addr, size, prot) == 0) {
1994 return true;
1995 }
1996 #else
1997 uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
1998 MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
1999 if (res != (uintptr_t) MAP_FAILED) {
2000 return true;
2001 }
2002 #endif
2003
2004 // Warn about any commit errors we see in non-product builds just
2005 // in case mmap() doesn't work as described on the man page.
2006 NOT_PRODUCT(warn_fail_commit_memory(addr, size, exec, errno);)
2007
2008 return false;
2009 }
2010
2011 bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
2012 bool exec) {
2013 // alignment_hint is ignored on this OS
2014 return pd_commit_memory(addr, size, exec);
2015 }
2016
2017 void os::pd_commit_memory_or_exit(char* addr, size_t size, bool exec,
2018 const char* mesg) {
2019 assert(mesg != NULL, "mesg must be specified");
2020 if (!pd_commit_memory(addr, size, exec)) {
2021 // add extra info in product mode for vm_exit_out_of_memory():
2022 PRODUCT_ONLY(warn_fail_commit_memory(addr, size, exec, errno);)
2023 vm_exit_out_of_memory(size, OOM_MMAP_ERROR, mesg);
2024 }
2025 }
2026
2027 void os::pd_commit_memory_or_exit(char* addr, size_t size,
2028 size_t alignment_hint, bool exec,
2029 const char* mesg) {
2030 // alignment_hint is ignored on this OS
2031 pd_commit_memory_or_exit(addr, size, exec, mesg);
2032 }
2033
2034 void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
2035 }
2036
2037 void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
2038 ::madvise(addr, bytes, MADV_DONTNEED);
2039 }
2040
2041 void os::numa_make_global(char *addr, size_t bytes) {
2042 }
2043
2044 void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) {
2045 }
2046
2047 bool os::numa_topology_changed() { return false; }
2048
2049 size_t os::numa_get_groups_num() {
2050 return 1;
2051 }
2052
2053 int os::numa_get_group_id() {
2066 return false;
2067 }
2068
2069 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
2070 return end;
2071 }
2072
2073
2074 bool os::pd_uncommit_memory(char* addr, size_t size) {
2075 #ifdef __OpenBSD__
2076 // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
2077 return ::mprotect(addr, size, PROT_NONE) == 0;
2078 #else
2079 uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
2080 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
2081 return res != (uintptr_t) MAP_FAILED;
2082 #endif
2083 }
2084
2085 bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
2086 return os::commit_memory(addr, size, !ExecMem);
2087 }
2088
2089 // If this is a growable mapping, remove the guard pages entirely by
2090 // munmap()ping them. If not, just call uncommit_memory().
2091 bool os::remove_stack_guard_pages(char* addr, size_t size) {
2092 return os::uncommit_memory(addr, size);
2093 }
2094
2095 static address _highest_vm_reserved_address = NULL;
2096
2097 // If 'fixed' is true, anon_mmap() will attempt to reserve anonymous memory
2098 // at 'requested_addr'. If there are existing memory mappings at the same
2099 // location, however, they will be overwritten. If 'fixed' is false,
2100 // 'requested_addr' is only treated as a hint, the return value may or
2101 // may not start from the requested address. Unlike Bsd mmap(), this
2102 // function returns NULL to indicate failure.
2103 static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) {
2104 char * addr;
2105 int flags;
2106
3411 perfMemory_exit();
3412 }
3413 }
3414
3415 // this is called _after_ the global arguments have been parsed
3416 jint os::init_2(void)
3417 {
3418 // Allocate a single page and mark it as readable for safepoint polling
3419 address polling_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
3420 guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" );
3421
3422 os::set_polling_page( polling_page );
3423
3424 #ifndef PRODUCT
3425 if(Verbose && PrintMiscellaneous)
3426 tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page);
3427 #endif
3428
3429 if (!UseMembar) {
3430 address mem_serialize_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
3431 guarantee( mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
3432 os::set_memory_serialize_page( mem_serialize_page );
3433
3434 #ifndef PRODUCT
3435 if(Verbose && PrintMiscellaneous)
3436 tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page);
3437 #endif
3438 }
3439
3440 os::large_page_init();
3441
3442 // initialize suspend/resume support - must do this before signal_sets_init()
3443 if (SR_initialize() != 0) {
3444 perror("SR_initialize failed");
3445 return JNI_ERR;
3446 }
3447
3448 Bsd::signal_sets_init();
3449 Bsd::install_signal_handlers();
3450
3451 // Check minimum allowable stack size for thread creation and to initialize
|