Chromium Code Reviews| 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> | |
|
siva
2012/07/19 19:38:23
The compiler uses our BitVector class for all thes
cshapiro
2012/07/19 22:34:29
With regard to our off-line discussion, this is a
| |
| 9 | |
| 8 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" | 11 #include "vm/allocation.h" |
| 10 #include "vm/raw_object.h" | 12 #include "vm/raw_object.h" |
| 11 | 13 |
| 12 namespace dart { | 14 namespace dart { |
| 13 | 15 |
| 14 // FreeListElement describes a freelist element. Smallest FreeListElement is | 16 // FreeListElement describes a freelist element. Smallest FreeListElement is |
| 15 // 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_ |
| 16 // 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 |
| 17 // 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 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 class FreeList { | 73 class FreeList { |
| 72 public: | 74 public: |
| 73 FreeList(); | 75 FreeList(); |
| 74 ~FreeList(); | 76 ~FreeList(); |
| 75 | 77 |
| 76 uword TryAllocate(intptr_t size); | 78 uword TryAllocate(intptr_t size); |
| 77 void Free(uword addr, intptr_t size); | 79 void Free(uword addr, intptr_t size); |
| 78 | 80 |
| 79 void Reset(); | 81 void Reset(); |
| 80 | 82 |
| 83 intptr_t Length(int index) const; | |
| 84 | |
| 85 void Print() const; | |
| 86 | |
| 81 private: | 87 private: |
| 82 static const int kNumLists = 128; | 88 static const int kNumLists = 128; |
| 83 | 89 |
| 84 static intptr_t IndexForSize(intptr_t size); | 90 static intptr_t IndexForSize(intptr_t size); |
| 85 | 91 |
| 86 void EnqueueElement(FreeListElement* element, intptr_t index); | 92 void EnqueueElement(FreeListElement* element, intptr_t index); |
| 87 FreeListElement* DequeueElement(intptr_t index); | 93 FreeListElement* DequeueElement(intptr_t index); |
| 88 | 94 |
| 89 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); | 95 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); |
| 90 | 96 |
| 97 std::bitset<kNumLists + 1> free_map_; | |
| 98 | |
| 91 FreeListElement* free_lists_[kNumLists + 1]; | 99 FreeListElement* free_lists_[kNumLists + 1]; |
| 92 | 100 |
| 93 DISALLOW_COPY_AND_ASSIGN(FreeList); | 101 DISALLOW_COPY_AND_ASSIGN(FreeList); |
| 94 }; | 102 }; |
| 95 | 103 |
| 96 } // namespace dart | 104 } // namespace dart |
| 97 | 105 |
| 98 #endif // VM_FREELIST_H_ | 106 #endif // VM_FREELIST_H_ |
| OLD | NEW |