Chromium Code Reviews| Index: src/d8.cc |
| diff --git a/src/d8.cc b/src/d8.cc |
| index 00fb70737fb317acd35657d30be417f6d8bd043c..44445c6198e813f72cca3ccba383e4328c6ad1ec 100644 |
| --- a/src/d8.cc |
| +++ b/src/d8.cc |
| @@ -62,15 +62,58 @@ namespace { |
| const int MB = 1024 * 1024; |
| const int kMaxWorkers = 50; |
| +#define USE_VM 1 |
| +#define VM_THRESHOLD 65536 |
| class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| public: |
| virtual void* Allocate(size_t length) { |
| +#if USE_VM |
| + if (RoundToPageSize(&length)) { |
| + void* data = base::VirtualMemory::ReserveRegion(length); |
| + if (data && !base::VirtualMemory::CommitRegion(data, length, false)) { |
|
Michael Starzinger
2016/11/21 13:58:09
This relies on the mamory being provided by the un
Michael Starzinger
2016/11/21 13:59:33
Same for the other *SANs, not sure which one it is
|
| + base::VirtualMemory::ReleaseRegion(data, length); |
| + data = nullptr; |
| + } |
| + return data; |
| + } |
| +#endif |
|
Clemens Hammacher
2016/11/21 14:00:28
The code duplication bothers me. We call AllocateU
|
| void* data = AllocateUninitialized(length); |
| return data == NULL ? data : memset(data, 0, length); |
| } |
| - virtual void* AllocateUninitialized(size_t length) { return malloc(length); } |
| - virtual void Free(void* data, size_t) { free(data); } |
| + virtual void* AllocateUninitialized(size_t length) { |
| +#if USE_VM |
| + if (RoundToPageSize(&length)) { |
| + void* data = base::VirtualMemory::ReserveRegion(length); |
| + if (data && !base::VirtualMemory::CommitRegion(data, length, false)) { |
| + base::VirtualMemory::ReleaseRegion(data, length); |
| + data = nullptr; |
| + } |
| + return data; |
| + } |
| +#endif |
| + return malloc(length); |
| + } |
| + virtual void Free(void* data, size_t length) { |
| +#if USE_VM |
| + if (RoundToPageSize(&length)) { |
| + base::VirtualMemory::ReleaseRegion(data, length); |
| + return; |
| + } |
| +#endif |
| + free(data); |
| + } |
| + // If {length} is at least a page, round up to next page size and return |
|
Clemens Hammacher
2016/11/21 14:00:28
... at least VM_THRESHOLD, ...
|
| + // {true}. |
| + // Otherwise return {false}. |
| + bool RoundToPageSize(size_t* length) { |
| + const size_t kPageSize = base::OS::CommitPageSize(); |
| + if (*length >= VM_THRESHOLD) { |
| + *length = ((*length + kPageSize - 1) / kPageSize) * kPageSize; |
| + return true; |
| + } |
| + return false; |
| + } |
| }; |