Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/assert.h" | 9 #include "vm/assert.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 that has the same size |
| 15 // as the smallest raw object. It uses the class_ field to point to a fake map | 15 // as the smallest raw object. It uses the class_ field to point to a fake map |
| 16 // to enable basic traversing of the heap and to identify the type of freelist | 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_ | 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 | 18 // 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 | 19 // minimal object size, the size of the element is embedded in the element at |
| 20 // the address following the next_ field. | 20 // the address following the next_ field. |
| 21 class FreeListElement { | 21 class FreeListElement { |
| 22 public: | 22 public: |
| 23 FreeListElement* next() const { return next_; } | 23 FreeListElement* next() const { |
| 24 void set_next(FreeListElement* next) { next_ = next; } | 24 // Clear the FreeBit. |
| 25 ASSERT((next_ & 1) == 1); | |
| 26 return reinterpret_cast<FreeListElement*>(next_ ^ 1); | |
|
turnidge
2012/01/04 01:06:17
Should this use the constant RawObject::kFreeBit?
Ivan Posva
2012/01/04 07:59:42
Done. In any case this use here should only be tem
| |
| 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; | |
|
turnidge
2012/01/04 01:06:17
Same as above.
Ivan Posva
2012/01/04 07:59:42
ditto.
| |
| 33 } | |
| 25 | 34 |
| 26 intptr_t Size() const { | 35 intptr_t Size() const { |
| 27 if (class_ == minimal_element_class_) { | 36 if (class_ == minimal_element_class_) { |
| 28 return kObjectAlignment; | 37 return kObjectAlignment; |
| 29 } | 38 } |
| 30 ASSERT(class_ == element_class_); | 39 ASSERT(class_ == element_class_); |
| 31 return *SizeAddress(); | 40 return *SizeAddress(); |
| 32 } | 41 } |
| 33 | 42 |
| 34 static FreeListElement* AsElement(uword addr, intptr_t size); | 43 static FreeListElement* AsElement(uword addr, intptr_t size); |
| 35 | 44 |
| 36 static bool IsSpecialClass(RawObject* raw_obj) { | 45 static bool IsSpecialClass(RawObject* raw_obj) { |
| 37 return (raw_obj == minimal_element_class_) || (raw_obj == element_class_); | 46 return (raw_obj == minimal_element_class_) || (raw_obj == element_class_); |
| 38 } | 47 } |
| 39 | 48 |
| 40 static void InitOnce(); | 49 static void InitOnce(); |
| 41 | 50 |
| 42 private: | 51 private: |
| 43 // This layout mirrors the layout of RawObject. | 52 // This layout mirrors the layout of RawObject. |
| 44 RawClass* class_; | 53 RawClass* class_; |
| 45 FreeListElement* next_; | 54 uword next_; |
| 46 | 55 |
| 47 // Returns the address of the embedded size. | 56 // Returns the address of the embedded size. |
| 48 intptr_t* SizeAddress() const { | 57 intptr_t* SizeAddress() const { |
| 49 ASSERT(class_ == element_class_); | 58 ASSERT(class_ == element_class_); |
| 50 uword addr = reinterpret_cast<uword>(&next_) + kWordSize; | 59 uword addr = reinterpret_cast<uword>(&next_) + kWordSize; |
| 51 return reinterpret_cast<intptr_t*>(addr); | 60 return reinterpret_cast<intptr_t*>(addr); |
| 52 } | 61 } |
| 53 | 62 |
| 54 // The two fake classe being used by the FreeList to identify free objects in | 63 // The two fake classe being used by the FreeList to identify free objects in |
| 55 // the heap. These can be static and shared between isolates since they | 64 // the heap. These can be static and shared between isolates since they |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); | 98 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); |
| 90 | 99 |
| 91 FreeListElement* free_lists_[kNumLists + 1]; | 100 FreeListElement* free_lists_[kNumLists + 1]; |
| 92 | 101 |
| 93 DISALLOW_COPY_AND_ASSIGN(FreeList); | 102 DISALLOW_COPY_AND_ASSIGN(FreeList); |
| 94 }; | 103 }; |
| 95 | 104 |
| 96 } // namespace dart | 105 } // namespace dart |
| 97 | 106 |
| 98 #endif // VM_FREELIST_H_ | 107 #endif // VM_FREELIST_H_ |
| OLD | NEW |