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

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

Issue 14162004: Unified the structure of VirtualMemory implementations across platforms a bit. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 8 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 | « no previous file | 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 return 0; 312 return 0;
313 } 313 }
314 314
315 315
316 // The VirtualMemory implementation is taken from platform-win32.cc. 316 // The VirtualMemory implementation is taken from platform-win32.cc.
317 // The mmap-based virtual memory implementation as it is used on most posix 317 // The mmap-based virtual memory implementation as it is used on most posix
318 // platforms does not work well because Cygwin does not support MAP_FIXED. 318 // platforms does not work well because Cygwin does not support MAP_FIXED.
319 // This causes VirtualMemory::Commit to not always commit the memory region 319 // This causes VirtualMemory::Commit to not always commit the memory region
320 // specified. 320 // specified.
321 321
322 bool VirtualMemory::IsReserved() { 322 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
323 return address_ != NULL;
324 }
325 323
326 324
327 VirtualMemory::VirtualMemory(size_t size) { 325 VirtualMemory::VirtualMemory(size_t size)
328 address_ = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS); 326 : address_(ReserveRegion(size)), size_(size) { }
329 size_ = size;
330 }
331 327
332 328
333 VirtualMemory::~VirtualMemory() { 329 VirtualMemory::~VirtualMemory() {
334 if (IsReserved()) { 330 if (IsReserved()) {
335 if (0 == VirtualFree(address(), 0, MEM_RELEASE)) address_ = NULL; 331 if (0 == VirtualFree(address(), 0, MEM_RELEASE)) address_ = NULL;
336 } 332 }
337 } 333 }
338 334
339 335
336 bool VirtualMemory::IsReserved() {
337 return address_ != NULL;
338 }
339
340
341 void VirtualMemory::Reset() {
342 address_ = NULL;
343 size_ = 0;
344 }
345
346
340 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) { 347 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
341 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; 348 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
342 if (NULL == VirtualAlloc(address, size, MEM_COMMIT, prot)) { 349 if (NULL == VirtualAlloc(address, size, MEM_COMMIT, prot)) {
343 return false; 350 return false;
344 } 351 }
345 352
346 UpdateAllocatedSpaceLimits(address, static_cast<int>(size)); 353 UpdateAllocatedSpaceLimits(address, static_cast<int>(size));
347 return true; 354 return true;
348 } 355 }
349 356
350 357
351 bool VirtualMemory::Uncommit(void* address, size_t size) { 358 bool VirtualMemory::Uncommit(void* address, size_t size) {
352 ASSERT(IsReserved()); 359 ASSERT(IsReserved());
353 return VirtualFree(address, size, MEM_DECOMMIT) != false; 360 return VirtualFree(address, size, MEM_DECOMMIT) != false;
354 } 361 }
355 362
356 363
357 bool VirtualMemory::Guard(void* address) { 364 bool VirtualMemory::Guard(void* address) {
358 if (NULL == VirtualAlloc(address, 365 if (NULL == VirtualAlloc(address,
359 OS::CommitPageSize(), 366 OS::CommitPageSize(),
360 MEM_COMMIT, 367 MEM_COMMIT,
361 PAGE_READONLY | PAGE_GUARD)) { 368 PAGE_READONLY | PAGE_GUARD)) {
362 return false; 369 return false;
363 } 370 }
364 return true; 371 return true;
365 } 372 }
366 373
367 374
375 void* VirtualMemory::ReserveRegion(size_t size) {
376 return VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS);
377 }
378
379
380 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
381 UNIMPLEMENTED();
382 return false;
383 }
384
385
386 bool VirtualMemory::UncommitRegion(void* base, size_t size) {
387 UNIMPLEMENTED();
388 return false;
389 }
390
391
392 bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
393 UNIMPLEMENTED();
394 return false;
395 }
396
397
368 bool VirtualMemory::HasLazyCommits() { 398 bool VirtualMemory::HasLazyCommits() {
369 // TODO(alph): implement for the platform. 399 // TODO(alph): implement for the platform.
370 return false; 400 return false;
371 } 401 }
372 402
373 403
374 class Thread::PlatformData : public Malloced { 404 class Thread::PlatformData : public Malloced {
375 public: 405 public:
376 PlatformData() : thread_(kNoThread) {} 406 PlatformData() : thread_(kNoThread) {}
377 pthread_t thread_; // Thread handle for pthread. 407 pthread_t thread_; // Thread handle for pthread.
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 828
799 829
800 void Sampler::Stop() { 830 void Sampler::Stop() {
801 ASSERT(IsActive()); 831 ASSERT(IsActive());
802 SamplerThread::RemoveActiveSampler(this); 832 SamplerThread::RemoveActiveSampler(this);
803 SetActive(false); 833 SetActive(false);
804 } 834 }
805 835
806 836
807 } } // namespace v8::internal 837 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/platform-freebsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698