8025942: os::Bsd::available_memory() needs implementation
authorhseigel
Sat, 12 Oct 2013 13:09:18 -0400
changeset 20683 7b211e525ab8
parent 20682 99749d154ce7
child 20684 057f5443edab
8025942: os::Bsd::available_memory() needs implementation Summary: Implement using the host_statistics64() api. Reviewed-by: dsamersoff, morris, dholmes, coleenp, hseigel, dcubed Contributed-by: gerard.ziemski@oracle.com
hotspot/src/os/bsd/vm/os_bsd.cpp
--- a/hotspot/src/os/bsd/vm/os_bsd.cpp	Fri Oct 11 22:22:19 2013 -0400
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp	Sat Oct 12 13:09:18 2013 -0400
@@ -159,9 +159,21 @@
   return Bsd::available_memory();
 }
 
+// available here means free
 julong os::Bsd::available_memory() {
-  // XXXBSD: this is just a stopgap implementation
-  return physical_memory() >> 2;
+  uint64_t available = physical_memory() >> 2;
+#ifdef __APPLE__
+  mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
+  vm_statistics64_data_t vmstat;
+  kern_return_t kerr = host_statistics64(mach_host_self(), HOST_VM_INFO64,
+                                         (host_info64_t)&vmstat, &count);
+  assert(kerr == KERN_SUCCESS,
+         "host_statistics64 failed - check mach_host_self() and count");
+  if (kerr == KERN_SUCCESS) {
+    available = vmstat.free_count * os::vm_page_size();
+  }
+#endif
+  return available;
 }
 
 julong os::physical_memory() {