Ignore:
Timestamp:
May 16, 2018, 10:21:41 PM (7 years ago)
Author:
[email protected]
Message:

UnlinkedFunctionExecutable doesn't need a parent source override field since it's only used for default class constructors
https://bugs.webkit.org/show_bug.cgi?id=185637

Reviewed by Keith Miller.

We had this general mechanism for overriding an UnlinkedFunctionExecutable's parent
source code. However, we were only using this for default class constructors. There
are only two types of default class constructors. This patch makes it so that
we just store this information inside of a single bit, and ask for the source
code as needed instead of holding it in a nullable field that is 24 bytes in size.

This brings UnlinkedFunctionExecutable's size down from 184 bytes to 160 bytes.
This has the consequence of making it allocated out of a 160 byte size class
instead of a 224 byte size class. This should bring down its memory footprint
by ~40%.

  • builtins/BuiltinExecutables.cpp:

(JSC::BuiltinExecutables::defaultConstructorSourceCode):
(JSC::BuiltinExecutables::createDefaultConstructor):
(JSC::BuiltinExecutables::createExecutable):

  • builtins/BuiltinExecutables.h:
  • bytecode/UnlinkedFunctionExecutable.cpp:

(JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
(JSC::UnlinkedFunctionExecutable::link):

  • bytecode/UnlinkedFunctionExecutable.h:
  • runtime/CodeCache.cpp:

(JSC::CodeCache::getUnlinkedGlobalFunctionExecutable):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.cpp

    r231477 r231889  
    11/*
    2  * Copyright (C) 2012-2013, 2015-2016 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2012-2018 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#include "UnlinkedFunctionExecutable.h"
    2828
     29#include "BuiltinExecutables.h"
    2930#include "BytecodeGenerator.h"
    3031#include "ClassInfo.h"
     
    4142namespace JSC {
    4243
    43 static_assert(sizeof(UnlinkedFunctionExecutable) <= 256, "UnlinkedFunctionExecutable should fit in a 256-byte cell.");
     44static_assert(sizeof(UnlinkedFunctionExecutable) <= 160, "UnlinkedFunctionExecutable should fit in a 160-byte cell. If you increase the size of this class, consider making a size class that perfectly fits it.");
    4445
    4546const ClassInfo UnlinkedFunctionExecutable::s_info = { "UnlinkedFunctionExecutable", nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(UnlinkedFunctionExecutable) };
     
    7778}
    7879
    79 UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM* vm, Structure* structure, const SourceCode& parentSource, SourceCode&& parentSourceOverride, FunctionMetadataNode* node, UnlinkedFunctionKind kind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, VariableEnvironment& parentScopeTDZVariables, DerivedContextType derivedContextType)
     80UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM* vm, Structure* structure, const SourceCode& parentSource, FunctionMetadataNode* node, UnlinkedFunctionKind kind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, VariableEnvironment& parentScopeTDZVariables, DerivedContextType derivedContextType, bool isBuiltinDefaultClassConstructor)
    8081    : Base(*vm, structure)
    8182    , m_firstLineOffset(node->firstLine() - parentSource.firstLine().oneBasedInt())
     
    9596    , m_hasCapturedVariables(false)
    9697    , m_isBuiltinFunction(kind == UnlinkedBuiltinFunction)
     98    , m_isBuiltinDefaultClassConstructor(isBuiltinDefaultClassConstructor)
    9799    , m_constructAbility(static_cast<unsigned>(constructAbility))
    98100    , m_constructorKind(static_cast<unsigned>(node->constructorKind()))
     
    104106    , m_ecmaName(node->ecmaName())
    105107    , m_inferredName(node->inferredName())
    106     , m_parentSourceOverride(WTFMove(parentSourceOverride))
    107108    , m_classSource(node->classSource())
    108109    , m_parentScopeTDZVariables(vm->m_compactVariableMap->get(parentScopeTDZVariables))
     
    115116    ASSERT(m_superBinding == static_cast<unsigned>(node->superBinding()));
    116117    ASSERT(m_derivedContextType == static_cast<unsigned>(derivedContextType));
     118    ASSERT(!(m_isBuiltinDefaultClassConstructor && constructorKind() == ConstructorKind::None));
    117119}
    118120
     
    133135FunctionExecutable* UnlinkedFunctionExecutable::link(VM& vm, const SourceCode& passedParentSource, std::optional<int> overrideLineNumber, Intrinsic intrinsic)
    134136{
    135     const SourceCode& parentSource = m_parentSourceOverride.isNull() ? passedParentSource : m_parentSourceOverride;
     137    const SourceCode& parentSource = !m_isBuiltinDefaultClassConstructor ? passedParentSource : BuiltinExecutables::defaultConstructorSourceCode(constructorKind());
    136138    unsigned firstLine = parentSource.firstLine().oneBasedInt() + m_firstLineOffset;
    137139    unsigned startOffset = parentSource.startOffset() + m_startOffset;
Note: See TracChangeset for help on using the changeset viewer.