Ignore:
Timestamp:
Feb 15, 2011, 3:54:06 PM (14 years ago)
Author:
[email protected]
Message:

2011-02-14 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough and Geoff Garen.

Refactor handles and weak pointers to become nicer and more automatic
https://bugs.webkit.org/show_bug.cgi?id=54415

Move to a true handle based mechanism for GC value protection. This
also allows us to switch to a more sensible behaviour for weak pointers
in which weak pointers are automatically updated.

This allows us to remove the old (and convoluted) that required all
objects that may be held by a weak reference to be aware of the reference
and manually clear them in their destructors.

This also adds a few new data types to JSC that we use to efficiently
allocate and return the underlying handle storage.

This patch is largely renaming and removing now unnecessary destructors
from objects.

New Global handle type used to keep gc objects live, even if they're not
marked.

(JSC::Global::Global):
(JSC::Global::~Global):
(JSC::Global::set):

We can only assign directly to a global from another global.
In all other cases we need the JSGlobalData to be provided
explicitly so we use a set function.

(JSC::Global::operator=):
(JSC::Global::clear):
(JSC::Global::isHashTableDeletedValue):
(JSC::Global::internalSet):

  • collector/handles/Handle.h: Added.

Root "Handle" type used for immutable handles and to provide the basic
APIs needed for pointer-like behaviour.

(JSC::HandleBase::operator!):
(JSC::HandleBase::operator UnspecifiedBoolType*):
(JSC::HandleBase::isEmpty):
(JSC::HandleBase::HandleBase):
(JSC::HandleBase::slot):
(JSC::HandleBase::invalidate):
(JSC::HandleBase::setSlot):
(JSC::HandleTypes::getFromSlot):
(JSC::HandleTypes::toJSValue):
(JSC::HandleTypes::validateUpcast):
(JSC::HandleConverter::operator->):
(JSC::HandleConverter::operator*):
(JSC::Handle::Handle):
(JSC::Handle::get):
(JSC::Handle::wrapSlot):
(JSC::operator==):
(JSC::operator!=):

  • collector/handles/HandleHeap.cpp: Added.

New heap for global handles.

(JSC::HandleHeap::HandleHeap):
(JSC::HandleHeap::grow):
(JSC::HandleHeap::markStrongHandles):
(JSC::HandleHeap::updateAfterMark):
(JSC::HandleHeap::clearWeakPointers):
(JSC::HandleHeap::writeBarrier):

  • collector/handles/HandleHeap.h: Added. (JSC::HandleHeap::heapFor): (JSC::HandleHeap::toHandle): (JSC::HandleHeap::toNode): (JSC::HandleHeap::allocate): (JSC::HandleHeap::deallocate): (JSC::HandleHeap::makeWeak):

Convert a hard handle into weak handle that does not
protect the object it points to.

(JSC::HandleHeap::makeSelfDestroying):

Converts a handle to a weak handle that will be returned
to the free list when the referenced object dies.

(JSC::HandleHeap::Node::Node):
(JSC::HandleHeap::Node::slot):
(JSC::HandleHeap::Node::handleHeap):
(JSC::HandleHeap::Node::setFinalizer):
(JSC::HandleHeap::Node::makeWeak):
(JSC::HandleHeap::Node::isWeak):
(JSC::HandleHeap::Node::makeSelfDestroying):
(JSC::HandleHeap::Node::isSelfDestroying):
(JSC::HandleHeap::Node::finalizer):
(JSC::HandleHeap::Node::setPrev):
(JSC::HandleHeap::Node::prev):
(JSC::HandleHeap::Node::setNext):
(JSC::HandleHeap::Node::next):

  • interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter):
  • interpreter/Interpreter.h:
  • interpreter/RegisterFile.cpp: (JSC::RegisterFile::globalObjectCollected):
  • interpreter/RegisterFile.h: (JSC::RegisterFile::RegisterFile):
  • runtime/GCHandle.cpp: Removed.
  • runtime/GCHandle.h: Removed.
  • runtime/Heap.cpp: (JSC::Heap::Heap): (JSC::Heap::destroy): (JSC::Heap::markRoots):
  • runtime/Heap.h: (JSC::Heap::allocateGlobalHandle): (JSC::Heap::reportExtraMemoryCost):
  • runtime/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData):
  • runtime/JSGlobalData.h: (JSC::JSGlobalData::allocateGlobalHandle):
  • runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::~JSGlobalObject):
  • runtime/JSPropertyNameIterator.cpp: (JSC::JSPropertyNameIterator::create): (JSC::JSPropertyNameIterator::~JSPropertyNameIterator):
  • runtime/JSPropertyNameIterator.h: (JSC::JSPropertyNameIterator::createStructure): (JSC::Structure::setEnumerationCache): (JSC::Structure::clearEnumerationCache):
  • runtime/Protect.h:
  • runtime/Structure.cpp: (JSC::Structure::~Structure):
  • runtime/Structure.h:
  • runtime/WeakGCPtr.h: (JSC::WeakGCPtrBase::get): (JSC::WeakGCPtrBase::clear): (JSC::WeakGCPtrBase::operator!): (JSC::WeakGCPtrBase::operator UnspecifiedBoolType*): (JSC::WeakGCPtrBase::~WeakGCPtrBase): (JSC::WeakGCPtrBase::WeakGCPtrBase): (JSC::WeakGCPtrBase::internalSet): (JSC::LazyWeakGCPtr::LazyWeakGCPtr): (JSC::LazyWeakGCPtr::set): (JSC::WeakGCPtr::WeakGCPtr): (JSC::WeakGCPtr::operator=):
  • runtime/WriteBarrier.h:
  • wtf/BlockStack.h: Added. (WTF::::BlockStack): (WTF::::~BlockStack): (WTF::::blocks): (WTF::::grow): (WTF::::shrink):
  • wtf/SentinelLinkedList.h: Added. (WTF::::SentinelLinkedList): (WTF::::begin): (WTF::::end): (WTF::::push): (WTF::::remove):
  • wtf/SinglyLinkedList.h: Added. (WTF::::SinglyLinkedList): (WTF::::isEmpty): (WTF::::push): (WTF::::pop):

2011-02-14 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough and Geoff Garen.

Refactor handles and weak pointers to become nicer and more automatic
https://bugs.webkit.org/show_bug.cgi?id=54415

Update to use new Global<> type

  • JSRun.cpp: (JSRun::JSRun): (JSRun::GlobalObject):
  • JSRun.h:
  • JSValueWrapper.cpp: (JSValueWrapper::JSValueWrapper):
  • JSValueWrapper.h:

2011-02-14 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough and Geoff Garen.

Refactor handles and weak pointers to become nicer and more automatic
https://bugs.webkit.org/show_bug.cgi?id=54415

Update WebCore to use the new Global<> type rather than ProtectedJSValue
and gc[Un]Protect. Also update to use new WeakGCPtr APIs, and remove now
unnecessary destructors.

  • ForwardingHeaders/collector/handles/Global.h: Added.
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.vcproj/copyForwardingHeaders.cmd:
  • bindings/js/JSCallbackData.h: (WebCore::JSCallbackData::JSCallbackData):
  • bindings/js/JSCustomVoidCallback.h:
  • bindings/js/JSDOMBinding.cpp: (WebCore::forgetDOMNode): (WebCore::cacheDOMNodeWrapper):
  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSDOMWindowShell.cpp: (WebCore::JSDOMWindowShell::setWindow):
  • bindings/js/JSDataGridDataSource.h:
  • bindings/js/JSEventListener.cpp: (WebCore::JSEventListener::JSEventListener):
  • bindings/js/JSEventListener.h: (WebCore::JSEventListener::setWrapper):
  • bindings/js/JSLazyEventListener.cpp: (WebCore::JSLazyEventListener::initializeJSFunction):
  • bindings/js/ScheduledAction.cpp: (WebCore::ScheduledAction::ScheduledAction): (WebCore::ScheduledAction::executeFunctionInContext):
  • bindings/js/ScheduledAction.h: (WebCore::ScheduledAction::ScheduledAction):
  • bindings/js/ScriptCachedFrameData.cpp: (WebCore::ScriptCachedFrameData::ScriptCachedFrameData): (WebCore::ScriptCachedFrameData::restore):
  • bindings/js/ScriptCachedFrameData.h:
  • bindings/js/ScriptCallStackFactory.cpp: (WebCore::createScriptArguments):
  • bindings/js/ScriptController.cpp: (WebCore::ScriptController::createWindowShell): (WebCore::ScriptController::evaluateInWorld): (WebCore::ScriptController::clearWindowShell): (WebCore::ScriptController::attachDebugger):
  • bindings/js/ScriptController.h:
  • bindings/js/ScriptFunctionCall.cpp: (WebCore::ScriptFunctionCall::call): (WebCore::ScriptCallback::call):
  • bindings/js/ScriptObject.cpp: (WebCore::ScriptObject::ScriptObject):
  • bindings/js/ScriptObject.h:
  • bindings/js/ScriptState.cpp: (WebCore::ScriptStateProtectedPtr::ScriptStateProtectedPtr): (WebCore::ScriptStateProtectedPtr::get):
  • bindings/js/ScriptState.h:
  • bindings/js/ScriptValue.cpp: (WebCore::ScriptValue::isFunction): (WebCore::ScriptValue::deserialize):
  • bindings/js/ScriptValue.h: (WebCore::ScriptValue::ScriptValue): (WebCore::ScriptValue::hasNoValue):
  • bindings/js/ScriptWrappable.h: (WebCore::ScriptWrappable::ScriptWrappable): (WebCore::ScriptWrappable::setWrapper):
  • bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): (WebCore::WorkerScriptController::~WorkerScriptController): (WebCore::WorkerScriptController::initScript): (WebCore::WorkerScriptController::evaluate):
  • bindings/js/WorkerScriptController.h: (WebCore::WorkerScriptController::workerContextWrapper):
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/NP_jsobject.cpp: (_NPN_InvokeDefault): (_NPN_Invoke): (_NPN_Evaluate): (_NPN_Construct):
  • bridge/jsc/BridgeJSC.cpp: (JSC::Bindings::Instance::Instance): (JSC::Bindings::Instance::~Instance): (JSC::Bindings::Instance::willDestroyRuntimeObject): (JSC::Bindings::Instance::willInvalidateRuntimeObject):
  • bridge/jsc/BridgeJSC.h:
  • bridge/runtime_object.cpp: (JSC::Bindings::RuntimeObject::invalidate):
  • bridge/runtime_root.cpp: (JSC::Bindings::RootObject::RootObject): (JSC::Bindings::RootObject::invalidate): (JSC::Bindings::RootObject::globalObject): (JSC::Bindings::RootObject::updateGlobalObject):
  • bridge/runtime_root.h:
  • dom/EventListener.h:
  • dom/EventTarget.h: (WebCore::EventTarget::markJSEventListeners):
  • xml/XMLHttpRequest.cpp:

Qt bindings courtesy of Csaba Osztrogonác

  • bridge/qt/qt_runtime.cpp: (JSC::Bindings::QtRuntimeConnectionMethod::call): (JSC::Bindings::QtConnectionObject::QtConnectionObject): (JSC::Bindings::QtConnectionObject::execute): (JSC::Bindings::QtConnectionObject::match):
  • bridge/qt/qt_runtime.h:

2011-02-14 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough and Geoff Garen.

Refactor handles and weak pointers to become nicer and more automatic
https://bugs.webkit.org/show_bug.cgi?id=54415

Update to use Global<> instead of ProtectedPtr, and refactored slightly
to get global data to places it's needed for when we're assigning to
Global<>s

  • ForwardingHeaders/collector/handles/Global.h: Added.
  • Plugins/Hosted/NetscapePluginInstanceProxy.h:
  • Plugins/Hosted/NetscapePluginInstanceProxy.mm: (WebKit::NetscapePluginInstanceProxy::LocalObjectMap::get): (WebKit::NetscapePluginInstanceProxy::LocalObjectMap::idForObject): (WebKit::NetscapePluginInstanceProxy::LocalObjectMap::forget): (WebKit::NetscapePluginInstanceProxy::getWindowNPObject): (WebKit::NetscapePluginInstanceProxy::getPluginElementNPObject): (WebKit::NetscapePluginInstanceProxy::evaluate): (WebKit::NetscapePluginInstanceProxy::invoke): (WebKit::NetscapePluginInstanceProxy::invokeDefault): (WebKit::NetscapePluginInstanceProxy::construct): (WebKit::NetscapePluginInstanceProxy::addValueToArray):
  • WebView/WebScriptDebugger.h:
  • WebView/WebScriptDebugger.mm: (WebScriptDebugger::WebScriptDebugger):

2011-02-14 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough and Geoff Garen.

Refactor handles and weak pointers to become nicer and more automatic
https://bugs.webkit.org/show_bug.cgi?id=54415

Update code to new Global<> API, and refactor to get global data to
necessary points.

  • WebProcess/Plugins/Netscape/NPJSObject.cpp: (WebKit::NPJSObject::create): (WebKit::NPJSObject::NPJSObject): (WebKit::NPJSObject::initialize): (WebKit::NPJSObject::invokeDefault): (WebKit::NPJSObject::construct): (WebKit::NPJSObject::invoke):
  • WebProcess/Plugins/Netscape/NPJSObject.h:
  • WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp: (WebKit::NPRuntimeObjectMap::getOrCreateNPObject): (WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant): (WebKit::NPRuntimeObjectMap::evaluate):
  • WebProcess/Plugins/Netscape/NPRuntimeObjectMap.h:
  • WebProcess/Plugins/PluginView.cpp: (WebKit::PluginView::windowScriptNPObject): (WebKit::PluginView::pluginElementNPObject):
Location:
trunk/Source/JavaScriptCore/interpreter
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r77165 r78634  
    420420}
    421421
    422 Interpreter::Interpreter()
     422Interpreter::Interpreter(JSGlobalData& globalData)
    423423    : m_sampleEntryDepth(0)
    424424    , m_reentryDepth(0)
     425    , m_registerFile(globalData)
    425426{
    426427#if ENABLE(COMPUTED_GOTO_INTERPRETER)
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.h

    r76248 r78634  
    7070        friend class CachedCall;
    7171    public:
    72         Interpreter();
     72        Interpreter(JSGlobalData&);
    7373
    7474        RegisterFile& registerFile() { return m_registerFile; }
  • trunk/Source/JavaScriptCore/interpreter/RegisterFile.cpp

    r67130 r78634  
    3030#include "RegisterFile.h"
    3131
     32#include "Interpreter.h"
     33#include "JSGlobalData.h"
    3234#include "JSGlobalObject.h"
    3335
     
    6062void RegisterFile::setGlobalObject(JSGlobalObject* globalObject)
    6163{
    62     m_globalObject = globalObject;
     64    m_globalObject.set(globalObject->globalData(), globalObject, globalObjectCollected);
    6365}
    6466
    65 bool RegisterFile::clearGlobalObject(JSGlobalObject* globalObject)
     67void RegisterFile::globalObjectCollected(JSGlobalData&, Handle<Unknown> value)
    6668{
    67     return m_globalObject.clear(globalObject);
     69    JSGlobalObject* globalObject = asGlobalObject(value.get());
     70    globalObject->globalData().interpreter->registerFile().setNumGlobals(0);
    6871}
    6972
  • trunk/Source/JavaScriptCore/interpreter/RegisterFile.h

    r76425 r78634  
    113113        static const ptrdiff_t maxExcessCapacity = 8 * 1024;
    114114
    115         RegisterFile(size_t capacity = defaultCapacity, size_t maxGlobals = defaultMaxGlobals);
     115        RegisterFile(JSGlobalData&, size_t capacity = defaultCapacity, size_t maxGlobals = defaultMaxGlobals);
    116116        ~RegisterFile();
    117117
     
    121121
    122122        void setGlobalObject(JSGlobalObject*);
    123         bool clearGlobalObject(JSGlobalObject*);
     123        static void globalObjectCollected(JSGlobalData&, Handle<Unknown>);
    124124        JSGlobalObject* globalObject();
    125125
     
    151151    };
    152152
    153     inline RegisterFile::RegisterFile(size_t capacity, size_t maxGlobals)
     153    inline RegisterFile::RegisterFile(JSGlobalData& globalData, size_t capacity, size_t maxGlobals)
    154154        : m_numGlobals(0)
    155155        , m_maxGlobals(maxGlobals)
     
    157157        , m_end(0)
    158158        , m_max(0)
     159        , m_globalObject(globalData, globalObjectCollected)
    159160    {
    160161        ASSERT(maxGlobals && isPageAligned(maxGlobals));
    161162        ASSERT(capacity && isPageAligned(capacity));
    162 
    163163        size_t bufferLength = (capacity + maxGlobals) * sizeof(Register);
    164164        m_reservation = PageReservation::reserve(roundUpAllocationSize(bufferLength, commitSize), OSAllocator::JSVMStackPages);
Note: See TracChangeset for help on using the changeset viewer.