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

Unified Diff: src/d8.cc

Issue 2520963002: [d8] Use virtual memory to allocate large array buffers. (Closed)
Patch Set: [d8] Use virtual memory to allocate large array buffers. Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 00fb70737fb317acd35657d30be417f6d8bd043c..2b8cabd51d1ff9bec411965cc66913d50dcfa3cc 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -30,6 +30,7 @@
#include "src/base/sys-info.h"
#include "src/basic-block-profiler.h"
#include "src/interpreter/interpreter.h"
+#include "src/msan.h"
#include "src/snapshot/natives.h"
#include "src/utils.h"
#include "src/v8.h"
@@ -62,15 +63,64 @@ 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 = VirtualMemoryAllocate(length);
+#if DEBUG
+ // In debug mode, check the memory is zero-initialized.
+ uint8_t* ptr = reinterpret_cast<uint8_t*>(data);
+ for (size_t i = 0; i < length; i++) {
+ DCHECK_EQ(0, ptr[i]);
+ }
+#endif
+ return data;
+ }
+#endif
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)) return VirtualMemoryAllocate(length);
+#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 {VM_THRESHOLD}, round up to next page size
Clemens Hammacher 2016/11/21 15:49:24 Nit: still an "a" to much ;)
+ // and return {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;
+ }
+#if USE_VM
+ void* VirtualMemoryAllocate(size_t length) {
+ void* data = base::VirtualMemory::ReserveRegion(length);
+ if (data && !base::VirtualMemory::CommitRegion(data, length, false)) {
+ base::VirtualMemory::ReleaseRegion(data, length);
+ return nullptr;
+ }
+ MSAN_MEMORY_IS_INITIALIZED(data, length);
+ return data;
+ }
+#endif
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698