⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181541 in webkit


Ignore:
Timestamp:
Mar 16, 2015, 4:21:37 AM (11 years ago)
Author:
Carlos Garcia Campos
Message:

Merge r181456 - Use std::atomic for CodeBlock::m_visitAggregateHasBeenCalled.
<https://webkit.org/b/142640>

Reviewed by Mark Hahnenberg.

We used to spin our own compare and swap on a uint8_t. Now that we can
use C++11, let's use std::atomic instead.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::visitAggregate):

  • The CAS here needs std::memory_order_acquire ordering because it requires lock acquisition semantics to visit the CodeBlock.
  • bytecode/CodeBlock.h:

(JSC::CodeBlockSet::mark):

  • heap/CodeBlockSet.cpp:

(JSC::CodeBlockSet::clearMarksForFullCollection):
(JSC::CodeBlockSet::clearMarksForEdenCollection):

  • These can go with relaxed ordering because they are all done before the GC starts parallel marking.
Location:
releases/WebKitGTK/webkit-2.8/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.8/Source/JavaScriptCore/ChangeLog

    r181538 r181541  
     12015-03-12  Mark Lam  <mark.lam@apple.com>
     2
     3        Use std::atomic for CodeBlock::m_visitAggregateHasBeenCalled.
     4        <https://webkit.org/b/142640>
     5
     6        Reviewed by Mark Hahnenberg.
     7
     8        We used to spin our own compare and swap on a uint8_t.  Now that we can
     9        use C++11, let's use std::atomic instead.
     10
     11        * bytecode/CodeBlock.cpp:
     12        (JSC::CodeBlock::visitAggregate):
     13        - The CAS here needs std::memory_order_acquire ordering because it
     14          requires lock acquisition semantics to visit the CodeBlock.
     15
     16        * bytecode/CodeBlock.h:
     17        (JSC::CodeBlockSet::mark):
     18        * heap/CodeBlockSet.cpp:
     19        (JSC::CodeBlockSet::clearMarksForFullCollection):
     20        (JSC::CodeBlockSet::clearMarksForEdenCollection):
     21        - These can go with relaxed ordering because they are all done before
     22          the GC starts parallel marking.
     23
    1242015-03-12  Csaba Osztrogonác  <ossy@webkit.org>
    225
  • releases/WebKitGTK/webkit-2.8/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r181533 r181541  
    22072207#if ENABLE(PARALLEL_GC)
    22082208    // I may be asked to scan myself more than once, and it may even happen concurrently.
    2209     // To this end, use a CAS loop to check if I've been called already. Only one thread
    2210     // may proceed past this point - whichever one wins the CAS race.
    2211     unsigned oldValue;
    2212     do {
    2213         oldValue = m_visitAggregateHasBeenCalled;
    2214         if (oldValue) {
    2215             // Looks like someone else won! Return immediately to ensure that we don't
    2216             // trace the same CodeBlock concurrently. Doing so is hazardous since we will
    2217             // be mutating the state of ValueProfiles, which contain JSValues, which can
    2218             // have word-tearing on 32-bit, leading to awesome timing-dependent crashes
    2219             // that are nearly impossible to track down.
    2220            
    2221             // Also note that it must be safe to return early as soon as we see the
    2222             // value true (well, (unsigned)1), since once a GC thread is in this method
    2223             // and has won the CAS race (i.e. was responsible for setting the value true)
    2224             // it will definitely complete the rest of this method before declaring
    2225             // termination.
    2226             return;
    2227         }
    2228     } while (!WTF::weakCompareAndSwap(&m_visitAggregateHasBeenCalled, 0, 1));
     2209    // To this end, use an atomic operation to check (and set) if I've been called already.
     2210    // Only one thread may proceed past this point - whichever one wins the atomic set race.
     2211    bool expected = false;
     2212    bool setByMe = m_visitAggregateHasBeenCalled.compare_exchange_strong(expected, true, std::memory_order_acquire);
     2213    if (!setByMe)
     2214        return;
    22292215#endif // ENABLE(PARALLEL_GC)
    22302216   
  • releases/WebKitGTK/webkit-2.8/Source/JavaScriptCore/bytecode/CodeBlock.h

    r181533 r181541  
    10571057    bool m_needsActivation;
    10581058    bool m_mayBeExecuting;
    1059     uint8_t m_visitAggregateHasBeenCalled;
     1059    std::atomic<bool> m_visitAggregateHasBeenCalled;
    10601060
    10611061    RefPtr<SourceProvider> m_source;
     
    12921292    codeBlock->m_mayBeExecuting = true;
    12931293    // We might not have cleared the marks for this CodeBlock, but we need to visit it.
    1294     codeBlock->m_visitAggregateHasBeenCalled = false;
     1294    codeBlock->m_visitAggregateHasBeenCalled.store(false, std::memory_order_relaxed);
    12951295#if ENABLE(GGC)
    12961296    m_currentlyExecuting.append(codeBlock);
  • releases/WebKitGTK/webkit-2.8/Source/JavaScriptCore/heap/CodeBlockSet.cpp

    r179359 r181541  
    6666    for (CodeBlock* codeBlock : m_oldCodeBlocks) {
    6767        codeBlock->m_mayBeExecuting = false;
    68         codeBlock->m_visitAggregateHasBeenCalled = false;
     68        codeBlock->m_visitAggregateHasBeenCalled.store(false, std::memory_order_relaxed);
    6969    }
    7070
     
    8383        executable->forEachCodeBlock([](CodeBlock* codeBlock) {
    8484            codeBlock->m_mayBeExecuting = false;
    85             codeBlock->m_visitAggregateHasBeenCalled = false;
     85            codeBlock->m_visitAggregateHasBeenCalled.store(false, std::memory_order_relaxed);
    8686        });
    8787    }
Note: See TracChangeset for help on using the changeset viewer.