Title: [233629] trunk/Source
Revision
233629
Author
[email protected]
Date
2018-07-08 10:39:55 -0700 (Sun, 08 Jul 2018)

Log Message

[JSC] Optimize padding of UnlinkedCodeBlock to shrink
https://bugs.webkit.org/show_bug.cgi?id=187448

Reviewed by Saam Barati.

Source/_javascript_Core:

We optimize the size of CodeType and TriState. And we arrange the layout of UnlinkedCodeBlock.
These optimizations reduce the size of UnlinkedCodeBlock from 304 to 288.

* bytecode/CodeType.h:
* bytecode/UnlinkedCodeBlock.cpp:
(JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
* bytecode/UnlinkedCodeBlock.h:
(JSC::UnlinkedCodeBlock::codeType const):
(JSC::UnlinkedCodeBlock::didOptimize const):
(JSC::UnlinkedCodeBlock::setDidOptimize):
* bytecode/VirtualRegister.h:

Source/WTF:

* wtf/TriState.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (233628 => 233629)


--- trunk/Source/_javascript_Core/ChangeLog	2018-07-08 16:58:29 UTC (rev 233628)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-07-08 17:39:55 UTC (rev 233629)
@@ -1,5 +1,24 @@
 2018-07-08  Yusuke Suzuki  <[email protected]>
 
+        [JSC] Optimize padding of UnlinkedCodeBlock to shrink
+        https://bugs.webkit.org/show_bug.cgi?id=187448
+
+        Reviewed by Saam Barati.
+
+        We optimize the size of CodeType and TriState. And we arrange the layout of UnlinkedCodeBlock.
+        These optimizations reduce the size of UnlinkedCodeBlock from 304 to 288.
+
+        * bytecode/CodeType.h:
+        * bytecode/UnlinkedCodeBlock.cpp:
+        (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
+        * bytecode/UnlinkedCodeBlock.h:
+        (JSC::UnlinkedCodeBlock::codeType const):
+        (JSC::UnlinkedCodeBlock::didOptimize const):
+        (JSC::UnlinkedCodeBlock::setDidOptimize):
+        * bytecode/VirtualRegister.h:
+
+2018-07-08  Yusuke Suzuki  <[email protected]>
+
         [JSC] Optimize padding of InferredTypeTable by using cellLock
         https://bugs.webkit.org/show_bug.cgi?id=187447
 

Modified: trunk/Source/_javascript_Core/bytecode/CodeType.h (233628 => 233629)


--- trunk/Source/_javascript_Core/bytecode/CodeType.h	2018-07-08 16:58:29 UTC (rev 233628)
+++ trunk/Source/_javascript_Core/bytecode/CodeType.h	2018-07-08 17:39:55 UTC (rev 233629)
@@ -27,7 +27,13 @@
 
 namespace JSC {
 
-enum CodeType { GlobalCode, EvalCode, FunctionCode, ModuleCode };
+// CodeType should be within 2 bits (0b00 - 0b11).
+enum CodeType : uint8_t {
+    GlobalCode,
+    EvalCode,
+    FunctionCode,
+    ModuleCode
+};
 
 } // namespace JSC
 

Modified: trunk/Source/_javascript_Core/bytecode/UnlinkedCodeBlock.cpp (233628 => 233629)


--- trunk/Source/_javascript_Core/bytecode/UnlinkedCodeBlock.cpp	2018-07-08 16:58:29 UTC (rev 233628)
+++ trunk/Source/_javascript_Core/bytecode/UnlinkedCodeBlock.cpp	2018-07-08 17:39:55 UTC (rev 233629)
@@ -57,7 +57,6 @@
     , m_numVars(0)
     , m_numCalleeLocals(0)
     , m_numParameters(0)
-    , m_globalObjectRegister(VirtualRegister())
     , m_usesEval(info.usesEval())
     , m_isStrictMode(info.isStrictMode())
     , m_isConstructor(info.isConstructor())
@@ -72,12 +71,12 @@
     , m_derivedContextType(static_cast<unsigned>(info.derivedContextType()))
     , m_evalContextType(static_cast<unsigned>(info.evalContextType()))
     , m_hasTailCalls(false)
+    , m_codeType(codeType)
+    , m_didOptimize(MixedTriState)
     , m_lineCount(0)
     , m_endColumn(UINT_MAX)
-    , m_didOptimize(MixedTriState)
     , m_parseMode(info.parseMode())
     , m_features(0)
-    , m_codeType(codeType)
     , m_arrayProfileCount(0)
     , m_arrayAllocationProfileCount(0)
     , m_objectAllocationProfileCount(0)
@@ -86,6 +85,8 @@
 {
     for (auto& constantRegisterIndex : m_linkTimeConstants)
         constantRegisterIndex = 0;
+    ASSERT(codeType == this->codeType());
+    ASSERT(MixedTriState == this->didOptimize());
     ASSERT(m_constructorKind == static_cast<unsigned>(info.constructorKind()));
 }
 

Modified: trunk/Source/_javascript_Core/bytecode/UnlinkedCodeBlock.h (233628 => 233629)


--- trunk/Source/_javascript_Core/bytecode/UnlinkedCodeBlock.h	2018-07-08 16:58:29 UTC (rev 233628)
+++ trunk/Source/_javascript_Core/bytecode/UnlinkedCodeBlock.h	2018-07-08 17:39:55 UTC (rev 233629)
@@ -319,7 +319,7 @@
     UnlinkedLLIntCallLinkInfo addLLIntCallLinkInfo() { return m_llintCallLinkInfoCount++; }
     unsigned numberOfLLintCallLinkInfos() { return m_llintCallLinkInfoCount; }
 
-    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; }
@@ -380,8 +380,12 @@
 
     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);
+        ASSERT(didOptimize == this->didOptimize());
+    }
 
     void dump(PrintStream&) const;
 
@@ -436,10 +440,6 @@
     std::unique_ptr<UnlinkedInstructionStream> m_unlinkedInstructions;
     std::unique_ptr<BytecodeLivenessAnalysis> m_liveness;
 
-    VirtualRegister m_thisRegister;
-    VirtualRegister m_scopeRegister;
-    VirtualRegister m_globalObjectRegister;
-
     String m_sourceURLDirective;
     String m_sourceMappingURLDirective;
 
@@ -461,16 +461,21 @@
     unsigned m_derivedContextType : 2;
     unsigned m_evalContextType : 2;
     unsigned m_hasTailCalls : 1;
+    unsigned m_codeType : 2; // CodeType
+    unsigned m_didOptimize : 2; // TriState
     unsigned m_lineCount;
     unsigned m_endColumn;
 
+    VirtualRegister m_thisRegister;
+    VirtualRegister m_scopeRegister;
+    VirtualRegister m_globalObjectRegister;
+
+    SourceParseMode m_parseMode;
+
 public:
     ConcurrentJSLock m_lock;
 private:
-    TriState m_didOptimize;
-    SourceParseMode m_parseMode;
     CodeFeatures m_features;
-    CodeType m_codeType;
 
     Vector<unsigned> m_jumpTargets;
 

Modified: trunk/Source/_javascript_Core/bytecode/VirtualRegister.h (233628 => 233629)


--- trunk/Source/_javascript_Core/bytecode/VirtualRegister.h	2018-07-08 16:58:29 UTC (rev 233628)
+++ trunk/Source/_javascript_Core/bytecode/VirtualRegister.h	2018-07-08 17:39:55 UTC (rev 233629)
@@ -47,9 +47,7 @@
     friend VirtualRegister virtualRegisterForLocal(int);
     friend VirtualRegister virtualRegisterForArgument(int, int);
 
-    VirtualRegister()
-        : m_virtualRegister(s_invalidVirtualRegister)
-    { }
+    VirtualRegister() = default;
 
     explicit VirtualRegister(int virtualRegister)
         : m_virtualRegister(virtualRegister)
@@ -109,7 +107,7 @@
     static int operandToArgument(int operand) { return operand - CallFrame::thisArgumentOffset(); }
     static int argumentToOperand(int argument) { return argument + CallFrame::thisArgumentOffset(); }
 
-    int m_virtualRegister;
+    int m_virtualRegister { s_invalidVirtualRegister };
 };
 
 COMPILE_ASSERT(sizeof(VirtualRegister) == sizeof(int), VirtualRegister_is_32bit);

Modified: trunk/Source/WTF/ChangeLog (233628 => 233629)


--- trunk/Source/WTF/ChangeLog	2018-07-08 16:58:29 UTC (rev 233628)
+++ trunk/Source/WTF/ChangeLog	2018-07-08 17:39:55 UTC (rev 233629)
@@ -1,3 +1,12 @@
+2018-07-08  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Optimize padding of UnlinkedCodeBlock to shrink
+        https://bugs.webkit.org/show_bug.cgi?id=187448
+
+        Reviewed by Saam Barati.
+
+        * wtf/TriState.h:
+
 2018-07-07  David Kilzer  <[email protected]>
 
         iOS port should define HAVE_RUNLOOP_TIMER

Modified: trunk/Source/WTF/wtf/TriState.h (233628 => 233629)


--- trunk/Source/WTF/wtf/TriState.h	2018-07-08 16:58:29 UTC (rev 233628)
+++ trunk/Source/WTF/wtf/TriState.h	2018-07-08 17:39:55 UTC (rev 233629)
@@ -28,7 +28,8 @@
 
 namespace WTF {
 
-enum TriState {
+// TriState should be within 2 bits (0b00 - 0b10).
+enum TriState : uint8_t {
     FalseTriState,
     TrueTriState,
     MixedTriState
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to