Skip to content

Commit 43bf06b

Browse files
committed
Merge pull request 'fibers' (#3) from fibers into main
Reviewed-on: http://git.local/dependencies/dart/pulls/3
2 parents 7df9a5a + 0833734 commit 43bf06b

33 files changed

+296
-194
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,9 @@ logs/logs.json
112112
logs/results.json
113113
.dart_tool/bisect_dart/
114114
doc/api/
115+
115116
build/
116-
sdk.code-workspace.local
117+
build-sdk-debug.sh
118+
build-sdk.sh
119+
*.exe
120+
*.aot

build-sdk-debug.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

build-sdk.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

new-recognized

Whitespace-only changes.

refresh-recognized.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

runtime/vm/app_snapshot.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9455,7 +9455,7 @@ void Deserializer::ReadInstructions(CodePtr code, bool deferred) {
94559455
instr = image_reader_->GetInstructionsAt(active_offset);
94569456
unchecked_offset = ReadUnsigned();
94579457
code->untag()->active_instructions_ = instr;
9458-
Code::InitializeCachedEntryPointsFrom(code, instr, unchecked_offset);
9458+
Code::InitializeCachedEntryPointsFrom(code, instr, unchecked_offset);
94599459
#endif // defined(DART_PRECOMPILED_RUNTIME)
94609460
}
94619461

runtime/vm/bootstrap_natives.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,6 @@ namespace dart {
262262
V(GrowableList_setData, 2) \
263263
V(Internal_unsafeCast, 1) \
264264
V(Internal_nativeEffect, 1) \
265-
V(Fiber_coroutineInitialize, 1) \
266-
V(Fiber_coroutineTransfer, 2) \
267-
V(Fiber_coroutineFork, 2) \
268265
V(Internal_collectAllGarbage, 0) \
269266
V(Internal_makeListFixedLength, 1) \
270267
V(Internal_makeFixedListUnmodifiable, 1) \
@@ -316,6 +313,9 @@ namespace dart {
316313
V(DartNativeApiFunctionPointer, 1) \
317314
V(TransferableTypedData_factory, 2) \
318315
V(TransferableTypedData_materialize, 1) \
316+
V(Fiber_coroutineInitialize, 1) \
317+
V(Fiber_coroutineTransfer, 2) \
318+
V(Fiber_coroutineFork, 2) \
319319
V(Coroutine_factory, 3)
320320

321321
// List of bootstrap native entry points used in the dart:mirror library.

runtime/vm/compiler/assembler/assembler_x64.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Assembler::Assembler(ObjectPoolBuilder* object_pool_builder,
3131
call(Address(THR,
3232
target::Thread::write_barrier_wrappers_thread_offset(reg)));
3333
};
34-
3534
generate_invoke_array_write_barrier_ = [&]() {
3635
call(
3736
Address(THR, target::Thread::array_write_barrier_entry_point_offset()));

runtime/vm/compiler/backend/constant_propagator.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,11 +1566,9 @@ void ConstantPropagator::VisitCall1ArgStub(Call1ArgStubInstr* instr) {
15661566
}
15671567

15681568
void ConstantPropagator::VisitCoroutineInitializeStub(CoroutineInitializeStubInstr* instr) {
1569-
SetValue(instr, non_constant_);
15701569
}
15711570

15721571
void ConstantPropagator::VisitCoroutineTransferStub(CoroutineTransferStubInstr* instr) {
1573-
SetValue(instr, non_constant_);
15741572
}
15751573

15761574
void ConstantPropagator::VisitCoroutineForkStub(CoroutineForkStubInstr* instr) {

runtime/vm/compiler/backend/flow_graph.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <array>
88

9-
#include "platform/text_buffer.h"
109
#include "vm/bit_vector.h"
1110
#include "vm/compiler/backend/dart_calling_conventions.h"
1211
#include "vm/compiler/backend/flow_graph_compiler.h"

runtime/vm/compiler/backend/il.cc

Lines changed: 106 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8562,10 +8562,48 @@ LocationSummary* CoroutineInitializeStubInstr::MakeLocationSummary(
85628562
}
85638563

85648564
void CoroutineInitializeStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
8565-
ObjectStore* object_store = compiler->isolate_group()->object_store();
8566-
Code& stub = Code::ZoneHandle(compiler->zone());
8567-
stub = object_store->coroutine_initialize_stub();
8568-
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
8565+
const Register kCoroutine = CoroutineInitializeStubABI::kCoroutineReg;
8566+
8567+
#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
8568+
SPILLS_LR_TO_FRAME({});
8569+
#endif
8570+
__ EnterFrame(0);
8571+
__ PushObject(compiler::NullObject());
8572+
__ PushRegister(kCoroutine);
8573+
__ CallRuntime(kEnterCoroutineRuntimeEntry, 1);
8574+
__ PopRegister(kCoroutine);
8575+
__ Drop(1);
8576+
__ LeaveFrame();
8577+
8578+
__ PushRegister(FPREG);
8579+
__ PushRegister(PP);
8580+
__ PushRegister(CODE_REG);
8581+
__ PushRegister(FUNCTION_REG);
8582+
8583+
__ EnterFrame(0);
8584+
__ LoadFieldFromOffset(SPREG, kCoroutine, Coroutine::stack_base_offset());
8585+
__ PushRegister(FPREG);
8586+
8587+
__ LoadCompressedFieldFromOffset(FUNCTION_REG, kCoroutine, Coroutine::entry_offset());
8588+
if (!FLAG_precompiled_mode) {
8589+
__ LoadCompressedFieldFromOffset(CODE_REG, FUNCTION_REG, Function::code_offset());
8590+
__ LoadImmediate(ARGS_DESC_REG, 0);
8591+
}
8592+
__ Call(compiler::FieldAddress(FUNCTION_REG, Function::entry_point_offset()));
8593+
8594+
__ PopRegister(FPREG);
8595+
__ LeaveFrame();
8596+
8597+
__ PopRegister(FUNCTION_REG);
8598+
__ PopRegister(CODE_REG);
8599+
__ PopRegister(PP);
8600+
__ PopRegister(FPREG);
8601+
8602+
__ EnterFrame(0);
8603+
__ PushObject(compiler::NullObject());
8604+
__ CallRuntime(kExitCoroutineRuntimeEntry, 0);
8605+
__ Drop(1);
8606+
__ LeaveFrame();
85698607
}
85708608

85718609
LocationSummary* CoroutineTransferStubInstr::MakeLocationSummary(
@@ -8580,10 +8618,30 @@ LocationSummary* CoroutineTransferStubInstr::MakeLocationSummary(
85808618
}
85818619

85828620
void CoroutineTransferStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
8583-
ObjectStore* object_store = compiler->isolate_group()->object_store();
8584-
Code& stub = Code::ZoneHandle(compiler->zone());
8585-
stub = object_store->coroutine_transfer_stub();
8586-
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
8621+
const Register kFromCoroutine = CoroutineTransferStubABI::kFromCoroutineReg;
8622+
const Register kToCoroutine = CoroutineTransferStubABI::kToCoroutineReg;
8623+
const Register kToStackLimit = CoroutineTransferStubABI::kToStackLimitReg;
8624+
8625+
#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
8626+
SPILLS_LR_TO_FRAME({});
8627+
#endif
8628+
__ PushRegister(FPREG);
8629+
__ PushRegister(PP);
8630+
__ PushRegister(CODE_REG);
8631+
__ PushRegister(FUNCTION_REG);
8632+
__ StoreFieldToOffset(SPREG, kFromCoroutine, Coroutine::stack_base_offset());
8633+
8634+
__ LoadFieldFromOffset(SPREG, kToCoroutine, Coroutine::stack_base_offset());
8635+
__ PopRegister(FUNCTION_REG);
8636+
__ PopRegister(CODE_REG);
8637+
__ PopRegister(PP);
8638+
__ PopRegister(FPREG);
8639+
8640+
__ LoadFieldFromOffset(kToStackLimit, kToCoroutine, Coroutine::stack_limit_offset());
8641+
__ StoreToOffset(kToStackLimit, THR, Thread::stack_limit_offset());
8642+
__ StoreToOffset(kToCoroutine, THR, Thread::coroutine_offset());
8643+
8644+
__ StoreFieldToOffset(kFromCoroutine, kToCoroutine, Coroutine::caller_offset());
85878645
}
85888646

85898647
LocationSummary* CoroutineForkStubInstr::MakeLocationSummary(
@@ -8598,10 +8656,46 @@ LocationSummary* CoroutineForkStubInstr::MakeLocationSummary(
85988656
}
85998657

86008658
void CoroutineForkStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
8601-
ObjectStore* object_store = compiler->isolate_group()->object_store();
8602-
Code& stub = Code::ZoneHandle(compiler->zone());
8603-
stub = object_store->coroutine_fork_stub();
8604-
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
8659+
const Register kCallerCoroutine = CoroutineForkStubABI::kCallerCoroutineReg;
8660+
const Register kForkedCoroutine = CoroutineForkStubABI::kForkedCoroutineReg;
8661+
const Register kStackLimit = CoroutineForkStubABI::kStackLimitReg;
8662+
8663+
#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
8664+
SPILLS_LR_TO_FRAME({});
8665+
#endif
8666+
__ PushRegister(FPREG);
8667+
__ PushRegister(PP);
8668+
__ PushRegister(CODE_REG);
8669+
__ PushRegister(FUNCTION_REG);
8670+
__ StoreFieldToOffset(SPREG, kCallerCoroutine, Coroutine::stack_base_offset());
8671+
8672+
__ StoreFieldToOffset(kCallerCoroutine, kForkedCoroutine, Coroutine::caller_offset());
8673+
8674+
__ LoadFieldFromOffset(kStackLimit, kForkedCoroutine, Coroutine::stack_limit_offset());
8675+
__ StoreToOffset(kStackLimit, THR, Thread::stack_limit_offset());
8676+
__ StoreToOffset(kForkedCoroutine, THR, Thread::coroutine_offset());
8677+
8678+
__ LoadFieldFromOffset(SPREG, kForkedCoroutine, Coroutine::stack_base_offset());
8679+
__ PushRegister(kForkedCoroutine);
8680+
8681+
__ LoadCompressedFieldFromOffset(FUNCTION_REG, kForkedCoroutine, Coroutine::entry_offset());
8682+
if (!FLAG_precompiled_mode) {
8683+
__ LoadCompressedFieldFromOffset(CODE_REG, FUNCTION_REG, Function::code_offset());
8684+
__ LoadImmediate(ARGS_DESC_REG, 0);
8685+
}
8686+
__ Call(compiler::FieldAddress(FUNCTION_REG, Function::entry_point_offset()));
8687+
8688+
__ PopRegister(kForkedCoroutine);
8689+
__ LoadFieldFromOffset(kCallerCoroutine, kForkedCoroutine, Coroutine::caller_offset());
8690+
__ LoadFieldFromOffset(SPREG, kCallerCoroutine, Coroutine::stack_base_offset());
8691+
__ PopRegister(FUNCTION_REG);
8692+
__ PopRegister(CODE_REG);
8693+
__ PopRegister(PP);
8694+
__ PopRegister(FPREG);
8695+
8696+
__ LoadFieldFromOffset(kStackLimit, kCallerCoroutine, Coroutine::stack_limit_offset());
8697+
__ StoreToOffset(kStackLimit, THR, Thread::stack_limit_offset());
8698+
__ StoreToOffset(kCallerCoroutine, THR, Thread::coroutine_offset());
86058699
}
86068700

86078701
Definition* SuspendInstr::Canonicalize(FlowGraph* flow_graph) {

runtime/vm/compiler/backend/il.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11476,10 +11476,10 @@ class Call1ArgStubInstr : public TemplateDefinition<1, Throws> {
1147611476
DISALLOW_COPY_AND_ASSIGN(Call1ArgStubInstr);
1147711477
};
1147811478

11479-
class CoroutineInitializeStubInstr : public TemplateDefinition<1, NoThrow> {
11479+
class CoroutineInitializeStubInstr : public TemplateInstruction<1, NoThrow> {
1148011480
public:
1148111481
CoroutineInitializeStubInstr(Value* root, intptr_t deopt_id)
11482-
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
11482+
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
1148311483
deopt_id) {
1148411484
SetInputAt(0, root);
1148511485
}
@@ -11495,16 +11495,16 @@ class CoroutineInitializeStubInstr : public TemplateDefinition<1, NoThrow> {
1149511495

1149611496
DECLARE_INSTRUCTION(CoroutineInitializeStub);
1149711497
PRINT_OPERANDS_TO_SUPPORT
11498-
DECLARE_EMPTY_SERIALIZATION(CoroutineInitializeStubInstr, TemplateDefinition)
11498+
DECLARE_EMPTY_SERIALIZATION(CoroutineInitializeStubInstr, TemplateInstruction)
1149911499

1150011500
private:
1150111501
DISALLOW_COPY_AND_ASSIGN(CoroutineInitializeStubInstr);
1150211502
};
1150311503

11504-
class CoroutineTransferStubInstr : public TemplateDefinition<2, NoThrow> {
11504+
class CoroutineTransferStubInstr : public TemplateInstruction<2, NoThrow> {
1150511505
public:
1150611506
CoroutineTransferStubInstr(Value* from, Value* to, intptr_t deopt_id)
11507-
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
11507+
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
1150811508
deopt_id) {
1150911509
SetInputAt(0, from);
1151011510
SetInputAt(1, to);
@@ -11523,16 +11523,16 @@ class CoroutineTransferStubInstr : public TemplateDefinition<2, NoThrow> {
1152311523

1152411524
DECLARE_INSTRUCTION(CoroutineTransferStub);
1152511525
PRINT_OPERANDS_TO_SUPPORT
11526-
DECLARE_EMPTY_SERIALIZATION(CoroutineTransferStubInstr, TemplateDefinition)
11526+
DECLARE_EMPTY_SERIALIZATION(CoroutineTransferStubInstr, TemplateInstruction)
1152711527

1152811528
private:
1152911529
DISALLOW_COPY_AND_ASSIGN(CoroutineTransferStubInstr);
1153011530
};
1153111531

11532-
class CoroutineForkStubInstr : public TemplateDefinition<2, NoThrow> {
11532+
class CoroutineForkStubInstr : public TemplateInstruction<2, NoThrow> {
1153311533
public:
1153411534
CoroutineForkStubInstr(Value* from, Value* to, intptr_t deopt_id)
11535-
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
11535+
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
1153611536
deopt_id) {
1153711537
SetInputAt(0, from);
1153811538
SetInputAt(1, to);
@@ -11552,7 +11552,7 @@ class CoroutineForkStubInstr : public TemplateDefinition<2, NoThrow> {
1155211552
DECLARE_INSTRUCTION(CoroutineForkStub);
1155311553
PRINT_OPERANDS_TO_SUPPORT
1155411554

11555-
DECLARE_EMPTY_SERIALIZATION(CoroutineForkStubInstr, TemplateDefinition)
11555+
DECLARE_EMPTY_SERIALIZATION(CoroutineForkStubInstr, TemplateInstruction)
1155611556

1155711557
private:
1155811558
DISALLOW_COPY_AND_ASSIGN(CoroutineForkStubInstr);

runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,12 +3371,6 @@ Fragment StreamingFlowGraphBuilder::BuildStaticInvocation(TokenPosition* p) {
33713371

33723372
const auto recognized_kind = target.recognized_kind();
33733373
switch (recognized_kind) {
3374-
case MethodRecognizer::kCoroutineInitialize:
3375-
return BuildCoroutineInitialize();
3376-
case MethodRecognizer::kCoroutineTransfer:
3377-
return BuildCoroutineTransfer();
3378-
case MethodRecognizer::kCoroutineFork:
3379-
return BuildCoroutineFork();
33803374
case MethodRecognizer::kNativeEffect:
33813375
return BuildNativeEffect();
33823376
case MethodRecognizer::kReachabilityFence:
@@ -6020,53 +6014,6 @@ Fragment StreamingFlowGraphBuilder::BuildNativeEffect() {
60206014
return code;
60216015
}
60226016

6023-
Fragment StreamingFlowGraphBuilder::BuildCoroutineInitialize() {
6024-
Fragment instructions;
6025-
ReadUInt();
6026-
ReadListLength();
6027-
ReadListLength();
6028-
instructions += BuildExpression();
6029-
ReadListLength();
6030-
instructions += B->CoroutineInitialize(TokenPosition::kNoSource);
6031-
return instructions;
6032-
}
6033-
6034-
Fragment StreamingFlowGraphBuilder::BuildCoroutineTransfer() {
6035-
Fragment instructions;
6036-
ReadUInt();
6037-
ReadListLength();
6038-
ReadListLength();
6039-
instructions += BuildExpression();
6040-
LocalVariable* from = MakeTemporary();
6041-
instructions += LoadLocal(from);
6042-
instructions += BuildExpression();
6043-
LocalVariable* to = MakeTemporary();
6044-
instructions += LoadLocal(to);
6045-
ReadListLength();
6046-
instructions += B->CoroutineTransfer(TokenPosition::kNoSource);
6047-
instructions += Drop();
6048-
instructions += Drop();
6049-
return instructions;
6050-
}
6051-
6052-
Fragment StreamingFlowGraphBuilder::BuildCoroutineFork() {
6053-
Fragment instructions;
6054-
ReadUInt();
6055-
ReadListLength();
6056-
ReadListLength();
6057-
instructions += BuildExpression();
6058-
LocalVariable* from = MakeTemporary();
6059-
instructions += LoadLocal(from);
6060-
instructions += BuildExpression();
6061-
LocalVariable* to = MakeTemporary();
6062-
instructions += LoadLocal(to);
6063-
ReadListLength();
6064-
instructions += B->CoroutineFork(TokenPosition::kNoSource);
6065-
instructions += Drop();
6066-
instructions += Drop();
6067-
return instructions;
6068-
}
6069-
60706017
Fragment StreamingFlowGraphBuilder::BuildReachabilityFence() {
60716018
const intptr_t argc = ReadUInt(); // Read argument count.
60726019
ASSERT(argc == 1); // LoadField, can be late.

runtime/vm/compiler/frontend/kernel_binary_flowgraph.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,6 @@ class StreamingFlowGraphBuilder : public KernelReaderHelper {
376376
// Build flow graph for '_nativeEffect'.
377377
Fragment BuildNativeEffect();
378378

379-
Fragment BuildCoroutineInitialize();
380-
381-
Fragment BuildCoroutineTransfer();
382-
383-
Fragment BuildCoroutineFork();
384379

385380
// Build the call-site manually, to avoid doing initialization checks
386381
// for late fields.

0 commit comments

Comments
 (0)