| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 // Platform-specific code for POSIX goes here. This is not a platform on its | 5 // Platform-specific code for POSIX goes here. This is not a platform on its |
| 6 // own, but contains the parts which are the same across the POSIX platforms | 6 // own, but contains the parts which are the same across the POSIX platforms |
| 7 // Linux, MacOS, FreeBSD, OpenBSD, NetBSD and QNX. | 7 // Linux, MacOS, FreeBSD, OpenBSD, NetBSD and QNX. |
| 8 | 8 |
| 9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // 0 is never a valid thread id. | 63 // 0 is never a valid thread id. |
| 64 const pthread_t kNoThread = (pthread_t) 0; | 64 const pthread_t kNoThread = (pthread_t) 0; |
| 65 | 65 |
| 66 bool g_hard_abort = false; | 66 bool g_hard_abort = false; |
| 67 | 67 |
| 68 const char* g_gc_fake_mmap = NULL; | 68 const char* g_gc_fake_mmap = NULL; |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 | 72 |
| 73 int OS::NumberOfProcessorsOnline() { | |
| 74 return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN)); | |
| 75 } | |
| 76 | |
| 77 | |
| 78 // Maximum size of the virtual memory. 0 means there is no artificial | |
| 79 // limit. | |
| 80 | |
| 81 intptr_t OS::MaxVirtualMemory() { | |
| 82 struct rlimit limit; | |
| 83 int result = getrlimit(RLIMIT_DATA, &limit); | |
| 84 if (result != 0) return 0; | |
| 85 #if V8_OS_NACL | |
| 86 // The NaCl compiler doesn't like resource.h constants. | |
| 87 if (static_cast<int>(limit.rlim_cur) == -1) return 0; | |
| 88 #else | |
| 89 if (limit.rlim_cur == RLIM_INFINITY) return 0; | |
| 90 #endif | |
| 91 return limit.rlim_cur; | |
| 92 } | |
| 93 | |
| 94 | |
| 95 uint64_t OS::TotalPhysicalMemory() { | |
| 96 #if V8_OS_MACOSX | |
| 97 int mib[2]; | |
| 98 mib[0] = CTL_HW; | |
| 99 mib[1] = HW_MEMSIZE; | |
| 100 int64_t size = 0; | |
| 101 size_t len = sizeof(size); | |
| 102 if (sysctl(mib, 2, &size, &len, NULL, 0) != 0) { | |
| 103 UNREACHABLE(); | |
| 104 return 0; | |
| 105 } | |
| 106 return static_cast<uint64_t>(size); | |
| 107 #elif V8_OS_FREEBSD | |
| 108 int pages, page_size; | |
| 109 size_t size = sizeof(pages); | |
| 110 sysctlbyname("vm.stats.vm.v_page_count", &pages, &size, NULL, 0); | |
| 111 sysctlbyname("vm.stats.vm.v_page_size", &page_size, &size, NULL, 0); | |
| 112 if (pages == -1 || page_size == -1) { | |
| 113 UNREACHABLE(); | |
| 114 return 0; | |
| 115 } | |
| 116 return static_cast<uint64_t>(pages) * page_size; | |
| 117 #elif V8_OS_CYGWIN | |
| 118 MEMORYSTATUS memory_info; | |
| 119 memory_info.dwLength = sizeof(memory_info); | |
| 120 if (!GlobalMemoryStatus(&memory_info)) { | |
| 121 UNREACHABLE(); | |
| 122 return 0; | |
| 123 } | |
| 124 return static_cast<uint64_t>(memory_info.dwTotalPhys); | |
| 125 #elif V8_OS_QNX | |
| 126 struct stat stat_buf; | |
| 127 if (stat("/proc", &stat_buf) != 0) { | |
| 128 UNREACHABLE(); | |
| 129 return 0; | |
| 130 } | |
| 131 return static_cast<uint64_t>(stat_buf.st_size); | |
| 132 #else | |
| 133 intptr_t pages = sysconf(_SC_PHYS_PAGES); | |
| 134 intptr_t page_size = sysconf(_SC_PAGESIZE); | |
| 135 if (pages == -1 || page_size == -1) { | |
| 136 UNREACHABLE(); | |
| 137 return 0; | |
| 138 } | |
| 139 return static_cast<uint64_t>(pages) * page_size; | |
| 140 #endif | |
| 141 } | |
| 142 | |
| 143 | |
| 144 int OS::ActivationFrameAlignment() { | 73 int OS::ActivationFrameAlignment() { |
| 145 #if V8_TARGET_ARCH_ARM | 74 #if V8_TARGET_ARCH_ARM |
| 146 // On EABI ARM targets this is required for fp correctness in the | 75 // On EABI ARM targets this is required for fp correctness in the |
| 147 // runtime system. | 76 // runtime system. |
| 148 return 8; | 77 return 8; |
| 149 #elif V8_TARGET_ARCH_MIPS | 78 #elif V8_TARGET_ARCH_MIPS |
| 150 return 8; | 79 return 8; |
| 151 #else | 80 #else |
| 152 // Otherwise we just assume 16 byte alignment, i.e.: | 81 // Otherwise we just assume 16 byte alignment, i.e.: |
| 153 // - With gcc 4.4 the tree vectorization optimizer can generate code | 82 // - With gcc 4.4 the tree vectorization optimizer can generate code |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 | 657 |
| 729 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 658 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
| 730 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 659 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); |
| 731 int result = pthread_setspecific(pthread_key, value); | 660 int result = pthread_setspecific(pthread_key, value); |
| 732 DCHECK_EQ(0, result); | 661 DCHECK_EQ(0, result); |
| 733 USE(result); | 662 USE(result); |
| 734 } | 663 } |
| 735 | 664 |
| 736 | 665 |
| 737 } } // namespace v8::base | 666 } } // namespace v8::base |
| OLD | NEW |