src/os/bsd/vm/os_bsd.cpp

changeset 6443
f4f6ae481e1a
parent 6442
b5c8a61d7fa0
parent 5272
1f4355cee9a2
child 6455
438e13354adf
     1.1 --- a/src/os/bsd/vm/os_bsd.cpp	Fri Jun 21 15:56:24 2013 -0700
     1.2 +++ b/src/os/bsd/vm/os_bsd.cpp	Thu Jun 27 13:04:51 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 @@ -2320,21 +2354,20 @@
    1.77    }
    1.78  
    1.79    // The memory is committed
    1.80 -  address pc = CALLER_PC;
    1.81 -  MemTracker::record_virtual_memory_reserve((address)addr, bytes, pc);
    1.82 -  MemTracker::record_virtual_memory_commit((address)addr, bytes, pc);
    1.83 +  MemTracker::record_virtual_memory_reserve_and_commit((address)addr, bytes, mtNone, CALLER_PC);
    1.84  
    1.85    return addr;
    1.86  }
    1.87  
    1.88  bool os::release_memory_special(char* base, size_t bytes) {
    1.89 +  MemTracker::Tracker tkr = MemTracker::get_virtual_memory_release_tracker();
    1.90    // detaching the SHM segment will also delete it, see reserve_memory_special()
    1.91    int rslt = shmdt(base);
    1.92    if (rslt == 0) {
    1.93 -    MemTracker::record_virtual_memory_uncommit((address)base, bytes);
    1.94 -    MemTracker::record_virtual_memory_release((address)base, bytes);
    1.95 +    tkr.record((address)base, bytes);
    1.96      return true;
    1.97    } else {
    1.98 +    tkr.discard();
    1.99      return false;
   1.100    }
   1.101  
   1.102 @@ -3512,7 +3545,7 @@
   1.103  
   1.104    if (!UseMembar) {
   1.105      address mem_serialize_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
   1.106 -    guarantee( mem_serialize_page != NULL, "mmap Failed for memory serialize page");
   1.107 +    guarantee( mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
   1.108      os::set_memory_serialize_page( mem_serialize_page );
   1.109  
   1.110  #ifndef PRODUCT

mercurial