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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 static const intptr_t kLiveBytesOffset = | 500 static const intptr_t kLiveBytesOffset = |
501 kSizeOffset + kPointerSize + kPointerSize + kPointerSize + | 501 kSizeOffset + kPointerSize + kPointerSize + kPointerSize + |
502 kPointerSize + kPointerSize + | 502 kPointerSize + kPointerSize + |
503 kPointerSize + kPointerSize + kPointerSize + kIntSize; | 503 kPointerSize + kPointerSize + kPointerSize + kIntSize; |
504 | 504 |
505 static const size_t kSlotsBufferOffset = kLiveBytesOffset + kIntSize; | 505 static const size_t kSlotsBufferOffset = kLiveBytesOffset + kIntSize; |
506 | 506 |
507 static const size_t kWriteBarrierCounterOffset = | 507 static const size_t kWriteBarrierCounterOffset = |
508 kSlotsBufferOffset + kPointerSize + kPointerSize; | 508 kSlotsBufferOffset + kPointerSize + kPointerSize; |
509 | 509 |
510 static const size_t kHeaderSize = kWriteBarrierCounterOffset + kPointerSize; | 510 static const size_t kHeaderSize = |
| 511 kWriteBarrierCounterOffset + kPointerSize + kPointerSize; |
511 | 512 |
512 static const int kBodyOffset = | 513 static const int kBodyOffset = |
513 CODE_POINTER_ALIGN(MAP_POINTER_ALIGN(kHeaderSize + Bitmap::kSize)); | 514 CODE_POINTER_ALIGN(MAP_POINTER_ALIGN(kHeaderSize + Bitmap::kSize)); |
514 | 515 |
515 // The start offset of the object area in a page. Aligned to both maps and | 516 // The start offset of the object area in a page. Aligned to both maps and |
516 // code alignment to be suitable for both. Also aligned to 32 words because | 517 // code alignment to be suitable for both. Also aligned to 32 words because |
517 // the marking bitmap is arranged in 32 bit chunks. | 518 // the marking bitmap is arranged in 32 bit chunks. |
518 static const int kObjectStartAlignment = 32 * kPointerSize; | 519 static const int kObjectStartAlignment = 32 * kPointerSize; |
519 static const int kObjectStartOffset = kBodyOffset - 1 + | 520 static const int kObjectStartOffset = kBodyOffset - 1 + |
520 (kObjectStartAlignment - (kBodyOffset - 1) % kObjectStartAlignment); | 521 (kObjectStartAlignment - (kBodyOffset - 1) % kObjectStartAlignment); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 ASSERT(slots_buffer_ == NULL); | 613 ASSERT(slots_buffer_ == NULL); |
613 ClearFlag(EVACUATION_CANDIDATE); | 614 ClearFlag(EVACUATION_CANDIDATE); |
614 } | 615 } |
615 | 616 |
616 Address area_start() { return area_start_; } | 617 Address area_start() { return area_start_; } |
617 Address area_end() { return area_end_; } | 618 Address area_end() { return area_end_; } |
618 int area_size() { | 619 int area_size() { |
619 return static_cast<int>(area_end() - area_start()); | 620 return static_cast<int>(area_end() - area_start()); |
620 } | 621 } |
621 | 622 |
| 623 // Approximate amount of physical memory committed for this chunk. |
| 624 size_t CommittedPhysicalMemory() { |
| 625 return high_water_mark_; |
| 626 } |
| 627 |
| 628 static inline void UpdateHighWaterMark(Address mark); |
| 629 |
622 protected: | 630 protected: |
623 MemoryChunk* next_chunk_; | 631 MemoryChunk* next_chunk_; |
624 MemoryChunk* prev_chunk_; | 632 MemoryChunk* prev_chunk_; |
625 size_t size_; | 633 size_t size_; |
626 intptr_t flags_; | 634 intptr_t flags_; |
627 | 635 |
628 // Start and end of allocatable memory on this chunk. | 636 // Start and end of allocatable memory on this chunk. |
629 Address area_start_; | 637 Address area_start_; |
630 Address area_end_; | 638 Address area_end_; |
631 | 639 |
632 // If the chunk needs to remember its memory reservation, it is stored here. | 640 // If the chunk needs to remember its memory reservation, it is stored here. |
633 VirtualMemory reservation_; | 641 VirtualMemory reservation_; |
634 // The identity of the owning space. This is tagged as a failure pointer, but | 642 // The identity of the owning space. This is tagged as a failure pointer, but |
635 // no failure can be in an object, so this can be distinguished from any entry | 643 // no failure can be in an object, so this can be distinguished from any entry |
636 // in a fixed array. | 644 // in a fixed array. |
637 Address owner_; | 645 Address owner_; |
638 Heap* heap_; | 646 Heap* heap_; |
639 // Used by the store buffer to keep track of which pages to mark scan-on- | 647 // Used by the store buffer to keep track of which pages to mark scan-on- |
640 // scavenge. | 648 // scavenge. |
641 int store_buffer_counter_; | 649 int store_buffer_counter_; |
642 // Count of bytes marked black on page. | 650 // Count of bytes marked black on page. |
643 int live_byte_count_; | 651 int live_byte_count_; |
644 SlotsBuffer* slots_buffer_; | 652 SlotsBuffer* slots_buffer_; |
645 SkipList* skip_list_; | 653 SkipList* skip_list_; |
646 intptr_t write_barrier_counter_; | 654 intptr_t write_barrier_counter_; |
| 655 // Assuming the initial allocation on a page is sequential, |
| 656 // count highest number of bytes ever allocated on the page. |
| 657 int high_water_mark_; |
647 | 658 |
648 static MemoryChunk* Initialize(Heap* heap, | 659 static MemoryChunk* Initialize(Heap* heap, |
649 Address base, | 660 Address base, |
650 size_t size, | 661 size_t size, |
651 Address area_start, | 662 Address area_start, |
652 Address area_end, | 663 Address area_end, |
653 Executability executable, | 664 Executability executable, |
654 Space* owner); | 665 Space* owner); |
655 | 666 |
656 friend class MemoryAllocator; | 667 friend class MemoryAllocator; |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 // Prepares for a mark-compact GC. | 1497 // Prepares for a mark-compact GC. |
1487 virtual void PrepareForMarkCompact(); | 1498 virtual void PrepareForMarkCompact(); |
1488 | 1499 |
1489 // Current capacity without growing (Size() + Available()). | 1500 // Current capacity without growing (Size() + Available()). |
1490 intptr_t Capacity() { return accounting_stats_.Capacity(); } | 1501 intptr_t Capacity() { return accounting_stats_.Capacity(); } |
1491 | 1502 |
1492 // Total amount of memory committed for this space. For paged | 1503 // Total amount of memory committed for this space. For paged |
1493 // spaces this equals the capacity. | 1504 // spaces this equals the capacity. |
1494 intptr_t CommittedMemory() { return Capacity(); } | 1505 intptr_t CommittedMemory() { return Capacity(); } |
1495 | 1506 |
| 1507 // Approximate amount of physical memory committed for this space. |
| 1508 size_t CommittedPhysicalMemory(); |
| 1509 |
1496 // Sets the capacity, the available space and the wasted space to zero. | 1510 // Sets the capacity, the available space and the wasted space to zero. |
1497 // The stats are rebuilt during sweeping by adding each page to the | 1511 // The stats are rebuilt during sweeping by adding each page to the |
1498 // capacity and the size when it is encountered. As free spaces are | 1512 // capacity and the size when it is encountered. As free spaces are |
1499 // discovered during the sweeping they are subtracted from the size and added | 1513 // discovered during the sweeping they are subtracted from the size and added |
1500 // to the available and wasted totals. | 1514 // to the available and wasted totals. |
1501 void ClearStats() { | 1515 void ClearStats() { |
1502 accounting_stats_.ClearSizeWaste(); | 1516 accounting_stats_.ClearSizeWaste(); |
1503 } | 1517 } |
1504 | 1518 |
1505 // Available bytes without growing. These are the bytes on the free list. | 1519 // Available bytes without growing. These are the bytes on the free list. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 } | 1560 } |
1547 | 1561 |
1548 void ResetFreeList() { | 1562 void ResetFreeList() { |
1549 free_list_.Reset(); | 1563 free_list_.Reset(); |
1550 } | 1564 } |
1551 | 1565 |
1552 // Set space allocation info. | 1566 // Set space allocation info. |
1553 void SetTop(Address top, Address limit) { | 1567 void SetTop(Address top, Address limit) { |
1554 ASSERT(top == limit || | 1568 ASSERT(top == limit || |
1555 Page::FromAddress(top) == Page::FromAddress(limit - 1)); | 1569 Page::FromAddress(top) == Page::FromAddress(limit - 1)); |
| 1570 MemoryChunk::UpdateHighWaterMark(allocation_info_.top); |
1556 allocation_info_.top = top; | 1571 allocation_info_.top = top; |
1557 allocation_info_.limit = limit; | 1572 allocation_info_.limit = limit; |
1558 } | 1573 } |
1559 | 1574 |
1560 void Allocate(int bytes) { | 1575 void Allocate(int bytes) { |
1561 accounting_stats_.AllocateBytes(bytes); | 1576 accounting_stats_.AllocateBytes(bytes); |
1562 } | 1577 } |
1563 | 1578 |
1564 void IncreaseCapacity(int size) { | 1579 void IncreaseCapacity(int size) { |
1565 accounting_stats_.ExpandSpace(size); | 1580 accounting_stats_.ExpandSpace(size); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 // Returns the maximum capacity of the semi space. | 1967 // Returns the maximum capacity of the semi space. |
1953 int MaximumCapacity() { return maximum_capacity_; } | 1968 int MaximumCapacity() { return maximum_capacity_; } |
1954 | 1969 |
1955 // Returns the initial capacity of the semi space. | 1970 // Returns the initial capacity of the semi space. |
1956 int InitialCapacity() { return initial_capacity_; } | 1971 int InitialCapacity() { return initial_capacity_; } |
1957 | 1972 |
1958 SemiSpaceId id() { return id_; } | 1973 SemiSpaceId id() { return id_; } |
1959 | 1974 |
1960 static void Swap(SemiSpace* from, SemiSpace* to); | 1975 static void Swap(SemiSpace* from, SemiSpace* to); |
1961 | 1976 |
| 1977 // Approximate amount of physical memory committed for this space. |
| 1978 size_t CommittedPhysicalMemory(); |
| 1979 |
1962 private: | 1980 private: |
1963 // Flips the semispace between being from-space and to-space. | 1981 // Flips the semispace between being from-space and to-space. |
1964 // Copies the flags into the masked positions on all pages in the space. | 1982 // Copies the flags into the masked positions on all pages in the space. |
1965 void FlipPages(intptr_t flags, intptr_t flag_mask); | 1983 void FlipPages(intptr_t flags, intptr_t flag_mask); |
1966 | 1984 |
1967 NewSpacePage* anchor() { return &anchor_; } | 1985 NewSpacePage* anchor() { return &anchor_; } |
1968 | 1986 |
1969 // The current and maximum capacity of the space. | 1987 // The current and maximum capacity of the space. |
1970 int capacity_; | 1988 int capacity_; |
1971 int maximum_capacity_; | 1989 int maximum_capacity_; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2149 ASSERT(to_space_.Capacity() == from_space_.Capacity()); | 2167 ASSERT(to_space_.Capacity() == from_space_.Capacity()); |
2150 return to_space_.Capacity(); | 2168 return to_space_.Capacity(); |
2151 } | 2169 } |
2152 | 2170 |
2153 // Return the total amount of memory committed for new space. | 2171 // Return the total amount of memory committed for new space. |
2154 intptr_t CommittedMemory() { | 2172 intptr_t CommittedMemory() { |
2155 if (from_space_.is_committed()) return 2 * Capacity(); | 2173 if (from_space_.is_committed()) return 2 * Capacity(); |
2156 return Capacity(); | 2174 return Capacity(); |
2157 } | 2175 } |
2158 | 2176 |
| 2177 // Approximate amount of physical memory committed for this space. |
| 2178 size_t CommittedPhysicalMemory(); |
| 2179 |
2159 // Return the available bytes without growing. | 2180 // Return the available bytes without growing. |
2160 intptr_t Available() { | 2181 intptr_t Available() { |
2161 return Capacity() - Size(); | 2182 return Capacity() - Size(); |
2162 } | 2183 } |
2163 | 2184 |
2164 // Return the maximum capacity of a semispace. | 2185 // Return the maximum capacity of a semispace. |
2165 int MaximumCapacity() { | 2186 int MaximumCapacity() { |
2166 ASSERT(to_space_.MaximumCapacity() == from_space_.MaximumCapacity()); | 2187 ASSERT(to_space_.MaximumCapacity() == from_space_.MaximumCapacity()); |
2167 return to_space_.MaximumCapacity(); | 2188 return to_space_.MaximumCapacity(); |
2168 } | 2189 } |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2516 } | 2537 } |
2517 | 2538 |
2518 virtual intptr_t SizeOfObjects() { | 2539 virtual intptr_t SizeOfObjects() { |
2519 return objects_size_; | 2540 return objects_size_; |
2520 } | 2541 } |
2521 | 2542 |
2522 intptr_t CommittedMemory() { | 2543 intptr_t CommittedMemory() { |
2523 return Size(); | 2544 return Size(); |
2524 } | 2545 } |
2525 | 2546 |
| 2547 // Approximate amount of physical memory committed for this space. |
| 2548 size_t CommittedPhysicalMemory(); |
| 2549 |
2526 int PageCount() { | 2550 int PageCount() { |
2527 return page_count_; | 2551 return page_count_; |
2528 } | 2552 } |
2529 | 2553 |
2530 // Finds an object for a given address, returns Failure::Exception() | 2554 // Finds an object for a given address, returns Failure::Exception() |
2531 // if it is not found. The function iterates through all objects in this | 2555 // if it is not found. The function iterates through all objects in this |
2532 // space, may be slow. | 2556 // space, may be slow. |
2533 MaybeObject* FindObject(Address a); | 2557 MaybeObject* FindObject(Address a); |
2534 | 2558 |
2535 // Finds a large object page containing the given address, returns NULL | 2559 // Finds a large object page containing the given address, returns NULL |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2668 } | 2692 } |
2669 // Must be small, since an iteration is used for lookup. | 2693 // Must be small, since an iteration is used for lookup. |
2670 static const int kMaxComments = 64; | 2694 static const int kMaxComments = 64; |
2671 }; | 2695 }; |
2672 #endif | 2696 #endif |
2673 | 2697 |
2674 | 2698 |
2675 } } // namespace v8::internal | 2699 } } // namespace v8::internal |
2676 | 2700 |
2677 #endif // V8_SPACES_H_ | 2701 #endif // V8_SPACES_H_ |
OLD | NEW |