Skip to content

Commit

Permalink
Merge pull request 'fibers' (#1) from fibers into main
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbashir committed Aug 26, 2024
2 parents b9479eb + e01cc31 commit f30b97e
Show file tree
Hide file tree
Showing 75 changed files with 10,104 additions and 18,213 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,5 @@ logs/logs.json
logs/results.json
.dart_tool/bisect_dart/
doc/api/
build/
sdk.code-workspace.local
2 changes: 2 additions & 0 deletions build-sdk-debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
./tools/build.py -m debug -a x64 runtime dart_precompiled_runtime create_common_sdk create_platform_sdk
3 changes: 3 additions & 0 deletions build-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
./tools/build.py -m release -a x64 runtime dart_precompiled_runtime create_platform_sdk

1 change: 1 addition & 0 deletions dart.S
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VM initialization failed: Invalid vm isolate snapshot seen
Empty file added new-recognized
Empty file.
1 change: 1 addition & 0 deletions pkg/analyzer_cli/tool/perf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ Set<Source?> scanReachableFiles(Uri entryUri) {
'dart:convert',
'dart:core',
'dart:developer',
'dart:fiber',
'dart:_internal',
'dart:isolate',
'dart:math',
Expand Down
2 changes: 2 additions & 0 deletions pkg/dev_compiler/lib/src/kernel/target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class DevCompilerTarget extends Target {
'dart:collection',
'dart:convert',
'dart:developer',
'dart:fiber',
'dart:io',
'dart:isolate',
'dart:js',
Expand All @@ -97,6 +98,7 @@ class DevCompilerTarget extends Target {
@override
List<String> get extraIndexedLibraries => const [
'dart:async',
'dart:fiber',
'dart:collection',
'dart:html',
'dart:indexed_db',
Expand Down
1 change: 1 addition & 0 deletions pkg/front_end/tool/fasta_perf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Map<Uri, Uint8List> scanReachableFiles(Uri entryUri) {
Uri.parse('dart:async'),
Uri.parse('dart:collection'),
Uri.parse('dart:convert'),
Uri.parse('dart:fiber'),
Uri.parse('dart:core'),
Uri.parse('dart:developer'),
Uri.parse('dart:_internal'),
Expand Down
1 change: 1 addition & 0 deletions pkg/front_end/tool/perf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Set<Source> scanReachableFiles(Uri entryUri) {
'dart:async',
'dart:collection',
'dart:convert',
'dart:fiber',
'dart:core',
'dart:developer',
'dart:_internal',
Expand Down
1 change: 1 addition & 0 deletions pkg/vm/lib/modular/target/dart_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class DartRunnerTarget extends VmTarget {
'dart:async',
'dart:collection',
'dart:convert',
'dart:fiber',
'dart:developer',
'dart:ffi',
'dart:_internal',
Expand Down
1 change: 1 addition & 0 deletions pkg/vm/lib/modular/target/flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FlutterTarget extends VmTarget {
'dart:async',
'dart:collection',
'dart:convert',
'dart:fiber',
'dart:developer',
'dart:ffi',
'dart:_internal',
Expand Down
1 change: 1 addition & 0 deletions pkg/vm/lib/modular/target/flutter_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FlutterRunnerTarget extends VmTarget {
'dart:async',
'dart:collection',
'dart:convert',
'dart:fiber',
'dart:developer',
'dart:ffi',
'dart:_internal',
Expand Down
1 change: 1 addition & 0 deletions pkg/vm/lib/modular/target/vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class VmTarget extends Target {
'dart:async',
'dart:collection',
'dart:convert',
'dart:fiber',
'dart:developer',
'dart:ffi',
'dart:_internal',
Expand Down
2 changes: 2 additions & 0 deletions refresh-recognized.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sed -f new-recognized runtime/vm/compiler/recognized_methods_list.h
9 changes: 9 additions & 0 deletions runtime/bin/dartutils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ Dart_Handle DartUtils::PrepareCLILibrary(Dart_Handle cli_lib) {
return Dart_Null();
}

Dart_Handle DartUtils::PrepareFiberLibrary(Dart_Handle fiber_lib) {
return Dart_Null();
}

Dart_Handle DartUtils::SetupPackageConfig(const char* packages_config) {
Dart_Handle result = Dart_Null();

Expand All @@ -578,6 +582,10 @@ Dart_Handle DartUtils::PrepareForScriptLoading(bool is_service_isolate,
RETURN_IF_ERROR(url);
Dart_Handle async_lib = Dart_LookupLibrary(url);
RETURN_IF_ERROR(async_lib);
url = NewString(kFiberLibURL);
RETURN_IF_ERROR(url);
Dart_Handle fiber_lib = Dart_LookupLibrary(url);
RETURN_IF_ERROR(fiber_lib);
url = NewString(kIsolateLibURL);
RETURN_IF_ERROR(url);
Dart_Handle isolate_lib = Dart_LookupLibrary(url);
Expand Down Expand Up @@ -611,6 +619,7 @@ Dart_Handle DartUtils::PrepareForScriptLoading(bool is_service_isolate,
RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib));
RETURN_IF_ERROR(PrepareIOLibrary(io_lib));
RETURN_IF_ERROR(PrepareCLILibrary(cli_lib));
RETURN_IF_ERROR(PrepareFiberLibrary(fiber_lib));
return result;
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/bin/dartutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class DartUtils {

static constexpr const char* kDartScheme = "dart:";
static constexpr const char* kAsyncLibURL = "dart:async";
static constexpr const char* kFiberLibURL = "dart:fiber";
static constexpr const char* kBuiltinLibURL = "dart:_builtin";
static constexpr const char* kCoreLibURL = "dart:core";
static constexpr const char* kInternalLibURL = "dart:_internal";
Expand Down Expand Up @@ -319,6 +320,7 @@ class DartUtils {
static Dart_Handle PrepareIOLibrary(Dart_Handle io_lib);
static Dart_Handle PrepareIsolateLibrary(Dart_Handle isolate_lib);
static Dart_Handle PrepareCLILibrary(Dart_Handle cli_lib);
static Dart_Handle PrepareFiberLibrary(Dart_Handle fiber_lib);

static dart::SimpleHashMap* environment_;

Expand Down
17 changes: 17 additions & 0 deletions runtime/lib/fiber.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#include "vm/bootstrap_natives.h"

#include "vm/compiler/method_recognizer.h"
#include "vm/compiler/runtime_api.h"
#include "vm/native_entry.h"
#include "vm/tagged_pointer.h"

namespace dart {
DEFINE_NATIVE_ENTRY(Coroutine_factory, 0, 2) {
GET_NON_NULL_NATIVE_ARGUMENT(Smi, stack, arguments->NativeArgAt(1));
return Coroutine::New(stack.Value());
}
} // namespace dart
1 change: 1 addition & 0 deletions runtime/lib/fiber_sources.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fiber_runtime_cc_files = [ "fiber.cc" ]
1 change: 1 addition & 0 deletions runtime/lib/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class MessageValidator : private WorkSet {
MESSAGE_SNAPSHOT_ILLEGAL(ReceivePort)
MESSAGE_SNAPSHOT_ILLEGAL(UserTag)
MESSAGE_SNAPSHOT_ILLEGAL(SuspendState)
MESSAGE_SNAPSHOT_ILLEGAL(Coroutine)
default:
klass = class_table_->At(cid);
if (klass.is_isolate_unsendable()) {
Expand Down
9 changes: 9 additions & 0 deletions runtime/lib/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ DEFINE_NATIVE_ENTRY(Internal_nativeEffect, 0, 1) {
UNREACHABLE();
}

DEFINE_NATIVE_ENTRY(Fiber_coroutineInitialize, 0, 1) {
UNREACHABLE();
}

DEFINE_NATIVE_ENTRY(Fiber_coroutineTransfer, 0, 2) {
UNREACHABLE();
}


DEFINE_NATIVE_ENTRY(Internal_collectAllGarbage, 0, 0) {
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging,
/*compact=*/true);
Expand Down
1 change: 1 addition & 0 deletions runtime/tools/dartfuzz/gen_api_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ void main() async {
await visitLibraryAtUri(session, 'dart:cli');
await visitLibraryAtUri(session, 'dart:collection');
await visitLibraryAtUri(session, 'dart:convert');
await visitLibraryAtUri(session, 'dart:fiber');
await visitLibraryAtUri(session, 'dart:core');
await visitLibraryAtUri(session, 'dart:io');
await visitLibraryAtUri(session, 'dart:isolate');
Expand Down
12 changes: 7 additions & 5 deletions runtime/vm/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import("//build_overrides/build.gni")
import("//third_party/protobuf/proto_library.gni")
import("../../build/executable_suffix.gni")
import("../../sdk/lib/async/async_sources.gni")
import("../../sdk/lib/fiber/fiber_sources.gni")
import("../../sdk/lib/collection/collection_sources.gni")
import("../../sdk/lib/convert/convert_sources.gni")
import("../../sdk/lib/core/core_sources.gni")
Expand All @@ -23,6 +24,7 @@ import("../bin/cli_sources.gni")
import("../bin/io_sources.gni")
import("../configs.gni")
import("../lib/async_sources.gni")
import("../lib/fiber_sources.gni")
import("../lib/convert_sources.gni")
import("../lib/core_sources.gni")
import("../lib/developer_sources.gni")
Expand Down Expand Up @@ -225,11 +227,11 @@ library_for_all_configs("libdart_lib") {
extra_deps += [ "$fuchsia_sdk/pkg/trace-engine" ]
}
include_dirs = [ ".." ]
allsources = async_runtime_cc_files + core_runtime_cc_files +
developer_runtime_cc_files + isolate_runtime_cc_files +
math_runtime_cc_files + mirrors_runtime_cc_files +
typed_data_runtime_cc_files + vmservice_runtime_cc_files +
ffi_runtime_cc_files
allsources = async_runtime_cc_files + fiber_runtime_cc_files +
core_runtime_cc_files + developer_runtime_cc_files +
isolate_runtime_cc_files + math_runtime_cc_files +
mirrors_runtime_cc_files + typed_data_runtime_cc_files +
vmservice_runtime_cc_files + ffi_runtime_cc_files
sources = [ "bootstrap.cc" ] + rebase_path(allsources, ".", "../lib")
snapshot_sources = []
}
Expand Down
5 changes: 5 additions & 0 deletions runtime/vm/bootstrap_natives.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ void Bootstrap::SetupNativeResolver() {
library.set_native_entry_resolver(resolver);
library.set_native_entry_symbol_resolver(symbol_resolver);

library = Library::FiberLibrary();
ASSERT(!library.IsNull());
library.set_native_entry_resolver(resolver);
library.set_native_entry_symbol_resolver(symbol_resolver);

library = Library::CollectionLibrary();
ASSERT(!library.IsNull());
library.set_native_entry_resolver(resolver);
Expand Down
5 changes: 4 additions & 1 deletion runtime/vm/bootstrap_natives.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ namespace dart {
V(GrowableList_setData, 2) \
V(Internal_unsafeCast, 1) \
V(Internal_nativeEffect, 1) \
V(Fiber_coroutineInitialize, 1) \
V(Fiber_coroutineTransfer, 2) \
V(Internal_collectAllGarbage, 0) \
V(Internal_makeListFixedLength, 1) \
V(Internal_makeFixedListUnmodifiable, 1) \
Expand Down Expand Up @@ -312,7 +314,8 @@ namespace dart {
V(DartApiDLMinorVersion, 0) \
V(DartNativeApiFunctionPointer, 1) \
V(TransferableTypedData_factory, 2) \
V(TransferableTypedData_materialize, 1)
V(TransferableTypedData_materialize, 1) \
V(Coroutine_factory, 2)

// 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/class_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static constexpr intptr_t kClassIdTagMax = (1 << 20) - 1;
V(SendPort) \
V(StackTrace) \
V(SuspendState) \
V(Coroutine) \
V(RegExp) \
V(WeakProperty) \
V(WeakReference) \
Expand Down
1 change: 1 addition & 0 deletions runtime/vm/compiler/assembler/assembler_x64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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
8 changes: 8 additions & 0 deletions runtime/vm/compiler/backend/constant_propagator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,14 @@ void ConstantPropagator::VisitCall1ArgStub(Call1ArgStubInstr* instr) {
SetValue(instr, non_constant_);
}

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

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

void ConstantPropagator::VisitSuspend(SuspendInstr* instr) {
SetValue(instr, non_constant_);
}
Expand Down
60 changes: 60 additions & 0 deletions runtime/vm/compiler/backend/il.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "vm/compiler/method_recognizer.h"
#include "vm/compiler/runtime_api.h"
#include "vm/constants.h"
#include "vm/constants_x86.h"
#include "vm/cpu.h"
#include "vm/dart_entry.h"
#include "vm/object.h"
Expand Down Expand Up @@ -8550,6 +8551,65 @@ void Call1ArgStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
locs(), deopt_id(), env());
}

LocationSummary* CoroutineInitializeStubInstr::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(CoroutineInitializeStubABI::kFromCoroutineReg));
return locs;
}

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();
__ PushRegister(FPREG);
__ PushRegister(THR);
__ PushRegister(TMP);
__ PushRegister(PP);
__ PushRegister(CODE_REG);
__ LoadFieldFromOffset(CoroutineTransferStubABI::kFromContextReg, CoroutineTransferStubABI::kFromCoroutineReg, compiler::target::Coroutine::context_offset());
__ StoreToOffset(SPREG, CoroutineTransferStubABI::kFromContextReg, CoroutineTransferStubABI::kContextSpOffset);
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
__ PopRegister(CODE_REG);
__ PopRegister(PP);
__ PopRegister(TMP);
__ PopRegister(THR);
__ PopRegister(FPREG);
}

LocationSummary* CoroutineTransferStubInstr::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(CoroutineTransferStubABI::kFromCoroutineReg));
locs->set_in(1, Location::RegisterLocation(CoroutineTransferStubABI::kToCoroutineReg));
return locs;
}

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();
__ PushRegister(FPREG);
__ PushRegister(THR);
__ PushRegister(TMP);
__ PushRegister(PP);
__ PushRegister(CODE_REG);
__ LoadFieldFromOffset(CoroutineTransferStubABI::kFromContextReg, CoroutineTransferStubABI::kFromCoroutineReg, compiler::target::Coroutine::context_offset());
__ StoreToOffset(SPREG, CoroutineTransferStubABI::kFromContextReg, CoroutineTransferStubABI::kContextSpOffset);
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
__ PopRegister(CODE_REG);
__ PopRegister(PP);
__ PopRegister(TMP);
__ PopRegister(THR);
__ PopRegister(FPREG);
}

Definition* SuspendInstr::Canonicalize(FlowGraph* flow_graph) {
if (stub_id() == StubId::kAwaitWithTypeCheck &&
!operand()->Type()->CanBeFuture()) {
Expand Down
Loading

0 comments on commit f30b97e

Please sign in to comment.