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" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 ASSERT((next_ & 1) == 1); | 25 ASSERT((next_ & 1) == 1); |
26 return reinterpret_cast<FreeListElement*>(next_ ^ 1); | 26 return reinterpret_cast<FreeListElement*>(next_ ^ 1); |
27 } | 27 } |
28 void set_next(FreeListElement* next) { | 28 void set_next(FreeListElement* next) { |
29 // Set the FreeBit. | 29 // Set the FreeBit. |
30 uword addr = reinterpret_cast<uword>(next); | 30 uword addr = reinterpret_cast<uword>(next); |
31 ASSERT((addr & 1) == 0); | 31 ASSERT((addr & 1) == 0); |
32 next_ = addr | 1; | 32 next_ = addr | 1; |
33 } | 33 } |
34 | 34 |
35 intptr_t Size() const { | 35 intptr_t size() const { |
36 if (class_ == minimal_element_class_) { | 36 return size_; |
37 return kObjectAlignment; | |
38 } | |
39 ASSERT(class_ == element_class_); | |
40 return *SizeAddress(); | |
41 } | 37 } |
42 | 38 |
43 static FreeListElement* AsElement(uword addr, intptr_t size); | 39 static FreeListElement* AsElement(uword addr, intptr_t size); |
44 | 40 |
45 static bool IsSpecialClass(RawObject* raw_obj) { | |
46 return (raw_obj == minimal_element_class_) || (raw_obj == element_class_); | |
47 } | |
48 | |
49 static void InitOnce(); | 41 static void InitOnce(); |
50 | 42 |
51 private: | 43 private: |
52 // This layout mirrors the layout of RawObject. | 44 // This layout mirrors the layout of RawObject. |
Ivan Posva
2012/06/06 13:42:11
As discussed offline the expectation here is that
| |
53 RawClass* class_; | |
54 uword next_; | 45 uword next_; |
55 | 46 intptr_t size_; |
56 // Returns the address of the embedded size. | |
57 intptr_t* SizeAddress() const { | |
58 ASSERT(class_ == element_class_); | |
59 uword addr = reinterpret_cast<uword>(&next_) + kWordSize; | |
60 return reinterpret_cast<intptr_t*>(addr); | |
61 } | |
62 | |
63 // The two fake classe being used by the FreeList to identify free objects in | |
64 // the heap. These can be static and shared between isolates since they | |
65 // contain no per-isolate information. Actually, they need to be static so | |
66 // that they can be used from free list elements efficiently. | |
67 // The minimal_element_class_ is used by minimally sized free list elements | |
68 // which cannot hold the size within the element. | |
69 // element_class_ is used for free lists elements containing a size. | |
70 static RawClass* minimal_element_class_; | |
71 static RawClass* element_class_; | |
72 | 47 |
73 // FreeListElements cannot be allocated. Instead references to them are | 48 // FreeListElements cannot be allocated. Instead references to them are |
74 // created using the AsElement factory method. | 49 // created using the AsElement factory method. |
75 DISALLOW_ALLOCATION(); | 50 DISALLOW_ALLOCATION(); |
76 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListElement); | 51 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListElement); |
77 }; | 52 }; |
78 | 53 |
79 | 54 |
80 class FreeList { | 55 class FreeList { |
81 public: | 56 public: |
(...skipping 16 matching lines...) Expand all Loading... | |
98 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); | 73 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); |
99 | 74 |
100 FreeListElement* free_lists_[kNumLists + 1]; | 75 FreeListElement* free_lists_[kNumLists + 1]; |
101 | 76 |
102 DISALLOW_COPY_AND_ASSIGN(FreeList); | 77 DISALLOW_COPY_AND_ASSIGN(FreeList); |
103 }; | 78 }; |
104 | 79 |
105 } // namespace dart | 80 } // namespace dart |
106 | 81 |
107 #endif // VM_FREELIST_H_ | 82 #endif // VM_FREELIST_H_ |
OLD | NEW |