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 <errno.h> | 9 #include <errno.h> |
10 #include <limits.h> | 10 #include <limits.h> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #endif | 48 #endif |
49 | 49 |
50 #if V8_OS_MACOSX | 50 #if V8_OS_MACOSX |
51 #include <dlfcn.h> | 51 #include <dlfcn.h> |
52 #endif | 52 #endif |
53 | 53 |
54 #if V8_OS_LINUX | 54 #if V8_OS_LINUX |
55 #include <sys/prctl.h> // NOLINT, for prctl | 55 #include <sys/prctl.h> // NOLINT, for prctl |
56 #endif | 56 #endif |
57 | 57 |
58 #if !V8_OS_NACL | 58 #if !defined(V8_OS_NACL) && !defined(_AIX) |
59 #include <sys/syscall.h> | 59 #include <sys/syscall.h> |
60 #endif | 60 #endif |
61 | 61 |
62 namespace v8 { | 62 namespace v8 { |
63 namespace base { | 63 namespace base { |
64 | 64 |
65 namespace { | 65 namespace { |
66 | 66 |
67 // 0 is never a valid thread id. | 67 // 0 is never a valid thread id. |
68 const pthread_t kNoThread = (pthread_t) 0; | 68 const pthread_t kNoThread = (pthread_t) 0; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 #endif | 165 #endif |
166 uintptr_t raw_addr; | 166 uintptr_t raw_addr; |
167 platform_random_number_generator.Pointer()->NextBytes(&raw_addr, | 167 platform_random_number_generator.Pointer()->NextBytes(&raw_addr, |
168 sizeof(raw_addr)); | 168 sizeof(raw_addr)); |
169 #if V8_TARGET_ARCH_X64 | 169 #if V8_TARGET_ARCH_X64 |
170 // Currently available CPUs have 48 bits of virtual addressing. Truncate | 170 // Currently available CPUs have 48 bits of virtual addressing. Truncate |
171 // the hint address to 46 bits to give the kernel a fighting chance of | 171 // the hint address to 46 bits to give the kernel a fighting chance of |
172 // fulfilling our placement request. | 172 // fulfilling our placement request. |
173 raw_addr &= V8_UINT64_C(0x3ffffffff000); | 173 raw_addr &= V8_UINT64_C(0x3ffffffff000); |
174 #elif V8_TARGET_ARCH_PPC64 | 174 #elif V8_TARGET_ARCH_PPC64 |
175 #if V8_TARGET_BIG_ENDIAN | 175 #if V8_OS_AIX |
| 176 // AIX: 64 bits of virtual addressing, but we limit address range to: |
| 177 // a) minimize Segment Lookaside Buffer (SLB) misses and |
| 178 raw_addr &= V8_UINT64_C(0x3ffff000); |
| 179 // Use extra address space to isolate the mmap regions. |
| 180 raw_addr += V8_UINT64_C(0x400000000000); |
| 181 #elif V8_TARGET_BIG_ENDIAN |
176 // Big-endian Linux: 44 bits of virtual addressing. | 182 // Big-endian Linux: 44 bits of virtual addressing. |
177 raw_addr &= V8_UINT64_C(0x03fffffff000); | 183 raw_addr &= V8_UINT64_C(0x03fffffff000); |
178 #else | 184 #else |
179 // Little-endian Linux: 48 bits of virtual addressing. | 185 // Little-endian Linux: 48 bits of virtual addressing. |
180 raw_addr &= V8_UINT64_C(0x3ffffffff000); | 186 raw_addr &= V8_UINT64_C(0x3ffffffff000); |
181 #endif | 187 #endif |
182 #else | 188 #else |
183 raw_addr &= 0x3ffff000; | 189 raw_addr &= 0x3ffff000; |
184 | 190 |
185 # ifdef __sun | 191 # ifdef __sun |
186 // For our Solaris/illumos mmap hint, we pick a random address in the bottom | 192 // For our Solaris/illumos mmap hint, we pick a random address in the bottom |
187 // half of the top half of the address space (that is, the third quarter). | 193 // half of the top half of the address space (that is, the third quarter). |
188 // Because we do not MAP_FIXED, this will be treated only as a hint -- the | 194 // Because we do not MAP_FIXED, this will be treated only as a hint -- the |
189 // system will not fail to mmap() because something else happens to already | 195 // system will not fail to mmap() because something else happens to already |
190 // be mapped at our random address. We deliberately set the hint high enough | 196 // be mapped at our random address. We deliberately set the hint high enough |
191 // to get well above the system's break (that is, the heap); Solaris and | 197 // to get well above the system's break (that is, the heap); Solaris and |
192 // illumos will try the hint and if that fails allocate as if there were | 198 // illumos will try the hint and if that fails allocate as if there were |
193 // no hint at all. The high hint prevents the break from getting hemmed in | 199 // no hint at all. The high hint prevents the break from getting hemmed in |
194 // at low values, ceding half of the address space to the system heap. | 200 // at low values, ceding half of the address space to the system heap. |
195 raw_addr += 0x80000000; | 201 raw_addr += 0x80000000; |
| 202 #elif V8_OS_AIX |
| 203 // The range 0x30000000 - 0xD0000000 is available on AIX; |
| 204 // choose the upper range. |
| 205 raw_addr += 0x90000000; |
196 # else | 206 # else |
197 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a | 207 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a |
198 // variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos | 208 // variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos |
199 // 10.6 and 10.7. | 209 // 10.6 and 10.7. |
200 raw_addr += 0x20000000; | 210 raw_addr += 0x20000000; |
201 # endif | 211 # endif |
202 #endif | 212 #endif |
203 return reinterpret_cast<void*>(raw_addr); | 213 return reinterpret_cast<void*>(raw_addr); |
204 } | 214 } |
205 | 215 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 264 } |
255 | 265 |
256 | 266 |
257 int OS::GetCurrentThreadId() { | 267 int OS::GetCurrentThreadId() { |
258 #if V8_OS_MACOSX || (V8_OS_ANDROID && defined(__APPLE__)) | 268 #if V8_OS_MACOSX || (V8_OS_ANDROID && defined(__APPLE__)) |
259 return static_cast<int>(pthread_mach_thread_np(pthread_self())); | 269 return static_cast<int>(pthread_mach_thread_np(pthread_self())); |
260 #elif V8_OS_LINUX | 270 #elif V8_OS_LINUX |
261 return static_cast<int>(syscall(__NR_gettid)); | 271 return static_cast<int>(syscall(__NR_gettid)); |
262 #elif V8_OS_ANDROID | 272 #elif V8_OS_ANDROID |
263 return static_cast<int>(gettid()); | 273 return static_cast<int>(gettid()); |
| 274 #elif V8_OS_AIX |
| 275 return static_cast<int>(thread_self()); |
264 #else | 276 #else |
265 return static_cast<int>(reinterpret_cast<intptr_t>(pthread_self())); | 277 return static_cast<int>(reinterpret_cast<intptr_t>(pthread_self())); |
266 #endif | 278 #endif |
267 } | 279 } |
268 | 280 |
269 | 281 |
270 // ---------------------------------------------------------------------------- | 282 // ---------------------------------------------------------------------------- |
271 // POSIX date/time support. | 283 // POSIX date/time support. |
272 // | 284 // |
273 | 285 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 529 |
518 | 530 |
519 void Thread::Start() { | 531 void Thread::Start() { |
520 int result; | 532 int result; |
521 pthread_attr_t attr; | 533 pthread_attr_t attr; |
522 memset(&attr, 0, sizeof(attr)); | 534 memset(&attr, 0, sizeof(attr)); |
523 result = pthread_attr_init(&attr); | 535 result = pthread_attr_init(&attr); |
524 DCHECK_EQ(0, result); | 536 DCHECK_EQ(0, result); |
525 // Native client uses default stack size. | 537 // Native client uses default stack size. |
526 #if !V8_OS_NACL | 538 #if !V8_OS_NACL |
527 if (stack_size_ > 0) { | 539 size_t stack_size = stack_size_; |
528 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); | 540 #if V8_OS_AIX |
| 541 if (stack_size == 0) { |
| 542 // Default on AIX is 96KB -- bump up to 2MB |
| 543 stack_size = 2 * 1024 * 1024; |
| 544 } |
| 545 #endif |
| 546 if (stack_size > 0) { |
| 547 result = pthread_attr_setstacksize(&attr, stack_size); |
529 DCHECK_EQ(0, result); | 548 DCHECK_EQ(0, result); |
530 } | 549 } |
531 #endif | 550 #endif |
532 { | 551 { |
533 LockGuard<Mutex> lock_guard(&data_->thread_creation_mutex_); | 552 LockGuard<Mutex> lock_guard(&data_->thread_creation_mutex_); |
534 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); | 553 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); |
535 } | 554 } |
536 DCHECK_EQ(0, result); | 555 DCHECK_EQ(0, result); |
537 result = pthread_attr_destroy(&attr); | 556 result = pthread_attr_destroy(&attr); |
538 DCHECK_EQ(0, result); | 557 DCHECK_EQ(0, result); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 | 690 |
672 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 691 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
673 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 692 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); |
674 int result = pthread_setspecific(pthread_key, value); | 693 int result = pthread_setspecific(pthread_key, value); |
675 DCHECK_EQ(0, result); | 694 DCHECK_EQ(0, result); |
676 USE(result); | 695 USE(result); |
677 } | 696 } |
678 | 697 |
679 | 698 |
680 } } // namespace v8::base | 699 } } // namespace v8::base |
OLD | NEW |