Maybe can we move m_markingMode to VisitorHelper? Then we won't need to
duplicate m_markingMode in two classes.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/Heap.cppFile third_party/WebKit/Source/platform/heap/Heap.cpp (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/Heap.cpp#newcode423third_party/WebKit/Source/platform/heap/Heap.cpp:423: DCHECK(slot &&
*slot);
DCHECK(slot);
DCHECK(*slot);
It would help to identify which dcheck failed.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cppFile third_party/WebKit/Source/platform/heap/HeapCompact.cpp (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode39third_party/WebKit/Source/platform/heap/HeapCompact.cpp:39: if
(!HeapCompact::isCompactableArena(page->arena()->arenaIndex()))
Maybe do you want to mean isCompact"ing"Arena?
Also this check should not be needed because you're already checking
isCompactingArena in BaseArena::makeConsistentForGC(), right?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode49third_party/WebKit/Source/platform/heap/HeapCompact.cpp:49: if
(refPage->isLargeObjectPage())
Maybe we also want to check if the refPage is in a compact"ing" arena.
We can check m_relocatablePages.contains(refPage) but need to be careful
about the performance impact. This method should be performance
sensitive.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode60third_party/WebKit/Source/platform/heap/HeapCompact.cpp:60:
blinkPageAddress(slotAddress) + blinkGuardPageSize);
It might be better to add a helper function to HeapPage.h. This is used
in a couple of places.
Address HeapPage::pagePayloadAddress(Address address);
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode66third_party/WebKit/Source/platform/heap/HeapCompact.cpp:66: // Unlikely
case, the slot resides on a compactable arena's page.
compact"ing"
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode132third_party/WebKit/Source/platform/heap/HeapCompact.cpp:132:
DCHECK(m_relocatablePages.contains(fromPage));
Add DCHECK(m_relocatablePages.contains(toPage));
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode140third_party/WebKit/Source/platform/heap/HeapCompact.cpp:140:
m_interiorFixups.set(slot, to);
I'll stop asking a question about this, but I still think line 140 is
not needed. This slot => to mapping will never be used in the future.
Note that this case happens only when the slot is in a not-yet compacted
page (including somewhere outside oilpan).
If we remove this, we can add DCHECK(!it->value) at line 113.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode164third_party/WebKit/Source/platform/heap/HeapCompact.cpp:164: BasePage*
refPage = reinterpret_cast<BasePage*>(
refPage => slotPage
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode169third_party/WebKit/Source/platform/heap/HeapCompact.cpp:169:
m_relocatablePages.contains(refPage)));
Shouldn't this be:
DCHECK(!*slot || !m_relocatablePages.contains(refPage));
?
m_relocatablePages should NOT contain the slot page, I think.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode190third_party/WebKit/Source/platform/heap/HeapCompact.cpp:190: void
addInteriorFixup(MovableReference* slot) {
Move this method up to just below add().
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode241third_party/WebKit/Source/platform/heap/HeapCompact.cpp:241: };
Would you add an assert to ScriptWrappableVisitor to check that
ScriptWrappableVisitor::m_headersToUnmark is not pointing to compactable
arenas?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode263third_party/WebKit/Source/platform/heap/HeapCompact.cpp:263: m_fixups =
MovableObjectFixups::create();
Nit: It wouldn't make much sense to create the fixup object lazily.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode283third_party/WebKit/Source/platform/heap/HeapCompact.cpp:283: reason !=
BlinkGC::ForcedGC)
Do we need this check? I guess the following
BlinkGC::HeapPointersOnStack check is sufficient.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode334third_party/WebKit/Source/platform/heap/HeapCompact.cpp:334: return
BlinkGC::GCWithSweepCompaction;
It doesn't really make sense to return GCWithSweepCompaction from this
method though. The caller side can just use GCWithSweepCompaction.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode387third_party/WebKit/Source/platform/heap/HeapCompact.cpp:387: if
(!arenaSize)
Actually this is not doing a meaningful check... arenaSize is just the
size of all system pages in the arena. It wouldn't be zero in almost all
cases.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode414third_party/WebKit/Source/platform/heap/HeapCompact.cpp:414: void
HeapCompact::startThreadCompaction(ThreadState*) {
Drop ThreadState*.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode419third_party/WebKit/Source/platform/heap/HeapCompact.cpp:419:
m_startCompactionTimeMS = WTF::currentTimeMS();
Slightly simpler:
MutexLocker locker;
if (!m_startCompactionTimeMS)
m_startCompactionTimeMS = currentTimeMS();
We can remove m_startCompaction.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.cpp#newcode423third_party/WebKit/Source/platform/heap/HeapCompact.cpp:423: void
HeapCompact::finishedThreadCompaction(ThreadState*) {
Drop ThreadState*.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.hFile third_party/WebKit/Source/platform/heap/HeapCompact.h (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.h#newcode91third_party/WebKit/Source/platform/heap/HeapCompact.h:91: void
finishedThreadCompaction(ThreadState*);
finishThreadCompaction (c.f., startThreadCompaction)
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.h#newcode94third_party/WebKit/Source/platform/heap/HeapCompact.h:94: // the given
arena. The number of pages that were freed together with the
Remove the first sentence.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.h#newcode98third_party/WebKit/Source/platform/heap/HeapCompact.h:98: size_t
freedSize);
Nit: If we just want to track of freedPages and freedSize, it might be
simpler to introduce increaseFreedPages(size_t) and
increaseFreedSize(size_t). I don't have any strong opinion.
Or you can just compare values of Heap::allocatedSpace before and after
the compaction. Then you won't need to track m_freedPages and
m_freedSize.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.h#newcode102third_party/WebKit/Source/platform/heap/HeapCompact.h:102: // for a GC.
// All pages in compactable arenas must be added.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.h#newcode105third_party/WebKit/Source/platform/heap/HeapCompact.h:105: // Notify
heap compaction that object at |from| has been relocated to.. |to|.
relocated to |to|.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.h#newcode122third_party/WebKit/Source/platform/heap/HeapCompact.h:122: // is on
order (checkIfCompacting()).
checkIfCompacting => shouldCompact
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.h#newcode155third_party/WebKit/Source/platform/heap/HeapCompact.h:155: size_t
m_freeListSize;
I'm not sure if this needs to be a member variable though. It's used
only in shouldCompact().
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.h#newcode160third_party/WebKit/Source/platform/heap/HeapCompact.h:160: unsigned
m_compactableArenas;
m_compact"able"Arenas => m_compact"ing"Arenas
(c.f., isCompact"able"Arena returns true for all backing store arenas.)
Also see my comment in MovableObjectFixup::addCompactablePage. I guess
there's some confusion around it.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapCompact.h#newcode177third_party/WebKit/Source/platform/heap/HeapCompact.h:177: // Logging
macros activated by debug switches.
Clean them up before landing.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.cppFile third_party/WebKit/Source/platform/heap/HeapPage.cpp (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.cpp#newcode478third_party/WebKit/Source/platform/heap/HeapPage.cpp:478:
heap.compaction()->finishedArenaCompaction(this, 0, 0);
This looks unnecessary. We can just immediately return.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.cpp#newcode534third_party/WebKit/Source/platform/heap/HeapPage.cpp:534: // If the
current page hasn't been allocated into (empty heap?), add
It should be empty heap, right?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.cpp#newcode538third_party/WebKit/Source/platform/heap/HeapPage.cpp:538:
context.m_currentPage->link(&context.m_availablePages);
Add DCHECK(context.m_currentPage->isEmpty()).
Or can't we easily add the dcheck because we're not clearing up the
available page?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.cpp#newcode552third_party/WebKit/Source/platform/heap/HeapPage.cpp:552: // Release
available page back to the OS.
pages
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.cpp#newcode555third_party/WebKit/Source/platform/heap/HeapPage.cpp:555: size_t
pageSize = availablePages->size();
Can we add DCHECK(availablePages->isEmpty())? Maybe we can't easily.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.cpp#newcode570third_party/WebKit/Source/platform/heap/HeapPage.cpp:570:
heap.compaction()->finishedArenaCompaction(this, freedPageCount,
freedSize);
freedPageCount looks redundant. It can be calculated by freedSize /
blinkPageSize.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.cpp#newcode1438third_party/WebKit/Source/platform/heap/HeapPage.cpp:1438:
DCHECK(header->checkHeader());
This is checked in the below isMarked().
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.cpp#newcode1450third_party/WebKit/Source/platform/heap/HeapPage.cpp:1450:
ASAN_UNPOISON_MEMORY_REGION(headerAddress, size);
This could be ASAN_UNPOISON_MEMORY_REGION(payload, payloadSize).
c.f., See what NormalPage::sweep is doing.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.cpp#newcode1525third_party/WebKit/Source/platform/heap/HeapPage.cpp:1525:
memset(unusedStart, 0, unusedSize);
This would not be needed (though I don't know if this matters for
performance).
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.hFile third_party/WebKit/Source/platform/heap/HeapPage.h (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.h#newcode311third_party/WebKit/Source/platform/heap/HeapPage.h:311: FreeListEntry**
prevNext() { return &m_next; }
This is unused.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.h#newcode520third_party/WebKit/Source/platform/heap/HeapPage.h:520: class
CompactionContext {
Thanks, this is much more readable :)
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapPage.h#newcode796third_party/WebKit/Source/platform/heap/HeapPage.h:796: void
allocateAndAddPage();
What's the point of splitting the method into the two?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapTest.cppFile third_party/WebKit/Source/platform/heap/HeapTest.cpp (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/HeapTest.cpp#newcode3774third_party/WebKit/Source/platform/heap/HeapTest.cpp:3774:
ThreadState::GCForbiddenScope gcScope(ThreadState::current());
Would you help me understand why these GCForbiddenScopes are needed?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/MarkingVisitorImpl.hFile third_party/WebKit/Source/platform/heap/MarkingVisitorImpl.h
(right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/MarkingVisitorImpl.h#newcode143third_party/WebKit/Source/platform/heap/MarkingVisitorImpl.h:143:
visitor->registerBackingStoreReference(reference);
How about simply calling registerBackingStoreReference when HashTable
calls registerDelayedMarkNoTracing? We need to delay calling
markNoTracing but won't need to delay calling
registerBackingStoreReference. Then we won't need this hack.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/SparseHeapBitmap.cppFile third_party/WebKit/Source/platform/heap/SparseHeapBitmap.cpp
(right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/SparseHeapBitmap.cpp#newcode50third_party/WebKit/Source/platform/heap/SparseHeapBitmap.cpp:50: return
bitmap->size() == 1;
Would you help me understand when this can happen?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/SparseHeapBitmap.cpp#newcode88third_party/WebKit/Source/platform/heap/SparseHeapBitmap.cpp:88: Address
oldBase = swapBase(address);
Why is this left expansion safe? What happens if there is some address
set in the range that will be lost by expanding the range to left?
If the left expansion is uncommon, would there any option to just not
support it for simplicity?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/SparseHeapBitmap.hFile third_party/WebKit/Source/platform/heap/SparseHeapBitmap.h (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/SparseHeapBitmap.h#newcode40third_party/WebKit/Source/platform/heap/SparseHeapBitmap.h:40: class
PLATFORM_EXPORT SparseHeapBitmap {
Maybe can we replace RegionTree (in PageMemory.h) with SparseHeapBitmap
in a follow up CL?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/SparseHeapBitmap.h#newcode83third_party/WebKit/Source/platform/heap/SparseHeapBitmap.h:83:
SparseHeapBitmap(Address base) : m_base(base), m_size(1) {
Add explicit.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/ThreadState.cppFile third_party/WebKit/Source/platform/heap/ThreadState.cpp (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/ThreadState.cpp#newcode508third_party/WebKit/Source/platform/heap/ThreadState.cpp:508:
GCForbiddenScope gcForbiddenScope(this);
I'm curious why you need this. Isn't SweepForbiddenScope enough for
preventing GCs from getting triggered during the weak processing?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/ThreadState.cpp#newcode1050third_party/WebKit/Source/platform/heap/ThreadState.cpp:1050:
ScriptForbiddenIfMainThreadScope scriptForbiddenScope;
Also shall we add NoAllocationScope just in case?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/ThreadState.cpp#newcode1155third_party/WebKit/Source/platform/heap/ThreadState.cpp:1155: compact();
Add a comment and mention why this must be put after pre-finalization
and eager sweeping.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/ThreadState.cpp#newcode1709third_party/WebKit/Source/platform/heap/ThreadState.cpp:1709:
GCForbiddenScope gcForbiddenScope(this);
I'm just curious but why did you add this? (I'm fine with adding it.)
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/ThreadState.cpp#newcode1722third_party/WebKit/Source/platform/heap/ThreadState.cpp:1722:
visitorType = heap().compaction()->initialize(this);
I'd prefer updating |gcType| instead of using |visitorType|, since the
rest of this function uses |gcType|.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/ThreadState.hFile third_party/WebKit/Source/platform/heap/ThreadState.h (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/ThreadState.h#newcode331third_party/WebKit/Source/platform/heap/ThreadState.h:331:
GCForbiddenScope(ThreadState* threadState) : m_threadState(threadState)
{
Add explicit.
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/Visitor.hFile third_party/WebKit/Source/platform/heap/Visitor.h (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/platform/heap/Visitor.h#newcode309third_party/WebKit/Source/platform/heap/Visitor.h:309:
GlobalMarkCompacting,
GlobalMarkingWithCompaction ?
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/wtf/LinkedHashSet.hFile third_party/WebKit/Source/wtf/LinkedHashSet.h (right):
https://codereview.chromium.org/2531973002/diff/280001/third_party/WebKit/Source/wtf/LinkedHashSet.h#newcode359third_party/WebKit/Source/wtf/LinkedHashSet.h:359: if (node.m_next >=
fromStart && node.m_next <= fromEnd) {
node.m_next < fromEnd ?
The same comment for other comparisons below.
https://codereview.chromium.org/2531973002/