OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015, the Fletch 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.md file. | |
4 | |
5 #ifndef SRC_VM_IMMUTABLE_HEAP_H_ | |
6 #define SRC_VM_IMMUTABLE_HEAP_H_ | |
7 | |
8 #include "src/shared/globals.h" | |
9 #include "src/vm/heap.h" | |
10 | |
11 namespace fletch { | |
12 | |
13 class ImmutableHeap { | |
14 public: | |
15 ImmutableHeap(); | |
16 ~ImmutableHeap(); | |
17 | |
18 // Will return a [Heap] which will have an allocation budget which is | |
19 // `known_live_memory / number_of_hw_threads_`. This is an approximation of a | |
20 // 2x growth strategy. | |
21 // | |
22 // TODO(kustermann): instead of `number_of_hw_threads_` we could make this | |
23 // better by keeping track of the current number of used scheduler threads. | |
24 Heap* AcquirePart(); | |
25 | |
26 // Will return `true` if the caller should trigger an immutable GC. | |
27 // | |
28 // It is assumed that this function is only called on allocation failures. | |
29 bool ReleasePart(Heap* part); | |
30 | |
31 // Merges all parts which have been acquired and subsequently released into | |
32 // the accumulated immutable heap. | |
33 // | |
34 // This function assumes that there are no parts outstanding. | |
35 void MergeParts(); | |
36 | |
37 // This method can only be called if | |
38 // * all acquired parts were released again | |
39 // * all cached parts were merged via [MergeParts] | |
40 void IterateProgramPointers(PointerVisitor* visitor); | |
41 | |
42 // This method can only be called if | |
43 // * all acquired parts were released again | |
44 // * all cached parts were merged via [MergeParts] | |
45 Heap* heap() { | |
46 ASSERT(outstanding_parts_ == 0 && unmerged_parts_ == NULL); | |
47 return &heap_; | |
48 } | |
49 | |
50 private: | |
51 // TODO(kustermann): Instead of having a linked list which requires heap | |
52 // allocations we should make a simple version of `std::vector` and use it | |
53 // here. | |
54 // [The number of parts is almost always fixed (i.e. the number of threads)] | |
55 class HeapPart { | |
56 public: | |
57 HeapPart(HeapPart* next_part) : heap_part(NULL), next(next_part) {} | |
58 | |
59 Heap* heap_part; | |
ricow1
2015/08/05 13:18:18
why is this called heap_part and not just heap (ju
kustermann
2015/08/05 13:20:53
Well, because it is only part of the [ImmutableHea
| |
60 HeapPart* next; | |
61 }; | |
62 | |
63 bool HasUnmergedParts() { return unmerged_parts_ != NULL; } | |
64 void AddUnmergedPart(Heap* heap); | |
65 Heap* RemoveUnmergedPart(); | |
66 | |
67 int number_of_hw_threads_; | |
68 | |
69 Mutex* heap_mutex_; | |
70 Heap heap_; | |
71 int outstanding_parts_; | |
72 HeapPart* unmerged_parts_; | |
73 int ticks_; | |
74 }; | |
75 | |
76 } // namespace fletch | |
77 | |
78 | |
79 #endif // SRC_VM_IMMUTABLE_HEAP_H_ | |
OLD | NEW |