Skip to content

Commit

Permalink
deps: V8: backport 7857eb34db42
Browse files Browse the repository at this point in the history
Original commit message:

    Reland^2 "Add ContinuationPreservedEmbedderData builtins to extras binding"

    This reverts commit cb1277e97a0ed32fd893be9f4e927f6e8b6c566c.

    > Original change's description:
    > > Add ContinuationPreservedEmbedderData builtins to extras binding
    > >
    > > Node.js and Deno wish to use CPED for AsyncLocalStorage and APM, which
    > > needs a high performance implementation. These builtins allow JavaScript
    > > to handle CPED performantly.
    > >
    > > Change-Id: I7577be80818524baa52791dfce57d442d7c0c933
    > > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5638129
    > > Commit-Queue: snek <[email protected]>
    > > Reviewed-by: Darius Mercadier <[email protected]>
    > > Reviewed-by: Leszek Swirski <[email protected]>
    > > Reviewed-by: Nico Hartmann <[email protected]>
    > > Cr-Commit-Position: refs/heads/main@{#94607}
    >
    > Change-Id: Ief390f0b99891c8de83b4c794180440f91cbaf1f
    > No-Presubmit: true
    > No-Tree-Checks: true
    > No-Try: true
    > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5649024
    > Auto-Submit: Shu-yu Guo <[email protected]>
    > Bot-Commit: Rubber Stamper <[email protected]>
    > Commit-Queue: Rubber Stamper <[email protected]>
    > Cr-Commit-Position: refs/heads/main@{#94608}

    Change-Id: I4943071ffe192084e83bfe3113cfe9c92ef31465
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5677045
    Reviewed-by: Darius Mercadier <[email protected]>
    Reviewed-by: Leszek Swirski <[email protected]>
    Commit-Queue: snek <[email protected]>
    Cr-Commit-Position: refs/heads/main@{#94866}

Refs: v8/v8@7857eb3
  • Loading branch information
Stephen Belanger committed Jul 22, 2024
1 parent ad1e561 commit bf70284
Show file tree
Hide file tree
Showing 29 changed files with 627 additions and 63 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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.16',
'v8_embedder_string': '-node.17',

##### V8 defaults for Node.js #####

Expand Down
1 change: 0 additions & 1 deletion deps/v8/src/builtins/base.tq
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,6 @@ extern macro ChangeUint32ToWord(uint32): uintptr; // Doesn't sign-extend.
extern macro ChangeInt32ToInt64(int32): int64; // Sign-extends.
extern macro ChangeUint32ToUint64(uint32): uint64; // Doesn't sign-extend.
extern macro LoadNativeContext(Context): NativeContext;
extern macro GetContinuationPreservedEmbedderData(): Object;
extern macro TruncateFloat64ToFloat16(float64): float16;
extern macro TruncateFloat32ToFloat16(float32): float16;
extern macro TruncateFloat64ToFloat32(float64): float32;
Expand Down
27 changes: 23 additions & 4 deletions deps/v8/src/builtins/promise-misc.tq
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ extern macro PromiseBuiltinsAssembler::IsIsolatePromiseHookEnabled(uint32):

extern macro PromiseBuiltinsAssembler::PromiseHookFlags(): uint32;

namespace macros {
extern macro GetContinuationPreservedEmbedderData(): Object;
extern macro SetContinuationPreservedEmbedderData(Object): void;
}

namespace promise {
extern macro IsFunctionWithPrototypeSlotMap(Map): bool;

Expand Down Expand Up @@ -80,7 +85,7 @@ macro NewPromiseFulfillReactionJobTask(
return new PromiseFulfillReactionJobTask{
map: PromiseFulfillReactionJobTaskMapConstant(),
continuation_preserved_embedder_data:
GetContinuationPreservedEmbedderData(),
macros::GetContinuationPreservedEmbedderData(),
argument,
context: handlerContext,
handler,
Expand Down Expand Up @@ -108,7 +113,7 @@ macro NewPromiseRejectReactionJobTask(
return new PromiseRejectReactionJobTask{
map: PromiseRejectReactionJobTaskMapConstant(),
continuation_preserved_embedder_data:
GetContinuationPreservedEmbedderData(),
macros::GetContinuationPreservedEmbedderData(),
argument,
context: handlerContext,
handler,
Expand Down Expand Up @@ -303,7 +308,7 @@ macro NewPromiseReaction(
return new PromiseReaction{
map: PromiseReactionMapConstant(),
continuation_preserved_embedder_data:
GetContinuationPreservedEmbedderData(),
macros::GetContinuationPreservedEmbedderData(),
next: next,
reject_handler: rejectHandler,
fulfill_handler: fulfillHandler,
Expand Down Expand Up @@ -347,7 +352,7 @@ macro NewPromiseResolveThenableJobTask(
return new PromiseResolveThenableJobTask{
map: PromiseResolveThenableJobTaskMapConstant(),
continuation_preserved_embedder_data:
GetContinuationPreservedEmbedderData(),
macros::GetContinuationPreservedEmbedderData(),
context: nativeContext,
promise_to_resolve: promiseToResolve,
thenable,
Expand Down Expand Up @@ -452,4 +457,18 @@ transitioning macro BranchIfAccessCheckFailed(
}
} label HasAccess {}
}

@if(V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA)
transitioning javascript builtin GetContinuationPreservedEmbedderData(
js-implicit context: Context, receiver: JSAny)(): JSAny {
return UnsafeCast<JSAny>(macros::GetContinuationPreservedEmbedderData());
}

@if(V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA)
transitioning javascript builtin SetContinuationPreservedEmbedderData(
js-implicit context: Context, receiver: JSAny)(data: Object): Undefined {
macros::SetContinuationPreservedEmbedderData(data);
return Undefined;
}

}
39 changes: 39 additions & 0 deletions deps/v8/src/compiler/js-call-reducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5108,6 +5108,12 @@ Reduction JSCallReducer::ReduceJSCall(Node* node,
case Builtin::kBigIntAsIntN:
case Builtin::kBigIntAsUintN:
return ReduceBigIntAsN(node, builtin);
#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
case Builtin::kGetContinuationPreservedEmbedderData:
return ReduceGetContinuationPreservedEmbedderData(node);
case Builtin::kSetContinuationPreservedEmbedderData:
return ReduceSetContinuationPreservedEmbedderData(node);
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
default:
break;
}
Expand Down Expand Up @@ -8780,6 +8786,39 @@ Reduction JSCallReducer::ReduceJSCallMathMinMaxWithArrayLike(Node* node,
return ReplaceWithSubgraph(&a, subgraph);
}

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
Reduction JSCallReducer::ReduceGetContinuationPreservedEmbedderData(
Node* node) {
JSCallNode n(node);
Effect effect = n.effect();
Control control = n.control();

Node* value = effect = graph()->NewNode(
simplified()->GetContinuationPreservedEmbedderData(), effect);

ReplaceWithValue(node, value, effect, control);
return Replace(node);
}

Reduction JSCallReducer::ReduceSetContinuationPreservedEmbedderData(
Node* node) {
JSCallNode n(node);
Effect effect = n.effect();
Control control = n.control();

if (n.ArgumentCount() == 0) return NoChange();

effect =
graph()->NewNode(simplified()->SetContinuationPreservedEmbedderData(),
n.Argument(0), effect);

Node* value = jsgraph()->UndefinedConstant();

ReplaceWithValue(node, value, effect, control);
return Replace(node);
}
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA

CompilationDependencies* JSCallReducer::dependencies() const {
return broker()->dependencies();
}
Expand Down
5 changes: 5 additions & 0 deletions deps/v8/src/compiler/js-call-reducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ class V8_EXPORT_PRIVATE JSCallReducer final : public AdvancedReducer {
base::Optional<Reduction> TryReduceJSCallMathMinMaxWithArrayLike(Node* node);
Reduction ReduceJSCallMathMinMaxWithArrayLike(Node* node, Builtin builtin);

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
Reduction ReduceGetContinuationPreservedEmbedderData(Node* node);
Reduction ReduceSetContinuationPreservedEmbedderData(Node* node);
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA

// The pendant to ReplaceWithValue when using GraphAssembler-based reductions.
Reduction ReplaceWithSubgraph(JSCallReducerAssembler* gasm, Node* subgraph);
std::pair<Node*, Node*> ReleaseEffectAndControlFromAssembler(
Expand Down
11 changes: 10 additions & 1 deletion deps/v8/src/compiler/opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@

#define SIMPLIFIED_SPECULATIVE_NUMBER_UNOP_LIST(V) V(SpeculativeToNumber)

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
#define SIMPLIFIED_CPED_OP_LIST(V) \
V(GetContinuationPreservedEmbedderData) \
V(SetContinuationPreservedEmbedderData)
#else
#define SIMPLIFIED_CPED_OP_LIST(V)
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA

#define SIMPLIFIED_OTHER_OP_LIST(V) \
V(Allocate) \
V(AllocateRaw) \
Expand Down Expand Up @@ -534,7 +542,8 @@
V(TransitionElementsKind) \
V(TypeOf) \
V(Unsigned32Divide) \
V(VerifyType)
V(VerifyType) \
SIMPLIFIED_CPED_OP_LIST(V)

#define SIMPLIFIED_SPECULATIVE_BIGINT_BINOP_LIST(V) \
V(SpeculativeBigIntAdd) \
Expand Down
11 changes: 11 additions & 0 deletions deps/v8/src/compiler/simplified-lowering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4635,6 +4635,17 @@ class RepresentationSelector {
SetOutput<T>(node, LoadRepresentationOf(node->op()).representation());
return;

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
case IrOpcode::kGetContinuationPreservedEmbedderData:
SetOutput<T>(node, MachineRepresentation::kTagged);
return;

case IrOpcode::kSetContinuationPreservedEmbedderData:
ProcessInput<T>(node, 0, UseInfo::AnyTagged());
SetOutput<T>(node, MachineRepresentation::kNone);
return;
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA

default:
FATAL(
"Representation inference: unsupported opcode %i (%s), node #%i\n.",
Expand Down
32 changes: 32 additions & 0 deletions deps/v8/src/compiler/simplified-operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,26 @@ struct SimplifiedOperatorGlobalCache final {
kSpeculativeToBigIntBigInt64Operator;
SpeculativeToBigIntOperator<BigIntOperationHint::kBigInt>
kSpeculativeToBigIntBigIntOperator;

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
struct GetContinuationPreservedEmbedderDataOperator : public Operator {
GetContinuationPreservedEmbedderDataOperator()
: Operator(IrOpcode::kGetContinuationPreservedEmbedderData,
Operator::kNoThrow | Operator::kNoDeopt | Operator::kNoWrite,
"GetContinuationPreservedEmbedderData", 0, 1, 0, 1, 1, 0) {}
};
GetContinuationPreservedEmbedderDataOperator
kGetContinuationPreservedEmbedderData;

struct SetContinuationPreservedEmbedderDataOperator : public Operator {
SetContinuationPreservedEmbedderDataOperator()
: Operator(IrOpcode::kSetContinuationPreservedEmbedderData,
Operator::kNoThrow | Operator::kNoDeopt | Operator::kNoRead,
"SetContinuationPreservedEmbedderData", 1, 1, 0, 0, 1, 0) {}
};
SetContinuationPreservedEmbedderDataOperator
kSetContinuationPreservedEmbedderData;
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
};

namespace {
Expand Down Expand Up @@ -2198,6 +2218,18 @@ const Operator* SimplifiedOperatorBuilder::StoreField(
2, 1, 1, 0, 1, 0, store_access);
}

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
const Operator*
SimplifiedOperatorBuilder::GetContinuationPreservedEmbedderData() {
return &cache_.kGetContinuationPreservedEmbedderData;
}

const Operator*
SimplifiedOperatorBuilder::SetContinuationPreservedEmbedderData() {
return &cache_.kSetContinuationPreservedEmbedderData;
}
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA

const Operator* SimplifiedOperatorBuilder::LoadMessage() {
return zone()->New<Operator>(IrOpcode::kLoadMessage, Operator::kEliminatable,
"LoadMessage", 1, 1, 1, 1, 1, 0);
Expand Down
5 changes: 5 additions & 0 deletions deps/v8/src/compiler/simplified-operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,11 @@ class V8_EXPORT_PRIVATE SimplifiedOperatorBuilder final
const FastApiCallFunctionVector& c_candidate_functions,
FeedbackSource const& feedback, CallDescriptor* descriptor);

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
const Operator* GetContinuationPreservedEmbedderData();
const Operator* SetContinuationPreservedEmbedderData();
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA

private:
Zone* zone() const { return zone_; }

Expand Down
10 changes: 10 additions & 0 deletions deps/v8/src/compiler/turboshaft/assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3855,6 +3855,16 @@ class TurboshaftAssemblerOpInterface
}
#endif // V8_ENABLE_WEBASSEMBLY

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
V<Object> GetContinuationPreservedEmbedderData() {
return ReduceIfReachableGetContinuationPreservedEmbedderData();
}

void SetContinuationPreservedEmbedderData(V<Object> data) {
ReduceIfReachableSetContinuationPreservedEmbedderData(data);
}
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA

template <typename Rep>
V<Rep> resolve(const V<Rep>& v) {
return v;
Expand Down
8 changes: 8 additions & 0 deletions deps/v8/src/compiler/turboshaft/graph-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,14 @@ OpIndex GraphBuilder::Process(
return OpIndex::Invalid();
}

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
case IrOpcode::kGetContinuationPreservedEmbedderData:
return __ GetContinuationPreservedEmbedderData();
case IrOpcode::kSetContinuationPreservedEmbedderData:
__ SetContinuationPreservedEmbedderData(Map(node->InputAt(0)));
return OpIndex::Invalid();
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA

default:
std::cerr << "unsupported node type: " << *node->op() << "\n";
node->Print(std::cerr);
Expand Down
19 changes: 19 additions & 0 deletions deps/v8/src/compiler/turboshaft/machine-lowering-reducer-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3164,6 +3164,25 @@ class MachineLoweringReducer : public Next {
}
}

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
V<Object> REDUCE(GetContinuationPreservedEmbedderData)() {
return __ Load(
__ ExternalConstant(
ExternalReference::continuation_preserved_embedder_data(isolate_)),
LoadOp::Kind::RawAligned(), MemoryRepresentation::TaggedPointer());
}

OpIndex REDUCE(SetContinuationPreservedEmbedderData)(V<Object> data) {
__ Store(
__ ExternalConstant(
ExternalReference::continuation_preserved_embedder_data(isolate_)),
data, StoreOp::Kind::RawAligned(),
MemoryRepresentation::TaggedPointer(),
WriteBarrierKind::kNoWriteBarrier);
return OpIndex::Invalid();
}
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA

private:
V<Word32> BuildUint32Mod(V<Word32> left, V<Word32> right) {
Label<Word32> done(this);
Expand Down
18 changes: 18 additions & 0 deletions deps/v8/src/compiler/turboshaft/maglev-graph-building-phase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,24 @@ class GraphBuilder {
return maglev::ProcessResult::kContinue;
}

#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
maglev::ProcessResult Process(
maglev::GetContinuationPreservedEmbedderData* node,
const maglev::ProcessingState&) {
V<Object> data = __ GetContinuationPreservedEmbedderData();
SetMap(node, data);
return maglev::ProcessResult::kContinue;
}

maglev::ProcessResult Process(
maglev::SetContinuationPreservedEmbedderData* node,
const maglev::ProcessingState&) {
V<Object> data = Map(node->input(0));
__ SetContinuationPreservedEmbedderData(data);
return maglev::ProcessResult::kContinue;
}
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA

template <typename NodeT>
maglev::ProcessResult Process(NodeT* node,
const maglev::ProcessingState& state) {
Expand Down
Loading

0 comments on commit bf70284

Please sign in to comment.