Title: [241201] trunk/Source/_javascript_Core
Revision
241201
Author
[email protected]
Date
2019-02-08 11:18:14 -0800 (Fri, 08 Feb 2019)

Log Message

[JSC] SourceProviderCacheItem should be small
https://bugs.webkit.org/show_bug.cgi?id=194432

Reviewed by Saam Barati.

Some JetStream2 tests stress the JS parser. At that time, so many SourceProviderCacheItems are created.
While they are removed when full-GC happens, it significantly increases the peak memory usage.
This patch reduces the size of SourceProviderCacheItem from 56 to 32.

* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseFunctionInfo):
* parser/ParserModes.h:
* parser/ParserTokens.h:
* parser/SourceProviderCacheItem.h:
(JSC::SourceProviderCacheItem::endFunctionToken const):
(JSC::SourceProviderCacheItem::SourceProviderCacheItem):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (241200 => 241201)


--- trunk/Source/_javascript_Core/ChangeLog	2019-02-08 18:49:23 UTC (rev 241200)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-02-08 19:18:14 UTC (rev 241201)
@@ -1,3 +1,22 @@
+2019-02-08  Yusuke Suzuki  <[email protected]>
+
+        [JSC] SourceProviderCacheItem should be small
+        https://bugs.webkit.org/show_bug.cgi?id=194432
+
+        Reviewed by Saam Barati.
+
+        Some JetStream2 tests stress the JS parser. At that time, so many SourceProviderCacheItems are created.
+        While they are removed when full-GC happens, it significantly increases the peak memory usage.
+        This patch reduces the size of SourceProviderCacheItem from 56 to 32.
+
+        * parser/Parser.cpp:
+        (JSC::Parser<LexerType>::parseFunctionInfo):
+        * parser/ParserModes.h:
+        * parser/ParserTokens.h:
+        * parser/SourceProviderCacheItem.h:
+        (JSC::SourceProviderCacheItem::endFunctionToken const):
+        (JSC::SourceProviderCacheItem::SourceProviderCacheItem):
+
 2019-02-07  Robin Morisset  <[email protected]>
 
         Fix Abs(Neg(x)) -> Abs(x) optimization in B3ReduceStrength

Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (241200 => 241201)


--- trunk/Source/_javascript_Core/parser/Parser.cpp	2019-02-08 18:49:23 UTC (rev 241200)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp	2019-02-08 19:18:14 UTC (rev 241201)
@@ -2598,7 +2598,6 @@
     if (TreeBuilder::CanUseFunctionCache && m_functionCache && sourceLength > minimumSourceLengthToCache) {
         SourceProviderCacheItemCreationParameters parameters;
         parameters.endFunctionOffset = functionInfo.endOffset;
-        parameters.functionNameStart = functionNameStart;
         parameters.lastTokenLine = location.line;
         parameters.lastTokenStartOffset = location.startOffset;
         parameters.lastTokenEndOffset = location.endOffset;

Modified: trunk/Source/_javascript_Core/parser/ParserModes.h (241200 => 241201)


--- trunk/Source/_javascript_Core/parser/ParserModes.h	2019-02-08 18:49:23 UTC (rev 241200)
+++ trunk/Source/_javascript_Core/parser/ParserModes.h	2019-02-08 19:18:14 UTC (rev 241201)
@@ -328,4 +328,5 @@
 const InnerArrowFunctionCodeFeatures NewTargetInnerArrowFunctionFeature =     1 << 5;
     
 const InnerArrowFunctionCodeFeatures AllInnerArrowFunctionCodeFeatures = EvalInnerArrowFunctionFeature | ArgumentsInnerArrowFunctionFeature | ThisInnerArrowFunctionFeature | SuperCallInnerArrowFunctionFeature | SuperPropertyInnerArrowFunctionFeature | NewTargetInnerArrowFunctionFeature;
+static_assert(AllInnerArrowFunctionCodeFeatures <= 0b111111, "InnerArrowFunctionCodeFeatures must be 6bits");
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/parser/ParserTokens.h (241200 => 241201)


--- trunk/Source/_javascript_Core/parser/ParserTokens.h	2019-02-08 18:49:23 UTC (rev 241200)
+++ trunk/Source/_javascript_Core/parser/ParserTokens.h	2019-02-08 19:18:14 UTC (rev 241201)
@@ -41,6 +41,8 @@
     // P = binary operator precedence
     // K = keyword flag
     // U = unary operator flag
+    //
+    // We must keep the upper 8bit (1byte) region empty. JSTokenType must be 24bits.
     UnaryOpTokenFlag = 128,
     KeywordTokenFlag = 256,
     BinaryOpTokenPrecedenceShift = 9,
@@ -189,6 +191,7 @@
     INVALID_TEMPLATE_LITERAL_ERRORTOK = 15 | ErrorTokenFlag,
     UNEXPECTED_ESCAPE_ERRORTOK = 16 | ErrorTokenFlag,
 };
+static_assert(static_cast<unsigned>(POW) <= 0x00ffffffU, "JSTokenType must be 24bits.");
 
 struct JSTextPosition {
     JSTextPosition() = default;

Modified: trunk/Source/_javascript_Core/parser/SourceProviderCacheItem.h (241200 => 241201)


--- trunk/Source/_javascript_Core/parser/SourceProviderCacheItem.h	2019-02-08 18:49:23 UTC (rev 241200)
+++ trunk/Source/_javascript_Core/parser/SourceProviderCacheItem.h	2019-02-08 19:18:14 UTC (rev 241201)
@@ -34,7 +34,6 @@
 namespace JSC {
 
 struct SourceProviderCacheItemCreationParameters {
-    unsigned functionNameStart;
     unsigned lastTokenLine;
     unsigned lastTokenStartOffset;
     unsigned lastTokenEndOffset;
@@ -41,7 +40,6 @@
     unsigned lastTokenLineStartOffset;
     unsigned endFunctionOffset;
     unsigned parameterCount;
-    unsigned functionLength;
     bool needsFullActivation;
     bool usesEval;
     bool strictMode;
@@ -68,7 +66,7 @@
     JSToken endFunctionToken() const 
     {
         JSToken token;
-        token.m_type = isBodyArrowExpression ? tokenType : CLOSEBRACE;
+        token.m_type = isBodyArrowExpression ? static_cast<JSTokenType>(tokenType) : CLOSEBRACE;
         token.m_data.offset = lastTokenStartOffset;
         token.m_location.startOffset = lastTokenStartOffset;
         token.m_location.endOffset = lastTokenEndOffset;
@@ -79,7 +77,6 @@
         return token;
     }
 
-    unsigned functionNameStart : 31;
     bool needsFullActivation : 1;
     unsigned endFunctionOffset : 31;
     bool usesEval : 1;
@@ -86,17 +83,16 @@
     unsigned lastTokenLine : 31;
     bool strictMode : 1;
     unsigned lastTokenStartOffset : 31;
+    unsigned expectedSuperBinding : 1; // SuperBinding
     unsigned lastTokenEndOffset: 31;
-    unsigned constructorKind : 2; // ConstructorKind
+    bool needsSuperBinding: 1;
     unsigned parameterCount : 31;
-    unsigned expectedSuperBinding : 1; // SuperBinding
-    bool needsSuperBinding: 1;
-    unsigned functionLength;
-    unsigned lastTokenLineStartOffset;
+    unsigned lastTokenLineStartOffset : 31;
+    bool isBodyArrowExpression : 1;
     unsigned usedVariablesCount;
-    InnerArrowFunctionCodeFeatures innerArrowFunctionFeatures;
-    bool isBodyArrowExpression;
-    JSTokenType tokenType;
+    unsigned tokenType : 24; // JSTokenType
+    unsigned innerArrowFunctionFeatures : 6; // InnerArrowFunctionCodeFeatures
+    unsigned constructorKind : 2; // ConstructorKind
 
     UniquedStringImpl** usedVariables() const { return const_cast<UniquedStringImpl**>(m_variables); }
 
@@ -121,25 +117,27 @@
 }
 
 inline SourceProviderCacheItem::SourceProviderCacheItem(const SourceProviderCacheItemCreationParameters& parameters)
-    : functionNameStart(parameters.functionNameStart)
-    , needsFullActivation(parameters.needsFullActivation)
+    : needsFullActivation(parameters.needsFullActivation)
     , endFunctionOffset(parameters.endFunctionOffset)
     , usesEval(parameters.usesEval)
     , lastTokenLine(parameters.lastTokenLine)
     , strictMode(parameters.strictMode)
     , lastTokenStartOffset(parameters.lastTokenStartOffset)
+    , expectedSuperBinding(static_cast<unsigned>(parameters.expectedSuperBinding))
     , lastTokenEndOffset(parameters.lastTokenEndOffset)
-    , constructorKind(static_cast<unsigned>(parameters.constructorKind))
+    , needsSuperBinding(parameters.needsSuperBinding)
     , parameterCount(parameters.parameterCount)
-    , expectedSuperBinding(static_cast<unsigned>(parameters.expectedSuperBinding))
-    , needsSuperBinding(parameters.needsSuperBinding)
-    , functionLength(parameters.functionLength)
     , lastTokenLineStartOffset(parameters.lastTokenLineStartOffset)
+    , isBodyArrowExpression(parameters.isBodyArrowExpression)
     , usedVariablesCount(parameters.usedVariables.size())
-    , innerArrowFunctionFeatures(parameters.innerArrowFunctionFeatures)
-    , isBodyArrowExpression(parameters.isBodyArrowExpression)
-    , tokenType(parameters.tokenType)
+    , tokenType(static_cast<unsigned>(parameters.tokenType))
+    , innerArrowFunctionFeatures(static_cast<unsigned>(parameters.innerArrowFunctionFeatures))
+    , constructorKind(static_cast<unsigned>(parameters.constructorKind))
 {
+    ASSERT(tokenType == static_cast<unsigned>(parameters.tokenType));
+    ASSERT(innerArrowFunctionFeatures == static_cast<unsigned>(parameters.innerArrowFunctionFeatures));
+    ASSERT(constructorKind == static_cast<unsigned>(parameters.constructorKind));
+    ASSERT(expectedSuperBinding == static_cast<unsigned>(parameters.expectedSuperBinding));
     for (unsigned i = 0; i < usedVariablesCount; ++i) {
         m_variables[i] = parameters.usedVariables[i];
         m_variables[i]->ref();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to