Chromium Code Reviews| Index: src/spaces.cc |
| diff --git a/src/spaces.cc b/src/spaces.cc |
| index 157458d4680d2064274f730026d76c5b9e269103..3d4ccc1035479531867d2552e4e2ed9dcb56aa6c 100644 |
| --- a/src/spaces.cc |
| +++ b/src/spaces.cc |
| @@ -391,14 +391,22 @@ void Page::InitializeAsAnchor(PagedSpace* owner) { |
| } |
| -NewSpacePage* NewSpacePage::Initialize(Heap* heap, Address start) { |
| +NewSpacePage* NewSpacePage::Initialize(Heap* heap, |
| + Address start, |
| + SemiSpaceId semispace_id) { |
| MemoryChunk* chunk = MemoryChunk::Initialize(heap, |
| start, |
| Page::kPageSize, |
| NOT_EXECUTABLE, |
| heap->new_space()); |
| + chunk->set_next_chunk(NULL); |
| + chunk->set_prev_chunk(NULL); |
| chunk->initialize_scan_on_scavenge(true); |
| - chunk->SetFlag(MemoryChunk::IN_NEW_SPACE); |
| + bool in_to_space = (semispace_id != kFromSpace); |
| + chunk->SetFlag(in_to_space ? MemoryChunk::IN_TO_SPACE |
| + : MemoryChunk::IN_FROM_SPACE); |
| + ASSERT(!chunk->IsFlagSet(in_to_space ? MemoryChunk::IN_FROM_SPACE |
| + : MemoryChunk::IN_TO_SPACE)); |
| heap->incremental_marking()->SetNewSpacePageFlags(chunk); |
| return static_cast<NewSpacePage*>(chunk); |
| } |
| @@ -932,9 +940,11 @@ void NewSpace::Flip() { |
| from_space_ = to_space_; |
| to_space_ = tmp; |
| - NewSpacePage* old_active_page = from_space_.current_page(); |
| - NewSpacePage* new_active_page = to_space_.current_page(); |
| - new_active_page->CopyFlagsFrom(old_active_page); |
| + // Copy GC flags from old active space (from-space) to new (to-space). |
| + intptr_t flags = from_space_.current_page()->GetFlags(); |
| + to_space_.Flip(flags, NewSpacePage::kCopyOnFlipFlagsMask); |
| + |
| + from_space_.Flip(0, 0); |
| } |
| @@ -1035,7 +1045,7 @@ bool SemiSpace::Commit() { |
| committed_ = true; |
| // TODO(gc): When more than one page is present, initialize and |
| // chain them all. |
| - current_page_ = NewSpacePage::Initialize(heap(), start_); |
| + current_page_ = NewSpacePage::Initialize(heap(), start_, id_); |
| return true; |
| } |
| @@ -1134,6 +1144,25 @@ bool SemiSpace::ShrinkTo(int new_capacity) { |
| } |
| +void SemiSpace::Flip(intptr_t flags, intptr_t mask) { |
| + bool becomes_to_space = (id_ == kFromSpace); |
| + id_ = becomes_to_space ? kToSpace : kFromSpace; |
|
Erik Corry
2011/05/24 12:38:36
This can all be rewritten in terms of SetFlag and
|
| + intptr_t semi_space_mask = |
| + (1 << MemoryChunk::IN_FROM_SPACE) | (1 << MemoryChunk::IN_TO_SPACE); |
| + flags &= ~semi_space_mask; |
| + if (becomes_to_space) { |
| + flags |= 1 << MemoryChunk::IN_TO_SPACE; |
| + } else { |
| + flags |= 1 << MemoryChunk::IN_FROM_SPACE; |
| + } |
| + mask |= semi_space_mask; |
| + NewSpacePage* page = NewSpacePage::FromAddress(start_); |
| + while (page != NULL) { |
| + page->SetFlags(flags, mask); |
| + page = page->next_page(); |
| + } |
| +} |
| + |
| #ifdef DEBUG |
| void SemiSpace::Print() { } |