Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 337ebfc

Browse filesBrowse files
addaleaxtargos
authored andcommitted
src: split out async stack corruption detection from inline fn
This is fairly expensive code that unnecessarily bloats the contents of the inline function. PR-URL: #41331 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 250e197 commit 337ebfc
Copy full SHA for 337ebfc

File tree

Expand file treeCollapse file tree

3 files changed

+21
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-14
lines changed
Open diff view settings
Collapse file

‎src/env-inl.h‎

Copy file name to clipboardExpand all lines: src/env-inl.h
+4-14Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,15 @@ inline void AsyncHooks::push_async_context(double async_id,
166166
inline bool AsyncHooks::pop_async_context(double async_id) {
167167
// In case of an exception then this may have already been reset, if the
168168
// stack was multiple MakeCallback()'s deep.
169-
if (fields_[kStackLength] == 0) return false;
169+
if (UNLIKELY(fields_[kStackLength] == 0)) return false;
170170

171171
// Ask for the async_id to be restored as a check that the stack
172172
// hasn't been corrupted.
173173
// Since async_hooks is experimental, do only perform the check
174174
// when async_hooks is enabled.
175-
if (fields_[kCheck] > 0 && async_id_fields_[kExecutionAsyncId] != async_id) {
176-
fprintf(stderr,
177-
"Error: async hook stack has become corrupted ("
178-
"actual: %.f, expected: %.f)\n",
179-
async_id_fields_.GetValue(kExecutionAsyncId),
180-
async_id);
181-
DumpBacktrace(stderr);
182-
fflush(stderr);
183-
if (!env()->abort_on_uncaught_exception())
184-
exit(1);
185-
fprintf(stderr, "\n");
186-
fflush(stderr);
187-
ABORT_NO_BACKTRACE();
175+
if (UNLIKELY(fields_[kCheck] > 0 &&
176+
async_id_fields_[kExecutionAsyncId] != async_id)) {
177+
FailWithCorruptedAsyncStack(async_id);
188178
}
189179

190180
uint32_t offset = fields_[kStackLength] - 1;
Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,21 @@ void AsyncHooks::grow_async_ids_stack() {
11961196
async_ids_stack_.GetJSArray()).Check();
11971197
}
11981198

1199+
void AsyncHooks::FailWithCorruptedAsyncStack(double expected_async_id) {
1200+
fprintf(stderr,
1201+
"Error: async hook stack has become corrupted ("
1202+
"actual: %.f, expected: %.f)\n",
1203+
async_id_fields_.GetValue(kExecutionAsyncId),
1204+
expected_async_id);
1205+
DumpBacktrace(stderr);
1206+
fflush(stderr);
1207+
if (!env()->abort_on_uncaught_exception())
1208+
exit(1);
1209+
fprintf(stderr, "\n");
1210+
fflush(stderr);
1211+
ABORT_NO_BACKTRACE();
1212+
}
1213+
11991214
void Environment::Exit(int exit_code) {
12001215
if (options()->trace_exit) {
12011216
HandleScope handle_scope(isolate());
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ class AsyncHooks : public MemoryRetainer {
774774
friend class Environment; // So we can call the constructor.
775775
explicit AsyncHooks(v8::Isolate* isolate, const SerializeInfo* info);
776776

777+
[[noreturn]] void FailWithCorruptedAsyncStack(double expected_async_id);
778+
777779
// Stores the ids of the current execution context stack.
778780
AliasedFloat64Array async_ids_stack_;
779781
// Attached to a Uint32Array that tracks the number of active hooks for

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.