Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbashir committed Nov 21, 2024
1 parent eb43bf4 commit 268daed
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 130 deletions.
2 changes: 1 addition & 1 deletion runtime/vm/compiler/backend/il.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8596,7 +8596,7 @@ LocationSummary* CoroutineTransferInstr::MakeLocationSummary(Zone* zone,
0, Location::RegisterLocation(CoroutineTransferABI::kFromCoroutineReg));
locs->set_in(
1, Location::RegisterLocation(CoroutineTransferABI::kToCoroutineReg));
locs->set_in(
locs->set_temp(
0, Location::RegisterLocation(CoroutineTransferABI::kToStackLimitReg));
return locs;
}
Expand Down
60 changes: 30 additions & 30 deletions runtime/vm/compiler/runtime_offsets_extracted.h

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions runtime/vm/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
#endif

namespace dart {

struct CoroutineState {
uword nsp;
uword sp;
uword attributes;
};

class CoroutineLink {
public:
DART_FORCE_INLINE
Expand All @@ -42,16 +35,6 @@ class CoroutineLink {
DART_FORCE_INLINE
void SetValue(CoroutinePtr value) {
value_ = value;
native_sp_ = 0;
sp_ = 0;
attributes_ = 0;
}

DART_FORCE_INLINE
void Synchronize(uword native_sp, uword sp, uword attributes) {
attributes_ = attributes;
native_sp_ = native_sp;
sp_ = sp;
}

DART_FORCE_INLINE
Expand Down Expand Up @@ -83,9 +66,6 @@ class CoroutineLink {
CoroutineLink* next_;
CoroutineLink* previous_;
CoroutinePtr value_;
uword native_sp_;
uword sp_;
uword attributes_;
};

} // namespace dart
Expand Down
12 changes: 0 additions & 12 deletions runtime/vm/coroutine_test.cc

This file was deleted.

6 changes: 3 additions & 3 deletions runtime/vm/flag_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ constexpr bool FLAG_support_il_printer = false;
"Check validity of token positions while compiling flow graphs") \
P(collect_dynamic_function_names, bool, true, \
"Collects all dynamic function names to identify unique targets") \
P(compactor_tasks, int, 0, \
P(compactor_tasks, int, 2, \
"The number of tasks to use for parallel compaction.") \
P(concurrent_mark, bool, true, "Concurrent mark for old generation.") \
P(concurrent_sweep, bool, true, "Concurrent sweep for old generation.") \
P(concurrent_mark, bool, false, "Concurrent mark for old generation.") \
P(concurrent_sweep, bool, false, "Concurrent sweep for old generation.") \
C(deoptimize_alot, false, false, bool, false, \
"Deoptimizes we are about to return to Dart code from native entries.") \
C(deoptimize_every, 0, 0, int, 0, \
Expand Down
31 changes: 2 additions & 29 deletions runtime/vm/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1777,8 +1777,8 @@ Isolate::Isolate(IsolateGroup* isolate_group,
// how the vm_tag (kEmbedderTagId) can be set, these tags need to
// move to the OSThread structure.
set_user_tag(UserTags::kDefaultUserTag);
active_coroutines()->Initialize();
finished_coroutines()->Initialize();
// active_coroutines()->Initialize();
// finished_coroutines()->Initialize();
}

#undef REUSABLE_HANDLE_SCOPE_INIT
Expand Down Expand Up @@ -2783,16 +2783,6 @@ void Isolate::VisitStackPointers(ObjectPointerVisitor* visitor,
if (mutator_thread_ != nullptr) {
if (mutator_thread_->has_coroutine()) {
mutator_thread_->VisitObjectPointersCoroutine(this, visitor, validate_frames);
// if (coroutines_ != nullptr) {
// for (uword index = 0; index < coroutines_count_; index++) {
// auto item = coroutines_[index];
// UntaggedCoroutine::VisitStack(*item, visitor);
// delete coroutines_[index];
// }
// delete[] coroutines_;
// coroutines_ = nullptr;
// coroutines_count_ = 0;
// }
return;
}
mutator_thread_->VisitObjectPointers(visitor, validate_frames);
Expand Down Expand Up @@ -2939,21 +2929,6 @@ void IsolateGroup::VisitObjectPointers(ObjectPointerVisitor* visitor,
ValidationPolicy validate_frames) {
VisitSharedPointers(visitor);
for (Isolate* isolate : isolates_) {
if (isolate->coroutines_registry() != Object::null()) {
auto count = Smi::Value(isolate->coroutines_registry().untag()->length());
isolate->coroutines_count_ = count;
isolate->coroutines_ = new CoroutineState*[count];
auto elements = isolate->coroutines_registry().untag()->data().untag();
for (auto index = 0; index < count; index ++) {
isolate->coroutines_[index] = new CoroutineState();
auto item = elements->element(index);
if (item.IsHeapObject() && item.IsWellFormed() && item.IsCoroutine()) {
isolate->coroutines_[index]->nsp = Coroutine::RawCast(item).untag()->native_stack_base();
isolate->coroutines_[index]->sp = Coroutine::RawCast(item).untag()->stack_base();
isolate->coroutines_[index]->attributes = Coroutine::RawCast(item).untag()->attributes();
}
}
}
isolate->VisitObjectPointers(visitor, validate_frames);
}
VisitStackPointers(visitor, validate_frames);
Expand Down Expand Up @@ -3023,8 +2998,6 @@ void IsolateGroup::VisitStackPointers(ObjectPointerVisitor* visitor,
}

visitor->clear_gc_root_type();

// visitor->VisitPointer(reinterpret_cast<ObjectPtr*>(&disabled_coroutine_));
}

void IsolateGroup::VisitObjectIdRingPointers(ObjectPointerVisitor* visitor) {
Expand Down
3 changes: 0 additions & 3 deletions runtime/vm/isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -1579,9 +1579,6 @@ class Isolate : public BaseIsolate, public IntrusiveDListEntry<Isolate> {
bool is_system_isolate_ = false;
std::unique_ptr<IsolateObjectStore> isolate_object_store_;
GrowableObjectArrayPtr coroutines_registry_;

CoroutineState** coroutines_;
uword coroutines_count_;
// End accessed from generated code.

IsolateGroup* const isolate_group_;
Expand Down
57 changes: 29 additions & 28 deletions runtime/vm/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26663,7 +26663,7 @@ CoroutinePtr Coroutine::New(uintptr_t size, FunctionPtr trampoline) {
GcSafepointOperationScope safepoint(Thread::Current());
auto isolate = Isolate::Current();
// auto finished = isolate->finished_coroutines();
auto active = isolate->active_coroutines();
// auto active = isolate->active_coroutines();
auto& registry = GrowableObjectArray::Handle(isolate->coroutines_registry());

auto page_size = VirtualMemory::PageSize();
Expand Down Expand Up @@ -26719,29 +26719,29 @@ CoroutinePtr Coroutine::New(uintptr_t size, FunctionPtr trampoline) {
coroutine.untag()->stack_base_ = stack_base;
coroutine.untag()->stack_limit_ = stack_limit;
coroutine.untag()->overflow_stack_limit_ = stack_limit + CalculateHeadroom(stack_base - stack_limit);
coroutine.untag()->to_state_.Initialize();
coroutine.untag()->to_state_.SetValue(coroutine.ptr());
// coroutine.untag()->to_state_.Initialize();
// coroutine.untag()->to_state_.SetValue(coroutine.ptr());
coroutine.untag()->set_trampoline(trampoline);

coroutine.untag()->set_index(registry.Length());
registry.Add(coroutine);

CoroutineLink::AddHead(active, coroutine.to_state());
//CoroutineLink::AddHead(active, coroutine.to_state());

return coroutine.ptr();
}

void Coroutine::recycle(Zone* zone) const {
change_state(CoroutineAttributes::created | CoroutineAttributes::running | CoroutineAttributes::suspended, CoroutineAttributes::finished);
auto finished = Isolate::Current()->finished_coroutines();
//auto finished = Isolate::Current()->finished_coroutines();
untag()->stack_base_ = untag()->stack_root_;
untag()->native_stack_base_ = (uword) nullptr;
CoroutineLink::StealHead(finished, to_state());
//CoroutineLink::StealHead(finished, to_state());
}

void Coroutine::dispose(Thread* thread, Zone* zone, bool remove_from_registry) const {
change_state(CoroutineAttributes::created | CoroutineAttributes::running | CoroutineAttributes::suspended, CoroutineAttributes::disposed);
CoroutineLink::Remove(to_state());
// CoroutineLink::Remove(to_state());
untag()->set_name(String::null());
untag()->set_entry(Closure::null());
untag()->set_trampoline(Function::null());
Expand All @@ -26762,29 +26762,30 @@ void Coroutine::dispose(Thread* thread, Zone* zone, bool remove_from_registry) c
untag()->stack_base_ = (uword) nullptr;
untag()->stack_limit_ = (uword) nullptr;
untag()->overflow_stack_limit_ = (uword) nullptr;
untag()->set_index(-1);

if (!remove_from_registry) {
untag()->set_index(-1);
return;
}
// if (!remove_from_registry) {
// untag()->set_index(-1);
// return;
// }

auto& coroutines = GrowableObjectArray::Handle(zone, thread->isolate()->coroutines_registry());
coroutines.RemoveAt(index());
untag()->set_index(-1);
// auto& coroutines = GrowableObjectArray::Handle(zone, thread->isolate()->coroutines_registry());
// coroutines.RemoveAt(index());
// untag()->set_index(-1);

if (coroutines.Capacity() < FLAG_coroutines_registry_shrink_capacity) {
return;
}
// if (coroutines.Capacity() < FLAG_coroutines_registry_shrink_capacity) {
// return;
// }

auto& new_coroutines = GrowableObjectArray::Handle(GrowableObjectArray::New(std::max(coroutines.Length(), (intptr_t)FLAG_coroutines_registry_initial_capacity)));
auto& new_coroutine = Coroutine::Handle();
for (intptr_t index = 0; index < coroutines.Length(); index++) {
new_coroutine ^= coroutines.At(index);
new_coroutine.set_index(new_coroutines.Length());
new_coroutines.Add(new_coroutine);
}
Array::Handle(coroutines.data()).Truncate(0);
thread->isolate()->set_coroutines_registry(new_coroutines.ptr());
// auto& new_coroutines = GrowableObjectArray::Handle(GrowableObjectArray::New(std::max(coroutines.Length(), (intptr_t)FLAG_coroutines_registry_initial_capacity)));
// auto& new_coroutine = Coroutine::Handle();
// for (intptr_t index = 0; index < coroutines.Length(); index++) {
// new_coroutine ^= coroutines.At(index);
// new_coroutine.set_index(new_coroutines.Length());
// new_coroutines.Add(new_coroutine);
// }
// Array::Handle(coroutines.data()).Truncate(0);
// thread->isolate()->set_coroutines_registry(new_coroutines.ptr());
}

const char* Coroutine::ToCString() const {
Expand Down Expand Up @@ -26868,8 +26869,8 @@ void Coroutine::HandleRootExit(Thread* thread, Zone* zone) {

void Coroutine::HandleForkedEnter(Thread* thread, Zone* zone) {
GcSafepointOperationScope safepoint(Thread::Current());
auto active = Isolate::Current()->active_coroutines();
CoroutineLink::StealHead(active, to_state());
// auto active = Isolate::Current()->active_coroutines();
//CoroutineLink::StealHead(active, to_state());
thread->EnterCoroutine(ptr());
}

Expand Down
1 change: 0 additions & 1 deletion runtime/vm/raw_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,6 @@ intptr_t UntaggedSuspendState::VisitSuspendStatePointers(
}

intptr_t UntaggedCoroutine::VisitCoroutinePointers(CoroutinePtr raw_obj, ObjectPointerVisitor* visitor) {
if (!visitor->CanVisitCoroutinePointers(raw_obj)) return Coroutine::InstanceSize();
visitor->VisitCompressedPointers(raw_obj->heap_base(), raw_obj->untag()->from(), raw_obj->untag()->to());
return Coroutine::InstanceSize();
}
Expand Down
1 change: 0 additions & 1 deletion runtime/vm/vm_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ vm_sources_tests = [
"code_patcher_ia32_test.cc",
"code_patcher_riscv_test.cc",
"code_patcher_x64_test.cc",
"coroutine_test.cc",
"compiler_test.cc",
"cpu_test.cc",
"cpuinfo_test.cc",
Expand Down
3 changes: 1 addition & 2 deletions test-sdk-deug.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash
export CPATH=""
./tools/build.py -m debug -a x64 runtime dart_precompiled_runtime ddc dartanalyzer analysis_server create_common_sdk create_platform_sdk
out/DebugX64/run_vm_tests Coroutine_test
./tools/build.py -m debug -a x64 runtime dart_precompiled_runtime ddc dartanalyzer analysis_server create_common_sdk create_platform_sdk

0 comments on commit 268daed

Please sign in to comment.