Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: src/base/sys-info.cc

Issue 818213002: Remove UNREACHABLE() statements from sys-info.cc (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/base/sys-info.h" 5 #include "src/base/sys-info.h"
6 6
7 #if V8_OS_POSIX 7 #if V8_OS_POSIX
8 #include <sys/resource.h> 8 #include <sys/resource.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/time.h> 10 #include <sys/time.h>
(...skipping 16 matching lines...) Expand all
27 namespace v8 { 27 namespace v8 {
28 namespace base { 28 namespace base {
29 29
30 // static 30 // static
31 int SysInfo::NumberOfProcessors() { 31 int SysInfo::NumberOfProcessors() {
32 #if V8_OS_OPENBSD 32 #if V8_OS_OPENBSD
33 int mib[2] = {CTL_HW, HW_NCPU}; 33 int mib[2] = {CTL_HW, HW_NCPU};
34 int ncpu = 0; 34 int ncpu = 0;
35 size_t len = sizeof(ncpu); 35 size_t len = sizeof(ncpu);
36 if (sysctl(mib, arraysize(mib), &ncpu, &len, NULL, 0) != 0) { 36 if (sysctl(mib, arraysize(mib), &ncpu, &len, NULL, 0) != 0) {
37 UNREACHABLE();
38 return 1; 37 return 1;
39 } 38 }
40 return ncpu; 39 return ncpu;
41 #elif V8_OS_POSIX 40 #elif V8_OS_POSIX
42 long result = sysconf(_SC_NPROCESSORS_ONLN); // NOLINT(runtime/int) 41 long result = sysconf(_SC_NPROCESSORS_ONLN); // NOLINT(runtime/int)
43 if (result == -1) { 42 if (result == -1) {
44 UNREACHABLE();
45 return 1; 43 return 1;
46 } 44 }
47 return static_cast<int>(result); 45 return static_cast<int>(result);
48 #elif V8_OS_WIN 46 #elif V8_OS_WIN
49 SYSTEM_INFO system_info = {0}; 47 SYSTEM_INFO system_info = {0};
50 ::GetNativeSystemInfo(&system_info); 48 ::GetNativeSystemInfo(&system_info);
51 return static_cast<int>(system_info.dwNumberOfProcessors); 49 return static_cast<int>(system_info.dwNumberOfProcessors);
52 #endif 50 #endif
53 } 51 }
54 52
55 53
56 // static 54 // static
57 int64_t SysInfo::AmountOfPhysicalMemory() { 55 int64_t SysInfo::AmountOfPhysicalMemory() {
58 #if V8_OS_MACOSX 56 #if V8_OS_MACOSX
59 int mib[2] = {CTL_HW, HW_MEMSIZE}; 57 int mib[2] = {CTL_HW, HW_MEMSIZE};
60 int64_t memsize = 0; 58 int64_t memsize = 0;
61 size_t len = sizeof(memsize); 59 size_t len = sizeof(memsize);
62 if (sysctl(mib, arraysize(mib), &memsize, &len, NULL, 0) != 0) { 60 if (sysctl(mib, arraysize(mib), &memsize, &len, NULL, 0) != 0) {
63 UNREACHABLE();
64 return 0; 61 return 0;
65 } 62 }
66 return memsize; 63 return memsize;
67 #elif V8_OS_FREEBSD 64 #elif V8_OS_FREEBSD
68 int pages, page_size; 65 int pages, page_size;
69 size_t size = sizeof(pages); 66 size_t size = sizeof(pages);
70 sysctlbyname("vm.stats.vm.v_page_count", &pages, &size, NULL, 0); 67 sysctlbyname("vm.stats.vm.v_page_count", &pages, &size, NULL, 0);
71 sysctlbyname("vm.stats.vm.v_page_size", &page_size, &size, NULL, 0); 68 sysctlbyname("vm.stats.vm.v_page_size", &page_size, &size, NULL, 0);
72 if (pages == -1 || page_size == -1) { 69 if (pages == -1 || page_size == -1) {
73 UNREACHABLE();
74 return 0; 70 return 0;
75 } 71 }
76 return static_cast<int64_t>(pages) * page_size; 72 return static_cast<int64_t>(pages) * page_size;
77 #elif V8_OS_CYGWIN || V8_OS_WIN 73 #elif V8_OS_CYGWIN || V8_OS_WIN
78 MEMORYSTATUSEX memory_info; 74 MEMORYSTATUSEX memory_info;
79 memory_info.dwLength = sizeof(memory_info); 75 memory_info.dwLength = sizeof(memory_info);
80 if (!GlobalMemoryStatusEx(&memory_info)) { 76 if (!GlobalMemoryStatusEx(&memory_info)) {
81 UNREACHABLE();
82 return 0; 77 return 0;
83 } 78 }
84 int64_t result = static_cast<int64_t>(memory_info.ullTotalPhys); 79 int64_t result = static_cast<int64_t>(memory_info.ullTotalPhys);
85 if (result < 0) result = std::numeric_limits<int64_t>::max(); 80 if (result < 0) result = std::numeric_limits<int64_t>::max();
86 return result; 81 return result;
87 #elif V8_OS_QNX 82 #elif V8_OS_QNX
88 struct stat stat_buf; 83 struct stat stat_buf;
89 if (stat("/proc", &stat_buf) != 0) { 84 if (stat("/proc", &stat_buf) != 0) {
90 UNREACHABLE();
91 return 0; 85 return 0;
92 } 86 }
93 return static_cast<int64_t>(stat_buf.st_size); 87 return static_cast<int64_t>(stat_buf.st_size);
94 #elif V8_OS_NACL 88 #elif V8_OS_NACL
95 // No support for _SC_PHYS_PAGES, assume 2GB. 89 // No support for _SC_PHYS_PAGES, assume 2GB.
96 return static_cast<int64_t>(1) << 31; 90 return static_cast<int64_t>(1) << 31;
97 #elif V8_OS_POSIX 91 #elif V8_OS_POSIX
98 long pages = sysconf(_SC_PHYS_PAGES); // NOLINT(runtime/int) 92 long pages = sysconf(_SC_PHYS_PAGES); // NOLINT(runtime/int)
99 long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int) 93 long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int)
100 if (pages == -1 || page_size == -1) { 94 if (pages == -1 || page_size == -1) {
101 UNREACHABLE();
102 return 0; 95 return 0;
103 } 96 }
104 return static_cast<int64_t>(pages) * page_size; 97 return static_cast<int64_t>(pages) * page_size;
105 #endif 98 #endif
106 } 99 }
107 100
108 101
109 // static 102 // static
110 int64_t SysInfo::AmountOfVirtualMemory() { 103 int64_t SysInfo::AmountOfVirtualMemory() {
111 #if V8_OS_NACL || V8_OS_WIN 104 #if V8_OS_NACL || V8_OS_WIN
112 return 0; 105 return 0;
113 #elif V8_OS_POSIX 106 #elif V8_OS_POSIX
114 struct rlimit rlim; 107 struct rlimit rlim;
115 int result = getrlimit(RLIMIT_DATA, &rlim); 108 int result = getrlimit(RLIMIT_DATA, &rlim);
116 if (result != 0) { 109 if (result != 0) {
117 UNREACHABLE();
118 return 0; 110 return 0;
119 } 111 }
120 return (rlim.rlim_cur == RLIM_INFINITY) ? 0 : rlim.rlim_cur; 112 return (rlim.rlim_cur == RLIM_INFINITY) ? 0 : rlim.rlim_cur;
121 #endif 113 #endif
122 } 114 }
123 115
124 } // namespace base 116 } // namespace base
125 } // namespace v8 117 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698