• mhahnenberg@apple.com's avatar
    Delayed structure sweep can leak structures without bound · 30738a77
    mhahnenberg@apple.com authored
    Reviewed by Geoffrey Garen.
    This patch gets rid of the separate Structure allocator in the MarkedSpace and adds two new destructor-only
    allocators. We now have separate allocators for our three types of objects: those objects with no destructors,
    those objects with destructors and with immortal structures, and those objects with destructors that don't have 
    immortal structures. All of the objects of the third type (destructors without immortal structures) now 
    inherit from a new class named JSDestructibleObject (which in turn is a subclass of JSNonFinalObject), which stores 
    the ClassInfo for these classes at a fixed offset for safe retrieval during sweeping/destruction.
    * API/JSCallbackConstructor.cpp: Use JSDestructibleObject for JSCallbackConstructor.
    * API/JSCallbackConstructor.h:
    * API/JSCallbackObject.cpp: Inherit from JSDestructibleObject for normal JSCallbackObjects and use a finalizer for 
    JSCallbackObject<JSGlobalObject>, since JSGlobalObject also uses a finalizer.
    (JSC::::create): We need to move the create function for JSCallbackObject<JSGlobalObject> out of line so we can add 
    the finalizer for it. We don't want to add the finalizer is something like finishCreation in case somebody decides 
    to subclass this. We use this same technique for many other subclasses of JSGlobalObject.
    * API/JSCallbackObject.h:
    * API/JSClassRef.cpp: Change all the JSCallbackObject<JSNonFinalObject> to use JSDestructibleObject instead.
    * API/JSObjectRef.cpp: Ditto.
    * API/JSValueRef.cpp: Ditto.
    * API/JSWeakObjectMapRefPrivate.cpp: Ditto.
    * JSCTypedArrayStubs.h:
    * JavaScriptCore.xcodeproj/project.pbxproj:
    * dfg/DFGSpeculativeJIT.h: Use the proper allocator type when doing inline allocation in the DFG.
    * heap/Heap.cpp:
    * heap/Heap.h: Add accessors for the various types of allocators now. Also remove the isSafeToSweepStructures function 
    since it's always safe to sweep Structures now.
    * heap/IncrementalSweeper.cpp: Remove all the logic to detect when it's safe to sweep Structures from the 
    IncrementalSweeper since it's always safe to sweep Structures now.
    * heap/IncrementalSweeper.h:
    * heap/MarkedAllocator.cpp: Remove the logic that was preventing us from sweeping Structures if it wasn't safe. Add 
    tracking of the specific destructor type of allocator. 
    * heap/MarkedAllocator.h:
    * heap/MarkedBlock.cpp: Add all the destructor type stuff to MarkedBlocks so that we do the right thing when sweeping. 
    We also use the stored destructor type to determine the right thing to do in all JSCell::classInfo() calls.
    * heap/MarkedBlock.h:
    * heap/MarkedSpace.cpp: Add the new destructor allocators to MarkedSpace.
    * heap/MarkedSpace.h:
    * heap/SlotVisitor.cpp: Add include because the symbol was needed in an inlined function.
    * jit/JIT.h: Make sure we use the correct allocator when doing inline allocations in the baseline JIT.
    * jit/JITInlineMethods.h:
    * jsc.cpp: 
    (GlobalObject::create): Add finalizer here since JSGlobalObject needs to use a finalizer instead of inheriting from 
    * runtime/Arguments.cpp: Inherit from JSDestructibleObject.
    * runtime/Arguments.h:
    * runtime/ErrorPrototype.cpp: Added an assert to make sure we have a trivial destructor.
    * runtime/Executable.h: Indicate that all of the Executable* classes have immortal Structures.
    * runtime/InternalFunction.cpp: Inherit from JSDestructibleObject.
    * runtime/InternalFunction.h:
    * runtime/JSCell.h: Added two static bools, needsDestruction and hasImmortalStructure, that classes can override 
    to indicate at compile time which part of the heap they should be allocated in.
    (JSC::allocateCell): Use the appropriate allocator depending on the destructor type.
    * runtime/JSDestructibleObject.h: Added. New class that stores the ClassInfo of any subclass so that it can be 
    accessed safely when the object is being destroyed.
    (JSC::JSCell::classInfo): Checks the current MarkedBlock to see where it should get the ClassInfo from so that it's always safe.
    * runtime/JSGlobalObject.cpp: JSGlobalObject now uses a finalizer instead of a destructor so that it can avoid forcing all 
    of its relatives in the inheritance hierarchy (e.g. JSScope) to use destructors as well.
    * runtime/JSGlobalObject.h:
    (JSC::JSGlobalObject::createRareDataIfNeeded): Since we always create a finalizer now, we don't have to worry about adding one 
    for the m_rareData field when it's created.
    * runtime/JSGlobalThis.h: Inherit from JSDestructibleObject.
    * runtime/JSPropertyNameIterator.h: Has an immortal Structure.
    * runtime/JSScope.cpp:
    * runtime/JSString.h: Has an immortal Structure.
    * runtime/JSWrapperObject.h: Inherit from JSDestructibleObject.
    * runtime/MathObject.cpp: Cleaning up some of the inheritance stuff.
    * runtime/NameInstance.h: Inherit from JSDestructibleObject.
    * runtime/RegExp.h: Has immortal Structure.
    * runtime/RegExpObject.cpp: Inheritance cleanup.
    * runtime/SparseArrayValueMap.h: Has immortal Structure.
    * runtime/Structure.h: Has immortal Structure.
    * runtime/StructureChain.h: Ditto.
    * runtime/SymbolTable.h: Ditto.
    No new tests.
    * ForwardingHeaders/runtime/JSDestructableObject.h: Added.
    * bindings/js/JSDOMWrapper.h: Inherits from JSDestructibleObject.
    * bindings/scripts/CodeGeneratorJS.pm: Add finalizers to anything that inherits from JSGlobalObject,
    e.g. JSDOMWindow and JSWorkerContexts. For those classes we also need to define needsDestruction as true.
    * bridge/objc/objc_runtime.h: Inherit from JSDestructibleObject.
    * bridge/objc/objc_runtime.mm:
    * bridge/runtime_array.cpp: Use a finalizer so that JSArray isn't forced to inherit from JSDestructibleObject.
    * bridge/runtime_array.h:
    * bridge/runtime_object.cpp: Inherit from JSDestructibleObject.
    * bridge/runtime_object.h:
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@130303 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JSGlobalObject.h 22.3 KB