Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: src/vm/immutable_heap.h

Issue 1263043007: Add ImmutableHeap class consisting of parts (Closed) Base URL: git@github.com:dart-lang/fletch.git@master
Patch Set: Addressed comments, merged other CL about allocation budget in space Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/vm/heap.h ('k') | src/vm/immutable_heap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/vm/immutable_heap.h
diff --git a/src/vm/immutable_heap.h b/src/vm/immutable_heap.h
new file mode 100644
index 0000000000000000000000000000000000000000..8bf5399909dcc1e2d471b97f035a9229e7ee51b9
--- /dev/null
+++ b/src/vm/immutable_heap.h
@@ -0,0 +1,79 @@
+// Copyright (c) 2015, the Fletch 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.md file.
+
+#ifndef SRC_VM_IMMUTABLE_HEAP_H_
+#define SRC_VM_IMMUTABLE_HEAP_H_
+
+#include "src/shared/globals.h"
+#include "src/vm/heap.h"
+
+namespace fletch {
+
+class ImmutableHeap {
+ public:
+ ImmutableHeap();
+ ~ImmutableHeap();
+
+ // Will return a [Heap] which will have an allocation budget which is
+ // `known_live_memory / number_of_hw_threads_`. This is an approximation of a
+ // 2x growth strategy.
+ //
+ // TODO(kustermann): instead of `number_of_hw_threads_` we could make this
+ // better by keeping track of the current number of used scheduler threads.
+ Heap* AcquirePart();
+
+ // Will return `true` if the caller should trigger an immutable GC.
+ //
+ // It is assumed that this function is only called on allocation failures.
+ bool ReleasePart(Heap* part);
+
+ // Merges all parts which have been acquired and subsequently released into
+ // the accumulated immutable heap.
+ //
+ // This function assumes that there are no parts outstanding.
+ void MergeParts();
+
+ // This method can only be called if
+ // * all acquired parts were released again
+ // * all cached parts were merged via [MergeParts]
+ void IterateProgramPointers(PointerVisitor* visitor);
+
+ // This method can only be called if
+ // * all acquired parts were released again
+ // * all cached parts were merged via [MergeParts]
+ Heap* heap() {
+ ASSERT(outstanding_parts_ == 0 && unmerged_parts_ == NULL);
+ return &heap_;
+ }
+
+ private:
+ // TODO(kustermann): Instead of having a linked list which requires heap
+ // allocations we should make a simple version of `std::vector` and use it
+ // here.
+ // [The number of parts is almost always fixed (i.e. the number of threads)]
+ class HeapPart {
+ public:
+ HeapPart(HeapPart* next_part) : heap_part(NULL), next(next_part) {}
+
+ 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
+ HeapPart* next;
+ };
+
+ bool HasUnmergedParts() { return unmerged_parts_ != NULL; }
+ void AddUnmergedPart(Heap* heap);
+ Heap* RemoveUnmergedPart();
+
+ int number_of_hw_threads_;
+
+ Mutex* heap_mutex_;
+ Heap heap_;
+ int outstanding_parts_;
+ HeapPart* unmerged_parts_;
+ int ticks_;
+};
+
+} // namespace fletch
+
+
+#endif // SRC_VM_IMMUTABLE_HEAP_H_
« no previous file with comments | « src/vm/heap.h ('k') | src/vm/immutable_heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698