Skip to content

Commit

Permalink
Merge pull request 'fibers' (dart-lang#14) from fibers into main
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbashir committed Sep 25, 2024
2 parents 835f8ef + c8b1f07 commit 937e3ce
Show file tree
Hide file tree
Showing 44 changed files with 4,064 additions and 2,208 deletions.
3 changes: 3 additions & 0 deletions build-sdk-product.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
export CPATH=""
./tools/build.py -m product -a x64 runtime dart_precompiled_runtime ddc dartanalyzer analysis_server create_common_sdk create_platform_sdk
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
5 changes: 3 additions & 2 deletions runtime/lib/fiber.cc → runtime/lib/coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include "vm/native_entry.h"

namespace dart {
DEFINE_NATIVE_ENTRY(Coroutine_factory, 0, 2) {
DEFINE_NATIVE_ENTRY(Coroutine_factory, 0, 3) {
GET_NON_NULL_NATIVE_ARGUMENT(Smi, size, arguments->NativeArgAt(1));
return Coroutine::New(size.Value());
GET_NON_NULL_NATIVE_ARGUMENT(Closure, trampoline, arguments->NativeArgAt(2));
return Coroutine::New(size.Value(), trampoline.function());
}
} // namespace dart
2 changes: 1 addition & 1 deletion runtime/lib/fiber_sources.gni
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fiber_runtime_cc_files = [ "fiber.cc" ]
fiber_runtime_cc_files = [ "coroutine.cc" ]
2 changes: 1 addition & 1 deletion runtime/vm/bootstrap_natives.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ namespace dart {
V(DartNativeApiFunctionPointer, 1) \
V(TransferableTypedData_factory, 2) \
V(TransferableTypedData_materialize, 1) \
V(Coroutine_factory, 2)
V(Coroutine_factory, 3)

// List of bootstrap native entry points used in the dart:mirror library.
#define MIRRORS_BOOTSTRAP_NATIVE_LIST(V) \
Expand Down
1 change: 1 addition & 0 deletions runtime/vm/compiler/backend/range_analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2837,6 +2837,7 @@ void LoadFieldInstr::InferRange(RangeAnalysis* analysis, Range* range) {
case Slot::Kind::kTypedDataBase_length:
case Slot::Kind::kTypedDataView_offset_in_bytes:
case Slot::Kind::kCoroutine_attributes:
case Slot::Kind::kCoroutine_index:
*range = Range(RangeBoundary::FromConstant(0), RangeBoundary::MaxSmi());
break;

Expand Down
1 change: 1 addition & 0 deletions runtime/vm/compiler/backend/slot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ bool Slot::IsImmutableLengthSlot() const {
case Slot::Kind::kRecord_shape:
case Slot::Kind::kAbstractType_hash:
case Slot::Kind::kCoroutine_attributes:
case Slot::Kind::kCoroutine_index:
return false;
}
UNREACHABLE();
Expand Down
6 changes: 5 additions & 1 deletion runtime/vm/compiler/backend/slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class ParsedFunction;
V(Coroutine, UntaggedCoroutine, entry, Closure, VAR) \
V(Coroutine, UntaggedCoroutine, trampoline, Function, VAR) \
V(Coroutine, UntaggedCoroutine, processor, Dynamic, VAR) \
V(Coroutine, UntaggedCoroutine, to_processor, Dynamic, VAR) \
V(Coroutine, UntaggedCoroutine, to_processor_next, Dynamic, VAR) \
V(Coroutine, UntaggedCoroutine, to_processor_previous, Dynamic, VAR) \
V(Coroutine, UntaggedCoroutine, caller, Coroutine, VAR) \
V(Coroutine, UntaggedCoroutine, scheduler, Coroutine, VAR)

Expand Down Expand Up @@ -125,6 +126,7 @@ class ParsedFunction;
V(TypeArguments, UntaggedTypeArguments, hash, Smi, VAR) \
V(TypeArguments, UntaggedTypeArguments, length, Smi, FINAL) \
V(AbstractType, UntaggedTypeArguments, hash, Smi, VAR) \
V(Coroutine, UntaggedCoroutine, index, Smi, VAR) \
V(Coroutine, UntaggedCoroutine, attributes, Smi, VAR)

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

Expand Down Expand Up @@ -290,6 +293,7 @@ class ParsedFunction;
// load optimizations.
#define UNTAGGED_NATIVE_NONDART_SLOTS_LIST(V) \
V(IsolateGroup, _, object_store, false, FINAL) \
V(Isolate, _, isolate_object_store, false, FINAL) \
V(Thread, _, api_top_scope, false, VAR) \
V(Thread, _, isolate, false, FINAL) \
V(Thread, _, isolate_group, false, FINAL) \
Expand Down
23 changes: 21 additions & 2 deletions runtime/vm/compiler/frontend/kernel_to_il.cc
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,12 @@ const Function& TypedListGetNativeFunction(Thread* thread, classid_t cid) {
V(Coroutine_getTrampoline, Coroutine_trampoline) \
V(Coroutine_getArguments, Coroutine_arguments) \
V(Coroutine_getAttributes, Coroutine_attributes) \
V(Coroutine_getCaller, Coroutine_caller) \
V(Coroutine_getScheduler, Coroutine_scheduler) \
V(Coroutine_getProcessor, Coroutine_processor) \
V(Coroutine_getToProcessor, Coroutine_to_processor) \
V(Coroutine_getToProcessorNext, Coroutine_to_processor_next) \
V(Coroutine_getToProcessorPrevious, Coroutine_to_processor_previous) \
V(Coroutine_getIndex, Coroutine_index) \
V(SuspendState_getThenCallback, SuspendState_then_callback) \
V(SuspendState_getErrorCallback, SuspendState_error_callback) \
V(TypedDataViewOffsetInBytes, TypedDataView_offset_in_bytes) \
Expand All @@ -956,9 +959,11 @@ const Function& TypedListGetNativeFunction(Thread* thread, classid_t cid) {
V(Coroutine_setTrampoline, Coroutine_trampoline) \
V(Coroutine_setArguments, Coroutine_arguments) \
V(Coroutine_setAttributes, Coroutine_attributes) \
V(Coroutine_setCaller, Coroutine_caller) \
V(Coroutine_setScheduler, Coroutine_scheduler) \
V(Coroutine_setProcessor, Coroutine_processor) \
V(Coroutine_setToProcessor, Coroutine_to_processor) \
V(Coroutine_setToProcessorNext, Coroutine_to_processor_next) \
V(Coroutine_setToProcessorPrevious, Coroutine_to_processor_previous) \
V(WeakProperty_setKey, WeakProperty_key) \
V(WeakProperty_setValue, WeakProperty_value) \
V(WeakReference_setTarget, WeakReference_target)
Expand Down Expand Up @@ -1956,6 +1961,13 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfRecognizedMethod(
body += LoadNativeField(Slot::Thread_coroutine());
break;
}
case MethodRecognizer::kCoroutine_atIndex: {
body += LoadIsolateObjectStore();
body += LoadNativeField(Slot::IsolateObjectStore_coroutines_registry());
body += LoadLocal(parsed_function_->RawParameterVariable(0));
body += LoadIndexed(kArrayCid);
break;
}
#define IL_BODY(method, slot) \
case MethodRecognizer::k##method: \
ASSERT_EQUAL(function.NumParameters(), 1); \
Expand Down Expand Up @@ -4676,6 +4688,13 @@ Fragment FlowGraphBuilder::LoadObjectStore() {
return body;
}

Fragment FlowGraphBuilder::LoadIsolateObjectStore() {
Fragment body;
body += LoadIsolate();
body += LoadNativeField(Slot::Isolate_isolate_object_store());
return body;
}

Fragment FlowGraphBuilder::LoadServiceExtensionStream() {
Fragment body;
body += LoadThread();
Expand Down
3 changes: 3 additions & 0 deletions runtime/vm/compiler/frontend/kernel_to_il.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ class FlowGraphBuilder : public BaseFlowGraphBuilder {

// Loads the (untagged) current ObjectStore address.
Fragment LoadObjectStore();

// Loads the (untagged) current IsolateObjectStore address.
Fragment LoadIsolateObjectStore();

// Loads the (untagged) service extension stream address.
Fragment LoadServiceExtensionStream();
Expand Down
22 changes: 14 additions & 8 deletions runtime/vm/compiler/recognized_methods_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,30 @@ namespace dart {
V(_Coroutine, _transfer, CoroutineTransfer, 0x94684214) \
V(_Coroutine, _fork, CoroutineFork, 0x9e657623) \
V(_Coroutine, get:_name, Coroutine_getName,0x2b1f1c32) \
V(_Coroutine, get:_index, Coroutine_getIndex, 0x683b41d2) \
V(_Coroutine, get:_entry, Coroutine_getEntry, 0xc825e938) \
V(_Coroutine, get:_trampoline, Coroutine_getTrampoline, 0xc5b7b65a) \
V(_Coroutine, get:_arguments, Coroutine_getArguments, 0x4df70fc1) \
V(_Coroutine, get:_attributes, Coroutine_getAttributes, 0x4bba9d49) \
V(_Coroutine, get:_caller, Coroutine_getCaller, 0xe388183b) \
V(_Coroutine, get:_scheduler, Coroutine_getScheduler, 0xd5f06e7c) \
V(_Coroutine, get:_processor, Coroutine_getProcessor, 0x4391e70d) \
V(_Coroutine, get:_toProcessor, Coroutine_getToProcessor, 0x69c3b244) \
V(_Coroutine, get:_caller, Coroutine_getCaller, 0x786ccafc) \
V(_Coroutine, get:_scheduler, Coroutine_getScheduler, 0x6ad5213d) \
V(_Coroutine, get:_processor, Coroutine_getProcessor, 0x6c9fb5d8) \
V(_Coroutine, get:_toProcessorNext, Coroutine_getToProcessorNext, 0x74a78b18)\
V(_Coroutine, get:_toProcessorPrevious, Coroutine_getToProcessorPrevious, \
0x6a5372a9) \
V(_Coroutine, set:_name, Coroutine_setName, 0x45ff0fef) \
V(_Coroutine, set:_entry, Coroutine_setEntry, 0x896541f5) \
V(_Coroutine, set:_trampoline, Coroutine_setTrampoline, 0x86f70f17) \
V(_Coroutine, set:_arguments, Coroutine_setArguments, 0x8c8ec23e) \
V(_Coroutine, set:_attributes, Coroutine_setAttributes, 0xb87a94c6) \
V(_Coroutine, set:_caller, Coroutine_setCaller, 0xbae0fb78) \
V(_Coroutine, set:_scheduler, Coroutine_setScheduler, 0xad4951b9) \
V(_Coroutine, set:_processor, Coroutine_setProcessor, 0x57c426ca) \
V(_Coroutine, set:_toProcessor, Coroutine_setToProcessor, 0x6b557dc1) \
V(_Coroutine, set:_caller, Coroutine_setCaller, 0xa96401f9) \
V(_Coroutine, set:_scheduler, Coroutine_setScheduler, 0x9bcc583a) \
V(_Coroutine, set:_processor, Coroutine_setProcessor, 0x74996ed5) \
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) \


// List of intrinsics:
Expand Down
15 changes: 13 additions & 2 deletions runtime/vm/compiler/runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1037,15 +1037,20 @@ class SuspendState : public AllStatic {
class Coroutine : public AllStatic {
public:
static word name_offset();
static word index_offset();
static word entry_offset();
static word trampoline_offset();
static word arguments_offset();
static word attributes_offset();
static word caller_offset();
static word scheduler_offset();
static word processor_offset();
static word to_processor_offset();
static word index_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();
static word stack_size_offset();
static word native_stack_base_offset();
static word stack_root_offset();
static word stack_base_offset();
Expand Down Expand Up @@ -1355,12 +1360,18 @@ class Isolate : public AllStatic {
static word current_tag_offset();
static word user_tag_offset();
static word finalizers_offset();
static word isolate_object_store_offset();
#if !defined(PRODUCT)
static word single_step_offset();
static word has_resumption_breakpoints_offset();
#endif // !defined(PRODUCT)
};

class IsolateObjectStore : public AllStatic {
public:
static word coroutines_registry_offset();
};

class IsolateGroup : public AllStatic {
public:
static word object_store_offset();
Expand Down
Loading

0 comments on commit 937e3ce

Please sign in to comment.