Title: [221528] trunk
Revision
221528
Author
[email protected]
Date
2017-09-02 01:35:46 -0700 (Sat, 02 Sep 2017)

Log Message

[DFG] Relax arity requirement
https://bugs.webkit.org/show_bug.cgi?id=175523

Reviewed by Saam Barati.

JSTests:

* stress/arity-mismatch-arguments-length.js: Added.
(shouldBe):
(test1):
(test):
* stress/arity-mismatch-get-argument.js: Added.
(shouldBe):
(builtin.createBuiltin):
(test):
* stress/arity-mismatch-inlining-extra-slots.js: Added.
(shouldBe):
(inlineTarget):
(test):
* stress/arity-mismatch-inlining.js: Added.
(shouldBe):
(inlineTarget):
(test):
* stress/arity-mismatch-rest.js: Added.
(shouldBe):
(test2):
(test1):
(test):

Source/_javascript_Core:

Our DFG pipeline gives up inlining when the arity of the target function is more than the number of the arguments.
It effectively prevents us from inlining and optimizing functions, which takes some optional arguments in the form
of the pre-ES6.

This patch removes the above restriction by performing the arity fixup in DFG.

SixSpeed shows improvement when we can inline arity-mismatched functions. (For example, calling generator.next()).

                               baseline                  patched

defaults.es5             1232.1226+-20.6775    ^    442.3326+-26.1883       ^ definitely 2.7855x faster
rest.es6                    5.3406+-0.8588     ^      3.5812+-0.5388        ^ definitely 1.4913x faster
spread-generator.es6      320.9107+-12.4808         310.4295+-12.0047         might be 1.0338x faster
generator.es6             318.3514+-9.6023     ^    286.4974+-12.6203       ^ definitely 1.1112x faster

* bytecode/InlineCallFrame.cpp:
(JSC::InlineCallFrame::dumpInContext const):
* bytecode/InlineCallFrame.h:
(JSC::InlineCallFrame::InlineCallFrame):
* dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* dfg/DFGArgumentsEliminationPhase.cpp:
* dfg/DFGArgumentsUtilities.cpp:
(JSC::DFG::argumentsInvolveStackSlot):
(JSC::DFG::emitCodeToGetArgumentsArrayLength):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::setLocal):
(JSC::DFG::ByteCodeParser::setArgument):
(JSC::DFG::ByteCodeParser::findArgumentPositionForLocal):
(JSC::DFG::ByteCodeParser::flush):
(JSC::DFG::ByteCodeParser::getArgumentCount):
(JSC::DFG::ByteCodeParser::inliningCost):
(JSC::DFG::ByteCodeParser::inlineCall):
(JSC::DFG::ByteCodeParser::attemptToInlineCall):
(JSC::DFG::ByteCodeParser::parseBlock):
(JSC::DFG::ByteCodeParser::InlineStackEntry::InlineStackEntry):
* dfg/DFGCommonData.cpp:
(JSC::DFG::CommonData::validateReferences):
* dfg/DFGConstantFoldingPhase.cpp:
(JSC::DFG::ConstantFoldingPhase::foldConstants):
* dfg/DFGGraph.cpp:
(JSC::DFG::Graph::isLiveInBytecode):
* dfg/DFGGraph.h:
(JSC::DFG::Graph::forAllLocalsLiveInBytecode):
* dfg/DFGOSRAvailabilityAnalysisPhase.cpp:
(JSC::DFG::LocalOSRAvailabilityCalculator::executeNode):
* dfg/DFGOSRExit.cpp:
(JSC::DFG::OSRExit::emitRestoreArguments):
* dfg/DFGOSRExitCompilerCommon.cpp:
(JSC::DFG::reifyInlinedCallFrames):
* dfg/DFGPreciseLocalClobberize.h:
(JSC::DFG::PreciseLocalClobberizeAdaptor::readTop):
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::emitGetLength):
(JSC::DFG::SpeculativeJIT::compileCreateDirectArguments):
* dfg/DFGStackLayoutPhase.cpp:
(JSC::DFG::StackLayoutPhase::run):
* ftl/FTLCompile.cpp:
(JSC::FTL::compile):
* ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileGetMyArgumentByVal):
(JSC::FTL::DFG::LowerDFGToB3::getArgumentsLength):
* ftl/FTLOperations.cpp:
(JSC::FTL::operationMaterializeObjectInOSR):
* interpreter/StackVisitor.cpp:
(JSC::StackVisitor::readInlinedFrame):
* jit/AssemblyHelpers.h:
(JSC::AssemblyHelpers::argumentsStart):
* jit/SetupVarargsFrame.cpp:
(JSC::emitSetupVarargsFrameFastCase):
* runtime/ClonedArguments.cpp:
(JSC::ClonedArguments::createWithInlineFrame):
* runtime/CommonSlowPaths.h:
(JSC::CommonSlowPaths::numberOfExtraSlots):
(JSC::CommonSlowPaths::numberOfStackPaddingSlots):
(JSC::CommonSlowPaths::numberOfStackPaddingSlotsWithExtraSlots):
(JSC::CommonSlowPaths::arityCheckFor):
* runtime/StackAlignment.h:
(JSC::stackAlignmentBytes):
(JSC::stackAlignmentRegisters):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (221527 => 221528)


--- trunk/JSTests/ChangeLog	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/JSTests/ChangeLog	2017-09-02 08:35:46 UTC (rev 221528)
@@ -1,3 +1,32 @@
+2017-09-02  Yusuke Suzuki  <[email protected]>
+
+        [DFG] Relax arity requirement
+        https://bugs.webkit.org/show_bug.cgi?id=175523
+
+        Reviewed by Saam Barati.
+
+        * stress/arity-mismatch-arguments-length.js: Added.
+        (shouldBe):
+        (test1):
+        (test):
+        * stress/arity-mismatch-get-argument.js: Added.
+        (shouldBe):
+        (builtin.createBuiltin):
+        (test):
+        * stress/arity-mismatch-inlining-extra-slots.js: Added.
+        (shouldBe):
+        (inlineTarget):
+        (test):
+        * stress/arity-mismatch-inlining.js: Added.
+        (shouldBe):
+        (inlineTarget):
+        (test):
+        * stress/arity-mismatch-rest.js: Added.
+        (shouldBe):
+        (test2):
+        (test1):
+        (test):
+
 2017-08-31  Yusuke Suzuki  <[email protected]>
 
         [JSC] Fix "name" and "length" of Proxy revoke function

Added: trunk/JSTests/stress/arity-mismatch-arguments-length.js (0 => 221528)


--- trunk/JSTests/stress/arity-mismatch-arguments-length.js	                        (rev 0)
+++ trunk/JSTests/stress/arity-mismatch-arguments-length.js	2017-09-02 08:35:46 UTC (rev 221528)
@@ -0,0 +1,50 @@
+function shouldBe(actual, expected)
+{
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+(function () {
+    function test1(arg1, arg2, arg3)
+    {
+        return arguments.length;
+    }
+
+    function test()
+    {
+        shouldBe(test1(), 0);
+        shouldBe(test1(0), 1);
+        shouldBe(test1(0, 1), 2);
+        shouldBe(test1(0, 1, 2), 3);
+        shouldBe(test1(0, 1, 2, 3), 4);
+    }
+    noInline(test);
+
+    for (var i = 0; i < 1e4; ++i)
+        test();
+}());
+
+(function () {
+    function test1(flag, arg1, arg2, arg3)
+    {
+        if (flag)
+            OSRExit();
+        return arguments;
+    }
+
+    function test(flag)
+    {
+        shouldBe(test1(flag).length, 1);
+        shouldBe(test1(flag, 0).length, 2);
+        shouldBe(test1(flag, 0, 1).length, 3);
+        shouldBe(test1(flag, 0, 1, 2).length, 4);
+        shouldBe(test1(flag, 0, 1, 2, 3).length, 5);
+    }
+    noInline(test);
+    for (var i = 0; i < 1e5; ++i)
+        test(false);
+
+    test(true);
+    test(true);
+    test(true);
+}());

Added: trunk/JSTests/stress/arity-mismatch-get-argument.js (0 => 221528)


--- trunk/JSTests/stress/arity-mismatch-get-argument.js	                        (rev 0)
+++ trunk/JSTests/stress/arity-mismatch-get-argument.js	2017-09-02 08:35:46 UTC (rev 221528)
@@ -0,0 +1,21 @@
+function shouldBe(actual, expected)
+{
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+var builtin = createBuiltin(`(function () {
+    return @argument(0);
+})`);
+
+function test()
+{
+    var result = builtin();
+    shouldBe(result, undefined);
+    var result = builtin(42);
+    shouldBe(result, 42);
+}
+noInline(test);
+
+for (var i = 0; i < 1e4; ++i)
+    test();

Added: trunk/JSTests/stress/arity-mismatch-inlining-extra-slots.js (0 => 221528)


--- trunk/JSTests/stress/arity-mismatch-inlining-extra-slots.js	                        (rev 0)
+++ trunk/JSTests/stress/arity-mismatch-inlining-extra-slots.js	2017-09-02 08:35:46 UTC (rev 221528)
@@ -0,0 +1,17 @@
+function shouldBe(actual, expected)
+{
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+function inlineTarget(arg1, arg2)
+{
+    return [arg1, arg2];
+}
+
+function test() {
+    shouldBe(JSON.stringify(inlineTarget(null)), `[null,null]`);
+}
+noInline(test);
+for (var i = 0; i < 3e4; ++i)
+    test();

Added: trunk/JSTests/stress/arity-mismatch-inlining.js (0 => 221528)


--- trunk/JSTests/stress/arity-mismatch-inlining.js	                        (rev 0)
+++ trunk/JSTests/stress/arity-mismatch-inlining.js	2017-09-02 08:35:46 UTC (rev 221528)
@@ -0,0 +1,24 @@
+function shouldBe(actual, expected)
+{
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+function inlineTarget(arg1, arg2, arg3, arg4, arg5)
+{
+    return [arg1, arg2, arg3, arg4, arg5];
+}
+
+function test() {
+    shouldBe(JSON.stringify(inlineTarget()), `[null,null,null,null,null]`);
+    shouldBe(JSON.stringify(inlineTarget(42)), `[42,null,null,null,null]`);
+    shouldBe(JSON.stringify(inlineTarget(42, 43)), `[42,43,null,null,null]`);
+    shouldBe(JSON.stringify(inlineTarget(42, 43, 44)), `[42,43,44,null,null]`);
+    shouldBe(JSON.stringify(inlineTarget(42, 43, 44, 45)), `[42,43,44,45,null]`);
+    shouldBe(JSON.stringify(inlineTarget(42, 43, 44, 45, 46)), `[42,43,44,45,46]`);
+    shouldBe(JSON.stringify(inlineTarget(42, 43, 44, 45, 46, 47)), `[42,43,44,45,46]`);
+    shouldBe(JSON.stringify(inlineTarget(42, 43, 44, 45, 46, 47, 48)), `[42,43,44,45,46]`);
+}
+noInline(test);
+for (var i = 0; i < 3e4; ++i)
+    test();

Added: trunk/JSTests/stress/arity-mismatch-rest.js (0 => 221528)


--- trunk/JSTests/stress/arity-mismatch-rest.js	                        (rev 0)
+++ trunk/JSTests/stress/arity-mismatch-rest.js	2017-09-02 08:35:46 UTC (rev 221528)
@@ -0,0 +1,65 @@
+function shouldBe(actual, expected)
+{
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+(function () {
+    function test2(...rest)
+    {
+        return rest;
+    }
+
+    function test1(arg1, arg2, arg3)
+    {
+        return test2(arg1, arg2, arg3);
+    }
+
+    function test()
+    {
+        var result = test1();
+        shouldBe(result.length, 3);
+        shouldBe(result[0], undefined);
+        shouldBe(result[1], undefined);
+        shouldBe(result[2], undefined);
+    }
+    noInline(test);
+
+    for (var i = 0; i < 1e4; ++i)
+        test();
+}());
+
+(function () {
+    function test1(...rest)
+    {
+        return rest;
+    }
+
+    function test()
+    {
+        var result = test1();
+        shouldBe(result.length, 0);
+    }
+    noInline(test);
+
+    for (var i = 0; i < 1e4; ++i)
+        test();
+}());
+
+(function () {
+    function test1(...rest)
+    {
+        return rest;
+    }
+    noInline(test1);
+
+    function test()
+    {
+        var result = test1();
+        shouldBe(result.length, 0);
+    }
+    noInline(test);
+
+    for (var i = 0; i < 1e4; ++i)
+        test();
+}());

Modified: trunk/Source/_javascript_Core/ChangeLog (221527 => 221528)


--- trunk/Source/_javascript_Core/ChangeLog	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-09-02 08:35:46 UTC (rev 221528)
@@ -1,3 +1,91 @@
+2017-09-02  Yusuke Suzuki  <[email protected]>
+
+        [DFG] Relax arity requirement
+        https://bugs.webkit.org/show_bug.cgi?id=175523
+
+        Reviewed by Saam Barati.
+
+        Our DFG pipeline gives up inlining when the arity of the target function is more than the number of the arguments.
+        It effectively prevents us from inlining and optimizing functions, which takes some optional arguments in the form
+        of the pre-ES6.
+
+        This patch removes the above restriction by performing the arity fixup in DFG.
+
+        SixSpeed shows improvement when we can inline arity-mismatched functions. (For example, calling generator.next()).
+
+                                       baseline                  patched
+
+        defaults.es5             1232.1226+-20.6775    ^    442.3326+-26.1883       ^ definitely 2.7855x faster
+        rest.es6                    5.3406+-0.8588     ^      3.5812+-0.5388        ^ definitely 1.4913x faster
+        spread-generator.es6      320.9107+-12.4808         310.4295+-12.0047         might be 1.0338x faster
+        generator.es6             318.3514+-9.6023     ^    286.4974+-12.6203       ^ definitely 1.1112x faster
+
+        * bytecode/InlineCallFrame.cpp:
+        (JSC::InlineCallFrame::dumpInContext const):
+        * bytecode/InlineCallFrame.h:
+        (JSC::InlineCallFrame::InlineCallFrame):
+        * dfg/DFGAbstractInterpreterInlines.h:
+        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
+        * dfg/DFGArgumentsEliminationPhase.cpp:
+        * dfg/DFGArgumentsUtilities.cpp:
+        (JSC::DFG::argumentsInvolveStackSlot):
+        (JSC::DFG::emitCodeToGetArgumentsArrayLength):
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::setLocal):
+        (JSC::DFG::ByteCodeParser::setArgument):
+        (JSC::DFG::ByteCodeParser::findArgumentPositionForLocal):
+        (JSC::DFG::ByteCodeParser::flush):
+        (JSC::DFG::ByteCodeParser::getArgumentCount):
+        (JSC::DFG::ByteCodeParser::inliningCost):
+        (JSC::DFG::ByteCodeParser::inlineCall):
+        (JSC::DFG::ByteCodeParser::attemptToInlineCall):
+        (JSC::DFG::ByteCodeParser::parseBlock):
+        (JSC::DFG::ByteCodeParser::InlineStackEntry::InlineStackEntry):
+        * dfg/DFGCommonData.cpp:
+        (JSC::DFG::CommonData::validateReferences):
+        * dfg/DFGConstantFoldingPhase.cpp:
+        (JSC::DFG::ConstantFoldingPhase::foldConstants):
+        * dfg/DFGGraph.cpp:
+        (JSC::DFG::Graph::isLiveInBytecode):
+        * dfg/DFGGraph.h:
+        (JSC::DFG::Graph::forAllLocalsLiveInBytecode):
+        * dfg/DFGOSRAvailabilityAnalysisPhase.cpp:
+        (JSC::DFG::LocalOSRAvailabilityCalculator::executeNode):
+        * dfg/DFGOSRExit.cpp:
+        (JSC::DFG::OSRExit::emitRestoreArguments):
+        * dfg/DFGOSRExitCompilerCommon.cpp:
+        (JSC::DFG::reifyInlinedCallFrames):
+        * dfg/DFGPreciseLocalClobberize.h:
+        (JSC::DFG::PreciseLocalClobberizeAdaptor::readTop):
+        * dfg/DFGSpeculativeJIT.cpp:
+        (JSC::DFG::SpeculativeJIT::emitGetLength):
+        (JSC::DFG::SpeculativeJIT::compileCreateDirectArguments):
+        * dfg/DFGStackLayoutPhase.cpp:
+        (JSC::DFG::StackLayoutPhase::run):
+        * ftl/FTLCompile.cpp:
+        (JSC::FTL::compile):
+        * ftl/FTLLowerDFGToB3.cpp:
+        (JSC::FTL::DFG::LowerDFGToB3::compileGetMyArgumentByVal):
+        (JSC::FTL::DFG::LowerDFGToB3::getArgumentsLength):
+        * ftl/FTLOperations.cpp:
+        (JSC::FTL::operationMaterializeObjectInOSR):
+        * interpreter/StackVisitor.cpp:
+        (JSC::StackVisitor::readInlinedFrame):
+        * jit/AssemblyHelpers.h:
+        (JSC::AssemblyHelpers::argumentsStart):
+        * jit/SetupVarargsFrame.cpp:
+        (JSC::emitSetupVarargsFrameFastCase):
+        * runtime/ClonedArguments.cpp:
+        (JSC::ClonedArguments::createWithInlineFrame):
+        * runtime/CommonSlowPaths.h:
+        (JSC::CommonSlowPaths::numberOfExtraSlots):
+        (JSC::CommonSlowPaths::numberOfStackPaddingSlots):
+        (JSC::CommonSlowPaths::numberOfStackPaddingSlotsWithExtraSlots):
+        (JSC::CommonSlowPaths::arityCheckFor):
+        * runtime/StackAlignment.h:
+        (JSC::stackAlignmentBytes):
+        (JSC::stackAlignmentRegisters):
+
 2017-09-01  Yusuke Suzuki  <[email protected]>
 
         [FTL] FTL allocation for async Function is incorrect

Modified: trunk/Source/_javascript_Core/bytecode/InlineCallFrame.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/bytecode/InlineCallFrame.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/bytecode/InlineCallFrame.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -74,7 +74,8 @@
         out.print(", closure call");
     else
         out.print(", known callee: ", inContext(calleeRecovery.constant(), context));
-    out.print(", numArgs+this = ", arguments.size());
+    out.print(", numArgs+this = ", argumentCountIncludingThis);
+    out.print(", numFixup = ", argumentsWithFixup.size() - argumentCountIncludingThis);
     out.print(", stackOffset = ", stackOffset);
     out.print(" (", virtualRegisterForLocal(0), " maps to ", virtualRegisterForLocal(0) + stackOffset, ")>");
 }

Modified: trunk/Source/_javascript_Core/bytecode/InlineCallFrame.h (221527 => 221528)


--- trunk/Source/_javascript_Core/bytecode/InlineCallFrame.h	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/bytecode/InlineCallFrame.h	2017-09-02 08:35:46 UTC (rev 221528)
@@ -175,11 +175,12 @@
         return caller ? caller->inlineCallFrame : nullptr;
     }
     
-    Vector<ValueRecovery> arguments; // Includes 'this'.
+    Vector<ValueRecovery> argumentsWithFixup; // Includes 'this' and arity fixups.
     WriteBarrier<CodeBlock> baselineCodeBlock;
     ValueRecovery calleeRecovery;
     CodeOrigin directCaller;
 
+    unsigned argumentCountIncludingThis; // Do not include fixups.
     signed stackOffset : 28;
     unsigned kind : 3; // real type is Kind
     bool isClosureCall : 1; // If false then we know that callee/scope are constants and the DFG won't treat them as variables, i.e. they have to be recovered manually.
@@ -189,7 +190,8 @@
     // InlineCallFrame's fields. This constructor is here just to reduce confusion if
     // we forgot to initialize explicitly.
     InlineCallFrame()
-        : stackOffset(0)
+        : argumentCountIncludingThis(0)
+        , stackOffset(0)
         , kind(Call)
         , isClosureCall(false)
     {

Modified: trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2017-09-02 08:35:46 UTC (rev 221528)
@@ -1758,7 +1758,7 @@
             
             unsigned argumentIndex = index.asUInt32() + node->numberOfArgumentsToSkip();
             if (inlineCallFrame) {
-                if (argumentIndex < inlineCallFrame->arguments.size() - 1) {
+                if (argumentIndex < inlineCallFrame->argumentCountIncludingThis - 1) {
                     forNode(node) = m_state.variables().operand(
                         virtualRegisterForArgument(argumentIndex + 1) + inlineCallFrame->stackOffset);
                     m_state.setFoundConstants(true);
@@ -1777,7 +1777,7 @@
             // We have a bound on the types even though it's random access. Take advantage of this.
             
             AbstractValue result;
-            for (unsigned i = 1 + node->numberOfArgumentsToSkip(); i < inlineCallFrame->arguments.size(); ++i) {
+            for (unsigned i = 1 + node->numberOfArgumentsToSkip(); i < inlineCallFrame->argumentCountIncludingThis; ++i) {
                 result.merge(
                     m_state.variables().operand(
                         virtualRegisterForArgument(i) + inlineCallFrame->stackOffset));

Modified: trunk/Source/_javascript_Core/dfg/DFGArgumentsEliminationPhase.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGArgumentsEliminationPhase.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGArgumentsEliminationPhase.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -490,7 +490,7 @@
                         }
                         
                         if (!isClobberedByBlock) {
-                            for (unsigned i = 0; i < inlineCallFrame->arguments.size() - 1; ++i) {
+                            for (unsigned i = 0; i < inlineCallFrame->argumentCountIncludingThis - 1; ++i) {
                                 VirtualRegister reg =
                                     VirtualRegister(inlineCallFrame->stackOffset) +
                                     CallFrame::argumentOffset(i);
@@ -700,7 +700,7 @@
                         
                         bool safeToGetStack;
                         if (inlineCallFrame)
-                            safeToGetStack = index < inlineCallFrame->arguments.size() - 1;
+                            safeToGetStack = index < inlineCallFrame->argumentCountIncludingThis - 1;
                         else {
                             safeToGetStack =
                                 index < static_cast<unsigned>(codeBlock()->numParameters()) - 1;
@@ -805,7 +805,7 @@
                                 ASSERT(spread->op() == PhantomSpread && spread->child1()->op() == PhantomCreateRest);
                                 unsigned numberOfArgumentsToSkip = spread->child1()->numberOfArgumentsToSkip();
                                 InlineCallFrame* inlineCallFrame = spread->child1()->origin.semantic.inlineCallFrame;
-                                unsigned frameArgumentCount = inlineCallFrame->arguments.size() - 1;
+                                unsigned frameArgumentCount = inlineCallFrame->argumentCountIncludingThis - 1;
                                 if (frameArgumentCount >= numberOfArgumentsToSkip)
                                     return frameArgumentCount - numberOfArgumentsToSkip;
                                 return 0;
@@ -834,7 +834,7 @@
                                     ASSERT(spread->op() == PhantomSpread && spread->child1()->op() == PhantomCreateRest);
                                     unsigned numberOfArgumentsToSkip = spread->child1()->numberOfArgumentsToSkip();
                                     InlineCallFrame* inlineCallFrame = spread->child1()->origin.semantic.inlineCallFrame;
-                                    unsigned frameArgumentCount = inlineCallFrame->arguments.size() - 1;
+                                    unsigned frameArgumentCount = inlineCallFrame->argumentCountIncludingThis - 1;
                                     for (unsigned loadIndex = numberOfArgumentsToSkip; loadIndex < frameArgumentCount; ++loadIndex) {
                                         VirtualRegister reg = virtualRegisterForArgument(loadIndex + 1) + inlineCallFrame->stackOffset;
                                         StackAccessData* data = "" FlushedJSValue);
@@ -887,7 +887,7 @@
                         if (inlineCallFrame
                             && !inlineCallFrame->isVarargs()) {
 
-                            unsigned argumentCountIncludingThis = inlineCallFrame->arguments.size();
+                            unsigned argumentCountIncludingThis = inlineCallFrame->argumentCountIncludingThis;
                             if (argumentCountIncludingThis > varargsData->offset)
                                 argumentCountIncludingThis -= varargsData->offset;
                             else
@@ -909,7 +909,7 @@
                                     Node* value = nullptr;
                                     unsigned loadIndex = storeIndex + varargsData->offset;
 
-                                    if (loadIndex + 1 < inlineCallFrame->arguments.size()) {
+                                    if (loadIndex + 1 < inlineCallFrame->argumentCountIncludingThis) {
                                         VirtualRegister reg = virtualRegisterForArgument(loadIndex + 1) + inlineCallFrame->stackOffset;
                                         StackAccessData* data = ""
                                             reg, FlushedJSValue);
@@ -1032,7 +1032,7 @@
                                 ASSERT(spread->child1()->op() == PhantomCreateRest);
                                 InlineCallFrame* inlineCallFrame = spread->child1()->origin.semantic.inlineCallFrame;
                                 unsigned numberOfArgumentsToSkip = spread->child1()->numberOfArgumentsToSkip();
-                                for (unsigned i = 1 + numberOfArgumentsToSkip; i < inlineCallFrame->arguments.size(); ++i) {
+                                for (unsigned i = 1 + numberOfArgumentsToSkip; i < inlineCallFrame->argumentCountIncludingThis; ++i) {
                                     StackAccessData* data = ""
                                         virtualRegisterForArgument(i) + inlineCallFrame->stackOffset,
                                         FlushedJSValue);
@@ -1069,7 +1069,7 @@
                         InlineCallFrame* inlineCallFrame = candidate->origin.semantic.inlineCallFrame;
                         if (inlineCallFrame && !inlineCallFrame->isVarargs()) {
                             Vector<Node*> arguments;
-                            for (unsigned i = 1 + varargsData->firstVarArgOffset; i < inlineCallFrame->arguments.size(); ++i) {
+                            for (unsigned i = 1 + varargsData->firstVarArgOffset; i < inlineCallFrame->argumentCountIncludingThis; ++i) {
                                 StackAccessData* data = ""
                                     virtualRegisterForArgument(i) + inlineCallFrame->stackOffset,
                                     FlushedJSValue);

Modified: trunk/Source/_javascript_Core/dfg/DFGArgumentsUtilities.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGArgumentsUtilities.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGArgumentsUtilities.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -45,7 +45,8 @@
         && reg == VirtualRegister(inlineCallFrame->stackOffset + CallFrameSlot::argumentCount))
         return true;
     
-    unsigned numArguments = inlineCallFrame->arguments.size() - 1;
+    // We do not include fixups here since it is not related to |arguments|, rest parameters, and varargs.
+    unsigned numArguments = inlineCallFrame->argumentCountIncludingThis - 1;
     VirtualRegister argumentStart =
         VirtualRegister(inlineCallFrame->stackOffset) + CallFrame::argumentOffset(0);
     return reg >= argumentStart && reg < argumentStart + numArguments;
@@ -74,7 +75,7 @@
         numberOfArgumentsToSkip = arguments->numberOfArgumentsToSkip();
     
     if (inlineCallFrame && !inlineCallFrame->isVarargs()) {
-        unsigned argumentsSize = inlineCallFrame->arguments.size() - 1;
+        unsigned argumentsSize = inlineCallFrame->argumentCountIncludingThis - 1;
         if (argumentsSize >= numberOfArgumentsToSkip)
             argumentsSize -= numberOfArgumentsToSkip;
         else

Modified: trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -35,6 +35,7 @@
 #include "CallLinkStatus.h"
 #include "CodeBlock.h"
 #include "CodeBlockWithJITType.h"
+#include "CommonSlowPaths.h"
 #include "DFGAbstractHeap.h"
 #include "DFGArrayMode.h"
 #include "DFGCFG.h"
@@ -62,6 +63,7 @@
 #include <wtf/CommaPrinter.h>
 #include <wtf/HashMap.h>
 #include <wtf/MathExtras.h>
+#include <wtf/SetForScope.h>
 #include <wtf/StdLibExtras.h>
 
 namespace JSC { namespace DFG {
@@ -220,7 +222,7 @@
     void emitFunctionChecks(CallVariant, Node* callTarget, VirtualRegister thisArgumnt);
     void emitArgumentPhantoms(int registerOffset, int argumentCountIncludingThis);
     Node* getArgumentCount();
-    unsigned inliningCost(CallVariant, int argumentCountIncludingThis, CallMode); // Return UINT_MAX if it's not an inlining candidate. By convention, intrinsics have a cost of 1.
+    unsigned inliningCost(CallVariant, int argumentCountIncludingThis, InlineCallFrame::Kind); // Return UINT_MAX if it's not an inlining candidate. By convention, intrinsics have a cost of 1.
     // Handle inlining. Return true if it succeeded, false if we need to plant a call.
     bool handleInlining(Node* callTargetNode, int resultOperand, const CallLinkStatus&, int registerOffset, VirtualRegister thisArgument, VirtualRegister argumentsArgument, unsigned argumentsOffset, int argumentCountIncludingThis, unsigned nextOffset, NodeType callOp, InlineCallFrame::Kind, SpeculatedType prediction);
     enum CallerLinkability { CallerDoesNormalLinking, CallerLinksManually };
@@ -470,8 +472,7 @@
     }
     Node* setLocal(const CodeOrigin& semanticOrigin, VirtualRegister operand, Node* value, SetMode setMode = NormalSet)
     {
-        CodeOrigin oldSemanticOrigin = m_currentSemanticOrigin;
-        m_currentSemanticOrigin = semanticOrigin;
+        SetForScope<CodeOrigin> originChange(m_currentSemanticOrigin, semanticOrigin);
 
         unsigned local = operand.toLocal();
         
@@ -490,8 +491,6 @@
             m_inlineStackTop->m_exitProfile.hasExitSite(semanticOrigin.bytecodeIndex, BadIndexingType));
         Node* node = addToGraph(SetLocal, OpInfo(variableAccessData), value);
         m_currentBlock->variablesAtTail.local(local) = node;
-
-        m_currentSemanticOrigin = oldSemanticOrigin;
         return node;
     }
 
@@ -525,8 +524,7 @@
     }
     Node* setArgument(const CodeOrigin& semanticOrigin, VirtualRegister operand, Node* value, SetMode setMode = NormalSet)
     {
-        CodeOrigin oldSemanticOrigin = m_currentSemanticOrigin;
-        m_currentSemanticOrigin = semanticOrigin;
+        SetForScope<CodeOrigin> originChange(m_currentSemanticOrigin, semanticOrigin);
 
         unsigned argument = operand.toArgument();
         ASSERT(argument < m_numArguments);
@@ -549,8 +547,6 @@
             m_inlineStackTop->m_exitProfile.hasExitSite(semanticOrigin.bytecodeIndex, BadIndexingType));
         Node* node = addToGraph(SetLocal, OpInfo(variableAccessData), value);
         m_currentBlock->variablesAtTail.argument(argument) = node;
-
-        m_currentSemanticOrigin = oldSemanticOrigin;
         return node;
     }
     
@@ -572,7 +568,7 @@
                 continue;
             if (operand.offset() == inlineCallFrame->stackOffset + CallFrame::thisArgumentOffset())
                 continue;
-            if (operand.offset() >= static_cast<int>(inlineCallFrame->stackOffset + CallFrame::thisArgumentOffset() + inlineCallFrame->arguments.size()))
+            if (operand.offset() >= static_cast<int>(inlineCallFrame->stackOffset + CallFrame::thisArgumentOffset() + inlineCallFrame->argumentsWithFixup.size()))
                 continue;
             int argument = VirtualRegister(operand.offset() - inlineCallFrame->stackOffset).toArgument();
             return stack->m_argumentPositions[argument];
@@ -632,7 +628,7 @@
         int numArguments;
         if (InlineCallFrame* inlineCallFrame = inlineStackEntry->m_inlineCallFrame) {
             ASSERT(!m_hasDebuggerEnabled);
-            numArguments = inlineCallFrame->arguments.size();
+            numArguments = inlineCallFrame->argumentsWithFixup.size();
             if (inlineCallFrame->isClosureCall)
                 flushDirect(inlineStackEntry->remapOperand(VirtualRegister(CallFrameSlot::callee)));
             if (inlineCallFrame->isVarargs())
@@ -1418,7 +1414,7 @@
         if (m_inlineStackTop->m_inlineCallFrame->isVarargs())
             argumentCount = get(VirtualRegister(CallFrameSlot::argumentCount));
         else
-            argumentCount = jsConstant(m_graph.freeze(jsNumber(m_inlineStackTop->m_inlineCallFrame->arguments.size()))->value());
+            argumentCount = jsConstant(m_graph.freeze(jsNumber(m_inlineStackTop->m_inlineCallFrame->argumentCountIncludingThis))->value());
     } else
         argumentCount = addToGraph(GetArgumentCountIncludingThis, OpInfo(0), OpInfo(SpecInt32Only));
     return argumentCount;
@@ -1430,9 +1426,10 @@
         addToGraph(Phantom, get(virtualRegisterForArgument(i, registerOffset)));
 }
 
-unsigned ByteCodeParser::inliningCost(CallVariant callee, int argumentCountIncludingThis, CallMode callMode)
+unsigned ByteCodeParser::inliningCost(CallVariant callee, int, InlineCallFrame::Kind kind)
 {
-    CodeSpecializationKind kind = specializationKindFor(callMode);
+    CallMode callMode = InlineCallFrame::callModeFor(kind);
+    CodeSpecializationKind specializationKind = specializationKindFor(callMode);
     if (verbose)
         dataLog("Considering inlining ", callee, " into ", currentCodeOrigin(), "\n");
     
@@ -1456,7 +1453,7 @@
     // to inline it if we had a static proof of what was being called; this might happen for example
     // if you call a global function, where watchpointing gives us static information. Overall,
     // it's a rare case because we expect that any hot callees would have already been compiled.
-    CodeBlock* codeBlock = executable->baselineCodeBlockFor(kind);
+    CodeBlock* codeBlock = executable->baselineCodeBlockFor(specializationKind);
     if (!codeBlock) {
         if (verbose)
             dataLog("    Failing because no code block available.\n");
@@ -1463,23 +1460,14 @@
         return UINT_MAX;
     }
 
-    // Does the number of arguments we're passing match the arity of the target? We currently
-    // inline only if the number of arguments passed is greater than or equal to the number
-    // arguments expected.
-    if (codeBlock->numParameters() > argumentCountIncludingThis) {
-        if (verbose)
-            dataLog("    Failing because of arity mismatch.\n");
-        return UINT_MAX;
-    }
-
     CapabilityLevel capabilityLevel = inlineFunctionForCapabilityLevel(
-        codeBlock, kind, callee.isClosureCall());
+        codeBlock, specializationKind, callee.isClosureCall());
     if (verbose) {
         dataLog("    Call mode: ", callMode, "\n");
         dataLog("    Is closure call: ", callee.isClosureCall(), "\n");
         dataLog("    Capability level: ", capabilityLevel, "\n");
-        dataLog("    Might inline function: ", mightInlineFunctionFor(codeBlock, kind), "\n");
-        dataLog("    Might compile function: ", mightCompileFunctionFor(codeBlock, kind), "\n");
+        dataLog("    Might inline function: ", mightInlineFunctionFor(codeBlock, specializationKind), "\n");
+        dataLog("    Might compile function: ", mightCompileFunctionFor(codeBlock, specializationKind), "\n");
         dataLog("    Is supported for inlining: ", isSupportedForInlining(codeBlock), "\n");
         dataLog("    Is inlining candidate: ", codeBlock->ownerScriptExecutable()->isInliningCandidate(), "\n");
     }
@@ -1545,14 +1533,27 @@
 {
     CodeSpecializationKind specializationKind = InlineCallFrame::specializationKindFor(kind);
     
-    ASSERT(inliningCost(callee, argumentCountIncludingThis, InlineCallFrame::callModeFor(kind)) != UINT_MAX);
+    ASSERT(inliningCost(callee, argumentCountIncludingThis, kind) != UINT_MAX);
     
     CodeBlock* codeBlock = callee.functionExecutable()->baselineCodeBlockFor(specializationKind);
     insertChecks(codeBlock);
 
     // FIXME: Don't flush constants!
+
+    // arityFixupCount and numberOfStackPaddingSlots are different. While arityFixupCount does not consider about stack alignment,
+    // numberOfStackPaddingSlots consider alignment. Consider the following case,
+    //
+    // before: [ ... ][arg0][header]
+    // after:  [ ... ][ext ][arg1][arg0][header]
+    //
+    // In the above case, arityFixupCount is 1. But numberOfStackPaddingSlots is 2 because the stack needs to be aligned.
+    // We insert extra slots to align stack.
+    int arityFixupCount = std::max<int>(codeBlock->numParameters() - argumentCountIncludingThis, 0);
+    int numberOfStackPaddingSlots = CommonSlowPaths::numberOfStackPaddingSlots(codeBlock, argumentCountIncludingThis);
+    ASSERT(!(numberOfStackPaddingSlots % stackAlignmentRegisters()));
+    int registerOffsetAfterFixup = registerOffset - numberOfStackPaddingSlots;
     
-    int inlineCallFrameStart = m_inlineStackTop->remapOperand(VirtualRegister(registerOffset)).offset() + CallFrame::headerSizeInRegisters;
+    int inlineCallFrameStart = m_inlineStackTop->remapOperand(VirtualRegister(registerOffsetAfterFixup)).offset() + CallFrame::headerSizeInRegisters;
     
     ensureLocals(
         VirtualRegister(inlineCallFrameStart).toLocal() + 1 +
@@ -1567,12 +1568,40 @@
     VariableAccessData* calleeVariable = nullptr;
     if (callee.isClosureCall()) {
         Node* calleeSet = set(
-            VirtualRegister(registerOffset + CallFrameSlot::callee), callTargetNode, ImmediateNakedSet);
+            VirtualRegister(registerOffsetAfterFixup + CallFrameSlot::callee), callTargetNode, ImmediateNakedSet);
         
         calleeVariable = calleeSet->variableAccessData();
         calleeVariable->mergeShouldNeverUnbox(true);
     }
     
+    if (arityFixupCount) {
+        Node* undefined = addToGraph(JSConstant, OpInfo(m_constantUndefined));
+        auto fill = [&] (VirtualRegister reg, Node* value) {
+            Node* result = set(reg, value, ImmediateNakedSet);
+            result->variableAccessData()->mergeShouldNeverUnbox(true); // We cannot exit after starting arity fixup.
+        };
+
+        // The stack needs to be aligned due to ABIs. Thus, we have a hole if the count of arguments is not aligned.
+        // We call this hole "extra slot". Consider the following case, the number of arguments is 2. If this argument
+        // count does not fulfill the stack alignment requirement, we already inserted extra slots.
+        //
+        // before: [ ... ][ext ][arg1][arg0][header]
+        //
+        // In the above case, one extra slot is inserted. If the code's parameter count is 3, we will fixup arguments.
+        // At that time, we can simply use this extra slots. So the fixuped stack is the following.
+        //
+        // before: [ ... ][ext ][arg1][arg0][header]
+        // after:  [ ... ][arg2][arg1][arg0][header]
+        //
+        // In such cases, we do not need to move frames.
+        if (registerOffsetAfterFixup != registerOffset) {
+            for (int index = 0; index < argumentCountIncludingThis; ++index)
+                fill(virtualRegisterForArgument(index, registerOffsetAfterFixup), get(virtualRegisterForArgument(index, registerOffset)));
+        }
+        for (int index = 0; index < arityFixupCount; ++index)
+            fill(virtualRegisterForArgument(argumentCountIncludingThis + index, registerOffsetAfterFixup), undefined);
+    }
+
     InlineStackEntry inlineStackEntry(
         this, codeBlock, codeBlock, m_graph.lastBlock(), callee.function(), resultReg,
         (VirtualRegister)inlineCallFrameStart, argumentCountIncludingThis, kind);
@@ -1771,7 +1800,7 @@
         }
     }
     
-    unsigned myInliningCost = inliningCost(callee, argumentCountIncludingThis, InlineCallFrame::callModeFor(kind));
+    unsigned myInliningCost = inliningCost(callee, argumentCountIncludingThis, kind);
     if (myInliningCost > inliningBalance)
         return false;
 
@@ -4348,7 +4377,7 @@
             InlineCallFrame* inlineCallFrame = this->inlineCallFrame();
             Node* length;
             if (inlineCallFrame && !inlineCallFrame->isVarargs()) {
-                unsigned argumentsLength = inlineCallFrame->arguments.size() - 1;
+                unsigned argumentsLength = inlineCallFrame->argumentCountIncludingThis - 1;
                 unsigned numParamsToSkip = currentInstruction[2].u.unsignedValue;
                 JSValue restLength;
                 if (argumentsLength <= numParamsToSkip)
@@ -5918,8 +5947,8 @@
             Node* argument;
             int32_t argumentIndexIncludingThis = currentInstruction[2].u.operand;
             if (inlineCallFrame && !inlineCallFrame->isVarargs()) {
-                int32_t argumentCountIncludingThis = inlineCallFrame->arguments.size();
-                if (argumentIndexIncludingThis < argumentCountIncludingThis)
+                int32_t argumentCountIncludingThisWithFixup = inlineCallFrame->argumentsWithFixup.size();
+                if (argumentIndexIncludingThis < argumentCountIncludingThisWithFixup)
                     argument = get(virtualRegisterForArgument(argumentIndexIncludingThis));
                 else
                     argument = addToGraph(JSConstant, OpInfo(m_constantUndefined));
@@ -6205,8 +6234,9 @@
         }
     }
     
-    m_argumentPositions.resize(argumentCountIncludingThis);
-    for (int i = 0; i < argumentCountIncludingThis; ++i) {
+    int argumentCountIncludingThisWithFixup = std::max<int>(argumentCountIncludingThis, codeBlock->numParameters());
+    m_argumentPositions.resize(argumentCountIncludingThisWithFixup);
+    for (int i = 0; i < argumentCountIncludingThisWithFixup; ++i) {
         byteCodeParser->m_graph.m_argumentPositions.append(ArgumentPosition());
         ArgumentPosition* argumentPosition = &byteCodeParser->m_graph.m_argumentPositions.last();
         m_argumentPositions[i] = argumentPosition;
@@ -6224,6 +6254,7 @@
         // plan finishes.
         m_inlineCallFrame->baselineCodeBlock.setWithoutWriteBarrier(codeBlock->baselineVersion());
         m_inlineCallFrame->setStackOffset(inlineCallFrameStart.offset() - CallFrame::headerSizeInRegisters);
+        m_inlineCallFrame->argumentCountIncludingThis = argumentCountIncludingThis;
         if (callee) {
             m_inlineCallFrame->calleeRecovery = ValueRecovery::constant(callee);
             m_inlineCallFrame->isClosureCall = false;
@@ -6230,7 +6261,7 @@
         } else
             m_inlineCallFrame->isClosureCall = true;
         m_inlineCallFrame->directCaller = byteCodeParser->currentCodeOrigin();
-        m_inlineCallFrame->arguments.resizeToFit(argumentCountIncludingThis); // Set the number of arguments including this, but don't configure the value recoveries, yet.
+        m_inlineCallFrame->argumentsWithFixup.resizeToFit(argumentCountIncludingThisWithFixup); // Set the number of arguments including this, but don't configure the value recoveries, yet.
         m_inlineCallFrame->kind = kind;
         
         m_identifierRemap.resize(codeBlock->numberOfIdentifiers());

Modified: trunk/Source/_javascript_Core/dfg/DFGCommonData.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGCommonData.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGCommonData.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -176,7 +176,7 @@
 {
     if (InlineCallFrameSet* set = inlineCallFrames.get()) {
         for (InlineCallFrame* inlineCallFrame : *set) {
-            for (ValueRecovery& recovery : inlineCallFrame->arguments) {
+            for (ValueRecovery& recovery : inlineCallFrame->argumentsWithFixup) {
                 if (recovery.isConstant())
                     trackedReferences.check(recovery.constant());
             }

Modified: trunk/Source/_javascript_Core/dfg/DFGConstantFoldingPhase.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGConstantFoldingPhase.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGConstantFoldingPhase.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -357,7 +357,7 @@
                 // GetMyArgumentByVal in such statically-out-of-bounds accesses; we just lose CFA unless
                 // GCSE removes the access entirely.
                 if (inlineCallFrame) {
-                    if (index >= inlineCallFrame->arguments.size() - 1)
+                    if (index >= inlineCallFrame->argumentCountIncludingThis - 1)
                         break;
                 } else {
                     if (index >= m_state.variables().numberOfArguments() - 1)
@@ -378,7 +378,7 @@
                         virtualRegisterForArgument(index + 1), FlushedJSValue);
                 }
                 
-                if (inlineCallFrame && !inlineCallFrame->isVarargs() && index < inlineCallFrame->arguments.size() - 1) {
+                if (inlineCallFrame && !inlineCallFrame->isVarargs() && index < inlineCallFrame->argumentCountIncludingThis - 1) {
                     node->convertToGetStack(data);
                     eliminated = true;
                     break;

Modified: trunk/Source/_javascript_Core/dfg/DFGGraph.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGGraph.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGGraph.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -1157,7 +1157,7 @@
         // Arguments are always live. This would be redundant if it wasn't for our
         // op_call_varargs inlining.
         if (reg.isArgument()
-            && static_cast<size_t>(reg.toArgument()) < inlineCallFrame->arguments.size()) {
+            && static_cast<size_t>(reg.toArgument()) < inlineCallFrame->argumentsWithFixup.size()) {
             if (verbose)
                 dataLog("Argument is live.\n");
             return true;

Modified: trunk/Source/_javascript_Core/dfg/DFGGraph.h (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGGraph.h	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGGraph.h	2017-09-02 08:35:46 UTC (rev 221528)
@@ -839,7 +839,7 @@
             // Arguments are always live. This would be redundant if it wasn't for our
             // op_call_varargs inlining. See the comment above.
             exclusionStart = stackOffset + CallFrame::argumentOffsetIncludingThis(0);
-            exclusionEnd = stackOffset + CallFrame::argumentOffsetIncludingThis(inlineCallFrame->arguments.size());
+            exclusionEnd = stackOffset + CallFrame::argumentOffsetIncludingThis(inlineCallFrame->argumentsWithFixup.size());
             
             // We will always have a "this" argument and exclusionStart should be a smaller stack
             // offset than exclusionEnd.

Modified: trunk/Source/_javascript_Core/dfg/DFGOSRAvailabilityAnalysisPhase.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGOSRAvailabilityAnalysisPhase.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGOSRAvailabilityAnalysisPhase.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -240,7 +240,7 @@
             m_availability.m_heap.set(PromotedHeapLocation(ArgumentsCalleePLoc, node), callee);
         }
         
-        for (unsigned i = numberOfArgumentsToSkip; i < inlineCallFrame->arguments.size() - 1; ++i) {
+        for (unsigned i = numberOfArgumentsToSkip; i < inlineCallFrame->argumentCountIncludingThis - 1; ++i) {
             Availability argument = m_availability.m_locals.operand(
                 inlineCallFrame->stackOffset + CallFrame::argumentOffset(i));
             

Modified: trunk/Source/_javascript_Core/dfg/DFGOSRExit.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGOSRExit.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGOSRExit.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -123,7 +123,7 @@
                 GPRInfo::regT1);
         } else {
             jit.move(
-                AssemblyHelpers::TrustedImm32(inlineCallFrame->arguments.size()),
+                AssemblyHelpers::TrustedImm32(inlineCallFrame->argumentCountIncludingThis),
                 GPRInfo::regT1);
         }
 

Modified: trunk/Source/_javascript_Core/dfg/DFGOSRExitCompilerCommon.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGOSRExitCompilerCommon.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGOSRExitCompilerCommon.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -222,7 +222,7 @@
             GPRInfo::regT2);
 
         if (!inlineCallFrame->isVarargs())
-            jit.store32(AssemblyHelpers::TrustedImm32(inlineCallFrame->arguments.size()), AssemblyHelpers::payloadFor((VirtualRegister)(inlineCallFrame->stackOffset + CallFrameSlot::argumentCount)));
+            jit.store32(AssemblyHelpers::TrustedImm32(inlineCallFrame->argumentCountIncludingThis), AssemblyHelpers::payloadFor((VirtualRegister)(inlineCallFrame->stackOffset + CallFrameSlot::argumentCount)));
 #if USE(JSVALUE64)
         jit.store64(callerFrameGPR, AssemblyHelpers::addressForByteOffset(inlineCallFrame->callerFrameOffset()));
         uint32_t locationBits = CallSiteIndex(codeOrigin->bytecodeIndex).bits();

Modified: trunk/Source/_javascript_Core/dfg/DFGPreciseLocalClobberize.h (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGPreciseLocalClobberize.h	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGPreciseLocalClobberize.h	2017-09-02 08:35:46 UTC (rev 221528)
@@ -114,7 +114,7 @@
                 return;
             }
             
-            for (unsigned i = 1 + numberOfArgumentsToSkip; i < inlineCallFrame->arguments.size(); i++)
+            for (unsigned i = 1 + numberOfArgumentsToSkip; i < inlineCallFrame->argumentsWithFixup.size(); i++)
                 m_read(VirtualRegister(inlineCallFrame->stackOffset + virtualRegisterForArgument(i).offset()));
             if (inlineCallFrame->isVarargs())
                 m_read(VirtualRegister(inlineCallFrame->stackOffset + CallFrameSlot::argumentCount));
@@ -219,7 +219,7 @@
             }
 
             ASSERT_WITH_MESSAGE(inlineCallFrame->isVarargs(), "GetArgument is only used for InlineCallFrame if the call frame is varargs.");
-            if (indexIncludingThis < inlineCallFrame->arguments.size())
+            if (indexIncludingThis < inlineCallFrame->argumentsWithFixup.size())
                 m_read(VirtualRegister(inlineCallFrame->stackOffset + virtualRegisterForArgument(indexIncludingThis).offset()));
             m_read(VirtualRegister(inlineCallFrame->stackOffset + CallFrameSlot::argumentCount));
             break;
@@ -239,7 +239,7 @@
             // Read all of the inline arguments and call frame headers that we didn't already capture.
             for (InlineCallFrame* inlineCallFrame = m_node->origin.semantic.inlineCallFrame; inlineCallFrame; inlineCallFrame = inlineCallFrame->getCallerInlineFrameSkippingTailCalls()) {
                 if (!inlineCallFrame->isStrictMode()) {
-                    for (unsigned i = inlineCallFrame->arguments.size(); i-- > 1;)
+                    for (unsigned i = inlineCallFrame->argumentsWithFixup.size(); i-- > 1;)
                         m_read(VirtualRegister(inlineCallFrame->stackOffset + virtualRegisterForArgument(i).offset()));
                 }
                 if (inlineCallFrame->isClosureCall)

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -172,7 +172,7 @@
 void SpeculativeJIT::emitGetLength(InlineCallFrame* inlineCallFrame, GPRReg lengthGPR, bool includeThis)
 {
     if (inlineCallFrame && !inlineCallFrame->isVarargs())
-        m_jit.move(TrustedImm32(inlineCallFrame->arguments.size() - !includeThis), lengthGPR);
+        m_jit.move(TrustedImm32(inlineCallFrame->argumentCountIncludingThis - !includeThis), lengthGPR);
     else {
         VirtualRegister argumentCountRegister = m_jit.argumentCount(inlineCallFrame);
         m_jit.load32(JITCompiler::payloadFor(argumentCountRegister), lengthGPR);
@@ -6797,7 +6797,7 @@
     bool lengthIsKnown; // if false, lengthGPR will have the length.
     if (node->origin.semantic.inlineCallFrame
         && !node->origin.semantic.inlineCallFrame->isVarargs()) {
-        knownLength = node->origin.semantic.inlineCallFrame->arguments.size() - 1;
+        knownLength = node->origin.semantic.inlineCallFrame->argumentCountIncludingThis - 1;
         lengthIsKnown = true;
     } else {
         knownLength = UINT_MAX;

Modified: trunk/Source/_javascript_Core/dfg/DFGStackLayoutPhase.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/dfg/DFGStackLayoutPhase.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/dfg/DFGStackLayoutPhase.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -121,7 +121,7 @@
                     CallFrameSlot::argumentCount + inlineCallFrame->stackOffset).toLocal());
             }
             
-            for (unsigned argument = inlineCallFrame->arguments.size(); argument-- > 1;) {
+            for (unsigned argument = inlineCallFrame->argumentsWithFixup.size(); argument-- > 1;) {
                 usedLocals.set(VirtualRegister(
                     virtualRegisterForArgument(argument).offset() +
                     inlineCallFrame->stackOffset).toLocal());
@@ -187,7 +187,7 @@
                     allocation, VirtualRegister(inlineCallFrame->stackOffset + CallFrameSlot::argumentCount));
             }
             
-            for (unsigned argument = inlineCallFrame->arguments.size(); argument-- > 1;) {
+            for (unsigned argument = inlineCallFrame->argumentsWithFixup.size(); argument-- > 1;) {
                 ArgumentPosition& position = m_graph.m_argumentPositions[
                     data.argumentPositionStart + argument];
                 VariableAccessData* variable = position.someVariable();
@@ -198,7 +198,7 @@
                     source = ValueSource::forFlushFormat(
                         variable->machineLocal(), variable->flushFormat());
                 }
-                inlineCallFrame->arguments[argument] = source.valueRecovery();
+                inlineCallFrame->argumentsWithFixup[argument] = source.valueRecovery();
             }
             
             RELEASE_ASSERT(inlineCallFrame->isClosureCall == !!data.calleeVariable);

Modified: trunk/Source/_javascript_Core/ftl/FTLCompile.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/ftl/FTLCompile.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/ftl/FTLCompile.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -98,9 +98,9 @@
         if (inlineCallFrame->argumentCountRegister.isValid())
             inlineCallFrame->argumentCountRegister += localsOffset;
         
-        for (unsigned argument = inlineCallFrame->arguments.size(); argument-- > 1;) {
-            inlineCallFrame->arguments[argument] =
-                inlineCallFrame->arguments[argument].withLocalsOffset(localsOffset);
+        for (unsigned argument = inlineCallFrame->argumentsWithFixup.size(); argument-- > 1;) {
+            inlineCallFrame->argumentsWithFixup[argument] =
+                inlineCallFrame->argumentsWithFixup[argument].withLocalsOffset(localsOffset);
         }
         
         if (inlineCallFrame->isClosureCall) {

Modified: trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -3698,7 +3698,7 @@
         
         LValue limit;
         if (inlineCallFrame && !inlineCallFrame->isVarargs())
-            limit = m_out.constInt32(inlineCallFrame->arguments.size() - 1);
+            limit = m_out.constInt32(inlineCallFrame->argumentCountIncludingThis - 1);
         else {
             VirtualRegister argumentCountRegister = AssemblyHelpers::argumentCount(inlineCallFrame);
             limit = m_out.sub(m_out.load32(payloadFor(argumentCountRegister)), m_out.int32One);
@@ -3721,8 +3721,8 @@
         
         TypedPointer base;
         if (inlineCallFrame) {
-            if (inlineCallFrame->arguments.size() > 1)
-                base = addressFor(inlineCallFrame->arguments[1].virtualRegister());
+            if (inlineCallFrame->argumentCountIncludingThis > 1)
+                base = addressFor(inlineCallFrame->argumentsWithFixup[1].virtualRegister());
         } else
             base = addressFor(virtualRegisterForArgument(1));
         
@@ -9659,7 +9659,7 @@
         ArgumentsLength length;
 
         if (inlineCallFrame && !inlineCallFrame->isVarargs()) {
-            length.known = inlineCallFrame->arguments.size() - 1;
+            length.known = inlineCallFrame->argumentCountIncludingThis - 1;
             length.isKnown = true;
             length.value = m_out.constInt32(length.known);
         } else {

Modified: trunk/Source/_javascript_Core/ftl/FTLOperations.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/ftl/FTLOperations.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/ftl/FTLOperations.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -293,7 +293,7 @@
                 break;
             }
         } else
-            argumentCount = materialization->origin().inlineCallFrame->arguments.size();
+            argumentCount = materialization->origin().inlineCallFrame->argumentCountIncludingThis;
         RELEASE_ASSERT(argumentCount);
         
         JSFunction* callee = nullptr;

Modified: trunk/Source/_javascript_Core/interpreter/StackVisitor.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/interpreter/StackVisitor.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/interpreter/StackVisitor.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -205,7 +205,7 @@
         if (inlineCallFrame->argumentCountRegister.isValid())
             m_frame.m_argumentCountIncludingThis = callFrame->r(inlineCallFrame->argumentCountRegister.offset()).unboxedInt32();
         else
-            m_frame.m_argumentCountIncludingThis = inlineCallFrame->arguments.size();
+            m_frame.m_argumentCountIncludingThis = inlineCallFrame->argumentCountIncludingThis;
         m_frame.m_codeBlock = inlineCallFrame->baselineCodeBlock.get();
         m_frame.m_bytecodeOffset = codeOrigin->bytecodeIndex;
 

Modified: trunk/Source/_javascript_Core/jit/AssemblyHelpers.h (221527 => 221528)


--- trunk/Source/_javascript_Core/jit/AssemblyHelpers.h	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/jit/AssemblyHelpers.h	2017-09-02 08:35:46 UTC (rev 221528)
@@ -1220,9 +1220,9 @@
     {
         if (!inlineCallFrame)
             return VirtualRegister(CallFrame::argumentOffset(0));
-        if (inlineCallFrame->arguments.size() <= 1)
+        if (inlineCallFrame->argumentsWithFixup.size() <= 1)
             return virtualRegisterForLocal(0);
-        ValueRecovery recovery = inlineCallFrame->arguments[1];
+        ValueRecovery recovery = inlineCallFrame->argumentsWithFixup[1];
         RELEASE_ASSERT(recovery.technique() == DisplacedInJSStack);
         return recovery.virtualRegister();
     }

Modified: trunk/Source/_javascript_Core/jit/SetupVarargsFrame.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/jit/SetupVarargsFrame.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/jit/SetupVarargsFrame.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -121,11 +121,10 @@
             argumentCountRecovery = ValueRecovery::displacedInJSStack(
                 inlineCallFrame->argumentCountRegister, DataFormatInt32);
         } else {
-            argumentCountRecovery = ValueRecovery::constant(
-                jsNumber(inlineCallFrame->arguments.size()));
+            argumentCountRecovery = ValueRecovery::constant(jsNumber(inlineCallFrame->argumentCountIncludingThis));
         }
-        if (inlineCallFrame->arguments.size() > 1)
-            firstArgumentReg = inlineCallFrame->arguments[1].virtualRegister();
+        if (inlineCallFrame->argumentsWithFixup.size() > 1)
+            firstArgumentReg = inlineCallFrame->argumentsWithFixup[1].virtualRegister();
         else
             firstArgumentReg = VirtualRegister(0);
     } else {

Modified: trunk/Source/_javascript_Core/runtime/ClonedArguments.cpp (221527 => 221528)


--- trunk/Source/_javascript_Core/runtime/ClonedArguments.cpp	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/runtime/ClonedArguments.cpp	2017-09-02 08:35:46 UTC (rev 221528)
@@ -103,12 +103,12 @@
             if (inlineCallFrame->argumentCountRegister.isValid())
                 length = targetFrame->r(inlineCallFrame->argumentCountRegister).unboxedInt32();
             else
-                length = inlineCallFrame->arguments.size();
+                length = inlineCallFrame->argumentCountIncludingThis;
             length--;
             result = createEmpty(myFrame, callee, length);
 
             for (unsigned i = length; i--;)
-                result->putDirectIndex(myFrame, i, inlineCallFrame->arguments[i + 1].recover(targetFrame));
+                result->putDirectIndex(myFrame, i, inlineCallFrame->argumentsWithFixup[i + 1].recover(targetFrame));
         } else {
             length = targetFrame->argumentCount();
             result = createEmpty(myFrame, callee, length);

Modified: trunk/Source/_javascript_Core/runtime/CommonSlowPaths.h (221527 => 221528)


--- trunk/Source/_javascript_Core/runtime/CommonSlowPaths.h	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/runtime/CommonSlowPaths.h	2017-09-02 08:35:46 UTC (rev 221528)
@@ -50,24 +50,42 @@
     void* thunkToCall;
 };
 
+ALWAYS_INLINE int numberOfExtraSlots(int argumentCountIncludingThis)
+{
+    int frameSize = argumentCountIncludingThis + CallFrame::headerSizeInRegisters;
+    int alignedFrameSize = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), frameSize);
+    return alignedFrameSize - frameSize;
+}
+
+ALWAYS_INLINE int numberOfStackPaddingSlots(CodeBlock* codeBlock, int argumentCountIncludingThis)
+{
+    if (argumentCountIncludingThis >= codeBlock->numParameters())
+        return 0;
+    int alignedFrameSize = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), argumentCountIncludingThis + CallFrame::headerSizeInRegisters);
+    int alignedFrameSizeForParameters = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), codeBlock->numParameters() + CallFrame::headerSizeInRegisters);
+    return alignedFrameSizeForParameters - alignedFrameSize;
+}
+
+ALWAYS_INLINE int numberOfStackPaddingSlotsWithExtraSlots(CodeBlock* codeBlock, int argumentCountIncludingThis)
+{
+    if (argumentCountIncludingThis >= codeBlock->numParameters())
+        return 0;
+    return numberOfStackPaddingSlots(codeBlock, argumentCountIncludingThis) + numberOfExtraSlots(argumentCountIncludingThis);
+}
+
 ALWAYS_INLINE int arityCheckFor(ExecState* exec, VM& vm, CodeSpecializationKind kind)
 {
     JSFunction* callee = jsCast<JSFunction*>(exec->jsCallee());
     ASSERT(!callee->isHostFunction());
     CodeBlock* newCodeBlock = callee->jsExecutable()->codeBlockFor(kind);
-    int argumentCountIncludingThis = exec->argumentCountIncludingThis();
+    ASSERT(exec->argumentCountIncludingThis() < static_cast<unsigned>(newCodeBlock->numParameters()));
+    int padding = numberOfStackPaddingSlotsWithExtraSlots(newCodeBlock, exec->argumentCountIncludingThis());
     
-    ASSERT(argumentCountIncludingThis < newCodeBlock->numParameters());
-    int frameSize = argumentCountIncludingThis + CallFrame::headerSizeInRegisters;
-    int alignedFrameSizeForParameters = WTF::roundUpToMultipleOf(stackAlignmentRegisters(),
-        newCodeBlock->numParameters() + CallFrame::headerSizeInRegisters);
-    int paddedStackSpace = alignedFrameSizeForParameters - frameSize;
-    
-    Register* newStack = exec->registers() - WTF::roundUpToMultipleOf(stackAlignmentRegisters(), paddedStackSpace);
+    Register* newStack = exec->registers() - WTF::roundUpToMultipleOf(stackAlignmentRegisters(), padding);
 
     if (UNLIKELY(!vm.ensureStackCapacityFor(newStack)))
         return -1;
-    return paddedStackSpace;
+    return padding;
 }
 
 inline bool opIn(ExecState* exec, JSValue baseVal, JSValue propName, ArrayProfile* arrayProfile = nullptr)

Modified: trunk/Source/_javascript_Core/runtime/StackAlignment.h (221527 => 221528)


--- trunk/Source/_javascript_Core/runtime/StackAlignment.h	2017-09-02 08:20:30 UTC (rev 221527)
+++ trunk/Source/_javascript_Core/runtime/StackAlignment.h	2017-09-02 08:35:46 UTC (rev 221528)
@@ -31,9 +31,9 @@
 namespace JSC {
 
 // NB. Different platforms may have different requirements here. But 16 bytes is very common.
-inline unsigned stackAlignmentBytes() { return 16; }
+inline constexpr unsigned stackAlignmentBytes() { return 16; }
 
-inline unsigned stackAlignmentRegisters()
+inline constexpr unsigned stackAlignmentRegisters()
 {
     return stackAlignmentBytes() / sizeof(EncodedJSValue);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to