Changeset 245213 in webkit


Ignore:
Timestamp:
May 12, 2019 12:43:16 PM (5 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Compact generator code's bytecode size
https://bugs.webkit.org/show_bug.cgi?id=197822

Reviewed by Michael Saboff.

op_put_to_scope's symbolTableOrScopeDepth is represented as int. This was OK for the old bytecode format since
VirtualRegister / scope depth can be represented by int anyway. But it is problematic now since only int8_t range
will be represented in narrow bytecode. When this field is used for symbol table constant index, it is always
larger than FirstConstantRegisterIndex. So it always exceeds the range of int8_t, and results in wide bytecode.
It makes all generator's op_put_to_scope wide bytecode.

In this patch, we introduce a new (logically) union type SymbolTableOrScopeDepth. It holds unsigned value, and we store the
SymbolTableConstantIndex - FirstConstantRegisterIndex in this unsigned value to make op_put_to_scope narrow bytecode.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bytecode/BytecodeGeneratorification.cpp:

(JSC::BytecodeGeneratorification::run):

  • bytecode/BytecodeList.rb:
  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::finishCreation):

  • bytecode/Fits.h:
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitProfileType):
(JSC::BytecodeGenerator::emitPutToScope):
(JSC::BytecodeGenerator::localScopeDepth const):

  • bytecompiler/BytecodeGenerator.h:
  • runtime/SymbolTableOrScopeDepth.h: Added.

(JSC::SymbolTableOrScopeDepth::symbolTable):
(JSC::SymbolTableOrScopeDepth::scopeDepth):
(JSC::SymbolTableOrScopeDepth::raw):
(JSC::SymbolTableOrScopeDepth::symbolTable const):
(JSC::SymbolTableOrScopeDepth::scopeDepth const):
(JSC::SymbolTableOrScopeDepth::raw const):
(JSC::SymbolTableOrScopeDepth::dump const):
(JSC::SymbolTableOrScopeDepth::SymbolTableOrScopeDepth):

Location:
trunk/Source/JavaScriptCore
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r244950 r245213  
    964964    runtime/SymbolPrototype.h
    965965    runtime/SymbolTable.h
     966    runtime/SymbolTableOrScopeDepth.h
    966967    runtime/TemplateObjectDescriptor.h
    967968    runtime/TestRunnerUtils.h
  • trunk/Source/JavaScriptCore/ChangeLog

    r245203 r245213  
     12019-05-12  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Compact generator code's bytecode size
     4        https://bugs.webkit.org/show_bug.cgi?id=197822
     5
     6        Reviewed by Michael Saboff.
     7
     8        op_put_to_scope's symbolTableOrScopeDepth is represented as int. This was OK for the old bytecode format since
     9        VirtualRegister / scope depth can be represented by int anyway. But it is problematic now since only int8_t range
     10        will be represented in narrow bytecode. When this field is used for symbol table constant index, it is always
     11        larger than FirstConstantRegisterIndex. So it always exceeds the range of int8_t, and results in wide bytecode.
     12        It makes all generator's op_put_to_scope wide bytecode.
     13
     14        In this patch, we introduce a new (logically) union type SymbolTableOrScopeDepth. It holds unsigned value, and we store the
     15        SymbolTableConstantIndex - FirstConstantRegisterIndex in this unsigned value to make op_put_to_scope narrow bytecode.
     16
     17        * CMakeLists.txt:
     18        * JavaScriptCore.xcodeproj/project.pbxproj:
     19        * bytecode/BytecodeGeneratorification.cpp:
     20        (JSC::BytecodeGeneratorification::run):
     21        * bytecode/BytecodeList.rb:
     22        * bytecode/CodeBlock.cpp:
     23        (JSC::CodeBlock::finishCreation):
     24        * bytecode/Fits.h:
     25        * bytecompiler/BytecodeGenerator.cpp:
     26        (JSC::BytecodeGenerator::BytecodeGenerator):
     27        (JSC::BytecodeGenerator::emitProfileType):
     28        (JSC::BytecodeGenerator::emitPutToScope):
     29        (JSC::BytecodeGenerator::localScopeDepth const):
     30        * bytecompiler/BytecodeGenerator.h:
     31        * runtime/SymbolTableOrScopeDepth.h: Added.
     32        (JSC::SymbolTableOrScopeDepth::symbolTable):
     33        (JSC::SymbolTableOrScopeDepth::scopeDepth):
     34        (JSC::SymbolTableOrScopeDepth::raw):
     35        (JSC::SymbolTableOrScopeDepth::symbolTable const):
     36        (JSC::SymbolTableOrScopeDepth::scopeDepth const):
     37        (JSC::SymbolTableOrScopeDepth::raw const):
     38        (JSC::SymbolTableOrScopeDepth::dump const):
     39        (JSC::SymbolTableOrScopeDepth::SymbolTableOrScopeDepth):
     40
    1412019-05-10  Saam barati  <sbarati@apple.com>
    242
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r244950 r245213  
    17431743                DEA7E2451BBC677F00D78440 /* JSTypedArrayViewPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = 53917E7C1B791106000EBD33 /* JSTypedArrayViewPrototype.h */; settings = {ATTRIBUTES = (Private, ); }; };
    17441744                E124A8F70E555775003091F1 /* OpaqueJSString.h in Headers */ = {isa = PBXBuildFile; fileRef = E124A8F50E555775003091F1 /* OpaqueJSString.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1745                E31179AA2288386100514B2C /* SymbolTableOrScopeDepth.h in Headers */ = {isa = PBXBuildFile; fileRef = E31179A92288385D00514B2C /* SymbolTableOrScopeDepth.h */; settings = {ATTRIBUTES = (Private, ); }; };
    17451746                E31618131EC5FE170006A218 /* DOMAnnotation.h in Headers */ = {isa = PBXBuildFile; fileRef = E31618101EC5FE080006A218 /* DOMAnnotation.h */; settings = {ATTRIBUTES = (Private, ); }; };
    17461747                E31618151EC5FE270006A218 /* DOMAttributeGetterSetter.h in Headers */ = {isa = PBXBuildFile; fileRef = E31618121EC5FE080006A218 /* DOMAttributeGetterSetter.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    47224723                E18E3A570DF9278C00D90B34 /* VM.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = VM.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
    47234724                E30677971B8BC6F5003F87F0 /* ModuleLoader.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ModuleLoader.js; sourceTree = "<group>"; };
     4725                E31179A92288385D00514B2C /* SymbolTableOrScopeDepth.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SymbolTableOrScopeDepth.h; sourceTree = "<group>"; };
    47244726                E31618101EC5FE080006A218 /* DOMAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMAnnotation.h; sourceTree = "<group>"; };
    47254727                E31618111EC5FE080006A218 /* DOMAttributeGetterSetter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMAttributeGetterSetter.cpp; sourceTree = "<group>"; };
     
    73007302                                0F919D2715856770004A4E7D /* SymbolTable.cpp */,
    73017303                                14A396A60CD2933100B5B4FF /* SymbolTable.h */,
     7304                                E31179A92288385D00514B2C /* SymbolTableOrScopeDepth.h */,
    73027305                                BDB4B5E099CD4C1BB3C1CF05 /* TemplateObjectDescriptor.cpp */,
    73037306                                70ECA6041AFDBEA200449739 /* TemplateObjectDescriptor.h */,
     
    98589861                                996B73281BDA08EF00331B84 /* SymbolPrototype.lut.h in Headers */,
    98599862                                BC18C46B0E16F5CD00B34460 /* SymbolTable.h in Headers */,
     9863                                E31179AA2288386100514B2C /* SymbolTableOrScopeDepth.h in Headers */,
    98609864                                0FD79A2D1EBBBDBB00DA88D3 /* Synchronousness.h in Headers */,
    98619865                                0F1FB38F1E173A6700A9BE50 /* SynchronousStopTheWorldMutatorScheduler.h in Headers */,
  • trunk/Source/JavaScriptCore/bytecode/BytecodeGeneratorification.cpp

    r244915 r245213  
    253253                    operand, // value
    254254                    GetPutInfo(DoNotThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization), // info
    255                     m_generatorFrameSymbolTableIndex, // symbol table constant index
     255                    SymbolTableOrScopeDepth::symbolTable(VirtualRegister { m_generatorFrameSymbolTableIndex }), // symbol table constant index
    256256                    storage.scopeOffset.offset() // scope offset
    257257                );
  • trunk/Source/JavaScriptCore/bytecode/BytecodeList.rb

    r243127 r245213  
    5151    :StructureChain,
    5252    :SymbolTable,
     53    :SymbolTableOrScopeDepth,
    5354    :ToThisStatus,
    5455    :TypeLocation,
     
    882883        # $begin: :private,
    883884        getPutInfo: GetPutInfo,
    884         symbolTableOrScopeDepth: int,
     885        symbolTableOrScopeDepth: SymbolTableOrScopeDepth,
    885886        offset: unsigned,
    886887    },
     
    978979    args: {
    979980        targetVirtualRegister: VirtualRegister,
    980         symbolTableOrScopeDepth: int,
     981        symbolTableOrScopeDepth: SymbolTableOrScopeDepth,
    981982        flag: ProfileTypeBytecodeFlag,
    982983        identifier?: unsigned,
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r245050 r245213  
    644644                // Only do watching if the property we're putting to is not anonymous.
    645645                if (bytecode.m_var != UINT_MAX) {
    646                     SymbolTable* symbolTable = jsCast<SymbolTable*>(getConstant(bytecode.m_symbolTableOrScopeDepth));
     646                    SymbolTable* symbolTable = jsCast<SymbolTable*>(getConstant(bytecode.m_symbolTableOrScopeDepth.symbolTable().offset()));
    647647                    const Identifier& ident = identifier(bytecode.m_var);
    648648                    ConcurrentJSLocker locker(symbolTable->m_lock);
     
    658658            const Identifier& ident = identifier(bytecode.m_var);
    659659            metadata.m_watchpointSet = nullptr;
    660             ResolveOp op = JSScope::abstractResolve(m_globalObject->globalExec(), bytecode.m_symbolTableOrScopeDepth, scope, ident, Put, bytecode.m_getPutInfo.resolveType(), bytecode.m_getPutInfo.initializationMode());
     660            ResolveOp op = JSScope::abstractResolve(m_globalObject->globalExec(), bytecode.m_symbolTableOrScopeDepth.scopeDepth(), scope, ident, Put, bytecode.m_getPutInfo.resolveType(), bytecode.m_getPutInfo.initializationMode());
    661661            RETURN_IF_EXCEPTION(throwScope, false);
    662662
     
    688688            case ProfileTypeBytecodeClosureVar: {
    689689                const Identifier& ident = identifier(bytecode.m_identifier);
    690                 unsigned localScopeDepth = bytecode.m_symbolTableOrScopeDepth;
     690                unsigned localScopeDepth = bytecode.m_symbolTableOrScopeDepth.scopeDepth();
    691691                // Even though type profiling may be profiling either a Get or a Put, we can always claim a Get because
    692692                // we're abstractly "read"ing from a JSScope.
     
    712712            }
    713713            case ProfileTypeBytecodeLocallyResolved: {
    714                 int symbolTableIndex = bytecode.m_symbolTableOrScopeDepth;
     714                int symbolTableIndex = bytecode.m_symbolTableOrScopeDepth.symbolTable().offset();
    715715                SymbolTable* symbolTable = jsCast<SymbolTable*>(getConstant(symbolTableIndex));
    716716                const Identifier& ident = identifier(bytecode.m_identifier);
  • trunk/Source/JavaScriptCore/bytecode/Fits.h

    r240138 r245213  
    3434#include "ResultType.h"
    3535#include "SpecialPointer.h"
     36#include "SymbolTableOrScopeDepth.h"
    3637#include "VirtualRegister.h"
    3738#include <type_traits>
     
    130131            return VirtualRegister { (i - s_firstConstantIndex) + FirstConstantRegisterIndex };
    131132        return VirtualRegister { i };
     133    }
     134};
     135
     136template<>
     137struct Fits<SymbolTableOrScopeDepth, OpcodeSize::Narrow> {
     138    static bool check(SymbolTableOrScopeDepth u)
     139    {
     140        return u.raw() <= UINT8_MAX;
     141    }
     142
     143    static uint8_t convert(SymbolTableOrScopeDepth u)
     144    {
     145        ASSERT(check(u));
     146        return static_cast<uint8_t>(u.raw());
     147    }
     148
     149    static SymbolTableOrScopeDepth convert(uint8_t u)
     150    {
     151        return SymbolTableOrScopeDepth::raw(u);
    132152    }
    133153};
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r245047 r245213  
    552552                    functionSymbolTable->set(NoLockingNecessary, name, entry);
    553553                }
    554                 OpPutToScope::emit(this, m_lexicalEnvironmentRegister, UINT_MAX, virtualRegisterForArgument(1 + i), GetPutInfo(ThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization), symbolTableConstantIndex, offset.offset());
     554                OpPutToScope::emit(this, m_lexicalEnvironmentRegister, UINT_MAX, virtualRegisterForArgument(1 + i), GetPutInfo(ThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization), SymbolTableOrScopeDepth::symbolTable(VirtualRegister { symbolTableConstantIndex }), offset.offset());
    555555            }
    556556           
     
    590590            functionSymbolTable->set(NoLockingNecessary, name, SymbolTableEntry(VarOffset(offset)));
    591591           
    592             OpPutToScope::emit(this, m_lexicalEnvironmentRegister, addConstant(ident), virtualRegisterForArgument(1 + i), GetPutInfo(ThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization), symbolTableConstantIndex, offset.offset());
     592            OpPutToScope::emit(this, m_lexicalEnvironmentRegister, addConstant(ident), virtualRegisterForArgument(1 + i), GetPutInfo(ThrowIfNotFound, LocalClosureVar, InitializationMode::NotInitialization), SymbolTableOrScopeDepth::symbolTable(VirtualRegister { symbolTableConstantIndex }), offset.offset());
    593593        }
    594594    }
     
    18041804        return;
    18051805
    1806     OpProfileType::emit(this, registerToProfile, 0, flag, { }, resolveType());
     1806    OpProfileType::emit(this, registerToProfile, { }, flag, { }, resolveType());
    18071807
    18081808    // Don't emit expression info for this version of profile type. This generally means
     
    18241824        return;
    18251825
    1826     OpProfileType::emit(this, registerToProfile, 0,  flag, { }, resolveType());
     1826    OpProfileType::emit(this, registerToProfile, { },  flag, { }, resolveType());
    18271827    emitTypeProfilerExpressionInfo(startDivot, endDivot);
    18281828}
     
    18371837
    18381838    ProfileTypeBytecodeFlag flag;
    1839     int symbolTableOrScopeDepth;
     1839    SymbolTableOrScopeDepth symbolTableOrScopeDepth;
    18401840    if (var.local() || var.offset().isScope()) {
    18411841        flag = ProfileTypeBytecodeLocallyResolved;
    18421842        ASSERT(var.symbolTableConstantIndex());
    1843         symbolTableOrScopeDepth = var.symbolTableConstantIndex();
     1843        symbolTableOrScopeDepth = SymbolTableOrScopeDepth::symbolTable(VirtualRegister { var.symbolTableConstantIndex() });
    18441844    } else {
    18451845        flag = ProfileTypeBytecodeClosureVar;
    1846         symbolTableOrScopeDepth = localScopeDepth();
     1846        symbolTableOrScopeDepth = SymbolTableOrScopeDepth::scopeDepth(localScopeDepth());
    18471847    }
    18481848
     
    25132513    case VarKind::Invalid: {
    25142514        GetPutInfo getPutInfo(0);
    2515         int scopeDepth;
     2515        SymbolTableOrScopeDepth symbolTableOrScopeDepth;
    25162516        ScopeOffset offset;
    25172517        if (variable.offset().isScope()) {
    25182518            offset = variable.offset().scopeOffset();
    25192519            getPutInfo = GetPutInfo(resolveMode, LocalClosureVar, initializationMode);
    2520             scopeDepth = variable.symbolTableConstantIndex();
     2520            symbolTableOrScopeDepth = SymbolTableOrScopeDepth::symbolTable(VirtualRegister { variable.symbolTableConstantIndex() });
    25212521        } else {
    25222522            ASSERT(resolveType() != LocalClosureVar);
    25232523            getPutInfo = GetPutInfo(resolveMode, resolveType(), initializationMode);
    2524             scopeDepth = localScopeDepth();
    2525         }
    2526         OpPutToScope::emit(this, scope, addConstant(variable.ident()), value, getPutInfo, scopeDepth, !!offset ? offset.offset() : 0);
     2524            symbolTableOrScopeDepth = SymbolTableOrScopeDepth::scopeDepth(localScopeDepth());
     2525        }
     2526        OpPutToScope::emit(this, scope, addConstant(variable.ident()), value, getPutInfo, symbolTableOrScopeDepth, !!offset ? offset.offset() : 0);
    25272527        m_codeBlock->addPropertyAccessInstruction(m_lastInstruction.offset());
    25282528        return value;
     
    37443744}
    37453745
    3746 int BytecodeGenerator::localScopeDepth() const
     3746unsigned BytecodeGenerator::localScopeDepth() const
    37473747{
    37483748    return m_localScopeDepth;
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r245047 r245213  
    12361236        SegmentedVector<LabelScope, 32> m_labelScopes;
    12371237        unsigned m_finallyDepth { 0 };
    1238         int m_localScopeDepth { 0 };
     1238        unsigned m_localScopeDepth { 0 };
    12391239        const CodeType m_codeType;
    12401240
    1241         int localScopeDepth() const;
     1241        unsigned localScopeDepth() const;
    12421242        void pushLocalControlFlowScope();
    12431243        void popLocalControlFlowScope();
Note: See TracChangeset for help on using the changeset viewer.