| 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 #ifndef V8_SHARED | |
| 9 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 10 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
| 11 #include "src/base/platform/time.h" | 10 #include "src/base/platform/time.h" |
| 12 #include "src/list.h" | 11 #include "src/list.h" |
| 13 #else | |
| 14 #include "include/v8.h" | |
| 15 #include "src/base/compiler-specific.h" | |
| 16 #endif // !V8_SHARED | |
| 17 | 12 |
| 18 #include "src/base/once.h" | 13 #include "src/base/once.h" |
| 19 | 14 |
| 20 | 15 |
| 21 namespace v8 { | 16 namespace v8 { |
| 22 | 17 |
| 23 | 18 |
| 24 #ifndef V8_SHARED | |
| 25 // A single counter in a counter collection. | 19 // A single counter in a counter collection. |
| 26 class Counter { | 20 class Counter { |
| 27 public: | 21 public: |
| 28 static const int kMaxNameSize = 64; | 22 static const int kMaxNameSize = 64; |
| 29 int32_t* Bind(const char* name, bool histogram); | 23 int32_t* Bind(const char* name, bool histogram); |
| 30 int32_t* ptr() { return &count_; } | 24 int32_t* ptr() { return &count_; } |
| 31 int32_t count() { return count_; } | 25 int32_t count() { return count_; } |
| 32 int32_t sample_total() { return sample_total_; } | 26 int32_t sample_total() { return sample_total_; } |
| 33 bool is_histogram() { return is_histogram_; } | 27 bool is_histogram() { return is_histogram_; } |
| 34 void AddSample(int32_t sample); | 28 void AddSample(int32_t sample); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 private: | 77 private: |
| 84 base::HashMap* map_; | 78 base::HashMap* map_; |
| 85 base::HashMap::Entry* entry_; | 79 base::HashMap::Entry* entry_; |
| 86 }; | 80 }; |
| 87 | 81 |
| 88 private: | 82 private: |
| 89 static int Hash(const char* name); | 83 static int Hash(const char* name); |
| 90 static bool Match(void* key1, void* key2); | 84 static bool Match(void* key1, void* key2); |
| 91 base::HashMap hash_map_; | 85 base::HashMap hash_map_; |
| 92 }; | 86 }; |
| 93 #endif // !V8_SHARED | |
| 94 | 87 |
| 95 | 88 |
| 96 class SourceGroup { | 89 class SourceGroup { |
| 97 public: | 90 public: |
| 98 SourceGroup() : | 91 SourceGroup() : |
| 99 #ifndef V8_SHARED | |
| 100 next_semaphore_(0), | 92 next_semaphore_(0), |
| 101 done_semaphore_(0), | 93 done_semaphore_(0), |
| 102 thread_(NULL), | 94 thread_(NULL), |
| 103 #endif // !V8_SHARED | |
| 104 argv_(NULL), | 95 argv_(NULL), |
| 105 begin_offset_(0), | 96 begin_offset_(0), |
| 106 end_offset_(0) {} | 97 end_offset_(0) {} |
| 107 | 98 |
| 108 ~SourceGroup(); | 99 ~SourceGroup(); |
| 109 | 100 |
| 110 void Begin(char** argv, int offset) { | 101 void Begin(char** argv, int offset) { |
| 111 argv_ = const_cast<const char**>(argv); | 102 argv_ = const_cast<const char**>(argv); |
| 112 begin_offset_ = offset; | 103 begin_offset_ = offset; |
| 113 } | 104 } |
| 114 | 105 |
| 115 void End(int offset) { end_offset_ = offset; } | 106 void End(int offset) { end_offset_ = offset; } |
| 116 | 107 |
| 117 void Execute(Isolate* isolate); | 108 void Execute(Isolate* isolate); |
| 118 | 109 |
| 119 #ifndef V8_SHARED | |
| 120 void StartExecuteInThread(); | 110 void StartExecuteInThread(); |
| 121 void WaitForThread(); | 111 void WaitForThread(); |
| 122 void JoinThread(); | 112 void JoinThread(); |
| 123 | 113 |
| 124 private: | 114 private: |
| 125 class IsolateThread : public base::Thread { | 115 class IsolateThread : public base::Thread { |
| 126 public: | 116 public: |
| 127 explicit IsolateThread(SourceGroup* group) | 117 explicit IsolateThread(SourceGroup* group) |
| 128 : base::Thread(GetThreadOptions()), group_(group) {} | 118 : base::Thread(GetThreadOptions()), group_(group) {} |
| 129 | 119 |
| 130 virtual void Run() { | 120 virtual void Run() { |
| 131 group_->ExecuteInThread(); | 121 group_->ExecuteInThread(); |
| 132 } | 122 } |
| 133 | 123 |
| 134 private: | 124 private: |
| 135 SourceGroup* group_; | 125 SourceGroup* group_; |
| 136 }; | 126 }; |
| 137 | 127 |
| 138 static base::Thread::Options GetThreadOptions(); | 128 static base::Thread::Options GetThreadOptions(); |
| 139 void ExecuteInThread(); | 129 void ExecuteInThread(); |
| 140 | 130 |
| 141 base::Semaphore next_semaphore_; | 131 base::Semaphore next_semaphore_; |
| 142 base::Semaphore done_semaphore_; | 132 base::Semaphore done_semaphore_; |
| 143 base::Thread* thread_; | 133 base::Thread* thread_; |
| 144 #endif // !V8_SHARED | |
| 145 | 134 |
| 146 void ExitShell(int exit_code); | 135 void ExitShell(int exit_code); |
| 147 Local<String> ReadFile(Isolate* isolate, const char* name); | 136 Local<String> ReadFile(Isolate* isolate, const char* name); |
| 148 | 137 |
| 149 const char** argv_; | 138 const char** argv_; |
| 150 int begin_offset_; | 139 int begin_offset_; |
| 151 int end_offset_; | 140 int end_offset_; |
| 152 }; | 141 }; |
| 153 | 142 |
| 154 #ifndef V8_SHARED | |
| 155 enum SerializationTag { | 143 enum SerializationTag { |
| 156 kSerializationTagUndefined, | 144 kSerializationTagUndefined, |
| 157 kSerializationTagNull, | 145 kSerializationTagNull, |
| 158 kSerializationTagTrue, | 146 kSerializationTagTrue, |
| 159 kSerializationTagFalse, | 147 kSerializationTagFalse, |
| 160 kSerializationTagNumber, | 148 kSerializationTagNumber, |
| 161 kSerializationTagString, | 149 kSerializationTagString, |
| 162 kSerializationTagArray, | 150 kSerializationTagArray, |
| 163 kSerializationTagObject, | 151 kSerializationTagObject, |
| 164 kSerializationTagArrayBuffer, | 152 kSerializationTagArrayBuffer, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args); | 248 static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 261 | 249 |
| 262 base::Semaphore in_semaphore_; | 250 base::Semaphore in_semaphore_; |
| 263 base::Semaphore out_semaphore_; | 251 base::Semaphore out_semaphore_; |
| 264 SerializationDataQueue in_queue_; | 252 SerializationDataQueue in_queue_; |
| 265 SerializationDataQueue out_queue_; | 253 SerializationDataQueue out_queue_; |
| 266 base::Thread* thread_; | 254 base::Thread* thread_; |
| 267 char* script_; | 255 char* script_; |
| 268 base::Atomic32 running_; | 256 base::Atomic32 running_; |
| 269 }; | 257 }; |
| 270 #endif // !V8_SHARED | |
| 271 | 258 |
| 272 | 259 |
| 273 class ShellOptions { | 260 class ShellOptions { |
| 274 public: | 261 public: |
| 275 ShellOptions() | 262 ShellOptions() |
| 276 : script_executed(false), | 263 : script_executed(false), |
| 277 send_idle_notification(false), | 264 send_idle_notification(false), |
| 278 invoke_weak_callbacks(false), | 265 invoke_weak_callbacks(false), |
| 279 omit_quit(false), | 266 omit_quit(false), |
| 280 stress_opt(false), | 267 stress_opt(false), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 int num_isolates; | 304 int num_isolates; |
| 318 v8::ScriptCompiler::CompileOptions compile_options; | 305 v8::ScriptCompiler::CompileOptions compile_options; |
| 319 SourceGroup* isolate_sources; | 306 SourceGroup* isolate_sources; |
| 320 const char* icu_data_file; | 307 const char* icu_data_file; |
| 321 const char* natives_blob; | 308 const char* natives_blob; |
| 322 const char* snapshot_blob; | 309 const char* snapshot_blob; |
| 323 bool trace_enabled; | 310 bool trace_enabled; |
| 324 const char* trace_config; | 311 const char* trace_config; |
| 325 }; | 312 }; |
| 326 | 313 |
| 327 #ifdef V8_SHARED | |
| 328 class Shell { | |
| 329 #else | |
| 330 class Shell : public i::AllStatic { | 314 class Shell : public i::AllStatic { |
| 331 #endif // V8_SHARED | |
| 332 | |
| 333 public: | 315 public: |
| 334 enum SourceType { SCRIPT, MODULE }; | 316 enum SourceType { SCRIPT, MODULE }; |
| 335 | 317 |
| 336 static MaybeLocal<Script> CompileString( | 318 static MaybeLocal<Script> CompileString( |
| 337 Isolate* isolate, Local<String> source, Local<Value> name, | 319 Isolate* isolate, Local<String> source, Local<Value> name, |
| 338 v8::ScriptCompiler::CompileOptions compile_options); | 320 v8::ScriptCompiler::CompileOptions compile_options); |
| 339 static bool ExecuteString(Isolate* isolate, Local<String> source, | 321 static bool ExecuteString(Isolate* isolate, Local<String> source, |
| 340 Local<Value> name, bool print_result, | 322 Local<Value> name, bool print_result, |
| 341 bool report_exceptions, | 323 bool report_exceptions, |
| 342 SourceType source_type = SCRIPT); | 324 SourceType source_type = SCRIPT); |
| 343 static const char* ToCString(const v8::String::Utf8Value& value); | 325 static const char* ToCString(const v8::String::Utf8Value& value); |
| 344 static void ReportException(Isolate* isolate, TryCatch* try_catch); | 326 static void ReportException(Isolate* isolate, TryCatch* try_catch); |
| 345 static Local<String> ReadFile(Isolate* isolate, const char* name); | 327 static Local<String> ReadFile(Isolate* isolate, const char* name); |
| 346 static Local<Context> CreateEvaluationContext(Isolate* isolate); | 328 static Local<Context> CreateEvaluationContext(Isolate* isolate); |
| 347 static int RunMain(Isolate* isolate, int argc, char* argv[], bool last_run); | 329 static int RunMain(Isolate* isolate, int argc, char* argv[], bool last_run); |
| 348 static int Main(int argc, char* argv[]); | 330 static int Main(int argc, char* argv[]); |
| 349 static void Exit(int exit_code); | 331 static void Exit(int exit_code); |
| 350 static void OnExit(Isolate* isolate); | 332 static void OnExit(Isolate* isolate); |
| 351 static void CollectGarbage(Isolate* isolate); | 333 static void CollectGarbage(Isolate* isolate); |
| 352 static void EmptyMessageQueues(Isolate* isolate); | 334 static void EmptyMessageQueues(Isolate* isolate); |
| 353 | 335 |
| 354 #ifndef V8_SHARED | |
| 355 // TODO(binji): stupid implementation for now. Is there an easy way to hash an | 336 // TODO(binji): stupid implementation for now. Is there an easy way to hash an |
| 356 // object for use in base::HashMap? By pointer? | 337 // object for use in base::HashMap? By pointer? |
| 357 typedef i::List<Local<Object>> ObjectList; | 338 typedef i::List<Local<Object>> ObjectList; |
| 358 static bool SerializeValue(Isolate* isolate, Local<Value> value, | 339 static bool SerializeValue(Isolate* isolate, Local<Value> value, |
| 359 const ObjectList& to_transfer, | 340 const ObjectList& to_transfer, |
| 360 ObjectList* seen_objects, | 341 ObjectList* seen_objects, |
| 361 SerializationData* out_data); | 342 SerializationData* out_data); |
| 362 static MaybeLocal<Value> DeserializeValue(Isolate* isolate, | 343 static MaybeLocal<Value> DeserializeValue(Isolate* isolate, |
| 363 const SerializationData& data, | 344 const SerializationData& data, |
| 364 int* offset); | 345 int* offset); |
| 365 static void CleanupWorkers(); | 346 static void CleanupWorkers(); |
| 366 static int* LookupCounter(const char* name); | 347 static int* LookupCounter(const char* name); |
| 367 static void* CreateHistogram(const char* name, | 348 static void* CreateHistogram(const char* name, |
| 368 int min, | 349 int min, |
| 369 int max, | 350 int max, |
| 370 size_t buckets); | 351 size_t buckets); |
| 371 static void AddHistogramSample(void* histogram, int sample); | 352 static void AddHistogramSample(void* histogram, int sample); |
| 372 static void MapCounters(v8::Isolate* isolate, const char* name); | 353 static void MapCounters(v8::Isolate* isolate, const char* name); |
| 373 | 354 |
| 374 static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args); | 355 static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 375 #endif // !V8_SHARED | |
| 376 | 356 |
| 377 static void RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args); | 357 static void RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 378 static void RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args); | 358 static void RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 379 static void RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args); | 359 static void RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 380 static void RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args); | 360 static void RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 381 static void RealmCreateAllowCrossRealmAccess( | 361 static void RealmCreateAllowCrossRealmAccess( |
| 382 const v8::FunctionCallbackInfo<v8::Value>& args); | 362 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 383 static void RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args); | 363 static void RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 384 static void RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args); | 364 static void RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 385 static void RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args); | 365 static void RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 static void AddOSMethods(v8::Isolate* isolate, | 423 static void AddOSMethods(v8::Isolate* isolate, |
| 444 Local<ObjectTemplate> os_template); | 424 Local<ObjectTemplate> os_template); |
| 445 | 425 |
| 446 static const char* kPrompt; | 426 static const char* kPrompt; |
| 447 static ShellOptions options; | 427 static ShellOptions options; |
| 448 static ArrayBuffer::Allocator* array_buffer_allocator; | 428 static ArrayBuffer::Allocator* array_buffer_allocator; |
| 449 | 429 |
| 450 private: | 430 private: |
| 451 static Global<Context> evaluation_context_; | 431 static Global<Context> evaluation_context_; |
| 452 static base::OnceType quit_once_; | 432 static base::OnceType quit_once_; |
| 453 #ifndef V8_SHARED | |
| 454 static Global<Function> stringify_function_; | 433 static Global<Function> stringify_function_; |
| 455 static CounterMap* counter_map_; | 434 static CounterMap* counter_map_; |
| 456 // We statically allocate a set of local counters to be used if we | 435 // We statically allocate a set of local counters to be used if we |
| 457 // don't want to store the stats in a memory-mapped file | 436 // don't want to store the stats in a memory-mapped file |
| 458 static CounterCollection local_counters_; | 437 static CounterCollection local_counters_; |
| 459 static CounterCollection* counters_; | 438 static CounterCollection* counters_; |
| 460 static base::OS::MemoryMappedFile* counters_file_; | 439 static base::OS::MemoryMappedFile* counters_file_; |
| 461 static base::LazyMutex context_mutex_; | 440 static base::LazyMutex context_mutex_; |
| 462 static const base::TimeTicks kInitialTicks; | 441 static const base::TimeTicks kInitialTicks; |
| 463 | 442 |
| 464 static base::LazyMutex workers_mutex_; | 443 static base::LazyMutex workers_mutex_; |
| 465 static bool allow_new_workers_; | 444 static bool allow_new_workers_; |
| 466 static i::List<Worker*> workers_; | 445 static i::List<Worker*> workers_; |
| 467 static i::List<SharedArrayBuffer::Contents> externalized_shared_contents_; | 446 static i::List<SharedArrayBuffer::Contents> externalized_shared_contents_; |
| 468 | 447 |
| 469 static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate); | 448 static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate); |
| 470 static Counter* GetCounter(const char* name, bool is_histogram); | 449 static Counter* GetCounter(const char* name, bool is_histogram); |
| 471 static Local<String> Stringify(Isolate* isolate, Local<Value> value); | 450 static Local<String> Stringify(Isolate* isolate, Local<Value> value); |
| 472 #endif // !V8_SHARED | |
| 473 static void Initialize(Isolate* isolate); | 451 static void Initialize(Isolate* isolate); |
| 474 static void RunShell(Isolate* isolate); | 452 static void RunShell(Isolate* isolate); |
| 475 static bool SetOptions(int argc, char* argv[]); | 453 static bool SetOptions(int argc, char* argv[]); |
| 476 static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); | 454 static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); |
| 477 static MaybeLocal<Context> CreateRealm( | 455 static MaybeLocal<Context> CreateRealm( |
| 478 const v8::FunctionCallbackInfo<v8::Value>& args); | 456 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 479 }; | 457 }; |
| 480 | 458 |
| 481 | 459 |
| 482 } // namespace v8 | 460 } // namespace v8 |
| 483 | 461 |
| 484 | 462 |
| 485 #endif // V8_D8_H_ | 463 #endif // V8_D8_H_ |
| OLD | NEW |