blob: 164c21404bedb7004b19a25fba7791e5cdda479f [file] [log] [blame]
// 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 "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 {
GCCompactor(Thread* thread, Heap* heap)
: HandleVisitor(thread),
heap_(heap) {}
~GCCompactor() { free(image_page_ranges_); }
void Compact(OldPage* pages, FreeList* freelist, Mutex* mutex);
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);
void VisitPointers(ObjectPtr* first, ObjectPtr* last);
void VisitCompressedPointers(uword heap_base,
CompressedObjectPtr* first,
CompressedObjectPtr* last);
void VisitHandle(uword addr);
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_;
} // namespace dart