• Home
  • Raw
  • Download

Lines Matching +full:hook +full:- +full:run +full:- +full:in +full:- +full:context

2 #include "allocated_buffer-inl.h"
4 #include "base_object-inl.h"
5 #include "debug_utils-inl.h"
6 #include "diagnosticfilename-inl.h"
7 #include "memory_tracker-inl.h"
12 #include "node_options-inl.h"
13 #include "node_process-inl.h"
14 #include "node_v8_platform-inl.h"
16 #include "req_wrap-inl.h"
20 #include "util-inl.h"
21 #include "v8-profiler.h"
33 using v8::Context;
62 Isolate* isolate = creator->GetIsolate(); in Serialize()
74 indexes.push_back(creator->AddData(PropertyName##_.Get(isolate))); in Serialize()
83 indexes.push_back(creator->AddData(async_wrap_provider(i))); in Serialize()
98 isolate_->GetDataFromSnapshotOnce<TypeName>((*indexes)[i++]); \ in DeserializeProperties()
115 isolate_->GetDataFromSnapshotOnce<String>((*indexes)[i++]); in DeserializeProperties()
129 // because the string is created in the old space straight away. It's going in CreateProperties()
130 // to end up in the old space sooner or later anyway but now it doesn't go in CreateProperties()
133 // One byte because our strings are ASCII and we can safely skip V8's UTF-8 in CreateProperties()
146 sizeof(StringValue) - 1) \ in CreateProperties()
158 sizeof(StringValue) - 1) \ in CreateProperties()
168 sizeof(StringValue) - 1) \ in CreateProperties()
173 // Create all the provider strings that will be passed to JS. Place them in in CreateProperties()
183 sizeof(#Provider) - 1).ToLocalChecked()); in CreateProperties()
196 : node_allocator->GetImpl()), in IsolateData()
199 new PerIsolateOptions(*(per_process::cli_options->per_isolate))); in IsolateData()
210 tracker->TrackField(#PropertyName, PropertyName()); in MemoryInfo()
216 tracker->TrackField("async_wrap_providers", async_wrap_providers_); in MemoryInfo()
219 tracker->TrackFieldWithSize( in MemoryInfo()
222 tracker->TrackFieldWithSize( in MemoryInfo()
224 // TODO(joyeecheung): implement MemoryRetainer in the option classes. in MemoryInfo()
232 if (!env_->owns_process_state() || !env_->can_call_into_js()) { in UpdateTraceCategoryState()
236 // `StopTracing()`. The only way to do this in a threadsafe fashion in UpdateTraceCategoryState()
245 Isolate* isolate = env_->isolate(); in UpdateTraceCategoryState()
247 Local<Function> cb = env_->trace_category_state_function(); in UpdateTraceCategoryState()
253 USE(cb->Call(env_->context(), Undefined(isolate), arraysize(args), args)); in UpdateTraceCategoryState()
258 Local<Context> ctx = context(); in CreateProperties()
261 Context::Scope context_scope(ctx); in CreateProperties()
263 templ->InstanceTemplate()->SetInternalFieldCount( in CreateProperties()
265 templ->Inherit(BaseObject::GetConstructorTemplate(this)); in CreateProperties()
270 // Store primordials setup by the per-context script in the environment. in CreateProperties()
274 per_context_bindings->Get(ctx, primordials_string()).ToLocalChecked(); in CreateProperties()
275 CHECK(primordials->IsObject()); in CreateProperties()
285 ->Get(ctx, \ in CreateProperties()
288 CHECK(ctor->IsObject()); \ in CreateProperties()
290 ctor.As<Object>()->Get(ctx, prototype_string).ToLocalChecked(); \ in CreateProperties()
291 CHECK(prototype->IsObject()); \ in CreateProperties()
333 Local<Context> context, in Environment() argument
338 : isolate_(context->GetIsolate()), in Environment()
340 immediate_info_(context->GetIsolate()), in Environment()
341 tick_info_(context->GetIsolate()), in Environment()
342 timer_base_(uv_now(isolate_data->event_loop())), in Environment()
349 thread_id_(thread_id.id == static_cast<uint64_t>(-1) ? in Environment()
351 context_(context->GetIsolate(), context) { in Environment()
352 // We'll be creating new objects so make sure we've entered the context. in Environment()
354 Context::Scope context_scope(context); in Environment()
367 // We create new copies of the per-Environment option sets, so that it is in Environment()
369 // part of the per-Isolate option set, for which in turn the defaults are in Environment()
370 // part of the per-process option set. in Environment()
372 *isolate_data->options()->per_env); in Environment()
374 options_->debug_options().host_port); in Environment()
385 AssignToContext(context, ContextInfo("")); in Environment()
393 if (TracingController* tracing_controller = writer->GetTracingController()) in Environment()
394 tracing_controller->AddTraceStateObserver(trace_state_observer_.get()); in Environment()
401 performance_state_->Mark( in Environment()
403 performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_NODE_START, in Environment()
405 performance_state_->Mark( in Environment()
412 traced_value->BeginArray("args"); in Environment()
413 for (const std::string& arg : args) traced_value->AppendString(arg); in Environment()
414 traced_value->EndArray(); in Environment()
415 traced_value->BeginArray("exec_args"); in Environment()
416 for (const std::string& arg : exec_args) traced_value->AppendString(arg); in Environment()
417 traced_value->EndArray(); in Environment()
425 // By default, always abort when --abort-on-uncaught-exception was passed. in Environment()
428 if (!options_->force_async_hooks_checks) { in Environment()
443 // There are pending RequestInterrupt() callbacks. Tell them not to run, in ~Environment()
444 // then force V8 to run interrupts by compiling and running an empty script in ~Environment()
451 Context::Scope context_scope(context()); in ~Environment()
455 isolate()->RequestInterrupt([](Isolate*, void* data) { in ~Environment()
461 if (Script::Compile(context(), String::Empty(isolate())).ToLocal(&script)) in ~Environment()
462 USE(script->Run(context())); in ~Environment()
470 if (options_->heap_snapshot_near_heap_limit > heap_limit_snapshot_taken_) { in ~Environment()
471 isolate_->RemoveNearHeapLimitCallback(Environment::NearHeapLimitCallback, in ~Environment()
475 isolate()->GetHeapProfiler()->RemoveBuildEmbedderGraphCallback( in ~Environment()
481 // Destroy inspector agent before erasing the context. The inspector in ~Environment()
482 // destructor depends on the context still being accessible. in ~Environment()
486 context()->SetAlignedPointerInEmbedderData( in ~Environment()
492 if (TracingController* tracing_controller = writer->GetTracingController()) in ~Environment()
493 tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get()); in ~Environment()
516 Context::Scope context_scope(context()); in InitializeLibuv()
528 // Inform V8's CPU profiler when we're idle. The profiler is sampling-based in InitializeLibuv()
529 // but not all samples are created equal; mark the wall clock time spent in in InitializeLibuv()
531 // still end up in v8.log but with state=IDLE rather than state=EXTERNAL. in InitializeLibuv()
541 HandleScope handle_scope(env->isolate()); in InitializeLibuv()
542 Context::Scope context_scope(env->context()); in InitializeLibuv()
543 env->RunAndClearNativeImmediates(); in InitializeLibuv()
558 // Register clean-up cb to be called to clean up the handles in InitializeLibuv()
559 // when the environment is freed, note that they are not cleaned in in InitializeLibuv()
560 // the one environment per process setup, but will be called in in InitializeLibuv()
570 isolate_->TerminateExecution(); in ExitEnv()
571 SetImmediateThreadsafe([](Environment* env) { uv_stop(env->event_loop()); }); in ExitEnv()
577 handle->data = env; in RegisterHandleCleanups()
579 env->CloseHandle(handle, [](uv_handle_t* handle) { in RegisterHandleCleanups()
581 memset(handle, 0xab, uv_handle_size(handle->type)); in RegisterHandleCleanups()
609 request->Cancel(); in CleanupHandles()
612 handle->Close(); in CleanupHandles()
628 env->isolate()->SetIdle(true); in StartProfilerIdleNotifier()
632 env->isolate()->SetIdle(false); in StartProfilerIdleNotifier()
660 // Copy into a vector, since we can't sort an unordered_set in-place. in RunCleanup()
664 // need to be able to check whether they were un-scheduled by another hook. in RunCleanup()
668 // Sort in descending order so that the most recently inserted callbacks in RunCleanup()
669 // are run first. in RunCleanup()
675 // This hook was removed from the `cleanup_hooks_` set during another in RunCleanup()
676 // hook that was run earlier. Nothing to do here. in RunCleanup()
716 head->Call(this); in RunAndClearInterrupts()
735 while (auto head = queue->Shift()) { in RunAndClearNativeImmediates()
736 bool is_refed = head->flags() & CallbackFlags::kRefed; in RunAndClearNativeImmediates()
741 head->Call(this); in RunAndClearNativeImmediates()
756 immediate_info()->ref_count_dec(ref_count); in RunAndClearNativeImmediates()
758 if (immediate_info()->ref_count() == 0) in RunAndClearNativeImmediates()
767 // count in immediate_info() either. in RunAndClearNativeImmediates()
778 // situation in which the Environment is destroyed before the handler runs in RequestInterruptFromV8()
783 // callbacks are already scheduled to run and we can delete our own pointer in RequestInterruptFromV8()
785 // ~Environment sets the Environment* contained in it to nullptr, so that in RequestInterruptFromV8()
786 // the callback can check whether ~Environment has already run and it is thus in RequestInterruptFromV8()
795 isolate()->RequestInterrupt([](Isolate* isolate, void* data) { in RequestInterruptFromV8()
804 env->interrupt_data_.store(nullptr); in RequestInterruptFromV8()
805 env->RunAndClearInterrupts(); in RequestInterruptFromV8()
829 if (!env->can_call_into_js()) in RunTimers()
832 HandleScope handle_scope(env->isolate()); in RunTimers()
833 Context::Scope context_scope(env->context()); in RunTimers()
835 Local<Object> process = env->process_object(); in RunTimers()
838 Local<Function> cb = env->timers_callback_function(); in RunTimers()
840 Local<Value> arg = env->GetNow(); in RunTimers()
842 // impossible for us to end up in an infinite loop due to how the JS-side in RunTimers()
847 ret = cb->Call(env->context(), process, 1, &arg); in RunTimers()
848 } while (ret.IsEmpty() && env->can_call_into_js()); in RunTimers()
858 // To allow for less JS-C++ boundary crossing, the value returned from JS in RunTimers()
866 ret.ToLocalChecked()->IntegerValue(env->context()).FromJust(); in RunTimers()
872 llabs(expiry_ms) - (uv_now(env->event_loop()) - env->timer_base()); in RunTimers()
874 env->ScheduleTimer(duration_ms > 0 ? duration_ms : 1); in RunTimers()
891 HandleScope scope(env->isolate()); in CheckImmediate()
892 Context::Scope context_scope(env->context()); in CheckImmediate()
894 env->RunAndClearNativeImmediates(); in CheckImmediate()
896 if (env->immediate_info()->count() == 0 || !env->can_call_into_js()) in CheckImmediate()
900 MakeCallback(env->isolate(), in CheckImmediate()
901 env->process_object(), in CheckImmediate()
902 env->immediate_callback_function(), in CheckImmediate()
906 } while (env->immediate_info()->has_outstanding() && env->can_call_into_js()); in CheckImmediate()
908 if (env->immediate_info()->ref_count() == 0) in CheckImmediate()
909 env->ToggleImmediateRef(false); in CheckImmediate()
916 // Idle handle is needed only to stop the event loop from blocking in poll. in ToggleImmediateRef()
928 now -= timer_base(); in GetNow()
943 obj->Set(env->context(), in CollectExceptionInfo()
944 env->errno_string(), in CollectExceptionInfo()
945 Integer::New(env->isolate(), errorno)).Check(); in CollectExceptionInfo()
947 obj->Set(env->context(), env->code_string(), in CollectExceptionInfo()
948 OneByteString(env->isolate(), err_string)).Check(); in CollectExceptionInfo()
951 obj->Set(env->context(), env->message_string(), in CollectExceptionInfo()
952 OneByteString(env->isolate(), message)).Check(); in CollectExceptionInfo()
958 Buffer::Copy(env->isolate(), path, strlen(path)).ToLocalChecked(); in CollectExceptionInfo()
959 obj->Set(env->context(), env->path_string(), path_buffer).Check(); in CollectExceptionInfo()
965 Buffer::Copy(env->isolate(), dest, strlen(dest)).ToLocalChecked(); in CollectExceptionInfo()
966 obj->Set(env->context(), env->dest_string(), dest_buffer).Check(); in CollectExceptionInfo()
970 obj->Set(env->context(), env->syscall_string(), in CollectExceptionInfo()
971 OneByteString(env->isolate(), syscall)).Check(); in CollectExceptionInfo()
981 if (!object->IsObject() || errorno == 0) in CollectUVExceptionInfo()
996 tracker->TrackField("fields", fields_); in MemoryInfo()
1000 tracker->TrackField("fields", fields_); in MemoryInfo()
1004 tracker->TrackField("async_ids_stack", async_ids_stack_); in MemoryInfo()
1005 tracker->TrackField("fields", fields_); in MemoryInfo()
1006 tracker->TrackField("async_id_fields", async_id_fields_); in MemoryInfo()
1007 tracker->TrackField("js_promise_hooks", js_promise_hooks_); in MemoryInfo()
1013 env()->async_hooks_binding()->Set( in grow_async_ids_stack()
1014 env()->context(), in grow_async_ids_stack()
1015 env()->async_ids_stack_string(), in grow_async_ids_stack()
1022 if (options()->trace_exit) { in Exit()
1049 w->Exit(1); in stop_sub_worker_contexts()
1050 w->JoinThread(); in stop_sub_worker_contexts()
1056 return worker_context()->env(); in worker_parent_env()
1064 this, "File descriptor %d opened in unmanaged mode twice", fd); in AddUnmanagedFd()
1073 this, "File descriptor %d closed but not opened in unmanaged mode", fd); in RemoveUnmanagedFd()
1088 // C++-backed Node.js objects on the heap that do not fall into the above in VerifyNoStrongBaseObjects()
1092 // In order to avoid this kind of problem, we check the list of BaseObjects in VerifyNoStrongBaseObjects()
1094 // or when in debug mode (where --verify-base-objects is always-on). in VerifyNoStrongBaseObjects()
1096 if (!options()->verify_base_objects) return; in VerifyNoStrongBaseObjects()
1099 if (obj->IsNotIndicativeOfMemoryLeakAtExit()) return; in VerifyNoStrongBaseObjects()
1101 obj->MemoryInfoName().c_str()); in VerifyNoStrongBaseObjects()
1123 return allowed - rss; in GuessMemoryAvailableToTheProcess()
1132 env->ForEachBaseObject([&](BaseObject* obj) { in BuildEmbedderGraph()
1133 if (obj->IsDoneInitializing()) in BuildEmbedderGraph()
1148 env->is_processing_heap_limit_callback_, in NearHeapLimitCallback()
1152 size_t max_young_gen_size = env->isolate_data()->max_young_gen_size; in NearHeapLimitCallback()
1157 size_t num_heap_spaces = env->isolate()->NumberOfHeapSpaces(); in NearHeapLimitCallback()
1159 env->isolate()->GetHeapSpaceStatistics(&stats, i); in NearHeapLimitCallback()
1190 // This might be hit when the snapshot is being taken in another in NearHeapLimitCallback()
1192 // When taking the snapshot, objects in the young generation may be in NearHeapLimitCallback()
1193 // promoted to the old generation, result in increased heap usage, in NearHeapLimitCallback()
1195 // Ideally, this should be as small as possible - the heap limit in NearHeapLimitCallback()
1197 // new limit, so in a heap with unbounded growth the isolate in NearHeapLimitCallback()
1198 // may eventually crash with this new limit - effectively raising in NearHeapLimitCallback()
1200 if (env->is_processing_heap_limit_callback_) { in NearHeapLimitCallback()
1204 "Not generating snapshots in nested callback. " in NearHeapLimitCallback()
1217 env->isolate()->RemoveNearHeapLimitCallback(NearHeapLimitCallback, in NearHeapLimitCallback()
1223 env->is_processing_heap_limit_callback_ = true; in NearHeapLimitCallback()
1225 std::string dir = env->options()->diagnostic_dir; in NearHeapLimitCallback()
1227 dir = env->GetCwd(); in NearHeapLimitCallback()
1234 // Remove the callback first in case it's triggered when generating in NearHeapLimitCallback()
1236 env->isolate()->RemoveNearHeapLimitCallback(NearHeapLimitCallback, in NearHeapLimitCallback()
1239 heap::WriteSnapshot(env->isolate(), filename.c_str()); in NearHeapLimitCallback()
1240 env->heap_limit_snapshot_taken_ += 1; in NearHeapLimitCallback()
1243 // --heapsnapshot-near-heap-limit. in NearHeapLimitCallback()
1244 if (env->heap_limit_snapshot_taken_ < in NearHeapLimitCallback()
1245 env->options_->heap_snapshot_near_heap_limit) { in NearHeapLimitCallback()
1246 env->isolate()->AddNearHeapLimitCallback(NearHeapLimitCallback, env); in NearHeapLimitCallback()
1252 env->isolate()->AutomaticallyRestoreInitialHeapLimit(0.95); in NearHeapLimitCallback()
1254 env->is_processing_heap_limit_callback_ = false; in NearHeapLimitCallback()
1260 // Remove non pointer fields that will be tracked in MemoryInfo() in SelfSize()
1264 size -= sizeof(async_hooks_); in SelfSize()
1265 size -= sizeof(tick_info_); in SelfSize()
1266 size -= sizeof(immediate_info_); in SelfSize()
1273 tracker->TrackField("isolate_data", isolate_data_); in MemoryInfo()
1274 tracker->TrackField("native_modules_with_cache", native_modules_with_cache); in MemoryInfo()
1275 tracker->TrackField("native_modules_without_cache", in MemoryInfo()
1277 tracker->TrackField("destroy_async_id_list", destroy_async_id_list_); in MemoryInfo()
1278 tracker->TrackField("exec_argv", exec_argv_); in MemoryInfo()
1279 tracker->TrackField("should_abort_on_uncaught_toggle", in MemoryInfo()
1281 tracker->TrackField("stream_base_state", stream_base_state_); in MemoryInfo()
1282 tracker->TrackFieldWithSize( in MemoryInfo()
1284 tracker->TrackField("async_hooks", async_hooks_); in MemoryInfo()
1285 tracker->TrackField("immediate_info", immediate_info_); in MemoryInfo()
1286 tracker->TrackField("tick_info", tick_info_); in MemoryInfo()
1289 tracker->TrackField(#PropertyName, PropertyName()); in MemoryInfo()
1293 // FIXME(joyeecheung): track other fields in Environment. in MemoryInfo()
1296 // - Internal types that do not implement MemoryRetainer yet in MemoryInfo()
1297 // - STL containers with MemoryRetainer* inside in MemoryInfo()
1298 // - STL containers with numeric types inside that should not have their in MemoryInfo()
1299 // nodes elided e.g. numeric keys in maps. in MemoryInfo()
1300 // We also need to make sure that when we add a non-pointer field as its own in MemoryInfo()
1305 isolate()->ClearKeptObjects(); in RunWeakRefCleanup()
1311 if (self->has_pointer_data() && in DeleteMe()
1312 self->pointer_data()->strong_ptr_count > 0) { in DeleteMe()
1313 return self->Detach(); in DeleteMe()
1329 Local<FunctionTemplate> tmpl = env->base_object_ctor_template(); in GetConstructorTemplate()
1331 tmpl = env->NewFunctionTemplate(nullptr); in GetConstructorTemplate()
1332 tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "BaseObject")); in GetConstructorTemplate()
1333 env->set_base_object_ctor_template(tmpl); in GetConstructorTemplate()