Skip to content

Commit 937e3ce

Browse files
committed
Merge pull request 'fibers' (dart-lang#14) from fibers into main
Reviewed-on: http://git.local/dependencies/dart/pulls/14
2 parents 835f8ef + c8b1f07 commit 937e3ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4064
-2208
lines changed

build-sdk-product.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
export CPATH=""
3+
./tools/build.py -m product -a x64 runtime dart_precompiled_runtime ddc dartanalyzer analysis_server create_common_sdk create_platform_sdk

runtime/bin/eventhandler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class CircularLinkedList {
135135
}
136136
}
137137

138-
void RemoveHead(ClearFun clear = nullptr) {
138+
void _removeHead(ClearFun clear = nullptr) {
139139
ASSERT(head_ != nullptr);
140140

141141
Entry* e = head_;
@@ -184,7 +184,7 @@ class CircularLinkedList {
184184

185185
void RemoveAll(ClearFun clear = nullptr) {
186186
while (HasHead()) {
187-
RemoveHead(clear);
187+
_removeHead(clear);
188188
}
189189
}
190190

@@ -502,7 +502,7 @@ class DescriptorInfoMultipleMixin : public DI {
502502
pentry->token_count--;
503503
}
504504
if (pentry->token_count <= 0) {
505-
active_readers_.RemoveHead();
505+
active_readers_._removeHead();
506506
} else {
507507
active_readers_.Rotate();
508508
}

runtime/bin/eventhandler_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ VM_UNIT_TEST_CASE(CircularLinkedList) {
3333

3434
// Test: Removing head results in next element to be head.
3535
for (int i = 1; i <= 100; i++) {
36-
list.RemoveHead();
36+
list._removeHead();
3737
for (int j = i + 1; j <= 100; j++) {
3838
EXPECT(list.HasHead());
3939
EXPECT(list.head() == j);

runtime/lib/fiber.cc renamed to runtime/lib/coroutine.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#include "vm/native_entry.h"
99

1010
namespace dart {
11-
DEFINE_NATIVE_ENTRY(Coroutine_factory, 0, 2) {
11+
DEFINE_NATIVE_ENTRY(Coroutine_factory, 0, 3) {
1212
GET_NON_NULL_NATIVE_ARGUMENT(Smi, size, arguments->NativeArgAt(1));
13-
return Coroutine::New(size.Value());
13+
GET_NON_NULL_NATIVE_ARGUMENT(Closure, trampoline, arguments->NativeArgAt(2));
14+
return Coroutine::New(size.Value(), trampoline.function());
1415
}
1516
} // namespace dart

runtime/lib/fiber_sources.gni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fiber_runtime_cc_files = [ "fiber.cc" ]
1+
fiber_runtime_cc_files = [ "coroutine.cc" ]

runtime/vm/bootstrap_natives.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ namespace dart {
313313
V(DartNativeApiFunctionPointer, 1) \
314314
V(TransferableTypedData_factory, 2) \
315315
V(TransferableTypedData_materialize, 1) \
316-
V(Coroutine_factory, 2)
316+
V(Coroutine_factory, 3)
317317

318318
// List of bootstrap native entry points used in the dart:mirror library.
319319
#define MIRRORS_BOOTSTRAP_NATIVE_LIST(V) \

runtime/vm/compiler/backend/range_analysis.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,7 @@ void LoadFieldInstr::InferRange(RangeAnalysis* analysis, Range* range) {
28372837
case Slot::Kind::kTypedDataBase_length:
28382838
case Slot::Kind::kTypedDataView_offset_in_bytes:
28392839
case Slot::Kind::kCoroutine_attributes:
2840+
case Slot::Kind::kCoroutine_index:
28402841
*range = Range(RangeBoundary::FromConstant(0), RangeBoundary::MaxSmi());
28412842
break;
28422843

runtime/vm/compiler/backend/slot.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ bool Slot::IsImmutableLengthSlot() const {
240240
case Slot::Kind::kRecord_shape:
241241
case Slot::Kind::kAbstractType_hash:
242242
case Slot::Kind::kCoroutine_attributes:
243+
case Slot::Kind::kCoroutine_index:
243244
return false;
244245
}
245246
UNREACHABLE();

runtime/vm/compiler/backend/slot.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class ParsedFunction;
9090
V(Coroutine, UntaggedCoroutine, entry, Closure, VAR) \
9191
V(Coroutine, UntaggedCoroutine, trampoline, Function, VAR) \
9292
V(Coroutine, UntaggedCoroutine, processor, Dynamic, VAR) \
93-
V(Coroutine, UntaggedCoroutine, to_processor, Dynamic, VAR) \
93+
V(Coroutine, UntaggedCoroutine, to_processor_next, Dynamic, VAR) \
94+
V(Coroutine, UntaggedCoroutine, to_processor_previous, Dynamic, VAR) \
9495
V(Coroutine, UntaggedCoroutine, caller, Coroutine, VAR) \
9596
V(Coroutine, UntaggedCoroutine, scheduler, Coroutine, VAR)
9697

@@ -125,6 +126,7 @@ class ParsedFunction;
125126
V(TypeArguments, UntaggedTypeArguments, hash, Smi, VAR) \
126127
V(TypeArguments, UntaggedTypeArguments, length, Smi, FINAL) \
127128
V(AbstractType, UntaggedTypeArguments, hash, Smi, VAR) \
129+
V(Coroutine, UntaggedCoroutine, index, Smi, VAR) \
128130
V(Coroutine, UntaggedCoroutine, attributes, Smi, VAR)
129131

130132
// The list of slots that correspond to non-nullable boxed fields of native
@@ -242,6 +244,7 @@ class ParsedFunction;
242244
V(Isolate, _, finalizers, GrowableObjectArray, VAR) \
243245
V(LocalHandle, _, ptr, Dynamic, VAR) \
244246
V(ObjectStore, _, record_field_names, Array, VAR) \
247+
V(IsolateObjectStore, _, coroutines_registry, Array, VAR) \
245248
V(Thread, _, coroutine, Coroutine, VAR) \
246249
V(PersistentHandle, _, ptr, Dynamic, VAR)
247250

@@ -290,6 +293,7 @@ class ParsedFunction;
290293
// load optimizations.
291294
#define UNTAGGED_NATIVE_NONDART_SLOTS_LIST(V) \
292295
V(IsolateGroup, _, object_store, false, FINAL) \
296+
V(Isolate, _, isolate_object_store, false, FINAL) \
293297
V(Thread, _, api_top_scope, false, VAR) \
294298
V(Thread, _, isolate, false, FINAL) \
295299
V(Thread, _, isolate_group, false, FINAL) \

runtime/vm/compiler/frontend/kernel_to_il.cc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,12 @@ const Function& TypedListGetNativeFunction(Thread* thread, classid_t cid) {
927927
V(Coroutine_getTrampoline, Coroutine_trampoline) \
928928
V(Coroutine_getArguments, Coroutine_arguments) \
929929
V(Coroutine_getAttributes, Coroutine_attributes) \
930+
V(Coroutine_getCaller, Coroutine_caller) \
930931
V(Coroutine_getScheduler, Coroutine_scheduler) \
931932
V(Coroutine_getProcessor, Coroutine_processor) \
932-
V(Coroutine_getToProcessor, Coroutine_to_processor) \
933+
V(Coroutine_getToProcessorNext, Coroutine_to_processor_next) \
934+
V(Coroutine_getToProcessorPrevious, Coroutine_to_processor_previous) \
935+
V(Coroutine_getIndex, Coroutine_index) \
933936
V(SuspendState_getThenCallback, SuspendState_then_callback) \
934937
V(SuspendState_getErrorCallback, SuspendState_error_callback) \
935938
V(TypedDataViewOffsetInBytes, TypedDataView_offset_in_bytes) \
@@ -956,9 +959,11 @@ const Function& TypedListGetNativeFunction(Thread* thread, classid_t cid) {
956959
V(Coroutine_setTrampoline, Coroutine_trampoline) \
957960
V(Coroutine_setArguments, Coroutine_arguments) \
958961
V(Coroutine_setAttributes, Coroutine_attributes) \
962+
V(Coroutine_setCaller, Coroutine_caller) \
959963
V(Coroutine_setScheduler, Coroutine_scheduler) \
960964
V(Coroutine_setProcessor, Coroutine_processor) \
961-
V(Coroutine_setToProcessor, Coroutine_to_processor) \
965+
V(Coroutine_setToProcessorNext, Coroutine_to_processor_next) \
966+
V(Coroutine_setToProcessorPrevious, Coroutine_to_processor_previous) \
962967
V(WeakProperty_setKey, WeakProperty_key) \
963968
V(WeakProperty_setValue, WeakProperty_value) \
964969
V(WeakReference_setTarget, WeakReference_target)
@@ -1956,6 +1961,13 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfRecognizedMethod(
19561961
body += LoadNativeField(Slot::Thread_coroutine());
19571962
break;
19581963
}
1964+
case MethodRecognizer::kCoroutine_atIndex: {
1965+
body += LoadIsolateObjectStore();
1966+
body += LoadNativeField(Slot::IsolateObjectStore_coroutines_registry());
1967+
body += LoadLocal(parsed_function_->RawParameterVariable(0));
1968+
body += LoadIndexed(kArrayCid);
1969+
break;
1970+
}
19591971
#define IL_BODY(method, slot) \
19601972
case MethodRecognizer::k##method: \
19611973
ASSERT_EQUAL(function.NumParameters(), 1); \
@@ -4676,6 +4688,13 @@ Fragment FlowGraphBuilder::LoadObjectStore() {
46764688
return body;
46774689
}
46784690

4691+
Fragment FlowGraphBuilder::LoadIsolateObjectStore() {
4692+
Fragment body;
4693+
body += LoadIsolate();
4694+
body += LoadNativeField(Slot::Isolate_isolate_object_store());
4695+
return body;
4696+
}
4697+
46794698
Fragment FlowGraphBuilder::LoadServiceExtensionStream() {
46804699
Fragment body;
46814700
body += LoadThread();

runtime/vm/compiler/frontend/kernel_to_il.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ class FlowGraphBuilder : public BaseFlowGraphBuilder {
318318

319319
// Loads the (untagged) current ObjectStore address.
320320
Fragment LoadObjectStore();
321+
322+
// Loads the (untagged) current IsolateObjectStore address.
323+
Fragment LoadIsolateObjectStore();
321324

322325
// Loads the (untagged) service extension stream address.
323326
Fragment LoadServiceExtensionStream();

runtime/vm/compiler/recognized_methods_list.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,24 +385,30 @@ namespace dart {
385385
V(_Coroutine, _transfer, CoroutineTransfer, 0x94684214) \
386386
V(_Coroutine, _fork, CoroutineFork, 0x9e657623) \
387387
V(_Coroutine, get:_name, Coroutine_getName,0x2b1f1c32) \
388+
V(_Coroutine, get:_index, Coroutine_getIndex, 0x683b41d2) \
388389
V(_Coroutine, get:_entry, Coroutine_getEntry, 0xc825e938) \
389390
V(_Coroutine, get:_trampoline, Coroutine_getTrampoline, 0xc5b7b65a) \
390391
V(_Coroutine, get:_arguments, Coroutine_getArguments, 0x4df70fc1) \
391392
V(_Coroutine, get:_attributes, Coroutine_getAttributes, 0x4bba9d49) \
392-
V(_Coroutine, get:_caller, Coroutine_getCaller, 0xe388183b) \
393-
V(_Coroutine, get:_scheduler, Coroutine_getScheduler, 0xd5f06e7c) \
394-
V(_Coroutine, get:_processor, Coroutine_getProcessor, 0x4391e70d) \
395-
V(_Coroutine, get:_toProcessor, Coroutine_getToProcessor, 0x69c3b244) \
393+
V(_Coroutine, get:_caller, Coroutine_getCaller, 0x786ccafc) \
394+
V(_Coroutine, get:_scheduler, Coroutine_getScheduler, 0x6ad5213d) \
395+
V(_Coroutine, get:_processor, Coroutine_getProcessor, 0x6c9fb5d8) \
396+
V(_Coroutine, get:_toProcessorNext, Coroutine_getToProcessorNext, 0x74a78b18)\
397+
V(_Coroutine, get:_toProcessorPrevious, Coroutine_getToProcessorPrevious, \
398+
0x6a5372a9) \
396399
V(_Coroutine, set:_name, Coroutine_setName, 0x45ff0fef) \
397400
V(_Coroutine, set:_entry, Coroutine_setEntry, 0x896541f5) \
398401
V(_Coroutine, set:_trampoline, Coroutine_setTrampoline, 0x86f70f17) \
399402
V(_Coroutine, set:_arguments, Coroutine_setArguments, 0x8c8ec23e) \
400403
V(_Coroutine, set:_attributes, Coroutine_setAttributes, 0xb87a94c6) \
401-
V(_Coroutine, set:_caller, Coroutine_setCaller, 0xbae0fb78) \
402-
V(_Coroutine, set:_scheduler, Coroutine_setScheduler, 0xad4951b9) \
403-
V(_Coroutine, set:_processor, Coroutine_setProcessor, 0x57c426ca) \
404-
V(_Coroutine, set:_toProcessor, Coroutine_setToProcessor, 0x6b557dc1) \
404+
V(_Coroutine, set:_caller, Coroutine_setCaller, 0xa96401f9) \
405+
V(_Coroutine, set:_scheduler, Coroutine_setScheduler, 0x9bcc583a) \
406+
V(_Coroutine, set:_processor, Coroutine_setProcessor, 0x74996ed5) \
407+
V(_Coroutine, set:_toProcessorNext, Coroutine_setToProcessorNext, 0xa59ec215)\
408+
V(_Coroutine, set:_toProcessorPrevious, Coroutine_setToProcessorPrevious, \
409+
0x9b4aa9a6) \
405410
V(_Coroutine, get:_current, Coroutine_getCurrent, 0xc845245c) \
411+
V(_Coroutine, _at, Coroutine_atIndex, 0x28baa8da) \
406412

407413

408414
// List of intrinsics:

runtime/vm/compiler/runtime_api.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,15 +1037,20 @@ class SuspendState : public AllStatic {
10371037
class Coroutine : public AllStatic {
10381038
public:
10391039
static word name_offset();
1040+
static word index_offset();
10401041
static word entry_offset();
10411042
static word trampoline_offset();
10421043
static word arguments_offset();
10431044
static word attributes_offset();
10441045
static word caller_offset();
10451046
static word scheduler_offset();
10461047
static word processor_offset();
1047-
static word to_processor_offset();
1048-
static word index_offset();
1048+
static word previous_offset();
1049+
static word next_offset();
1050+
static word to_state_offset();
1051+
static word to_processor_next_offset();
1052+
static word to_processor_previous_offset();
1053+
static word stack_size_offset();
10491054
static word native_stack_base_offset();
10501055
static word stack_root_offset();
10511056
static word stack_base_offset();
@@ -1355,12 +1360,18 @@ class Isolate : public AllStatic {
13551360
static word current_tag_offset();
13561361
static word user_tag_offset();
13571362
static word finalizers_offset();
1363+
static word isolate_object_store_offset();
13581364
#if !defined(PRODUCT)
13591365
static word single_step_offset();
13601366
static word has_resumption_breakpoints_offset();
13611367
#endif // !defined(PRODUCT)
13621368
};
13631369

1370+
class IsolateObjectStore : public AllStatic {
1371+
public:
1372+
static word coroutines_registry_offset();
1373+
};
1374+
13641375
class IsolateGroup : public AllStatic {
13651376
public:
13661377
static word object_store_offset();

0 commit comments

Comments
 (0)