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 "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/raw_object.h" | 10 #include "vm/raw_object.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 // FreeListElement describes a freelist element that has the same size | 14 // FreeListElement describes a freelist element. Smallest FreeListElement is |
| 15 // as the smallest raw object. It uses the class_ field to point to a fake map | 15 // two words in size. Second word of the raw object is used to keep a next_ |
| 16 // to enable basic traversing of the heap and to identify the type of freelist | |
| 17 // element. It reuses the second word of the raw object 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 // minimal object size, the size of the element is embedded in the element at | 17 // object size encodable in tags field, the size of the element is embedded in |
| 20 // the address following the next_ field. | 18 // the element at the address following the next_ field. |
| 21 class FreeListElement { | 19 class FreeListElement { |
| 22 public: | 20 public: |
| 23 FreeListElement* next() const { | 21 FreeListElement* next() const { |
| 24 // Clear the FreeBit. | 22 return next_; |
| 25 ASSERT((next_ & 1) == 1); | |
| 26 return reinterpret_cast<FreeListElement*>(next_ ^ 1); | |
| 27 } | |
| 28 void set_next(FreeListElement* next) { | |
| 29 // Set the FreeBit. | |
| 30 uword addr = reinterpret_cast<uword>(next); | |
| 31 ASSERT((addr & 1) == 0); | |
| 32 next_ = addr | 1; | |
| 33 } | 23 } |
| 34 | 24 |
| 35 intptr_t size() const { | 25 void set_next(FreeListElement* next) { |
| 36 return size_; | 26 next_ = next; |
| 27 } | |
| 28 | |
| 29 intptr_t Size() { | |
| 30 intptr_t size = RawObject::SizeTag::decode(tags_); | |
| 31 if (size != 0) return size; | |
| 32 return *SizeAddress(); | |
| 37 } | 33 } |
| 38 | 34 |
| 39 static FreeListElement* AsElement(uword addr, intptr_t size); | 35 static FreeListElement* AsElement(uword addr, intptr_t size); |
| 40 | 36 |
| 41 static void InitOnce(); | 37 static void InitOnce(); |
| 42 | 38 |
| 39 // Used to allocate class for free list elements in Object::InitOnce. | |
| 40 class FakeInstance { | |
| 41 public: | |
| 42 static cpp_vtable vtable() { return 0; } | |
| 43 static intptr_t InstanceSize() { return 0; } | |
| 44 static const ObjectKind kInstanceKind = kFreeListElement; | |
| 45 static bool IsInstance() { return true; } | |
|
Ivan Posva
2012/06/08 12:50:20
private:
DISALLOW_ALLOCATION();
DISALLOW_IMPLI
Vyacheslav Egorov (Google)
2012/06/08 12:58:27
Did
private:
DISALLOW_ALLOCATION();
DISALLOW_
| |
| 46 }; | |
| 47 | |
| 43 private: | 48 private: |
| 44 // This layout mirrors the layout of RawObject. | 49 // This layout mirrors the layout of RawObject. |
| 45 uword next_; | 50 uword tags_; |
| 46 intptr_t size_; | 51 FreeListElement* next_; |
| 52 | |
| 53 // Returns the address of the embedded size. | |
| 54 intptr_t* SizeAddress() const { | |
| 55 uword addr = reinterpret_cast<uword>(&next_) + kWordSize; | |
| 56 return reinterpret_cast<intptr_t*>(addr); | |
| 57 } | |
| 47 | 58 |
| 48 // FreeListElements cannot be allocated. Instead references to them are | 59 // FreeListElements cannot be allocated. Instead references to them are |
| 49 // created using the AsElement factory method. | 60 // created using the AsElement factory method. |
| 50 DISALLOW_ALLOCATION(); | 61 DISALLOW_ALLOCATION(); |
| 51 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListElement); | 62 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListElement); |
| 52 }; | 63 }; |
| 53 | 64 |
| 54 | 65 |
| 55 class FreeList { | 66 class FreeList { |
| 56 public: | 67 public: |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 73 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); | 84 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); |
| 74 | 85 |
| 75 FreeListElement* free_lists_[kNumLists + 1]; | 86 FreeListElement* free_lists_[kNumLists + 1]; |
| 76 | 87 |
| 77 DISALLOW_COPY_AND_ASSIGN(FreeList); | 88 DISALLOW_COPY_AND_ASSIGN(FreeList); |
| 78 }; | 89 }; |
| 79 | 90 |
| 80 } // namespace dart | 91 } // namespace dart |
| 81 | 92 |
| 82 #endif // VM_FREELIST_H_ | 93 #endif // VM_FREELIST_H_ |
| OLD | NEW |