Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: src/heap/heap.cc

Issue 1683653002: Add a generic remembered set class. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #include "src/heap/heap.h" 5 #include "src/heap/heap.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/ast/scopeinfo.h" 9 #include "src/ast/scopeinfo.h"
10 #include "src/base/bits.h" 10 #include "src/base/bits.h"
11 #include "src/base/once.h" 11 #include "src/base/once.h"
12 #include "src/base/utils/random-number-generator.h" 12 #include "src/base/utils/random-number-generator.h"
13 #include "src/bootstrapper.h" 13 #include "src/bootstrapper.h"
14 #include "src/codegen.h" 14 #include "src/codegen.h"
15 #include "src/compilation-cache.h" 15 #include "src/compilation-cache.h"
16 #include "src/conversions.h" 16 #include "src/conversions.h"
17 #include "src/debug/debug.h" 17 #include "src/debug/debug.h"
18 #include "src/deoptimizer.h" 18 #include "src/deoptimizer.h"
19 #include "src/global-handles.h" 19 #include "src/global-handles.h"
20 #include "src/heap/array-buffer-tracker.h" 20 #include "src/heap/array-buffer-tracker.h"
21 #include "src/heap/gc-idle-time-handler.h" 21 #include "src/heap/gc-idle-time-handler.h"
22 #include "src/heap/gc-tracer.h" 22 #include "src/heap/gc-tracer.h"
23 #include "src/heap/incremental-marking.h" 23 #include "src/heap/incremental-marking.h"
24 #include "src/heap/mark-compact-inl.h" 24 #include "src/heap/mark-compact-inl.h"
25 #include "src/heap/mark-compact.h" 25 #include "src/heap/mark-compact.h"
26 #include "src/heap/memory-reducer.h" 26 #include "src/heap/memory-reducer.h"
27 #include "src/heap/object-stats.h" 27 #include "src/heap/object-stats.h"
28 #include "src/heap/objects-visiting-inl.h" 28 #include "src/heap/objects-visiting-inl.h"
29 #include "src/heap/objects-visiting.h" 29 #include "src/heap/objects-visiting.h"
30 #include "src/heap/remembered-set.h"
30 #include "src/heap/scavenge-job.h" 31 #include "src/heap/scavenge-job.h"
31 #include "src/heap/scavenger-inl.h" 32 #include "src/heap/scavenger-inl.h"
32 #include "src/heap/store-buffer.h" 33 #include "src/heap/store-buffer.h"
33 #include "src/interpreter/interpreter.h" 34 #include "src/interpreter/interpreter.h"
34 #include "src/profiler/cpu-profiler.h" 35 #include "src/profiler/cpu-profiler.h"
35 #include "src/regexp/jsregexp.h" 36 #include "src/regexp/jsregexp.h"
36 #include "src/runtime-profiler.h" 37 #include "src/runtime-profiler.h"
37 #include "src/snapshot/natives.h" 38 #include "src/snapshot/natives.h"
38 #include "src/snapshot/serialize.h" 39 #include "src/snapshot/serialize.h"
39 #include "src/snapshot/snapshot.h" 40 #include "src/snapshot/snapshot.h"
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 isolate()->optimizing_compile_dispatcher()->AgeBufferedOsrJobs(); 456 isolate()->optimizing_compile_dispatcher()->AgeBufferedOsrJobs();
456 } 457 }
457 458
458 if (new_space_.IsAtMaximumCapacity()) { 459 if (new_space_.IsAtMaximumCapacity()) {
459 maximum_size_scavenges_++; 460 maximum_size_scavenges_++;
460 } else { 461 } else {
461 maximum_size_scavenges_ = 0; 462 maximum_size_scavenges_ = 0;
462 } 463 }
463 CheckNewSpaceExpansionCriteria(); 464 CheckNewSpaceExpansionCriteria();
464 UpdateNewSpaceAllocationCounter(); 465 UpdateNewSpaceAllocationCounter();
466 store_buffer()->MoveEntriesToRememberedSet();
465 } 467 }
466 468
467 469
468 intptr_t Heap::SizeOfObjects() { 470 intptr_t Heap::SizeOfObjects() {
469 intptr_t total = 0; 471 intptr_t total = 0;
470 AllSpaces spaces(this); 472 AllSpaces spaces(this);
471 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { 473 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) {
472 total += space->SizeOfObjects(); 474 total += space->SizeOfObjects();
473 } 475 }
474 return total; 476 return total;
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 { 1673 {
1672 // Copy roots. 1674 // Copy roots.
1673 GCTracer::Scope gc_scope(tracer(), GCTracer::Scope::SCAVENGER_ROOTS); 1675 GCTracer::Scope gc_scope(tracer(), GCTracer::Scope::SCAVENGER_ROOTS);
1674 IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE); 1676 IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE);
1675 } 1677 }
1676 1678
1677 { 1679 {
1678 // Copy objects reachable from the old generation. 1680 // Copy objects reachable from the old generation.
1679 GCTracer::Scope gc_scope(tracer(), 1681 GCTracer::Scope gc_scope(tracer(),
1680 GCTracer::Scope::SCAVENGER_OLD_TO_NEW_POINTERS); 1682 GCTracer::Scope::SCAVENGER_OLD_TO_NEW_POINTERS);
1681 store_buffer()->IteratePointersToNewSpace(&Scavenger::ScavengeObject); 1683 RememberedSet<OLD_TO_NEW>::IterateWithWrapper(this,
1684 Scavenger::ScavengeObject);
1682 } 1685 }
1683 1686
1684 { 1687 {
1685 GCTracer::Scope gc_scope(tracer(), GCTracer::Scope::SCAVENGER_WEAK); 1688 GCTracer::Scope gc_scope(tracer(), GCTracer::Scope::SCAVENGER_WEAK);
1686 // Copy objects reachable from the encountered weak collections list. 1689 // Copy objects reachable from the encountered weak collections list.
1687 scavenge_visitor.VisitPointer(&encountered_weak_collections_); 1690 scavenge_visitor.VisitPointer(&encountered_weak_collections_);
1688 // Copy objects reachable from the encountered weak cells. 1691 // Copy objects reachable from the encountered weak cells.
1689 scavenge_visitor.VisitPointer(&encountered_weak_cells_); 1692 scavenge_visitor.VisitPointer(&encountered_weak_cells_);
1690 } 1693 }
1691 1694
(...skipping 2734 matching lines...) Expand 10 before | Expand all | Expand 10 after
4426 return false; 4429 return false;
4427 } 4430 }
4428 } 4431 }
4429 4432
4430 4433
4431 #ifdef VERIFY_HEAP 4434 #ifdef VERIFY_HEAP
4432 void Heap::Verify() { 4435 void Heap::Verify() {
4433 CHECK(HasBeenSetUp()); 4436 CHECK(HasBeenSetUp());
4434 HandleScope scope(isolate()); 4437 HandleScope scope(isolate());
4435 4438
4436 store_buffer()->Verify();
4437
4438 if (mark_compact_collector()->sweeping_in_progress()) { 4439 if (mark_compact_collector()->sweeping_in_progress()) {
4439 // We have to wait here for the sweeper threads to have an iterable heap. 4440 // We have to wait here for the sweeper threads to have an iterable heap.
4440 mark_compact_collector()->EnsureSweepingCompleted(); 4441 mark_compact_collector()->EnsureSweepingCompleted();
4441 } 4442 }
4442 4443
4443 VerifyPointersVisitor visitor; 4444 VerifyPointersVisitor visitor;
4444 IterateRoots(&visitor, VISIT_ONLY_STRONG); 4445 IterateRoots(&visitor, VISIT_ONLY_STRONG);
4445 4446
4446 VerifySmisVisitor smis_visitor; 4447 VerifySmisVisitor smis_visitor;
4447 IterateSmiRoots(&smis_visitor); 4448 IterateSmiRoots(&smis_visitor);
(...skipping 27 matching lines...) Expand all
4475 Memory::Address_at(cursor) = kFromSpaceZapValue; 4476 Memory::Address_at(cursor) = kFromSpaceZapValue;
4476 } 4477 }
4477 } 4478 }
4478 } 4479 }
4479 4480
4480 4481
4481 void Heap::IterateAndMarkPointersToFromSpace(HeapObject* object, Address start, 4482 void Heap::IterateAndMarkPointersToFromSpace(HeapObject* object, Address start,
4482 Address end, bool record_slots, 4483 Address end, bool record_slots,
4483 ObjectSlotCallback callback) { 4484 ObjectSlotCallback callback) {
4484 Address slot_address = start; 4485 Address slot_address = start;
4486 Page* page = Page::FromAddress(start);
4485 4487
4486 while (slot_address < end) { 4488 while (slot_address < end) {
4487 Object** slot = reinterpret_cast<Object**>(slot_address); 4489 Object** slot = reinterpret_cast<Object**>(slot_address);
4488 Object* target = *slot; 4490 Object* target = *slot;
4489 // If the store buffer becomes overfull we mark pages as being exempt from 4491 // If the store buffer becomes overfull we mark pages as being exempt from
4490 // the store buffer. These pages are scanned to find pointers that point 4492 // the store buffer. These pages are scanned to find pointers that point
4491 // to the new space. In that case we may hit newly promoted objects and 4493 // to the new space. In that case we may hit newly promoted objects and
4492 // fix the pointers before the promotion queue gets to them. Thus the 'if'. 4494 // fix the pointers before the promotion queue gets to them. Thus the 'if'.
4493 if (target->IsHeapObject()) { 4495 if (target->IsHeapObject()) {
4494 if (Heap::InFromSpace(target)) { 4496 if (Heap::InFromSpace(target)) {
4495 callback(reinterpret_cast<HeapObject**>(slot), 4497 callback(reinterpret_cast<HeapObject**>(slot),
4496 HeapObject::cast(target)); 4498 HeapObject::cast(target));
4497 Object* new_target = *slot; 4499 Object* new_target = *slot;
4498 if (InNewSpace(new_target)) { 4500 if (InNewSpace(new_target)) {
4499 SLOW_DCHECK(Heap::InToSpace(new_target)); 4501 SLOW_DCHECK(Heap::InToSpace(new_target));
4500 SLOW_DCHECK(new_target->IsHeapObject()); 4502 SLOW_DCHECK(new_target->IsHeapObject());
4501 store_buffer_.Mark(reinterpret_cast<Address>(slot)); 4503 RememberedSet<OLD_TO_NEW>::Insert(page, slot_address);
4502 } 4504 }
4503 SLOW_DCHECK(!MarkCompactCollector::IsOnEvacuationCandidate(new_target)); 4505 SLOW_DCHECK(!MarkCompactCollector::IsOnEvacuationCandidate(new_target));
4504 } else if (record_slots && 4506 } else if (record_slots &&
4505 MarkCompactCollector::IsOnEvacuationCandidate(target)) { 4507 MarkCompactCollector::IsOnEvacuationCandidate(target)) {
4506 mark_compact_collector()->RecordSlot(object, slot, target); 4508 mark_compact_collector()->RecordSlot(object, slot, target);
4507 } 4509 }
4508 } 4510 }
4509 slot_address += kPointerSize; 4511 slot_address += kPointerSize;
4510 } 4512 }
4511 } 4513 }
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
5471 }; 5473 };
5472 5474
5473 5475
5474 void Heap::CheckHandleCount() { 5476 void Heap::CheckHandleCount() {
5475 CheckHandleCountVisitor v; 5477 CheckHandleCountVisitor v;
5476 isolate_->handle_scope_implementer()->Iterate(&v); 5478 isolate_->handle_scope_implementer()->Iterate(&v);
5477 } 5479 }
5478 5480
5479 void Heap::ClearRecordedSlot(HeapObject* object, Object** slot) { 5481 void Heap::ClearRecordedSlot(HeapObject* object, Object** slot) {
5480 if (!InNewSpace(object)) { 5482 if (!InNewSpace(object)) {
5481 store_buffer()->Remove(reinterpret_cast<Address>(slot)); 5483 store_buffer()->MoveEntriesToRememberedSet();
5484 Address slot_addr = reinterpret_cast<Address>(slot);
5485 Page* page = Page::FromAddress(slot_addr);
5486 DCHECK_EQ(page->owner()->identity(), OLD_SPACE);
5487 RememberedSet<OLD_TO_NEW>::Remove(page, slot_addr);
5482 } 5488 }
5483 } 5489 }
5484 5490
5485 Space* AllSpaces::next() { 5491 Space* AllSpaces::next() {
5486 switch (counter_++) { 5492 switch (counter_++) {
5487 case NEW_SPACE: 5493 case NEW_SPACE:
5488 return heap_->new_space(); 5494 return heap_->new_space();
5489 case OLD_SPACE: 5495 case OLD_SPACE:
5490 return heap_->old_space(); 5496 return heap_->old_space();
5491 case CODE_SPACE: 5497 case CODE_SPACE:
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
6214 } 6220 }
6215 6221
6216 6222
6217 // static 6223 // static
6218 int Heap::GetStaticVisitorIdForMap(Map* map) { 6224 int Heap::GetStaticVisitorIdForMap(Map* map) {
6219 return StaticVisitorBase::GetVisitorId(map); 6225 return StaticVisitorBase::GetVisitorId(map);
6220 } 6226 }
6221 6227
6222 } // namespace internal 6228 } // namespace internal
6223 } // namespace v8 6229 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/heap-inl.h » ('j') | src/heap/store-buffer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698