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

Side by Side Diff: src/spaces.h

Issue 6713075: Create an abstraction (MarkBit) object to hold the location of the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 9 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 ASSERT((0 <= index) && (index <= MapSpace::kMaxMapPageIndex)) 110 ASSERT((0 <= index) && (index <= MapSpace::kMaxMapPageIndex))
111 111
112 112
113 class PagedSpace; 113 class PagedSpace;
114 class MemoryAllocator; 114 class MemoryAllocator;
115 class AllocationInfo; 115 class AllocationInfo;
116 class Space; 116 class Space;
117 class OldSpaceFreeList; 117 class OldSpaceFreeList;
118 118
119 119
120
121 class MarkBit {
Vyacheslav Egorov (Chromium) 2011/03/21 16:54:23 // TODO(gc) ensure all operations inlined and obje
Erik Corry 2011/03/21 20:48:53 Checked on gcc/x86. TODO added.
122 public:
123 typedef uint32_t CellType;
124
125 inline MarkBit(CellType* cell, CellType mask)
126 : cell_(cell), mask_(mask) { }
127
128 inline CellType* cell() { return cell_; }
129 inline CellType mask() { return mask_; }
130
131 #ifdef DEBUG
132 bool operator==(const MarkBit& other) {
133 return cell_ == other.cell_ && mask_ == other.mask_;
134 }
135 #endif
136
137 inline void Set() { *cell_ |= mask_; }
138 inline bool Get() { return (*cell_ & mask_) != 0; }
139 inline void Clear() { *cell_ &= ~mask_; }
140
141 inline MarkBit Next() {
142 CellType new_mask = mask_ << 1;
143 if (new_mask == 0) {
144 return MarkBit(cell_ + 1, 1);
145 } else {
146 return MarkBit(cell_, new_mask);
147 }
148 }
149
150 private:
151 CellType* cell_;
152 CellType mask_;
153 };
154
155
120 // Bitmap is a sequence of cells each containing fixed number of bits. 156 // Bitmap is a sequence of cells each containing fixed number of bits.
121 template<typename StorageDescriptor> 157 template<typename StorageDescriptor>
122 class Bitmap { 158 class Bitmap {
123 public: 159 public:
124 typedef uint32_t CellType;
125 static const uint32_t kBitsPerCell = 32; 160 static const uint32_t kBitsPerCell = 32;
126 static const uint32_t kBitsPerCellLog2 = 5; 161 static const uint32_t kBitsPerCellLog2 = 5;
127 static const uint32_t kBitIndexMask = kBitsPerCell - 1; 162 static const uint32_t kBitIndexMask = kBitsPerCell - 1;
128 163
129 static int CellsForLength(int length) { 164 static int CellsForLength(int length) {
130 return (length + kBitsPerCell - 1) >> kBitsPerCellLog2; 165 return (length + kBitsPerCell - 1) >> kBitsPerCellLog2;
131 } 166 }
132 167
133 int CellsCount() { 168 int CellsCount() {
134 return StorageDescriptor::CellsCount(this->address()); 169 return StorageDescriptor::CellsCount(this->address());
135 } 170 }
136 171
137 static int SizeFor(int cells_count) { 172 static int SizeFor(int cells_count) {
138 return sizeof(CellType)*cells_count; 173 return sizeof(MarkBit::CellType)*cells_count;
139 } 174 }
140 175
141 INLINE(static uint32_t IndexToCell(uint32_t index)) { 176 INLINE(static uint32_t IndexToCell(uint32_t index)) {
142 return index >> kBitsPerCellLog2; 177 return index >> kBitsPerCellLog2;
143 } 178 }
144 179
145 INLINE(static uint32_t IndexToBit(uint32_t index)) {
146 return index & kBitIndexMask;
147 }
148
149 INLINE(static uint32_t CellToIndex(uint32_t index)) { 180 INLINE(static uint32_t CellToIndex(uint32_t index)) {
150 return index << kBitsPerCellLog2; 181 return index << kBitsPerCellLog2;
151 } 182 }
152 183
153 INLINE(static uint32_t CellAlignIndex(uint32_t index)) { 184 INLINE(static uint32_t CellAlignIndex(uint32_t index)) {
154 return (index + kBitIndexMask) & ~kBitIndexMask; 185 return (index + kBitIndexMask) & ~kBitIndexMask;
155 } 186 }
156 187
157 INLINE(CellType* cells()) { 188 INLINE(MarkBit::CellType* cells()) {
158 return reinterpret_cast<CellType*>(this); 189 return reinterpret_cast<MarkBit::CellType*>(this);
159 } 190 }
160 191
161 INLINE(Address address()) { 192 INLINE(Address address()) {
162 return reinterpret_cast<Address>(this); 193 return reinterpret_cast<Address>(this);
163 } 194 }
164 195
165 INLINE(static Bitmap* FromAddress(Address addr)) { 196 INLINE(static Bitmap* FromAddress(Address addr)) {
166 return reinterpret_cast<Bitmap*>(addr); 197 return reinterpret_cast<Bitmap*>(addr);
167 } 198 }
168 199
169 INLINE(static Bitmap* FromAddress(uint32_t* addr)) { 200 inline MarkBit MarkBitFromIndex(uint32_t index) {
170 return reinterpret_cast<Bitmap*>(addr); 201 MarkBit::CellType mask = 1 << (index & kBitIndexMask);
171 } 202 MarkBit::CellType* cell = this->cells() + (index >> kBitsPerCellLog2);
172 203 return MarkBit(cell, mask);
173 INLINE(bool TestAndSet(const uint32_t index)) {
174 const uint32_t mask = 1 << (index & kBitIndexMask);
175 if (cells()[index >> kBitsPerCellLog2] & mask) {
176 return true;
177 } else {
178 cells()[index >> kBitsPerCellLog2] |= mask;
179 return false;
180 }
181 }
182
183 INLINE(bool Get(uint32_t index)) {
184 uint32_t mask = 1 << (index & kBitIndexMask);
185 return (this->cells()[index >> kBitsPerCellLog2] & mask) != 0;
186 }
187
188 INLINE(void Set(uint32_t index)) {
189 uint32_t mask = 1 << (index & kBitIndexMask);
190 cells()[index >> kBitsPerCellLog2] |= mask;
191 }
192
193 INLINE(void Clear(uint32_t index)) {
194 uint32_t mask = 1 << (index & kBitIndexMask);
195 cells()[index >> kBitsPerCellLog2] &= ~mask;
196 } 204 }
197 205
198 INLINE(void ClearRange(uint32_t start, uint32_t size)) { 206 INLINE(void ClearRange(uint32_t start, uint32_t size)) {
199 const uint32_t end = start + size; 207 const uint32_t end = start + size;
200 const uint32_t start_cell = start >> kBitsPerCellLog2; 208 const uint32_t start_cell = start >> kBitsPerCellLog2;
201 const uint32_t end_cell = end >> kBitsPerCellLog2; 209 const uint32_t end_cell = end >> kBitsPerCellLog2;
202 210 ASSERT((start & kBitIndexMask) == 0);
203 const uint32_t start_mask = (-1) << (start & kBitIndexMask); 211 ASSERT((end & kBitIndexMask) == 0);
204 const uint32_t end_mask = (1 << (end & kBitIndexMask)) - 1;
205 212
206 ASSERT(static_cast<int>(start_cell) < CellsCount()); 213 ASSERT(static_cast<int>(start_cell) < CellsCount());
207 ASSERT(static_cast<int>(end_cell) < CellsCount() || 214 ASSERT(static_cast<int>(end_cell) <= CellsCount());
208 (end_mask == 0 && static_cast<int>(end_cell) == CellsCount()));
209 215
210 if (start_cell == end_cell) { 216 for (uint32_t cell = start_cell; cell < end_cell; cell++) {
211 cells()[start_cell] &= ~(start_mask & end_mask); 217 cells()[cell] = 0;
212 } else {
213 cells()[start_cell] &= ~start_mask;
214 if (end_mask != 0) cells()[end_cell] &= ~end_mask;
215
216 for (uint32_t cell = start_cell + 1, last_cell = end_cell - 1;
217 cell <= last_cell;
218 cell++) {
219 cells()[cell] = 0;
220 }
221 } 218 }
222 } 219 }
223 220
224 INLINE(void Clear()) { 221 INLINE(void Clear()) {
225 for (int i = 0; i < CellsCount(); i++) cells()[i] = 0; 222 for (int i = 0; i < CellsCount(); i++) cells()[i] = 0;
226 } 223 }
227 224
228 static void PrintWord(uint32_t word, uint32_t himask = 0) { 225 static void PrintWord(uint32_t word, uint32_t himask = 0) {
229 for (uint32_t mask = 1; mask != 0; mask <<= 1) { 226 for (uint32_t mask = 1; mask != 0; mask <<= 1) {
230 if ((mask & himask) != 0) PrintF("["); 227 if ((mask & himask) != 0) PrintF("[");
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 // Set the age mark in the active semispace. 1606 // Set the age mark in the active semispace.
1610 void set_age_mark(Address mark) { to_space_.set_age_mark(mark); } 1607 void set_age_mark(Address mark) { to_space_.set_age_mark(mark); }
1611 1608
1612 // The start address of the space and a bit mask. Anding an address in the 1609 // The start address of the space and a bit mask. Anding an address in the
1613 // new space with the mask will result in the start address. 1610 // new space with the mask will result in the start address.
1614 Address start() { return start_; } 1611 Address start() { return start_; }
1615 uintptr_t mask() { return address_mask_; } 1612 uintptr_t mask() { return address_mask_; }
1616 1613
1617 INLINE(uint32_t AddressToMarkbitIndex(Address addr)) { 1614 INLINE(uint32_t AddressToMarkbitIndex(Address addr)) {
1618 ASSERT(Contains(addr)); 1615 ASSERT(Contains(addr));
1619 ASSERT(IsAligned(OffsetFrom(addr), kPointerSize)); 1616 ASSERT(IsAligned(OffsetFrom(addr), kPointerSize) ||
1617 IsAligned(OffsetFrom(addr) - 1, kPointerSize));
1620 return static_cast<uint32_t>(addr - start_) >> kPointerSizeLog2; 1618 return static_cast<uint32_t>(addr - start_) >> kPointerSizeLog2;
1621 } 1619 }
1622 1620
1623 INLINE(Address MarkbitIndexToAddress(uint32_t index)) { 1621 INLINE(Address MarkbitIndexToAddress(uint32_t index)) {
1624 return reinterpret_cast<Address>(index << kPointerSizeLog2); 1622 return reinterpret_cast<Address>(index << kPointerSizeLog2);
1625 } 1623 }
1626 1624
1627 // The allocation top and limit addresses. 1625 // The allocation top and limit addresses.
1628 Address* allocation_top_address() { return &allocation_info_.top; } 1626 Address* allocation_top_address() { return &allocation_info_.top; }
1629 Address* allocation_limit_address() { return &allocation_info_.limit; } 1627 Address* allocation_limit_address() { return &allocation_info_.limit; }
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 1997
2000 private: 1998 private:
2001 LargePage* current_; 1999 LargePage* current_;
2002 HeapObjectCallback size_func_; 2000 HeapObjectCallback size_func_;
2003 }; 2001 };
2004 2002
2005 2003
2006 } } // namespace v8::internal 2004 } } // namespace v8::internal
2007 2005
2008 #endif // V8_SPACES_H_ 2006 #endif // V8_SPACES_H_
OLDNEW
« src/mark-compact.cc ('K') | « src/runtime-profiler.cc ('k') | src/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698