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 RUNTIME_VM_FREELIST_H_ | 5 #ifndef RUNTIME_VM_FREELIST_H_ |
6 #define RUNTIME_VM_FREELIST_H_ | 6 #define RUNTIME_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/bit_set.h" | 10 #include "vm/bit_set.h" |
11 #include "vm/raw_object.h" | 11 #include "vm/raw_object.h" |
12 #include "vm/os_thread.h" | 12 #include "vm/os_thread.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 // FreeListElement describes a freelist element. Smallest FreeListElement is | 16 // 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_ | 17 // 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 | 18 // 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 | 19 // object size encodable in tags field, the size of the element is embedded in |
20 // the element at the address following the next_ field. All words written by | 20 // the element at the address following the next_ field. All words written by |
21 // the freelist are guaranteed to look like Smis. | 21 // the freelist are guaranteed to look like Smis. |
22 // A FreeListElement never has its header mark bit set. | 22 // A FreeListElement never has its header mark bit set. |
23 class FreeListElement { | 23 class FreeListElement { |
24 public: | 24 public: |
25 FreeListElement* next() const { | 25 FreeListElement* next() const { return next_; } |
26 return next_; | 26 uword next_address() const { return reinterpret_cast<uword>(&next_); } |
27 } | |
28 uword next_address() const { | |
29 return reinterpret_cast<uword>(&next_); | |
30 } | |
31 | 27 |
32 void set_next(FreeListElement* next) { | 28 void set_next(FreeListElement* next) { next_ = next; } |
33 next_ = next; | |
34 } | |
35 | 29 |
36 intptr_t Size() { | 30 intptr_t Size() { |
37 intptr_t size = RawObject::SizeTag::decode(tags_); | 31 intptr_t size = RawObject::SizeTag::decode(tags_); |
38 if (size != 0) return size; | 32 if (size != 0) return size; |
39 return *SizeAddress(); | 33 return *SizeAddress(); |
40 } | 34 } |
41 | 35 |
42 static FreeListElement* AsElement(uword addr, intptr_t size); | 36 static FreeListElement* AsElement(uword addr, intptr_t size); |
43 | 37 |
44 static void InitOnce(); | 38 static void InitOnce(); |
45 | 39 |
46 static intptr_t HeaderSizeFor(intptr_t size); | 40 static intptr_t HeaderSizeFor(intptr_t size); |
47 | 41 |
48 // Used to allocate class for free list elements in Object::InitOnce. | 42 // Used to allocate class for free list elements in Object::InitOnce. |
49 class FakeInstance { | 43 class FakeInstance { |
50 public: | 44 public: |
51 FakeInstance() { } | 45 FakeInstance() {} |
52 static cpp_vtable vtable() { return 0; } | 46 static cpp_vtable vtable() { return 0; } |
53 static intptr_t InstanceSize() { return 0; } | 47 static intptr_t InstanceSize() { return 0; } |
54 static intptr_t NextFieldOffset() { return -kWordSize; } | 48 static intptr_t NextFieldOffset() { return -kWordSize; } |
55 static const ClassId kClassId = kFreeListElement; | 49 static const ClassId kClassId = kFreeListElement; |
56 static bool IsInstance() { return true; } | 50 static bool IsInstance() { return true; } |
57 | 51 |
58 private: | 52 private: |
59 DISALLOW_ALLOCATION(); | 53 DISALLOW_ALLOCATION(); |
60 DISALLOW_COPY_AND_ASSIGN(FakeInstance); | 54 DISALLOW_COPY_AND_ASSIGN(FakeInstance); |
61 }; | 55 }; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 122 |
129 // The largest available small size in bytes, or negative if there is none. | 123 // The largest available small size in bytes, or negative if there is none. |
130 intptr_t last_free_small_size_; | 124 intptr_t last_free_small_size_; |
131 | 125 |
132 DISALLOW_COPY_AND_ASSIGN(FreeList); | 126 DISALLOW_COPY_AND_ASSIGN(FreeList); |
133 }; | 127 }; |
134 | 128 |
135 } // namespace dart | 129 } // namespace dart |
136 | 130 |
137 #endif // RUNTIME_VM_FREELIST_H_ | 131 #endif // RUNTIME_VM_FREELIST_H_ |
OLD | NEW |