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