| 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 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 | 1513 |
| 1514 void SemiSpace::TearDown() { | 1514 void SemiSpace::TearDown() { |
| 1515 start_ = NULL; | 1515 start_ = NULL; |
| 1516 capacity_ = 0; | 1516 capacity_ = 0; |
| 1517 } | 1517 } |
| 1518 | 1518 |
| 1519 | 1519 |
| 1520 bool SemiSpace::Commit() { | 1520 bool SemiSpace::Commit() { |
| 1521 ASSERT(!is_committed()); | 1521 ASSERT(!is_committed()); |
| 1522 int pages = capacity_ / Page::kPageSize; | 1522 int pages = capacity_ / Page::kPageSize; |
| 1523 Address end = start_ + maximum_capacity_; | 1523 if (!heap()->isolate()->memory_allocator()->CommitBlock(start_, |
| 1524 Address start = end - pages * Page::kPageSize; | |
| 1525 if (!heap()->isolate()->memory_allocator()->CommitBlock(start, | |
| 1526 capacity_, | 1524 capacity_, |
| 1527 executable())) { | 1525 executable())) { |
| 1528 return false; | 1526 return false; |
| 1529 } | 1527 } |
| 1530 | 1528 |
| 1531 NewSpacePage* page = anchor(); | 1529 NewSpacePage* current = anchor(); |
| 1532 for (int i = 1; i <= pages; i++) { | 1530 for (int i = 0; i < pages; i++) { |
| 1533 NewSpacePage* new_page = | 1531 NewSpacePage* new_page = |
| 1534 NewSpacePage::Initialize(heap(), end - i * Page::kPageSize, this); | 1532 NewSpacePage::Initialize(heap(), start_ + i * Page::kPageSize, this); |
| 1535 new_page->InsertAfter(page); | 1533 new_page->InsertAfter(current); |
| 1536 page = new_page; | 1534 current = new_page; |
| 1537 } | 1535 } |
| 1538 | 1536 |
| 1539 committed_ = true; | 1537 committed_ = true; |
| 1540 Reset(); | 1538 Reset(); |
| 1541 return true; | 1539 return true; |
| 1542 } | 1540 } |
| 1543 | 1541 |
| 1544 | 1542 |
| 1545 bool SemiSpace::Uncommit() { | 1543 bool SemiSpace::Uncommit() { |
| 1546 ASSERT(is_committed()); | 1544 ASSERT(is_committed()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1570 bool SemiSpace::GrowTo(int new_capacity) { | 1568 bool SemiSpace::GrowTo(int new_capacity) { |
| 1571 if (!is_committed()) { | 1569 if (!is_committed()) { |
| 1572 if (!Commit()) return false; | 1570 if (!Commit()) return false; |
| 1573 } | 1571 } |
| 1574 ASSERT((new_capacity & Page::kPageAlignmentMask) == 0); | 1572 ASSERT((new_capacity & Page::kPageAlignmentMask) == 0); |
| 1575 ASSERT(new_capacity <= maximum_capacity_); | 1573 ASSERT(new_capacity <= maximum_capacity_); |
| 1576 ASSERT(new_capacity > capacity_); | 1574 ASSERT(new_capacity > capacity_); |
| 1577 int pages_before = capacity_ / Page::kPageSize; | 1575 int pages_before = capacity_ / Page::kPageSize; |
| 1578 int pages_after = new_capacity / Page::kPageSize; | 1576 int pages_after = new_capacity / Page::kPageSize; |
| 1579 | 1577 |
| 1580 Address end = start_ + maximum_capacity_; | |
| 1581 Address start = end - new_capacity; | |
| 1582 size_t delta = new_capacity - capacity_; | 1578 size_t delta = new_capacity - capacity_; |
| 1583 | 1579 |
| 1584 ASSERT(IsAligned(delta, OS::AllocateAlignment())); | 1580 ASSERT(IsAligned(delta, OS::AllocateAlignment())); |
| 1585 if (!heap()->isolate()->memory_allocator()->CommitBlock( | 1581 if (!heap()->isolate()->memory_allocator()->CommitBlock( |
| 1586 start, delta, executable())) { | 1582 start_ + capacity_, delta, executable())) { |
| 1587 return false; | 1583 return false; |
| 1588 } | 1584 } |
| 1589 capacity_ = new_capacity; | 1585 capacity_ = new_capacity; |
| 1590 NewSpacePage* last_page = anchor()->prev_page(); | 1586 NewSpacePage* last_page = anchor()->prev_page(); |
| 1591 ASSERT(last_page != anchor()); | 1587 ASSERT(last_page != anchor()); |
| 1592 for (int i = pages_before + 1; i <= pages_after; i++) { | 1588 for (int i = pages_before; i < pages_after; i++) { |
| 1593 Address page_address = end - i * Page::kPageSize; | 1589 Address page_address = start_ + i * Page::kPageSize; |
| 1594 NewSpacePage* new_page = NewSpacePage::Initialize(heap(), | 1590 NewSpacePage* new_page = NewSpacePage::Initialize(heap(), |
| 1595 page_address, | 1591 page_address, |
| 1596 this); | 1592 this); |
| 1597 new_page->InsertAfter(last_page); | 1593 new_page->InsertAfter(last_page); |
| 1598 Bitmap::Clear(new_page); | 1594 Bitmap::Clear(new_page); |
| 1599 // Duplicate the flags that was set on the old page. | 1595 // Duplicate the flags that was set on the old page. |
| 1600 new_page->SetFlags(last_page->GetFlags(), | 1596 new_page->SetFlags(last_page->GetFlags(), |
| 1601 NewSpacePage::kCopyOnFlipFlagsMask); | 1597 NewSpacePage::kCopyOnFlipFlagsMask); |
| 1602 last_page = new_page; | 1598 last_page = new_page; |
| 1603 } | 1599 } |
| 1604 return true; | 1600 return true; |
| 1605 } | 1601 } |
| 1606 | 1602 |
| 1607 | 1603 |
| 1608 bool SemiSpace::ShrinkTo(int new_capacity) { | 1604 bool SemiSpace::ShrinkTo(int new_capacity) { |
| 1609 ASSERT((new_capacity & Page::kPageAlignmentMask) == 0); | 1605 ASSERT((new_capacity & Page::kPageAlignmentMask) == 0); |
| 1610 ASSERT(new_capacity >= initial_capacity_); | 1606 ASSERT(new_capacity >= initial_capacity_); |
| 1611 ASSERT(new_capacity < capacity_); | 1607 ASSERT(new_capacity < capacity_); |
| 1612 if (is_committed()) { | 1608 if (is_committed()) { |
| 1613 // Semispaces grow backwards from the end of their allocated capacity, | |
| 1614 // so we find the before and after start addresses relative to the | |
| 1615 // end of the space. | |
| 1616 Address space_end = start_ + maximum_capacity_; | |
| 1617 Address old_start = space_end - capacity_; | |
| 1618 size_t delta = capacity_ - new_capacity; | 1609 size_t delta = capacity_ - new_capacity; |
| 1619 ASSERT(IsAligned(delta, OS::AllocateAlignment())); | 1610 ASSERT(IsAligned(delta, OS::AllocateAlignment())); |
| 1620 | 1611 |
| 1621 MemoryAllocator* allocator = heap()->isolate()->memory_allocator(); | 1612 MemoryAllocator* allocator = heap()->isolate()->memory_allocator(); |
| 1622 if (!allocator->UncommitBlock(old_start, delta)) { | 1613 if (!allocator->UncommitBlock(start_ + new_capacity, delta)) { |
| 1623 return false; | 1614 return false; |
| 1624 } | 1615 } |
| 1625 | 1616 |
| 1626 int pages_after = new_capacity / Page::kPageSize; | 1617 int pages_after = new_capacity / Page::kPageSize; |
| 1627 NewSpacePage* new_last_page = | 1618 NewSpacePage* new_last_page = |
| 1628 NewSpacePage::FromAddress(space_end - pages_after * Page::kPageSize); | 1619 NewSpacePage::FromAddress(start_ + (pages_after - 1) * Page::kPageSize); |
| 1629 new_last_page->set_next_page(anchor()); | 1620 new_last_page->set_next_page(anchor()); |
| 1630 anchor()->set_prev_page(new_last_page); | 1621 anchor()->set_prev_page(new_last_page); |
| 1631 ASSERT((current_page_ <= first_page()) && (current_page_ >= new_last_page)); | 1622 ASSERT((current_page_ >= first_page()) && (current_page_ <= new_last_page)); |
| 1632 } | 1623 } |
| 1633 | 1624 |
| 1634 capacity_ = new_capacity; | 1625 capacity_ = new_capacity; |
| 1635 | 1626 |
| 1636 return true; | 1627 return true; |
| 1637 } | 1628 } |
| 1638 | 1629 |
| 1639 | 1630 |
| 1640 void SemiSpace::FlipPages(intptr_t flags, intptr_t mask) { | 1631 void SemiSpace::FlipPages(intptr_t flags, intptr_t mask) { |
| 1641 anchor_.set_owner(this); | 1632 anchor_.set_owner(this); |
| (...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3221 object->ShortPrint(); | 3212 object->ShortPrint(); |
| 3222 PrintF("\n"); | 3213 PrintF("\n"); |
| 3223 } | 3214 } |
| 3224 printf(" --------------------------------------\n"); | 3215 printf(" --------------------------------------\n"); |
| 3225 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3216 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3226 } | 3217 } |
| 3227 | 3218 |
| 3228 #endif // DEBUG | 3219 #endif // DEBUG |
| 3229 | 3220 |
| 3230 } } // namespace v8::internal | 3221 } } // namespace v8::internal |
| OLD | NEW |