[JSC] Shrink sizeof(UnlinkedCodeBlock)
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Feb 2019 18:28:33 +0000 (18:28 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Feb 2019 18:28:33 +0000 (18:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194281

Reviewed by Michael Saboff.

Source/JavaScriptCore:

This patch first attempts to reduce the size of UnlinkedCodeBlock in a relatively simpler way. Reordering members, remove unused member, and
move rarely used members to RareData. This changes sizeof(UnlinkedCodeBlock) from 312 to 256.

Still we have several chances to reduce sizeof(UnlinkedCodeBlock). Making more Vectors to RefCountedArrays can be done with some restructuring
of generatorification phase. It would be possible to remove m_sourceURLDirective and m_sourceMappingURLDirective from UnlinkedCodeBlock since
they should be in SourceProvider and that should be enough. These changes require some intrusive modifications and we make them as a future work.

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::finishCreation):
* bytecode/CodeBlock.h:
(JSC::CodeBlock::bitVectors const): Deleted.
* bytecode/CodeType.h:
* bytecode/UnlinkedCodeBlock.cpp:
(JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
(JSC::UnlinkedCodeBlock::shrinkToFit):
* bytecode/UnlinkedCodeBlock.h:
(JSC::UnlinkedCodeBlock::bitVector):
(JSC::UnlinkedCodeBlock::addBitVector):
(JSC::UnlinkedCodeBlock::addSetConstant):
(JSC::UnlinkedCodeBlock::constantRegisters):
(JSC::UnlinkedCodeBlock::numberOfConstantIdentifierSets const):
(JSC::UnlinkedCodeBlock::constantIdentifierSets):
(JSC::UnlinkedCodeBlock::codeType const):
(JSC::UnlinkedCodeBlock::didOptimize const):
(JSC::UnlinkedCodeBlock::setDidOptimize):
(JSC::UnlinkedCodeBlock::usesGlobalObject const): Deleted.
(JSC::UnlinkedCodeBlock::setGlobalObjectRegister): Deleted.
(JSC::UnlinkedCodeBlock::globalObjectRegister const): Deleted.
(JSC::UnlinkedCodeBlock::bitVectors const): Deleted.
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitLoad):
(JSC::BytecodeGenerator::emitLoadGlobalObject): Deleted.
* bytecompiler/BytecodeGenerator.h:
* runtime/CachedTypes.cpp:
(JSC::CachedCodeBlockRareData::encode):
(JSC::CachedCodeBlockRareData::decode const):
(JSC::CachedCodeBlock::scopeRegister const):
(JSC::CachedCodeBlock::codeType const):
(JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
(JSC::CachedCodeBlock<CodeBlockType>::decode const):
(JSC::CachedCodeBlock<CodeBlockType>::encode):
(JSC::CachedCodeBlock::globalObjectRegister const): Deleted.

Source/WTF:

* wtf/TriState.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240981 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/CodeBlock.cpp
Source/JavaScriptCore/bytecode/CodeBlock.h
Source/JavaScriptCore/bytecode/CodeType.h
Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp
Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
Source/JavaScriptCore/runtime/CachedTypes.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/TriState.h

index 17fc4ef..4c70a3c 100644 (file)
@@ -1,3 +1,53 @@
+2019-02-05  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Shrink sizeof(UnlinkedCodeBlock)
+        https://bugs.webkit.org/show_bug.cgi?id=194281
+
+        Reviewed by Michael Saboff.
+
+        This patch first attempts to reduce the size of UnlinkedCodeBlock in a relatively simpler way. Reordering members, remove unused member, and
+        move rarely used members to RareData. This changes sizeof(UnlinkedCodeBlock) from 312 to 256.
+
+        Still we have several chances to reduce sizeof(UnlinkedCodeBlock). Making more Vectors to RefCountedArrays can be done with some restructuring
+        of generatorification phase. It would be possible to remove m_sourceURLDirective and m_sourceMappingURLDirective from UnlinkedCodeBlock since
+        they should be in SourceProvider and that should be enough. These changes require some intrusive modifications and we make them as a future work.
+
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::finishCreation):
+        * bytecode/CodeBlock.h:
+        (JSC::CodeBlock::bitVectors const): Deleted.
+        * bytecode/CodeType.h:
+        * bytecode/UnlinkedCodeBlock.cpp:
+        (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
+        (JSC::UnlinkedCodeBlock::shrinkToFit):
+        * bytecode/UnlinkedCodeBlock.h:
+        (JSC::UnlinkedCodeBlock::bitVector):
+        (JSC::UnlinkedCodeBlock::addBitVector):
+        (JSC::UnlinkedCodeBlock::addSetConstant):
+        (JSC::UnlinkedCodeBlock::constantRegisters):
+        (JSC::UnlinkedCodeBlock::numberOfConstantIdentifierSets const):
+        (JSC::UnlinkedCodeBlock::constantIdentifierSets):
+        (JSC::UnlinkedCodeBlock::codeType const):
+        (JSC::UnlinkedCodeBlock::didOptimize const):
+        (JSC::UnlinkedCodeBlock::setDidOptimize):
+        (JSC::UnlinkedCodeBlock::usesGlobalObject const): Deleted.
+        (JSC::UnlinkedCodeBlock::setGlobalObjectRegister): Deleted.
+        (JSC::UnlinkedCodeBlock::globalObjectRegister const): Deleted.
+        (JSC::UnlinkedCodeBlock::bitVectors const): Deleted.
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::emitLoad):
+        (JSC::BytecodeGenerator::emitLoadGlobalObject): Deleted.
+        * bytecompiler/BytecodeGenerator.h:
+        * runtime/CachedTypes.cpp:
+        (JSC::CachedCodeBlockRareData::encode):
+        (JSC::CachedCodeBlockRareData::decode const):
+        (JSC::CachedCodeBlock::scopeRegister const):
+        (JSC::CachedCodeBlock::codeType const):
+        (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
+        (JSC::CachedCodeBlock<CodeBlockType>::decode const):
+        (JSC::CachedCodeBlock<CodeBlockType>::encode):
+        (JSC::CachedCodeBlock::globalObjectRegister const): Deleted.
+
 2019-02-04  Yusuke Suzuki  <ysuzuki@apple.com>
 
         Unreviewed, add missing exception checks after r240637
index 3837d11..b4f228c 100644 (file)
@@ -416,12 +416,6 @@ bool CodeBlock::finishCreation(VM& vm, ScriptExecutable* ownerExecutable, Unlink
     setConstantRegisters(unlinkedCodeBlock->constantRegisters(), unlinkedCodeBlock->constantsSourceCodeRepresentation());
     RETURN_IF_EXCEPTION(throwScope, false);
 
-    setConstantIdentifierSetRegisters(vm, unlinkedCodeBlock->constantIdentifierSets());
-    RETURN_IF_EXCEPTION(throwScope, false);
-
-    if (unlinkedCodeBlock->usesGlobalObject())
-        m_constantRegisters[unlinkedCodeBlock->globalObjectRegister().toConstantIndex()].set(vm, this, m_globalObject.get());
-
     for (unsigned i = 0; i < LinkTimeConstantCount; i++) {
         LinkTimeConstant type = static_cast<LinkTimeConstant>(i);
         if (unsigned registerIndex = unlinkedCodeBlock->registerIndexForLinkTimeConstant(type))
@@ -458,6 +452,10 @@ bool CodeBlock::finishCreation(VM& vm, ScriptExecutable* ownerExecutable, Unlink
 
     if (unlinkedCodeBlock->hasRareData()) {
         createRareDataIfNecessary();
+
+        setConstantIdentifierSetRegisters(vm, unlinkedCodeBlock->constantIdentifierSets());
+        RETURN_IF_EXCEPTION(throwScope, false);
+
         if (size_t count = unlinkedCodeBlock->numberOfExceptionHandlers()) {
             m_rareData->m_exceptionHandlers.resizeToFit(count);
             for (size_t i = 0; i < count; i++) {
index d5a232b..2b380db 100644 (file)
@@ -569,7 +569,6 @@ public:
     int numberOfFunctionDecls() { return m_functionDecls.size(); }
     FunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); }
     
-    const Vector<BitVector>& bitVectors() const { return m_unlinkedCode->bitVectors(); }
     const BitVector& bitVector(size_t i) { return m_unlinkedCode->bitVector(i); }
 
     Heap* heap() const { return &m_vm->heap; }
index 3c38ca2..d4bda79 100644 (file)
@@ -27,7 +27,7 @@
 
 namespace JSC {
 
-enum CodeType { GlobalCode, EvalCode, FunctionCode, ModuleCode };
+enum CodeType : uint8_t { GlobalCode, EvalCode, FunctionCode, ModuleCode };
 
 } // namespace JSC
 
index 6095d58..7fba73d 100644 (file)
@@ -56,8 +56,6 @@ const ClassInfo UnlinkedCodeBlock::s_info = { "UnlinkedCodeBlock", nullptr, null
 
 UnlinkedCodeBlock::UnlinkedCodeBlock(VM* vm, Structure* structure, CodeType codeType, const ExecutableInfo& info, DebuggerMode debuggerMode)
     : Base(*vm, structure)
-    , m_globalObjectRegister(VirtualRegister())
-    , m_metadata(UnlinkedMetadataTable::create())
     , m_usesEval(info.usesEval())
     , m_isStrictMode(info.isStrictMode())
     , m_isConstructor(info.isConstructor())
@@ -72,14 +70,16 @@ UnlinkedCodeBlock::UnlinkedCodeBlock(VM* vm, Structure* structure, CodeType code
     , m_derivedContextType(static_cast<unsigned>(info.derivedContextType()))
     , m_evalContextType(static_cast<unsigned>(info.evalContextType()))
     , m_hasTailCalls(false)
-    , m_features(0)
-    , m_didOptimize(MixedTriState)
+    , m_codeType(static_cast<unsigned>(codeType))
+    , m_didOptimize(static_cast<unsigned>(MixedTriState))
     , m_parseMode(info.parseMode())
-    , m_codeType(codeType)
+    , m_metadata(UnlinkedMetadataTable::create())
 {
     for (auto& constantRegisterIndex : m_linkTimeConstants)
         constantRegisterIndex = 0;
     ASSERT(m_constructorKind == static_cast<unsigned>(info.constructorKind()));
+    ASSERT(m_codeType == static_cast<unsigned>(codeType));
+    ASSERT(m_didOptimize == static_cast<unsigned>(MixedTriState));
 }
 
 void UnlinkedCodeBlock::visitChildren(JSCell* cell, SlotVisitor& visitor)
@@ -381,9 +381,7 @@ void UnlinkedCodeBlock::shrinkToFit()
     m_jumpTargets.shrinkToFit();
     m_propertyAccessInstructions.shrinkToFit();
     m_identifiers.shrinkToFit();
-    m_bitVectors.shrinkToFit();
     m_constantRegisters.shrinkToFit();
-    m_constantIdentifierSets.shrinkToFit();
     m_constantsSourceCodeRepresentation.shrinkToFit();
     m_functionDecls.shrinkToFit();
     m_functionExprs.shrinkToFit();
@@ -395,6 +393,8 @@ void UnlinkedCodeBlock::shrinkToFit()
         m_rareData->m_stringSwitchJumpTables.shrinkToFit();
         m_rareData->m_expressionInfoFatPositions.shrinkToFit();
         m_rareData->m_opProfileControlFlowBytecodeOffsets.shrinkToFit();
+        m_rareData->m_bitVectors.shrinkToFit();
+        m_rareData->m_constantIdentifierSets.shrinkToFit();
     }
 }
 
index d0bb0c7..8dc6769 100644 (file)
@@ -140,10 +140,6 @@ public:
     void setThisRegister(VirtualRegister thisRegister) { m_thisRegister = thisRegister; }
     void setScopeRegister(VirtualRegister scopeRegister) { m_scopeRegister = scopeRegister; }
 
-    bool usesGlobalObject() const { return m_globalObjectRegister.isValid(); }
-    void setGlobalObjectRegister(VirtualRegister globalObjectRegister) { m_globalObjectRegister = globalObjectRegister; }
-    VirtualRegister globalObjectRegister() const { return m_globalObjectRegister; }
-
     // Parameter information
     void setNumParameters(int newValue) { m_numParameters = newValue; }
     void addParameter() { m_numParameters++; }
@@ -156,22 +152,23 @@ public:
     const Identifier& identifier(int index) const { return m_identifiers[index]; }
     const Vector<Identifier>& identifiers() const { return m_identifiers; }
 
-    const Vector<BitVector>& bitVectors() const { return m_bitVectors; }
-    BitVector& bitVector(size_t i) { return m_bitVectors[i]; }
+    BitVector& bitVector(size_t i) { ASSERT(m_rareData); return m_rareData->m_bitVectors[i]; }
     unsigned addBitVector(BitVector&& bitVector)
     {
-        m_bitVectors.append(WTFMove(bitVector));
-        return m_bitVectors.size() - 1;
+        createRareDataIfNecessary();
+        m_rareData->m_bitVectors.append(WTFMove(bitVector));
+        return m_rareData->m_bitVectors.size() - 1;
     }
 
     void addSetConstant(IdentifierSet& set)
     {
+        createRareDataIfNecessary();
         VM& vm = *this->vm();
         auto locker = lockDuringMarking(vm.heap, cellLock());
         unsigned result = m_constantRegisters.size();
         m_constantRegisters.append(WriteBarrier<Unknown>());
         m_constantsSourceCodeRepresentation.append(SourceCodeRepresentation::Other);
-        m_constantIdentifierSets.append(ConstantIdentifierSetEntry(set, result));
+        m_rareData->m_constantIdentifierSets.append(ConstantIdentifierSetEntry(set, result));
     }
 
     unsigned addConstant(JSValue v, SourceCodeRepresentation sourceCodeRepresentation = SourceCodeRepresentation::Other)
@@ -204,13 +201,16 @@ public:
         ASSERT(index < LinkTimeConstantCount);
         return m_linkTimeConstants[index];
     }
+
     const Vector<WriteBarrier<Unknown>>& constantRegisters() { return m_constantRegisters; }
-    const Vector<ConstantIdentifierSetEntry>& constantIdentifierSets() { return m_constantIdentifierSets; }
     const WriteBarrier<Unknown>& constantRegister(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex]; }
     ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; }
     ALWAYS_INLINE JSValue getConstant(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex].get(); }
     const Vector<SourceCodeRepresentation>& constantsSourceCodeRepresentation() { return m_constantsSourceCodeRepresentation; }
 
+    unsigned numberOfConstantIdentifierSets() const { return m_rareData ? m_rareData->m_constantIdentifierSets.size() : 0; }
+    const Vector<ConstantIdentifierSetEntry>& constantIdentifierSets() { ASSERT(m_rareData); return m_rareData->m_constantIdentifierSets; }
+
     // Jumps
     size_t numberOfJumpTargets() const { return m_jumpTargets.size(); }
     void addJumpTarget(unsigned jumpTarget) { m_jumpTargets.append(jumpTarget); }
@@ -272,7 +272,7 @@ public:
     void addExceptionHandler(const UnlinkedHandlerInfo& handler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(handler); }
     UnlinkedHandlerInfo& exceptionHandler(int index) { ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; }
 
-    CodeType codeType() const { return m_codeType; }
+    CodeType codeType() const { return static_cast<CodeType>(m_codeType); }
 
     VirtualRegister thisRegister() const { return m_thisRegister; }
     VirtualRegister scopeRegister() const { return m_scopeRegister; }
@@ -333,8 +333,8 @@ public:
 
     bool wasCompiledWithDebuggingOpcodes() const { return m_wasCompiledWithDebuggingOpcodes; }
 
-    TriState didOptimize() const { return m_didOptimize; }
-    void setDidOptimize(TriState didOptimize) { m_didOptimize = didOptimize; }
+    TriState didOptimize() const { return static_cast<TriState>(m_didOptimize); }
+    void setDidOptimize(TriState didOptimize) { m_didOptimize = static_cast<unsigned>(didOptimize); }
 
     void dump(PrintStream&) const;
 
@@ -401,20 +401,10 @@ private:
     void getLineAndColumn(const ExpressionRangeInfo&, unsigned& line, unsigned& column) const;
     BytecodeLivenessAnalysis& livenessAnalysisSlow(CodeBlock*);
 
-    std::unique_ptr<InstructionStream> m_instructions;
-    std::unique_ptr<BytecodeLivenessAnalysis> m_liveness;
-
     VirtualRegister m_thisRegister;
     VirtualRegister m_scopeRegister;
-    VirtualRegister m_globalObjectRegister;
-
-    String m_sourceURLDirective;
-    String m_sourceMappingURLDirective;
-    Ref<UnlinkedMetadataTable> m_metadata;
 
-#if ENABLE(DFG_JIT)
-    DFG::ExitProfile m_exitProfile;
-#endif
+    std::array<unsigned, LinkTimeConstantCount> m_linkTimeConstants;
 
     unsigned m_usesEval : 1;
     unsigned m_isStrictMode : 1;
@@ -430,6 +420,13 @@ private:
     unsigned m_derivedContextType : 2;
     unsigned m_evalContextType : 2;
     unsigned m_hasTailCalls : 1;
+    unsigned m_codeType : 2;
+    unsigned m_didOptimize : 2;
+public:
+    ConcurrentJSLock m_lock;
+private:
+    CodeFeatures m_features { 0 };
+    SourceParseMode m_parseMode;
 
     unsigned m_lineCount { 0 };
     unsigned m_endColumn { UINT_MAX };
@@ -438,33 +435,34 @@ private:
     int m_numCalleeLocals { 0 };
     int m_numParameters { 0 };
 
-public:
-    ConcurrentJSLock m_lock;
-private:
-    CodeFeatures m_features { 0 };
-    TriState m_didOptimize;
-    SourceParseMode m_parseMode;
-    CodeType m_codeType;
+    String m_sourceURLDirective;
+    String m_sourceMappingURLDirective;
 
     Vector<InstructionStream::Offset> m_jumpTargets;
+    Ref<UnlinkedMetadataTable> m_metadata;
+    std::unique_ptr<InstructionStream> m_instructions;
+    std::unique_ptr<BytecodeLivenessAnalysis> m_liveness;
+
+
+#if ENABLE(DFG_JIT)
+    DFG::ExitProfile m_exitProfile;
+#endif
+
 
     Vector<InstructionStream::Offset> m_propertyAccessInstructions;
 
     // Constant Pools
     Vector<Identifier> m_identifiers;
-    Vector<BitVector> m_bitVectors;
     Vector<WriteBarrier<Unknown>> m_constantRegisters;
-    Vector<ConstantIdentifierSetEntry> m_constantIdentifierSets;
     Vector<SourceCodeRepresentation> m_constantsSourceCodeRepresentation;
     typedef Vector<WriteBarrier<UnlinkedFunctionExecutable>> FunctionExpressionVector;
     FunctionExpressionVector m_functionDecls;
     FunctionExpressionVector m_functionExprs;
-    std::array<unsigned, LinkTimeConstantCount> m_linkTimeConstants;
 
 public:
     struct RareData {
-        WTF_MAKE_FAST_ALLOCATED;
-    public:
+        WTF_MAKE_STRUCT_FAST_ALLOCATED;
+
         Vector<UnlinkedHandlerInfo> m_exceptionHandlers;
 
         // Jump Tables
@@ -479,6 +477,8 @@ public:
         };
         HashMap<unsigned, TypeProfilerExpressionRange> m_typeProfilerInfoMap;
         Vector<InstructionStream::Offset> m_opProfileControlFlowBytecodeOffsets;
+        Vector<BitVector> m_bitVectors;
+        Vector<ConstantIdentifierSetEntry> m_constantIdentifierSets;
     };
 
     void addOutOfLineJumpTarget(InstructionStream::Offset, int target);
index d6e131b..cc76f23 100644 (file)
@@ -1869,11 +1869,13 @@ RegisterID* BytecodeGenerator::emitLoad(RegisterID* dst, JSValue v, SourceCodeRe
 
 RegisterID* BytecodeGenerator::emitLoad(RegisterID* dst, IdentifierSet& set)
 {
-    for (const auto& entry : m_codeBlock->constantIdentifierSets()) {
-        if (entry.first != set)
-            continue;
-        
-        return &m_constantPoolRegisters[entry.second];
+    if (m_codeBlock->numberOfConstantIdentifierSets()) {
+        for (const auto& entry : m_codeBlock->constantIdentifierSets()) {
+            if (entry.first != set)
+                continue;
+            
+            return &m_constantPoolRegisters[entry.second];
+        }
     }
     
     unsigned index = addConstantIndex();
@@ -1886,19 +1888,6 @@ RegisterID* BytecodeGenerator::emitLoad(RegisterID* dst, IdentifierSet& set)
     return m_setRegister;
 }
 
-RegisterID* BytecodeGenerator::emitLoadGlobalObject(RegisterID* dst)
-{
-    if (!m_globalObjectRegister) {
-        int index = addConstantIndex();
-        m_codeBlock->addConstant(JSValue());
-        m_globalObjectRegister = &m_constantPoolRegisters[index];
-        m_codeBlock->setGlobalObjectRegister(VirtualRegister(index));
-    }
-    if (dst)
-        move(dst, m_globalObjectRegister);
-    return m_globalObjectRegister;
-}
-
 template<typename LookUpVarKindFunctor>
 bool BytecodeGenerator::instantiateLexicalVariables(const VariableEnvironment& lexicalVariables, SymbolTable* symbolTable, ScopeRegisterType scopeRegisterType, LookUpVarKindFunctor lookUpVarKind)
 {
index 6ad716e..e31f06e 100644 (file)
@@ -671,7 +671,6 @@ namespace JSC {
         RegisterID* emitLoad(RegisterID* dst, const Identifier&);
         RegisterID* emitLoad(RegisterID* dst, JSValue, SourceCodeRepresentation = SourceCodeRepresentation::Other);
         RegisterID* emitLoad(RegisterID* dst, IdentifierSet& excludedList);
-        RegisterID* emitLoadGlobalObject(RegisterID* dst);
 
         template<typename UnaryOp, typename = std::enable_if_t<UnaryOp::opcodeID != op_negate>>
         RegisterID* emitUnaryOp(RegisterID* dst, RegisterID* src)
@@ -1241,7 +1240,6 @@ namespace JSC {
         RegisterID* m_lexicalEnvironmentRegister { nullptr };
         RegisterID* m_generatorRegister { nullptr };
         RegisterID* m_emptyValueRegister { nullptr };
-        RegisterID* m_globalObjectRegister { nullptr };
         RegisterID* m_newTargetRegister { nullptr };
         RegisterID* m_isDerivedConstuctor { nullptr };
         RegisterID* m_linkTimeConstantRegisters[LinkTimeConstantCount];
index c67e17d..b53dfd6 100644 (file)
@@ -733,39 +733,6 @@ private:
     CachedHashMap<CachedRefPtr<CachedStringImpl>, UnlinkedStringJumpTable:: OffsetLocation> m_offsetTable;
 };
 
-class CachedCodeBlockRareData : public CachedObject<UnlinkedCodeBlock::RareData> {
-public:
-    void encode(Encoder& encoder, const UnlinkedCodeBlock::RareData& rareData)
-    {
-        m_exceptionHandlers.encode(encoder, rareData.m_exceptionHandlers);
-        m_switchJumpTables.encode(encoder, rareData.m_switchJumpTables);
-        m_stringSwitchJumpTables.encode(encoder, rareData.m_stringSwitchJumpTables);
-        m_expressionInfoFatPositions.encode(encoder, rareData.m_expressionInfoFatPositions);
-        m_typeProfilerInfoMap.encode(encoder, rareData.m_typeProfilerInfoMap);
-        m_opProfileControlFlowBytecodeOffsets.encode(encoder, rareData.m_opProfileControlFlowBytecodeOffsets);
-    }
-
-    UnlinkedCodeBlock::RareData* decode(Decoder& decoder) const
-    {
-        UnlinkedCodeBlock::RareData* rareData = new UnlinkedCodeBlock::RareData { };
-        m_exceptionHandlers.decode(decoder, rareData->m_exceptionHandlers);
-        m_switchJumpTables.decode(decoder, rareData->m_switchJumpTables);
-        m_stringSwitchJumpTables.decode(decoder, rareData->m_stringSwitchJumpTables);
-        m_expressionInfoFatPositions.decode(decoder, rareData->m_expressionInfoFatPositions);
-        m_typeProfilerInfoMap.decode(decoder, rareData->m_typeProfilerInfoMap);
-        m_opProfileControlFlowBytecodeOffsets.decode(decoder, rareData->m_opProfileControlFlowBytecodeOffsets);
-        return rareData;
-    }
-
-private:
-    CachedVector<UnlinkedHandlerInfo> m_exceptionHandlers;
-    CachedVector<CachedSimpleJumpTable> m_switchJumpTables;
-    CachedVector<CachedStringJumpTable> m_stringSwitchJumpTables;
-    CachedVector<ExpressionRangeInfo::FatPosition> m_expressionInfoFatPositions;
-    CachedHashMap<unsigned, UnlinkedCodeBlock::RareData::TypeProfilerExpressionRange> m_typeProfilerInfoMap;
-    CachedVector<InstructionStream::Offset> m_opProfileControlFlowBytecodeOffsets;
-};
-
 class CachedBitVector : public VariableLengthObject<BitVector> {
 public:
     void encode(Encoder& encoder, const BitVector& bitVector)
@@ -828,6 +795,45 @@ private:
     CachedHashSet<CachedRefPtr<CachedUniquedStringImpl>, IdentifierRepHash> m_set;
 };
 
+class CachedCodeBlockRareData : public CachedObject<UnlinkedCodeBlock::RareData> {
+public:
+    void encode(Encoder& encoder, const UnlinkedCodeBlock::RareData& rareData)
+    {
+        m_exceptionHandlers.encode(encoder, rareData.m_exceptionHandlers);
+        m_switchJumpTables.encode(encoder, rareData.m_switchJumpTables);
+        m_stringSwitchJumpTables.encode(encoder, rareData.m_stringSwitchJumpTables);
+        m_expressionInfoFatPositions.encode(encoder, rareData.m_expressionInfoFatPositions);
+        m_typeProfilerInfoMap.encode(encoder, rareData.m_typeProfilerInfoMap);
+        m_opProfileControlFlowBytecodeOffsets.encode(encoder, rareData.m_opProfileControlFlowBytecodeOffsets);
+        m_bitVectors.encode(encoder, rareData.m_bitVectors);
+        m_constantIdentifierSets.encode(encoder, rareData.m_constantIdentifierSets);
+    }
+
+    UnlinkedCodeBlock::RareData* decode(Decoder& decoder) const
+    {
+        UnlinkedCodeBlock::RareData* rareData = new UnlinkedCodeBlock::RareData { };
+        m_exceptionHandlers.decode(decoder, rareData->m_exceptionHandlers);
+        m_switchJumpTables.decode(decoder, rareData->m_switchJumpTables);
+        m_stringSwitchJumpTables.decode(decoder, rareData->m_stringSwitchJumpTables);
+        m_expressionInfoFatPositions.decode(decoder, rareData->m_expressionInfoFatPositions);
+        m_typeProfilerInfoMap.decode(decoder, rareData->m_typeProfilerInfoMap);
+        m_opProfileControlFlowBytecodeOffsets.decode(decoder, rareData->m_opProfileControlFlowBytecodeOffsets);
+        m_bitVectors.decode(decoder, rareData->m_bitVectors);
+        m_constantIdentifierSets.decode(decoder, rareData->m_constantIdentifierSets);
+        return rareData;
+    }
+
+private:
+    CachedVector<UnlinkedHandlerInfo> m_exceptionHandlers;
+    CachedVector<CachedSimpleJumpTable> m_switchJumpTables;
+    CachedVector<CachedStringJumpTable> m_stringSwitchJumpTables;
+    CachedVector<ExpressionRangeInfo::FatPosition> m_expressionInfoFatPositions;
+    CachedHashMap<unsigned, UnlinkedCodeBlock::RareData::TypeProfilerExpressionRange> m_typeProfilerInfoMap;
+    CachedVector<InstructionStream::Offset> m_opProfileControlFlowBytecodeOffsets;
+    CachedVector<CachedBitVector> m_bitVectors;
+    CachedVector<CachedConstantIdentifierSetEntry> m_constantIdentifierSets;
+};
+
 class CachedVariableEnvironment : public CachedObject<VariableEnvironment> {
 public:
     void encode(Encoder& encoder, const VariableEnvironment& env)
@@ -1472,7 +1478,6 @@ public:
 
     VirtualRegister thisRegister() const { return m_thisRegister; }
     VirtualRegister scopeRegister() const { return m_scopeRegister; }
-    VirtualRegister globalObjectRegister() const { return m_globalObjectRegister; }
 
     String sourceURLDirective(Decoder& decoder) const { return m_sourceURLDirective.decode(decoder); }
     String sourceMappingURLDirective(Decoder& decoder) const { return m_sourceMappingURLDirective.decode(decoder); }
@@ -1502,14 +1507,14 @@ public:
 
     CodeFeatures features() const { return m_features; }
     SourceParseMode parseMode() const { return m_parseMode; }
-    CodeType codeType() const { return m_codeType; }
+    unsigned codeType() const { return m_codeType; }
 
     UnlinkedCodeBlock::RareData* rareData(Decoder& decoder) const { return m_rareData.decodeAsPtr(decoder); }
 
 private:
     VirtualRegister m_thisRegister;
     VirtualRegister m_scopeRegister;
-    VirtualRegister m_globalObjectRegister;
+    std::array<unsigned, LinkTimeConstantCount> m_linkTimeConstants;
 
     unsigned m_usesEval : 1;
     unsigned m_isStrictMode : 1;
@@ -1525,6 +1530,10 @@ private:
     unsigned m_derivedContextType : 2;
     unsigned m_evalContextType : 2;
     unsigned m_hasTailCalls : 1;
+    unsigned m_codeType : 2;
+
+    CodeFeatures m_features;
+    SourceParseMode m_parseMode;
 
     unsigned m_lineCount;
     unsigned m_endColumn;
@@ -1533,11 +1542,6 @@ private:
     int m_numCalleeLocals;
     int m_numParameters;
 
-    CodeFeatures m_features;
-    SourceParseMode m_parseMode;
-    CodeType m_codeType;
-
-    std::array<unsigned, LinkTimeConstantCount> m_linkTimeConstants;
     CachedMetadataTable m_metadata;
 
     CachedOptional<CachedCodeBlockRareData> m_rareData;
@@ -1553,9 +1557,7 @@ private:
     CachedVector<ExpressionRangeInfo> m_expressionInfo;
     CachedHashMap<InstructionStream::Offset, int> m_outOfLineJumpTargets;
 
-    CachedVector<CachedConstantIdentifierSetEntry> m_constantIdentifierSets;
     CachedVector<CachedIdentifier> m_identifiers;
-    CachedVector<CachedBitVector> m_bitVectors;
     CachedVector<CachedWriteBarrier<CachedFunctionExecutable>> m_functionDecls;
     CachedVector<CachedWriteBarrier<CachedFunctionExecutable>> m_functionExprs;
 };
@@ -1691,16 +1693,8 @@ using CachedCodeBlockType = typename CachedCodeBlockTypeImpl<T>::type;
 template<typename CodeBlockType>
 ALWAYS_INLINE UnlinkedCodeBlock::UnlinkedCodeBlock(Decoder& decoder, Structure* structure, const CachedCodeBlock<CodeBlockType>& cachedCodeBlock)
     : Base(decoder.vm(), structure)
-    , m_instructions(cachedCodeBlock.instructions(decoder))
-    , m_liveness(nullptr)
     , m_thisRegister(cachedCodeBlock.thisRegister())
     , m_scopeRegister(cachedCodeBlock.scopeRegister())
-    , m_globalObjectRegister(cachedCodeBlock.globalObjectRegister())
-
-    , m_sourceURLDirective(cachedCodeBlock.sourceURLDirective(decoder))
-    , m_sourceMappingURLDirective(cachedCodeBlock.sourceMappingURLDirective(decoder))
-
-    , m_metadata(cachedCodeBlock.metadata(decoder))
 
     , m_usesEval(cachedCodeBlock.usesEval())
     , m_isStrictMode(cachedCodeBlock.isStrictMode())
@@ -1716,14 +1710,23 @@ ALWAYS_INLINE UnlinkedCodeBlock::UnlinkedCodeBlock(Decoder& decoder, Structure*
     , m_derivedContextType(cachedCodeBlock.derivedContextType())
     , m_evalContextType(cachedCodeBlock.evalContextType())
     , m_hasTailCalls(cachedCodeBlock.hasTailCalls())
+    , m_codeType(cachedCodeBlock.codeType())
+
+    , m_features(cachedCodeBlock.features())
+    , m_parseMode(cachedCodeBlock.parseMode())
+
     , m_lineCount(cachedCodeBlock.lineCount())
     , m_endColumn(cachedCodeBlock.endColumn())
     , m_numVars(cachedCodeBlock.numVars())
     , m_numCalleeLocals(cachedCodeBlock.numCalleeLocals())
     , m_numParameters(cachedCodeBlock.numParameters())
-    , m_features(cachedCodeBlock.features())
-    , m_parseMode(cachedCodeBlock.parseMode())
-    , m_codeType(cachedCodeBlock.codeType())
+
+    , m_sourceURLDirective(cachedCodeBlock.sourceURLDirective(decoder))
+    , m_sourceMappingURLDirective(cachedCodeBlock.sourceMappingURLDirective(decoder))
+
+    , m_metadata(cachedCodeBlock.metadata(decoder))
+    , m_instructions(cachedCodeBlock.instructions(decoder))
+
     , m_rareData(cachedCodeBlock.rareData(decoder))
 {
 }
@@ -1740,9 +1743,7 @@ ALWAYS_INLINE void CachedCodeBlock<CodeBlockType>::decode(Decoder& decoder, Unli
     m_expressionInfo.decode(decoder, codeBlock.m_expressionInfo);
     m_outOfLineJumpTargets.decode(decoder, codeBlock.m_outOfLineJumpTargets);
     m_jumpTargets.decode(decoder, codeBlock.m_jumpTargets);
-    m_constantIdentifierSets.decode(decoder, codeBlock.m_constantIdentifierSets);
     m_identifiers.decode(decoder, codeBlock.m_identifiers);
-    m_bitVectors.decode(decoder, codeBlock.m_bitVectors);
     m_functionDecls.decode(decoder, codeBlock.m_functionDecls, &codeBlock);
     m_functionExprs.decode(decoder, codeBlock.m_functionExprs, &codeBlock);
 }
@@ -1856,7 +1857,6 @@ ALWAYS_INLINE void CachedCodeBlock<CodeBlockType>::encode(Encoder& encoder, cons
 {
     m_thisRegister = codeBlock.m_thisRegister;
     m_scopeRegister = codeBlock.m_scopeRegister;
-    m_globalObjectRegister = codeBlock.m_globalObjectRegister;
     m_usesEval = codeBlock.m_usesEval;
     m_isStrictMode = codeBlock.m_isStrictMode;
     m_isConstructor = codeBlock.m_isConstructor;
@@ -1897,9 +1897,7 @@ ALWAYS_INLINE void CachedCodeBlock<CodeBlockType>::encode(Encoder& encoder, cons
     m_jumpTargets.encode(encoder, codeBlock.m_jumpTargets);
     m_outOfLineJumpTargets.encode(encoder, codeBlock.m_outOfLineJumpTargets);
 
-    m_constantIdentifierSets.encode(encoder, codeBlock.m_constantIdentifierSets);
     m_identifiers.encode(encoder, codeBlock.m_identifiers);
-    m_bitVectors.encode(encoder, codeBlock.m_bitVectors);
     m_functionDecls.encode(encoder, codeBlock.m_functionDecls);
     m_functionExprs.encode(encoder, codeBlock.m_functionExprs);
 }
index 244c5c3..f3a9db4 100644 (file)
@@ -1,3 +1,12 @@
+2019-02-05  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Shrink sizeof(UnlinkedCodeBlock)
+        https://bugs.webkit.org/show_bug.cgi?id=194281
+
+        Reviewed by Michael Saboff.
+
+        * wtf/TriState.h:
+
 2019-02-05  Zan Dobersek  <zdobersek@igalia.com>
 
         [GLib] Stop URI-escaping file system representations
index 24ace54..5ae785d 100644 (file)
@@ -27,7 +27,7 @@
 
 namespace WTF {
 
-enum TriState : int8_t {
+enum TriState : uint8_t {
     FalseTriState,
     TrueTriState,
     MixedTriState