Ignore:
Timestamp:
Sep 20, 2018, 6:11:19 PM (7 years ago)
Author:
[email protected]
Message:

[JSC] Heap::reportExtraMemoryVisited shows contention if we have many JSString
https://bugs.webkit.org/show_bug.cgi?id=189558

Reviewed by Mark Lam.

When running web-tooling-benchmark postcss test on Linux JSCOnly port, we get the following result in perf report.

10.95% AutomaticThread libJavaScriptCore.so.1.0.0 . JSC::Heap::reportExtraMemoryVisited

This is because postcss produces bunch of JSString, which require reportExtraMemoryVisited calls in JSString::visitChildren.
And since reportExtraMemoryVisited attempts to update atomic counter, if we have bunch of marking threads, it becomes super contended.

This patch reduces the frequency of updating the atomic counter. Each SlotVisitor has per-SlotVisitor m_extraMemorySize counter.
And we propagate this value to the global atomic counter when rebalance happens.

We also reduce HeapCell::heap() access by using vm.heap.

  • heap/SlotVisitor.cpp:

(JSC::SlotVisitor::didStartMarking):
(JSC::SlotVisitor::propagateExternalMemoryVisitedIfNecessary):
(JSC::SlotVisitor::drain):
(JSC::SlotVisitor::performIncrementOfDraining):

  • heap/SlotVisitor.h:
  • heap/SlotVisitorInlines.h:

(JSC::SlotVisitor::reportExtraMemoryVisited):

  • runtime/JSString.cpp:

(JSC::JSRopeString::resolveRopeToAtomicString const):
(JSC::JSRopeString::resolveRope const):

  • runtime/JSString.h:

(JSC::JSString::finishCreation):

  • wasm/js/JSWebAssemblyInstance.cpp:

(JSC::JSWebAssemblyInstance::finishCreation):

  • wasm/js/JSWebAssemblyMemory.cpp:

(JSC::JSWebAssemblyMemory::finishCreation):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSString.cpp

    r235491 r236296  
    206206    // If we resolved a string that didn't previously exist, notify the heap that we've grown.
    207207    if (m_value.impl()->hasOneRef())
    208         Heap::heap(this)->reportExtraMemoryAllocated(m_value.impl()->cost());
     208        vm.heap.reportExtraMemoryAllocated(m_value.impl()->cost());
    209209}
    210210
     
    265265        LChar* buffer;
    266266        if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) {
    267             Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost());
     267            exec->vm().heap.reportExtraMemoryAllocated(newImpl->cost());
    268268            m_value = WTFMove(newImpl);
    269269        } else {
     
    279279    UChar* buffer;
    280280    if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) {
    281         Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost());
     281        exec->vm().heap.reportExtraMemoryAllocated(newImpl->cost());
    282282        m_value = WTFMove(newImpl);
    283283    } else {
Note: See TracChangeset for help on using the changeset viewer.