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

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: 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 cached_parts_(),
16 ticks_(0) {
17 }
18
19 ImmutableHeap::~ImmutableHeap() {
20 delete heap_mutex_;
21
22 while (HasCachedParts()) {
23 Heap* heap = RemoveCachedPart();
24 delete heap;
25 }
26 }
27
28 void ImmutableHeap::AddCachedPart(Heap* heap) {
29 CachedHeapPart* cached_part = new CachedHeapPart();
Mads Ager (google) 2015/08/05 10:19:02 This could be a one-liner? cached_parts_ = new Ca
kustermann 2015/08/05 11:11:46 Made it a two liner, see other reason why I don't
30 cached_part->heap_part_ = heap;
31 cached_part->next_ = cached_parts_;
32 cached_parts_ = cached_part;
33 }
34
35 Heap* ImmutableHeap::RemoveCachedPart() {
36 CachedHeapPart* part = cached_parts_;
37 if (part == NULL) return NULL;
38
39 Heap* heap = part->heap_part_;
40 cached_parts_ = part->next_;
41 delete part;
42 return heap;
43 }
44
45 void ImmutableHeap::MergeParts() {
46 ScopedLock locker(heap_mutex_);
47
48 ASSERT(outstanding_parts_ == 0);
49 while (HasCachedParts()) {
50 Heap* heap_part = RemoveCachedPart();
51 heap_.MergeInOtherHeap(heap_part);
52 delete heap_part;
53 }
54
55 ticks_ = 0;
56 }
57
58 void ImmutableHeap::IterateProgramPointers(PointerVisitor* visitor) {
59 ASSERT(outstanding_parts_ == 0 && cached_parts_ == NULL);
60
61 HeapObjectPointerVisitor heap_pointer_visitor(visitor);
62 heap_.IterateObjects(&heap_pointer_visitor);
63 }
64
65 Heap* ImmutableHeap::AcquirePart() {
66 ScopedLock locker(heap_mutex_);
67
68 // Calculate new allocation budget we want to give out.
69 Space* merged_space = heap_.space();
70 int size = 0;
71 if (merged_space != NULL && !merged_space->is_empty()) {
72 // We allow each thread to get the amount of live memory per
73 // thread (i.e. a "2x of live memory" heap size strategy).
74 size = merged_space->Used() / number_of_hw_threads_;
75 }
76 int budget = Utils::Maximum(size, Space::kDefaultChunkSize);
77
78 Heap* part;
79 if (HasCachedParts()) {
80 part = RemoveCachedPart();
81 part->space()->SetAllocationBudget(budget);
82 } else {
83 part = new Heap(NULL, budget);
84 }
85
86 outstanding_parts_++;
87 return part;
88 }
89
90 bool ImmutableHeap::ReleasePart(Heap* part) {
91 ScopedLock locker(heap_mutex_);
92 ASSERT(outstanding_parts_ > 0);
93 outstanding_parts_--;
94
95 part->Flush();
96 part->AdjustAllocationBudget();
97 AddCachedPart(part);
98
99 return ticks_++ == number_of_hw_threads_;
100 }
101
102 } // namespace fletch
OLDNEW
« src/vm/immutable_heap.h ('K') | « src/vm/immutable_heap.h ('k') | src/vm/vm.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698