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

Side by Side Diff: vm/freelist.h

Issue 8787012: - Add free list to be used for sweep phase of mark-sweep collector. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 VM_FREELIST_H_
6 #define VM_FREELIST_H_
7
8 #include "vm/allocation.h"
9 #include "vm/assert.h"
10 #include "vm/raw_object.h"
11
12 namespace dart {
13
14 // FreeListElement describes a freelist element that has the same size
15 // as the smallest raw object. It uses the class_ field to point to a fake map
16 // to enable basic traversing of the heap and to identify the type of freelist
17 // element. It reuses the second word of the raw object to keep a next_
18 // pointer to chain elements of the list together. For objects larger than the
19 // minimal object size, the size of the element is embedded in the element at
20 // the address following the next_ field.
21 class FreeListElement {
22 public:
23 FreeListElement* next() const { return next_; }
24 void set_next(FreeListElement* next) { next_ = next; }
25
26 intptr_t Size() const {
27 if (class_ == minimal_element_class_) {
28 return kObjectAlignment;
29 }
30 ASSERT(class_ == element_class_);
31 return *SizeAddress();
32 }
33
34 static FreeListElement* AsElement(uword addr, intptr_t size);
35
36 static void InitOnce();
37
38 private:
39 // This layout mirrors the layout of RawObject.
40 RawClass* class_;
41 FreeListElement* next_;
42
43 // Returns the address of the embedded size.
44 intptr_t* SizeAddress() const {
45 ASSERT(class_ == element_class_);
46 uword addr = reinterpret_cast<uword>(&next_) + kWordSize;
47 return reinterpret_cast<intptr_t*>(addr);
48 }
49
50 // The two fake classe being used by the FreeList to identify free objects in
51 // the heap. These can be static and shared between isolates since they
52 // contain no per-isolate information. Actually, they need to be static so
53 // that they can be used from free list elements efficiently.
54 // The minimal_element_class_ is used by minimally sized free list elements
55 // which cannot hold the size within the element.
56 // element_class_ is used for free lists elements containing a size.
57 static RawClass* minimal_element_class_;
58 static RawClass* element_class_;
59
60 // FreeListElements cannot be allocated. Instead references to them are
61 // created using the AsElement factory method.
62 DISALLOW_ALLOCATION();
63 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListElement);
64 };
65
66
67 class FreeList {
68 public:
69 FreeList();
70 ~FreeList();
71
72 uword TryAllocate(intptr_t size);
73 void Free(uword addr, intptr_t size);
74
75 void Reset();
76
77 private:
78 static const int kNumLists = 128;
79
80 static intptr_t IndexForSize(intptr_t size);
81
82 void EnqueueElement(FreeListElement* element, intptr_t index);
83 FreeListElement* DequeueElement(intptr_t index);
84
85 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size);
86
87 FreeListElement* free_lists_[kNumLists + 1];
88
89 DISALLOW_COPY_AND_ASSIGN(FreeList);
90 };
91
92 } // namespace dart
93
94 #endif // VM_FREELIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698