Flutter Engine
The Flutter Engine
compactor.h
Go to the documentation of this file.
1// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_HEAP_COMPACTOR_H_
6#define RUNTIME_VM_HEAP_COMPACTOR_H_
7
9
10#include "vm/allocation.h"
11#include "vm/dart_api_state.h"
12#include "vm/globals.h"
13#include "vm/visitor.h"
14
15namespace dart {
16
17// Forward declarations.
18class FreeList;
19class Heap;
20class Page;
21
22// Implements a sliding compactor.
23class GCCompactor : public ValueObject,
24 public HandleVisitor,
26 public:
30 heap_(heap) {}
31 ~GCCompactor() { free(image_page_ranges_); }
32
33 void Compact(Page* pages, FreeList* freelist, Mutex* mutex);
34
35 private:
36 friend class CompactorTask;
37
38 void SetupImagePageBoundaries();
39 void SetupLargePages();
40 void ForwardLargePages();
41 void ForwardStackPointers();
42 void ForwardPointer(ObjectPtr* ptr);
43 void ForwardCompressedPointer(uword heap_base, CompressedObjectPtr* ptr);
44 void VisitTypedDataViewPointers(TypedDataViewPtr view,
46 CompressedObjectPtr* last) override;
47 void VisitPointers(ObjectPtr* first, ObjectPtr* last) override;
48#if defined(DART_COMPRESSED_POINTERS)
49 void VisitCompressedPointers(uword heap_base,
51 CompressedObjectPtr* last) override;
52#endif
53 bool CanVisitSuspendStatePointers(SuspendStatePtr suspend_state) override;
54 void VisitHandle(uword addr) override;
55
56 Heap* heap_;
57
58 struct ImagePageRange {
60 uword end;
61 };
62 static int CompareImagePageRanges(const ImagePageRange* a,
63 const ImagePageRange* b) {
64 if (a->start < b->start) {
65 return -1;
66 } else if (a->start == b->start) {
67 return 0;
68 } else {
69 return 1;
70 }
71 }
72 intptr_t image_page_hi_ = 0;
73 ImagePageRange* image_page_ranges_ = nullptr;
74
75 Mutex large_pages_mutex_;
76 Page* large_pages_ = nullptr;
77 Page* fixed_pages_ = nullptr;
78
79 // The typed data views whose inner pointer must be updated after sliding is
80 // complete.
81 Mutex typed_data_view_mutex_;
82 MallocGrowableArray<TypedDataViewPtr> typed_data_views_;
83
84 // SuspendState objects with copied frame must be updated after sliding is
85 // complete.
86 bool can_visit_stack_frames_ = false;
87 Mutex postponed_suspend_states_mutex_;
88 MallocGrowableArray<SuspendStatePtr> postponed_suspend_states_;
89};
90
91} // namespace dart
92
93#endif // RUNTIME_VM_HEAP_COMPACTOR_H_
void Compact(Page *pages, FreeList *freelist, Mutex *mutex)
Definition: compactor.cc:184
GCCompactor(Thread *thread, Heap *heap)
Definition: compactor.h:27
Thread * thread() const
IsolateGroup * isolate_group() const
Definition: visitor.h:25
void VisitCompressedPointers(uword heap_base, CompressedObjectPtr *first, CompressedObjectPtr *last)
Definition: visitor.h:43
static bool b
struct MyStruct a[10]
glong glong end
Definition: dart_vm.cc:33
uintptr_t uword
Definition: globals.h:501