From 3b93fd6b2bb9e41aacedfa498873e4943659bc19 Mon Sep 17 00:00:00 2001 From: Jakob Linke Date: Mon, 13 Apr 2026 13:35:47 +0200 Subject: [PATCH] deps: V8: backport 1a0089053443 Original commit message: [stack traces] Fall back to full walk when receiver is unboxed The lightweight OptimizedJSFrame::Summarize path added in crrev.com/c/7722138 assumed that closure and receiver are always encoded as LITERAL or TAGGED_STACK_SLOT in the deopt translation. This holds for the closure (a JSFunction reference is always tagged) but not for the receiver: the "receiver" slot in an InterpretedFrame translation is just parameter 0 of the (possibly inlined) frame and is emitted via BuildDeoptFrameSingleValue, which encodes it according to the value's representation. An inlined frame whose `this` was typed as Float64 ends up as DOUBLE_STACK_SLOT, hitting UNREACHABLE in ResolveTaggedValue. Rename ResolveTaggedValue to TryResolveTaggedValue, return std::optional, and fall back to SummarizeFull when the receiver isn't a directly-resolvable tagged value. Fixed: 499260582 Change-Id: I1f9cdd28e4b6b76a253a46e43b248d9239a4ecd8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7748309 Auto-Submit: Jakob Linke Reviewed-by: Leszek Swirski Commit-Queue: Leszek Swirski Commit-Queue: Jakob Linke Cr-Commit-Position: refs/heads/main@{#106423} Refs: https://github.com/v8/v8/commit/1a0089053443ae4001fd15b84f1b46f330a0b3fa Co-authored-by: Antoine du Hamel PR-URL: https://github.com/nodejs/node/pull/65764 Backport-PR-URL: https://github.com/nodejs/node/pull/66241 Reviewed-By: Matteo Collina --- common.gypi | 2 +- deps/v8/src/deoptimizer/translated-state.cc | 8 ++++-- deps/v8/src/deoptimizer/translated-state.h | 6 +++-- deps/v8/src/execution/frames.cc | 25 +++++++++++++------ .../test/mjsunit/regress/regress-499260582.js | 20 +++++++++++++++ 5 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 deps/v8/test/mjsunit/regress/regress-499260582.js diff --git a/common.gypi b/common.gypi index ca8b53bb6e4..751083c4b8e 100644 --- a/common.gypi +++ b/common.gypi @@ -42,7 +42,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.61', + 'v8_embedder_string': '-node.62', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/deoptimizer/translated-state.cc b/deps/v8/src/deoptimizer/translated-state.cc index 4bb03ad7684..80ced80a688 100644 --- a/deps/v8/src/deoptimizer/translated-state.cc +++ b/deps/v8/src/deoptimizer/translated-state.cc @@ -1882,7 +1882,7 @@ Address TranslatedState::DecompressIfNeeded(intptr_t value) { } // static -Tagged TranslatedState::ResolveTaggedValue( +std::optional> TranslatedState::TryResolveTaggedValue( DeoptTranslationIterator* it, Address fp, Tagged literals) { TranslationOpcode opcode = it->NextOpcode(); @@ -1898,7 +1898,11 @@ Tagged TranslatedState::ResolveTaggedValue( return Tagged(DecompressIfNeeded(value)); } default: - UNREACHABLE(); + // Any other encoding (unboxed numerics, register-resident values, + // captured objects, etc.) requires the full TranslatedState path to + // materialize. Caller should fall back. + it->SkipOperands(TranslationOpcodeOperandCount(opcode)); + return std::nullopt; } } diff --git a/deps/v8/src/deoptimizer/translated-state.h b/deps/v8/src/deoptimizer/translated-state.h index f04d0e10b1a..7ebcea4fd52 100644 --- a/deps/v8/src/deoptimizer/translated-state.h +++ b/deps/v8/src/deoptimizer/translated-state.h @@ -497,8 +497,10 @@ class TranslatedState { // Resolves one deopt translation value opcode to a raw Tagged, // reading from the live frame if needed. Only LITERAL and - // TAGGED_STACK_SLOT are expected; other opcodes are UNREACHABLE. - static Tagged ResolveTaggedValue( + // TAGGED_STACK_SLOT can be resolved cheaply; for any other opcode the + // iterator is left positioned just past the opcode and std::nullopt is + // returned so the caller can fall back to the full materialization path. + static std::optional> TryResolveTaggedValue( DeoptTranslationIterator* it, Address fp, Tagged literals); diff --git a/deps/v8/src/execution/frames.cc b/deps/v8/src/execution/frames.cc index 01dc6b766a7..e2d95c1f8c2 100644 --- a/deps/v8/src/execution/frames.cc +++ b/deps/v8/src/execution/frames.cc @@ -3175,13 +3175,22 @@ FrameSummaries OptimizedJSFrame::Summarize() const { // Skip remaining header operands to reach the values. it.SkipOperands(TranslationOpcodeOperandCount(opcode) - 2); - // Resolve closure and receiver from the live frame. Both are always - // encoded as LITERAL or TAGGED_STACK_SLOT in the deopt translation. - Tagged function_obj = - TranslatedState::ResolveTaggedValue(&it, fp(), literal_array); - DCHECK(IsJSFunction(function_obj)); - Tagged receiver_obj = - TranslatedState::ResolveTaggedValue(&it, fp(), literal_array); + // Resolve closure and receiver from the live frame. The closure is + // always tagged (LITERAL or TAGGED_STACK_SLOT), but the receiver is + // just parameter 0 of the (possibly inlined) frame and may be encoded + // in any representation the optimizer chose (e.g. DOUBLE_STACK_SLOT + // for an unboxed Float64). Fall back to the full materialization path + // in that case. + std::optional> function_obj = + TranslatedState::TryResolveTaggedValue(&it, fp(), literal_array); + DCHECK(function_obj.has_value()); + DCHECK(IsJSFunction(*function_obj)); + std::optional> receiver_obj = + TranslatedState::TryResolveTaggedValue(&it, fp(), literal_array); + if (!receiver_obj.has_value()) { + needs_full_walk = true; + break; + } Tagged abstract_code; int code_offset; @@ -3197,7 +3206,7 @@ FrameSummaries OptimizedJSFrame::Summarize() const { DirectHandle params = GetParameters(); FrameSummary::JavaScriptFrameSummary summary( - isolate(), receiver_obj, Cast(function_obj), + isolate(), *receiver_obj, Cast(*function_obj), abstract_code, code_offset, is_constructor, *params); summaries.frames.push_back(summary); is_constructor = false; diff --git a/deps/v8/test/mjsunit/regress/regress-499260582.js b/deps/v8/test/mjsunit/regress/regress-499260582.js new file mode 100644 index 00000000000..08e4a2daf9b --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-499260582.js @@ -0,0 +1,20 @@ +// Copyright 2026 the V8 project authors. All rights reserved. +// Use of this source code governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax --jit-fuzzing --single-threaded + +function f9(a10, a11) { + 'use strict'; + for (let v12 = 0; v12 < 5; v12++) { + const v15 = ({ maxByteLength: 1073741824 }).maxByteLength; + %OptimizeOsr(); + function F16(a18, a19, a20) { + if (!new.target) { throw 'must be called with new'; } + } + try { F16.call(v15); } catch (e) {} + } + return f9; +} +%PrepareFunctionForOptimization(f9); +f9(f9, f9);