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

Side by Side Diff: src/platform-cygwin.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.h ('k') | src/platform-freebsd.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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "platform.h" 45 #include "platform.h"
46 #include "simulator.h" 46 #include "simulator.h"
47 #include "v8threads.h" 47 #include "v8threads.h"
48 #include "vm-state-inl.h" 48 #include "vm-state-inl.h"
49 #include "win32-headers.h" 49 #include "win32-headers.h"
50 50
51 namespace v8 { 51 namespace v8 {
52 namespace internal { 52 namespace internal {
53 53
54 54
55 static Mutex* limit_mutex = NULL;
56
57
58 const char* OS::LocalTimezone(double time) { 55 const char* OS::LocalTimezone(double time) {
59 if (std::isnan(time)) return ""; 56 if (std::isnan(time)) return "";
60 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); 57 time_t tv = static_cast<time_t>(floor(time/msPerSecond));
61 struct tm* t = localtime(&tv); 58 struct tm* t = localtime(&tv);
62 if (NULL == t) return ""; 59 if (NULL == t) return "";
63 return tzname[0]; // The location of the timezone string on Cygwin. 60 return tzname[0]; // The location of the timezone string on Cygwin.
64 } 61 }
65 62
66 63
67 double OS::LocalTimeOffset() { 64 double OS::LocalTimeOffset() {
68 // On Cygwin, struct tm does not contain a tm_gmtoff field. 65 // On Cygwin, struct tm does not contain a tm_gmtoff field.
69 time_t utc = time(NULL); 66 time_t utc = time(NULL);
70 ASSERT(utc != -1); 67 ASSERT(utc != -1);
71 struct tm* loc = localtime(&utc); 68 struct tm* loc = localtime(&utc);
72 ASSERT(loc != NULL); 69 ASSERT(loc != NULL);
73 // time - localtime includes any daylight savings offset, so subtract it. 70 // time - localtime includes any daylight savings offset, so subtract it.
74 return static_cast<double>((mktime(loc) - utc) * msPerSecond - 71 return static_cast<double>((mktime(loc) - utc) * msPerSecond -
75 (loc->tm_isdst > 0 ? 3600 * msPerSecond : 0)); 72 (loc->tm_isdst > 0 ? 3600 * msPerSecond : 0));
76 } 73 }
77 74
78 75
79 // We keep the lowest and highest addresses mapped as a quick way of
80 // determining that pointers are outside the heap (used mostly in assertions
81 // and verification). The estimate is conservative, i.e., not all addresses in
82 // 'allocated' space are actually allocated to our heap. The range is
83 // [lowest, highest), inclusive on the low and and exclusive on the high end.
84 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1);
85 static void* highest_ever_allocated = reinterpret_cast<void*>(0);
86
87
88 static void UpdateAllocatedSpaceLimits(void* address, int size) {
89 ASSERT(limit_mutex != NULL);
90 LockGuard<Mutex> lock_guard(limit_mutex);
91
92 lowest_ever_allocated = Min(lowest_ever_allocated, address);
93 highest_ever_allocated =
94 Max(highest_ever_allocated,
95 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size));
96 }
97
98
99 bool OS::IsOutsideAllocatedSpace(void* address) {
100 return address < lowest_ever_allocated || address >= highest_ever_allocated;
101 }
102
103
104 void* OS::Allocate(const size_t requested, 76 void* OS::Allocate(const size_t requested,
105 size_t* allocated, 77 size_t* allocated,
106 bool is_executable) { 78 bool is_executable) {
107 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE)); 79 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE));
108 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 80 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
109 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 81 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
110 if (mbase == MAP_FAILED) { 82 if (mbase == MAP_FAILED) {
111 LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed")); 83 LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed"));
112 return NULL; 84 return NULL;
113 } 85 }
114 *allocated = msize; 86 *allocated = msize;
115 UpdateAllocatedSpaceLimits(mbase, msize);
116 return mbase; 87 return mbase;
117 } 88 }
118 89
119 90
120 void OS::DumpBacktrace() { 91 void OS::DumpBacktrace() {
121 // Currently unsupported. 92 // Currently unsupported.
122 } 93 }
123 94
124 95
125 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 96 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 void* VirtualMemory::ReserveRegion(size_t size) { 329 void* VirtualMemory::ReserveRegion(size_t size) {
359 return RandomizedVirtualAlloc(size, MEM_RESERVE, PAGE_NOACCESS); 330 return RandomizedVirtualAlloc(size, MEM_RESERVE, PAGE_NOACCESS);
360 } 331 }
361 332
362 333
363 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { 334 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
364 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; 335 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
365 if (NULL == VirtualAlloc(base, size, MEM_COMMIT, prot)) { 336 if (NULL == VirtualAlloc(base, size, MEM_COMMIT, prot)) {
366 return false; 337 return false;
367 } 338 }
368
369 UpdateAllocatedSpaceLimits(base, static_cast<int>(size));
370 return true; 339 return true;
371 } 340 }
372 341
373 342
374 bool VirtualMemory::Guard(void* address) { 343 bool VirtualMemory::Guard(void* address) {
375 if (NULL == VirtualAlloc(address, 344 if (NULL == VirtualAlloc(address,
376 OS::CommitPageSize(), 345 OS::CommitPageSize(),
377 MEM_COMMIT, 346 MEM_COMMIT,
378 PAGE_READONLY | PAGE_GUARD)) { 347 PAGE_READONLY | PAGE_GUARD)) {
379 return false; 348 return false;
(...skipping 19 matching lines...) Expand all
399 368
400 369
401 void OS::SetUp() { 370 void OS::SetUp() {
402 // Seed the random number generator. 371 // Seed the random number generator.
403 // Convert the current time to a 64-bit integer first, before converting it 372 // Convert the current time to a 64-bit integer first, before converting it
404 // to an unsigned. Going directly can cause an overflow and the seed to be 373 // to an unsigned. Going directly can cause an overflow and the seed to be
405 // set to all ones. The seed will be identical for different instances that 374 // set to all ones. The seed will be identical for different instances that
406 // call this setup code within the same millisecond. 375 // call this setup code within the same millisecond.
407 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); 376 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
408 srandom(static_cast<unsigned int>(seed)); 377 srandom(static_cast<unsigned int>(seed));
409 limit_mutex = new Mutex();
410 } 378 }
411 379
412 380
413 void OS::TearDown() {
414 delete limit_mutex;
415 }
416
417
418 } } // namespace v8::internal 381 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform.h ('k') | src/platform-freebsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698