Skip to content

Commit

Permalink
Merge pull request 'fibers' (dart-lang#15) from fibers into main
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbashir committed Sep 30, 2024
2 parents 937e3ce + 4c057ae commit 1f38b23
Show file tree
Hide file tree
Showing 38 changed files with 841 additions and 541 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@ build-sdk.sh
build-fiber-test.sh
*.exe
*.aot
*.S
*.S
*.s
6 changes: 3 additions & 3 deletions runtime/bin/eventhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class CircularLinkedList {
}
}

void _removeHead(ClearFun clear = nullptr) {
void RemoveHead(ClearFun clear = nullptr) {
ASSERT(head_ != nullptr);

Entry* e = head_;
Expand Down Expand Up @@ -184,7 +184,7 @@ class CircularLinkedList {

void RemoveAll(ClearFun clear = nullptr) {
while (HasHead()) {
_removeHead(clear);
RemoveHead(clear);
}
}

Expand Down Expand Up @@ -502,7 +502,7 @@ class DescriptorInfoMultipleMixin : public DI {
pentry->token_count--;
}
if (pentry->token_count <= 0) {
active_readers_._removeHead();
active_readers_.RemoveHead();
} else {
active_readers_.Rotate();
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/bin/eventhandler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ VM_UNIT_TEST_CASE(CircularLinkedList) {

// Test: Removing head results in next element to be head.
for (int i = 1; i <= 100; i++) {
list._removeHead();
list.RemoveHead();
for (int j = i + 1; j <= 100; j++) {
EXPECT(list.HasHead());
EXPECT(list.head() == j);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ var globalState = "";
void main() {
// testBase();

testClosures();
while (true) {
testClosures();
}
// testRecycle();
}

Expand Down
126 changes: 40 additions & 86 deletions runtime/vm/compiler/backend/il.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8551,106 +8551,52 @@ void Call1ArgStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
locs(), deopt_id(), env());
}

LocationSummary* CoroutineInitializeInstr::MakeLocationSummary(
Zone* zone,
bool opt) const {
LocationSummary* CoroutineInitializeInstr::MakeLocationSummary(Zone* zone,
bool opt) const {
const intptr_t kNumInputs = 1;
const intptr_t kNumTemps = 0;
LocationSummary* locs = new (zone) LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
locs->set_in(0, Location::RegisterLocation(CoroutineInitializeABI::kCoroutineReg));
LocationSummary* locs = new (zone)
LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
locs->set_in(
0, Location::RegisterLocation(CoroutineInitializeABI::kCoroutineReg));
return locs;
}

void CoroutineInitializeInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register kCoroutine = CoroutineInitializeABI::kCoroutineReg;

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

__ PushRegister(FPREG);
__ StoreFieldToOffset(SPREG, kCoroutine, Coroutine::native_stack_base_offset());

__ LoadFieldFromOffset(SPREG, kCoroutine, Coroutine::stack_base_offset());
__ PushRegister(kCoroutine);
compiler->GenerateStubCall(source(), StubCode::CoroutineEntry(), UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
__ PopRegister(kCoroutine);
__ StoreFieldToOffset(SPREG, kCoroutine, Coroutine::stack_base_offset());

__ LoadFieldFromOffset(SPREG, kCoroutine, Coroutine::native_stack_base_offset());
__ PopRegister(FPREG);
if (!FLAG_precompiled_mode) __ RestoreCodePointer();
if (FLAG_precompiled_mode) __ movq(PP, compiler::Address(THR, Thread::global_object_pool_offset()));

__ PushObject(compiler::NullObject());
__ PushRegister(kCoroutine);
__ CallRuntime(kExitCoroutineRuntimeEntry, 1);
__ PopRegister(kCoroutine);
__ Drop(1);
compiler->GenerateStubCall(source(), StubCode::CoroutineInitialize(),
UntaggedPcDescriptors::kOther, locs(), deopt_id(),
env());
}

LocationSummary* CoroutineForkInstr::MakeLocationSummary(
Zone* zone,
bool opt) const {
LocationSummary* CoroutineForkInstr::MakeLocationSummary(Zone* zone,
bool opt) const {
const intptr_t kNumInputs = 2;
const intptr_t kNumTemps = 0;
LocationSummary* locs = new (zone) LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
locs->set_in(0, Location::RegisterLocation(CoroutineForkABI::kCallerCoroutineReg));
locs->set_in(1, Location::RegisterLocation(CoroutineForkABI::kForkedCoroutineReg));
LocationSummary* locs = new (zone)
LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
locs->set_in(
0, Location::RegisterLocation(CoroutineForkABI::kCallerCoroutineReg));
locs->set_in(
1, Location::RegisterLocation(CoroutineForkABI::kForkedCoroutineReg));
return locs;
}

void CoroutineForkInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register kCallerCoroutine = CoroutineForkABI::kCallerCoroutineReg;
const Register kForkedCoroutine = CoroutineForkABI::kForkedCoroutineReg;

#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
SPILLS_LR_TO_FRAME({});
#endif
__ PushObject(compiler::NullObject());
__ PushRegister(kForkedCoroutine);
__ CallRuntime(kEnterForkedCoroutineRuntimeEntry, 1);
__ PopRegister(kForkedCoroutine);
__ Drop(1);

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

__ PushRegister(FPREG);
__ StoreFieldToOffset(SPREG, kCallerCoroutine, Coroutine::stack_base_offset());

__ LoadFieldFromOffset(SPREG, kForkedCoroutine, Coroutine::stack_base_offset());
__ PushRegister(kForkedCoroutine);
compiler->GenerateStubCall(source(), StubCode::CoroutineEntry(), UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
__ PopRegister(kForkedCoroutine);
__ StoreFieldToOffset(SPREG, kForkedCoroutine, Coroutine::stack_base_offset());

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

__ LoadFieldFromOffset(SPREG, kCallerCoroutine, Coroutine::stack_base_offset());
__ PopRegister(FPREG);
if (!FLAG_precompiled_mode) __ RestoreCodePointer();
if (FLAG_precompiled_mode) __ movq(PP, compiler::Address(THR, Thread::global_object_pool_offset()));

__ PushObject(compiler::NullObject());
__ PushRegister(kForkedCoroutine);
__ CallRuntime(kExitForkedCoroutineRuntimeEntry, 1);
__ PopRegister(kForkedCoroutine);
__ Drop(1);
compiler->GenerateStubCall(source(), StubCode::CoroutineFork(),
UntaggedPcDescriptors::kOther, locs(), deopt_id(),
env());
}

LocationSummary* CoroutineTransferInstr::MakeLocationSummary(
Zone* zone,
bool opt) const {
LocationSummary* CoroutineTransferInstr::MakeLocationSummary(Zone* zone,
bool opt) const {
const intptr_t kNumInputs = 2;
const intptr_t kNumTemps = 0;
LocationSummary* locs = new (zone) LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
locs->set_in(0, Location::RegisterLocation(CoroutineTransferABI::kFromCoroutineReg));
locs->set_in(1, Location::RegisterLocation(CoroutineTransferABI::kToCoroutineReg));
LocationSummary* locs = new (zone)
LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
locs->set_in(
0, Location::RegisterLocation(CoroutineTransferABI::kFromCoroutineReg));
locs->set_in(
1, Location::RegisterLocation(CoroutineTransferABI::kToCoroutineReg));
return locs;
}

Expand All @@ -8661,18 +8607,26 @@ void CoroutineTransferInstr::EmitNativeCode(FlowGraphCompiler* compiler) {

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

__ LoadFieldFromOffset(SPREG, kToCoroutine, Coroutine::stack_base_offset());
__ PopRegister(FPREG);
if (!FLAG_precompiled_mode) __ RestoreCodePointer();
if (FLAG_precompiled_mode) __ movq(PP, compiler::Address(THR, Thread::global_object_pool_offset()));
if (FLAG_precompiled_mode)
__ movq(PP, compiler::Address(THR, Thread::global_object_pool_offset()));

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

compiler::Label scheduled_interrupts;
__ LoadFromOffset(TMP, THR, Thread::stack_limit_offset());
__ testq(TMP, compiler::Immediate(Thread::kInterruptsMask));
__ BranchIf(ZERO, &scheduled_interrupts);
__ StoreToOffset(kToStackLimit, THR, Thread::stack_limit_offset());
__ Bind(&scheduled_interrupts);
}

Definition* SuspendInstr::Canonicalize(FlowGraph* flow_graph) {
Expand Down
1 change: 1 addition & 0 deletions runtime/vm/compiler/frontend/kernel_to_il.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,7 @@ bool FlowGraphBuilder::IsRecognizedMethodForFlowGraph(
case MethodRecognizer::kCoroutineInitialize:
case MethodRecognizer::kCoroutineTransfer:
case MethodRecognizer::kCoroutine_getCurrent:
case MethodRecognizer::kCoroutine_atIndex:
return true;
default:
return false;
Expand Down
10 changes: 5 additions & 5 deletions runtime/vm/compiler/recognized_methods_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ namespace dart {
V(::, _memCopy, MemCopy, 0x51939aa6) \
V(::, debugger, Debugger, 0xf0aaff14) \
V(::, _checkNotDeeplyImmutable, CheckNotDeeplyImmutable, 0x34e4da90) \
V(_Coroutine, _initialize, CoroutineInitialize, 0xa75fb4b4) \
V(_Coroutine, _transfer, CoroutineTransfer, 0x94684214) \
V(_Coroutine, _fork, CoroutineFork, 0x9e657623) \
V(_Coroutine, _initialize, CoroutineInitialize, 0xa75fbc36) \
V(_Coroutine, _transfer, CoroutineTransfer, 0x94684996) \
V(_Coroutine, _fork, CoroutineFork, 0x9e657da5) \
V(_Coroutine, get:_name, Coroutine_getName,0x2b1f1c32) \
V(_Coroutine, get:_index, Coroutine_getIndex, 0x683b41d2) \
V(_Coroutine, get:_entry, Coroutine_getEntry, 0xc825e938) \
Expand All @@ -407,8 +407,8 @@ namespace dart {
V(_Coroutine, set:_toProcessorNext, Coroutine_setToProcessorNext, 0xa59ec215)\
V(_Coroutine, set:_toProcessorPrevious, Coroutine_setToProcessorPrevious, \
0x9b4aa9a6) \
V(_Coroutine, get:_current, Coroutine_getCurrent, 0xc845245c) \
V(_Coroutine, _at, Coroutine_atIndex, 0x28baa8da) \
V(_Coroutine, get:_current, Coroutine_getCurrent, 0xc8452bde) \
V(_Coroutine, _at, Coroutine_atIndex, 0x28bab05c) \


// List of intrinsics:
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/compiler/runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,6 @@ class Coroutine : public AllStatic {
static word caller_offset();
static word scheduler_offset();
static word processor_offset();
static word previous_offset();
static word next_offset();
static word to_state_offset();
static word to_processor_next_offset();
static word to_processor_previous_offset();
Expand All @@ -1055,6 +1053,7 @@ class Coroutine : public AllStatic {
static word stack_root_offset();
static word stack_base_offset();
static word stack_limit_offset();
static word overflow_stack_limit_offset();
static word InstanceSize();
FINAL_CLASS();
};
Expand Down Expand Up @@ -1281,6 +1280,7 @@ class Thread : public AllStatic {
static word auto_scope_native_wrapper_entry_point_offset();

static word coroutine_offset();
static word disabled_coroutine_offset();

#define THREAD_XMM_CONSTANT_LIST(V) \
V(float_not) \
Expand Down
Loading

0 comments on commit 1f38b23

Please sign in to comment.