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

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

Issue 7865025: Move aligned allocation to the platform files. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Removed leftover debug code. Created 9 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-macos.cc ('k') | src/spaces.h » ('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 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 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 #endif 1390 #endif
1391 } 1391 }
1392 1392
1393 1393
1394 void OS::ReleaseStore(volatile AtomicWord* ptr, AtomicWord value) { 1394 void OS::ReleaseStore(volatile AtomicWord* ptr, AtomicWord value) {
1395 MemoryBarrier(); 1395 MemoryBarrier();
1396 *ptr = value; 1396 *ptr = value;
1397 } 1397 }
1398 1398
1399 1399
1400 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
1401
1402
1403 VirtualMemory::VirtualMemory(size_t size)
1404 : address_(ReserveRegion(size)), size_(size) { }
1405
1406
1407 VirtualMemory::VirtualMemory(size_t size, size_t alignment)
1408 : address_(NULL), size_(0) {
1409 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
1410 size_t request_size = RoundUp(size + alignment,
1411 static_cast<intptr_t>(OS::AllocateAlignment()));
1412 void* address = ReserveRegion(request_size);
1413 if (address == NULL) return;
1414 Address base = RoundUp(static_cast<Address>(address), alignment);
1415 // Try reducing the size by freeing and then reallocating a specific area.
1416 ReleaseRegion(address, request_size);
1417 address = VirtualAlloc(base, size, MEM_RESERVE, PAGE_NOACCESS);
1418 if (address != NULL) {
1419 request_size = size;
1420 ASSERT(base == static_cast<Address>(address));
1421 } else {
1422 // Resizing failed, just go with a bigger area.
1423 address = ReserveRegion(request_size);
1424 if (address == NULL) return;
1425 }
1426 address_ = address;
1427 size_ = request_size;
1428 }
1429
1430
1431 VirtualMemory::~VirtualMemory() {
1432 if (IsReserved()) {
1433 bool result = ReleaseRegion(address_, size_);
1434 ASSERT(result);
1435 USE(result);
1436 }
1437 }
1438
1439
1400 bool VirtualMemory::IsReserved() { 1440 bool VirtualMemory::IsReserved() {
1401 return address_ != NULL; 1441 return address_ != NULL;
1402 } 1442 }
1403 1443
1404 1444
1405 VirtualMemory::VirtualMemory(size_t size) { 1445 void VirtualMemory::Reset() {
1406 address_ = ReserveRegion(size); 1446 address_ = NULL;
1407 size_ = size; 1447 size_ = 0;
1408 }
1409
1410
1411 VirtualMemory::~VirtualMemory() {
1412 if (IsReserved()) {
1413 if (0 == VirtualFree(address(), 0, MEM_RELEASE)) address_ = NULL;
1414 }
1415 } 1448 }
1416 1449
1417 1450
1418 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) { 1451 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
1419 if (CommitRegion(address, size, is_executable)) { 1452 if (CommitRegion(address, size, is_executable)) {
1420 UpdateAllocatedSpaceLimits(address, static_cast<int>(size)); 1453 UpdateAllocatedSpaceLimits(address, static_cast<int>(size));
1421 return true; 1454 return true;
1422 } 1455 }
1423 return false; 1456 return false;
1424 } 1457 }
(...skipping 15 matching lines...) Expand all
1440 if (NULL == VirtualAlloc(base, size, MEM_COMMIT, prot)) { 1473 if (NULL == VirtualAlloc(base, size, MEM_COMMIT, prot)) {
1441 return false; 1474 return false;
1442 } 1475 }
1443 1476
1444 UpdateAllocatedSpaceLimits(base, static_cast<int>(size)); 1477 UpdateAllocatedSpaceLimits(base, static_cast<int>(size));
1445 return true; 1478 return true;
1446 } 1479 }
1447 1480
1448 1481
1449 bool VirtualMemory::UncommitRegion(void* base, size_t size) { 1482 bool VirtualMemory::UncommitRegion(void* base, size_t size) {
1450 return VirtualFree(base, size, MEM_DECOMMIT) != false; 1483 return VirtualFree(base, size, MEM_DECOMMIT) != 0;
1451 } 1484 }
1452 1485
1453 1486
1454 bool VirtualMemory::ReleaseRegion(void* base, size_t size) { 1487 bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
1455 return VirtualFree(base, size, MEM_DECOMMIT) != false; 1488 return VirtualFree(base, 0, MEM_RELEASE) != 0;
1456 } 1489 }
1457 1490
1458 1491
1459 1492
1460 // ---------------------------------------------------------------------------- 1493 // ----------------------------------------------------------------------------
1461 // Win32 thread support. 1494 // Win32 thread support.
1462 1495
1463 // Definition of invalid thread handle and id. 1496 // Definition of invalid thread handle and id.
1464 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; 1497 static const HANDLE kNoThread = INVALID_HANDLE_VALUE;
1465 1498
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 2028
1996 2029
1997 void Sampler::Stop() { 2030 void Sampler::Stop() {
1998 ASSERT(IsActive()); 2031 ASSERT(IsActive());
1999 SamplerThread::RemoveActiveSampler(this); 2032 SamplerThread::RemoveActiveSampler(this);
2000 SetActive(false); 2033 SetActive(false);
2001 } 2034 }
2002 2035
2003 2036
2004 } } // namespace v8::internal 2037 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-macos.cc ('k') | src/spaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698