| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 return -0.0; | 89 return -0.0; |
| 90 } else { | 90 } else { |
| 91 return ceil(x); | 91 return ceil(x); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 | 95 |
| 96 static Mutex* limit_mutex = NULL; | 96 static Mutex* limit_mutex = NULL; |
| 97 | 97 |
| 98 | 98 |
| 99 void OS::PostSetUp() { | |
| 100 POSIXPostSetUp(); | |
| 101 } | |
| 102 | |
| 103 | |
| 104 // We keep the lowest and highest addresses mapped as a quick way of | 99 // We keep the lowest and highest addresses mapped as a quick way of |
| 105 // determining that pointers are outside the heap (used mostly in assertions | 100 // determining that pointers are outside the heap (used mostly in assertions |
| 106 // and verification). The estimate is conservative, i.e., not all addresses in | 101 // and verification). The estimate is conservative, i.e., not all addresses in |
| 107 // 'allocated' space are actually allocated to our heap. The range is | 102 // 'allocated' space are actually allocated to our heap. The range is |
| 108 // [lowest, highest), inclusive on the low and and exclusive on the high end. | 103 // [lowest, highest), inclusive on the low and and exclusive on the high end. |
| 109 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); | 104 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); |
| 110 static void* highest_ever_allocated = reinterpret_cast<void*>(0); | 105 static void* highest_ever_allocated = reinterpret_cast<void*>(0); |
| 111 | 106 |
| 112 | 107 |
| 113 static void UpdateAllocatedSpaceLimits(void* address, int size) { | 108 static void UpdateAllocatedSpaceLimits(void* address, int size) { |
| 114 ASSERT(limit_mutex != NULL); | 109 ASSERT(limit_mutex != NULL); |
| 115 ScopedLock lock(limit_mutex); | 110 ScopedLock lock(limit_mutex); |
| 116 | 111 |
| 117 lowest_ever_allocated = Min(lowest_ever_allocated, address); | 112 lowest_ever_allocated = Min(lowest_ever_allocated, address); |
| 118 highest_ever_allocated = | 113 highest_ever_allocated = |
| 119 Max(highest_ever_allocated, | 114 Max(highest_ever_allocated, |
| 120 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); | 115 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); |
| 121 } | 116 } |
| 122 | 117 |
| 123 | 118 |
| 124 bool OS::IsOutsideAllocatedSpace(void* address) { | 119 bool OS::IsOutsideAllocatedSpace(void* address) { |
| 125 return address < lowest_ever_allocated || address >= highest_ever_allocated; | 120 return address < lowest_ever_allocated || address >= highest_ever_allocated; |
| 126 } | 121 } |
| 127 | 122 |
| 128 | 123 |
| 129 size_t OS::AllocateAlignment() { | |
| 130 return getpagesize(); | |
| 131 } | |
| 132 | |
| 133 | |
| 134 // Constants used for mmap. | 124 // Constants used for mmap. |
| 135 // kMmapFd is used to pass vm_alloc flags to tag the region with the user | 125 // kMmapFd is used to pass vm_alloc flags to tag the region with the user |
| 136 // defined tag 255 This helps identify V8-allocated regions in memory analysis | 126 // defined tag 255 This helps identify V8-allocated regions in memory analysis |
| 137 // tools like vmmap(1). | 127 // tools like vmmap(1). |
| 138 static const int kMmapFd = VM_MAKE_TAG(255); | 128 static const int kMmapFd = VM_MAKE_TAG(255); |
| 139 static const off_t kMmapFdOffset = 0; | 129 static const off_t kMmapFdOffset = 0; |
| 140 | 130 |
| 141 | 131 |
| 142 void* OS::Allocate(const size_t requested, | 132 void* OS::Allocate(const size_t requested, |
| 143 size_t* allocated, | 133 size_t* allocated, |
| 144 bool is_executable) { | 134 bool is_executable) { |
| 145 const size_t msize = RoundUp(requested, getpagesize()); | 135 const size_t msize = RoundUp(requested, getpagesize()); |
| 146 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); | 136 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); |
| 147 void* mbase = mmap(OS::GetRandomMmapAddr(), | 137 void* mbase = mmap(OS::GetRandomMmapAddr(), |
| 148 msize, | 138 msize, |
| 149 prot, | 139 prot, |
| 150 MAP_PRIVATE | MAP_ANON, | 140 MAP_PRIVATE | MAP_ANON, |
| 151 kMmapFd, | 141 kMmapFd, |
| 152 kMmapFdOffset); | 142 kMmapFdOffset); |
| 153 if (mbase == MAP_FAILED) { | 143 if (mbase == MAP_FAILED) { |
| 154 LOG(Isolate::Current(), StringEvent("OS::Allocate", "mmap failed")); | 144 LOG(Isolate::Current(), StringEvent("OS::Allocate", "mmap failed")); |
| 155 return NULL; | 145 return NULL; |
| 156 } | 146 } |
| 157 *allocated = msize; | 147 *allocated = msize; |
| 158 UpdateAllocatedSpaceLimits(mbase, msize); | 148 UpdateAllocatedSpaceLimits(mbase, msize); |
| 159 return mbase; | 149 return mbase; |
| 160 } | 150 } |
| 161 | 151 |
| 162 | 152 |
| 163 void OS::Free(void* address, const size_t size) { | |
| 164 // TODO(1240712): munmap has a return value which is ignored here. | |
| 165 int result = munmap(address, size); | |
| 166 USE(result); | |
| 167 ASSERT(result == 0); | |
| 168 } | |
| 169 | |
| 170 | |
| 171 void OS::Sleep(int milliseconds) { | |
| 172 usleep(1000 * milliseconds); | |
| 173 } | |
| 174 | |
| 175 | |
| 176 int OS::NumberOfCores() { | |
| 177 return sysconf(_SC_NPROCESSORS_ONLN); | |
| 178 } | |
| 179 | |
| 180 | |
| 181 void OS::Abort() { | |
| 182 // Redirect to std abort to signal abnormal program termination | |
| 183 abort(); | |
| 184 } | |
| 185 | |
| 186 | |
| 187 void OS::DebugBreak() { | |
| 188 asm("int $3"); | |
| 189 } | |
| 190 | |
| 191 | |
| 192 void OS::DumpBacktrace() { | 153 void OS::DumpBacktrace() { |
| 193 // If weak link to execinfo lib has failed, ie because we are on 10.4, abort. | 154 // If weak link to execinfo lib has failed, ie because we are on 10.4, abort. |
| 194 if (backtrace == NULL) return; | 155 if (backtrace == NULL) return; |
| 195 | 156 |
| 196 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace(); | 157 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace(); |
| 197 } | 158 } |
| 198 | 159 |
| 199 | 160 |
| 200 class PosixMemoryMappedFile : public OS::MemoryMappedFile { | 161 class PosixMemoryMappedFile : public OS::MemoryMappedFile { |
| 201 public: | 162 public: |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 limit_mutex = CreateMutex(); | 646 limit_mutex = CreateMutex(); |
| 686 } | 647 } |
| 687 | 648 |
| 688 | 649 |
| 689 void OS::TearDown() { | 650 void OS::TearDown() { |
| 690 delete limit_mutex; | 651 delete limit_mutex; |
| 691 } | 652 } |
| 692 | 653 |
| 693 | 654 |
| 694 } } // namespace v8::internal | 655 } } // namespace v8::internal |
| OLD | NEW |