Changeset 35442 in webkit for trunk/JavaScriptCore/API/JSBase.cpp


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/JSBase.cpp

    r35159 r35442  
    8686void JSGarbageCollect(JSContextRef ctx)
    8787{
    88     // Unlikely, but it is legal to call JSGarbageCollect(0) before actually doing anything that would implicitly call initializeThreading().
     88    // We used to recommend passing NULL as an argument here, which caused the only heap to be collected.
     89    // As there is no longer a shared heap, the previously recommended usage became a no-op (but the GC
     90    // will happen when the context group is destroyed).
     91    // Because the function argument was originally ignored, some clients may pass their released context here,
     92    // in which case there is a risk of crashing if another thread performs GC on the same heap in between.
    8993    if (!ctx)
    90         initializeThreading();
     94        return;
    9195
    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;
     96    ExecState* exec = toJS(ctx);
     97    JSGlobalData& globalData = exec->globalData();
     98    Heap* heap = globalData.heap;
    9999
    100         JSLock lock(globalData.isSharedInstance);
     100    JSLock lock(globalData.isSharedInstance);
    101101
    102         if (!heap->isBusy())
    103             heap->collect();
    104     } else {
    105         JSLock lock(true);
    106 
    107         if (JSGlobalData::sharedInstanceExists()) {
    108             Heap* heap = JSGlobalData::sharedInstance().heap;
    109             if (!heap->isBusy())
    110                 heap->collect();
    111         }
    112     }
     102    if (!heap->isBusy())
     103        heap->collect();
    113104
    114105    // FIXME: Perhaps we should trigger a second mark and sweep
Note: See TracChangeset for help on using the changeset viewer.