| 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 <bitset> | |
| 9 | |
| 10 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 11 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 12 #include "vm/raw_object.h" | 10 #include "vm/raw_object.h" |
| 13 | 11 |
| 14 namespace dart { | 12 namespace dart { |
| 15 | 13 |
| 16 // FreeListElement describes a freelist element. Smallest FreeListElement is | 14 // FreeListElement describes a freelist element. Smallest FreeListElement is |
| 17 // two words in size. Second word of the raw object is used to keep a next_ | 15 // two words in size. Second word of the raw object is used to keep a next_ |
| 18 // pointer to chain elements of the list together. For objects larger than the | 16 // pointer to chain elements of the list together. For objects larger than the |
| 19 // object size encodable in tags field, the size of the element is embedded in | 17 // object size encodable in tags field, the size of the element is embedded in |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 class FreeList { | 71 class FreeList { |
| 74 public: | 72 public: |
| 75 FreeList(); | 73 FreeList(); |
| 76 ~FreeList(); | 74 ~FreeList(); |
| 77 | 75 |
| 78 uword TryAllocate(intptr_t size); | 76 uword TryAllocate(intptr_t size); |
| 79 void Free(uword addr, intptr_t size); | 77 void Free(uword addr, intptr_t size); |
| 80 | 78 |
| 81 void Reset(); | 79 void Reset(); |
| 82 | 80 |
| 83 intptr_t Length(int index) const; | |
| 84 | |
| 85 void Print() const; | |
| 86 | |
| 87 private: | 81 private: |
| 88 static const int kNumLists = 128; | 82 static const int kNumLists = 128; |
| 89 | 83 |
| 90 static intptr_t IndexForSize(intptr_t size); | 84 static intptr_t IndexForSize(intptr_t size); |
| 91 | 85 |
| 92 void EnqueueElement(FreeListElement* element, intptr_t index); | 86 void EnqueueElement(FreeListElement* element, intptr_t index); |
| 93 FreeListElement* DequeueElement(intptr_t index); | 87 FreeListElement* DequeueElement(intptr_t index); |
| 94 | 88 |
| 95 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); | 89 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); |
| 96 | 90 |
| 97 std::bitset<kNumLists + 1> free_map_; | |
| 98 | |
| 99 FreeListElement* free_lists_[kNumLists + 1]; | 91 FreeListElement* free_lists_[kNumLists + 1]; |
| 100 | 92 |
| 101 DISALLOW_COPY_AND_ASSIGN(FreeList); | 93 DISALLOW_COPY_AND_ASSIGN(FreeList); |
| 102 }; | 94 }; |
| 103 | 95 |
| 104 } // namespace dart | 96 } // namespace dart |
| 105 | 97 |
| 106 #endif // VM_FREELIST_H_ | 98 #endif // VM_FREELIST_H_ |
| OLD | NEW |