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 #ifndef V8_D8_H_ | 5 #ifndef V8_D8_H_ |
| 6 #define V8_D8_H_ | 6 #define V8_D8_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <unordered_set> | |
| 9 | 10 |
| 10 #include "src/allocation.h" | 11 #include "src/allocation.h" |
| 11 #include "src/base/hashmap.h" | 12 #include "src/base/hashmap.h" |
| 12 #include "src/base/platform/time.h" | 13 #include "src/base/platform/time.h" |
| 13 #include "src/list.h" | 14 #include "src/list.h" |
| 14 #include "src/utils.h" | 15 #include "src/utils.h" |
| 15 | 16 |
| 16 #include "src/base/once.h" | 17 #include "src/base/once.h" |
| 17 | 18 |
| 18 | 19 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 base::Thread* thread_; | 137 base::Thread* thread_; |
| 137 | 138 |
| 138 void ExitShell(int exit_code); | 139 void ExitShell(int exit_code); |
| 139 Local<String> ReadFile(Isolate* isolate, const char* name); | 140 Local<String> ReadFile(Isolate* isolate, const char* name); |
| 140 | 141 |
| 141 const char** argv_; | 142 const char** argv_; |
| 142 int begin_offset_; | 143 int begin_offset_; |
| 143 int end_offset_; | 144 int end_offset_; |
| 144 }; | 145 }; |
| 145 | 146 |
| 146 enum SerializationTag { | |
| 147 kSerializationTagUndefined, | |
| 148 kSerializationTagNull, | |
| 149 kSerializationTagTrue, | |
| 150 kSerializationTagFalse, | |
| 151 kSerializationTagNumber, | |
| 152 kSerializationTagString, | |
| 153 kSerializationTagArray, | |
| 154 kSerializationTagObject, | |
| 155 kSerializationTagArrayBuffer, | |
| 156 kSerializationTagTransferredArrayBuffer, | |
| 157 kSerializationTagTransferredSharedArrayBuffer, | |
| 158 }; | |
| 159 | |
| 160 | 147 |
| 161 class SerializationData { | 148 class SerializationData { |
| 162 public: | 149 public: |
| 163 SerializationData() {} | 150 SerializationData() : data_(nullptr), size_(0) {} |
| 164 ~SerializationData(); | 151 ~SerializationData(); |
| 165 | 152 |
| 166 void WriteTag(SerializationTag tag); | 153 uint8_t* data() { return data_; } |
| 167 void WriteMemory(const void* p, int length); | 154 size_t size() { return size_; } |
| 168 void WriteArrayBufferContents(const ArrayBuffer::Contents& contents); | 155 const std::vector<ArrayBuffer::Contents>& array_buffer_contents() { |
| 169 void WriteSharedArrayBufferContents( | 156 return array_buffer_contents_; |
| 170 const SharedArrayBuffer::Contents& contents); | 157 } |
| 171 | 158 const std::vector<SharedArrayBuffer::Contents>& |
| 172 template <typename T> | 159 shared_array_buffer_contents() { |
| 173 void Write(const T& data) { | 160 return shared_array_buffer_contents_; |
| 174 WriteMemory(&data, sizeof(data)); | |
| 175 } | 161 } |
| 176 | 162 |
| 177 SerializationTag ReadTag(int* offset) const; | 163 void ClearTransferredArrayBuffers(); |
| 178 void ReadMemory(void* p, int length, int* offset) const; | |
| 179 void ReadArrayBufferContents(ArrayBuffer::Contents* contents, | |
| 180 int* offset) const; | |
| 181 void ReadSharedArrayBufferContents(SharedArrayBuffer::Contents* contents, | |
| 182 int* offset) const; | |
| 183 | |
| 184 template <typename T> | |
| 185 T Read(int* offset) const { | |
| 186 T value; | |
| 187 ReadMemory(&value, sizeof(value), offset); | |
| 188 return value; | |
| 189 } | |
| 190 | 164 |
| 191 private: | 165 private: |
| 192 i::List<uint8_t> data_; | 166 uint8_t* data_; |
|
jbroman
2017/01/24 18:53:43
This looks like it's leaked. You could use unique_
binji
2017/01/25 00:31:36
Done.
| |
| 193 i::List<ArrayBuffer::Contents> array_buffer_contents_; | 167 size_t size_; |
| 194 i::List<SharedArrayBuffer::Contents> shared_array_buffer_contents_; | 168 std::vector<ArrayBuffer::Contents> array_buffer_contents_; |
| 169 std::vector<SharedArrayBuffer::Contents> shared_array_buffer_contents_; | |
| 170 | |
| 171 private: | |
| 172 friend class Serializer; | |
| 173 | |
| 174 DISALLOW_COPY_AND_ASSIGN(SerializationData); | |
| 195 }; | 175 }; |
| 196 | 176 |
| 197 | 177 |
| 198 class SerializationDataQueue { | 178 class SerializationDataQueue { |
| 199 public: | 179 public: |
| 200 void Enqueue(SerializationData* data); | 180 void Enqueue(SerializationData* data); |
| 201 bool Dequeue(SerializationData** data); | 181 bool Dequeue(SerializationData** data); |
| 202 bool IsEmpty(); | 182 bool IsEmpty(); |
| 203 void Clear(); | 183 void Clear(); |
| 204 | 184 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 static void ReportException(Isolate* isolate, TryCatch* try_catch); | 308 static void ReportException(Isolate* isolate, TryCatch* try_catch); |
| 329 static Local<String> ReadFile(Isolate* isolate, const char* name); | 309 static Local<String> ReadFile(Isolate* isolate, const char* name); |
| 330 static Local<Context> CreateEvaluationContext(Isolate* isolate); | 310 static Local<Context> CreateEvaluationContext(Isolate* isolate); |
| 331 static int RunMain(Isolate* isolate, int argc, char* argv[], bool last_run); | 311 static int RunMain(Isolate* isolate, int argc, char* argv[], bool last_run); |
| 332 static int Main(int argc, char* argv[]); | 312 static int Main(int argc, char* argv[]); |
| 333 static void Exit(int exit_code); | 313 static void Exit(int exit_code); |
| 334 static void OnExit(Isolate* isolate); | 314 static void OnExit(Isolate* isolate); |
| 335 static void CollectGarbage(Isolate* isolate); | 315 static void CollectGarbage(Isolate* isolate); |
| 336 static void EmptyMessageQueues(Isolate* isolate); | 316 static void EmptyMessageQueues(Isolate* isolate); |
| 337 | 317 |
| 338 // TODO(binji): stupid implementation for now. Is there an easy way to hash an | 318 static Maybe<SerializationData*> SerializeValue(Isolate* isolate, |
| 339 // object for use in base::HashMap? By pointer? | 319 Local<Value> value, |
| 340 typedef i::List<Local<Object>> ObjectList; | 320 Local<Value> transfer); |
| 341 static bool SerializeValue(Isolate* isolate, Local<Value> value, | |
| 342 const ObjectList& to_transfer, | |
| 343 ObjectList* seen_objects, | |
| 344 SerializationData* out_data); | |
| 345 static MaybeLocal<Value> DeserializeValue(Isolate* isolate, | 321 static MaybeLocal<Value> DeserializeValue(Isolate* isolate, |
| 346 const SerializationData& data, | 322 SerializationData* data); |
| 347 int* offset); | |
| 348 static void CleanupWorkers(); | 323 static void CleanupWorkers(); |
| 349 static int* LookupCounter(const char* name); | 324 static int* LookupCounter(const char* name); |
| 350 static void* CreateHistogram(const char* name, | 325 static void* CreateHistogram(const char* name, |
| 351 int min, | 326 int min, |
| 352 int max, | 327 int max, |
| 353 size_t buckets); | 328 size_t buckets); |
| 354 static void AddHistogramSample(void* histogram, int sample); | 329 static void AddHistogramSample(void* histogram, int sample); |
| 355 static void MapCounters(v8::Isolate* isolate, const char* name); | 330 static void MapCounters(v8::Isolate* isolate, const char* name); |
| 356 | 331 |
| 357 static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args); | 332 static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 // don't want to store the stats in a memory-mapped file | 414 // don't want to store the stats in a memory-mapped file |
| 440 static CounterCollection local_counters_; | 415 static CounterCollection local_counters_; |
| 441 static CounterCollection* counters_; | 416 static CounterCollection* counters_; |
| 442 static base::OS::MemoryMappedFile* counters_file_; | 417 static base::OS::MemoryMappedFile* counters_file_; |
| 443 static base::LazyMutex context_mutex_; | 418 static base::LazyMutex context_mutex_; |
| 444 static const base::TimeTicks kInitialTicks; | 419 static const base::TimeTicks kInitialTicks; |
| 445 | 420 |
| 446 static base::LazyMutex workers_mutex_; | 421 static base::LazyMutex workers_mutex_; |
| 447 static bool allow_new_workers_; | 422 static bool allow_new_workers_; |
| 448 static i::List<Worker*> workers_; | 423 static i::List<Worker*> workers_; |
| 449 static i::List<SharedArrayBuffer::Contents> externalized_shared_contents_; | 424 static std::unordered_set<SharedArrayBuffer::Contents> |
| 425 externalized_shared_contents_; | |
| 450 | 426 |
| 451 static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate); | 427 static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate); |
| 452 static Counter* GetCounter(const char* name, bool is_histogram); | 428 static Counter* GetCounter(const char* name, bool is_histogram); |
| 453 static Local<String> Stringify(Isolate* isolate, Local<Value> value); | 429 static Local<String> Stringify(Isolate* isolate, Local<Value> value); |
| 454 static void Initialize(Isolate* isolate); | 430 static void Initialize(Isolate* isolate); |
| 455 static void RunShell(Isolate* isolate); | 431 static void RunShell(Isolate* isolate); |
| 456 static bool SetOptions(int argc, char* argv[]); | 432 static bool SetOptions(int argc, char* argv[]); |
| 457 static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); | 433 static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); |
| 458 static MaybeLocal<Context> CreateRealm( | 434 static MaybeLocal<Context> CreateRealm( |
| 459 const v8::FunctionCallbackInfo<v8::Value>& args); | 435 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 460 static MaybeLocal<Module> FetchModuleTree(v8::Local<v8::Context> context, | 436 static MaybeLocal<Module> FetchModuleTree(v8::Local<v8::Context> context, |
| 461 const std::string& file_name); | 437 const std::string& file_name); |
| 462 }; | 438 }; |
| 463 | 439 |
| 464 | 440 |
| 465 } // namespace v8 | 441 } // namespace v8 |
| 466 | 442 |
| 467 | 443 |
| 468 #endif // V8_D8_H_ | 444 #endif // V8_D8_H_ |
| OLD | NEW |