Ignore:
Timestamp:
Jun 19, 2008, 10:29:29 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin.

Prepare JavaScript heap for being per-thread.

File:
1 edited

Legend:

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

    r34607 r34659  
    9090}
    9191
    92 JSGlobalObject* JSGlobalObject::s_head = 0;
    93 
    9492JSGlobalObject::~JSGlobalObject()
    9593{
    96     ASSERT(JSLock::currentThreadIsHoldingLock());
    97 
    9894    if (d()->debugger)
    9995        d()->debugger->detach(this);
     
    10197    d()->next->d()->prev = d()->prev;
    10298    d()->prev->d()->next = d()->next;
    103     s_head = d()->next;
    104     if (s_head == this)
    105         s_head = 0;
     99    JSGlobalObject*& headObject = head();
     100    if (headObject == this)
     101        headObject = d()->next;
     102    if (headObject == this)
     103        headObject = 0;
    106104
    107105    HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
     
    116114    ASSERT(JSLock::currentThreadIsHoldingLock());
    117115
    118     if (s_head) {
    119         d()->prev = s_head;
    120         d()->next = s_head->d()->next;
    121         s_head->d()->next->d()->prev = this;
    122         s_head->d()->next = this;
     116    if (JSGlobalObject*& headObject = head()) {
     117        d()->prev = headObject;
     118        d()->next = headObject->d()->next;
     119        headObject->d()->next->d()->prev = this;
     120        headObject->d()->next = this;
    123121    } else
    124         s_head = d()->next = d()->prev = this;
     122        headObject = d()->next = d()->prev = this;
    125123
    126124    resetTimeoutCheck();
     
    142140void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
    143141{
     142    ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
     143
    144144    if (symbolTablePut(propertyName, value))
    145145        return;
     
    235235
    236236    // Prototypes
    237     d()->functionPrototype = new FunctionPrototype(exec);
    238     d()->objectPrototype = new ObjectPrototype(exec, d()->functionPrototype);
     237    d()->functionPrototype = new (exec) FunctionPrototype(exec);
     238    d()->objectPrototype = new (exec) ObjectPrototype(exec, d()->functionPrototype);
    239239    d()->functionPrototype->setPrototype(d()->objectPrototype);
    240240
    241     d()->arrayPrototype = new ArrayPrototype(exec, d()->objectPrototype);
    242     d()->stringPrototype = new StringPrototype(exec, d()->objectPrototype);
    243     d()->booleanPrototype = new BooleanPrototype(exec, d()->objectPrototype, d()->functionPrototype);
    244     d()->numberPrototype = new NumberPrototype(exec, d()->objectPrototype, d()->functionPrototype);
    245     d()->datePrototype = new DatePrototype(exec, d()->objectPrototype);
    246     d()->regExpPrototype = new RegExpPrototype(exec, d()->objectPrototype, d()->functionPrototype);
    247     d()->errorPrototype = new ErrorPrototype(exec, d()->objectPrototype, d()->functionPrototype);
    248    
    249     d()->evalErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "EvalError", "EvalError");
    250     d()->rangeErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "RangeError", "RangeError");
    251     d()->referenceErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "ReferenceError", "ReferenceError");
    252     d()->syntaxErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "SyntaxError", "SyntaxError");
    253     d()->typeErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "TypeError", "TypeError");
    254     d()->URIErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "URIError", "URIError");
     241    d()->arrayPrototype = new (exec) ArrayPrototype(exec, d()->objectPrototype);
     242    d()->stringPrototype = new (exec) StringPrototype(exec, d()->objectPrototype);
     243    d()->booleanPrototype = new (exec) BooleanPrototype(exec, d()->objectPrototype, d()->functionPrototype);
     244    d()->numberPrototype = new (exec) NumberPrototype(exec, d()->objectPrototype, d()->functionPrototype);
     245    d()->datePrototype = new (exec) DatePrototype(exec, d()->objectPrototype);
     246    d()->regExpPrototype = new (exec) RegExpPrototype(exec, d()->objectPrototype, d()->functionPrototype);
     247    d()->errorPrototype = new (exec) ErrorPrototype(exec, d()->objectPrototype, d()->functionPrototype);
     248   
     249    d()->evalErrorPrototype = new (exec) NativeErrorPrototype(exec, d()->errorPrototype, "EvalError", "EvalError");
     250    d()->rangeErrorPrototype = new (exec) NativeErrorPrototype(exec, d()->errorPrototype, "RangeError", "RangeError");
     251    d()->referenceErrorPrototype = new (exec) NativeErrorPrototype(exec, d()->errorPrototype, "ReferenceError", "ReferenceError");
     252    d()->syntaxErrorPrototype = new (exec) NativeErrorPrototype(exec, d()->errorPrototype, "SyntaxError", "SyntaxError");
     253    d()->typeErrorPrototype = new (exec) NativeErrorPrototype(exec, d()->errorPrototype, "TypeError", "TypeError");
     254    d()->URIErrorPrototype = new (exec) NativeErrorPrototype(exec, d()->errorPrototype, "URIError", "URIError");
    255255
    256256    // Constructors
    257     d()->objectConstructor = new ObjectConstructor(exec, d()->objectPrototype, d()->functionPrototype);
    258     d()->functionConstructor = new FunctionConstructor(exec, d()->functionPrototype);
    259     d()->arrayConstructor = new ArrayConstructor(exec, d()->functionPrototype, d()->arrayPrototype);
    260     d()->stringConstructor = new StringConstructor(exec, d()->functionPrototype, d()->stringPrototype);
    261     d()->booleanConstructor = new BooleanConstructor(exec, d()->functionPrototype, d()->booleanPrototype);
    262     d()->numberConstructor = new NumberConstructor(exec, d()->functionPrototype, d()->numberPrototype);
    263     d()->dateConstructor = new DateConstructor(exec, d()->functionPrototype, d()->datePrototype);
    264     d()->regExpConstructor = new RegExpConstructor(exec, d()->functionPrototype, d()->regExpPrototype);
    265     d()->errorConstructor = new ErrorConstructor(exec, d()->functionPrototype, d()->errorPrototype);
    266    
    267     d()->evalErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->evalErrorPrototype);
    268     d()->rangeErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->rangeErrorPrototype);
    269     d()->referenceErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->referenceErrorPrototype);
    270     d()->syntaxErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->syntaxErrorPrototype);
    271     d()->typeErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->typeErrorPrototype);
    272     d()->URIErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->URIErrorPrototype);
     257    d()->objectConstructor = new (exec) ObjectConstructor(exec, d()->objectPrototype, d()->functionPrototype);
     258    d()->functionConstructor = new (exec) FunctionConstructor(exec, d()->functionPrototype);
     259    d()->arrayConstructor = new (exec) ArrayConstructor(exec, d()->functionPrototype, d()->arrayPrototype);
     260    d()->stringConstructor = new (exec) StringConstructor(exec, d()->functionPrototype, d()->stringPrototype);
     261    d()->booleanConstructor = new (exec) BooleanConstructor(exec, d()->functionPrototype, d()->booleanPrototype);
     262    d()->numberConstructor = new (exec) NumberConstructor(exec, d()->functionPrototype, d()->numberPrototype);
     263    d()->dateConstructor = new (exec) DateConstructor(exec, d()->functionPrototype, d()->datePrototype);
     264    d()->regExpConstructor = new (exec) RegExpConstructor(exec, d()->functionPrototype, d()->regExpPrototype);
     265    d()->errorConstructor = new (exec) ErrorConstructor(exec, d()->functionPrototype, d()->errorPrototype);
     266   
     267    d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, d()->functionPrototype, d()->evalErrorPrototype);
     268    d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, d()->functionPrototype, d()->rangeErrorPrototype);
     269    d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, d()->functionPrototype, d()->referenceErrorPrototype);
     270    d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, d()->functionPrototype, d()->syntaxErrorPrototype);
     271    d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, d()->functionPrototype, d()->typeErrorPrototype);
     272    d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, d()->functionPrototype, d()->URIErrorPrototype);
    273273   
    274274    d()->functionPrototype->putDirect(exec->propertyNames().constructor, d()->functionConstructor, DontEnum);
     
    312312    // Set global values.
    313313    GlobalPropertyInfo staticGlobals[] = {
    314         GlobalPropertyInfo(Identifier(exec, "Math"), new MathObject(exec, d()->objectPrototype), DontEnum | DontDelete),
    315         GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(), DontEnum | DontDelete),
    316         GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(Inf), DontEnum | DontDelete),
     314        GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, d()->objectPrototype), DontEnum | DontDelete),
     315        GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete),
     316        GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete),
    317317        GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete)
    318318    };
     
    322322    // Set global functions.
    323323
    324     d()->evalFunction = new PrototypeReflexiveFunction(exec, d()->functionPrototype, 1, exec->propertyNames().eval, globalFuncEval, this);
     324    d()->evalFunction = new (exec) PrototypeReflexiveFunction(exec, d()->functionPrototype, 1, exec->propertyNames().eval, globalFuncEval, this);
    325325    putDirectFunction(d()->evalFunction, DontEnum);
    326     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum);
    327     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum);
    328     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum);
    329     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum);
    330     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum);
    331     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum);
    332     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum);
    333     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum);
    334     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum);
    335     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum);
     326    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum);
     327    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum);
     328    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum);
     329    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum);
     330    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum);
     331    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum);
     332    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum);
     333    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum);
     334    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum);
     335    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum);
    336336#ifndef NDEBUG
    337     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "kjsprint"), globalFuncKJSPrint), DontEnum);
     337    putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 1, Identifier(exec, "kjsprint"), globalFuncKJSPrint), DontEnum);
    338338#endif
    339339
     
    412412        (*it)->mark();
    413413
    414     registerFileStack().mark();
     414    registerFileStack().mark(globalData()->heap);
    415415
    416416    markIfNeeded(d()->globalExec->exception());
     
    466466}
    467467
     468void* JSGlobalObject::operator new(size_t size)
     469{
     470#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
     471    return JSGlobalData::threadInstance().heap->inlineAllocate(size);
     472#else
     473    return JSGlobalData::threadInstance().heap->allocate(size);
     474#endif
     475}
     476
     477void* JSGlobalObject::operator new(size_t size, SharedTag)
     478{
     479#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
     480    return JSGlobalData::sharedInstance().heap->inlineAllocate(size);
     481#else
     482    return JSGlobalData::sharedInstance().heap->allocate(size);
     483#endif
     484}
    468485
    469486} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.