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 OpenBSD and NetBSD goes here. For the | 5 // Platform-specific code for OpenBSD and NetBSD goes here. For the |
6 // POSIX-compatible parts, the implementation is in platform-posix.cc. | 6 // POSIX-compatible parts, the implementation is in platform-posix.cc. |
7 | 7 |
8 #include <pthread.h> | 8 #include <pthread.h> |
9 #include <semaphore.h> | 9 #include <semaphore.h> |
10 #include <signal.h> | 10 #include <signal.h> |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <sys/resource.h> | 12 #include <sys/resource.h> |
13 #include <sys/syscall.h> | 13 #include <sys/syscall.h> |
14 #include <sys/time.h> | 14 #include <sys/time.h> |
15 #include <sys/types.h> | 15 #include <sys/types.h> |
16 | 16 |
17 #include <errno.h> | 17 #include <errno.h> |
18 #include <fcntl.h> // open | 18 #include <fcntl.h> // open |
19 #include <stdarg.h> | 19 #include <stdarg.h> |
20 #include <strings.h> // index | 20 #include <strings.h> // index |
21 #include <sys/mman.h> // mmap & munmap | 21 #include <sys/mman.h> // mmap & munmap |
22 #include <sys/stat.h> // open | 22 #include <sys/stat.h> // open |
23 #include <sys/types.h> // mmap & munmap | 23 #include <sys/types.h> // mmap & munmap |
24 #include <unistd.h> // sysconf | 24 #include <unistd.h> // sysconf |
25 | 25 |
| 26 #include <cmath> |
| 27 |
26 #undef MAP_TYPE | 28 #undef MAP_TYPE |
27 | 29 |
28 #include "src/v8.h" | |
29 | |
30 #include "src/platform.h" | 30 #include "src/platform.h" |
| 31 #include "src/utils.h" |
31 | 32 |
32 | 33 |
33 namespace v8 { | 34 namespace v8 { |
34 namespace internal { | 35 namespace internal { |
35 | 36 |
36 | 37 |
37 const char* OS::LocalTimezone(double time, TimezoneCache* cache) { | 38 const char* OS::LocalTimezone(double time, TimezoneCache* cache) { |
38 if (std::isnan(time)) return ""; | 39 if (std::isnan(time)) return ""; |
39 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond)); | 40 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond)); |
40 struct tm* t = localtime(&tv); | 41 struct tm* t = localtime(&tv); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 void OS::SignalCodeMovingGC() { | 178 void OS::SignalCodeMovingGC() { |
178 // Support for ll_prof.py. | 179 // Support for ll_prof.py. |
179 // | 180 // |
180 // The Linux profiler built into the kernel logs all mmap's with | 181 // The Linux profiler built into the kernel logs all mmap's with |
181 // PROT_EXEC so that analysis tools can properly attribute ticks. We | 182 // PROT_EXEC so that analysis tools can properly attribute ticks. We |
182 // do a mmap with a name known by ll_prof.py and immediately munmap | 183 // do a mmap with a name known by ll_prof.py and immediately munmap |
183 // it. This injects a GC marker into the stream of events generated | 184 // it. This injects a GC marker into the stream of events generated |
184 // by the kernel and allows us to synchronize V8 code log and the | 185 // by the kernel and allows us to synchronize V8 code log and the |
185 // kernel log. | 186 // kernel log. |
186 int size = sysconf(_SC_PAGESIZE); | 187 int size = sysconf(_SC_PAGESIZE); |
187 FILE* f = fopen(FLAG_gc_fake_mmap, "w+"); | 188 FILE* f = fopen(OS::GetGCFakeMMapFile(), "w+"); |
188 if (f == NULL) { | 189 if (f == NULL) { |
189 OS::PrintError("Failed to open %s\n", FLAG_gc_fake_mmap); | 190 OS::PrintError("Failed to open %s\n", OS::GetGCFakeMMapFile()); |
190 OS::Abort(); | 191 OS::Abort(); |
191 } | 192 } |
192 void* addr = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_PRIVATE, | 193 void* addr = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_PRIVATE, |
193 fileno(f), 0); | 194 fileno(f), 0); |
194 ASSERT(addr != MAP_FAILED); | 195 ASSERT(addr != MAP_FAILED); |
195 OS::Free(addr, size); | 196 OS::Free(addr, size); |
196 fclose(f); | 197 fclose(f); |
197 } | 198 } |
198 | 199 |
199 | 200 |
(...skipping 16 matching lines...) Expand all Loading... |
216 size_t request_size = RoundUp(size + alignment, | 217 size_t request_size = RoundUp(size + alignment, |
217 static_cast<intptr_t>(OS::AllocateAlignment())); | 218 static_cast<intptr_t>(OS::AllocateAlignment())); |
218 void* reservation = mmap(OS::GetRandomMmapAddr(), | 219 void* reservation = mmap(OS::GetRandomMmapAddr(), |
219 request_size, | 220 request_size, |
220 PROT_NONE, | 221 PROT_NONE, |
221 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, | 222 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, |
222 kMmapFd, | 223 kMmapFd, |
223 kMmapFdOffset); | 224 kMmapFdOffset); |
224 if (reservation == MAP_FAILED) return; | 225 if (reservation == MAP_FAILED) return; |
225 | 226 |
226 Address base = static_cast<Address>(reservation); | 227 uint8_t* base = static_cast<uint8_t*>(reservation); |
227 Address aligned_base = RoundUp(base, alignment); | 228 uint8_t* aligned_base = RoundUp(base, alignment); |
228 ASSERT_LE(base, aligned_base); | 229 ASSERT_LE(base, aligned_base); |
229 | 230 |
230 // Unmap extra memory reserved before and after the desired block. | 231 // Unmap extra memory reserved before and after the desired block. |
231 if (aligned_base != base) { | 232 if (aligned_base != base) { |
232 size_t prefix_size = static_cast<size_t>(aligned_base - base); | 233 size_t prefix_size = static_cast<size_t>(aligned_base - base); |
233 OS::Free(base, prefix_size); | 234 OS::Free(base, prefix_size); |
234 request_size -= prefix_size; | 235 request_size -= prefix_size; |
235 } | 236 } |
236 | 237 |
237 size_t aligned_size = RoundUp(size, OS::AllocateAlignment()); | 238 size_t aligned_size = RoundUp(size, OS::AllocateAlignment()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 return munmap(base, size) == 0; | 329 return munmap(base, size) == 0; |
329 } | 330 } |
330 | 331 |
331 | 332 |
332 bool VirtualMemory::HasLazyCommits() { | 333 bool VirtualMemory::HasLazyCommits() { |
333 // TODO(alph): implement for the platform. | 334 // TODO(alph): implement for the platform. |
334 return false; | 335 return false; |
335 } | 336 } |
336 | 337 |
337 } } // namespace v8::internal | 338 } } // namespace v8::internal |
OLD | NEW |