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>
86 lines
2.6 KiB
C++
86 lines
2.6 KiB
C++
// 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.
|
|
|
|
#ifndef RUNTIME_VM_HEAP_COMPACTOR_H_
|
|
#define RUNTIME_VM_HEAP_COMPACTOR_H_
|
|
|
|
#include "platform/growable_array.h"
|
|
|
|
#include "vm/allocation.h"
|
|
#include "vm/dart_api_state.h"
|
|
#include "vm/globals.h"
|
|
#include "vm/visitor.h"
|
|
|
|
namespace dart {
|
|
|
|
// Forward declarations.
|
|
class FreeList;
|
|
class Heap;
|
|
class OldPage;
|
|
|
|
// Implements a sliding compactor.
|
|
class GCCompactor : public ValueObject,
|
|
public HandleVisitor,
|
|
public ObjectPointerVisitor {
|
|
public:
|
|
GCCompactor(Thread* thread, Heap* heap)
|
|
: HandleVisitor(thread),
|
|
ObjectPointerVisitor(thread->isolate_group()),
|
|
heap_(heap) {}
|
|
~GCCompactor() { free(image_page_ranges_); }
|
|
|
|
void Compact(OldPage* pages, FreeList* freelist, Mutex* mutex);
|
|
|
|
private:
|
|
friend class CompactorTask;
|
|
|
|
void SetupImagePageBoundaries();
|
|
void ForwardStackPointers();
|
|
void ForwardPointer(ObjectPtr* ptr);
|
|
void ForwardCompressedPointer(uword heap_base, CompressedObjectPtr* ptr);
|
|
void VisitTypedDataViewPointers(TypedDataViewPtr view,
|
|
CompressedObjectPtr* first,
|
|
CompressedObjectPtr* last) override;
|
|
void VisitPointers(ObjectPtr* first, ObjectPtr* last) override;
|
|
void VisitCompressedPointers(uword heap_base,
|
|
CompressedObjectPtr* first,
|
|
CompressedObjectPtr* last) override;
|
|
bool CanVisitSuspendStatePointers(SuspendStatePtr suspend_state) override;
|
|
void VisitHandle(uword addr) override;
|
|
|
|
Heap* heap_;
|
|
|
|
struct ImagePageRange {
|
|
uword start;
|
|
uword end;
|
|
};
|
|
static int CompareImagePageRanges(const ImagePageRange* a,
|
|
const ImagePageRange* b) {
|
|
if (a->start < b->start) {
|
|
return -1;
|
|
} else if (a->start == b->start) {
|
|
return 0;
|
|
} else {
|
|
return 1;
|
|
}
|
|
}
|
|
intptr_t image_page_hi_ = 0;
|
|
ImagePageRange* image_page_ranges_ = nullptr;
|
|
|
|
// The typed data views whose inner pointer must be updated after sliding is
|
|
// complete.
|
|
Mutex typed_data_view_mutex_;
|
|
MallocGrowableArray<TypedDataViewPtr> typed_data_views_;
|
|
|
|
// SuspendState objects with copied frame must be updated after sliding is
|
|
// complete.
|
|
bool can_visit_stack_frames_ = false;
|
|
Mutex postponed_suspend_states_mutex_;
|
|
MallocGrowableArray<SuspendStatePtr> postponed_suspend_states_;
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_VM_HEAP_COMPACTOR_H_
|