Index: src/platform-posix.cc |
diff --git a/src/platform-posix.cc b/src/platform-posix.cc |
index fe27eaf71f437fcc099ffdebb8e24f60c999921f..f4e11e733b1f3d12d233dfde2389a86530681b82 100644 |
--- a/src/platform-posix.cc |
+++ b/src/platform-posix.cc |
@@ -102,6 +102,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 |