Changeset 35853 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Aug 20, 2008, 12:23:06 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Geoff Garen.

Bring back shared JSGlobalData and implicit locking, because too many clients rely on it.

Location:
trunk/JavaScriptCore/kjs
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/AllInOneFile.cpp

    r35478 r35853  
    6262#include "interpreter.cpp"
    6363#include "JSImmediate.cpp"
     64#include "JSLock.cpp"
    6465#include "JSWrapperObject.cpp"
    6566#include "lexer.cpp"
  • trunk/JavaScriptCore/kjs/JSGlobalData.cpp

    r35815 r35853  
    3333#include "CommonIdentifiers.h"
    3434#include "JSClassRef.h"
     35#include "JSLock.h"
    3536#include "Machine.h"
    3637#include "Parser.h"
     
    5657extern const HashTable stringTable;
    5758
    58 JSGlobalData::JSGlobalData()
     59JSGlobalData::JSGlobalData(bool isShared)
    5960    : machine(new Machine)
    6061    , heap(new Heap(this))
     
    8586    , parser(new Parser)
    8687    , head(0)
     88    , isSharedInstance(isShared)
    8789{
    8890}
     
    9193{
    9294    delete heap;
    93     heap = 0; // zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
    9495    delete machine;
     96#ifndef NDEBUG
     97    // Zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
     98    heap = 0;
    9599    machine = 0;
     100#endif
    96101
    97102#if ENABLE(JSC_MULTIPLE_THREADS)
     
    132137}
    133138
     139bool JSGlobalData::sharedInstanceExists()
     140{
     141    return sharedInstanceInternal();
    134142}
     143
     144JSGlobalData& JSGlobalData::sharedInstance()
     145{
     146    JSGlobalData*& instance = sharedInstanceInternal();
     147    if (!instance)
     148        instance = new JSGlobalData(true);
     149    return *instance;
     150}
     151
     152JSGlobalData*& JSGlobalData::sharedInstanceInternal()
     153{
     154    ASSERT(JSLock::currentThreadIsHoldingLock());
     155    static JSGlobalData* sharedInstance;
     156    return sharedInstance;
     157}
     158
     159}
  • trunk/JavaScriptCore/kjs/JSGlobalData.h

    r35511 r35853  
    5555    class JSGlobalData : public RefCounted<JSGlobalData> {
    5656    public:
     57        static bool sharedInstanceExists();
     58        static JSGlobalData& sharedInstance();
     59
    5760        static PassRefPtr<JSGlobalData> create();
    5861        ~JSGlobalData();
     
    8386        JSGlobalObject* head;
    8487
     88        bool isSharedInstance;
     89
    8590    private:
    86         JSGlobalData();
     91        JSGlobalData(bool isShared = false);
     92
     93        static JSGlobalData*& sharedInstanceInternal();
    8794    };
    8895
  • trunk/JavaScriptCore/kjs/JSGlobalObject.cpp

    r35807 r35853  
    4444#include "GlobalEvalFunction.h"
    4545#include "JSGlobalObjectFunctions.h"
     46#include "JSLock.h"
    4647#include "Machine.h"
    4748#include "MathObject.h"
     
    7980JSGlobalObject::~JSGlobalObject()
    8081{
     82    ASSERT(JSLock::currentThreadIsHoldingLock());
     83
    8184    if (d()->debugger)
    8285        d()->debugger->detach(this);
     
    110113void JSGlobalObject::init(JSObject* thisValue)
    111114{
     115    ASSERT(JSLock::currentThreadIsHoldingLock());
     116
    112117    d()->globalData = Heap::heap(this)->globalData();
    113118
  • trunk/JavaScriptCore/kjs/Shell.cpp

    r35807 r35853  
    3131#include "JSFunction.h"
    3232#include "JSGlobalObject.h"
     33#include "JSLock.h"
    3334#include "JSObject.h"
    3435#include "Parser.h"
     
    209210JSValue* functionGC(ExecState* exec, JSObject*, JSValue*, const ArgList&)
    210211{
     212    JSLock lock(false);
    211213    exec->heap()->collect();
    212214    return jsUndefined();
     
    460462    KJS::initializeThreading();
    461463
     464    JSLock lock(false);
     465
    462466    Options options;
    463467    parseArguments(argc, argv, options);
  • trunk/JavaScriptCore/kjs/collector.cpp

    r35830 r35853  
    2525#include "ExecState.h"
    2626#include "JSGlobalObject.h"
     27#include "JSLock.h"
    2728#include "JSString.h"
    2829#include "JSValue.h"
     
    135136Heap::~Heap()
    136137{
     138    JSLock lock(false);
     139
    137140    // The global object is not GC protected at this point, so sweeping may delete it (and thus the global data)
    138141    // before other objects that may use the global data.
     
    274277
    275278    CollectorHeap& heap = heapType == PrimaryHeap ? primaryHeap : numberHeap;
     279    ASSERT(JSLock::lockCount() > 0);
     280    ASSERT(JSLock::currentThreadIsHoldingLock());
    276281    ASSERT(s <= HeapConstants<heapType>::cellSize);
    277282    UNUSED_PARAM(s); // s is now only used for the above assert
     
    778783{
    779784    // Most clients do not need to call this, with the notable exception of WebCore.
    780     // Clients that use context from a single context group from multiple threads are supposed
     785    // Clients that use shared heap have JSLock protection, while others are supposed
    781786    // to do explicit locking. WebCore violates this contract in Database code,
    782787    // which calls gcUnprotect from a secondary thread.
     
    788793{
    789794    ASSERT(k);
     795    ASSERT(JSLock::currentThreadIsHoldingLock() || !m_globalData->isSharedInstance);
    790796
    791797    if (JSImmediate::isImmediate(k))
     
    804810{
    805811    ASSERT(k);
     812    ASSERT(JSLock::currentThreadIsHoldingLock() || !m_globalData->isSharedInstance);
    806813
    807814    if (JSImmediate::isImmediate(k))
     
    941948bool Heap::collect()
    942949{
     950#ifndef NDEBUG
     951    if (m_globalData->isSharedInstance) {
     952        ASSERT(JSLock::lockCount() > 0);
     953        ASSERT(JSLock::currentThreadIsHoldingLock());
     954    }
     955#endif
     956
    943957    ASSERT((primaryHeap.operationInProgress == NoOperation) | (numberHeap.operationInProgress == NoOperation));
    944958    if ((primaryHeap.operationInProgress != NoOperation) | (numberHeap.operationInProgress != NoOperation))
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r35478 r35853  
    2626#include "ExecState.h"
    2727#include "JSGlobalObject.h"
     28#include "JSLock.h"
    2829#include "Machine.h"
    2930#include "Parser.h"
     
    4647Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source)
    4748{
     49    JSLock lock(exec);
     50
    4851    int errLine;
    4952    UString errMsg;
     
    6265Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source, JSValue* thisValue)
    6366{
     67    JSLock lock(exec);
     68   
    6469    // parse the source code
    6570    int sourceId;
Note: See TracChangeset for help on using the changeset viewer.