Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <errno.h> | 5 #include <errno.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "include/libplatform/libplatform.h" | 23 #include "include/libplatform/libplatform.h" |
| 24 #include "include/libplatform/v8-tracing.h" | 24 #include "include/libplatform/v8-tracing.h" |
| 25 #include "src/api.h" | 25 #include "src/api.h" |
| 26 #include "src/base/cpu.h" | 26 #include "src/base/cpu.h" |
| 27 #include "src/base/debug/stack_trace.h" | 27 #include "src/base/debug/stack_trace.h" |
| 28 #include "src/base/logging.h" | 28 #include "src/base/logging.h" |
| 29 #include "src/base/platform/platform.h" | 29 #include "src/base/platform/platform.h" |
| 30 #include "src/base/sys-info.h" | 30 #include "src/base/sys-info.h" |
| 31 #include "src/basic-block-profiler.h" | 31 #include "src/basic-block-profiler.h" |
| 32 #include "src/interpreter/interpreter.h" | 32 #include "src/interpreter/interpreter.h" |
| 33 #include "src/msan.h" | |
| 33 #include "src/snapshot/natives.h" | 34 #include "src/snapshot/natives.h" |
| 34 #include "src/utils.h" | 35 #include "src/utils.h" |
| 35 #include "src/v8.h" | 36 #include "src/v8.h" |
| 36 | 37 |
| 37 #ifdef V8_INSPECTOR_ENABLED | 38 #ifdef V8_INSPECTOR_ENABLED |
| 38 #include "include/v8-inspector.h" | 39 #include "include/v8-inspector.h" |
| 39 #endif // V8_INSPECTOR_ENABLED | 40 #endif // V8_INSPECTOR_ENABLED |
| 40 | 41 |
| 41 #if !defined(_WIN32) && !defined(_WIN64) | 42 #if !defined(_WIN32) && !defined(_WIN64) |
| 42 #include <unistd.h> // NOLINT | 43 #include <unistd.h> // NOLINT |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 55 #define CHECK(condition) assert(condition) | 56 #define CHECK(condition) assert(condition) |
| 56 #endif | 57 #endif |
| 57 | 58 |
| 58 namespace v8 { | 59 namespace v8 { |
| 59 | 60 |
| 60 namespace { | 61 namespace { |
| 61 | 62 |
| 62 const int MB = 1024 * 1024; | 63 const int MB = 1024 * 1024; |
| 63 const int kMaxWorkers = 50; | 64 const int kMaxWorkers = 50; |
| 64 | 65 |
| 66 #define USE_VM 1 | |
| 67 #define VM_THRESHOLD 65536 | |
| 65 | 68 |
| 66 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 69 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 67 public: | 70 public: |
| 68 virtual void* Allocate(size_t length) { | 71 virtual void* Allocate(size_t length) { |
| 72 #if USE_VM | |
| 73 if (RoundToPageSize(&length)) { | |
| 74 void* data = VirtualMemoryAllocate(length); | |
| 75 #if DEBUG | |
| 76 // In debug mode, check the memory is zero-initialized. | |
| 77 uint8_t* ptr = reinterpret_cast<uint8_t*>(data); | |
| 78 for (size_t i = 0; i < length; i++) { | |
| 79 DCHECK_EQ(0, ptr[i]); | |
| 80 } | |
| 81 #endif | |
| 82 return data; | |
| 83 } | |
| 84 #endif | |
| 69 void* data = AllocateUninitialized(length); | 85 void* data = AllocateUninitialized(length); |
| 70 return data == NULL ? data : memset(data, 0, length); | 86 return data == NULL ? data : memset(data, 0, length); |
| 71 } | 87 } |
| 72 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } | 88 virtual void* AllocateUninitialized(size_t length) { |
| 73 virtual void Free(void* data, size_t) { free(data); } | 89 #if USE_VM |
| 90 if (RoundToPageSize(&length)) return VirtualMemoryAllocate(length); | |
| 91 #endif | |
| 92 return malloc(length); | |
| 93 } | |
| 94 virtual void Free(void* data, size_t length) { | |
| 95 #if USE_VM | |
| 96 if (RoundToPageSize(&length)) { | |
| 97 base::VirtualMemory::ReleaseRegion(data, length); | |
| 98 return; | |
| 99 } | |
| 100 #endif | |
| 101 free(data); | |
| 102 } | |
| 103 // 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 ;)
| |
| 104 // and return {true}. Otherwise return {false}. | |
| 105 bool RoundToPageSize(size_t* length) { | |
| 106 const size_t kPageSize = base::OS::CommitPageSize(); | |
| 107 if (*length >= VM_THRESHOLD) { | |
| 108 *length = ((*length + kPageSize - 1) / kPageSize) * kPageSize; | |
| 109 return true; | |
| 110 } | |
| 111 return false; | |
| 112 } | |
| 113 #if USE_VM | |
| 114 void* VirtualMemoryAllocate(size_t length) { | |
| 115 void* data = base::VirtualMemory::ReserveRegion(length); | |
| 116 if (data && !base::VirtualMemory::CommitRegion(data, length, false)) { | |
| 117 base::VirtualMemory::ReleaseRegion(data, length); | |
| 118 return nullptr; | |
| 119 } | |
| 120 MSAN_MEMORY_IS_INITIALIZED(data, length); | |
| 121 return data; | |
| 122 } | |
| 123 #endif | |
| 74 }; | 124 }; |
| 75 | 125 |
| 76 | 126 |
| 77 class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 127 class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 78 public: | 128 public: |
| 79 void* Allocate(size_t length) override { | 129 void* Allocate(size_t length) override { |
| 80 size_t actual_length = length > 10 * MB ? 1 : length; | 130 size_t actual_length = length > 10 * MB ? 1 : length; |
| 81 void* data = AllocateUninitialized(actual_length); | 131 void* data = AllocateUninitialized(actual_length); |
| 82 return data == NULL ? data : memset(data, 0, actual_length); | 132 return data == NULL ? data : memset(data, 0, actual_length); |
| 83 } | 133 } |
| (...skipping 2880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2964 } | 3014 } |
| 2965 | 3015 |
| 2966 } // namespace v8 | 3016 } // namespace v8 |
| 2967 | 3017 |
| 2968 | 3018 |
| 2969 #ifndef GOOGLE3 | 3019 #ifndef GOOGLE3 |
| 2970 int main(int argc, char* argv[]) { | 3020 int main(int argc, char* argv[]) { |
| 2971 return v8::Shell::Main(argc, argv); | 3021 return v8::Shell::Main(argc, argv); |
| 2972 } | 3022 } |
| 2973 #endif | 3023 #endif |
| OLD | NEW |