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-win32.cc

Issue 7865025: Move aligned allocation to the platform files. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Working on win32 too 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
OLDNEW
1 // Copyright 2006-2008 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
11 // with the distribution. 11 // with the distribution.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 // Test for infinity - usually defined in math.h 61 // Test for infinity - usually defined in math.h
62 int isinf(double x) { 62 int isinf(double x) {
63 return (_fpclass(x) & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0; 63 return (_fpclass(x) & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0;
64 } 64 }
65 65
66 66
67 // Test if x is less than y and both nominal - usually defined in math.h 67 // Test if x is less than y and both nominal - usually defined in math.h
68 int isless(double x, double y) { 68 int isless(double x, double y) {
69 return isnan(x) || isnan(y) ? 0 : x < y; 69 return isnan(x) || isnan(y) ? 0 : x < y;
70 } 70 }
Vyacheslav Egorov (Chromium) 2011/09/14 12:46:51 Accident edit?
Lasse Reichstein 2011/09/15 10:58:49 Also no edit here. Are you comparing to previous C
71 71
72 72
73 // Test if x is greater than y and both nominal - usually defined in math.h 73 // Test if x is greater than y and both nominal - usually defined in math.h
74 int isgreater(double x, double y) { 74 int isgreater(double x, double y) {
75 return isnan(x) || isnan(y) ? 0 : x > y; 75 return isnan(x) || isnan(y) ? 0 : x > y;
76 } 76 }
77 77
78 78
79 // Classify floating point number - usually defined in math.h 79 // Classify floating point number - usually defined in math.h
80 int fpclassify(double x) { 80 int fpclassify(double x) {
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 #endif 1458 #endif
1459 } 1459 }
1460 1460
1461 1461
1462 void OS::ReleaseStore(volatile AtomicWord* ptr, AtomicWord value) { 1462 void OS::ReleaseStore(volatile AtomicWord* ptr, AtomicWord value) {
1463 MemoryBarrier(); 1463 MemoryBarrier();
1464 *ptr = value; 1464 *ptr = value;
1465 } 1465 }
1466 1466
1467 1467
1468 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
1469
1470
1471 VirtualMemory::VirtualMemory(size_t size)
1472 : address_(ReserveRegion(size)), size_(size) { }
1473
1474
1475 VirtualMemory::VirtualMemory(size_t size, size_t alignment)
1476 : address_(NULL), size_(0) {
1477 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
1478 size_t request_size = RoundUp(size + alignment,
1479 static_cast<intptr_t>(OS::AllocateAlignment()));
1480 void* address = ReserveRegion(reserve_size);
1481 if (address == NULL) return;
1482 Address base = RoundUp(static_cast<Address>(address), alignment);
1483 // Try reducing the size by freeing and then reallocating a specific area.
1484 ReleaseRegion(address, request_size);
1485 address = VirtualAlloc(base, size, MEM_RESERVE, PAGE_NOACCESS);
1486 if (address != NULL) {
1487 request_size = size;
1488 ASSERT(base == static_cast<Address>(address));
1489 } else {
1490 // Resizing failed, just go with a bigger area.
1491 address = ReserveRegion(reserve_size);
1492 if (address == NULL) return;
1493 }
1494 address_ = address;
1495 size_ = request_size;
1496 }
1497
1498
1499 VirtualMemory::~VirtualMemory() {
1500 if (IsReserved()) {
1501 bool result = ReleaseRegion(address_, size_);
1502 ASSERT(result);
1503 USE(result);
1504 }
1505 }
1506
1507
1468 bool VirtualMemory::IsReserved() { 1508 bool VirtualMemory::IsReserved() {
1469 return address_ != NULL; 1509 return address_ != NULL;
1470 } 1510 }
1471 1511
1472 1512
1473 VirtualMemory::VirtualMemory(size_t size) { 1513 void VirtualMemory::Reset() {
1474 address_ = ReserveRegion(size); 1514 address_ = NULL;
1475 size_ = size; 1515 size_ = 0;
1476 }
1477
1478
1479 VirtualMemory::~VirtualMemory() {
1480 if (IsReserved()) {
1481 if (0 == VirtualFree(address(), 0, MEM_RELEASE)) address_ = NULL;
1482 }
1483 } 1516 }
1484 1517
1485 1518
1486 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) { 1519 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
1487 if (CommitRegion(address, size, is_executable)) { 1520 if (CommitRegion(address, size, is_executable)) {
1488 UpdateAllocatedSpaceLimits(address, static_cast<int>(size)); 1521 UpdateAllocatedSpaceLimits(address, static_cast<int>(size));
1489 return true; 1522 return true;
1490 } 1523 }
1491 return false; 1524 return false;
1492 } 1525 }
(...skipping 15 matching lines...) Expand all
1508 if (NULL == VirtualAlloc(base, size, MEM_COMMIT, prot)) { 1541 if (NULL == VirtualAlloc(base, size, MEM_COMMIT, prot)) {
1509 return false; 1542 return false;
1510 } 1543 }
1511 1544
1512 UpdateAllocatedSpaceLimits(base, static_cast<int>(size)); 1545 UpdateAllocatedSpaceLimits(base, static_cast<int>(size));
1513 return true; 1546 return true;
1514 } 1547 }
1515 1548
1516 1549
1517 bool VirtualMemory::UncommitRegion(void* base, size_t size) { 1550 bool VirtualMemory::UncommitRegion(void* base, size_t size) {
1518 return VirtualFree(base, size, MEM_DECOMMIT) != false; 1551 return VirtualFree(base, size, MEM_DECOMMIT) != 0;
1519 } 1552 }
1520 1553
1521 1554
1522 bool VirtualMemory::ReleaseRegion(void* base, size_t size) { 1555 bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
1523 return VirtualFree(base, size, MEM_DECOMMIT) != false; 1556 return VirtualFree(base, 0, MEM_RELEASE) != 0;
1524 } 1557 }
1525 1558
1526 1559
1527 1560
1528 // ---------------------------------------------------------------------------- 1561 // ----------------------------------------------------------------------------
1529 // Win32 thread support. 1562 // Win32 thread support.
1530 1563
1531 // Definition of invalid thread handle and id. 1564 // Definition of invalid thread handle and id.
1532 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; 1565 static const HANDLE kNoThread = INVALID_HANDLE_VALUE;
1533 1566
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 2096
2064 2097
2065 void Sampler::Stop() { 2098 void Sampler::Stop() {
2066 ASSERT(IsActive()); 2099 ASSERT(IsActive());
2067 SamplerThread::RemoveActiveSampler(this); 2100 SamplerThread::RemoveActiveSampler(this);
2068 SetActive(false); 2101 SetActive(false);
2069 } 2102 }
2070 2103
2071 2104
2072 } } // namespace v8::internal 2105 } } // namespace v8::internal
OLDNEW
« src/platform-linux.cc ('K') | « src/platform-macos.cc ('k') | src/spaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698