Skip to content

Commit

Permalink
Merge pull request 'fibers' (dart-lang#3) from fibers into main
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbashir committed Sep 1, 2024
2 parents 7df9a5a + 0833734 commit 43bf06b
Show file tree
Hide file tree
Showing 33 changed files with 296 additions and 194 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,9 @@ logs/logs.json
logs/results.json
.dart_tool/bisect_dart/
doc/api/

build/
sdk.code-workspace.local
build-sdk-debug.sh
build-sdk.sh
*.exe
*.aot
2 changes: 0 additions & 2 deletions build-sdk-debug.sh

This file was deleted.

3 changes: 0 additions & 3 deletions build-sdk.sh

This file was deleted.

Empty file removed new-recognized
Empty file.
2 changes: 0 additions & 2 deletions refresh-recognized.sh

This file was deleted.

2 changes: 1 addition & 1 deletion runtime/vm/app_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9455,7 +9455,7 @@ void Deserializer::ReadInstructions(CodePtr code, bool deferred) {
instr = image_reader_->GetInstructionsAt(active_offset);
unchecked_offset = ReadUnsigned();
code->untag()->active_instructions_ = instr;
Code::InitializeCachedEntryPointsFrom(code, instr, unchecked_offset);
Code::InitializeCachedEntryPointsFrom(code, instr, unchecked_offset);
#endif // defined(DART_PRECOMPILED_RUNTIME)
}

Expand Down
6 changes: 3 additions & 3 deletions runtime/vm/bootstrap_natives.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@ namespace dart {
V(GrowableList_setData, 2) \
V(Internal_unsafeCast, 1) \
V(Internal_nativeEffect, 1) \
V(Fiber_coroutineInitialize, 1) \
V(Fiber_coroutineTransfer, 2) \
V(Fiber_coroutineFork, 2) \
V(Internal_collectAllGarbage, 0) \
V(Internal_makeListFixedLength, 1) \
V(Internal_makeFixedListUnmodifiable, 1) \
Expand Down Expand Up @@ -316,6 +313,9 @@ namespace dart {
V(DartNativeApiFunctionPointer, 1) \
V(TransferableTypedData_factory, 2) \
V(TransferableTypedData_materialize, 1) \
V(Fiber_coroutineInitialize, 1) \
V(Fiber_coroutineTransfer, 2) \
V(Fiber_coroutineFork, 2) \
V(Coroutine_factory, 3)

// List of bootstrap native entry points used in the dart:mirror library.
Expand Down
1 change: 0 additions & 1 deletion runtime/vm/compiler/assembler/assembler_x64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Assembler::Assembler(ObjectPoolBuilder* object_pool_builder,
call(Address(THR,
target::Thread::write_barrier_wrappers_thread_offset(reg)));
};

generate_invoke_array_write_barrier_ = [&]() {
call(
Address(THR, target::Thread::array_write_barrier_entry_point_offset()));
Expand Down
2 changes: 0 additions & 2 deletions runtime/vm/compiler/backend/constant_propagator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1566,11 +1566,9 @@ void ConstantPropagator::VisitCall1ArgStub(Call1ArgStubInstr* instr) {
}

void ConstantPropagator::VisitCoroutineInitializeStub(CoroutineInitializeStubInstr* instr) {
SetValue(instr, non_constant_);
}

void ConstantPropagator::VisitCoroutineTransferStub(CoroutineTransferStubInstr* instr) {
SetValue(instr, non_constant_);
}

void ConstantPropagator::VisitCoroutineForkStub(CoroutineForkStubInstr* instr) {
Expand Down
1 change: 0 additions & 1 deletion runtime/vm/compiler/backend/flow_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <array>

#include "platform/text_buffer.h"
#include "vm/bit_vector.h"
#include "vm/compiler/backend/dart_calling_conventions.h"
#include "vm/compiler/backend/flow_graph_compiler.h"
Expand Down
118 changes: 106 additions & 12 deletions runtime/vm/compiler/backend/il.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8562,10 +8562,48 @@ LocationSummary* CoroutineInitializeStubInstr::MakeLocationSummary(
}

void CoroutineInitializeStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
ObjectStore* object_store = compiler->isolate_group()->object_store();
Code& stub = Code::ZoneHandle(compiler->zone());
stub = object_store->coroutine_initialize_stub();
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
const Register kCoroutine = CoroutineInitializeStubABI::kCoroutineReg;

#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
SPILLS_LR_TO_FRAME({});
#endif
__ EnterFrame(0);
__ PushObject(compiler::NullObject());
__ PushRegister(kCoroutine);
__ CallRuntime(kEnterCoroutineRuntimeEntry, 1);
__ PopRegister(kCoroutine);
__ Drop(1);
__ LeaveFrame();

__ PushRegister(FPREG);
__ PushRegister(PP);
__ PushRegister(CODE_REG);
__ PushRegister(FUNCTION_REG);

__ EnterFrame(0);
__ LoadFieldFromOffset(SPREG, kCoroutine, Coroutine::stack_base_offset());
__ PushRegister(FPREG);

__ LoadCompressedFieldFromOffset(FUNCTION_REG, kCoroutine, Coroutine::entry_offset());
if (!FLAG_precompiled_mode) {
__ LoadCompressedFieldFromOffset(CODE_REG, FUNCTION_REG, Function::code_offset());
__ LoadImmediate(ARGS_DESC_REG, 0);
}
__ Call(compiler::FieldAddress(FUNCTION_REG, Function::entry_point_offset()));

__ PopRegister(FPREG);
__ LeaveFrame();

__ PopRegister(FUNCTION_REG);
__ PopRegister(CODE_REG);
__ PopRegister(PP);
__ PopRegister(FPREG);

__ EnterFrame(0);
__ PushObject(compiler::NullObject());
__ CallRuntime(kExitCoroutineRuntimeEntry, 0);
__ Drop(1);
__ LeaveFrame();
}

LocationSummary* CoroutineTransferStubInstr::MakeLocationSummary(
Expand All @@ -8580,10 +8618,30 @@ LocationSummary* CoroutineTransferStubInstr::MakeLocationSummary(
}

void CoroutineTransferStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
ObjectStore* object_store = compiler->isolate_group()->object_store();
Code& stub = Code::ZoneHandle(compiler->zone());
stub = object_store->coroutine_transfer_stub();
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
const Register kFromCoroutine = CoroutineTransferStubABI::kFromCoroutineReg;
const Register kToCoroutine = CoroutineTransferStubABI::kToCoroutineReg;
const Register kToStackLimit = CoroutineTransferStubABI::kToStackLimitReg;

#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
SPILLS_LR_TO_FRAME({});
#endif
__ PushRegister(FPREG);
__ PushRegister(PP);
__ PushRegister(CODE_REG);
__ PushRegister(FUNCTION_REG);
__ StoreFieldToOffset(SPREG, kFromCoroutine, Coroutine::stack_base_offset());

__ LoadFieldFromOffset(SPREG, kToCoroutine, Coroutine::stack_base_offset());
__ PopRegister(FUNCTION_REG);
__ PopRegister(CODE_REG);
__ PopRegister(PP);
__ PopRegister(FPREG);

__ LoadFieldFromOffset(kToStackLimit, kToCoroutine, Coroutine::stack_limit_offset());
__ StoreToOffset(kToStackLimit, THR, Thread::stack_limit_offset());
__ StoreToOffset(kToCoroutine, THR, Thread::coroutine_offset());

__ StoreFieldToOffset(kFromCoroutine, kToCoroutine, Coroutine::caller_offset());
}

LocationSummary* CoroutineForkStubInstr::MakeLocationSummary(
Expand All @@ -8598,10 +8656,46 @@ LocationSummary* CoroutineForkStubInstr::MakeLocationSummary(
}

void CoroutineForkStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
ObjectStore* object_store = compiler->isolate_group()->object_store();
Code& stub = Code::ZoneHandle(compiler->zone());
stub = object_store->coroutine_fork_stub();
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
const Register kCallerCoroutine = CoroutineForkStubABI::kCallerCoroutineReg;
const Register kForkedCoroutine = CoroutineForkStubABI::kForkedCoroutineReg;
const Register kStackLimit = CoroutineForkStubABI::kStackLimitReg;

#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
SPILLS_LR_TO_FRAME({});
#endif
__ PushRegister(FPREG);
__ PushRegister(PP);
__ PushRegister(CODE_REG);
__ PushRegister(FUNCTION_REG);
__ StoreFieldToOffset(SPREG, kCallerCoroutine, Coroutine::stack_base_offset());

__ StoreFieldToOffset(kCallerCoroutine, kForkedCoroutine, Coroutine::caller_offset());

__ LoadFieldFromOffset(kStackLimit, kForkedCoroutine, Coroutine::stack_limit_offset());
__ StoreToOffset(kStackLimit, THR, Thread::stack_limit_offset());
__ StoreToOffset(kForkedCoroutine, THR, Thread::coroutine_offset());

__ LoadFieldFromOffset(SPREG, kForkedCoroutine, Coroutine::stack_base_offset());
__ PushRegister(kForkedCoroutine);

__ LoadCompressedFieldFromOffset(FUNCTION_REG, kForkedCoroutine, Coroutine::entry_offset());
if (!FLAG_precompiled_mode) {
__ LoadCompressedFieldFromOffset(CODE_REG, FUNCTION_REG, Function::code_offset());
__ LoadImmediate(ARGS_DESC_REG, 0);
}
__ Call(compiler::FieldAddress(FUNCTION_REG, Function::entry_point_offset()));

__ PopRegister(kForkedCoroutine);
__ LoadFieldFromOffset(kCallerCoroutine, kForkedCoroutine, Coroutine::caller_offset());
__ LoadFieldFromOffset(SPREG, kCallerCoroutine, Coroutine::stack_base_offset());
__ PopRegister(FUNCTION_REG);
__ PopRegister(CODE_REG);
__ PopRegister(PP);
__ PopRegister(FPREG);

__ LoadFieldFromOffset(kStackLimit, kCallerCoroutine, Coroutine::stack_limit_offset());
__ StoreToOffset(kStackLimit, THR, Thread::stack_limit_offset());
__ StoreToOffset(kCallerCoroutine, THR, Thread::coroutine_offset());
}

Definition* SuspendInstr::Canonicalize(FlowGraph* flow_graph) {
Expand Down
18 changes: 9 additions & 9 deletions runtime/vm/compiler/backend/il.h
Original file line number Diff line number Diff line change
Expand Up @@ -11476,10 +11476,10 @@ class Call1ArgStubInstr : public TemplateDefinition<1, Throws> {
DISALLOW_COPY_AND_ASSIGN(Call1ArgStubInstr);
};

class CoroutineInitializeStubInstr : public TemplateDefinition<1, NoThrow> {
class CoroutineInitializeStubInstr : public TemplateInstruction<1, NoThrow> {
public:
CoroutineInitializeStubInstr(Value* root, intptr_t deopt_id)
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
deopt_id) {
SetInputAt(0, root);
}
Expand All @@ -11495,16 +11495,16 @@ class CoroutineInitializeStubInstr : public TemplateDefinition<1, NoThrow> {

DECLARE_INSTRUCTION(CoroutineInitializeStub);
PRINT_OPERANDS_TO_SUPPORT
DECLARE_EMPTY_SERIALIZATION(CoroutineInitializeStubInstr, TemplateDefinition)
DECLARE_EMPTY_SERIALIZATION(CoroutineInitializeStubInstr, TemplateInstruction)

private:
DISALLOW_COPY_AND_ASSIGN(CoroutineInitializeStubInstr);
};

class CoroutineTransferStubInstr : public TemplateDefinition<2, NoThrow> {
class CoroutineTransferStubInstr : public TemplateInstruction<2, NoThrow> {
public:
CoroutineTransferStubInstr(Value* from, Value* to, intptr_t deopt_id)
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
deopt_id) {
SetInputAt(0, from);
SetInputAt(1, to);
Expand All @@ -11523,16 +11523,16 @@ class CoroutineTransferStubInstr : public TemplateDefinition<2, NoThrow> {

DECLARE_INSTRUCTION(CoroutineTransferStub);
PRINT_OPERANDS_TO_SUPPORT
DECLARE_EMPTY_SERIALIZATION(CoroutineTransferStubInstr, TemplateDefinition)
DECLARE_EMPTY_SERIALIZATION(CoroutineTransferStubInstr, TemplateInstruction)

private:
DISALLOW_COPY_AND_ASSIGN(CoroutineTransferStubInstr);
};

class CoroutineForkStubInstr : public TemplateDefinition<2, NoThrow> {
class CoroutineForkStubInstr : public TemplateInstruction<2, NoThrow> {
public:
CoroutineForkStubInstr(Value* from, Value* to, intptr_t deopt_id)
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
deopt_id) {
SetInputAt(0, from);
SetInputAt(1, to);
Expand All @@ -11552,7 +11552,7 @@ class CoroutineForkStubInstr : public TemplateDefinition<2, NoThrow> {
DECLARE_INSTRUCTION(CoroutineForkStub);
PRINT_OPERANDS_TO_SUPPORT

DECLARE_EMPTY_SERIALIZATION(CoroutineForkStubInstr, TemplateDefinition)
DECLARE_EMPTY_SERIALIZATION(CoroutineForkStubInstr, TemplateInstruction)

private:
DISALLOW_COPY_AND_ASSIGN(CoroutineForkStubInstr);
Expand Down
53 changes: 0 additions & 53 deletions runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3371,12 +3371,6 @@ Fragment StreamingFlowGraphBuilder::BuildStaticInvocation(TokenPosition* p) {

const auto recognized_kind = target.recognized_kind();
switch (recognized_kind) {
case MethodRecognizer::kCoroutineInitialize:
return BuildCoroutineInitialize();
case MethodRecognizer::kCoroutineTransfer:
return BuildCoroutineTransfer();
case MethodRecognizer::kCoroutineFork:
return BuildCoroutineFork();
case MethodRecognizer::kNativeEffect:
return BuildNativeEffect();
case MethodRecognizer::kReachabilityFence:
Expand Down Expand Up @@ -6020,53 +6014,6 @@ Fragment StreamingFlowGraphBuilder::BuildNativeEffect() {
return code;
}

Fragment StreamingFlowGraphBuilder::BuildCoroutineInitialize() {
Fragment instructions;
ReadUInt();
ReadListLength();
ReadListLength();
instructions += BuildExpression();
ReadListLength();
instructions += B->CoroutineInitialize(TokenPosition::kNoSource);
return instructions;
}

Fragment StreamingFlowGraphBuilder::BuildCoroutineTransfer() {
Fragment instructions;
ReadUInt();
ReadListLength();
ReadListLength();
instructions += BuildExpression();
LocalVariable* from = MakeTemporary();
instructions += LoadLocal(from);
instructions += BuildExpression();
LocalVariable* to = MakeTemporary();
instructions += LoadLocal(to);
ReadListLength();
instructions += B->CoroutineTransfer(TokenPosition::kNoSource);
instructions += Drop();
instructions += Drop();
return instructions;
}

Fragment StreamingFlowGraphBuilder::BuildCoroutineFork() {
Fragment instructions;
ReadUInt();
ReadListLength();
ReadListLength();
instructions += BuildExpression();
LocalVariable* from = MakeTemporary();
instructions += LoadLocal(from);
instructions += BuildExpression();
LocalVariable* to = MakeTemporary();
instructions += LoadLocal(to);
ReadListLength();
instructions += B->CoroutineFork(TokenPosition::kNoSource);
instructions += Drop();
instructions += Drop();
return instructions;
}

Fragment StreamingFlowGraphBuilder::BuildReachabilityFence() {
const intptr_t argc = ReadUInt(); // Read argument count.
ASSERT(argc == 1); // LoadField, can be late.
Expand Down
5 changes: 0 additions & 5 deletions runtime/vm/compiler/frontend/kernel_binary_flowgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,6 @@ class StreamingFlowGraphBuilder : public KernelReaderHelper {
// Build flow graph for '_nativeEffect'.
Fragment BuildNativeEffect();

Fragment BuildCoroutineInitialize();

Fragment BuildCoroutineTransfer();

Fragment BuildCoroutineFork();

// Build the call-site manually, to avoid doing initialization checks
// for late fields.
Expand Down
Loading

0 comments on commit 43bf06b

Please sign in to comment.