Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: src/platform-freebsd.cc

Issue 23903008: Drop OS::IsOutsideAllocatedSpace() and move the tracking to the MemoryAllocator. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix invalid calculation of committed memory boundaries. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-cygwin.cc ('k') | src/platform-linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 #include "platform-posix.h" 57 #include "platform-posix.h"
58 #include "platform.h" 58 #include "platform.h"
59 #include "vm-state-inl.h" 59 #include "vm-state-inl.h"
60 60
61 61
62 namespace v8 { 62 namespace v8 {
63 namespace internal { 63 namespace internal {
64 64
65 65
66 static Mutex* limit_mutex = NULL;
67
68
69 const char* OS::LocalTimezone(double time) { 66 const char* OS::LocalTimezone(double time) {
70 if (std::isnan(time)) return ""; 67 if (std::isnan(time)) return "";
71 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); 68 time_t tv = static_cast<time_t>(floor(time/msPerSecond));
72 struct tm* t = localtime(&tv); 69 struct tm* t = localtime(&tv);
73 if (NULL == t) return ""; 70 if (NULL == t) return "";
74 return t->tm_zone; 71 return t->tm_zone;
75 } 72 }
76 73
77 74
78 double OS::LocalTimeOffset() { 75 double OS::LocalTimeOffset() {
79 time_t tv = time(NULL); 76 time_t tv = time(NULL);
80 struct tm* t = localtime(&tv); 77 struct tm* t = localtime(&tv);
81 // tm_gmtoff includes any daylight savings offset, so subtract it. 78 // tm_gmtoff includes any daylight savings offset, so subtract it.
82 return static_cast<double>(t->tm_gmtoff * msPerSecond - 79 return static_cast<double>(t->tm_gmtoff * msPerSecond -
83 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); 80 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
84 } 81 }
85 82
86 83
87 // We keep the lowest and highest addresses mapped as a quick way of
88 // determining that pointers are outside the heap (used mostly in assertions
89 // and verification). The estimate is conservative, i.e., not all addresses in
90 // 'allocated' space are actually allocated to our heap. The range is
91 // [lowest, highest), inclusive on the low and and exclusive on the high end.
92 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1);
93 static void* highest_ever_allocated = reinterpret_cast<void*>(0);
94
95
96 static void UpdateAllocatedSpaceLimits(void* address, int size) {
97 ASSERT(limit_mutex != NULL);
98 LockGuard<Mutex> lock_guard(limit_mutex);
99
100 lowest_ever_allocated = Min(lowest_ever_allocated, address);
101 highest_ever_allocated =
102 Max(highest_ever_allocated,
103 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size));
104 }
105
106
107 bool OS::IsOutsideAllocatedSpace(void* address) {
108 return address < lowest_ever_allocated || address >= highest_ever_allocated;
109 }
110
111
112 void* OS::Allocate(const size_t requested, 84 void* OS::Allocate(const size_t requested,
113 size_t* allocated, 85 size_t* allocated,
114 bool executable) { 86 bool executable) {
115 const size_t msize = RoundUp(requested, getpagesize()); 87 const size_t msize = RoundUp(requested, getpagesize());
116 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); 88 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0);
117 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); 89 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0);
118 90
119 if (mbase == MAP_FAILED) { 91 if (mbase == MAP_FAILED) {
120 LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed")); 92 LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed"));
121 return NULL; 93 return NULL;
122 } 94 }
123 *allocated = msize; 95 *allocated = msize;
124 UpdateAllocatedSpaceLimits(mbase, msize);
125 return mbase; 96 return mbase;
126 } 97 }
127 98
128 99
129 void OS::DumpBacktrace() { 100 void OS::DumpBacktrace() {
130 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace(); 101 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace();
131 } 102 }
132 103
133 104
134 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 105 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { 309 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
339 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 310 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
340 if (MAP_FAILED == mmap(base, 311 if (MAP_FAILED == mmap(base,
341 size, 312 size,
342 prot, 313 prot,
343 MAP_PRIVATE | MAP_ANON | MAP_FIXED, 314 MAP_PRIVATE | MAP_ANON | MAP_FIXED,
344 kMmapFd, 315 kMmapFd,
345 kMmapFdOffset)) { 316 kMmapFdOffset)) {
346 return false; 317 return false;
347 } 318 }
348
349 UpdateAllocatedSpaceLimits(base, size);
350 return true; 319 return true;
351 } 320 }
352 321
353 322
354 bool VirtualMemory::UncommitRegion(void* base, size_t size) { 323 bool VirtualMemory::UncommitRegion(void* base, size_t size) {
355 return mmap(base, 324 return mmap(base,
356 size, 325 size,
357 PROT_NONE, 326 PROT_NONE,
358 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED, 327 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED,
359 kMmapFd, 328 kMmapFd,
(...skipping 13 matching lines...) Expand all
373 342
374 343
375 void OS::SetUp() { 344 void OS::SetUp() {
376 // Seed the random number generator. 345 // Seed the random number generator.
377 // Convert the current time to a 64-bit integer first, before converting it 346 // Convert the current time to a 64-bit integer first, before converting it
378 // to an unsigned. Going directly can cause an overflow and the seed to be 347 // to an unsigned. Going directly can cause an overflow and the seed to be
379 // set to all ones. The seed will be identical for different instances that 348 // set to all ones. The seed will be identical for different instances that
380 // call this setup code within the same millisecond. 349 // call this setup code within the same millisecond.
381 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); 350 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
382 srandom(static_cast<unsigned int>(seed)); 351 srandom(static_cast<unsigned int>(seed));
383 limit_mutex = new Mutex();
384 } 352 }
385 353
386 354
387 void OS::TearDown() {
388 delete limit_mutex;
389 }
390
391
392 } } // namespace v8::internal 355 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-cygwin.cc ('k') | src/platform-linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698