bf4bb95308
The new implementation moves away from desugaring of async functions on kernel AST, state machine generated in the flow graph and capturing all local variables in the context. Instead, async/await is implemented using a few stubs (InitSuspendableFunction, Suspend, Resume, Return and AsyncExceptionHandler). The stubs are implemented in a platform-independent way using (macro-)assembler helpers. When suspending a function, its frame is copied into a SuspendState object, and when resuming a function it is copied back onto the stack. No extra code is generated for accessing local variables. Callback closures are created lazily on the first await. Design doc: go/compact-async-await. Part 1 (kernel): https://dart-review.googlesource.com/c/sdk/+/241842 TEST=ci Issue: https://github.com/dart-lang/sdk/issues/48378 Change-Id: Ibad757035b7cc438ebdff80b460728b1d3eff1f5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242000 Reviewed-by: Ryan Macnak <rmacnak@google.com> Reviewed-by: Slava Egorov <vegorov@google.com>
121 lines
3.6 KiB
C++
121 lines
3.6 KiB
C++
// Copyright (c) 2011, 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.
|
|
|
|
#ifndef RUNTIME_VM_VISITOR_H_
|
|
#define RUNTIME_VM_VISITOR_H_
|
|
|
|
#include "vm/allocation.h"
|
|
#include "vm/class_table.h"
|
|
#include "vm/globals.h"
|
|
#include "vm/growable_array.h"
|
|
|
|
namespace dart {
|
|
|
|
// Forward declarations.
|
|
class Isolate;
|
|
class IsolateGroup;
|
|
|
|
// An object pointer visitor interface.
|
|
class ObjectPointerVisitor {
|
|
public:
|
|
explicit ObjectPointerVisitor(IsolateGroup* isolate_group);
|
|
virtual ~ObjectPointerVisitor() {}
|
|
|
|
IsolateGroup* isolate_group() const { return isolate_group_; }
|
|
|
|
// Visit pointers inside the given typed data [view].
|
|
//
|
|
// Range of pointers to visit 'first' <= pointer <= 'last'.
|
|
virtual void VisitTypedDataViewPointers(TypedDataViewPtr view,
|
|
CompressedObjectPtr* first,
|
|
CompressedObjectPtr* last) {
|
|
VisitCompressedPointers(view->heap_base(), first, last);
|
|
}
|
|
|
|
// Range of pointers to visit 'first' <= pointer <= 'last'.
|
|
virtual void VisitPointers(ObjectPtr* first, ObjectPtr* last) = 0;
|
|
virtual void VisitCompressedPointers(uword heap_base,
|
|
CompressedObjectPtr* first,
|
|
CompressedObjectPtr* last) = 0;
|
|
|
|
// len argument is the number of pointers to visit starting from 'p'.
|
|
void VisitPointers(ObjectPtr* p, intptr_t len) {
|
|
VisitPointers(p, (p + len - 1));
|
|
}
|
|
|
|
void VisitPointer(ObjectPtr* p) { VisitPointers(p, p); }
|
|
|
|
const char* gc_root_type() const { return gc_root_type_; }
|
|
void set_gc_root_type(const char* gc_root_type) {
|
|
gc_root_type_ = gc_root_type;
|
|
}
|
|
|
|
void clear_gc_root_type() { gc_root_type_ = "unknown"; }
|
|
|
|
virtual bool visit_weak_persistent_handles() const { return false; }
|
|
|
|
// When visiting objects to build retaining paths, trace field values
|
|
// through fields.
|
|
// Otherwise trace field values through isolate's field_table.
|
|
virtual bool trace_values_through_fields() const { return false; }
|
|
|
|
const SharedClassTable* shared_class_table() const {
|
|
return shared_class_table_;
|
|
}
|
|
|
|
// Returns true if pointers of the given SuspendState object can be visited.
|
|
// Compactor overrides this method in order to postpone visiting SuspendState
|
|
// objects with evacuated frames, as visiting them may touch other Dart
|
|
// objects (array of InstructionsTables) which have inconsistent state
|
|
// until compaction is finished.
|
|
virtual bool CanVisitSuspendStatePointers(SuspendStatePtr suspend_state) {
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
IsolateGroup* isolate_group_;
|
|
const char* gc_root_type_;
|
|
SharedClassTable* shared_class_table_;
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectPointerVisitor);
|
|
};
|
|
|
|
// An object visitor interface.
|
|
class ObjectVisitor {
|
|
public:
|
|
ObjectVisitor() {}
|
|
|
|
virtual ~ObjectVisitor() {}
|
|
|
|
// Invoked for each object.
|
|
virtual void VisitObject(ObjectPtr obj) = 0;
|
|
|
|
private:
|
|
DISALLOW_COPY_AND_ASSIGN(ObjectVisitor);
|
|
};
|
|
|
|
// An object finder visitor interface.
|
|
class FindObjectVisitor {
|
|
public:
|
|
FindObjectVisitor() {}
|
|
virtual ~FindObjectVisitor() {}
|
|
|
|
// Allow to specify a address filter.
|
|
virtual uword filter_addr() const { return 0; }
|
|
bool VisitRange(uword begin_addr, uword end_addr) const {
|
|
uword addr = filter_addr();
|
|
return (addr == 0) || ((begin_addr <= addr) && (addr < end_addr));
|
|
}
|
|
|
|
// Check if object matches find condition.
|
|
virtual bool FindObject(ObjectPtr obj) const = 0;
|
|
|
|
private:
|
|
DISALLOW_COPY_AND_ASSIGN(FindObjectVisitor);
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_VM_VISITOR_H_
|