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

Side by Side Diff: src/vm/immutable_heap.cc

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 unified diff | Download patch
OLDNEW
(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 #include "src/vm/immutable_heap.h"
6 #include "src/vm/object_memory.h"
7
8 namespace fletch {
9
10 ImmutableHeap::ImmutableHeap()
11 : number_of_hw_threads_(Platform::GetNumberOfHardwareThreads()),
12 heap_mutex_(Platform::CreateMutex()),
13 heap_(new Space(), reinterpret_cast<WeakPointer*>(NULL)),
14 outstanding_parts_(0),
15 unmerged_parts_(),
16 ticks_(0) {
17 }
18
19 ImmutableHeap::~ImmutableHeap() {
20 delete heap_mutex_;
21
22 while (HasUnmergedParts()) {
23 Heap* heap = RemoveUnmergedPart();
24 delete heap;
25 }
26 }
27
28 void ImmutableHeap::AddUnmergedPart(Heap* heap) {
29 unmerged_parts_ = new HeapPart(unmerged_parts_);
30 unmerged_parts_->heap_part = heap;
31 }
32
33 Heap* ImmutableHeap::RemoveUnmergedPart() {
34 HeapPart* part = unmerged_parts_;
35 if (part == NULL) return NULL;
36
37 Heap* heap = part->heap_part;
38 unmerged_parts_ = part->next;
39 delete part;
40 return heap;
41 }
42
43 void ImmutableHeap::MergeParts() {
44 ScopedLock locker(heap_mutex_);
45
46 ASSERT(outstanding_parts_ == 0);
47 while (HasUnmergedParts()) {
48 Heap* heap_part = RemoveUnmergedPart();
49 heap_.MergeInOtherHeap(heap_part);
50 delete heap_part;
51 }
52
53 ticks_ = 0;
54 }
55
56 void ImmutableHeap::IterateProgramPointers(PointerVisitor* visitor) {
57 ASSERT(outstanding_parts_ == 0 && unmerged_parts_ == NULL);
58
59 HeapObjectPointerVisitor heap_pointer_visitor(visitor);
60 heap_.IterateObjects(&heap_pointer_visitor);
61 }
62
63 Heap* ImmutableHeap::AcquirePart() {
64 ScopedLock locker(heap_mutex_);
65
66 // Calculate new allocation budget we want to give out.
67 Space* merged_space = heap_.space();
68 int size = 0;
69 if (merged_space != NULL && !merged_space->is_empty()) {
70 // We allow each thread to get the amount of live memory per
71 // thread (i.e. a "2x of live memory" heap size strategy).
72 size = merged_space->Used() / number_of_hw_threads_;
73 }
74 int budget = Utils::Maximum(size, Space::kDefaultChunkSize);
75
76 Heap* part;
77 if (HasUnmergedParts()) {
78 part = RemoveUnmergedPart();
79 part->space()->SetAllocationBudget(budget);
80 } else {
81 part = new Heap(NULL, budget);
82 }
83
84 outstanding_parts_++;
85 return part;
86 }
87
88 bool ImmutableHeap::ReleasePart(Heap* part) {
89 ScopedLock locker(heap_mutex_);
90 ASSERT(outstanding_parts_ > 0);
91 outstanding_parts_--;
92
93 part->Flush();
94 part->AdjustAllocationBudget();
95 AddUnmergedPart(part);
96
97 return ticks_++ == number_of_hw_threads_;
98 }
99
100 } // namespace fletch
OLDNEW
« src/vm/immutable_heap.h ('K') | « src/vm/immutable_heap.h ('k') | src/vm/object_memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698