Revision: 23435
Author: [email protected]
Date: Wed Aug 27 08:29:22 2014 UTC
Log: Sync our homegrown SysInfo replacement with the one in Chrome
base.
Also fix several inconsistencies/bugs on the way.
TEST=base-unittests
[email protected]
Review URL: https://codereview.chromium.org/510693003
https://code.google.com/p/v8/source/detail?r=23435
Added:
/branches/bleeding_edge/src/base/sys-info.cc
/branches/bleeding_edge/src/base/sys-info.h
/branches/bleeding_edge/test/base-unittests/sys-info-unittest.cc
Modified:
/branches/bleeding_edge/BUILD.gn
/branches/bleeding_edge/src/base/platform/platform-posix.cc
/branches/bleeding_edge/src/base/platform/platform-win32.cc
/branches/bleeding_edge/src/base/platform/platform.h
/branches/bleeding_edge/src/d8.cc
/branches/bleeding_edge/src/isolate.cc
/branches/bleeding_edge/src/libplatform/default-platform.cc
/branches/bleeding_edge/test/base-unittests/base-unittests.gyp
/branches/bleeding_edge/test/base-unittests/platform/platform-unittest.cc
/branches/bleeding_edge/tools/gyp/v8.gyp
=======================================
--- /dev/null
+++ /branches/bleeding_edge/src/base/sys-info.cc Wed Aug 27 08:29:22 2014
UTC
@@ -0,0 +1,122 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/base/sys-info.h"
+
+#if V8_OS_POSIX
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#endif
+
+#if V8_OS_BSD
+#include <sys/sysctl.h>
+#endif
+
+#include <limits>
+
+#include "src/base/logging.h"
+#include "src/base/macros.h"
+#if V8_OS_WIN
+#include "src/base/win32-headers.h"
+#endif
+
+namespace v8 {
+namespace base {
+
+// static
+int SysInfo::NumberOfProcessors() {
+#if V8_OS_OPENBSD
+ int mib[2] = {CTL_HW, HW_NCPU};
+ int ncpu = 0;
+ size_t len = sizeof(ncpu);
+ if (sysctl(mib, arraysize(mib), &ncpu, &len, NULL, 0) != 0) {
+ UNREACHABLE();
+ return 1;
+ }
+ return ncpu;
+#elif V8_OS_POSIX
+ long result = sysconf(_SC_NPROCESSORS_ONLN); // NOLINT(runtime/int)
+ if (result == -1) {
+ UNREACHABLE();
+ return 1;
+ }
+ return static_cast<int>(result);
+#elif V8_OS_WIN
+ SYSTEM_INFO system_info = {0};
+ ::GetNativeSystemInfo(&system_info);
+ return static_cast<int>(system_info.dwNumberOfProcessors);
+#endif
+}
+
+
+// static
+int64_t SysInfo::AmountOfPhysicalMemory() {
+#if V8_OS_MACOSX
+ int mib[2] = {CTL_HW, HW_MEMSIZE};
+ int64_t memsize = 0;
+ size_t len = sizeof(memsize);
+ if (sysctl(mib, arraysize(mib), &memsize, &len, NULL, 0) != 0) {
+ UNREACHABLE();
+ return 0;
+ }
+ return memsize;
+#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<int64_t>(pages) * page_size;
+#elif V8_OS_CYGWIN || V8_OS_WIN
+ MEMORYSTATUSEX memory_info;
+ memory_info.dwLength = sizeof(memory_info);
+ if (!GlobalMemoryStatusEx(&memory_info)) {
+ UNREACHABLE();
+ return 0;
+ }
+ int64_t result = static_cast<int64_t>(memory_info.ullTotalPhys);
+ if (result < 0) result = std::numeric_limits<int64_t>::max();
+ return result;
+#elif V8_OS_QNX
+ struct stat stat_buf;
+ if (stat("/proc", &stat_buf) != 0) {
+ UNREACHABLE();
+ return 0;
+ }
+ return static_cast<int64_t>(stat_buf.st_size);
+#elif V8_OS_POSIX
+ long pages = sysconf(_SC_PHYS_PAGES); // NOLINT(runtime/int)
+ long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int)
+ if (pages == -1 || page_size == -1) {
+ UNREACHABLE();
+ return 0;
+ }
+ return static_cast<int64_t>(pages) * page_size;
+#endif
+}
+
+
+// static
+int64_t SysInfo::AmountOfVirtualMemory() {
+#if V8_OS_NACL || V8_OS_WIN
+ return 0;
+#elif V8_OS_POSIX
+ struct rlimit rlim;
+ int result = getrlimit(RLIMIT_DATA, &rlim);
+ if (result != 0) {
+ UNREACHABLE();
+ return 0;
+ }
+ return (rlim.rlim_cur == RLIM_INFINITY) ? 0 : rlim.rlim_cur;
+#endif
+}
+
+} // namespace base
+} // namespace v8
=======================================
--- /dev/null
+++ /branches/bleeding_edge/src/base/sys-info.h Wed Aug 27 08:29:22 2014 UTC
@@ -0,0 +1,30 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_BASE_SYS_INFO_H_
+#define V8_BASE_SYS_INFO_H_
+
+#include "include/v8stdint.h"
+#include "src/base/build_config.h"
+
+namespace v8 {
+namespace base {
+
+class SysInfo V8_FINAL {
+ public:
+ // Returns the number of logical processors/core on the current machine.
+ static int NumberOfProcessors();
+
+ // Returns the number of bytes of physical memory on the current machine.
+ static int64_t AmountOfPhysicalMemory();
+
+ // Returns the number of bytes of virtual memory of this process. A
return
+ // value of zero means that there is no limit on the available virtual
memory.
+ static int64_t AmountOfVirtualMemory();
+};
+
+} // namespace base
+} // namespace v8
+
+#endif // V8_BASE_SYS_INFO_H_
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/base-unittests/sys-info-unittest.cc Wed
Aug 27 08:29:22 2014 UTC
@@ -0,0 +1,26 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/base/sys-info.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace base {
+
+TEST(SysInfoTest, NumberOfProcessors) {
+ EXPECT_LT(0, SysInfo::NumberOfProcessors());
+}
+
+
+TEST(SysInfoTest, AmountOfPhysicalMemory) {
+ EXPECT_LT(0, SysInfo::AmountOfPhysicalMemory());
+}
+
+
+TEST(SysInfoTest, AmountOfVirtualMemory) {
+ EXPECT_LE(0, SysInfo::AmountOfVirtualMemory());
+}
+
+} // namespace base
+} // namespace v8
=======================================
--- /branches/bleeding_edge/BUILD.gn Tue Aug 26 17:57:18 2014 UTC
+++ /branches/bleeding_edge/BUILD.gn Wed Aug 27 08:29:22 2014 UTC
@@ -1183,6 +1183,8 @@
"src/base/safe_conversions_impl.h",
"src/base/safe_math.h",
"src/base/safe_math_impl.h",
+ "src/base/sys-info.cc",
+ "src/base/sys-info.h",
"src/base/utils/random-number-generator.cc",
"src/base/utils/random-number-generator.h",
]
=======================================
--- /branches/bleeding_edge/src/base/platform/platform-posix.cc Tue Aug 5
13:23:55 2014 UTC
+++ /branches/bleeding_edge/src/base/platform/platform-posix.cc Wed Aug 27
08:29:22 2014 UTC
@@ -70,77 +70,6 @@
} // namespace
-int OS::NumberOfProcessorsOnline() {
- return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
-}
-
-
-// Maximum size of the virtual memory. 0 means there is no artificial
-// limit.
-
-intptr_t OS::MaxVirtualMemory() {
- struct rlimit limit;
- int result = getrlimit(RLIMIT_DATA, &limit);
- if (result != 0) return 0;
-#if V8_OS_NACL
- // The NaCl compiler doesn't like resource.h constants.
- if (static_cast<int>(limit.rlim_cur) == -1) return 0;
-#else
- if (limit.rlim_cur == RLIM_INFINITY) return 0;
-#endif
- return limit.rlim_cur;
-}
-
-
-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);
-#elif V8_OS_QNX
- struct stat stat_buf;
- if (stat("/proc", &stat_buf) != 0) {
- UNREACHABLE();
- return 0;
- }
- return static_cast<uint64_t>(stat_buf.st_size);
-#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
=======================================
--- /branches/bleeding_edge/src/base/platform/platform-win32.cc Mon Aug 4
11:34:54 2014 UTC
+++ /branches/bleeding_edge/src/base/platform/platform-win32.cc Wed Aug 27
08:29:22 2014 UTC
@@ -113,11 +113,6 @@
} // namespace
-intptr_t OS::MaxVirtualMemory() {
- return 0;
-}
-
-
class TimezoneCache {
public:
TimezoneCache() : initialized_(false) { }
@@ -1166,18 +1161,6 @@
void OS::SignalCodeMovingGC() {
}
-
-
-uint64_t OS::TotalPhysicalMemory() {
- MEMORYSTATUSEX memory_info;
- memory_info.dwLength = sizeof(memory_info);
- if (!GlobalMemoryStatusEx(&memory_info)) {
- UNREACHABLE();
- return 0;
- }
-
- return static_cast<uint64_t>(memory_info.ullTotalPhys);
-}
#else // __MINGW32__
@@ -1190,13 +1173,6 @@
#endif // __MINGW32__
-int OS::NumberOfProcessorsOnline() {
- SYSTEM_INFO info;
- GetSystemInfo(&info);
- return info.dwNumberOfProcessors;
-}
-
-
double OS::nan_value() {
#ifdef _MSC_VER
return std::numeric_limits<double>::quiet_NaN();
=======================================
--- /branches/bleeding_edge/src/base/platform/platform.h Tue Aug 12
13:33:35 2014 UTC
+++ /branches/bleeding_edge/src/base/platform/platform.h Wed Aug 27
08:29:22 2014 UTC
@@ -284,16 +284,6 @@
// using --never-compact) if accurate profiling is desired.
static void SignalCodeMovingGC();
- // Returns the number of processors online.
- static int NumberOfProcessorsOnline();
-
- // The total amount of physical memory available on the current system.
- static uint64_t TotalPhysicalMemory();
-
- // Maximum size of the virtual memory. 0 means there is no artificial
- // limit.
- static intptr_t MaxVirtualMemory();
-
// Returns the double constant NAN
static double nan_value();
=======================================
--- /branches/bleeding_edge/src/d8.cc Tue Aug 12 17:54:41 2014 UTC
+++ /branches/bleeding_edge/src/d8.cc Wed Aug 27 08:29:22 2014 UTC
@@ -45,6 +45,7 @@
#include "src/base/cpu.h"
#include "src/base/logging.h"
#include "src/base/platform/platform.h"
+#include "src/base/sys-info.h"
#include "src/d8-debug.h"
#include "src/debug.h"
#include "src/natives.h"
@@ -1614,9 +1615,9 @@
Isolate* isolate = Isolate::New();
#ifndef V8_SHARED
v8::ResourceConstraints constraints;
- constraints.ConfigureDefaults(base::OS::TotalPhysicalMemory(),
- base::OS::MaxVirtualMemory(),
- base::OS::NumberOfProcessorsOnline());
+ constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
+ base::SysInfo::AmountOfVirtualMemory(),
+ base::SysInfo::NumberOfProcessors());
v8::SetResourceConstraints(isolate, &constraints);
#endif
DumbLineEditor dumb_line_editor(isolate);
=======================================
--- /branches/bleeding_edge/src/isolate.cc Tue Aug 26 16:32:51 2014 UTC
+++ /branches/bleeding_edge/src/isolate.cc Wed Aug 27 08:29:22 2014 UTC
@@ -8,6 +8,7 @@
#include "src/ast.h"
#include "src/base/platform/platform.h"
+#include "src/base/sys-info.h"
#include "src/base/utils/random-number-generator.h"
#include "src/bootstrapper.h"
#include "src/codegen.h"
@@ -1947,7 +1948,7 @@
if (max_available_threads_ < 1) {
// Choose the default between 1 and 4.
max_available_threads_ =
- Max(Min(base::OS::NumberOfProcessorsOnline(), 4), 1);
+ Max(Min(base::SysInfo::NumberOfProcessors(), 4), 1);
}
if (!FLAG_job_based_sweeping) {
=======================================
--- /branches/bleeding_edge/src/libplatform/default-platform.cc Mon Aug 4
11:34:54 2014 UTC
+++ /branches/bleeding_edge/src/libplatform/default-platform.cc Wed Aug 27
08:29:22 2014 UTC
@@ -9,6 +9,7 @@
#include "src/base/logging.h"
#include "src/base/platform/platform.h"
+#include "src/base/sys-info.h"
#include "src/libplatform/worker-thread.h"
namespace v8 {
@@ -58,8 +59,9 @@
void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) {
base::LockGuard<base::Mutex> guard(&lock_);
DCHECK(thread_pool_size >= 0);
- if (thread_pool_size < 1)
- thread_pool_size = base::OS::NumberOfProcessorsOnline();
+ if (thread_pool_size < 1) {
+ thread_pool_size = base::SysInfo::NumberOfProcessors();
+ }
thread_pool_size_ =
std::max(std::min(thread_pool_size, kMaxThreadPoolSize), 1);
}
=======================================
--- /branches/bleeding_edge/test/base-unittests/base-unittests.gyp Fri Aug
22 08:52:40 2014 UTC
+++ /branches/bleeding_edge/test/base-unittests/base-unittests.gyp Wed Aug
27 08:29:22 2014 UTC
@@ -27,6 +27,7 @@
'platform/platform-unittest.cc',
'platform/semaphore-unittest.cc',
'platform/time-unittest.cc',
+ 'sys-info-unittest.cc',
'utils/random-number-generator-unittest.cc',
],
'conditions': [
=======================================
---
/branches/bleeding_edge/test/base-unittests/platform/platform-unittest.cc
Tue Aug 26 09:19:24 2014 UTC
+++
/branches/bleeding_edge/test/base-unittests/platform/platform-unittest.cc
Wed Aug 27 08:29:22 2014 UTC
@@ -26,11 +26,6 @@
OS::GetCurrentProcessId());
#endif
}
-
-
-TEST(OS, NumberOfProcessorsOnline) {
- EXPECT_GT(OS::NumberOfProcessorsOnline(), 0);
-}
namespace {
=======================================
--- /branches/bleeding_edge/tools/gyp/v8.gyp Wed Aug 27 04:49:41 2014 UTC
+++ /branches/bleeding_edge/tools/gyp/v8.gyp Wed Aug 27 08:29:22 2014 UTC
@@ -1150,6 +1150,8 @@
'../../src/base/safe_conversions_impl.h',
'../../src/base/safe_math.h',
'../../src/base/safe_math_impl.h',
+ '../../src/base/sys-info.cc',
+ '../../src/base/sys-info.h',
'../../src/base/utils/random-number-generator.cc',
'../../src/base/utils/random-number-generator.h',
],
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.