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

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

Issue 10450014: Request for comments on overall approach. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix scavenger and freelist handling 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"
(...skipping 14 matching lines...) Expand all
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; 37 }
38 } 38 void set_size(intptr_t size) {
39 ASSERT(class_ == element_class_); 39 size_ = size;
40 return *SizeAddress();
41 } 40 }
42 41
43 static FreeListElement* AsElement(uword addr, intptr_t size); 42 static FreeListElement* AsElement(uword addr, intptr_t size);
44 43
45 static bool IsSpecialClass(RawObject* raw_obj) { 44 static bool IsSpecialClass(RawObject* raw_obj) {
46 return (raw_obj == minimal_element_class_) || (raw_obj == element_class_); 45 return raw_obj->IsFree();
47 } 46 }
48 47
49 static void InitOnce(); 48 static void InitOnce();
50 49
50 static RawClass* freelist_class() {
51 return freelist_class_;
52 }
53
51 private: 54 private:
52 // This layout mirrors the layout of RawObject. 55 // This layout mirrors the layout of RawObject.
53 RawClass* class_;
54 uword next_; 56 uword next_;
Ivan Posva 2012/05/26 04:34:46 I don't think this works. How do you plan to itera
Vyacheslav Egorov (Google) 2012/05/26 16:48:22 Yes it does have exactly the same layout as RawObj
57 intptr_t size_;
55 58
56 // Returns the address of the embedded size. 59 static RawClass* freelist_class_;
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 60
73 // FreeListElements cannot be allocated. Instead references to them are 61 // FreeListElements cannot be allocated. Instead references to them are
74 // created using the AsElement factory method. 62 // created using the AsElement factory method.
75 DISALLOW_ALLOCATION(); 63 DISALLOW_ALLOCATION();
76 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListElement); 64 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListElement);
77 }; 65 };
78 66
79 67
80 class FreeList { 68 class FreeList {
81 public: 69 public:
(...skipping 16 matching lines...) Expand all
98 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); 86 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size);
99 87
100 FreeListElement* free_lists_[kNumLists + 1]; 88 FreeListElement* free_lists_[kNumLists + 1];
101 89
102 DISALLOW_COPY_AND_ASSIGN(FreeList); 90 DISALLOW_COPY_AND_ASSIGN(FreeList);
103 }; 91 };
104 92
105 } // namespace dart 93 } // namespace dart
106 94
107 #endif // VM_FREELIST_H_ 95 #endif // VM_FREELIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698