src/os/bsd/vm/os_bsd.cpp

changeset 5255
a837fa3d3f86
parent 5237
f2110083203d
child 5272
1f4355cee9a2
     1.1 --- a/src/os/bsd/vm/os_bsd.cpp	Mon Jun 10 11:30:51 2013 +0200
     1.2 +++ b/src/os/bsd/vm/os_bsd.cpp	Thu Jun 13 11:16:38 2013 -0700
     1.3 @@ -2074,6 +2074,13 @@
     1.4    }
     1.5  }
     1.6  
     1.7 +static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
     1.8 +                                    int err) {
     1.9 +  warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
    1.10 +          ", %d) failed; error='%s' (errno=%d)", addr, size, exec,
    1.11 +          strerror(err), err);
    1.12 +}
    1.13 +
    1.14  // NOTE: Bsd kernel does not really reserve the pages for us.
    1.15  //       All it does is to check if there are enough free pages
    1.16  //       left at the time of mmap(). This could be a potential
    1.17 @@ -2082,18 +2089,45 @@
    1.18    int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
    1.19  #ifdef __OpenBSD__
    1.20    // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
    1.21 -  return ::mprotect(addr, size, prot) == 0;
    1.22 +  if (::mprotect(addr, size, prot) == 0) {
    1.23 +    return true;
    1.24 +  }
    1.25  #else
    1.26    uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
    1.27                                     MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
    1.28 -  return res != (uintptr_t) MAP_FAILED;
    1.29 +  if (res != (uintptr_t) MAP_FAILED) {
    1.30 +    return true;
    1.31 +  }
    1.32  #endif
    1.33 +
    1.34 +  // Warn about any commit errors we see in non-product builds just
    1.35 +  // in case mmap() doesn't work as described on the man page.
    1.36 +  NOT_PRODUCT(warn_fail_commit_memory(addr, size, exec, errno);)
    1.37 +
    1.38 +  return false;
    1.39  }
    1.40  
    1.41 -
    1.42  bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
    1.43                         bool exec) {
    1.44 -  return commit_memory(addr, size, exec);
    1.45 +  // alignment_hint is ignored on this OS
    1.46 +  return pd_commit_memory(addr, size, exec);
    1.47 +}
    1.48 +
    1.49 +void os::pd_commit_memory_or_exit(char* addr, size_t size, bool exec,
    1.50 +                                  const char* mesg) {
    1.51 +  assert(mesg != NULL, "mesg must be specified");
    1.52 +  if (!pd_commit_memory(addr, size, exec)) {
    1.53 +    // add extra info in product mode for vm_exit_out_of_memory():
    1.54 +    PRODUCT_ONLY(warn_fail_commit_memory(addr, size, exec, errno);)
    1.55 +    vm_exit_out_of_memory(size, OOM_MMAP_ERROR, mesg);
    1.56 +  }
    1.57 +}
    1.58 +
    1.59 +void os::pd_commit_memory_or_exit(char* addr, size_t size,
    1.60 +                                  size_t alignment_hint, bool exec,
    1.61 +                                  const char* mesg) {
    1.62 +  // alignment_hint is ignored on this OS
    1.63 +  pd_commit_memory_or_exit(addr, size, exec, mesg);
    1.64  }
    1.65  
    1.66  void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
    1.67 @@ -2148,7 +2182,7 @@
    1.68  }
    1.69  
    1.70  bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
    1.71 -  return os::commit_memory(addr, size);
    1.72 +  return os::commit_memory(addr, size, !ExecMem);
    1.73  }
    1.74  
    1.75  // If this is a growable mapping, remove the guard pages entirely by
    1.76 @@ -3512,7 +3546,7 @@
    1.77  
    1.78    if (!UseMembar) {
    1.79      address mem_serialize_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
    1.80 -    guarantee( mem_serialize_page != NULL, "mmap Failed for memory serialize page");
    1.81 +    guarantee( mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
    1.82      os::set_memory_serialize_page( mem_serialize_page );
    1.83  
    1.84  #ifndef PRODUCT

mercurial