Changeset 58012 in webkit


Ignore:
Timestamp:
Apr 21, 2010 1:59:14 PM (14 years ago)
Author:
weinig@apple.com
Message:

Fix for https://bugs.webkit.org/show_bug.cgi?id=37937
Wean JavaScriptCore off calls to isMainThread()

Reviewed by Geoffrey Garen.

JavaScriptCore:

  • Replace use of isMainThread() for interpreter reentry checks with a stored value on the JSGlobalData.
  • Replace use of isMainThread() for useMainThread only check in the collector with a stored exclusive thread.
  • API/JSContextRef.cpp:

(JSContextGroupCreate):
Always default to a small stack type for uses of the JSC API. It is
unlikely that the interpreter reentry required on the web will be as
important for other uses of JavaScriptCore.

Update exports.

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::execute):
(JSC::Interpreter::prepareForRepeatCall):
Use new stored JSGlobalData::maxReentryDepth instead of isMainThread().

  • interpreter/Interpreter.h:

Rename MaxMainThreadReentryDepth to MaxLargeThreadReentryDepth and
MaxSecondaryThreadReentryDepth to MaxSmallThreadReentryDepth.

  • jsc.cpp:

(main): Use the a large stack for jsc since it is always using the
main thread.

  • runtime/ArrayPrototype.cpp:

(JSC::arrayProtoFuncToString):
(JSC::arrayProtoFuncToLocaleString):
(JSC::arrayProtoFuncJoin):
Use new stored JSGlobalData::maxReentryDepth instead of isMainThread().

  • runtime/Collector.cpp:

(JSC::Heap::registerThread):
Use the concept of making JSC run on an exclusiveThread instead of
forcing a mainThreadOnly assertion.

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::createNonDefault):
(JSC::JSGlobalData::create):
(JSC::JSGlobalData::createLeaked):
(JSC::JSGlobalData::sharedInstance):

  • runtime/JSGlobalData.h:

Add ThreadStackType argument to JSGlobalData constructors and set
maxReentryDepth based on it.

WebCore:

No change in behavior.

  • bindings/js/JSDOMWindowBase.cpp:

(WebCore::JSDOMWindowBase::commonJSGlobalData):
Explicitly set a large stack type for the common JSGlobalData and
set the currently running thread as the exclusive thread for its
execution.

  • bindings/js/WorkerScriptController.cpp:

(WebCore::WorkerScriptController::WorkerScriptController):
Explicitly set a small stack type for the workers JSGlobalData.

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r58001 r58012  
    4747{
    4848    initializeThreading();
    49     return toRef(JSGlobalData::createNonDefault().releaseRef());
     49    return toRef(JSGlobalData::createNonDefault(ThreadStackTypeSmall).releaseRef());
    5050}
    5151
     
    8585
    8686    JSLock lock(LockForReal);
    87     RefPtr<JSGlobalData> globalData = group ? PassRefPtr<JSGlobalData>(toJS(group)) : JSGlobalData::createNonDefault();
     87    RefPtr<JSGlobalData> globalData = group ? PassRefPtr<JSGlobalData>(toJS(group)) : JSGlobalData::createNonDefault(ThreadStackTypeSmall);
    8888
    8989    APIEntryShim entryShim(globalData.get(), false);
  • trunk/JavaScriptCore/ChangeLog

    r58010 r58012  
     12010-04-21  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Fix for https://bugs.webkit.org/show_bug.cgi?id=37937
     6        Wean JavaScriptCore off calls to isMainThread()
     7
     8        - Replace use of isMainThread() for interpreter reentry checks
     9          with a stored value on the JSGlobalData.
     10        - Replace use of isMainThread() for useMainThread only check in the
     11          collector with a stored exclusive thread.
     12
     13        * API/JSContextRef.cpp:
     14        (JSContextGroupCreate):
     15        Always default to a small stack type for uses of the JSC API. It is
     16        unlikely that the interpreter reentry required on the web will be as
     17        important for other uses of JavaScriptCore.
     18
     19        * JavaScriptCore.exp:
     20        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
     21        Update exports.
     22
     23        * interpreter/Interpreter.cpp:
     24        (JSC::Interpreter::execute):
     25        (JSC::Interpreter::prepareForRepeatCall):
     26        Use new stored JSGlobalData::maxReentryDepth instead of isMainThread().
     27
     28        * interpreter/Interpreter.h:
     29        Rename MaxMainThreadReentryDepth to MaxLargeThreadReentryDepth and
     30        MaxSecondaryThreadReentryDepth to MaxSmallThreadReentryDepth.
     31
     32        * jsc.cpp:
     33        (main): Use the a large stack for jsc since it is always using the
     34        main thread.
     35       
     36        * runtime/ArrayPrototype.cpp:
     37        (JSC::arrayProtoFuncToString):
     38        (JSC::arrayProtoFuncToLocaleString):
     39        (JSC::arrayProtoFuncJoin):
     40        Use new stored JSGlobalData::maxReentryDepth instead of isMainThread().
     41
     42        * runtime/Collector.cpp:
     43        (JSC::Heap::registerThread):
     44        Use the concept of making JSC run on an exclusiveThread instead of
     45        forcing a mainThreadOnly assertion.
     46       
     47        * runtime/JSGlobalData.cpp:
     48        (JSC::JSGlobalData::JSGlobalData):
     49        (JSC::JSGlobalData::createNonDefault):
     50        (JSC::JSGlobalData::create):
     51        (JSC::JSGlobalData::createLeaked):
     52        (JSC::JSGlobalData::sharedInstance):
     53        * runtime/JSGlobalData.h:
     54        Add ThreadStackType argument to JSGlobalData constructors and set
     55        maxReentryDepth based on it.
     56
    1572010-04-21  Gavin Barraclough  <barraclough@apple.com>
    258
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r58001 r58012  
    121121__ZN3JSC12JSGlobalData10ClientDataD2Ev
    122122__ZN3JSC12JSGlobalData11jsArrayVPtrE
    123 __ZN3JSC12JSGlobalData12createLeakedEv
     123__ZN3JSC12JSGlobalData12createLeakedENS_15ThreadStackTypeE
    124124__ZN3JSC12JSGlobalData12jsStringVPtrE
    125125__ZN3JSC12JSGlobalData12stopSamplingEv
     
    128128__ZN3JSC12JSGlobalData14resetDateCacheEv
    129129__ZN3JSC12JSGlobalData14sharedInstanceEv
    130 __ZN3JSC12JSGlobalData6createEv
     130__ZN3JSC12JSGlobalData6createENS_15ThreadStackTypeE
    131131__ZN3JSC12JSGlobalDataD1Ev
    132132__ZN3JSC12SamplingTool5setupEv
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r58010 r58012  
    103103    ?convertUTF8ToUTF16@Unicode@WTF@@YA?AW4ConversionResult@12@PAPBDPBDPAPA_WPA_W_N@Z
    104104    ?create@ByteArray@WTF@@SA?AV?$PassRefPtr@VByteArray@WTF@@@2@I@Z
    105     ?create@JSGlobalData@JSC@@SA?AV?$PassRefPtr@VJSGlobalData@JSC@@@WTF@@XZ
     105    ?create@JSGlobalData@JSC@@SA?AV?$PassRefPtr@VJSGlobalData@JSC@@@WTF@@W4ThreadStackType@2@@Z
    106106    ?create@OpaqueJSString@@SA?AV?$PassRefPtr@UOpaqueJSString@@@WTF@@ABVUString@JSC@@@Z
    107107    ?create@StringImpl@WebCore@@SA?AV?$PassRefPtr@VStringImpl@WebCore@@@WTF@@PBD@Z
     
    111111    ?createInheritorID@JSObject@JSC@@AAEPAVStructure@2@XZ
    112112    ?createInterruptedExecutionException@JSC@@YA?AVJSValue@1@PAVJSGlobalData@1@@Z
    113     ?createLeaked@JSGlobalData@JSC@@SA?AV?$PassRefPtr@VJSGlobalData@JSC@@@WTF@@XZ
     113    ?createLeaked@JSGlobalData@JSC@@SA?AV?$PassRefPtr@VJSGlobalData@JSC@@@WTF@@W4ThreadStackType@2@@Z
    114114    ?createSingleCharacterString@SmallStrings@JSC@@AAEXPAVJSGlobalData@2@E@Z
    115115    ?createStackOverflowError@JSC@@YA?AVJSValue@1@PAVExecState@1@@Z
  • trunk/JavaScriptCore/interpreter/Interpreter.cpp

    r57955 r58012  
    581581    ASSERT(!scopeChain->globalData->exception);
    582582
    583     if (m_reentryDepth >= MaxSecondaryThreadReentryDepth) {
    584         if (!isMainThread() || m_reentryDepth >= MaxMainThreadReentryDepth) {
     583    if (m_reentryDepth >= MaxSmallThreadReentryDepth) {
     584        if (m_reentryDepth >= callFrame->globalData().maxReentryDepth) {
    585585            *exception = createStackOverflowError(callFrame);
    586586            return jsNull();
     
    642642    ASSERT(!scopeChain->globalData->exception);
    643643
    644     if (m_reentryDepth >= MaxSecondaryThreadReentryDepth) {
    645         if (!isMainThread() || m_reentryDepth >= MaxMainThreadReentryDepth) {
     644    if (m_reentryDepth >= MaxSmallThreadReentryDepth) {
     645        if (m_reentryDepth >= callFrame->globalData().maxReentryDepth) {
    646646            *exception = createStackOverflowError(callFrame);
    647647            return jsNull();
     
    704704    ASSERT(!scopeChain->globalData->exception);
    705705   
    706     if (m_reentryDepth >= MaxSecondaryThreadReentryDepth) {
    707         if (!isMainThread() || m_reentryDepth >= MaxMainThreadReentryDepth) {
     706    if (m_reentryDepth >= MaxSmallThreadReentryDepth) {
     707        if (m_reentryDepth >= callFrame->globalData().maxReentryDepth) {
    708708            *exception = createStackOverflowError(callFrame);
    709709            return CallFrameClosure();
     
    780780    ASSERT(!scopeChain->globalData->exception);
    781781
    782     if (m_reentryDepth >= MaxSecondaryThreadReentryDepth) {
    783         if (!isMainThread() || m_reentryDepth >= MaxMainThreadReentryDepth) {
     782    if (m_reentryDepth >= MaxSmallThreadReentryDepth) {
     783        if (m_reentryDepth >= callFrame->globalData().maxReentryDepth) {
    784784            *exception = createStackOverflowError(callFrame);
    785785            return jsNull();
  • trunk/JavaScriptCore/interpreter/Interpreter.h

    r49409 r58012  
    6565    };
    6666
    67     enum { MaxMainThreadReentryDepth = 256, MaxSecondaryThreadReentryDepth = 32 };
     67    enum { MaxLargeThreadReentryDepth = 256, MaxSmallThreadReentryDepth = 32 };
    6868
    6969    class Interpreter : public FastAllocBase {
  • trunk/JavaScriptCore/jsc.cpp

    r57318 r58012  
    347347    // Structured Exception Handling
    348348    int res = 0;
    349     JSGlobalData* globalData = JSGlobalData::create().releaseRef();
     349    JSGlobalData* globalData = JSGlobalData::create(ThreadStackTypeLarge).releaseRef();
    350350    TRY
    351351        res = jscmain(argc, argv, globalData);
  • trunk/JavaScriptCore/runtime/ArrayPrototype.cpp

    r57978 r58012  
    157157   
    158158    HashSet<JSObject*>& arrayVisitedElements = exec->globalData().arrayVisitedElements;
    159     if (arrayVisitedElements.size() >= MaxSecondaryThreadReentryDepth) {
    160         if (!isMainThread() || arrayVisitedElements.size() >= MaxMainThreadReentryDepth)
    161             return throwError(exec, RangeError, "Maximum call stack size exceeded.");
     159    if (arrayVisitedElements.size() >= MaxSmallThreadReentryDepth) {
     160        if (arrayVisitedElements.size() >= exec->globalData().maxReentryDepth)
     161            return throwError(exec, RangeError, "Maximum call stack size exceeded.");   
    162162    }
    163163
     
    215215
    216216    HashSet<JSObject*>& arrayVisitedElements = exec->globalData().arrayVisitedElements;
    217     if (arrayVisitedElements.size() >= MaxSecondaryThreadReentryDepth) {
    218         if (!isMainThread() || arrayVisitedElements.size() >= MaxMainThreadReentryDepth)
    219             return throwError(exec, RangeError, "Maximum call stack size exceeded.");
     217    if (arrayVisitedElements.size() >= MaxSmallThreadReentryDepth) {
     218        if (arrayVisitedElements.size() >= exec->globalData().maxReentryDepth)
     219            return throwError(exec, RangeError, "Maximum call stack size exceeded.");   
    220220    }
    221221
     
    253253
    254254    HashSet<JSObject*>& arrayVisitedElements = exec->globalData().arrayVisitedElements;
    255     if (arrayVisitedElements.size() >= MaxSecondaryThreadReentryDepth) {
    256         if (!isMainThread() || arrayVisitedElements.size() >= MaxMainThreadReentryDepth)
    257             return throwError(exec, RangeError, "Maximum call stack size exceeded.");
     255    if (arrayVisitedElements.size() >= MaxSmallThreadReentryDepth) {
     256        if (arrayVisitedElements.size() >= exec->globalData().maxReentryDepth)
     257            return throwError(exec, RangeError, "Maximum call stack size exceeded.");   
    258258    }
    259259
  • trunk/JavaScriptCore/runtime/Collector.cpp

    r57025 r58012  
    639639void Heap::registerThread()
    640640{
    641     ASSERT(!m_globalData->mainThreadOnly || isMainThread());
     641    ASSERT(!m_globalData->exclusiveThread || m_globalData->exclusiveThread == currentThread());
    642642
    643643    if (!m_currentThreadRegistrar || pthread_getspecific(m_currentThreadRegistrar))
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r57879 r58012  
    104104}
    105105
    106 JSGlobalData::JSGlobalData(bool isShared)
     106JSGlobalData::JSGlobalData(bool isShared, ThreadStackType threadStackType)
    107107    : isSharedInstance(isShared)
    108108    , clientData(0)
     
    147147    , cachedUTCOffset(NaN)
    148148    , weakRandom(static_cast<int>(currentTime()))
     149    , maxReentryDepth(threadStackType == ThreadStackTypeSmall ? MaxSmallThreadReentryDepth : MaxLargeThreadReentryDepth)
    149150#ifndef NDEBUG
    150     , mainThreadOnly(false)
     151    , exclusiveThread(0)
    151152#endif
    152153{
     
    197198}
    198199
    199 PassRefPtr<JSGlobalData> JSGlobalData::createNonDefault()
    200 {
    201     return adoptRef(new JSGlobalData(false));
    202 }
    203 
    204 PassRefPtr<JSGlobalData> JSGlobalData::create()
    205 {
    206     JSGlobalData* globalData = new JSGlobalData(false);
     200PassRefPtr<JSGlobalData> JSGlobalData::createNonDefault(ThreadStackType type)
     201{
     202    return adoptRef(new JSGlobalData(false, type));
     203}
     204
     205PassRefPtr<JSGlobalData> JSGlobalData::create(ThreadStackType type)
     206{
     207    JSGlobalData* globalData = new JSGlobalData(false, type);
    207208    wtfThreadData().initializeIdentifierTable(globalData->identifierTable);
    208209    return adoptRef(globalData);
    209210}
    210211
    211 PassRefPtr<JSGlobalData> JSGlobalData::createLeaked()
     212PassRefPtr<JSGlobalData> JSGlobalData::createLeaked(ThreadStackType type)
    212213{
    213214    Structure::startIgnoringLeaks();
    214     RefPtr<JSGlobalData> data = create();
     215    RefPtr<JSGlobalData> data = create(type);
    215216    Structure::stopIgnoringLeaks();
    216217    return data.release();
     
    226227    JSGlobalData*& instance = sharedInstanceInternal();
    227228    if (!instance) {
    228         instance = new JSGlobalData(true);
     229        instance = new JSGlobalData(true, ThreadStackTypeSmall);
    229230#if ENABLE(JSC_MULTIPLE_THREADS)
    230231        instance->makeUsableFromMultipleThreads();
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r57192 r58012  
    8585    };
    8686
     87    enum ThreadStackType {
     88        ThreadStackTypeLarge,
     89        ThreadStackTypeSmall
     90    };
     91
    8792    class JSGlobalData : public RefCounted<JSGlobalData> {
    8893    public:
     
    9499        static JSGlobalData& sharedInstance();
    95100
    96         static PassRefPtr<JSGlobalData> create();
    97         static PassRefPtr<JSGlobalData> createLeaked();
    98         static PassRefPtr<JSGlobalData> createNonDefault();
     101        static PassRefPtr<JSGlobalData> create(ThreadStackType);
     102        static PassRefPtr<JSGlobalData> createLeaked(ThreadStackType);
     103        static PassRefPtr<JSGlobalData> createNonDefault(ThreadStackType);
    99104        ~JSGlobalData();
    100105
     
    188193        WeakRandom weakRandom;
    189194
     195        int maxReentryDepth;
    190196#ifndef NDEBUG
    191         bool mainThreadOnly;
     197        ThreadIdentifier exclusiveThread;
    192198#endif
    193199
     
    198204        void dumpSampleData(ExecState* exec);
    199205    private:
    200         JSGlobalData(bool isShared);
     206        JSGlobalData(bool isShared, ThreadStackType);
    201207        static JSGlobalData*& sharedInstanceInternal();
    202208        void createNativeThunk();
  • trunk/WebCore/ChangeLog

    r58006 r58012  
     12010-04-21  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Fix for https://bugs.webkit.org/show_bug.cgi?id=37937
     6        Wean JavaScriptCore off calls to isMainThread()
     7
     8        No change in behavior.
     9
     10        * bindings/js/JSDOMWindowBase.cpp:
     11        (WebCore::JSDOMWindowBase::commonJSGlobalData):
     12        Explicitly set a large stack type for the common JSGlobalData and
     13        set the currently running thread as the exclusive thread for its
     14        execution.
     15
     16        * bindings/js/WorkerScriptController.cpp:
     17        (WebCore::WorkerScriptController::WorkerScriptController):
     18        Explicitly set a small stack type for the workers JSGlobalData.
     19
    1202010-04-21  Gavin Barraclough  <barraclough@apple.com>
    221
  • trunk/WebCore/bindings/js/JSDOMWindowBase.cpp

    r57379 r58012  
    3737#include "Settings.h"
    3838#include "WebCoreJSClientData.h"
     39#include <wtf/Threading.h>
    3940#include <wtf/text/CString.h>
    4041
     
    157158    static JSGlobalData* globalData = 0;
    158159    if (!globalData) {
    159         globalData = JSGlobalData::createLeaked().releaseRef();
     160        globalData = JSGlobalData::createLeaked(ThreadStackTypeLarge).releaseRef();
    160161        globalData->timeoutChecker.setTimeoutInterval(10000); // 10 seconds
    161162#ifndef NDEBUG
    162         globalData->mainThreadOnly = true;
     163        globalData->exclusiveThread = currentThread();
    163164#endif
    164165        initNormalWorldClientData(globalData);
  • trunk/WebCore/bindings/js/WorkerScriptController.cpp

    r57379 r58012  
    4949
    5050WorkerScriptController::WorkerScriptController(WorkerContext* workerContext)
    51     : m_globalData(JSGlobalData::create())
     51    : m_globalData(JSGlobalData::create(ThreadStackTypeSmall))
    5252    , m_workerContext(workerContext)
    5353    , m_executionForbidden(false)
Note: See TracChangeset for help on using the changeset viewer.