Changeset 86883 in webkit


Ignore:
Timestamp:
May 19, 2011 1:18:39 PM (13 years ago)
Author:
oliver@apple.com
Message:

2011-05-19 Oliver Hunt <oliver@apple.com>

Reviewed by Geoffrey Garen.

Make Executables release their JIT code as soon as they become dead
https://bugs.webkit.org/show_bug.cgi?id=61134

Add an ability to clear an Executable's jit code without requiring
it to be destroyed, and then call that from a finalizer.

  • heap/Weak.h: (JSC::Weak::Weak): (JSC::Weak::leak):
  • jit/JITCode.h: (JSC::JITCode::clear):
  • runtime/Executable.cpp: (JSC::ExecutableFinalizer::finalize): (JSC::ExecutableBase::executableFinalizer):
  • runtime/Executable.h: (JSC::ExecutableBase::ExecutableBase): (JSC::ExecutableBase::clearExecutableCode):
Location:
trunk/Source/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r86850 r86883  
     12011-05-19  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Make Executables release their JIT code as soon as they become dead
     6        https://bugs.webkit.org/show_bug.cgi?id=61134
     7
     8        Add an ability to clear an Executable's jit code without requiring
     9        it to be destroyed, and then call that from a finalizer.
     10
     11        * heap/Weak.h:
     12        (JSC::Weak::Weak):
     13        (JSC::Weak::leak):
     14        * jit/JITCode.h:
     15        (JSC::JITCode::clear):
     16        * runtime/Executable.cpp:
     17        (JSC::ExecutableFinalizer::finalize):
     18        (JSC::ExecutableBase::executableFinalizer):
     19        * runtime/Executable.h:
     20        (JSC::ExecutableBase::ExecutableBase):
     21        (JSC::ExecutableBase::clearExecutableCode):
     22
    1232011-05-19  Adam Roben  <aroben@apple.com>
    224
  • trunk/Source/JavaScriptCore/heap/Handle.h

    r86209 r86883  
    4848
    4949class HandleBase {
     50    template <typename T> friend class Weak;
    5051    friend class HandleHeap;
    5152    friend struct JSCallbackObjectData;
  • trunk/Source/JavaScriptCore/heap/HandleHeap.h

    r84660 r86883  
    7171#if !ASSERT_DISABLED
    7272    bool hasWeakOwner(HandleSlot, WeakHandleOwner*);
     73    bool hasFinalizer(HandleSlot);
    7374#endif
    7475
     
    198199    return toNode(handle)->weakOwner() == weakOwner;
    199200}
     201
     202inline bool HandleHeap::hasFinalizer(HandleSlot handle)
     203{
     204    return toNode(handle)->weakOwner();
     205}
    200206#endif
    201207
  • trunk/Source/JavaScriptCore/heap/Weak.h

    r84660 r86883  
    5454    }
    5555
     56    enum AdoptTag { Adopt };
     57    template<typename U> Weak(AdoptTag, Handle<U> handle)
     58        : Handle<T>(handle.slot())
     59    {
     60        validateCell(get());
     61    }
     62   
    5663    Weak(const Weak& other)
    5764        : Handle<T>()
     
    122129        return *this;
    123130    }
     131   
     132    HandleSlot leakHandle()
     133    {
     134        ASSERT(HandleHeap::heapFor(slot())->hasFinalizer(slot()));
     135        HandleSlot result = slot();
     136        setSlot(0);
     137        return result;
     138    }
    124139
    125140private:
  • trunk/Source/JavaScriptCore/jit/JITCode.h

    r70703 r86883  
    102102        }
    103103
     104        void clear()
     105        {
     106            m_ref.~CodeRef();
     107            new (&m_ref) CodeRef();
     108        }
     109
    104110    private:
    105111        JITCode(void* code, PassRefPtr<ExecutablePool> executablePool, size_t size)
  • trunk/Source/JavaScriptCore/runtime/Executable.cpp

    r86837 r86883  
    4343const ClassInfo ExecutableBase::s_info = { "Executable", 0, 0, 0 };
    4444
     45#if ENABLE(JIT)
     46class ExecutableFinalizer : public WeakHandleOwner {
     47    virtual void finalize(Handle<Unknown> handle, void*)
     48    {
     49        Weak<ExecutableBase> executable(Weak<ExecutableBase>::Adopt, handle);
     50        executable->clearExecutableCode();
     51    }
     52};
     53
     54WeakHandleOwner* ExecutableBase::executableFinalizer()
     55{
     56    DEFINE_STATIC_LOCAL(ExecutableFinalizer, finalizer, ());
     57    return &finalizer;
     58}
     59#endif
     60   
    4561const ClassInfo NativeExecutable::s_info = { "NativeExecutable", &ExecutableBase::s_info, 0, 0 };
    4662
  • trunk/Source/JavaScriptCore/runtime/Executable.h

    r86499 r86883  
    5858            , m_numParametersForConstruct(numParameters)
    5959        {
     60#if ENABLE(JIT)
     61            Weak<ExecutableBase> finalizer(globalData, this, executableFinalizer());
     62            finalizer.leakHandle();
     63#endif
    6064        }
    6165
     
    8791            ASSERT(m_jitCodeForConstruct);
    8892            return m_jitCodeForConstruct;
     93        }
     94
     95        void clearExecutableCode()
     96        {
     97            m_jitCodeForCall.clear();
     98            m_jitCodeForConstruct.clear();
    8999        }
    90100
     
    94104        MacroAssemblerCodePtr m_jitCodeForCallWithArityCheck;
    95105        MacroAssemblerCodePtr m_jitCodeForConstructWithArityCheck;
     106       
     107    private:
     108        static WeakHandleOwner* executableFinalizer();
    96109#endif
    97110    };
Note: See TracChangeset for help on using the changeset viewer.