Skip to content

Commit

Permalink
Merge pull request 'fibers' (dart-lang#17) from fibers into main
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbashir committed Nov 1, 2024
2 parents 9ffee69 + 635d5bc commit 0e1392d
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 68 deletions.
1 change: 0 additions & 1 deletion runtime/platform/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <functional>
#include <cassert> // For assert() in constant expressions.

#if defined(_WIN32)
Expand Down
3 changes: 3 additions & 0 deletions runtime/vm/compiler/backend/constant_propagator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1566,12 +1566,15 @@ void ConstantPropagator::VisitCall1ArgStub(Call1ArgStubInstr* instr) {
}

void ConstantPropagator::VisitCoroutineInitialize(CoroutineInitializeInstr* instr) {
SetValue(instr, non_constant_);
}

void ConstantPropagator::VisitCoroutineTransfer(CoroutineTransferInstr* instr) {
SetValue(instr, non_constant_);
}

void ConstantPropagator::VisitCoroutineFork(CoroutineForkInstr* instr) {
SetValue(instr, non_constant_);
}

void ConstantPropagator::VisitSuspend(SuspendInstr* instr) {
Expand Down
7 changes: 4 additions & 3 deletions runtime/vm/compiler/backend/il.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#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 @@ -8614,9 +8613,11 @@ void CoroutineTransferInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
__ 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::overflow_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());

Expand Down
18 changes: 9 additions & 9 deletions runtime/vm/compiler/backend/il.h
Original file line number Diff line number Diff line change
Expand Up @@ -11476,10 +11476,10 @@ class Call1ArgStubInstr : public TemplateDefinition<1, Throws> {
DISALLOW_COPY_AND_ASSIGN(Call1ArgStubInstr);
};

class CoroutineInitializeInstr : public TemplateInstruction<1, Throws> {
class CoroutineInitializeInstr : public TemplateDefinition<1, Throws> {
public:
CoroutineInitializeInstr(Value* root, intptr_t deopt_id)
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
deopt_id) {
SetInputAt(0, root);
}
Expand All @@ -11495,16 +11495,16 @@ class CoroutineInitializeInstr : public TemplateInstruction<1, Throws> {

DECLARE_INSTRUCTION(CoroutineInitialize);
PRINT_OPERANDS_TO_SUPPORT
DECLARE_EMPTY_SERIALIZATION(CoroutineInitializeInstr, TemplateInstruction)
DECLARE_EMPTY_SERIALIZATION(CoroutineInitializeInstr, TemplateDefinition)

private:
DISALLOW_COPY_AND_ASSIGN(CoroutineInitializeInstr);
};

class CoroutineTransferInstr : public TemplateInstruction<2, Throws> {
class CoroutineTransferInstr : public TemplateDefinition<2, Throws> {
public:
CoroutineTransferInstr(Value* from, Value* to, intptr_t deopt_id)
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
deopt_id) {
SetInputAt(0, from);
SetInputAt(1, to);
Expand All @@ -11523,16 +11523,16 @@ class CoroutineTransferInstr : public TemplateInstruction<2, Throws> {

DECLARE_INSTRUCTION(CoroutineTransfer);
PRINT_OPERANDS_TO_SUPPORT
DECLARE_EMPTY_SERIALIZATION(CoroutineTransferInstr, TemplateInstruction)
DECLARE_EMPTY_SERIALIZATION(CoroutineTransferInstr, TemplateDefinition)

private:
DISALLOW_COPY_AND_ASSIGN(CoroutineTransferInstr);
};

class CoroutineForkInstr : public TemplateInstruction<2, Throws> {
class CoroutineForkInstr : public TemplateDefinition<2, Throws> {
public:
CoroutineForkInstr(Value* from, Value* to, intptr_t deopt_id)
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
deopt_id) {
SetInputAt(0, from);
SetInputAt(1, to);
Expand All @@ -11552,7 +11552,7 @@ class CoroutineForkInstr : public TemplateInstruction<2, Throws> {
DECLARE_INSTRUCTION(CoroutineFork);
PRINT_OPERANDS_TO_SUPPORT

DECLARE_EMPTY_SERIALIZATION(CoroutineForkInstr, TemplateInstruction)
DECLARE_EMPTY_SERIALIZATION(CoroutineForkInstr, TemplateDefinition)

private:
DISALLOW_COPY_AND_ASSIGN(CoroutineForkInstr);
Expand Down
3 changes: 0 additions & 3 deletions runtime/vm/compiler/stub_code_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
// BSD-style license that can be found in the LICENSE file.

#include "vm/compiler/runtime_api.h"
#include "vm/constants.h"
#include "vm/flags.h"
#include "vm/globals.h"

// For `StubCodeCompiler::GenerateAllocateUnhandledExceptionStub`
#include "vm/compiler/backend/il.h"
#include "vm/stub_code.h"

#define SHOULD_NOT_INCLUDE_RUNTIME

Expand Down Expand Up @@ -3309,7 +3307,6 @@ void StubCodeCompiler::GenerateCoroutineForkStub() {
__ Call(compiler::FieldAddress(FUNCTION_REG, Function::entry_point_offset()));

__ PopRegister(kForkedCoroutine);

__ StoreFieldToOffset(SPREG, kForkedCoroutine, Coroutine::stack_base_offset());

__ LoadCompressedFieldFromOffset(kCallerCoroutine, kForkedCoroutine, Coroutine::caller_offset());
Expand Down
2 changes: 0 additions & 2 deletions runtime/vm/compiler/stub_code_compiler_x64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

#include <setjmp.h>

#include "vm/compiler/jit/compiler.h"
#include "vm/compiler/runtime_api.h"
#include "vm/globals.h"

// For `AllocateObjectInstr::WillAllocateNewOrRemembered`
// For `GenericCheckBoundInstr::UseUnboxedRepresentation`
#include "vm/compiler/backend/il.h"
#include "vm/stub_code.h"

#define SHOULD_NOT_INCLUDE_RUNTIME

Expand Down
5 changes: 0 additions & 5 deletions runtime/vm/constants_x64.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,11 @@ struct CoroutineEntryABI {

struct CoroutineInitializeABI {
static constexpr Register kCoroutineReg = CoroutineEntryABI::kCoroutineReg;
static constexpr Register kSourceFrameSizeReg = RAX;
static constexpr Register kSourceFrameReg = RCX;
};

struct CoroutineForkABI {
static constexpr Register kCallerCoroutineReg = RSI;
static constexpr Register kForkedCoroutineReg = CoroutineEntryABI::kCoroutineReg;
static constexpr Register kStackLimitReg = RDX;
static constexpr Register kSourceFrameSizeReg = RAX;
static constexpr Register kSourceFrameReg = RCX;
};

struct CoroutineTransferABI {
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "lib/stacktrace.h"

#include "vm/compiler/runtime_api.h"
#include "vm/dart_api_impl.h"
#include "vm/dart_entry.h"
#include "vm/datastream.h"
Expand Down Expand Up @@ -688,6 +687,7 @@ NO_SANITIZE_SAFE_STACK // This function manipulates the safestack pointer.
typedef void (*ExcpHandler)(uword, uword, uword, Thread*);
ExcpHandler func =
reinterpret_cast<ExcpHandler>(StubCode::JumpToFrame().EntryPoint());

if (thread->is_unwind_in_progress()) {
thread->SetUnwindErrorInProgress(true);
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/flag_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ constexpr bool FLAG_support_il_printer = false;
D(trace_optimization, bool, false, "Print optimization details.") \
R(trace_profiler, false, bool, false, "Profiler trace") \
D(trace_profiler_verbose, bool, false, "Verbose profiler trace") \
D(trace_runtime_calls, bool, true, "Trace runtime calls.") \
D(trace_runtime_calls, bool, false, "Trace runtime calls.") \
R(trace_ssa_allocator, false, bool, false, \
"Trace register allocation over SSA.") \
P(trace_strong_mode_types, bool, false, \
Expand Down Expand Up @@ -245,7 +245,7 @@ constexpr bool FLAG_support_il_printer = false;
P(coroutines_registry_initial_size, int, 64, \
"All coroutines array initial size.") \
P(coroutines_registry_shrink_marker, int, 1024 * 1024, \
"All coroutines array initial size.") \
"Shrink coroutines registry when reached marker size.") \
P(verify_entry_points, bool, false, \
"Throw API error on invalid member access through native API. See " \
"entry_point_pragma.md") \
Expand Down
2 changes: 0 additions & 2 deletions runtime/vm/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "vm/class_finalizer.h"
#include "vm/code_observers.h"
#include "vm/compiler/jit/compiler.h"
#include "vm/dart.h"
#include "vm/dart_api_message.h"
#include "vm/dart_api_state.h"
#include "vm/dart_entry.h"
Expand Down Expand Up @@ -50,7 +49,6 @@
#include "vm/stack_frame.h"
#include "vm/stub_code.h"
#include "vm/symbols.h"
#include "vm/tagged_pointer.h"
#include "vm/tags.h"
#include "vm/thread.h"
#include "vm/thread_interrupter.h"
Expand Down
19 changes: 14 additions & 5 deletions runtime/vm/isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -1634,14 +1634,23 @@ class Isolate : public BaseIsolate, public IntrusiveDListEntry<Isolate> {
VMTagCounters vm_tag_counters_;

// We use 6 list entries for each pending service extension calls.
enum {kPendingHandlerIndex = 0, kPendingMethodNameIndex, kPendingKeysIndex,
kPendingValuesIndex, kPendingReplyPortIndex, kPendingIdIndex,
kPendingEntrySize};
enum {
kPendingHandlerIndex = 0,
kPendingMethodNameIndex,
kPendingKeysIndex,
kPendingValuesIndex,
kPendingReplyPortIndex,
kPendingIdIndex,
kPendingEntrySize
};
GrowableObjectArrayPtr pending_service_extension_calls_;

// We use 2 list entries for each registered extension handler.
enum {kRegisteredNameIndex = 0, kRegisteredHandlerIndex,
kRegisteredEntrySize};
enum {
kRegisteredNameIndex = 0,
kRegisteredHandlerIndex,
kRegisteredEntrySize
};
GrowableObjectArrayPtr registered_service_extension_handlers_;

// Used to wake the isolate when it is in the pause event loop.
Expand Down
8 changes: 4 additions & 4 deletions runtime/vm/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

#include "vm/object.h"

#include <algorithm>
#include <memory>
#include "platform/globals.h"
#include "vm/flags.h"

#if !defined(DART_TARGET_OS_WINDOWS)
#include <sys/mman.h>
Expand Down Expand Up @@ -72,7 +70,6 @@
#include "vm/stack_frame.h"
#include "vm/stub_code.h"
#include "vm/symbols.h"
#include "vm/tagged_pointer.h"
#include "vm/tags.h"
#include "vm/thread_registry.h"
#include "vm/timeline.h"
Expand Down Expand Up @@ -836,7 +833,9 @@ void Object::Init(IsolateGroup* isolate_group) {
sentinel_class_ = cls.ptr();

// Allocate and initialize the sentinel values.
{ *sentinel_ ^= Sentinel::New(); }
{
*sentinel_ ^= Sentinel::New();
}

// Allocate and initialize optimizing compiler constants.
{
Expand Down Expand Up @@ -2790,6 +2789,7 @@ ObjectPtr Object::Allocate(intptr_t cls_id,
ASSERT(thread->no_safepoint_scope_depth() == 0);
ASSERT(thread->no_callback_scope_depth() == 0);
Heap* heap = thread->heap();

uword address = heap->Allocate(thread, size, space);
if (UNLIKELY(address == 0)) {
// SuspendLongJumpScope during Dart entry ensures that if a longjmp base is
Expand Down
9 changes: 5 additions & 4 deletions runtime/vm/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef RUNTIME_VM_OBJECT_H_
#define RUNTIME_VM_OBJECT_H_

#include "platform/globals.h"
#if defined(SHOULD_NOT_INCLUDE_RUNTIME)
#error "Should not include runtime"
#endif
Expand Down Expand Up @@ -7039,9 +7038,11 @@ class Code : public Object {
explicit Comments(const Array& comments);

// Layout of entries describing comments.
enum {kPCOffsetEntry = 0, // PC offset to a comment as a Smi.
kCommentEntry, // Comment text as a String.
kNumberOfEntries};
enum {
kPCOffsetEntry = 0, // PC offset to a comment as a Smi.
kCommentEntry, // Comment text as a String.
kNumberOfEntries
};

const Array& comments_;
String& string_;
Expand Down
25 changes: 12 additions & 13 deletions runtime/vm/object_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,18 @@ static StackTracePtr CreatePreallocatedStackTrace(Zone* zone) {
return stack_trace.ptr();
}

ErrorPtr IsolateObjectStore::PreallocateObjects(const Object& out_of_memory)
{
Thread* thread = Thread::Current();
Isolate* isolate = thread->isolate();
Zone* zone = thread->zone();
ASSERT(isolate != nullptr && isolate->isolate_object_store() == this);
ASSERT(preallocated_stack_trace() == StackTrace::null());
resume_capabilities_ = GrowableObjectArray::New();
exit_listeners_ = GrowableObjectArray::New();
error_listeners_ = GrowableObjectArray::New();
coroutines_registry_ = Array::New(FLAG_coroutines_registry_initial_size);
dart_args_1_ = Array::New(1);
dart_args_2_ = Array::New(2);
ErrorPtr IsolateObjectStore::PreallocateObjects(const Object& out_of_memory) {
Thread* thread = Thread::Current();
Isolate* isolate = thread->isolate();
Zone* zone = thread->zone();
ASSERT(isolate != nullptr && isolate->isolate_object_store() == this);
ASSERT(preallocated_stack_trace() == StackTrace::null());
resume_capabilities_ = GrowableObjectArray::New();
exit_listeners_ = GrowableObjectArray::New();
error_listeners_ = GrowableObjectArray::New();
coroutines_registry_ = Array::New(FLAG_coroutines_registry_initial_size);
dart_args_1_ = Array::New(1);
dart_args_2_ = Array::New(2);

// Allocate pre-allocated unhandled exception object initialized with the
// pre-allocated OutOfMemoryError.
Expand Down
9 changes: 2 additions & 7 deletions runtime/vm/runtime_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@

#include <memory>

#include "platform/globals.h"
#include "platform/memory_sanitizer.h"
#include "platform/thread_sanitizer.h"
#include "vm/code_descriptors.h"
#include "vm/code_patcher.h"
#include "vm/compiler/api/deopt_id.h"
#include "vm/compiler/api/type_check_mode.h"
#include "vm/compiler/jit/compiler.h"
#include "vm/compiler/runtime_api.h"
#include "vm/dart_api_impl.h"
#include "vm/dart_api_state.h"
#include "vm/dart_entry.h"
Expand All @@ -28,15 +26,12 @@
#include "vm/kernel_isolate.h"
#include "vm/message.h"
#include "vm/message_handler.h"
#include "vm/native_entry.h"
#include "vm/object_store.h"
#include "vm/os_thread.h"
#include "vm/parser.h"
#include "vm/resolver.h"
#include "vm/service_isolate.h"
#include "vm/stack_frame.h"
#include "vm/symbols.h"
#include "vm/tagged_pointer.h"
#include "vm/thread.h"
#include "vm/type_testing_stubs.h"
#include "vm/zone_text_buffer.h"
Expand Down Expand Up @@ -72,7 +67,7 @@ DEFINE_FLAG(bool,
false,
"Ensure results of allocation via runtime calls are not in an "
"active TLAB.");
DEFINE_FLAG(bool, trace_deoptimization, true, "Trace deoptimization");
DEFINE_FLAG(bool, trace_deoptimization, false, "Trace deoptimization");
DEFINE_FLAG(bool,
trace_deoptimization_verbose,
false,
Expand Down Expand Up @@ -113,7 +108,7 @@ DEFINE_FLAG(bool,
"Enable specializing megamorphic calls from unoptimized code.");
DEFINE_FLAG(bool,
verbose_stack_overflow,
true,
false,
"Print additional details about stack overflow.");

DECLARE_FLAG(int, reload_every);
Expand Down
Loading

0 comments on commit 0e1392d

Please sign in to comment.