| 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 TryAllocateSmallLocked(intptr_t size); |
| 97 | 102 |
| 98 private: | 103 private: |
| 99 static const int kNumLists = 128; | 104 static const int kNumLists = 128; |
| 100 | 105 |
| 101 static intptr_t IndexForSize(intptr_t size); | 106 static intptr_t IndexForSize(intptr_t size); |
| 102 | 107 |
| 103 intptr_t LengthLocked(int index) const; | 108 intptr_t LengthLocked(int index) const; |
| 104 | 109 |
| 105 void EnqueueElement(FreeListElement* element, intptr_t index); | 110 void EnqueueElement(FreeListElement* element, intptr_t index); |
| 106 FreeListElement* DequeueElement(intptr_t index); | 111 FreeListElement* DequeueElement(intptr_t index); |
| 107 | 112 |
| 108 void SplitElementAfterAndEnqueue(FreeListElement* element, | 113 void SplitElementAfterAndEnqueue(FreeListElement* element, |
| 109 intptr_t size, | 114 intptr_t size, |
| 110 bool is_protected); | 115 bool is_protected); |
| 111 | 116 |
| 112 void PrintSmall() const; | 117 void PrintSmall() const; |
| 113 void PrintLarge() const; | 118 void PrintLarge() const; |
| 114 | 119 |
| 115 // Lock protecting the free list data structures. | 120 // Lock protecting the free list data structures. |
| 116 Mutex* mutex_; | 121 Mutex* mutex_; |
| 117 | 122 |
| 118 BitSet<kNumLists> free_map_; | 123 BitSet<kNumLists> free_map_; |
| 119 | 124 |
| 120 FreeListElement* free_lists_[kNumLists + 1]; | 125 FreeListElement* free_lists_[kNumLists + 1]; |
| 121 | 126 |
| 127 // The largest available small size in bytes, or negative if there is none. |
| 128 intptr_t last_free_small_size_; |
| 129 |
| 122 DISALLOW_COPY_AND_ASSIGN(FreeList); | 130 DISALLOW_COPY_AND_ASSIGN(FreeList); |
| 123 }; | 131 }; |
| 124 | 132 |
| 125 } // namespace dart | 133 } // namespace dart |
| 126 | 134 |
| 127 #endif // VM_FREELIST_H_ | 135 #endif // VM_FREELIST_H_ |
| OLD | NEW |