Lines Matching +full:hook +full:- +full:run +full:- +full:in +full:- +full:context
4 #include "debug_utils-inl.h"
5 #include "memory_tracker-inl.h"
11 #include "node_options-inl.h"
13 #include "node_v8_platform-inl.h"
15 #include "req_wrap-inl.h"
18 #include "util-inl.h"
19 #include "v8-profiler.h"
30 using v8::Context;
60 Isolate* isolate = creator->GetIsolate(); in Serialize()
72 indexes.push_back(creator->AddData(PropertyName##_.Get(isolate))); in Serialize()
81 indexes.push_back(creator->AddData(async_wrap_provider(i))); in Serialize()
96 isolate_->GetDataFromSnapshotOnce<TypeName>((*indexes)[i++]); \ in DeserializeProperties()
112 isolate_->GetDataFromSnapshotOnce<String>((*indexes)[i++]); in DeserializeProperties()
125 // because the string is created in the old space straight away. It's going in CreateProperties()
126 // to end up in the old space sooner or later anyway but now it doesn't go in CreateProperties()
129 // One byte because our strings are ASCII and we can safely skip V8's UTF-8 in CreateProperties()
142 sizeof(StringValue) - 1) \ in CreateProperties()
154 sizeof(StringValue) - 1) \ in CreateProperties()
164 sizeof(StringValue) - 1) \ in CreateProperties()
169 // Create all the provider strings that will be passed to JS. Place them in in CreateProperties()
179 sizeof(#Provider) - 1).ToLocalChecked()); in CreateProperties()
191 allocator_(isolate->GetArrayBufferAllocator()), in IsolateData()
193 : node_allocator->GetImpl()), in IsolateData()
199 new PerIsolateOptions(*(per_process::cli_options->per_isolate))); in IsolateData()
210 tracker->TrackField(#PropertyName, PropertyName()); in MemoryInfo()
215 tracker->TrackField(#PropertyName, PropertyName()); in MemoryInfo()
219 tracker->TrackField("async_wrap_providers", async_wrap_providers_); in MemoryInfo()
222 tracker->TrackFieldWithSize( in MemoryInfo()
225 tracker->TrackFieldWithSize( in MemoryInfo()
228 tracker->TrackFieldWithSize( in MemoryInfo()
230 // TODO(joyeecheung): implement MemoryRetainer in the option classes. in MemoryInfo()
238 if (!env_->owns_process_state() || !env_->can_call_into_js()) { in UpdateTraceCategoryState()
242 // `StopTracing()`. The only way to do this in a threadsafe fashion in UpdateTraceCategoryState()
251 Isolate* isolate = env_->isolate(); in UpdateTraceCategoryState()
253 Local<Function> cb = env_->trace_category_state_function(); in UpdateTraceCategoryState()
259 USE(cb->Call(env_->context(), Undefined(isolate), arraysize(args), args)); in UpdateTraceCategoryState()
264 Local<Context> ctx = context(); in CreateProperties()
266 templ->InstanceTemplate()->SetInternalFieldCount(1); in CreateProperties()
267 templ->Inherit(BaseObject::GetConstructorTemplate(this)); in CreateProperties()
268 Local<Object> obj = templ->GetFunction(ctx) in CreateProperties()
270 ->NewInstance(ctx) in CreateProperties()
272 obj->SetAlignedPointerInInternalField(0, this); in CreateProperties()
276 // Store primordials setup by the per-context script in the environment. in CreateProperties()
280 per_context_bindings->Get(ctx, primordials_string()).ToLocalChecked(); in CreateProperties()
281 CHECK(primordials->IsObject()); in CreateProperties()
316 Local<Context> context, in Environment() argument
321 : isolate_(context->GetIsolate()), in Environment()
323 immediate_info_(context->GetIsolate()), in Environment()
324 tick_info_(context->GetIsolate()), in Environment()
325 timer_base_(uv_now(isolate_data->event_loop())), in Environment()
332 thread_id_(thread_id.id == static_cast<uint64_t>(-1) ? in Environment()
336 context_(context->GetIsolate(), context) { in Environment()
337 // We'll be creating new objects so make sure we've entered the context. in Environment()
339 Context::Scope context_scope(context); in Environment()
352 // We create new copies of the per-Environment option sets, so that it is in Environment()
354 // part of the per-Isolate option set, for which in turn the defaults are in Environment()
355 // part of the per-process option set. in Environment()
356 options_.reset(new EnvironmentOptions(*isolate_data->options()->per_env)); in Environment()
358 new ExclusiveAccess<HostPort>(options_->debug_options().host_port)); in Environment()
369 AssignToContext(context, ContextInfo("")); in Environment()
377 if (TracingController* tracing_controller = writer->GetTracingController()) in Environment()
378 tracing_controller->AddTraceStateObserver(trace_state_observer_.get()); in Environment()
385 performance_state_->Mark( in Environment()
387 performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_NODE_START, in Environment()
389 performance_state_->Mark( in Environment()
396 traced_value->BeginArray("args"); in Environment()
397 for (const std::string& arg : args) traced_value->AppendString(arg); in Environment()
398 traced_value->EndArray(); in Environment()
399 traced_value->BeginArray("exec_args"); in Environment()
400 for (const std::string& arg : exec_args) traced_value->AppendString(arg); in Environment()
401 traced_value->EndArray(); in Environment()
409 // By default, always abort when --abort-on-uncaught-exception was passed. in Environment()
412 if (options_->no_force_async_hooks_checks) { in Environment()
423 // There are pending RequestInterrupt() callbacks. Tell them not to run, in ~Environment()
424 // then force V8 to run interrupts by compiling and running an empty script in ~Environment()
431 Context::Scope context_scope(context()); in ~Environment()
435 isolate()->RequestInterrupt([](Isolate*, void* data) { in ~Environment()
441 if (Script::Compile(context(), String::Empty(isolate())).ToLocal(&script)) in ~Environment()
442 USE(script->Run(context())); in ~Environment()
447 isolate()->GetHeapProfiler()->RemoveBuildEmbedderGraphCallback( in ~Environment()
450 // Make sure there are no re-used libuv wrapper objects. in ~Environment()
457 // Destroy inspector agent before erasing the context. The inspector in ~Environment()
458 // destructor depends on the context still being accessible. in ~Environment()
462 context()->SetAlignedPointerInEmbedderData( in ~Environment()
468 if (TracingController* tracing_controller = writer->GetTracingController()) in ~Environment()
469 tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get()); in ~Environment()
497 Context::Scope context_scope(context()); in InitializeLibuv()
509 // Inform V8's CPU profiler when we're idle. The profiler is sampling-based in InitializeLibuv()
510 // but not all samples are created equal; mark the wall clock time spent in in InitializeLibuv()
512 // still end up in v8.log but with state=IDLE rather than state=EXTERNAL. in InitializeLibuv()
514 // probably fortify in the API contract, namely that the last started prepare in InitializeLibuv()
515 // or check watcher runs first. It's not 100% foolproof; if an add-on starts in InitializeLibuv()
526 env->CleanupFinalizationGroups(); in InitializeLibuv()
527 env->RunAndClearNativeImmediates(); in InitializeLibuv()
542 // Register clean-up cb to be called to clean up the handles in InitializeLibuv()
543 // when the environment is freed, note that they are not cleaned in in InitializeLibuv()
544 // the one environment per process setup, but will be called in in InitializeLibuv()
557 isolate_->TerminateExecution(); in Stop()
558 SetImmediateThreadsafe([](Environment* env) { uv_stop(env->event_loop()); }); in Stop()
564 handle->data = env; in RegisterHandleCleanups()
566 env->CloseHandle(handle, [](uv_handle_t* handle) { in RegisterHandleCleanups()
568 memset(handle, 0xab, uv_handle_size(handle->type)); in RegisterHandleCleanups()
596 request->Cancel(); in CleanupHandles()
599 handle->Close(); in CleanupHandles()
622 env->isolate()->SetIdle(true); in StartProfilerIdleNotifier()
627 env->isolate()->SetIdle(false); in StartProfilerIdleNotifier()
659 // Copy into a vector, since we can't sort an unordered_set in-place. in RunCleanup()
663 // need to be able to check whether they were un-scheduled by another hook. in RunCleanup()
667 // Sort in descending order so that the most recently inserted callbacks in RunCleanup()
668 // are run first. in RunCleanup()
674 // This hook was removed from the `cleanup_hooks_` set during another in RunCleanup()
675 // hook that was run earlier. Nothing to do here. in RunCleanup()
715 head->Call(this); in RunAndClearInterrupts()
734 while (auto head = queue->Shift()) { in RunAndClearNativeImmediates()
735 bool is_refed = head->flags() & CallbackFlags::kRefed; in RunAndClearNativeImmediates()
740 head->Call(this); in RunAndClearNativeImmediates()
755 immediate_info()->ref_count_dec(ref_count); in RunAndClearNativeImmediates()
757 if (immediate_info()->ref_count() == 0) in RunAndClearNativeImmediates()
766 // count in immediate_info() either. in RunAndClearNativeImmediates()
777 // situation in which the Environment is destroyed before the handler runs in RequestInterruptFromV8()
782 // callbacks are already scheduled to run and we can delete our own pointer in RequestInterruptFromV8()
784 // ~Environment sets the Environment* contained in it to nullptr, so that in RequestInterruptFromV8()
785 // the callback can check whether ~Environment has already run and it is thus in RequestInterruptFromV8()
794 isolate()->RequestInterrupt([](Isolate* isolate, void* data) { in RequestInterruptFromV8()
803 env->interrupt_data_.store(nullptr); in RequestInterruptFromV8()
804 env->RunAndClearInterrupts(); in RequestInterruptFromV8()
828 if (!env->can_call_into_js()) in RunTimers()
831 HandleScope handle_scope(env->isolate()); in RunTimers()
832 Context::Scope context_scope(env->context()); in RunTimers()
834 Local<Object> process = env->process_object(); in RunTimers()
837 Local<Function> cb = env->timers_callback_function(); in RunTimers()
839 Local<Value> arg = env->GetNow(); in RunTimers()
841 // impossible for us to end up in an infinite loop due to how the JS-side in RunTimers()
846 ret = cb->Call(env->context(), process, 1, &arg); in RunTimers()
847 } while (ret.IsEmpty() && env->can_call_into_js()); in RunTimers()
857 // To allow for less JS-C++ boundary crossing, the value returned from JS in RunTimers()
865 ret.ToLocalChecked()->IntegerValue(env->context()).FromJust(); in RunTimers()
871 llabs(expiry_ms) - (uv_now(env->event_loop()) - env->timer_base()); in RunTimers()
873 env->ScheduleTimer(duration_ms > 0 ? duration_ms : 1); in RunTimers()
890 HandleScope scope(env->isolate()); in CheckImmediate()
891 Context::Scope context_scope(env->context()); in CheckImmediate()
893 env->RunAndClearNativeImmediates(); in CheckImmediate()
895 if (env->immediate_info()->count() == 0 || !env->can_call_into_js()) in CheckImmediate()
899 MakeCallback(env->isolate(), in CheckImmediate()
900 env->process_object(), in CheckImmediate()
901 env->immediate_callback_function(), in CheckImmediate()
905 } while (env->immediate_info()->has_outstanding() && env->can_call_into_js()); in CheckImmediate()
907 if (env->immediate_info()->ref_count() == 0) in CheckImmediate()
908 env->ToggleImmediateRef(false); in CheckImmediate()
915 // Idle handle is needed only to stop the event loop from blocking in poll. in ToggleImmediateRef()
927 now -= timer_base(); in GetNow()
942 obj->Set(env->context(), in CollectExceptionInfo()
943 env->errno_string(), in CollectExceptionInfo()
944 Integer::New(env->isolate(), errorno)).Check(); in CollectExceptionInfo()
946 obj->Set(env->context(), env->code_string(), in CollectExceptionInfo()
947 OneByteString(env->isolate(), err_string)).Check(); in CollectExceptionInfo()
950 obj->Set(env->context(), env->message_string(), in CollectExceptionInfo()
951 OneByteString(env->isolate(), message)).Check(); in CollectExceptionInfo()
957 Buffer::Copy(env->isolate(), path, strlen(path)).ToLocalChecked(); in CollectExceptionInfo()
958 obj->Set(env->context(), env->path_string(), path_buffer).Check(); in CollectExceptionInfo()
964 Buffer::Copy(env->isolate(), dest, strlen(dest)).ToLocalChecked(); in CollectExceptionInfo()
965 obj->Set(env->context(), env->dest_string(), dest_buffer).Check(); in CollectExceptionInfo()
969 obj->Set(env->context(), env->syscall_string(), in CollectExceptionInfo()
970 OneByteString(env->isolate(), syscall)).Check(); in CollectExceptionInfo()
980 if (!object->IsObject() || errorno == 0) in CollectUVExceptionInfo()
995 tracker->TrackField("fields", fields_); in MemoryInfo()
999 tracker->TrackField("fields", fields_); in MemoryInfo()
1003 tracker->TrackField("async_ids_stack", async_ids_stack_); in MemoryInfo()
1004 tracker->TrackField("fields", fields_); in MemoryInfo()
1005 tracker->TrackField("async_id_fields", async_id_fields_); in MemoryInfo()
1011 env()->async_hooks_binding()->Set( in grow_async_ids_stack()
1012 env()->context(), in grow_async_ids_stack()
1013 env()->async_ids_stack_string(), in grow_async_ids_stack()
1020 if (options()->trace_exit) { in Exit()
1045 w->Exit(1); in stop_sub_worker_contexts()
1046 w->JoinThread(); in stop_sub_worker_contexts()
1052 return worker_context()->env(); in worker_parent_env()
1060 this, "File descriptor %d opened in unmanaged mode twice", fd); in AddUnmanagedFd()
1069 this, "File descriptor %d closed but not opened in unmanaged mode", fd); in RemoveUnmanagedFd()
1079 env->ForEachBaseObject([&](BaseObject* obj) { in BuildEmbedderGraph()
1080 if (obj->IsDoneInitializing()) in BuildEmbedderGraph()
1087 // Remove non pointer fields that will be tracked in MemoryInfo() in SelfSize()
1091 size -= sizeof(async_hooks_); in SelfSize()
1092 size -= sizeof(tick_info_); in SelfSize()
1093 size -= sizeof(immediate_info_); in SelfSize()
1100 tracker->TrackField("isolate_data", isolate_data_); in MemoryInfo()
1101 tracker->TrackField("native_modules_with_cache", native_modules_with_cache); in MemoryInfo()
1102 tracker->TrackField("native_modules_without_cache", in MemoryInfo()
1104 tracker->TrackField("destroy_async_id_list", destroy_async_id_list_); in MemoryInfo()
1105 tracker->TrackField("exec_argv", exec_argv_); in MemoryInfo()
1106 tracker->TrackField("should_abort_on_uncaught_toggle", in MemoryInfo()
1108 tracker->TrackField("stream_base_state", stream_base_state_); in MemoryInfo()
1109 tracker->TrackField("fs_stats_field_array", fs_stats_field_array_); in MemoryInfo()
1110 tracker->TrackField("fs_stats_field_bigint_array", in MemoryInfo()
1112 tracker->TrackFieldWithSize( in MemoryInfo()
1114 tracker->TrackField("async_hooks", async_hooks_); in MemoryInfo()
1115 tracker->TrackField("immediate_info", immediate_info_); in MemoryInfo()
1116 tracker->TrackField("tick_info", tick_info_); in MemoryInfo()
1119 tracker->TrackField(#PropertyName, PropertyName()); in MemoryInfo()
1123 // FIXME(joyeecheung): track other fields in Environment. in MemoryInfo()
1126 // - Internal types that do not implement MemoryRetainer yet in MemoryInfo()
1127 // - STL containers with MemoryRetainer* inside in MemoryInfo()
1128 // - STL containers with numeric types inside that should not have their in MemoryInfo()
1129 // nodes elided e.g. numeric keys in maps. in MemoryInfo()
1130 // We also need to make sure that when we add a non-pointer field as its own in MemoryInfo()
1138 if (isolate_data()->uses_node_allocator()) { in Reallocate()
1140 isolate_data()->node_allocator()->Reallocate(data, old_size, size)); in Reallocate()
1148 memset(new_data + old_size, 0, size - old_size); in Reallocate()
1156 MultiIsolatePlatform* platform = isolate_data()->platform(); in AddArrayBufferAllocatorToKeepAliveUntilIsolateDispose()
1160 platform->AddIsolateFinishedCallback(isolate(), [](void* data) { in AddArrayBufferAllocatorToKeepAliveUntilIsolateDispose()
1165 keep_alive_allocators_->insert(allocator); in AddArrayBufferAllocatorToKeepAliveUntilIsolateDispose()
1169 isolate()->ClearKeptObjects(); in RunWeakRefCleanup()
1174 Context::Scope context_scope(context()); in CleanupFinalizationGroups()
1184 // Re-schedule the execution of the remainder of the queue. in CleanupFinalizationGroups()
1195 if (self->has_pointer_data() && in DeleteMe()
1196 self->pointer_data()->strong_ptr_count > 0) { in DeleteMe()
1197 return self->Detach(); in DeleteMe()
1213 Local<FunctionTemplate> tmpl = env->base_object_ctor_template(); in GetConstructorTemplate()
1215 tmpl = env->NewFunctionTemplate(nullptr); in GetConstructorTemplate()
1216 tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "BaseObject")); in GetConstructorTemplate()
1217 env->set_base_object_ctor_template(tmpl); in GetConstructorTemplate()