OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #include "platform-posix.h" | 69 #include "platform-posix.h" |
70 #include "platform.h" | 70 #include "platform.h" |
71 #include "v8threads.h" | 71 #include "v8threads.h" |
72 #include "vm-state-inl.h" | 72 #include "vm-state-inl.h" |
73 | 73 |
74 | 74 |
75 namespace v8 { | 75 namespace v8 { |
76 namespace internal { | 76 namespace internal { |
77 | 77 |
78 | 78 |
79 static Mutex* limit_mutex = NULL; | |
80 | |
81 | |
82 #ifdef __arm__ | 79 #ifdef __arm__ |
83 | 80 |
84 bool OS::ArmUsingHardFloat() { | 81 bool OS::ArmUsingHardFloat() { |
85 // GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify | 82 // GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify |
86 // the Floating Point ABI used (PCS stands for Procedure Call Standard). | 83 // the Floating Point ABI used (PCS stands for Procedure Call Standard). |
87 // We use these as well as a couple of other defines to statically determine | 84 // We use these as well as a couple of other defines to statically determine |
88 // what FP ABI used. | 85 // what FP ABI used. |
89 // GCC versions 4.4 and below don't support hard-fp. | 86 // GCC versions 4.4 and below don't support hard-fp. |
90 // GCC versions 4.5 may support hard-fp without defining __ARM_PCS or | 87 // GCC versions 4.5 may support hard-fp without defining __ARM_PCS or |
91 // __ARM_PCS_VFP. | 88 // __ARM_PCS_VFP. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 130 |
134 double OS::LocalTimeOffset() { | 131 double OS::LocalTimeOffset() { |
135 time_t tv = time(NULL); | 132 time_t tv = time(NULL); |
136 struct tm* t = localtime(&tv); | 133 struct tm* t = localtime(&tv); |
137 // tm_gmtoff includes any daylight savings offset, so subtract it. | 134 // tm_gmtoff includes any daylight savings offset, so subtract it. |
138 return static_cast<double>(t->tm_gmtoff * msPerSecond - | 135 return static_cast<double>(t->tm_gmtoff * msPerSecond - |
139 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); | 136 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); |
140 } | 137 } |
141 | 138 |
142 | 139 |
143 // We keep the lowest and highest addresses mapped as a quick way of | |
144 // determining that pointers are outside the heap (used mostly in assertions | |
145 // and verification). The estimate is conservative, i.e., not all addresses in | |
146 // 'allocated' space are actually allocated to our heap. The range is | |
147 // [lowest, highest), inclusive on the low and and exclusive on the high end. | |
148 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); | |
149 static void* highest_ever_allocated = reinterpret_cast<void*>(0); | |
150 | |
151 | |
152 static void UpdateAllocatedSpaceLimits(void* address, int size) { | |
153 ASSERT(limit_mutex != NULL); | |
154 LockGuard<Mutex> lock_guard(limit_mutex); | |
155 | |
156 lowest_ever_allocated = Min(lowest_ever_allocated, address); | |
157 highest_ever_allocated = | |
158 Max(highest_ever_allocated, | |
159 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); | |
160 } | |
161 | |
162 | |
163 bool OS::IsOutsideAllocatedSpace(void* address) { | |
164 return address < lowest_ever_allocated || address >= highest_ever_allocated; | |
165 } | |
166 | |
167 | |
168 void* OS::Allocate(const size_t requested, | 140 void* OS::Allocate(const size_t requested, |
169 size_t* allocated, | 141 size_t* allocated, |
170 bool is_executable) { | 142 bool is_executable) { |
171 const size_t msize = RoundUp(requested, AllocateAlignment()); | 143 const size_t msize = RoundUp(requested, AllocateAlignment()); |
172 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); | 144 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); |
173 void* addr = OS::GetRandomMmapAddr(); | 145 void* addr = OS::GetRandomMmapAddr(); |
174 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 146 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
175 if (mbase == MAP_FAILED) { | 147 if (mbase == MAP_FAILED) { |
176 LOG(i::Isolate::Current(), | 148 LOG(i::Isolate::Current(), |
177 StringEvent("OS::Allocate", "mmap failed")); | 149 StringEvent("OS::Allocate", "mmap failed")); |
178 return NULL; | 150 return NULL; |
179 } | 151 } |
180 *allocated = msize; | 152 *allocated = msize; |
181 UpdateAllocatedSpaceLimits(mbase, msize); | |
182 return mbase; | 153 return mbase; |
183 } | 154 } |
184 | 155 |
185 | 156 |
186 void OS::DumpBacktrace() { | 157 void OS::DumpBacktrace() { |
187 // backtrace is a glibc extension. | 158 // backtrace is a glibc extension. |
188 #if defined(__GLIBC__) && !defined(__UCLIBC__) | 159 #if defined(__GLIBC__) && !defined(__UCLIBC__) |
189 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace(); | 160 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace(); |
190 #endif | 161 #endif |
191 } | 162 } |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 #endif | 436 #endif |
466 if (MAP_FAILED == mmap(base, | 437 if (MAP_FAILED == mmap(base, |
467 size, | 438 size, |
468 prot, | 439 prot, |
469 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, | 440 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, |
470 kMmapFd, | 441 kMmapFd, |
471 kMmapFdOffset)) { | 442 kMmapFdOffset)) { |
472 return false; | 443 return false; |
473 } | 444 } |
474 | 445 |
475 UpdateAllocatedSpaceLimits(base, size); | |
476 return true; | 446 return true; |
477 } | 447 } |
478 | 448 |
479 | 449 |
480 bool VirtualMemory::UncommitRegion(void* base, size_t size) { | 450 bool VirtualMemory::UncommitRegion(void* base, size_t size) { |
481 return mmap(base, | 451 return mmap(base, |
482 size, | 452 size, |
483 PROT_NONE, | 453 PROT_NONE, |
484 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED, | 454 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED, |
485 kMmapFd, | 455 kMmapFd, |
486 kMmapFdOffset) != MAP_FAILED; | 456 kMmapFdOffset) != MAP_FAILED; |
487 } | 457 } |
488 | 458 |
489 | 459 |
490 bool VirtualMemory::ReleaseRegion(void* base, size_t size) { | 460 bool VirtualMemory::ReleaseRegion(void* base, size_t size) { |
491 return munmap(base, size) == 0; | 461 return munmap(base, size) == 0; |
492 } | 462 } |
493 | 463 |
494 | 464 |
495 bool VirtualMemory::HasLazyCommits() { | 465 bool VirtualMemory::HasLazyCommits() { |
496 return true; | 466 return true; |
497 } | 467 } |
498 | 468 |
499 | 469 |
500 void OS::SetUp() { | 470 void OS::SetUp() { |
501 // Seed the random number generator. We preserve microsecond resolution. | 471 // Seed the random number generator. We preserve microsecond resolution. |
502 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()) ^ (getpid() << 16); | 472 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()) ^ (getpid() << 16); |
503 srandom(static_cast<unsigned int>(seed)); | 473 srandom(static_cast<unsigned int>(seed)); |
504 limit_mutex = new Mutex(); | |
505 } | 474 } |
506 | 475 |
507 | 476 |
508 void OS::TearDown() { | |
509 delete limit_mutex; | |
510 } | |
511 | |
512 | |
513 } } // namespace v8::internal | 477 } } // namespace v8::internal |
OLD | NEW |