OLD | NEW |
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 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 | 1228 |
1229 // Grow the space by adding available bytes. They are initially marked as | 1229 // Grow the space by adding available bytes. They are initially marked as |
1230 // being in use (part of the size), but will normally be immediately freed, | 1230 // being in use (part of the size), but will normally be immediately freed, |
1231 // putting them on the free list and removing them from size_. | 1231 // putting them on the free list and removing them from size_. |
1232 void ExpandSpace(int size_in_bytes) { | 1232 void ExpandSpace(int size_in_bytes) { |
1233 capacity_ += size_in_bytes; | 1233 capacity_ += size_in_bytes; |
1234 size_ += size_in_bytes; | 1234 size_ += size_in_bytes; |
1235 ASSERT(size_ >= 0); | 1235 ASSERT(size_ >= 0); |
1236 } | 1236 } |
1237 | 1237 |
| 1238 // Shrink the space by removing available bytes. Since shrinking is done |
| 1239 // during sweeping, bytes have been marked as being in use (part of the size) |
| 1240 // and are hereby freed. |
| 1241 void ShrinkSpace(int size_in_bytes) { |
| 1242 capacity_ -= size_in_bytes; |
| 1243 size_ -= size_in_bytes; |
| 1244 ASSERT(size_ >= 0); |
| 1245 } |
| 1246 |
1238 // Allocate from available bytes (available -> size). | 1247 // Allocate from available bytes (available -> size). |
1239 void AllocateBytes(intptr_t size_in_bytes) { | 1248 void AllocateBytes(intptr_t size_in_bytes) { |
1240 size_ += size_in_bytes; | 1249 size_ += size_in_bytes; |
1241 ASSERT(size_ >= 0); | 1250 ASSERT(size_ >= 0); |
1242 } | 1251 } |
1243 | 1252 |
1244 // Free allocated bytes, making them available (size -> available). | 1253 // Free allocated bytes, making them available (size -> available). |
1245 void DeallocateBytes(intptr_t size_in_bytes) { | 1254 void DeallocateBytes(intptr_t size_in_bytes) { |
1246 size_ -= size_in_bytes; | 1255 size_ -= size_in_bytes; |
1247 ASSERT(size_ >= 0); | 1256 ASSERT(size_ >= 0); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 // Give a block of memory to the space's free list. It might be added to | 1486 // Give a block of memory to the space's free list. It might be added to |
1478 // the free list or accounted as waste. | 1487 // the free list or accounted as waste. |
1479 // If add_to_freelist is false then just accounting stats are updated and | 1488 // If add_to_freelist is false then just accounting stats are updated and |
1480 // no attempt to add area to free list is made. | 1489 // no attempt to add area to free list is made. |
1481 int Free(Address start, int size_in_bytes) { | 1490 int Free(Address start, int size_in_bytes) { |
1482 int wasted = free_list_.Free(start, size_in_bytes); | 1491 int wasted = free_list_.Free(start, size_in_bytes); |
1483 accounting_stats_.DeallocateBytes(size_in_bytes - wasted); | 1492 accounting_stats_.DeallocateBytes(size_in_bytes - wasted); |
1484 return size_in_bytes - wasted; | 1493 return size_in_bytes - wasted; |
1485 } | 1494 } |
1486 | 1495 |
1487 int FreeOrUnmapPage(Page* page, Address start, int size_in_bytes); | |
1488 | |
1489 // Set space allocation info. | 1496 // Set space allocation info. |
1490 void SetTop(Address top, Address limit) { | 1497 void SetTop(Address top, Address limit) { |
1491 ASSERT(top == limit || | 1498 ASSERT(top == limit || |
1492 Page::FromAddress(top) == Page::FromAddress(limit - 1)); | 1499 Page::FromAddress(top) == Page::FromAddress(limit - 1)); |
1493 allocation_info_.top = top; | 1500 allocation_info_.top = top; |
1494 allocation_info_.limit = limit; | 1501 allocation_info_.limit = limit; |
1495 } | 1502 } |
1496 | 1503 |
1497 void Allocate(int bytes) { | 1504 void Allocate(int bytes) { |
1498 accounting_stats_.AllocateBytes(bytes); | 1505 accounting_stats_.AllocateBytes(bytes); |
1499 } | 1506 } |
1500 | 1507 |
1501 void IncreaseCapacity(int size) { | 1508 void IncreaseCapacity(int size) { |
1502 accounting_stats_.ExpandSpace(size); | 1509 accounting_stats_.ExpandSpace(size); |
1503 } | 1510 } |
1504 | 1511 |
1505 // Releases half of unused pages. | 1512 // Releases an unused page and shrinks the space. |
1506 void Shrink(); | 1513 void ReleasePage(Page* page); |
| 1514 |
| 1515 // Releases all of the unused pages. |
| 1516 void ReleaseAllUnusedPages(); |
1507 | 1517 |
1508 // The dummy page that anchors the linked list of pages. | 1518 // The dummy page that anchors the linked list of pages. |
1509 Page* anchor() { return &anchor_; } | 1519 Page* anchor() { return &anchor_; } |
1510 | 1520 |
1511 #ifdef DEBUG | 1521 #ifdef DEBUG |
1512 // Print meta info and objects in this space. | 1522 // Print meta info and objects in this space. |
1513 virtual void Print(); | 1523 virtual void Print(); |
1514 | 1524 |
1515 // Verify integrity of this space. | 1525 // Verify integrity of this space. |
1516 virtual void Verify(ObjectVisitor* visitor); | 1526 virtual void Verify(ObjectVisitor* visitor); |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2609 } | 2619 } |
2610 // Must be small, since an iteration is used for lookup. | 2620 // Must be small, since an iteration is used for lookup. |
2611 static const int kMaxComments = 64; | 2621 static const int kMaxComments = 64; |
2612 }; | 2622 }; |
2613 #endif | 2623 #endif |
2614 | 2624 |
2615 | 2625 |
2616 } } // namespace v8::internal | 2626 } } // namespace v8::internal |
2617 | 2627 |
2618 #endif // V8_SPACES_H_ | 2628 #endif // V8_SPACES_H_ |
OLD | NEW |