Changeset 201180 in webkit


Ignore:
Timestamp:
May 19, 2016 2:02:44 PM (8 years ago)
Author:
mark.lam@apple.com
Message:

Code that null checks the VM pointer before any use should ref the VM.
https://bugs.webkit.org/show_bug.cgi?id=157864

Reviewed by Filip Pizlo and Keith Miller.

JSLock::willReleaseLock() and HeapTimer::timerDidFire() need to reference the VM
through a RefPtr. Otherwise, there's no guarantee that the VM won't be deleted
after their null checks.

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::vm):
(JSC::CodeBlock::setVM): Deleted.

  • Not used, and suggests that it can be changed during the lifetime of the CodeBlock (which should not be).
  • heap/HeapTimer.cpp:

(JSC::HeapTimer::timerDidFire):

  • runtime/JSLock.cpp:

(JSC::JSLock::willReleaseLock):

  • Store the VM pointer in a RefPtr first, and null check the RefPtr instead of the raw VM pointer. This makes the null check a strong guarantee that the VM pointer is valid while these functions are using it.
Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r201176 r201180  
     12016-05-19  Mark Lam  <mark.lam@apple.com>
     2
     3        Code that null checks the VM pointer before any use should ref the VM.
     4        https://bugs.webkit.org/show_bug.cgi?id=157864
     5
     6        Reviewed by Filip Pizlo and Keith Miller.
     7
     8        JSLock::willReleaseLock() and HeapTimer::timerDidFire() need to reference the VM
     9        through a RefPtr.  Otherwise, there's no guarantee that the VM won't be deleted
     10        after their null checks.
     11
     12        * bytecode/CodeBlock.h:
     13        (JSC::CodeBlock::vm):
     14        (JSC::CodeBlock::setVM): Deleted.
     15        - Not used, and suggests that it can be changed during the lifetime of the
     16          CodeBlock (which should not be).
     17
     18        * heap/HeapTimer.cpp:
     19        (JSC::HeapTimer::timerDidFire):
     20        * runtime/JSLock.cpp:
     21        (JSC::JSLock::willReleaseLock):
     22        - Store the VM pointer in a RefPtr first, and null check the RefPtr instead of
     23          the raw VM pointer.  This makes the null check a strong guarantee that the
     24          VM pointer is valid while these functions are using it.
     25
    1262016-05-19  Saam barati  <sbarati@apple.com>
    227
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r200981 r201180  
    341341    ScriptExecutable* ownerScriptExecutable() const { return jsCast<ScriptExecutable*>(m_ownerExecutable.get()); }
    342342
    343     void setVM(VM* vm) { m_vm = vm; }
    344     VM* vm() { return m_vm; }
     343    VM* vm() const { return m_vm; }
    345344
    346345    void setThisRegister(VirtualRegister thisRegister) { m_thisRegister = thisRegister; }
  • trunk/Source/JavaScriptCore/heap/HeapTimer.cpp

    r192773 r201180  
    8181    apiLock->lock();
    8282
    83     VM* vm = apiLock->vm();
    84     // The VM has been destroyed, so we should just give up.
     83    RefPtr<VM> vm = apiLock->vm();
    8584    if (!vm) {
     85        // The VM has been destroyed, so we should just give up.
    8686        apiLock->unlock();
    8787        return;
     
    9999
    100100    {
    101         JSLockHolder locker(vm);
     101        JSLockHolder locker(vm.get());
    102102        heapTimer->doWork();
    103103    }
  • trunk/Source/JavaScriptCore/runtime/JSLock.cpp

    r194840 r201180  
    178178void JSLock::willReleaseLock()
    179179{
    180     if (m_vm) {
    181         m_vm->drainMicrotasks();
    182 
    183         m_vm->heap.releaseDelayedReleasedObjects();
    184         m_vm->setStackPointerAtVMEntry(nullptr);
     180    RefPtr<VM> vm = m_vm;
     181    if (vm) {
     182        vm->drainMicrotasks();
     183
     184        vm->heap.releaseDelayedReleasedObjects();
     185        vm->setStackPointerAtVMEntry(nullptr);
    185186    }
    186187
Note: See TracChangeset for help on using the changeset viewer.