| 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 | |
| 8 | #include "platform/growable_array.h" |
| 9 | |
| 10 | #include "vm/allocation.h" |
| 11 | #include "vm/dart_api_state.h" |
| 12 | #include "vm/globals.h" |
| 13 | #include "vm/visitor.h" |
| 14 | |
| 15 | namespace dart { |
| 16 | |
| 17 | // Forward declarations. |
| 18 | class FreeList; |
| 19 | class Heap; |
| 20 | class OldPage; |
| 21 | |
| 22 | // Implements a sliding compactor. |
| 23 | class GCCompactor : public ValueObject, |
| 24 | public HandleVisitor, |
| 25 | public ObjectPointerVisitor { |
| 26 | public: |
| 27 | GCCompactor(Thread* thread, Heap* heap) |
| 28 | : HandleVisitor(thread), |
| 29 | ObjectPointerVisitor(thread->isolate_group()), |
| 30 | heap_(heap) {} |
| 31 | ~GCCompactor() { free(image_page_ranges_); } |
| 32 | |
| 33 | void Compact(OldPage* pages, FreeList* freelist, Mutex* mutex); |
| 34 | |
| 35 | private: |
| 36 | friend class CompactorTask; |
| 37 | |
| 38 | void SetupImagePageBoundaries(); |
| 39 | void ForwardStackPointers(); |
| 40 | void ForwardPointer(ObjectPtr* ptr); |
| 41 | void VisitTypedDataViewPointers(TypedDataViewPtr view, |
| 42 | ObjectPtr* first, |
| 43 | ObjectPtr* last); |
| 44 | void VisitPointers(ObjectPtr* first, ObjectPtr* last); |
| 45 | void VisitHandle(uword addr); |
| 46 | |
| 47 | Heap* heap_; |
| 48 | |
| 49 | struct { |
| 50 | uword ; |
| 51 | uword ; |
| 52 | }; |
| 53 | static int (const ImagePageRange* a, |
| 54 | const ImagePageRange* b) { |
| 55 | if (a->start < b->start) { |
| 56 | return -1; |
| 57 | } else if (a->start == b->start) { |
| 58 | return 0; |
| 59 | } else { |
| 60 | return 1; |
| 61 | } |
| 62 | } |
| 63 | intptr_t image_page_hi_ = 0; |
| 64 | ImagePageRange* image_page_ranges_ = nullptr; |
| 65 | |
| 66 | // The typed data views whose inner pointer must be updated after sliding is |
| 67 | // complete. |
| 68 | Mutex typed_data_view_mutex_; |
| 69 | MallocGrowableArray<TypedDataViewPtr> typed_data_views_; |
| 70 | }; |
| 71 | |
| 72 | } // namespace dart |
| 73 | |
| 74 | #endif // RUNTIME_VM_HEAP_COMPACTOR_H_ |
| 75 | |