13 #include <unordered_map> 16 #include "src/allocation.h" 17 #include "src/async-hooks-wrapper.h" 18 #include "src/base/platform/time.h" 19 #include "src/string-hasher.h" 20 #include "src/utils.h" 22 #include "src/base/once.h" 31 static const int kMaxNameSize = 64;
32 int32_t* Bind(
const char* name,
bool histogram);
33 int32_t* ptr() {
return &count_; }
34 int32_t count() {
return count_; }
35 int32_t sample_total() {
return sample_total_; }
36 bool is_histogram() {
return is_histogram_; }
37 void AddSample(int32_t sample);
40 int32_t sample_total_;
42 uint8_t name_[kMaxNameSize];
54 static const unsigned kMaxCounters = 512;
59 Counter counters_[kMaxCounters];
63 std::size_t operator()(
const char* name)
const {
66 while ((c = *name++) != 0) {
90 void Begin(
char** argv,
int offset) {
91 argv_ =
const_cast<const char**
>(argv);
92 begin_offset_ = offset;
95 void End(
int offset) { end_offset_ = offset; }
97 void Execute(Isolate* isolate);
99 void StartExecuteInThread();
100 void WaitForThread();
108 void Run()
override { group_->ExecuteInThread(); }
114 void ExecuteInThread();
120 void ExitShell(
int exit_code);
133 : data_(contents.Data()),
134 length_(contents.ByteLength()),
135 deleter_(contents.Deleter()),
136 deleter_data_(contents.DeleterData()) {}
138 : data_(contents.Data()),
139 length_(contents.ByteLength()),
140 deleter_(contents.Deleter()),
141 deleter_data_(contents.DeleterData()) {}
143 : data_(other.data_),
144 length_(other.length_),
145 deleter_(other.deleter_),
146 deleter_data_(other.deleter_data_) {
147 other.data_ =
nullptr;
149 other.deleter_ =
nullptr;
150 other.deleter_data_ =
nullptr;
153 if (
this != &other) {
155 length_ = other.length_;
156 deleter_ = other.deleter_;
157 deleter_data_ = other.deleter_data_;
158 other.data_ =
nullptr;
160 other.deleter_ =
nullptr;
161 other.deleter_data_ =
nullptr;
170 ArrayBuffer::Contents::DeleterCallback deleter_;
180 uint8_t* data() {
return data_.get(); }
181 size_t size() {
return size_; }
182 const std::vector<ArrayBuffer::Contents>& array_buffer_contents() {
183 return array_buffer_contents_;
185 const std::vector<SharedArrayBuffer::Contents>&
186 shared_array_buffer_contents() {
187 return shared_array_buffer_contents_;
189 const std::vector<WasmCompiledModule::TransferrableModule>&
190 transferrable_modules() {
191 return transferrable_modules_;
196 void operator()(uint8_t* p)
const { free(p); }
199 std::unique_ptr<uint8_t, DataDeleter> data_;
201 std::vector<ArrayBuffer::Contents> array_buffer_contents_;
202 std::vector<SharedArrayBuffer::Contents> shared_array_buffer_contents_;
203 std::vector<WasmCompiledModule::TransferrableModule> transferrable_modules_;
214 void Enqueue(std::unique_ptr<SerializationData> data);
215 bool Dequeue(std::unique_ptr<SerializationData>* data);
221 std::vector<std::unique_ptr<SerializationData>> data_;
232 void StartExecuteInThread(
const char* script);
236 void PostMessage(std::unique_ptr<SerializationData> data);
242 std::unique_ptr<SerializationData> GetMessage();
249 void WaitForThread();
254 explicit WorkerThread(
Worker* worker)
258 void Run()
override { worker_->ExecuteInThread(); }
264 void ExecuteInThread();
273 base::Atomic32 running_;
299 AsyncHooks* GetAsyncHooks() {
return async_hooks_wrapper_; }
303 friend class RealmScope;
310 std::queue<Global<Function>> set_timeout_callbacks_;
311 std::queue<Global<Context>> set_timeout_contexts_;
321 enum CodeCacheOptions {
324 kProduceCacheAfterExecute
328 : send_idle_notification(
false),
329 invoke_weak_callbacks(
false),
335 interactive_shell(
false),
337 expected_to_throw(
false),
338 mock_arraybuffer_allocator(
false),
339 enable_inspector(
false),
341 compile_options(v8::ScriptCompiler::kNoCompileOptions),
342 stress_background_compile(
false),
343 code_cache_options(CodeCacheOptions::kNoProduceCache),
344 isolate_sources(
nullptr),
345 icu_data_file(
nullptr),
346 natives_blob(
nullptr),
347 snapshot_blob(
nullptr),
348 trace_enabled(
false),
350 trace_config(
nullptr),
352 disable_in_process_stack_traces(
false),
353 read_from_tcp_port(-1) {}
356 delete[] isolate_sources;
359 bool send_idle_notification;
360 bool invoke_weak_callbacks;
366 bool interactive_shell;
368 bool expected_to_throw;
369 bool mock_arraybuffer_allocator;
370 size_t mock_arraybuffer_allocator_limit = 0;
371 bool enable_inspector;
373 v8::ScriptCompiler::CompileOptions compile_options;
374 bool stress_background_compile;
375 CodeCacheOptions code_cache_options;
377 const char* icu_data_file;
378 const char* natives_blob;
379 const char* snapshot_blob;
381 const char* trace_path;
382 const char* trace_config;
383 const char* lcov_file;
384 bool disable_in_process_stack_traces;
385 int read_from_tcp_port;
386 bool enable_os_system =
false;
387 bool quiet_load =
false;
388 int thread_pool_size = 0;
389 bool stress_delay_tasks =
false;
390 std::vector<const char*> arguments;
391 bool include_arguments =
true;
396 enum PrintResult :
bool { kPrintResult =
true, kNoPrintResult =
false };
397 enum ReportExceptions :
bool {
398 kReportExceptions =
true,
399 kNoReportExceptions =
false 401 enum ProcessMessageQueue :
bool {
402 kProcessMessageQueue =
true,
403 kNoProcessMessageQueue =
false 406 static bool ExecuteString(Isolate* isolate,
Local<String> source,
408 ReportExceptions report_exceptions,
409 ProcessMessageQueue process_message_queue);
410 static bool ExecuteModule(Isolate* isolate,
const char* file_name);
411 static void ReportException(Isolate* isolate, TryCatch* try_catch);
412 static Local<String> ReadFile(Isolate* isolate,
const char* name);
414 static int RunMain(Isolate* isolate,
int argc,
char* argv[],
bool last_run);
415 static int Main(
int argc,
char* argv[]);
416 static void Exit(
int exit_code);
417 static void OnExit(Isolate* isolate);
418 static void CollectGarbage(Isolate* isolate);
419 static bool EmptyMessageQueues(Isolate* isolate);
420 static void CompleteMessageLoop(Isolate* isolate);
422 static std::unique_ptr<SerializationData> SerializeValue(
425 Isolate* isolate, std::unique_ptr<SerializationData> data);
426 static void CleanupWorkers();
427 static int* LookupCounter(
const char* name);
428 static void* CreateHistogram(
const char* name,
432 static void AddHistogramSample(
void* histogram,
int sample);
433 static void MapCounters(v8::Isolate* isolate,
const char* name);
442 static void RealmCreateAllowCrossRealmAccess(
453 static void AsyncHooksCreateHook(
455 static void AsyncHooksExecutionAsyncId(
457 static void AsyncHooksTriggerAsyncId(
472 args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
477 static void WorkerPostMessage(
517 static void HostInitializeImportMetaObject(
Local<Context> context,
524 static void DoHostImportModuleDynamically(
void* data);
525 static void AddOSMethods(v8::Isolate* isolate,
528 static const char* kPrompt;
532 static void SetWaitUntilDone(Isolate* isolate,
bool value);
534 static char* ReadCharsFromTcpPort(
const char* name,
int* size_out);
536 static void set_script_executed() { script_executed_.store(
true); }
537 static bool use_interactive_shell() {
538 return (options.interactive_shell || !script_executed_.load()) &&
544 static base::OnceType quit_once_;
546 static CounterMap* counter_map_;
556 static bool allow_new_workers_;
557 static std::vector<Worker*> workers_;
558 static std::vector<ExternalizedContents> externalized_contents_;
561 static std::atomic<bool> script_executed_;
563 static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate);
565 static void WriteLcovData(v8::Isolate* isolate,
const char* file);
566 static Counter* GetCounter(
const char* name,
bool is_histogram);
568 static void Initialize(Isolate* isolate);
569 static void RunShell(Isolate* isolate);
570 static bool SetOptions(
int argc,
char* argv[]);
578 const std::string& file_name);
581 static void StoreInCodeCache(Isolate* isolate,
Local<Value> name,
586 static std::map<Isolate*, bool> isolate_status_;
589 static std::map<std::string, std::unique_ptr<ScriptCompiler::CachedData>>