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

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

Issue 106593002: Write protect executable pages in the VM. Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
« no previous file with comments | « runtime/vm/debugger.cc ('k') | runtime/vm/freelist.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bit_set.h" 10 #include "vm/bit_set.h"
11 #include "vm/raw_object.h" 11 #include "vm/raw_object.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 // FreeListElement describes a freelist element. Smallest FreeListElement is 15 // FreeListElement describes a freelist element. Smallest FreeListElement is
16 // two words in size. Second word of the raw object is used to keep a next_ 16 // two words in size. Second word of the raw object is used to keep a next_
17 // pointer to chain elements of the list together. For objects larger than the 17 // pointer to chain elements of the list together. For objects larger than the
18 // object size encodable in tags field, the size of the element is embedded in 18 // object size encodable in tags field, the size of the element is embedded in
19 // the element at the address following the next_ field. 19 // the element at the address following the next_ field.
20 class FreeListElement { 20 class FreeListElement {
21 public: 21 public:
22 // Maximum header size is three words (tags, next, and size).
23 static const intptr_t kHeaderSize = 3 * kWordSize;
24
22 FreeListElement* next() const { 25 FreeListElement* next() const {
23 return next_; 26 return next_;
24 } 27 }
28 uword next_address() const {
29 return reinterpret_cast<uword>(&next_);
30 }
25 31
26 void set_next(FreeListElement* next) { 32 void set_next(FreeListElement* next) {
27 next_ = next; 33 next_ = next;
28 } 34 }
29 35
30 intptr_t Size() { 36 intptr_t Size() {
31 intptr_t size = RawObject::SizeTag::decode(tags_); 37 intptr_t size = RawObject::SizeTag::decode(tags_);
32 if (size != 0) return size; 38 if (size != 0) return size;
33 return *SizeAddress(); 39 return *SizeAddress();
34 } 40 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 DISALLOW_ALLOCATION(); 74 DISALLOW_ALLOCATION();
69 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListElement); 75 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListElement);
70 }; 76 };
71 77
72 78
73 class FreeList { 79 class FreeList {
74 public: 80 public:
75 FreeList(); 81 FreeList();
76 ~FreeList(); 82 ~FreeList();
77 83
78 uword TryAllocate(intptr_t size); 84 uword TryAllocate(intptr_t size, bool is_protected);
79 void Free(uword addr, intptr_t size); 85 void Free(uword addr, intptr_t size);
80 86
81 void Reset(); 87 void Reset();
82 88
83 intptr_t Length(int index) const; 89 intptr_t Length(int index) const;
84 90
85 void Print() const; 91 void Print() const;
86 92
87 private: 93 private:
88 static const int kNumLists = 128; 94 static const int kNumLists = 128;
89 95
90 static intptr_t IndexForSize(intptr_t size); 96 static intptr_t IndexForSize(intptr_t size);
91 97
92 void EnqueueElement(FreeListElement* element, intptr_t index); 98 void EnqueueElement(FreeListElement* element, intptr_t index);
93 FreeListElement* DequeueElement(intptr_t index); 99 FreeListElement* DequeueElement(intptr_t index);
94 100
95 void SplitElementAfterAndEnqueue(FreeListElement* element, intptr_t size); 101 void SplitElementAfterAndEnqueue(FreeListElement* element,
102 intptr_t size,
103 bool is_protected);
96 104
97 void PrintSmall() const; 105 void PrintSmall() const;
98 void PrintLarge() const; 106 void PrintLarge() const;
99 107
100 BitSet<kNumLists> free_map_; 108 BitSet<kNumLists> free_map_;
101 109
102 FreeListElement* free_lists_[kNumLists + 1]; 110 FreeListElement* free_lists_[kNumLists + 1];
103 111
104 DISALLOW_COPY_AND_ASSIGN(FreeList); 112 DISALLOW_COPY_AND_ASSIGN(FreeList);
105 }; 113 };
106 114
107 } // namespace dart 115 } // namespace dart
108 116
109 #endif // VM_FREELIST_H_ 117 #endif // VM_FREELIST_H_
OLDNEW
« no previous file with comments | « runtime/vm/debugger.cc ('k') | runtime/vm/freelist.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698