Changeset 253423 in webkit for trunk/Source/JavaScriptCore/heap


Ignore:
Timestamp:
Dec 12, 2019, 1:36:13 AM (5 years ago)
Author:
[email protected]
Message:

[JSC] IsoHeapCellType should have destroy function member instead of specializing template function
https://bugs.webkit.org/show_bug.cgi?id=205152

Reviewed by Saam Barati.

We were specializing MarkedBlock::Handle::specializedSweep in 5 different ways for each IsoSubspace-ed cell.
This bloats binary. Instead of specializing it with CellType, we specialize it with one functor, which invokes
function pointer held by IsoHeapCellType. This requires one indirect function call per cell. But this is OK since,

  1. We were using JSDestructibleObject's cell->classInfo->methodTable.destroy function call to dispatch destruction, before IsoSubspace replaces them with IsoHeapCellType-based destruction. Compared to that, the new one is still saving one pointer chasing basically (classInfo dereference, we assume cell deference is no cost since it will be done anyway).
  2. We still keep JSString's destroy function inlining by using IsoInlinedHeapCellType. This is important since it is critical to performance and we had JSStringHeapCellType before we replaced it with IsoHeapCellType. But IsoInlinedHeapCellType specialization is for only one class so generated binary size is the same to the old code using JSStringHeapCellType.

This saves 480KB binary-size in JavaScriptCore. And more importantly, after this patch, adding IsoSubspace
will not bloat code, so we can simply put things into IsoSubspace.

This patch also removes using namespace JSC; in global code in JavaScriptCore except for API codes, since
it starts causing build failure due to unified builds: API defines JSType enum in a global scope, which is
different from our JSC::JSType. If we do using namespace JSC; in a global scope, it can lead to ambiguity of
looking up.

  • API/JSHeapFinalizerPrivate.cpp:

(JSContextGroupAddHeapFinalizer):
(JSContextGroupRemoveHeapFinalizer):

  • API/JSHeapFinalizerPrivate.h:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • assembler/AbstractMacroAssembler.cpp:
  • bindings/ScriptFunctionCall.cpp:
  • bindings/ScriptObject.cpp:
  • bindings/ScriptValue.cpp:
  • heap/IsoHeapCellType.cpp: Copied from Source/JavaScriptCore/assembler/AbstractMacroAssembler.cpp.

(JSC::IsoHeapCellType::finishSweep):
(JSC::IsoHeapCellType::destroy):

  • heap/IsoHeapCellType.h:
  • heap/IsoInlinedHeapCellType.h: Copied from Source/JavaScriptCore/heap/IsoHeapCellType.h.
  • heap/MutatorState.cpp:
  • heap/Synchronousness.cpp:
  • inspector/InjectedScriptHost.cpp:
  • inspector/InjectedScriptManager.cpp:
  • inspector/JSGlobalObjectConsoleClient.cpp:
  • inspector/JSGlobalObjectInspectorController.cpp:
  • inspector/JSGlobalObjectScriptDebugServer.cpp:
  • inspector/JSInjectedScriptHost.cpp:
  • inspector/JSInjectedScriptHostPrototype.cpp:
  • inspector/JSJavaScriptCallFrame.cpp:
  • inspector/JSJavaScriptCallFramePrototype.cpp:
  • inspector/JavaScriptCallFrame.cpp:
  • inspector/PerGlobalObjectWrapperWorld.cpp:
  • inspector/ScriptCallStackFactory.cpp:
  • inspector/ScriptDebugServer.cpp:
  • inspector/agents/InspectorHeapAgent.cpp:
  • inspector/agents/InspectorScriptProfilerAgent.cpp:
  • inspector/agents/JSGlobalObjectAuditAgent.cpp:
  • inspector/agents/JSGlobalObjectDebuggerAgent.cpp:
  • inspector/agents/JSGlobalObjectRuntimeAgent.cpp:
  • runtime/VM.cpp:

(JSC::VM::VM):

  • runtime/VM.h:
Location:
trunk/Source/JavaScriptCore/heap
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/heap/IsoHeapCellType.cpp

    r253422 r253423  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #ifndef JSHeapFinalizerPrivate_h
    27 #define JSHeapFinalizerPrivate_h
     26#include "config.h"
     27#include "IsoHeapCellType.h"
    2828
    29 #include <JavaScriptCore/JSContextRef.h>
    30 #include <stdbool.h>
     29#include "JSCInlines.h"
     30#include "MarkedBlockInlines.h"
    3131
    32 #ifdef __cplusplus
    33 extern "C" {
    34 #endif
     32namespace JSC {
    3533
    36 typedef void (*JSHeapFinalizer)(JSContextGroupRef, void *userData);
     34void IsoHeapCellType::finishSweep(MarkedBlock::Handle& handle, FreeList* freeList)
     35{
     36    handle.finishSweepKnowingHeapCellType(freeList, *this);
     37}
    3738
    38 JS_EXPORT void JSContextGroupAddHeapFinalizer(JSContextGroupRef, JSHeapFinalizer, void *userData);
    39 JS_EXPORT void JSContextGroupRemoveHeapFinalizer(JSContextGroupRef, JSHeapFinalizer, void *userData);
     39void IsoHeapCellType::destroy(VM&, JSCell* cell)
     40{
     41    m_destroy(cell);
     42}
    4043
    41 #ifdef __cplusplus
    42 }
    43 #endif
     44} // namespace JSC
    4445
    45 #endif // JSHeapFinalizerPrivate_h
    46 
  • trunk/Source/JavaScriptCore/heap/IsoHeapCellType.h

    r252843 r253423  
    2929namespace JSC {
    3030
    31 template<typename CellType>
    3231class IsoHeapCellType final : public HeapCellType {
    3332public:
    34     IsoHeapCellType()
    35         : HeapCellType(CellAttributes(CellType::needsDestruction ? NeedsDestruction : DoesNotNeedDestruction, HeapCell::JSCell))
     33    using DestroyFunctionPtr = void (*)(JSCell*);
     34
     35    IsoHeapCellType(DestructionMode destructionMode, DestroyFunctionPtr destroyFunction)
     36        : HeapCellType(CellAttributes(destructionMode, HeapCell::JSCell))
     37        , m_destroy(destroyFunction)
    3638    {
    3739    }
    3840
    39     struct DestroyFunc {
    40         ALWAYS_INLINE void operator()(VM&, JSCell* cell) const
    41         {
    42             CellType::destroy(cell);
    43         }
    44     };
    45 
    46     void finishSweep(MarkedBlock::Handle& handle, FreeList* freeList) override
     41    template<typename CellType>
     42    static std::unique_ptr<IsoHeapCellType> create()
    4743    {
    48         handle.finishSweepKnowingHeapCellType(freeList, DestroyFunc());
     44        return makeUnique<IsoHeapCellType>(CellType::needsDestruction ? NeedsDestruction : DoesNotNeedDestruction, &CellType::destroy);
    4945    }
    5046
    51     void destroy(VM&, JSCell* cell) override
     47    void finishSweep(MarkedBlock::Handle&, FreeList*) override;
     48    void destroy(VM&, JSCell*) override;
     49
     50    ALWAYS_INLINE void operator()(VM&, JSCell* cell) const
    5251    {
    53         CellType::destroy(cell);
     52        m_destroy(cell);
    5453    }
     54
     55private:
     56    DestroyFunctionPtr WTF_VTBL_FUNCPTR_PTRAUTH_STR("IsoHeapCellType.destroy") m_destroy;
    5557};
    5658
    5759} // namespace JSC
    58 
  • trunk/Source/JavaScriptCore/heap/IsoInlinedHeapCellType.h

    r253422 r253423  
    3030
    3131template<typename CellType>
    32 class IsoHeapCellType final : public HeapCellType {
     32class IsoInlinedHeapCellType final : public HeapCellType {
    3333public:
    34     IsoHeapCellType()
     34    IsoInlinedHeapCellType()
    3535        : HeapCellType(CellAttributes(CellType::needsDestruction ? NeedsDestruction : DoesNotNeedDestruction, HeapCell::JSCell))
    3636    {
  • trunk/Source/JavaScriptCore/heap/MutatorState.cpp

    r212778 r253423  
    2929#include <wtf/PrintStream.h>
    3030
     31namespace WTF {
     32
    3133using namespace JSC;
    32 
    33 namespace WTF {
    3434
    3535void printInternal(PrintStream& out, MutatorState state)
  • trunk/Source/JavaScriptCore/heap/Synchronousness.cpp

    r216218 r253423  
    2929#include <wtf/PrintStream.h>
    3030
     31namespace WTF {
     32
    3133using namespace JSC;
    32 
    33 namespace WTF {
    3434
    3535void printInternal(PrintStream& out, Synchronousness synchronousness)
Note: See TracChangeset for help on using the changeset viewer.