Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (86882 => 86883)
--- trunk/Source/_javascript_Core/ChangeLog 2011-05-19 20:18:26 UTC (rev 86882)
+++ trunk/Source/_javascript_Core/ChangeLog 2011-05-19 20:18:39 UTC (rev 86883)
@@ -1,3 +1,25 @@
+2011-05-19 Oliver Hunt <[email protected]>
+
+ 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):
+
2011-05-19 Adam Roben <[email protected]>
Remove a redundant and broken data export
Modified: trunk/Source/_javascript_Core/heap/Handle.h (86882 => 86883)
--- trunk/Source/_javascript_Core/heap/Handle.h 2011-05-19 20:18:26 UTC (rev 86882)
+++ trunk/Source/_javascript_Core/heap/Handle.h 2011-05-19 20:18:39 UTC (rev 86883)
@@ -47,6 +47,7 @@
template<typename KeyType, typename MappedType, typename FinalizerCallback, typename HashArg, typename KeyTraitsArg> class WeakGCMap;
class HandleBase {
+ template <typename T> friend class Weak;
friend class HandleHeap;
friend struct JSCallbackObjectData;
template <typename KeyType, typename MappedType, typename FinalizerCallback, typename HashArg, typename KeyTraitsArg> friend class WeakGCMap;
Modified: trunk/Source/_javascript_Core/heap/HandleHeap.h (86882 => 86883)
--- trunk/Source/_javascript_Core/heap/HandleHeap.h 2011-05-19 20:18:26 UTC (rev 86882)
+++ trunk/Source/_javascript_Core/heap/HandleHeap.h 2011-05-19 20:18:39 UTC (rev 86883)
@@ -70,6 +70,7 @@
#if !ASSERT_DISABLED
bool hasWeakOwner(HandleSlot, WeakHandleOwner*);
+ bool hasFinalizer(HandleSlot);
#endif
unsigned protectedGlobalObjectCount();
@@ -197,6 +198,11 @@
{
return toNode(handle)->weakOwner() == weakOwner;
}
+
+inline bool HandleHeap::hasFinalizer(HandleSlot handle)
+{
+ return toNode(handle)->weakOwner();
+}
#endif
inline HandleHeap::Node::Node(HandleHeap* handleHeap)
Modified: trunk/Source/_javascript_Core/heap/Weak.h (86882 => 86883)
--- trunk/Source/_javascript_Core/heap/Weak.h 2011-05-19 20:18:26 UTC (rev 86882)
+++ trunk/Source/_javascript_Core/heap/Weak.h 2011-05-19 20:18:39 UTC (rev 86883)
@@ -53,6 +53,13 @@
set(value);
}
+ enum AdoptTag { Adopt };
+ template<typename U> Weak(AdoptTag, Handle<U> handle)
+ : Handle<T>(handle.slot())
+ {
+ validateCell(get());
+ }
+
Weak(const Weak& other)
: Handle<T>()
{
@@ -121,6 +128,14 @@
setSlot(HandleHeap::heapFor(other.slot())->copyWeak(other.slot()));
return *this;
}
+
+ HandleSlot leakHandle()
+ {
+ ASSERT(HandleHeap::heapFor(slot())->hasFinalizer(slot()));
+ HandleSlot result = slot();
+ setSlot(0);
+ return result;
+ }
private:
static HandleSlot hashTableDeletedValue() { return reinterpret_cast<HandleSlot>(-1); }
Modified: trunk/Source/_javascript_Core/jit/JITCode.h (86882 => 86883)
--- trunk/Source/_javascript_Core/jit/JITCode.h 2011-05-19 20:18:26 UTC (rev 86882)
+++ trunk/Source/_javascript_Core/jit/JITCode.h 2011-05-19 20:18:39 UTC (rev 86883)
@@ -101,6 +101,12 @@
return JITCode(code.dataLocation(), 0, 0);
}
+ void clear()
+ {
+ m_ref.~CodeRef();
+ new (&m_ref) CodeRef();
+ }
+
private:
JITCode(void* code, PassRefPtr<ExecutablePool> executablePool, size_t size)
: m_ref(code, executablePool, size)
Modified: trunk/Source/_javascript_Core/runtime/Executable.cpp (86882 => 86883)
--- trunk/Source/_javascript_Core/runtime/Executable.cpp 2011-05-19 20:18:26 UTC (rev 86882)
+++ trunk/Source/_javascript_Core/runtime/Executable.cpp 2011-05-19 20:18:39 UTC (rev 86883)
@@ -42,6 +42,22 @@
const ClassInfo ExecutableBase::s_info = { "Executable", 0, 0, 0 };
+#if ENABLE(JIT)
+class ExecutableFinalizer : public WeakHandleOwner {
+ virtual void finalize(Handle<Unknown> handle, void*)
+ {
+ Weak<ExecutableBase> executable(Weak<ExecutableBase>::Adopt, handle);
+ executable->clearExecutableCode();
+ }
+};
+
+WeakHandleOwner* ExecutableBase::executableFinalizer()
+{
+ DEFINE_STATIC_LOCAL(ExecutableFinalizer, finalizer, ());
+ return &finalizer;
+}
+#endif
+
const ClassInfo NativeExecutable::s_info = { "NativeExecutable", &ExecutableBase::s_info, 0, 0 };
NativeExecutable::~NativeExecutable()
Modified: trunk/Source/_javascript_Core/runtime/Executable.h (86882 => 86883)
--- trunk/Source/_javascript_Core/runtime/Executable.h 2011-05-19 20:18:26 UTC (rev 86882)
+++ trunk/Source/_javascript_Core/runtime/Executable.h 2011-05-19 20:18:39 UTC (rev 86883)
@@ -57,6 +57,10 @@
, m_numParametersForCall(numParameters)
, m_numParametersForConstruct(numParameters)
{
+#if ENABLE(JIT)
+ Weak<ExecutableBase> finalizer(globalData, this, executableFinalizer());
+ finalizer.leakHandle();
+#endif
}
bool isHostFunction() const
@@ -88,11 +92,20 @@
return m_jitCodeForConstruct;
}
+ void clearExecutableCode()
+ {
+ m_jitCodeForCall.clear();
+ m_jitCodeForConstruct.clear();
+ }
+
protected:
JITCode m_jitCodeForCall;
JITCode m_jitCodeForConstruct;
MacroAssemblerCodePtr m_jitCodeForCallWithArityCheck;
MacroAssemblerCodePtr m_jitCodeForConstructWithArityCheck;
+
+ private:
+ static WeakHandleOwner* executableFinalizer();
#endif
};