Changeset 76457 in webkit


Ignore:
Timestamp:
Jan 22, 2011 9:03:16 PM (13 years ago)
Author:
ggaren@apple.com
Message:

2011-01-22 Geoffrey Garen <ggaren@apple.com>

Reviewed by Dan Bernstein.

ASSERT running run-webkit-tests --threaded.
https://bugs.webkit.org/show_bug.cgi?id=52971


SunSpider and v8 report no change.

  • runtime/ConservativeSet.cpp: (JSC::ConservativeSet::grow): (JSC::ConservativeSet::add):
  • runtime/ConservativeSet.h: Tweaked the inline capacity to 128, and the growth policy to 2X, to make SunSpider and v8 happy. (JSC::ConservativeSet::ConservativeSet): (JSC::ConservativeSet::~ConservativeSet): (JSC::ConservativeSet::mark): Use OSAllocator directly, instead of malloc. Malloc is forbidden during a multi-threaded mark phase because it can cause deadlock.

2011-01-22 Geoffrey Garen <ggaren@apple.com>

Reviewed by Dan Bernstein.

Beefed up --threaded mode to catch even more kinds of errors.
https://bugs.webkit.org/show_bug.cgi?id=52971

  • DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp: Use a shared context group to force JSC to mark multiple threads. (This used to be the default, but it changed in SnowLeopard.) (runJavaScriptThread): Do more locking and unlocking, and more allocation, to give threading mistakes more chances to show themselves. (startJavaScriptThreads): (stopJavaScriptThreads):
Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r76454 r76457  
     12011-01-22  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Dan Bernstein.
     4
     5        ASSERT running run-webkit-tests --threaded.
     6        https://bugs.webkit.org/show_bug.cgi?id=52971
     7       
     8        SunSpider and v8 report no change.
     9
     10        * runtime/ConservativeSet.cpp:
     11        (JSC::ConservativeSet::grow):
     12        (JSC::ConservativeSet::add):
     13        * runtime/ConservativeSet.h: Tweaked the inline capacity to 128, and
     14        the growth policy to 2X, to make SunSpider and v8 happy.
     15        (JSC::ConservativeSet::ConservativeSet):
     16        (JSC::ConservativeSet::~ConservativeSet):
     17        (JSC::ConservativeSet::mark): Use OSAllocator directly, instead of malloc.
     18        Malloc is forbidden during a multi-threaded mark phase because it can
     19        cause deadlock.
     20
    1212011-01-22  Geoffrey Garen  <ggaren@apple.com>
    222
  • trunk/Source/JavaScriptCore/runtime/ConservativeSet.cpp

    r76454 r76457  
    3434}
    3535
     36void ConservativeSet::grow()
     37{
     38    size_t newCapacity = m_capacity == inlineCapacity ? nonInlineCapacity : m_capacity * 2;
     39    JSCell** newSet = static_cast<JSCell**>(OSAllocator::reserveAndCommit(newCapacity * sizeof(JSCell*)));
     40    memcpy(newSet, m_set, m_size * sizeof(JSCell*));
     41    if (m_set != m_inlineSet)
     42        OSAllocator::decommitAndRelease(m_set, m_capacity * sizeof(JSCell*));
     43    m_capacity = newCapacity;
     44    m_set = newSet;
     45}
     46
    3647void ConservativeSet::add(void* begin, void* end)
    3748{
     
    4455        if (!m_heap->contains(*it))
    4556            continue;
    46         m_vector.append(reinterpret_cast<JSCell*>(*it));
     57
     58        if (m_size == m_capacity)
     59            grow();
     60
     61        m_set[m_size++] = reinterpret_cast<JSCell*>(*it);
    4762    }
    4863}
  • trunk/Source/JavaScriptCore/runtime/ConservativeSet.h

    r76454 r76457  
    3838public:
    3939    ConservativeSet(Heap*);
     40    ~ConservativeSet();
    4041
    4142    void add(void* begin, void* end);
     
    4344
    4445private:
     46    static const size_t inlineCapacity = 128;
     47    static const size_t nonInlineCapacity = 8192 / sizeof(JSCell*);
     48   
     49    void grow();
     50
    4551    Heap* m_heap;
    46     Vector<JSCell*, 64> m_vector;
     52    JSCell** m_set;
     53    size_t m_size;
     54    size_t m_capacity;
     55    JSCell* m_inlineSet[inlineCapacity];
    4756};
    4857
    4958inline ConservativeSet::ConservativeSet(Heap* heap)
    5059    : m_heap(heap)
     60    , m_set(m_inlineSet)
     61    , m_size(0)
     62    , m_capacity(inlineCapacity)
    5163{
     64}
     65
     66inline ConservativeSet::~ConservativeSet()
     67{
     68    if (m_set != m_inlineSet)
     69        OSAllocator::decommitAndRelease(m_set, m_capacity * sizeof(JSCell*));
    5270}
    5371
    5472inline void ConservativeSet::mark(MarkStack& markStack)
    5573{
    56     for (size_t i = 0; i < m_vector.size(); ++i)
    57         markStack.append(m_vector[i]);
     74    for (size_t i = 0; i < m_size; ++i)
     75        markStack.append(m_set[i]);
    5876}
    5977
  • trunk/Tools/ChangeLog

    r76451 r76457  
     12011-01-22  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Dan Bernstein.
     4
     5        Beefed up --threaded mode to catch even more kinds of errors.
     6        https://bugs.webkit.org/show_bug.cgi?id=52971
     7
     8        * DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp: Use a shared
     9        context group to force JSC to mark multiple threads. (This used to be
     10        the default, but it changed in SnowLeopard.)
     11        (runJavaScriptThread): Do more locking and unlocking, and more allocation,
     12        to give threading mistakes more chances to show themselves.
     13        (startJavaScriptThreads):
     14        (stopJavaScriptThreads):
     15
    1162011-01-22  Robert Hogan  <robert@webkit.org>
    217
  • trunk/Tools/DumpRenderTree/pthreads/JavaScriptThreadingPthreads.cpp

    r51336 r76457  
    3838#include <wtf/HashSet.h>
    3939
     40static JSContextGroupRef javaScriptThreadsGroup;
     41
    4042static pthread_mutex_t javaScriptThreadsMutex = PTHREAD_MUTEX_INITIALIZER;
    4143static bool javaScriptThreadsShouldTerminate;
     
    5254}
    5355
    54 // Loops forever, running a script and randomly respawning, until
    55 // javaScriptThreadsShouldTerminate becomes true.
     56// This function exercises JSC in a loop until javaScriptThreadsShouldTerminate
     57// becomes true or it probabilistically decides to spawn a replacement thread and exit.
    5658void* runJavaScriptThread(void* arg)
    5759{
    58     const char* const script =
     60    static const char* const script =
    5961        "var array = [];"
    60         "for (var i = 0; i < 10; i++) {"
     62        "for (var i = 0; i < 1024; i++) {"
    6163        "    array.push(String(i));"
    6264        "}";
    6365
     66    pthread_mutex_lock(&javaScriptThreadsMutex);
     67    JSGlobalContextRef ctx = JSGlobalContextCreateInGroup(javaScriptThreadsGroup, 0);
     68    pthread_mutex_unlock(&javaScriptThreadsMutex);
     69
     70    pthread_mutex_lock(&javaScriptThreadsMutex);
     71    JSStringRef scriptRef = JSStringCreateWithUTF8CString(script);
     72    pthread_mutex_unlock(&javaScriptThreadsMutex);
     73
    6474    while (1) {
    65         JSGlobalContextRef ctx = JSGlobalContextCreate(0);
    66         JSStringRef scriptRef = JSStringCreateWithUTF8CString(script);
    67 
     75        pthread_mutex_lock(&javaScriptThreadsMutex);
    6876        JSValueRef exception = 0;
    6977        JSEvaluateScript(ctx, scriptRef, 0, 0, 1, &exception);
    7078        ASSERT(!exception);
    71 
    72         JSGarbageCollect(ctx);
    73         JSGlobalContextRelease(ctx);
    74         JSStringRelease(scriptRef);
    75        
    76         JSGarbageCollect(0);
     79        pthread_mutex_unlock(&javaScriptThreadsMutex);
    7780
    7881        pthread_mutex_lock(&javaScriptThreadsMutex);
     82        size_t valuesCount = 1024;
     83        JSValueRef values[valuesCount];
     84        for (size_t i = 0; i < valuesCount; ++i)
     85            values[i] = JSObjectMake(ctx, 0, 0);
     86        pthread_mutex_unlock(&javaScriptThreadsMutex);
    7987
    8088        // Check for cancellation.
    81         if (javaScriptThreadsShouldTerminate) {
    82             javaScriptThreads()->remove(pthread_self());
    83             pthread_mutex_unlock(&javaScriptThreadsMutex);
    84             return 0;
    85         }
     89        if (javaScriptThreadsShouldTerminate)
     90            goto done;
    8691
    8792        // Respawn probabilistically.
    8893        if (random() % 5 == 0) {
     94            pthread_mutex_lock(&javaScriptThreadsMutex);
    8995            pthread_t pthread;
    9096            pthread_create(&pthread, 0, &runJavaScriptThread, 0);
    9197            pthread_detach(pthread);
     98            javaScriptThreads()->add(pthread);
     99            pthread_mutex_unlock(&javaScriptThreadsMutex);
     100            goto done;
     101        }
     102    }
    92103
    93             javaScriptThreads()->remove(pthread_self());
    94             javaScriptThreads()->add(pthread);
    95 
    96             pthread_mutex_unlock(&javaScriptThreadsMutex);
    97             return 0;
    98         }
    99 
    100         pthread_mutex_unlock(&javaScriptThreadsMutex);
    101     }
     104done:
     105    pthread_mutex_lock(&javaScriptThreadsMutex);
     106    JSStringRelease(scriptRef);
     107    JSGarbageCollect(ctx);
     108    JSGlobalContextRelease(ctx);
     109    javaScriptThreads()->remove(pthread_self());
     110    pthread_mutex_unlock(&javaScriptThreadsMutex);
     111    return 0;
    102112}
    103113
    104114void startJavaScriptThreads()
    105115{
     116    javaScriptThreadsGroup = JSContextGroupCreate();
     117
    106118    pthread_mutex_lock(&javaScriptThreadsMutex);
    107119
     
    122134    javaScriptThreadsShouldTerminate = true;
    123135
    124     ASSERT(javaScriptThreads()->size() == javaScriptThreadsCount);
    125 
    126136    pthread_mutex_unlock(&javaScriptThreadsMutex);
    127137
Note: See TracChangeset for help on using the changeset viewer.