Ignore:
Timestamp:
Jul 29, 2008, 11:05:11 PM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Geoff Garen.

Implement JSContextGroup APIs to make concurrent execution possible for
JavaScriptCore clients.

This changes the behavior of JSGlobalContextCreate(), so that it now uses a private context
group for each context, making JSlock implicit locking unnecessary.

  • API/JSContextRef.h:
  • API/JSContextRef.cpp: (JSContextGroupCreate): (JSContextGroupRetain): (JSContextGroupRelease): (JSGlobalContextCreate): (JSGlobalContextCreateInGroup): (JSGlobalContextRelease): (JSContextGetGroup): Added new methods. JSGlobalContextCreate() calls JSGlobalContextCreateInGroup() now.
  • API/APICast.h: (toJS): (toRef): Added converters for JSContextGroupRef.
  • API/JSBase.cpp: (JSGarbageCollect): JSGarbageCollect(0) is now a no-op, and the passed in context is actually used.
  • API/JSBase.h: Aded a typedef for JSContextGroupRef. Updated documentation for JSGarbageCollect().
  • kjs/JSGlobalData.cpp:
  • kjs/JSGlobalData.h: Removed support for JSGlobalData shared instance. JSGlobalData::isSharedInstance member variable still remains, to be deleted in a followup patch.
  • kjs/JSLock.cpp: (KJS::JSLock::JSLock): Disabled JSLock, to be deleted in a follow-up patch.


  • kjs/collector.cpp: (KJS::Heap::markOtherThreadConservatively): Removed an assertion that referenced JSGlobalData::sharedInstance.
  • kjs/collector.h: Made Heap destructor public, so that JSContextRelease can use it.

JavaScriptGlue:

  • JSRun.cpp: (JSRun::JSRun):
  • JSUtils.cpp: (getThreadGlobalExecState): Changed JavaScriptGlue to use a JSGlobalData of its own, now that there is no shared instance.
File:
1 edited

Legend:

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

    r35293 r35442  
    3838using namespace KJS;
    3939
     40JSContextGroupRef JSContextGroupCreate()
     41{
     42    return toRef(JSGlobalData::create().releaseRef());
     43}
     44
     45JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group)
     46{
     47    toJS(group)->ref();
     48    return group;
     49}
     50
     51void JSContextGroupRelease(JSContextGroupRef group)
     52{
     53    toJS(group)->deref();
     54}
     55
    4056JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass)
     57{
     58    return JSGlobalContextCreateInGroup(toRef(JSGlobalData::create().get()), globalObjectClass);
     59}
     60
     61JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass)
    4162{
    4263    initializeThreading();
     
    4465    JSLock lock(true);
    4566
    46     JSGlobalData* sharedGlobalData = &JSGlobalData::sharedInstance();
     67    JSGlobalData* globalData = toJS(group);
    4768
    4869    if (!globalObjectClass) {
    49         JSGlobalObject* globalObject = new (sharedGlobalData) JSGlobalObject;
     70        JSGlobalObject* globalObject = new (globalData) JSGlobalObject;
    5071        return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
    5172    }
    5273
    53     JSGlobalObject* globalObject = new (sharedGlobalData) JSCallbackObject<JSGlobalObject>(globalObjectClass);
     74    JSGlobalObject* globalObject = new (globalData) JSCallbackObject<JSGlobalObject>(globalObjectClass);
    5475    ExecState* exec = globalObject->globalExec();
    5576    JSValue* prototype = globalObjectClass->prototype(exec);
     
    7697
    7798    gcUnprotect(exec->dynamicGlobalObject());
     99
     100    JSGlobalData& globalData = exec->globalData();
     101    if (globalData.refCount() == 1) {
     102        // The last reference was released, this is our last chance to collect.
     103        Heap* heap = globalData.heap;
     104
     105        ASSERT(!heap->protectedObjectCount());
     106        ASSERT(!heap->isBusy());
     107
     108        // Heap::destroy() will delete JSGlobalObject, which will in turn delete JSGlobalData, which will
     109        // delete the heap, which would cause a crash if allowed.
     110        globalData.heap = 0;
     111
     112        delete heap;
     113    }
    78114}
    79115
     
    86122    return toRef(exec->dynamicGlobalObject()->toThisObject(exec));
    87123}
     124
     125JSContextGroupRef JSContextGetGroup(JSContextRef ctx)
     126{
     127    ExecState* exec = toJS(ctx);
     128    return toRef(&exec->globalData());
     129}
Note: See TracChangeset for help on using the changeset viewer.