Changeset 58012 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Apr 21, 2010, 1:59:14 PM (15 years ago)
Author:
[email protected]
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/JavaScriptCore/runtime
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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();
Note: See TracChangeset for help on using the changeset viewer.