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 #ifndef V8_D8_H_ | 5 #ifndef V8_D8_H_ |
6 #define V8_D8_H_ | 6 #define V8_D8_H_ |
7 | 7 |
| 8 #include <iterator> |
8 #include <memory> | 9 #include <memory> |
9 #include <string> | 10 #include <string> |
10 #include <unordered_set> | |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "src/allocation.h" | 13 #include "src/allocation.h" |
14 #include "src/base/functional.h" | |
15 #include "src/base/hashmap.h" | 14 #include "src/base/hashmap.h" |
16 #include "src/base/platform/time.h" | 15 #include "src/base/platform/time.h" |
17 #include "src/list.h" | 16 #include "src/list.h" |
18 #include "src/utils.h" | 17 #include "src/utils.h" |
19 | 18 |
20 #include "src/base/once.h" | 19 #include "src/base/once.h" |
21 | 20 |
22 | 21 |
23 namespace v8 { | 22 namespace v8 { |
24 | 23 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 base::Thread* thread_; | 139 base::Thread* thread_; |
141 | 140 |
142 void ExitShell(int exit_code); | 141 void ExitShell(int exit_code); |
143 Local<String> ReadFile(Isolate* isolate, const char* name); | 142 Local<String> ReadFile(Isolate* isolate, const char* name); |
144 | 143 |
145 const char** argv_; | 144 const char** argv_; |
146 int begin_offset_; | 145 int begin_offset_; |
147 int end_offset_; | 146 int end_offset_; |
148 }; | 147 }; |
149 | 148 |
| 149 // The backing store of an ArrayBuffer or SharedArrayBuffer, after |
| 150 // Externalize() has been called on it. |
| 151 class ExternalizedContents { |
| 152 public: |
| 153 explicit ExternalizedContents(const ArrayBuffer::Contents& contents) |
| 154 : data_(contents.Data()), size_(contents.ByteLength()) {} |
| 155 explicit ExternalizedContents(const SharedArrayBuffer::Contents& contents) |
| 156 : data_(contents.Data()), size_(contents.ByteLength()) {} |
| 157 ExternalizedContents(ExternalizedContents&& other) |
| 158 : data_(other.data_), size_(other.size_) { |
| 159 other.data_ = nullptr; |
| 160 other.size_ = 0; |
| 161 } |
| 162 ExternalizedContents& operator=(ExternalizedContents&& other) { |
| 163 if (this != &other) { |
| 164 data_ = other.data_; |
| 165 size_ = other.size_; |
| 166 other.data_ = nullptr; |
| 167 other.size_ = 0; |
| 168 } |
| 169 return *this; |
| 170 } |
| 171 ~ExternalizedContents(); |
| 172 |
| 173 private: |
| 174 void* data_; |
| 175 size_t size_; |
| 176 |
| 177 DISALLOW_COPY_AND_ASSIGN(ExternalizedContents); |
| 178 }; |
150 | 179 |
151 class SerializationData { | 180 class SerializationData { |
152 public: | 181 public: |
153 SerializationData() : data_(nullptr), size_(0) {} | 182 SerializationData() : size_(0) {} |
154 ~SerializationData(); | |
155 | 183 |
156 uint8_t* data() { return data_.get(); } | 184 uint8_t* data() { return data_.get(); } |
157 size_t size() { return size_; } | 185 size_t size() { return size_; } |
158 const std::vector<ArrayBuffer::Contents>& array_buffer_contents() { | 186 const std::vector<ArrayBuffer::Contents>& array_buffer_contents() { |
159 return array_buffer_contents_; | 187 return array_buffer_contents_; |
160 } | 188 } |
161 const std::vector<SharedArrayBuffer::Contents>& | 189 const std::vector<SharedArrayBuffer::Contents>& |
162 shared_array_buffer_contents() { | 190 shared_array_buffer_contents() { |
163 return shared_array_buffer_contents_; | 191 return shared_array_buffer_contents_; |
164 } | 192 } |
165 | 193 |
166 void ClearTransferredArrayBuffers(); | 194 void AppendExternalizedContentsTo(std::vector<ExternalizedContents>* to) { |
| 195 to->insert(to->end(), |
| 196 std::make_move_iterator(externalized_contents_.begin()), |
| 197 std::make_move_iterator(externalized_contents_.end())); |
| 198 externalized_contents_.clear(); |
| 199 } |
167 | 200 |
168 private: | 201 private: |
169 struct DataDeleter { | 202 struct DataDeleter { |
170 void operator()(uint8_t* p) const { free(p); } | 203 void operator()(uint8_t* p) const { free(p); } |
171 }; | 204 }; |
172 | 205 |
173 std::unique_ptr<uint8_t, DataDeleter> data_; | 206 std::unique_ptr<uint8_t, DataDeleter> data_; |
174 size_t size_; | 207 size_t size_; |
175 std::vector<ArrayBuffer::Contents> array_buffer_contents_; | 208 std::vector<ArrayBuffer::Contents> array_buffer_contents_; |
176 std::vector<SharedArrayBuffer::Contents> shared_array_buffer_contents_; | 209 std::vector<SharedArrayBuffer::Contents> shared_array_buffer_contents_; |
| 210 std::vector<ExternalizedContents> externalized_contents_; |
177 | 211 |
178 private: | 212 private: |
179 friend class Serializer; | 213 friend class Serializer; |
180 | 214 |
181 DISALLOW_COPY_AND_ASSIGN(SerializationData); | 215 DISALLOW_COPY_AND_ASSIGN(SerializationData); |
182 }; | 216 }; |
183 | 217 |
184 | 218 |
185 class SerializationDataQueue { | 219 class SerializationDataQueue { |
186 public: | 220 public: |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 static Global<Function> stringify_function_; | 451 static Global<Function> stringify_function_; |
418 static CounterMap* counter_map_; | 452 static CounterMap* counter_map_; |
419 // We statically allocate a set of local counters to be used if we | 453 // We statically allocate a set of local counters to be used if we |
420 // don't want to store the stats in a memory-mapped file | 454 // don't want to store the stats in a memory-mapped file |
421 static CounterCollection local_counters_; | 455 static CounterCollection local_counters_; |
422 static CounterCollection* counters_; | 456 static CounterCollection* counters_; |
423 static base::OS::MemoryMappedFile* counters_file_; | 457 static base::OS::MemoryMappedFile* counters_file_; |
424 static base::LazyMutex context_mutex_; | 458 static base::LazyMutex context_mutex_; |
425 static const base::TimeTicks kInitialTicks; | 459 static const base::TimeTicks kInitialTicks; |
426 | 460 |
427 struct SharedArrayBufferContentsHash { | |
428 size_t operator()(const v8::SharedArrayBuffer::Contents& contents) const { | |
429 return base::hash_combine(contents.Data(), contents.ByteLength()); | |
430 } | |
431 }; | |
432 | |
433 struct SharedArrayBufferContentsIsEqual { | |
434 bool operator()(const SharedArrayBuffer::Contents& a, | |
435 const SharedArrayBuffer::Contents& b) const { | |
436 return a.Data() == b.Data() && a.ByteLength() == b.ByteLength(); | |
437 } | |
438 }; | |
439 | |
440 static base::LazyMutex workers_mutex_; | 461 static base::LazyMutex workers_mutex_; |
441 static bool allow_new_workers_; | 462 static bool allow_new_workers_; |
442 static i::List<Worker*> workers_; | 463 static i::List<Worker*> workers_; |
443 static std::unordered_set<SharedArrayBuffer::Contents, | 464 static std::vector<ExternalizedContents> externalized_contents_; |
444 SharedArrayBufferContentsHash, | |
445 SharedArrayBufferContentsIsEqual> | |
446 externalized_shared_contents_; | |
447 | 465 |
448 static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate); | 466 static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate); |
449 static Counter* GetCounter(const char* name, bool is_histogram); | 467 static Counter* GetCounter(const char* name, bool is_histogram); |
450 static Local<String> Stringify(Isolate* isolate, Local<Value> value); | 468 static Local<String> Stringify(Isolate* isolate, Local<Value> value); |
451 static void Initialize(Isolate* isolate); | 469 static void Initialize(Isolate* isolate); |
452 static void RunShell(Isolate* isolate); | 470 static void RunShell(Isolate* isolate); |
453 static bool SetOptions(int argc, char* argv[]); | 471 static bool SetOptions(int argc, char* argv[]); |
454 static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); | 472 static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); |
455 static MaybeLocal<Context> CreateRealm( | 473 static MaybeLocal<Context> CreateRealm( |
456 const v8::FunctionCallbackInfo<v8::Value>& args); | 474 const v8::FunctionCallbackInfo<v8::Value>& args); |
457 static MaybeLocal<Module> FetchModuleTree(v8::Local<v8::Context> context, | 475 static MaybeLocal<Module> FetchModuleTree(v8::Local<v8::Context> context, |
458 const std::string& file_name); | 476 const std::string& file_name); |
459 }; | 477 }; |
460 | 478 |
461 | 479 |
462 } // namespace v8 | 480 } // namespace v8 |
463 | 481 |
464 | 482 |
465 #endif // V8_D8_H_ | 483 #endif // V8_D8_H_ |
OLD | NEW |