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

Side by Side Diff: src/spaces.h

Issue 6970004: Introduce lazy sweeping. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Created 9 years, 7 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 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 public: 1007 public:
1008 AllocationStats() { Clear(); } 1008 AllocationStats() { Clear(); }
1009 1009
1010 // Zero out all the allocation statistics (ie, no capacity). 1010 // Zero out all the allocation statistics (ie, no capacity).
1011 void Clear() { 1011 void Clear() {
1012 capacity_ = 0; 1012 capacity_ = 0;
1013 size_ = 0; 1013 size_ = 0;
1014 waste_ = 0; 1014 waste_ = 0;
1015 } 1015 }
1016 1016
1017 void ClearSizeWaste() {
1018 size_ = capacity_;
1019 waste_ = 0;
1020 }
1021
Erik Corry 2011/05/09 21:20:11 Extra blank line here.
1022
1017 // Reset the allocation statistics (ie, available = capacity with no 1023 // Reset the allocation statistics (ie, available = capacity with no
1018 // wasted or allocated bytes). 1024 // wasted or allocated bytes).
1019 void Reset() { 1025 void Reset() {
1020 size_ = 0; 1026 size_ = 0;
1021 waste_ = 0; 1027 waste_ = 0;
1022 } 1028 }
1023 1029
1024 // Accessors for the allocation statistics. 1030 // Accessors for the allocation statistics.
1025 intptr_t Capacity() { return capacity_; } 1031 intptr_t Capacity() { return capacity_; }
1026 intptr_t Size() { return size_; } 1032 intptr_t Size() { return size_; }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 1230
1225 // Total amount of memory committed for this space. For paged 1231 // Total amount of memory committed for this space. For paged
1226 // spaces this equals the capacity. 1232 // spaces this equals the capacity.
1227 intptr_t CommittedMemory() { return Capacity(); } 1233 intptr_t CommittedMemory() { return Capacity(); }
1228 1234
1229 // Sets the capacity, the available space and the wasted space to zero. 1235 // Sets the capacity, the available space and the wasted space to zero.
1230 // The stats are rebuilt during sweeping by adding each page to the 1236 // The stats are rebuilt during sweeping by adding each page to the
1231 // capacity and the size when it is encountered. As free spaces are 1237 // capacity and the size when it is encountered. As free spaces are
1232 // discovered during the sweeping they are subtracted from the size and added 1238 // discovered during the sweeping they are subtracted from the size and added
1233 // to the available and wasted totals. 1239 // to the available and wasted totals.
1234 void ClearStats() { accounting_stats_.Clear(); } 1240 void ClearStats() {
1241 accounting_stats_.ClearSizeWaste();
1242 }
1235 1243
1236 // Available bytes without growing. These are the bytes on the free list. 1244 // Available bytes without growing. These are the bytes on the free list.
1237 // The bytes in the linear allocation area are not included in this total 1245 // The bytes in the linear allocation area are not included in this total
1238 // because updating the stats would slow down allocation. New pages are 1246 // because updating the stats would slow down allocation. New pages are
1239 // immediately added to the free list so they show up here. 1247 // immediately added to the free list so they show up here.
1240 intptr_t Available() { return free_list_.available(); } 1248 intptr_t Available() { return free_list_.available(); }
1241 1249
1242 // Allocated bytes in this space. Garbage bytes that were not found due to 1250 // Allocated bytes in this space. Garbage bytes that were not found due to
1243 // lazy sweeping are counted as being allocated! The bytes in the current 1251 // lazy sweeping are counted as being allocated! The bytes in the current
1244 // linear allocation area (between top and limit) are also counted here. 1252 // linear allocation area (between top and limit) are also counted here.
(...skipping 15 matching lines...) Expand all
1260 // Allocate the requested number of bytes in the space if possible, return a 1268 // Allocate the requested number of bytes in the space if possible, return a
1261 // failure object if not. 1269 // failure object if not.
1262 MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes); 1270 MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes);
1263 1271
1264 virtual bool ReserveSpace(int bytes); 1272 virtual bool ReserveSpace(int bytes);
1265 1273
1266 // Give a block of memory to the space's free list. It might be added to 1274 // Give a block of memory to the space's free list. It might be added to
1267 // the free list or accounted as waste. 1275 // the free list or accounted as waste.
1268 // If add_to_freelist is false then just accounting stats are updated and 1276 // If add_to_freelist is false then just accounting stats are updated and
1269 // no attempt to add area to free list is made. 1277 // no attempt to add area to free list is made.
1270 void Free(Address start, int size_in_bytes) { 1278 int Free(Address start, int size_in_bytes) {
1271 int wasted = free_list_.Free(start, size_in_bytes); 1279 int wasted = free_list_.Free(start, size_in_bytes);
1272 accounting_stats_.DeallocateBytes(size_in_bytes - wasted); 1280 accounting_stats_.DeallocateBytes(size_in_bytes - wasted);
1281 return size_in_bytes - wasted;
1273 } 1282 }
1274 1283
1275 // Set space allocation info. 1284 // Set space allocation info.
1276 void SetTop(Address top, Address limit) { 1285 void SetTop(Address top, Address limit) {
1277 ASSERT(top == limit || 1286 ASSERT(top == limit ||
1278 Page::FromAddress(top) == Page::FromAddress(limit - 1)); 1287 Page::FromAddress(top) == Page::FromAddress(limit - 1));
1279 allocation_info_.top = top; 1288 allocation_info_.top = top;
1280 allocation_info_.limit = limit; 1289 allocation_info_.limit = limit;
1281 } 1290 }
1282 1291
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 1328
1320 // Report code object related statistics 1329 // Report code object related statistics
1321 void CollectCodeStatistics(); 1330 void CollectCodeStatistics();
1322 static void ReportCodeStatistics(); 1331 static void ReportCodeStatistics();
1323 static void ResetCodeStatistics(); 1332 static void ResetCodeStatistics();
1324 #endif 1333 #endif
1325 1334
1326 bool was_swept_conservatively() { return was_swept_conservatively_; } 1335 bool was_swept_conservatively() { return was_swept_conservatively_; }
1327 void set_was_swept_conservatively(bool b) { was_swept_conservatively_ = b; } 1336 void set_was_swept_conservatively(bool b) { was_swept_conservatively_ = b; }
1328 1337
1338 void SetPagesToSweep(Page* first, Page* last) {
1339 first_unswept_page_ = first;
1340 last_unswept_page_ = last;
1341
1342 Page* p = first;
1343 do {
1344 p->SetFlag(MemoryChunk::WAS_SWEPT_CONSERVATIVELY);
1345 p = p->next_page();
1346 } while (p != last);
1347 }
1348
1349 bool AdvanceSweeper(intptr_t bytes_to_sweep);
1350
1351 bool IsSweepingComplete() {
1352 return !first_unswept_page_->is_valid();
1353 }
1354
1355 Page* FirstPage() { return anchor_.next_page(); }
1356 Page* LastPage() { return anchor_.prev_page(); }
1357
1329 protected: 1358 protected:
1330 // Maximum capacity of this space. 1359 // Maximum capacity of this space.
1331 intptr_t max_capacity_; 1360 intptr_t max_capacity_;
1332 1361
1333 // Accounting information for this space. 1362 // Accounting information for this space.
1334 AllocationStats accounting_stats_; 1363 AllocationStats accounting_stats_;
1335 1364
1336 // The dummy page that anchors the double linked list of pages. 1365 // The dummy page that anchors the double linked list of pages.
1337 Page anchor_; 1366 Page anchor_;
1338 1367
1339 // The space's free list. 1368 // The space's free list.
1340 OldSpaceFreeList free_list_; 1369 OldSpaceFreeList free_list_;
1341 1370
1342 // Normal allocation information. 1371 // Normal allocation information.
1343 AllocationInfo allocation_info_; 1372 AllocationInfo allocation_info_;
1344 1373
1345 // Bytes of each page that cannot be allocated. Possibly non-zero 1374 // Bytes of each page that cannot be allocated. Possibly non-zero
1346 // for pages in spaces with only fixed-size objects. Always zero 1375 // for pages in spaces with only fixed-size objects. Always zero
1347 // for pages in spaces with variable sized objects (those pages are 1376 // for pages in spaces with variable sized objects (those pages are
1348 // padded with free-list nodes). 1377 // padded with free-list nodes).
1349 int page_extra_; 1378 int page_extra_;
1350 1379
1351 bool was_swept_conservatively_; 1380 bool was_swept_conservatively_;
1352 1381
1382 Page* first_unswept_page_;
1383 Page* last_unswept_page_;
1384
1353 // Sets allocation pointer. If the allocation pointer already pointed to a 1385 // Sets allocation pointer. If the allocation pointer already pointed to a
1354 // non-zero-length area then that area may be returned to the free list. 1386 // non-zero-length area then that area may be returned to the free list.
1355 void SetAllocationInfo(Address start, Address end); 1387 void SetAllocationInfo(Address start, Address end);
1356 1388
1357 // Expands the space by allocating a fixed number of pages. Returns false if 1389 // Expands the space by allocating a fixed number of pages. Returns false if
1358 // it cannot allocate requested number of pages from OS. 1390 // it cannot allocate requested number of pages from OS.
1359 bool Expand(); 1391 bool Expand();
1360 1392
1361 // Generic fast case allocation function that tries linear allocation at the 1393 // Generic fast case allocation function that tries linear allocation at the
1362 // address denoted by top in allocation_info_. 1394 // address denoted by top in allocation_info_.
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 } 2249 }
2218 // Must be small, since an iteration is used for lookup. 2250 // Must be small, since an iteration is used for lookup.
2219 static const int kMaxComments = 64; 2251 static const int kMaxComments = 64;
2220 }; 2252 };
2221 #endif 2253 #endif
2222 2254
2223 2255
2224 } } // namespace v8::internal 2256 } } // namespace v8::internal
2225 2257
2226 #endif // V8_SPACES_H_ 2258 #endif // V8_SPACES_H_
OLDNEW
« src/mark-compact.cc ('K') | « src/mark-compact.cc ('k') | src/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698