OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_FREELIST_H_ | 5 #ifndef VM_FREELIST_H_ |
6 #define VM_FREELIST_H_ | 6 #define VM_FREELIST_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/bit_set.h" | 10 #include "vm/bit_set.h" |
11 #include "vm/raw_object.h" | 11 #include "vm/raw_object.h" |
| 12 #include "vm/thread.h" |
12 | 13 |
13 namespace dart { | 14 namespace dart { |
14 | 15 |
15 // FreeListElement describes a freelist element. Smallest FreeListElement is | 16 // FreeListElement describes a freelist element. Smallest FreeListElement is |
16 // two words in size. Second word of the raw object is used to keep a next_ | 17 // two words in size. Second word of the raw object is used to keep a next_ |
17 // pointer to chain elements of the list together. For objects larger than the | 18 // pointer to chain elements of the list together. For objects larger than the |
18 // object size encodable in tags field, the size of the element is embedded in | 19 // object size encodable in tags field, the size of the element is embedded in |
19 // the element at the address following the next_ field. | 20 // the element at the address following the next_ field. |
20 class FreeListElement { | 21 class FreeListElement { |
21 public: | 22 public: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 class FreeList { | 79 class FreeList { |
79 public: | 80 public: |
80 FreeList(); | 81 FreeList(); |
81 ~FreeList(); | 82 ~FreeList(); |
82 | 83 |
83 uword TryAllocate(intptr_t size, bool is_protected); | 84 uword TryAllocate(intptr_t size, bool is_protected); |
84 void Free(uword addr, intptr_t size); | 85 void Free(uword addr, intptr_t size); |
85 | 86 |
86 void Reset(); | 87 void Reset(); |
87 | 88 |
88 intptr_t Length(int index) const; | 89 void Print() const; |
89 | 90 |
90 void Print() const; | 91 Mutex* mutex() { return mutex_; } |
| 92 uword TryAllocateLocked(intptr_t size, bool is_protected); |
| 93 void FreeLocked(uword addr, intptr_t size); |
91 | 94 |
92 private: | 95 private: |
93 static const int kNumLists = 128; | 96 static const int kNumLists = 128; |
94 | 97 |
95 static intptr_t IndexForSize(intptr_t size); | 98 static intptr_t IndexForSize(intptr_t size); |
96 | 99 |
| 100 intptr_t Length(int index) const; |
| 101 |
97 void EnqueueElement(FreeListElement* element, intptr_t index); | 102 void EnqueueElement(FreeListElement* element, intptr_t index); |
98 FreeListElement* DequeueElement(intptr_t index); | 103 FreeListElement* DequeueElement(intptr_t index); |
99 | 104 |
100 void SplitElementAfterAndEnqueue(FreeListElement* element, | 105 void SplitElementAfterAndEnqueue(FreeListElement* element, |
101 intptr_t size, | 106 intptr_t size, |
102 bool is_protected); | 107 bool is_protected); |
103 | 108 |
104 void PrintSmall() const; | 109 void PrintSmall() const; |
105 void PrintLarge() const; | 110 void PrintLarge() const; |
106 | 111 |
| 112 // Lock protecting the free list data structures. |
| 113 Mutex* mutex_; |
| 114 |
107 BitSet<kNumLists> free_map_; | 115 BitSet<kNumLists> free_map_; |
108 | 116 |
109 FreeListElement* free_lists_[kNumLists + 1]; | 117 FreeListElement* free_lists_[kNumLists + 1]; |
110 | 118 |
111 DISALLOW_COPY_AND_ASSIGN(FreeList); | 119 DISALLOW_COPY_AND_ASSIGN(FreeList); |
112 }; | 120 }; |
113 | 121 |
114 } // namespace dart | 122 } // namespace dart |
115 | 123 |
116 #endif // VM_FREELIST_H_ | 124 #endif // VM_FREELIST_H_ |
OLD | NEW |