OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_HEAP_SPACES_H_ | 5 #ifndef V8_HEAP_SPACES_H_ |
6 #define V8_HEAP_SPACES_H_ | 6 #define V8_HEAP_SPACES_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/atomic-utils.h" | 9 #include "src/atomic-utils.h" |
10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
(...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 | 1537 |
1538 // Reset the allocation statistics (i.e., available = capacity with no wasted | 1538 // Reset the allocation statistics (i.e., available = capacity with no wasted |
1539 // or allocated bytes). | 1539 // or allocated bytes). |
1540 void Reset() { | 1540 void Reset() { |
1541 size_ = 0; | 1541 size_ = 0; |
1542 } | 1542 } |
1543 | 1543 |
1544 // Accessors for the allocation statistics. | 1544 // Accessors for the allocation statistics. |
1545 intptr_t Capacity() { return capacity_; } | 1545 intptr_t Capacity() { return capacity_; } |
1546 intptr_t MaxCapacity() { return max_capacity_; } | 1546 intptr_t MaxCapacity() { return max_capacity_; } |
1547 intptr_t Size() { return size_; } | 1547 intptr_t Size() { |
| 1548 CHECK_GE(size_, 0); |
| 1549 return size_; |
| 1550 } |
1548 | 1551 |
1549 // Grow the space by adding available bytes. They are initially marked as | 1552 // Grow the space by adding available bytes. They are initially marked as |
1550 // being in use (part of the size), but will normally be immediately freed, | 1553 // being in use (part of the size), but will normally be immediately freed, |
1551 // putting them on the free list and removing them from size_. | 1554 // putting them on the free list and removing them from size_. |
1552 void ExpandSpace(int size_in_bytes) { | 1555 void ExpandSpace(int size_in_bytes) { |
1553 capacity_ += size_in_bytes; | 1556 capacity_ += size_in_bytes; |
1554 size_ += size_in_bytes; | 1557 size_ += size_in_bytes; |
1555 if (capacity_ > max_capacity_) { | 1558 if (capacity_ > max_capacity_) { |
1556 max_capacity_ = capacity_; | 1559 max_capacity_ = capacity_; |
1557 } | 1560 } |
1558 DCHECK(size_ >= 0); | 1561 CHECK(size_ >= 0); |
1559 } | 1562 } |
1560 | 1563 |
1561 // Shrink the space by removing available bytes. Since shrinking is done | 1564 // Shrink the space by removing available bytes. Since shrinking is done |
1562 // during sweeping, bytes have been marked as being in use (part of the size) | 1565 // during sweeping, bytes have been marked as being in use (part of the size) |
1563 // and are hereby freed. | 1566 // and are hereby freed. |
1564 void ShrinkSpace(int size_in_bytes) { | 1567 void ShrinkSpace(int size_in_bytes) { |
1565 capacity_ -= size_in_bytes; | 1568 capacity_ -= size_in_bytes; |
1566 size_ -= size_in_bytes; | 1569 size_ -= size_in_bytes; |
1567 DCHECK(size_ >= 0); | 1570 CHECK(size_ >= 0); |
1568 } | 1571 } |
1569 | 1572 |
1570 // Allocate from available bytes (available -> size). | 1573 // Allocate from available bytes (available -> size). |
1571 void AllocateBytes(intptr_t size_in_bytes) { | 1574 void AllocateBytes(intptr_t size_in_bytes) { |
1572 size_ += size_in_bytes; | 1575 size_ += size_in_bytes; |
1573 DCHECK(size_ >= 0); | 1576 CHECK(size_ >= 0); |
1574 } | 1577 } |
1575 | 1578 |
1576 // Free allocated bytes, making them available (size -> available). | 1579 // Free allocated bytes, making them available (size -> available). |
1577 void DeallocateBytes(intptr_t size_in_bytes) { | 1580 void DeallocateBytes(intptr_t size_in_bytes) { |
1578 size_ -= size_in_bytes; | 1581 size_ -= size_in_bytes; |
1579 DCHECK_GE(size_, 0); | 1582 CHECK_GE(size_, 0); |
1580 } | 1583 } |
1581 | 1584 |
1582 // Merge {other} into {this}. | 1585 // Merge {other} into {this}. |
1583 void Merge(const AllocationStats& other) { | 1586 void Merge(const AllocationStats& other) { |
1584 capacity_ += other.capacity_; | 1587 capacity_ += other.capacity_; |
1585 size_ += other.size_; | 1588 size_ += other.size_; |
1586 if (other.max_capacity_ > max_capacity_) { | 1589 if (other.max_capacity_ > max_capacity_) { |
1587 max_capacity_ = other.max_capacity_; | 1590 max_capacity_ = other.max_capacity_; |
1588 } | 1591 } |
| 1592 CHECK_GE(size_, 0); |
1589 } | 1593 } |
1590 | 1594 |
1591 void DecreaseCapacity(intptr_t size_in_bytes) { | 1595 void DecreaseCapacity(intptr_t size_in_bytes) { |
1592 capacity_ -= size_in_bytes; | 1596 capacity_ -= size_in_bytes; |
1593 DCHECK_GE(capacity_, 0); | 1597 CHECK_GE(capacity_, 0); |
1594 DCHECK_GE(capacity_, size_); | 1598 CHECK_GE(capacity_, size_); |
1595 } | 1599 } |
1596 | 1600 |
1597 void IncreaseCapacity(intptr_t size_in_bytes) { capacity_ += size_in_bytes; } | 1601 void IncreaseCapacity(intptr_t size_in_bytes) { capacity_ += size_in_bytes; } |
1598 | 1602 |
1599 private: | 1603 private: |
1600 // |capacity_|: The number of object-area bytes (i.e., not including page | 1604 // |capacity_|: The number of object-area bytes (i.e., not including page |
1601 // bookkeeping structures) currently in the space. | 1605 // bookkeeping structures) currently in the space. |
1602 intptr_t capacity_; | 1606 intptr_t capacity_; |
1603 | 1607 |
1604 // |max_capacity_|: The maximum capacity ever observed. | 1608 // |max_capacity_|: The maximum capacity ever observed. |
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3124 count = 0; | 3128 count = 0; |
3125 } | 3129 } |
3126 // Must be small, since an iteration is used for lookup. | 3130 // Must be small, since an iteration is used for lookup. |
3127 static const int kMaxComments = 64; | 3131 static const int kMaxComments = 64; |
3128 }; | 3132 }; |
3129 #endif | 3133 #endif |
3130 } // namespace internal | 3134 } // namespace internal |
3131 } // namespace v8 | 3135 } // namespace v8 |
3132 | 3136 |
3133 #endif // V8_HEAP_SPACES_H_ | 3137 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |