Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: runtime/vm/freelist.h

Issue 10538022: Do not reuse tags_ field to store next_ pointer of FreeListElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 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
Ivan Posva 2012/06/08 07:19:20 Comment out of date.
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 { 23 FreeListElement* next() const {
24 // Clear the FreeBit. 24 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 } 25 }
34 26
35 intptr_t size() const { 27 void set_next(FreeListElement* next) {
36 return size_; 28 next_ = next;
29 }
30
31 intptr_t Size() {
32 intptr_t size = RawObject::SizeTag::decode(tags_);
33 if (size != 0) return size;
34 return *SizeAddress();
37 } 35 }
38 36
39 static FreeListElement* AsElement(uword addr, intptr_t size); 37 static FreeListElement* AsElement(uword addr, intptr_t size);
40 38
41 static void InitOnce(); 39 static void InitOnce();
42 40
41 static RawClass* element_class() {
42 return element_class_;
43 }
44
43 private: 45 private:
44 // This layout mirrors the layout of RawObject. 46 // This layout mirrors the layout of RawObject.
45 uword next_; 47 uword tags_;
46 intptr_t size_; 48 FreeListElement* next_;
49
50 // Returns the address of the embedded size.
51 intptr_t* SizeAddress() const {
52 uword addr = reinterpret_cast<uword>(&next_) + kWordSize;
53 return reinterpret_cast<intptr_t*>(addr);
54 }
55
56 // Fake class corresponding to kFreeListElement class id.
57 static RawClass* element_class_;
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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698