| 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 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 | 1115 |
| 1116 void PagedSpace::ResetFreeListStatistics() { | 1116 void PagedSpace::ResetFreeListStatistics() { |
| 1117 PageIterator page_iterator(this); | 1117 PageIterator page_iterator(this); |
| 1118 while (page_iterator.has_next()) { | 1118 while (page_iterator.has_next()) { |
| 1119 Page* page = page_iterator.next(); | 1119 Page* page = page_iterator.next(); |
| 1120 page->ResetFreeListStatistics(); | 1120 page->ResetFreeListStatistics(); |
| 1121 } | 1121 } |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 | 1124 |
| 1125 void PagedSpace::IncreaseCapacity(int size) { |
| 1126 accounting_stats_.ExpandSpace(size); |
| 1127 } |
| 1128 |
| 1129 |
| 1125 void PagedSpace::ReleasePage(Page* page, bool unlink) { | 1130 void PagedSpace::ReleasePage(Page* page, bool unlink) { |
| 1126 ASSERT(page->LiveBytes() == 0); | 1131 ASSERT(page->LiveBytes() == 0); |
| 1127 ASSERT(AreaSize() == page->area_size()); | 1132 ASSERT(AreaSize() == page->area_size()); |
| 1128 | 1133 |
| 1129 // Adjust list of unswept pages if the page is the head of the list. | 1134 // Adjust list of unswept pages if the page is the head of the list. |
| 1130 if (first_unswept_page_ == page) { | 1135 if (first_unswept_page_ == page) { |
| 1131 first_unswept_page_ = page->next_page(); | 1136 first_unswept_page_ = page->next_page(); |
| 1132 if (first_unswept_page_ == anchor()) { | 1137 if (first_unswept_page_ == anchor()) { |
| 1133 first_unswept_page_ = Page::FromAddress(NULL); | 1138 first_unswept_page_ = Page::FromAddress(NULL); |
| 1134 } | 1139 } |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 // Creates a space in the young generation. The constructor does not | 1509 // Creates a space in the young generation. The constructor does not |
| 1505 // allocate memory from the OS. A SemiSpace is given a contiguous chunk of | 1510 // allocate memory from the OS. A SemiSpace is given a contiguous chunk of |
| 1506 // memory of size 'capacity' when set up, and does not grow or shrink | 1511 // memory of size 'capacity' when set up, and does not grow or shrink |
| 1507 // otherwise. In the mark-compact collector, the memory region of the from | 1512 // otherwise. In the mark-compact collector, the memory region of the from |
| 1508 // space is used as the marking stack. It requires contiguous memory | 1513 // space is used as the marking stack. It requires contiguous memory |
| 1509 // addresses. | 1514 // addresses. |
| 1510 ASSERT(maximum_capacity >= Page::kPageSize); | 1515 ASSERT(maximum_capacity >= Page::kPageSize); |
| 1511 initial_capacity_ = RoundDown(initial_capacity, Page::kPageSize); | 1516 initial_capacity_ = RoundDown(initial_capacity, Page::kPageSize); |
| 1512 capacity_ = initial_capacity; | 1517 capacity_ = initial_capacity; |
| 1513 maximum_capacity_ = RoundDown(maximum_capacity, Page::kPageSize); | 1518 maximum_capacity_ = RoundDown(maximum_capacity, Page::kPageSize); |
| 1519 maximum_committed_ = 0; |
| 1514 committed_ = false; | 1520 committed_ = false; |
| 1515 start_ = start; | 1521 start_ = start; |
| 1516 address_mask_ = ~(maximum_capacity - 1); | 1522 address_mask_ = ~(maximum_capacity - 1); |
| 1517 object_mask_ = address_mask_ | kHeapObjectTagMask; | 1523 object_mask_ = address_mask_ | kHeapObjectTagMask; |
| 1518 object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag; | 1524 object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag; |
| 1519 age_mark_ = start_; | 1525 age_mark_ = start_; |
| 1520 } | 1526 } |
| 1521 | 1527 |
| 1522 | 1528 |
| 1523 void SemiSpace::TearDown() { | 1529 void SemiSpace::TearDown() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1536 } | 1542 } |
| 1537 | 1543 |
| 1538 NewSpacePage* current = anchor(); | 1544 NewSpacePage* current = anchor(); |
| 1539 for (int i = 0; i < pages; i++) { | 1545 for (int i = 0; i < pages; i++) { |
| 1540 NewSpacePage* new_page = | 1546 NewSpacePage* new_page = |
| 1541 NewSpacePage::Initialize(heap(), start_ + i * Page::kPageSize, this); | 1547 NewSpacePage::Initialize(heap(), start_ + i * Page::kPageSize, this); |
| 1542 new_page->InsertAfter(current); | 1548 new_page->InsertAfter(current); |
| 1543 current = new_page; | 1549 current = new_page; |
| 1544 } | 1550 } |
| 1545 | 1551 |
| 1552 SetCapacity(capacity_); |
| 1546 committed_ = true; | 1553 committed_ = true; |
| 1547 Reset(); | 1554 Reset(); |
| 1548 return true; | 1555 return true; |
| 1549 } | 1556 } |
| 1550 | 1557 |
| 1551 | 1558 |
| 1552 bool SemiSpace::Uncommit() { | 1559 bool SemiSpace::Uncommit() { |
| 1553 ASSERT(is_committed()); | 1560 ASSERT(is_committed()); |
| 1554 Address start = start_ + maximum_capacity_ - capacity_; | 1561 Address start = start_ + maximum_capacity_ - capacity_; |
| 1555 if (!heap()->isolate()->memory_allocator()->UncommitBlock(start, capacity_)) { | 1562 if (!heap()->isolate()->memory_allocator()->UncommitBlock(start, capacity_)) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1584 int pages_before = capacity_ / Page::kPageSize; | 1591 int pages_before = capacity_ / Page::kPageSize; |
| 1585 int pages_after = new_capacity / Page::kPageSize; | 1592 int pages_after = new_capacity / Page::kPageSize; |
| 1586 | 1593 |
| 1587 size_t delta = new_capacity - capacity_; | 1594 size_t delta = new_capacity - capacity_; |
| 1588 | 1595 |
| 1589 ASSERT(IsAligned(delta, OS::AllocateAlignment())); | 1596 ASSERT(IsAligned(delta, OS::AllocateAlignment())); |
| 1590 if (!heap()->isolate()->memory_allocator()->CommitBlock( | 1597 if (!heap()->isolate()->memory_allocator()->CommitBlock( |
| 1591 start_ + capacity_, delta, executable())) { | 1598 start_ + capacity_, delta, executable())) { |
| 1592 return false; | 1599 return false; |
| 1593 } | 1600 } |
| 1594 capacity_ = new_capacity; | 1601 SetCapacity(new_capacity); |
| 1595 NewSpacePage* last_page = anchor()->prev_page(); | 1602 NewSpacePage* last_page = anchor()->prev_page(); |
| 1596 ASSERT(last_page != anchor()); | 1603 ASSERT(last_page != anchor()); |
| 1597 for (int i = pages_before; i < pages_after; i++) { | 1604 for (int i = pages_before; i < pages_after; i++) { |
| 1598 Address page_address = start_ + i * Page::kPageSize; | 1605 Address page_address = start_ + i * Page::kPageSize; |
| 1599 NewSpacePage* new_page = NewSpacePage::Initialize(heap(), | 1606 NewSpacePage* new_page = NewSpacePage::Initialize(heap(), |
| 1600 page_address, | 1607 page_address, |
| 1601 this); | 1608 this); |
| 1602 new_page->InsertAfter(last_page); | 1609 new_page->InsertAfter(last_page); |
| 1603 Bitmap::Clear(new_page); | 1610 Bitmap::Clear(new_page); |
| 1604 // Duplicate the flags that was set on the old page. | 1611 // Duplicate the flags that was set on the old page. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1624 } | 1631 } |
| 1625 | 1632 |
| 1626 int pages_after = new_capacity / Page::kPageSize; | 1633 int pages_after = new_capacity / Page::kPageSize; |
| 1627 NewSpacePage* new_last_page = | 1634 NewSpacePage* new_last_page = |
| 1628 NewSpacePage::FromAddress(start_ + (pages_after - 1) * Page::kPageSize); | 1635 NewSpacePage::FromAddress(start_ + (pages_after - 1) * Page::kPageSize); |
| 1629 new_last_page->set_next_page(anchor()); | 1636 new_last_page->set_next_page(anchor()); |
| 1630 anchor()->set_prev_page(new_last_page); | 1637 anchor()->set_prev_page(new_last_page); |
| 1631 ASSERT((current_page_ >= first_page()) && (current_page_ <= new_last_page)); | 1638 ASSERT((current_page_ >= first_page()) && (current_page_ <= new_last_page)); |
| 1632 } | 1639 } |
| 1633 | 1640 |
| 1634 capacity_ = new_capacity; | 1641 SetCapacity(new_capacity); |
| 1635 | 1642 |
| 1636 return true; | 1643 return true; |
| 1637 } | 1644 } |
| 1638 | 1645 |
| 1639 | 1646 |
| 1640 void SemiSpace::FlipPages(intptr_t flags, intptr_t mask) { | 1647 void SemiSpace::FlipPages(intptr_t flags, intptr_t mask) { |
| 1641 anchor_.set_owner(this); | 1648 anchor_.set_owner(this); |
| 1642 // Fixup back-pointers to anchor. Address of anchor changes | 1649 // Fixup back-pointers to anchor. Address of anchor changes |
| 1643 // when we swap. | 1650 // when we swap. |
| 1644 anchor_.prev_page()->set_next_page(&anchor_); | 1651 anchor_.prev_page()->set_next_page(&anchor_); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 // has changed. | 1694 // has changed. |
| 1688 // Swap to/from-space bits on pages. | 1695 // Swap to/from-space bits on pages. |
| 1689 // Copy GC flags from old active space (from-space) to new (to-space). | 1696 // Copy GC flags from old active space (from-space) to new (to-space). |
| 1690 intptr_t flags = from->current_page()->GetFlags(); | 1697 intptr_t flags = from->current_page()->GetFlags(); |
| 1691 to->FlipPages(flags, NewSpacePage::kCopyOnFlipFlagsMask); | 1698 to->FlipPages(flags, NewSpacePage::kCopyOnFlipFlagsMask); |
| 1692 | 1699 |
| 1693 from->FlipPages(0, 0); | 1700 from->FlipPages(0, 0); |
| 1694 } | 1701 } |
| 1695 | 1702 |
| 1696 | 1703 |
| 1704 void SemiSpace::SetCapacity(int new_capacity) { |
| 1705 capacity_ = new_capacity; |
| 1706 if (capacity_ > maximum_committed_) { |
| 1707 maximum_committed_ = capacity_; |
| 1708 } |
| 1709 } |
| 1710 |
| 1711 |
| 1697 void SemiSpace::set_age_mark(Address mark) { | 1712 void SemiSpace::set_age_mark(Address mark) { |
| 1698 ASSERT(NewSpacePage::FromLimit(mark)->semi_space() == this); | 1713 ASSERT(NewSpacePage::FromLimit(mark)->semi_space() == this); |
| 1699 age_mark_ = mark; | 1714 age_mark_ = mark; |
| 1700 // Mark all pages up to the one containing mark. | 1715 // Mark all pages up to the one containing mark. |
| 1701 NewSpacePageIterator it(space_start(), mark); | 1716 NewSpacePageIterator it(space_start(), mark); |
| 1702 while (it.has_next()) { | 1717 while (it.has_next()) { |
| 1703 it.next()->SetFlag(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK); | 1718 it.next()->SetFlag(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK); |
| 1704 } | 1719 } |
| 1705 } | 1720 } |
| 1706 | 1721 |
| (...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2931 first_page_(NULL), | 2946 first_page_(NULL), |
| 2932 size_(0), | 2947 size_(0), |
| 2933 page_count_(0), | 2948 page_count_(0), |
| 2934 objects_size_(0), | 2949 objects_size_(0), |
| 2935 chunk_map_(ComparePointers, 1024) {} | 2950 chunk_map_(ComparePointers, 1024) {} |
| 2936 | 2951 |
| 2937 | 2952 |
| 2938 bool LargeObjectSpace::SetUp() { | 2953 bool LargeObjectSpace::SetUp() { |
| 2939 first_page_ = NULL; | 2954 first_page_ = NULL; |
| 2940 size_ = 0; | 2955 size_ = 0; |
| 2956 maximum_committed_ = 0; |
| 2941 page_count_ = 0; | 2957 page_count_ = 0; |
| 2942 objects_size_ = 0; | 2958 objects_size_ = 0; |
| 2943 chunk_map_.Clear(); | 2959 chunk_map_.Clear(); |
| 2944 return true; | 2960 return true; |
| 2945 } | 2961 } |
| 2946 | 2962 |
| 2947 | 2963 |
| 2948 void LargeObjectSpace::TearDown() { | 2964 void LargeObjectSpace::TearDown() { |
| 2949 while (first_page_ != NULL) { | 2965 while (first_page_ != NULL) { |
| 2950 LargePage* page = first_page_; | 2966 LargePage* page = first_page_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2977 AllocateLargePage(object_size, this, executable); | 2993 AllocateLargePage(object_size, this, executable); |
| 2978 if (page == NULL) return Failure::RetryAfterGC(identity()); | 2994 if (page == NULL) return Failure::RetryAfterGC(identity()); |
| 2979 ASSERT(page->area_size() >= object_size); | 2995 ASSERT(page->area_size() >= object_size); |
| 2980 | 2996 |
| 2981 size_ += static_cast<int>(page->size()); | 2997 size_ += static_cast<int>(page->size()); |
| 2982 objects_size_ += object_size; | 2998 objects_size_ += object_size; |
| 2983 page_count_++; | 2999 page_count_++; |
| 2984 page->set_next_page(first_page_); | 3000 page->set_next_page(first_page_); |
| 2985 first_page_ = page; | 3001 first_page_ = page; |
| 2986 | 3002 |
| 3003 if (size_ > maximum_committed_) { |
| 3004 maximum_committed_ = size_; |
| 3005 } |
| 3006 |
| 2987 // Register all MemoryChunk::kAlignment-aligned chunks covered by | 3007 // Register all MemoryChunk::kAlignment-aligned chunks covered by |
| 2988 // this large page in the chunk map. | 3008 // this large page in the chunk map. |
| 2989 uintptr_t base = reinterpret_cast<uintptr_t>(page) / MemoryChunk::kAlignment; | 3009 uintptr_t base = reinterpret_cast<uintptr_t>(page) / MemoryChunk::kAlignment; |
| 2990 uintptr_t limit = base + (page->size() - 1) / MemoryChunk::kAlignment; | 3010 uintptr_t limit = base + (page->size() - 1) / MemoryChunk::kAlignment; |
| 2991 for (uintptr_t key = base; key <= limit; key++) { | 3011 for (uintptr_t key = base; key <= limit; key++) { |
| 2992 HashMap::Entry* entry = chunk_map_.Lookup(reinterpret_cast<void*>(key), | 3012 HashMap::Entry* entry = chunk_map_.Lookup(reinterpret_cast<void*>(key), |
| 2993 static_cast<uint32_t>(key), | 3013 static_cast<uint32_t>(key), |
| 2994 true); | 3014 true); |
| 2995 ASSERT(entry != NULL); | 3015 ASSERT(entry != NULL); |
| 2996 entry->value = page; | 3016 entry->value = page; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3223 object->ShortPrint(); | 3243 object->ShortPrint(); |
| 3224 PrintF("\n"); | 3244 PrintF("\n"); |
| 3225 } | 3245 } |
| 3226 printf(" --------------------------------------\n"); | 3246 printf(" --------------------------------------\n"); |
| 3227 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3247 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3228 } | 3248 } |
| 3229 | 3249 |
| 3230 #endif // DEBUG | 3250 #endif // DEBUG |
| 3231 | 3251 |
| 3232 } } // namespace v8::internal | 3252 } } // namespace v8::internal |
| OLD | NEW |