Index: src/platform-posix.cc |
diff --git a/src/platform-posix.cc b/src/platform-posix.cc |
index df15ee2e5b5ec6580431e38c0d5e6d5d53aa2590..797557d76f830cde51cb37943edce6f5d6f3504b 100644 |
--- a/src/platform-posix.cc |
+++ b/src/platform-posix.cc |
@@ -100,6 +100,48 @@ intptr_t OS::MaxVirtualMemory() { |
} |
+uint64_t OS::TotalPhysicalMemory() { |
+#if V8_OS_MACOSX |
+ int mib[2]; |
+ mib[0] = CTL_HW; |
+ mib[1] = HW_MEMSIZE; |
+ int64_t size = 0; |
+ size_t len = sizeof(size); |
+ if (sysctl(mib, 2, &size, &len, NULL, 0) != 0) { |
+ UNREACHABLE(); |
+ return 0; |
+ } |
+ return static_cast<uint64_t>(size); |
+#elif V8_OS_FREEBSD |
+ int pages, page_size; |
+ size_t size = sizeof(pages); |
+ sysctlbyname("vm.stats.vm.v_page_count", &pages, &size, NULL, 0); |
+ sysctlbyname("vm.stats.vm.v_page_size", &page_size, &size, NULL, 0); |
+ if (pages == -1 || page_size == -1) { |
+ UNREACHABLE(); |
+ return 0; |
+ } |
+ return static_cast<uint64_t>(pages) * page_size; |
+#elif V8_OS_CYGWIN |
+ MEMORYSTATUS memory_info; |
+ memory_info.dwLength = sizeof(memory_info); |
+ if (!GlobalMemoryStatus(&memory_info)) { |
+ UNREACHABLE(); |
+ return 0; |
+ } |
+ return static_cast<uint64_t>(memory_info.dwTotalPhys); |
+#else |
+ intptr_t pages = sysconf(_SC_PHYS_PAGES); |
+ intptr_t page_size = sysconf(_SC_PAGESIZE); |
+ if (pages == -1 || page_size == -1) { |
+ UNREACHABLE(); |
+ return 0; |
+ } |
+ return static_cast<uint64_t>(pages) * page_size; |
+#endif |
+} |
+ |
+ |
int OS::ActivationFrameAlignment() { |
#if V8_TARGET_ARCH_ARM |
// On EABI ARM targets this is required for fp correctness in the |