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" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 void Reset(); | 87 void Reset(); |
88 | 88 |
89 void Print() const; | 89 void Print() const; |
90 | 90 |
91 Mutex* mutex() { return mutex_; } | 91 Mutex* mutex() { return mutex_; } |
92 uword TryAllocateLocked(intptr_t size, bool is_protected); | 92 uword TryAllocateLocked(intptr_t size, bool is_protected); |
93 void FreeLocked(uword addr, intptr_t size); | 93 void FreeLocked(uword addr, intptr_t size); |
94 | 94 |
95 // Returns a large element, at least 'minimum_size', or NULL if none exists. | 95 // Returns a large element, at least 'minimum_size', or NULL if none exists. |
96 FreeListElement* TryAllocateLarge(intptr_t minimum_size); | 96 FreeListElement* TryAllocateLarge(intptr_t minimum_size); |
| 97 FreeListElement* TryAllocateLargeLocked(intptr_t minimum_size); |
| 98 |
| 99 // Allocates locked and unprotected memory, but only from small elements |
| 100 // (i.e., fixed size lists). |
| 101 uword TryAllocateSmall(intptr_t size); |
| 102 // Returns 'b' such that all small elements have size <= 'b' bytes. |
| 103 intptr_t SmallSizeBound() const { return last_free_small_size_; } |
97 | 104 |
98 private: | 105 private: |
99 static const int kNumLists = 128; | 106 static const int kNumLists = 128; |
100 | 107 |
101 static intptr_t IndexForSize(intptr_t size); | 108 static intptr_t IndexForSize(intptr_t size); |
102 | 109 |
103 intptr_t LengthLocked(int index) const; | 110 intptr_t LengthLocked(int index) const; |
104 | 111 |
105 void EnqueueElement(FreeListElement* element, intptr_t index); | 112 void EnqueueElement(FreeListElement* element, intptr_t index); |
106 FreeListElement* DequeueElement(intptr_t index); | 113 FreeListElement* DequeueElement(intptr_t index); |
107 | 114 |
108 void SplitElementAfterAndEnqueue(FreeListElement* element, | 115 void SplitElementAfterAndEnqueue(FreeListElement* element, |
109 intptr_t size, | 116 intptr_t size, |
110 bool is_protected); | 117 bool is_protected); |
111 | 118 |
112 void PrintSmall() const; | 119 void PrintSmall() const; |
113 void PrintLarge() const; | 120 void PrintLarge() const; |
114 | 121 |
115 // Lock protecting the free list data structures. | 122 // Lock protecting the free list data structures. |
116 Mutex* mutex_; | 123 Mutex* mutex_; |
117 | 124 |
118 BitSet<kNumLists> free_map_; | 125 BitSet<kNumLists> free_map_; |
119 | 126 |
120 FreeListElement* free_lists_[kNumLists + 1]; | 127 FreeListElement* free_lists_[kNumLists + 1]; |
121 | 128 |
| 129 // The largest available small size in bytes, or negative if there is none. |
| 130 intptr_t last_free_small_size_; |
| 131 |
122 DISALLOW_COPY_AND_ASSIGN(FreeList); | 132 DISALLOW_COPY_AND_ASSIGN(FreeList); |
123 }; | 133 }; |
124 | 134 |
125 } // namespace dart | 135 } // namespace dart |
126 | 136 |
127 #endif // VM_FREELIST_H_ | 137 #endif // VM_FREELIST_H_ |
OLD | NEW |