OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 if (-1.0 < x && x < 0.0) { | 85 if (-1.0 < x && x < 0.0) { |
86 return -0.0; | 86 return -0.0; |
87 } else { | 87 } else { |
88 return ceil(x); | 88 return ceil(x); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 | 92 |
93 static Mutex* limit_mutex = NULL; | 93 static Mutex* limit_mutex = NULL; |
94 | 94 |
95 | |
Vyacheslav Egorov (Chromium)
2011/10/10 14:13:14
accidentally deleted new line
| |
96 void OS::Setup() { | 95 void OS::Setup() { |
97 // Seed the random number generator. | 96 // Seed the random number generator. We preserve microsecond resolution. |
98 // Convert the current time to a 64-bit integer first, before converting it | 97 uint64_t seed = Ticks() ^ (getpid() << 16); |
99 // to an unsigned. Going directly will cause an overflow and the seed to be | |
100 // set to all ones. The seed will be identical for different instances that | |
101 // call this setup code within the same millisecond. | |
102 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); | |
103 srandom(static_cast<unsigned int>(seed)); | 98 srandom(static_cast<unsigned int>(seed)); |
104 limit_mutex = CreateMutex(); | 99 limit_mutex = CreateMutex(); |
105 } | 100 } |
106 | 101 |
107 | 102 |
108 // We keep the lowest and highest addresses mapped as a quick way of | 103 // We keep the lowest and highest addresses mapped as a quick way of |
109 // determining that pointers are outside the heap (used mostly in assertions | 104 // determining that pointers are outside the heap (used mostly in assertions |
110 // and verification). The estimate is conservative, ie, not all addresses in | 105 // and verification). The estimate is conservative, ie, not all addresses in |
111 // 'allocated' space are actually allocated to our heap. The range is | 106 // 'allocated' space are actually allocated to our heap. The range is |
112 // [lowest, highest), inclusive on the low and and exclusive on the high end. | 107 // [lowest, highest), inclusive on the low and and exclusive on the high end. |
(...skipping 28 matching lines...) Expand all Loading... | |
141 // tools like vmmap(1). | 136 // tools like vmmap(1). |
142 static const int kMmapFd = VM_MAKE_TAG(255); | 137 static const int kMmapFd = VM_MAKE_TAG(255); |
143 static const off_t kMmapFdOffset = 0; | 138 static const off_t kMmapFdOffset = 0; |
144 | 139 |
145 | 140 |
146 void* OS::Allocate(const size_t requested, | 141 void* OS::Allocate(const size_t requested, |
147 size_t* allocated, | 142 size_t* allocated, |
148 bool is_executable) { | 143 bool is_executable) { |
149 const size_t msize = RoundUp(requested, getpagesize()); | 144 const size_t msize = RoundUp(requested, getpagesize()); |
150 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); | 145 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); |
151 void* mbase = mmap(NULL, msize, prot, | 146 void* mbase = mmap(OS::GetRandomMmapAddr(), |
147 msize, | |
148 prot, | |
152 MAP_PRIVATE | MAP_ANON, | 149 MAP_PRIVATE | MAP_ANON, |
153 kMmapFd, kMmapFdOffset); | 150 kMmapFd, |
151 kMmapFdOffset); | |
154 if (mbase == MAP_FAILED) { | 152 if (mbase == MAP_FAILED) { |
155 LOG(Isolate::Current(), StringEvent("OS::Allocate", "mmap failed")); | 153 LOG(Isolate::Current(), StringEvent("OS::Allocate", "mmap failed")); |
156 return NULL; | 154 return NULL; |
157 } | 155 } |
158 *allocated = msize; | 156 *allocated = msize; |
159 UpdateAllocatedSpaceLimits(mbase, msize); | 157 UpdateAllocatedSpaceLimits(mbase, msize); |
160 return mbase; | 158 return mbase; |
161 } | 159 } |
162 | 160 |
163 | 161 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 | 198 |
201 | 199 |
202 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { | 200 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { |
203 FILE* file = fopen(name, "r+"); | 201 FILE* file = fopen(name, "r+"); |
204 if (file == NULL) return NULL; | 202 if (file == NULL) return NULL; |
205 | 203 |
206 fseek(file, 0, SEEK_END); | 204 fseek(file, 0, SEEK_END); |
207 int size = ftell(file); | 205 int size = ftell(file); |
208 | 206 |
209 void* memory = | 207 void* memory = |
210 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); | 208 mmap(OS::GetRandomMmapAddr(), |
209 size, | |
210 PROT_READ | PROT_WRITE, | |
211 MAP_SHARED, | |
212 fileno(file), | |
213 0); | |
211 return new PosixMemoryMappedFile(file, memory, size); | 214 return new PosixMemoryMappedFile(file, memory, size); |
212 } | 215 } |
213 | 216 |
214 | 217 |
215 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, | 218 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, |
216 void* initial) { | 219 void* initial) { |
217 FILE* file = fopen(name, "w+"); | 220 FILE* file = fopen(name, "w+"); |
218 if (file == NULL) return NULL; | 221 if (file == NULL) return NULL; |
219 int result = fwrite(initial, size, 1, file); | 222 int result = fwrite(initial, size, 1, file); |
220 if (result < 1) { | 223 if (result < 1) { |
221 fclose(file); | 224 fclose(file); |
222 return NULL; | 225 return NULL; |
223 } | 226 } |
224 void* memory = | 227 void* memory = |
225 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); | 228 mmap(OS::GetRandomMmapAddr(), |
229 size, | |
230 PROT_READ | PROT_WRITE, | |
231 MAP_SHARED, | |
232 fileno(file), | |
233 0); | |
226 return new PosixMemoryMappedFile(file, memory, size); | 234 return new PosixMemoryMappedFile(file, memory, size); |
227 } | 235 } |
228 | 236 |
229 | 237 |
230 PosixMemoryMappedFile::~PosixMemoryMappedFile() { | 238 PosixMemoryMappedFile::~PosixMemoryMappedFile() { |
231 if (memory_) OS::Free(memory_, size_); | 239 if (memory_) OS::Free(memory_, size_); |
232 fclose(file_); | 240 fclose(file_); |
233 } | 241 } |
234 | 242 |
235 | 243 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 | 347 |
340 VirtualMemory::VirtualMemory(size_t size) | 348 VirtualMemory::VirtualMemory(size_t size) |
341 : address_(ReserveRegion(size)), size_(size) { } | 349 : address_(ReserveRegion(size)), size_(size) { } |
342 | 350 |
343 | 351 |
344 VirtualMemory::VirtualMemory(size_t size, size_t alignment) | 352 VirtualMemory::VirtualMemory(size_t size, size_t alignment) |
345 : address_(NULL), size_(0) { | 353 : address_(NULL), size_(0) { |
346 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); | 354 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); |
347 size_t request_size = RoundUp(size + alignment, | 355 size_t request_size = RoundUp(size + alignment, |
348 static_cast<intptr_t>(OS::AllocateAlignment())); | 356 static_cast<intptr_t>(OS::AllocateAlignment())); |
349 void* reservation = mmap(NULL, | 357 void* reservation = mmap(OS::GetRandomMmapAddr(), |
350 request_size, | 358 request_size, |
351 PROT_NONE, | 359 PROT_NONE, |
352 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, | 360 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, |
353 kMmapFd, | 361 kMmapFd, |
354 kMmapFdOffset); | 362 kMmapFdOffset); |
355 if (reservation == MAP_FAILED) return; | 363 if (reservation == MAP_FAILED) return; |
356 | 364 |
357 Address base = static_cast<Address>(reservation); | 365 Address base = static_cast<Address>(reservation); |
358 Address aligned_base = RoundUp(base, alignment); | 366 Address aligned_base = RoundUp(base, alignment); |
359 ASSERT_LE(base, aligned_base); | 367 ASSERT_LE(base, aligned_base); |
(...skipping 30 matching lines...) Expand all Loading... | |
390 } | 398 } |
391 | 399 |
392 | 400 |
393 void VirtualMemory::Reset() { | 401 void VirtualMemory::Reset() { |
394 address_ = NULL; | 402 address_ = NULL; |
395 size_ = 0; | 403 size_ = 0; |
396 } | 404 } |
397 | 405 |
398 | 406 |
399 void* VirtualMemory::ReserveRegion(size_t size) { | 407 void* VirtualMemory::ReserveRegion(size_t size) { |
400 void* result = mmap(NULL, | 408 void* result = mmap(OS::GetRandomMmapAddr(), |
401 size, | 409 size, |
402 PROT_NONE, | 410 PROT_NONE, |
403 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, | 411 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, |
404 kMmapFd, | 412 kMmapFd, |
405 kMmapFdOffset); | 413 kMmapFdOffset); |
406 | 414 |
407 if (result == MAP_FAILED) return NULL; | 415 if (result == MAP_FAILED) return NULL; |
408 | 416 |
409 return result; | 417 return result; |
410 } | 418 } |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 | 887 |
880 | 888 |
881 void Sampler::Stop() { | 889 void Sampler::Stop() { |
882 ASSERT(IsActive()); | 890 ASSERT(IsActive()); |
883 SamplerThread::RemoveActiveSampler(this); | 891 SamplerThread::RemoveActiveSampler(this); |
884 SetActive(false); | 892 SetActive(false); |
885 } | 893 } |
886 | 894 |
887 | 895 |
888 } } // namespace v8::internal | 896 } } // namespace v8::internal |
OLD | NEW |