Changeset 35159 in webkit for trunk/JavaScriptCore/API


Ignore:
Timestamp:
Jul 14, 2008, 4:28:57 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Geoff Garen.

Eliminate per-thread JavaScript global data instance support and make arbitrary
global data/global object combinations possible.

Location:
trunk/JavaScriptCore/API
Files:
6 edited

Legend:

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

    r34977 r35159  
    4242{
    4343    ExecState* exec = toJS(ctx);
     44    exec->globalData().heap->registerThread();
    4445    JSLock lock(exec);
     46
    4547    JSObject* jsThisObject = toJS(thisObject);
    4648    UString::Rep* scriptRep = toJS(script);
     
    6769{
    6870    ExecState* exec = toJS(ctx);
     71    exec->globalData().heap->registerThread();
    6972    JSLock lock(exec);
     73
    7074    UString::Rep* scriptRep = toJS(script);
    7175    UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
     
    8690        initializeThreading();
    8791
    88     // It might seem that we have a context passed to this function, and can use toJS(ctx)->heap(), but the parameter is likely to be NULL,
    89     // and it may actually be garbage for some clients (most likely, because of JSGarbageCollect being called after releasing the context).
     92    // When using a shared heap, clients need to call JSGarbageCollect(0) after releasing the last reference to the context to avoid
     93    // leaking protected objects. Because the function arguments were originally ignored, some clients may pass their released context here,
     94    // in which case there is a risk of crashing if another thread performs GC on the same heap in between.
     95    if (ctx) {
     96        ExecState* exec = toJS(ctx);
     97        JSGlobalData& globalData = exec->globalData();
     98        Heap* heap = globalData.heap;
    9099
    91     if (JSGlobalData::threadInstanceExists()) {
    92         Heap* heap = JSGlobalData::threadInstance().heap;
     100        JSLock lock(globalData.isSharedInstance);
     101
    93102        if (!heap->isBusy())
    94103            heap->collect();
    95     }
     104    } else {
     105        JSLock lock(true);
    96106
    97     JSLock lock(true);
    98 
    99     if (JSGlobalData::sharedInstanceExists()) {
    100         Heap* heap = JSGlobalData::sharedInstance().heap;
    101         if (!heap->isBusy())
    102             heap->collect();
     107        if (JSGlobalData::sharedInstanceExists()) {
     108            Heap* heap = JSGlobalData::sharedInstance().heap;
     109            if (!heap->isBusy())
     110                heap->collect();
     111        }
    103112    }
    104113
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r34947 r35159  
    4444    JSLock lock(true);
    4545
     46    JSGlobalData* sharedGlobalData = &JSGlobalData::sharedInstance();
     47
    4648    if (!globalObjectClass) {
    47         JSGlobalObject* globalObject = new (JSGlobalObject::Shared) JSGlobalObject;
     49        JSGlobalObject* globalObject = new (sharedGlobalData) JSGlobalObject;
    4850        return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
    4951    }
    5052
    51     JSGlobalObject* globalObject = new (JSGlobalObject::Shared) JSCallbackObject<JSGlobalObject>(globalObjectClass);
     53    JSGlobalObject* globalObject = new (sharedGlobalData) JSCallbackObject<JSGlobalObject>(globalObjectClass);
    5254    JSGlobalContextRef ctx = toGlobalRef(globalObject->globalExec());
    5355    JSValue* prototype = globalObjectClass->prototype(ctx);
     
    6163{
    6264    ExecState* exec = toJS(ctx);
     65    exec->globalData().heap->registerThread();
    6366    JSLock lock(exec);
     67
    6468    gcProtect(exec->dynamicGlobalObject());
    6569    return ctx;
     
    7074    ExecState* exec = toJS(ctx);
    7175    JSLock lock(exec);
     76
    7277    gcUnprotect(exec->dynamicGlobalObject());
    7378}
     
    7681{
    7782    ExecState* exec = toJS(ctx);
     83    exec->globalData().heap->registerThread();
    7884
    7985    // It is necessary to call toThisObject to get the wrapper object when used with WebCore.
  • trunk/JavaScriptCore/API/JSObjectRef.cpp

    r34947 r35159  
    6969{
    7070    ExecState* exec = toJS(ctx);
     71    exec->globalData().heap->registerThread();
    7172    JSLock lock(exec);
    7273
     
    8485{
    8586    ExecState* exec = toJS(ctx);
    86     JSLock lock(exec);
     87    exec->globalData().heap->registerThread();
     88    JSLock lock(exec);
     89
    8790    Identifier nameID = name ? Identifier(exec, toJS(name)) : Identifier(exec, "anonymous");
    8891   
     
    9396{
    9497    ExecState* exec = toJS(ctx);
    95     JSLock lock(exec);
    96    
     98    exec->globalData().heap->registerThread();
     99    JSLock lock(exec);
     100
    97101    JSValue* jsPrototype = jsClass
    98102        ? jsClass->prototype(ctx)
     
    107111{
    108112    ExecState* exec = toJS(ctx);
     113    exec->globalData().heap->registerThread();
    109114    JSLock lock(exec);
    110115
     
    146151{
    147152    ExecState* exec = toJS(ctx);
    148     JSLock lock(exec);
     153    exec->globalData().heap->registerThread();
     154    JSLock lock(exec);
     155
    149156    JSObject* jsObject = toJS(object);
    150157    UString::Rep* nameRep = toJS(propertyName);
     
    156163{
    157164    ExecState* exec = toJS(ctx);
    158     JSLock lock(exec);
     165    exec->globalData().heap->registerThread();
     166    JSLock lock(exec);
     167
    159168    JSObject* jsObject = toJS(object);
    160169    UString::Rep* nameRep = toJS(propertyName);
     
    172181{
    173182    ExecState* exec = toJS(ctx);
    174     JSLock lock(exec);
     183    exec->globalData().heap->registerThread();
     184    JSLock lock(exec);
     185
    175186    JSObject* jsObject = toJS(object);
    176187    Identifier name(exec, toJS(propertyName));
     
    192203{
    193204    ExecState* exec = toJS(ctx);
    194     JSLock lock(exec);
     205    exec->globalData().heap->registerThread();
     206    JSLock lock(exec);
     207
    195208    JSObject* jsObject = toJS(object);
    196209
     
    208221{
    209222    ExecState* exec = toJS(ctx);
    210     JSLock lock(exec);
     223    exec->globalData().heap->registerThread();
     224    JSLock lock(exec);
     225
    211226    JSObject* jsObject = toJS(object);
    212227    JSValue* jsValue = toJS(value);
     
    223238{
    224239    ExecState* exec = toJS(ctx);
    225     JSLock lock(exec);
     240    exec->globalData().heap->registerThread();
     241    JSLock lock(exec);
     242
    226243    JSObject* jsObject = toJS(object);
    227244    UString::Rep* nameRep = toJS(propertyName);
     
    272289{
    273290    ExecState* exec = toJS(ctx);
    274     JSLock lock(exec);
     291    exec->globalData().heap->registerThread();
     292    JSLock lock(exec);
     293
    275294    JSObject* jsObject = toJS(object);
    276295    JSObject* jsThisObject = toJS(thisObject);
     
    308327{
    309328    ExecState* exec = toJS(ctx);
    310     JSLock lock(exec);
     329    exec->globalData().heap->registerThread();
     330    JSLock lock(exec);
     331
    311332    JSObject* jsObject = toJS(object);
    312333
     
    343364    JSObject* jsObject = toJS(object);
    344365    ExecState* exec = toJS(ctx);
    345     JSLock lock(exec);
    346    
     366    exec->globalData().heap->registerThread();
     367    JSLock lock(exec);
     368
    347369    JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(&exec->globalData());
    348370    jsObject->getPropertyNames(exec, propertyNames->array);
     
    380402    UString::Rep* rep = toJS(propertyName);
    381403
     404    propertyNames->globalData()->heap->registerThread();
    382405    JSLock lock(propertyNames->globalData()->isSharedInstance);
     406
    383407    propertyNames->add(rep);
    384408}
  • trunk/JavaScriptCore/API/JSStringRef.cpp

    r34947 r35159  
    6767    bool needsLocking = rep->identifierTable;
    6868    if (needsLocking) {
    69         // It is wasteful to take the lock for per-thread contexts, but we don't have a good way
     69        // It is wasteful to take the lock for non-shared contexts, but we don't have a good way
    7070        // to determine what the context is.
    7171        JSLock lock(true);
  • trunk/JavaScriptCore/API/JSStringRefCF.cpp

    r34947 r35159  
    3030#include "APICast.h"
    3131#include "JSStringRef.h"
    32 #include <kjs/JSLock.h>
    3332#include <kjs/ustring.h>
    3433#include <kjs/JSValue.h>
  • trunk/JavaScriptCore/API/JSValueRef.cpp

    r34947 r35159  
    120120{
    121121    ExecState* exec = toJS(ctx);
     122    exec->globalData().heap->registerThread();
    122123    JSLock lock(exec);
    123124
     
    146147{
    147148    ExecState* exec = toJS(ctx);
     149    exec->globalData().heap->registerThread();
    148150    JSLock lock(exec);
    149151
     
    179181{
    180182    ExecState* exec = toJS(ctx);
     183    exec->globalData().heap->registerThread();
    181184    JSLock lock(exec);
    182185
     
    187190{
    188191    ExecState* exec = toJS(ctx);
     192    exec->globalData().heap->registerThread();
    189193    JSLock lock(exec);
    190194
     
    203207{
    204208    ExecState* exec = toJS(ctx);
     209    exec->globalData().heap->registerThread();
    205210    JSLock lock(exec);
    206211
     
    220225{
    221226    ExecState* exec = toJS(ctx);
     227    exec->globalData().heap->registerThread();
    222228    JSLock lock(exec);
    223229
     
    237243{
    238244    ExecState* exec = toJS(ctx);
     245    exec->globalData().heap->registerThread();
    239246    JSLock lock(exec);
    240247
     
    254261{
    255262    ExecState* exec = toJS(ctx);
     263    exec->globalData().heap->registerThread();
    256264    JSLock lock(exec);
    257265
     
    263271{
    264272    ExecState* exec = toJS(ctx);
     273    exec->globalData().heap->registerThread();
    265274    JSLock lock(exec);
    266275
Note: See TracChangeset for help on using the changeset viewer.