Title: [187629] branches/jsc-tailcall/Source/_javascript_Core
Revision
187629
Author
[email protected]
Date
2015-07-30 17:43:25 -0700 (Thu, 30 Jul 2015)

Log Message

jsc-tailcall: Add enums for type-safety
https://bugs.webkit.org/show_bug.cgi?id=147475

Reviewed by Michael Saboff.

This adds:

 - A CallMode enum to distinguish tail calls from regular calls from construct

 - A FrameAction enum to indicate whether to keep or reuse the call
   frame. It also changes JITOperations.h to correctly use this to tell
   slowPathFor to *not* trash the frame on a regular call (before
   r187505, this was statically known in slowPathFor).

* CMakeLists.txt:
* _javascript_Core.vcxproj/_javascript_Core.vcxproj:
* _javascript_Core.vcxproj/_javascript_Core.vcxproj.filters:
* _javascript_Core.xcodeproj/project.pbxproj:
* assembler/AbstractMacroAssembler.h:
(JSC::AbstractMacroAssembler::repatchNearCall):
* assembler/CodeLocation.h:
(JSC::CodeLocationNearCall::CodeLocationNearCall):
(JSC::CodeLocationNearCall::callMode):
(JSC::CodeLocationCommon::nearCallAtOffset):
* assembler/LinkBuffer.h:
(JSC::LinkBuffer::locationOfNearCall):
* bytecode/CallLinkInfo.h:
(JSC::CallLinkInfo::callModeFor):
(JSC::CallLinkInfo::callMode):
(JSC::CallLinkInfo::isTailCall):
(JSC::CallLinkInfo::isVarargs):
* bytecode/CallMode.cpp: Added.
(WTF::printInternal):
* bytecode/CallMode.h: Added.
* jit/JITOperations.cpp:
* jit/Repatch.cpp:
(JSC::linkPolymorphicCall):
* jit/ThunkGenerators.cpp:
(JSC::slowPathFor):
(JSC::virtualThunkFor):

Modified Paths

Added Paths

Diff

Modified: branches/jsc-tailcall/Source/_javascript_Core/CMakeLists.txt (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/CMakeLists.txt	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/CMakeLists.txt	2015-07-31 00:43:25 UTC (rev 187629)
@@ -76,6 +76,7 @@
     bytecode/CallEdge.cpp
     bytecode/CallLinkInfo.cpp
     bytecode/CallLinkStatus.cpp
+    bytecode/CallMode.cpp
     bytecode/CallVariant.cpp
     bytecode/CodeBlock.cpp
     bytecode/CodeBlockHash.cpp

Modified: branches/jsc-tailcall/Source/_javascript_Core/ChangeLog (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/ChangeLog	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/ChangeLog	2015-07-31 00:43:25 UTC (rev 187629)
@@ -1,5 +1,48 @@
 2015-07-30  Basile Clement  <[email protected]>
 
+        jsc-tailcall: Add enums for type-safety
+        https://bugs.webkit.org/show_bug.cgi?id=147475
+
+        Reviewed by Michael Saboff.
+
+        This adds:
+
+         - A CallMode enum to distinguish tail calls from regular calls from construct
+
+         - A FrameAction enum to indicate whether to keep or reuse the call
+           frame. It also changes JITOperations.h to correctly use this to tell
+           slowPathFor to *not* trash the frame on a regular call (before
+           r187505, this was statically known in slowPathFor).
+
+        * CMakeLists.txt:
+        * _javascript_Core.vcxproj/_javascript_Core.vcxproj:
+        * _javascript_Core.vcxproj/_javascript_Core.vcxproj.filters:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * assembler/AbstractMacroAssembler.h:
+        (JSC::AbstractMacroAssembler::repatchNearCall):
+        * assembler/CodeLocation.h:
+        (JSC::CodeLocationNearCall::CodeLocationNearCall):
+        (JSC::CodeLocationNearCall::callMode):
+        (JSC::CodeLocationCommon::nearCallAtOffset):
+        * assembler/LinkBuffer.h:
+        (JSC::LinkBuffer::locationOfNearCall):
+        * bytecode/CallLinkInfo.h:
+        (JSC::CallLinkInfo::callModeFor):
+        (JSC::CallLinkInfo::callMode):
+        (JSC::CallLinkInfo::isTailCall):
+        (JSC::CallLinkInfo::isVarargs):
+        * bytecode/CallMode.cpp: Added.
+        (WTF::printInternal):
+        * bytecode/CallMode.h: Added.
+        * jit/JITOperations.cpp:
+        * jit/Repatch.cpp:
+        (JSC::linkPolymorphicCall):
+        * jit/ThunkGenerators.cpp:
+        (JSC::slowPathFor):
+        (JSC::virtualThunkFor):
+
+2015-07-30  Basile Clement  <[email protected]>
+
         jsc-tailcall: Don't waste stack space when arity fixup was performed
         https://bugs.webkit.org/show_bug.cgi?id=147447
 

Modified: branches/jsc-tailcall/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj	2015-07-31 00:43:25 UTC (rev 187629)
@@ -317,6 +317,7 @@
     <ClCompile Include="..\bytecode\CallEdge.cpp" />
     <ClCompile Include="..\bytecode\CallLinkInfo.cpp" />
     <ClCompile Include="..\bytecode\CallLinkStatus.cpp" />
+    <ClCompile Include="..\bytecode\CallMode.cpp" />
     <ClCompile Include="..\bytecode\CallVariant.cpp" />
     <ClCompile Include="..\bytecode\CodeBlock.cpp" />
     <ClCompile Include="..\bytecode\CodeBlockHash.cpp" />
@@ -967,6 +968,7 @@
     <ClInclude Include="..\bytecode\CallEdge.h" />
     <ClInclude Include="..\bytecode\CallLinkInfo.h" />
     <ClInclude Include="..\bytecode\CallLinkStatus.h" />
+    <ClInclude Include="..\bytecode\CallMode.h" />
     <ClInclude Include="..\bytecode\CallReturnOffsetToBytecodeOffset.h" />
     <ClInclude Include="..\bytecode\CallVariant.h" />
     <ClInclude Include="..\bytecode\CodeBlock.h" />

Modified: branches/jsc-tailcall/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters	2015-07-31 00:43:25 UTC (rev 187629)
@@ -156,6 +156,9 @@
     <ClCompile Include="..\bytecode\CallLinkStatus.cpp">
       <Filter>bytecode</Filter>
     </ClCompile>
+    <ClCompile Include="..\bytecode\CallMode.cpp">
+      <Filter>bytecode</Filter>
+    </ClCompile>
     <ClCompile Include="..\bytecode\CodeBlock.cpp">
       <Filter>bytecode</Filter>
     </ClCompile>
@@ -1935,6 +1938,9 @@
     <ClInclude Include="..\bytecode\CallLinkStatus.h">
       <Filter>bytecode</Filter>
     </ClInclude>
+    <ClInclude Include="..\bytecode\CallMode.h">
+      <Filter>bytecode</Filter>
+    </ClInclude>
     <ClInclude Include="..\bytecode\CallReturnOffsetToBytecodeOffset.h">
       <Filter>bytecode</Filter>
     </ClInclude>

Modified: branches/jsc-tailcall/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2015-07-31 00:43:25 UTC (rev 187629)
@@ -962,6 +962,8 @@
 		5DBB151B131D0B310056AD36 /* testapi.js in Copy Support Script */ = {isa = PBXBuildFile; fileRef = 14D857740A4696C80032146C /* testapi.js */; };
 		5DBB1525131D0BD70056AD36 /* minidom.js in Copy Support Script */ = {isa = PBXBuildFile; fileRef = 1412110D0A48788700480255 /* minidom.js */; };
 		5DE6E5B30E1728EC00180407 /* create_hash_table in Headers */ = {isa = PBXBuildFile; fileRef = F692A8540255597D01FF60F7 /* create_hash_table */; settings = {ATTRIBUTES = (); }; };
+		627673231B680C1E00FD9F2E /* CallMode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 627673211B680C1E00FD9F2E /* CallMode.cpp */; };
+		627673241B680C1E00FD9F2E /* CallMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 627673221B680C1E00FD9F2E /* CallMode.h */; };
 		62D2D38F1ADF103F000206C1 /* FunctionRareData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62D2D38D1ADF103F000206C1 /* FunctionRareData.cpp */; };
 		62D2D3901ADF103F000206C1 /* FunctionRareData.h in Headers */ = {isa = PBXBuildFile; fileRef = 62D2D38E1ADF103F000206C1 /* FunctionRareData.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		62F2AA371B0BEDE300610C7A /* DFGLazyNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62A9A29E1B0BED4800BD54CA /* DFGLazyNode.cpp */; };
@@ -2676,6 +2678,8 @@
 		5DAFD6CB146B686300FBEFB4 /* JSC.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = JSC.xcconfig; sourceTree = "<group>"; };
 		5DDDF44614FEE72200B4FB4D /* LLIntDesiredOffsets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LLIntDesiredOffsets.h; path = LLIntOffsets/LLIntDesiredOffsets.h; sourceTree = BUILT_PRODUCTS_DIR; };
 		5DE3D0F40DD8DDFB00468714 /* WebKitAvailability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitAvailability.h; sourceTree = "<group>"; };
+		627673211B680C1E00FD9F2E /* CallMode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CallMode.cpp; sourceTree = "<group>"; };
+		627673221B680C1E00FD9F2E /* CallMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallMode.h; sourceTree = "<group>"; };
 		62A9A29E1B0BED4800BD54CA /* DFGLazyNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGLazyNode.cpp; path = dfg/DFGLazyNode.cpp; sourceTree = "<group>"; };
 		62A9A29F1B0BED4800BD54CA /* DFGLazyNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGLazyNode.h; path = dfg/DFGLazyNode.h; sourceTree = "<group>"; };
 		62D2D38D1ADF103F000206C1 /* FunctionRareData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FunctionRareData.cpp; sourceTree = "<group>"; };
@@ -5257,6 +5261,8 @@
 				0F0B83AF14BCF71400885B4F /* CallLinkInfo.h */,
 				0F93329314CA7DC10085F3C6 /* CallLinkStatus.cpp */,
 				0F93329414CA7DC10085F3C6 /* CallLinkStatus.h */,
+				627673211B680C1E00FD9F2E /* CallMode.cpp */,
+				627673221B680C1E00FD9F2E /* CallMode.h */,
 				0F0B83B814BCF95B00885B4F /* CallReturnOffsetToBytecodeOffset.h */,
 				0F3B7E2419A11B8000D9BC56 /* CallVariant.cpp */,
 				0F3B7E2519A11B8000D9BC56 /* CallVariant.h */,
@@ -5278,6 +5284,8 @@
 				0F426A4A1460CD6B00131F8F /* DataFormat.h */,
 				0FC712DC17CD8778008CC93C /* DeferredCompilationCallback.cpp */,
 				0FC712DD17CD8778008CC93C /* DeferredCompilationCallback.h */,
+				FE5068661AE25E280009DAB7 /* DeferredSourceDump.cpp */,
+				FE5068641AE246390009DAB7 /* DeferredSourceDump.h */,
 				0FBC0AE41496C7C100D4FBDD /* DFGExitProfile.cpp */,
 				0FBC0AE51496C7C100D4FBDD /* DFGExitProfile.h */,
 				969A07920ED1D3AE00F1F681 /* EvalCodeCache.h */,
@@ -5325,8 +5333,6 @@
 				0FF60AC016740F8100029779 /* ReduceWhitespace.h */,
 				1429D8830ED21C3D00B89619 /* SamplingTool.cpp */,
 				1429D8840ED21C3D00B89619 /* SamplingTool.h */,
-				FE5068661AE25E280009DAB7 /* DeferredSourceDump.cpp */,
-				FE5068641AE246390009DAB7 /* DeferredSourceDump.h */,
 				0F5541AF1613C1FB00CE3E25 /* SpecialPointer.cpp */,
 				0F5541B01613C1FB00CE3E25 /* SpecialPointer.h */,
 				0FD82E84141F3FDA00179C94 /* SpeculatedType.cpp */,
@@ -5865,6 +5871,7 @@
 				86EC9DD01328DF82002B2AD7 /* DFGOperations.h in Headers */,
 				A7D89CFE17A0B8CC00773AD8 /* DFGOSRAvailabilityAnalysisPhase.h in Headers */,
 				0FD82E57141DAF1000179C94 /* DFGOSREntry.h in Headers */,
+				627673241B680C1E00FD9F2E /* CallMode.h in Headers */,
 				0FD8A32617D51F5700CA2C40 /* DFGOSREntrypointCreationPhase.h in Headers */,
 				62F2AA381B0BEDE300610C7A /* DFGLazyNode.h in Headers */,
 				0FC0976A1468A6F700CF2442 /* DFGOSRExit.h in Headers */,
@@ -7567,6 +7574,7 @@
 				0F2D4DEF19832DD3007D4B19 /* TypeSet.cpp in Sources */,
 				9335F24D12E6765B002B5553 /* StringRecursionChecker.cpp in Sources */,
 				BCDE3B430E6C832D001453A7 /* Structure.cpp in Sources */,
+				627673231B680C1E00FD9F2E /* CallMode.cpp in Sources */,
 				7E4EE70F0EBB7A5B005934AA /* StructureChain.cpp in Sources */,
 				C2F0F2D116BAEEE900187C19 /* StructureRareData.cpp in Sources */,
 				7013CA8B1B491A9400CAE613 /* JSJob.cpp in Sources */,

Modified: branches/jsc-tailcall/Source/_javascript_Core/assembler/AbstractMacroAssembler.h (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/assembler/AbstractMacroAssembler.h	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/assembler/AbstractMacroAssembler.h	2015-07-31 00:43:25 UTC (rev 187629)
@@ -1154,10 +1154,10 @@
     static void repatchNearCall(CodeLocationNearCall nearCall, CodeLocationLabel destination)
     {
         switch (nearCall.callMode()) {
-        case CallMode::Tail:
+        case NearCallMode::Tail:
             AssemblerType::relinkJump(nearCall.dataLocation(), destination.executableAddress());
             return;
-        case CallMode::Regular:
+        case NearCallMode::Regular:
             AssemblerType::relinkCall(nearCall.dataLocation(), destination.executableAddress());
             return;
         }

Modified: branches/jsc-tailcall/Source/_javascript_Core/assembler/CodeLocation.h (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/assembler/CodeLocation.h	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/assembler/CodeLocation.h	2015-07-31 00:43:25 UTC (rev 187629)
@@ -32,7 +32,7 @@
 
 namespace JSC {
 
-enum CallMode { Regular, Tail };
+enum NearCallMode { Regular, Tail };
 
 class CodeLocationInstruction;
 class CodeLocationLabel;
@@ -61,7 +61,7 @@
     CodeLocationLabel labelAtOffset(int offset);
     CodeLocationJump jumpAtOffset(int offset);
     CodeLocationCall callAtOffset(int offset);
-    CodeLocationNearCall nearCallAtOffset(int offset, CallMode);
+    CodeLocationNearCall nearCallAtOffset(int offset, NearCallMode);
     CodeLocationDataLabelPtr dataLabelPtrAtOffset(int offset);
     CodeLocationDataLabel32 dataLabel32AtOffset(int offset);
     CodeLocationDataLabelCompact dataLabelCompactAtOffset(int offset);
@@ -117,13 +117,13 @@
 class CodeLocationNearCall : public CodeLocationCommon {
 public:
     CodeLocationNearCall() {}
-    explicit CodeLocationNearCall(MacroAssemblerCodePtr location, CallMode callMode)
+    explicit CodeLocationNearCall(MacroAssemblerCodePtr location, NearCallMode callMode)
         : CodeLocationCommon(location), m_callMode(callMode) {}
-    explicit CodeLocationNearCall(void* location, CallMode callMode)
+    explicit CodeLocationNearCall(void* location, NearCallMode callMode)
         : CodeLocationCommon(MacroAssemblerCodePtr(location)), m_callMode(callMode) {}
-    CallMode callMode() { return m_callMode; }
+    NearCallMode callMode() { return m_callMode; }
 private:
-    CallMode m_callMode = CallMode::Regular;
+    NearCallMode m_callMode = NearCallMode::Regular;
 };
 
 class CodeLocationDataLabel32 : public CodeLocationCommon {
@@ -186,7 +186,7 @@
     return CodeLocationCall(reinterpret_cast<char*>(dataLocation()) + offset);
 }
 
-inline CodeLocationNearCall CodeLocationCommon::nearCallAtOffset(int offset, CallMode callMode)
+inline CodeLocationNearCall CodeLocationCommon::nearCallAtOffset(int offset, NearCallMode callMode)
 {
     ASSERT_VALID_CODE_OFFSET(offset);
     return CodeLocationNearCall(reinterpret_cast<char*>(dataLocation()) + offset, callMode);

Modified: branches/jsc-tailcall/Source/_javascript_Core/assembler/LinkBuffer.h (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/assembler/LinkBuffer.h	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/assembler/LinkBuffer.h	2015-07-31 00:43:25 UTC (rev 187629)
@@ -181,7 +181,7 @@
         ASSERT(call.isFlagSet(Call::Linkable));
         ASSERT(call.isFlagSet(Call::Near));
         return CodeLocationNearCall(MacroAssembler::getLinkerAddress(code(), applyOffset(call.m_label)),
-            call.isFlagSet(Call::Tail) ? CallMode::Tail : CallMode::Regular);
+            call.isFlagSet(Call::Tail) ? NearCallMode::Tail : NearCallMode::Regular);
     }
 
     CodeLocationLabel locationOf(PatchableJump jump)

Modified: branches/jsc-tailcall/Source/_javascript_Core/bytecode/CallLinkInfo.h (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/bytecode/CallLinkInfo.h	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/bytecode/CallLinkInfo.h	2015-07-31 00:43:25 UTC (rev 187629)
@@ -26,6 +26,7 @@
 #ifndef CallLinkInfo_h
 #define CallLinkInfo_h
 
+#include "CallMode.h"
 #include "CodeLocation.h"
 #include "CodeSpecializationKind.h"
 #include "JITWriteBarrier.h"
@@ -73,18 +74,6 @@
         }
     }
 
-    static bool isTailCallType(CallType callType)
-    {
-        switch (callType) {
-        case TailCall:
-        case TailCallVarargs:
-            return true;
-
-        default:
-            return false;
-        }
-    }
-    
     CallLinkInfo()
         : m_registerPreservationMode(static_cast<unsigned>(RegisterPreservationNotRequired))
         , m_hasSeenShouldRepatch(false)
@@ -113,6 +102,37 @@
         return specializationKindFor(static_cast<CallType>(m_callType));
     }
 
+    static CallMode callModeFor(CallType callType)
+    {
+        switch (callType) {
+        case Call:
+        case CallVarargs:
+            return CallMode::Regular;
+        case TailCall:
+        case TailCallVarargs:
+            return CallMode::Tail;
+        case Construct:
+        case ConstructVarargs:
+            return CallMode::Construct;
+        case None:
+            RELEASE_ASSERT_NOT_REACHED();
+        }
+    }
+    CallMode callMode() const
+    {
+        return callModeFor(static_cast<CallType>(m_callType));
+    }
+
+    bool isTailCall() const
+    {
+        return callMode() == CallMode::Tail;
+    }
+
+    bool isVarargs() const
+    {
+        return isVarargsCallType(static_cast<CallType>(m_callType));
+    }
+
     RegisterPreservationMode registerPreservationMode() const
     {
         return static_cast<RegisterPreservationMode>(m_registerPreservationMode);

Added: branches/jsc-tailcall/Source/_javascript_Core/bytecode/CallMode.cpp (0 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/bytecode/CallMode.cpp	                        (rev 0)
+++ branches/jsc-tailcall/Source/_javascript_Core/bytecode/CallMode.cpp	2015-07-31 00:43:25 UTC (rev 187629)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "CallMode.h"
+
+#include <wtf/PrintStream.h>
+
+namespace WTF {
+
+void printInternal(PrintStream& out, JSC::CallMode callMode)
+{
+    switch (callMode) {
+    case JSC::CallMode::Tail:
+        out.print("TailCall");
+        return;
+    case JSC::CallMode::Regular:
+        out.print("Call");
+        return;
+    case JSC::CallMode::Construct:
+        out.print("Construct");
+        return;
+    }
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
+} // namespace WTF

Added: branches/jsc-tailcall/Source/_javascript_Core/bytecode/CallMode.h (0 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/bytecode/CallMode.h	                        (rev 0)
+++ branches/jsc-tailcall/Source/_javascript_Core/bytecode/CallMode.h	2015-07-31 00:43:25 UTC (rev 187629)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef CallMode_h
+#define CallMode_h
+
+namespace JSC {
+
+enum class CallMode { Regular, Tail, Construct };
+
+enum FrameAction { KeepTheFrame = 0, ReuseTheFrame };
+
+} // namespace JSC
+
+namespace WTF {
+
+class PrintStream;
+void printInternal(PrintStream&, JSC::CallMode);
+
+} // namespace WTF
+
+#endif // CallMode_h
+

Modified: branches/jsc-tailcall/Source/_javascript_Core/jit/JITOperations.cpp (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/jit/JITOperations.cpp	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/jit/JITOperations.cpp	2015-07-31 00:43:25 UTC (rev 187629)
@@ -705,14 +705,14 @@
     return JSValue::encode(result);
 }
 
-static SlowPathReturnType handleHostCall(ExecState* execCallee, JSValue callee, CodeSpecializationKind kind)
+static SlowPathReturnType handleHostCall(ExecState* execCallee, JSValue callee, CallLinkInfo* callLinkInfo)
 {
     ExecState* exec = execCallee->callerFrame();
     VM* vm = &exec->vm();
 
     execCallee->setCodeBlock(0);
 
-    if (kind == CodeForCall) {
+    if (callLinkInfo->specializationKind() == CodeForCall) {
         CallData callData;
         CallType callType = getCallData(callee, callData);
     
@@ -722,18 +722,25 @@
             NativeCallFrameTracer tracer(vm, execCallee);
             execCallee->setCallee(asObject(callee));
             vm->hostCallReturnValue = JSValue::decode(callData.native.function(execCallee));
-            if (vm->exception())
-                return encodeResult(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(), reinterpret_cast<void*>(0));
+            if (vm->exception()) {
+                return encodeResult(
+                    vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(),
+                    reinterpret_cast<void*>(KeepTheFrame));
+            }
 
-            return encodeResult(bitwise_cast<void*>(getHostCallReturnValue), reinterpret_cast<void*>(1));
+            return encodeResult(
+                bitwise_cast<void*>(getHostCallReturnValue),
+                reinterpret_cast<void*>(callLinkInfo->callMode() == CallMode::Tail ? ReuseTheFrame : KeepTheFrame));
         }
     
         ASSERT(callType == CallTypeNone);
         exec->vm().throwException(exec, createNotAFunctionError(exec, callee));
-        return encodeResult(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(), reinterpret_cast<void*>(0));
+        return encodeResult(
+            vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(),
+            reinterpret_cast<void*>(KeepTheFrame));
     }
 
-    ASSERT(kind == CodeForConstruct);
+    ASSERT(callLinkInfo->specializationKind() == CodeForConstruct);
     
     ConstructData constructData;
     ConstructType constructType = getConstructData(callee, constructData);
@@ -744,15 +751,20 @@
         NativeCallFrameTracer tracer(vm, execCallee);
         execCallee->setCallee(asObject(callee));
         vm->hostCallReturnValue = JSValue::decode(constructData.native.function(execCallee));
-        if (vm->exception())
-            return encodeResult(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(), reinterpret_cast<void*>(0));
+        if (vm->exception()) {
+            return encodeResult(
+                vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(),
+                reinterpret_cast<void*>(KeepTheFrame));
+        }
 
-        return encodeResult(bitwise_cast<void*>(getHostCallReturnValue), reinterpret_cast<void*>(1));
+        return encodeResult(bitwise_cast<void*>(getHostCallReturnValue), reinterpret_cast<void*>(KeepTheFrame));
     }
     
     ASSERT(constructType == ConstructTypeNone);
     exec->vm().throwException(exec, createNotAConstructorError(exec, callee));
-    return encodeResult(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(), reinterpret_cast<void*>(0));
+    return encodeResult(
+        vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(),
+        reinterpret_cast<void*>(KeepTheFrame));
 }
 
 SlowPathReturnType JIT_OPERATION operationLinkCall(ExecState* execCallee, CallLinkInfo* callLinkInfo)
@@ -768,7 +780,7 @@
         // FIXME: We should cache these kinds of calls. They can be common and currently they are
         // expensive.
         // https://bugs.webkit.org/show_bug.cgi?id=144458
-        return handleHostCall(execCallee, calleeAsValue, kind);
+        return handleHostCall(execCallee, calleeAsValue, callLinkInfo);
     }
 
     JSFunction* callee = jsCast<JSFunction*>(calleeAsFunctionCell);
@@ -784,17 +796,21 @@
 
         if (!isCall(kind) && functionExecutable->isBuiltinFunction()) {
             exec->vm().throwException(exec, createNotAConstructorError(exec, callee));
-            return encodeResult(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(), reinterpret_cast<void*>(0));
+            return encodeResult(
+                vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(),
+                reinterpret_cast<void*>(KeepTheFrame));
         }
 
         JSObject* error = functionExecutable->prepareForExecution(execCallee, callee, scope, kind);
         if (error) {
             exec->vm().throwException(exec, error);
-            return encodeResult(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(), reinterpret_cast<void*>(0));
+            return encodeResult(
+                vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(),
+                reinterpret_cast<void*>(KeepTheFrame));
         }
         codeBlock = functionExecutable->codeBlockFor(kind);
         ArityCheckMode arity;
-        if (execCallee->argumentCountIncludingThis() < static_cast<size_t>(codeBlock->numParameters()) || CallLinkInfo::isVarargsCallType(callLinkInfo->callType()))
+        if (execCallee->argumentCountIncludingThis() < static_cast<size_t>(codeBlock->numParameters()) || callLinkInfo->isVarargs())
             arity = MustCheckArity;
         else
             arity = ArityCheckNotRequired;
@@ -805,7 +821,7 @@
     else
         linkFor(execCallee, *callLinkInfo, codeBlock, callee, codePtr);
     
-    return encodeResult(codePtr.executableAddress(), reinterpret_cast<void*>(1));
+    return encodeResult(codePtr.executableAddress(), reinterpret_cast<void*>(callLinkInfo->callMode() == CallMode::Tail ? ReuseTheFrame : KeepTheFrame));
 }
 
 inline SlowPathReturnType virtualForWithFunction(
@@ -819,7 +835,7 @@
     JSValue calleeAsValue = execCallee->calleeAsValue();
     calleeAsFunctionCell = getJSFunction(calleeAsValue);
     if (UNLIKELY(!calleeAsFunctionCell))
-        return handleHostCall(execCallee, calleeAsValue, kind);
+        return handleHostCall(execCallee, calleeAsValue, callLinkInfo);
     
     JSFunction* function = jsCast<JSFunction*>(calleeAsFunctionCell);
     JSScope* scope = function->scopeUnchecked();
@@ -829,18 +845,22 @@
 
         if (!isCall(kind) && functionExecutable->isBuiltinFunction()) {
             exec->vm().throwException(exec, createNotAConstructorError(exec, function));
-            return encodeResult(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(), reinterpret_cast<void*>(0));
+            return encodeResult(
+                vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(),
+                reinterpret_cast<void*>(KeepTheFrame));
         }
 
         JSObject* error = functionExecutable->prepareForExecution(execCallee, function, scope, kind);
         if (error) {
             exec->vm().throwException(exec, error);
-            return encodeResult(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(), reinterpret_cast<void*>(0));
+            return encodeResult(
+                vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress(),
+                reinterpret_cast<void*>(KeepTheFrame));
         }
     }
     return encodeResult(executable->entrypointFor(
         *vm, kind, MustCheckArity, callLinkInfo->registerPreservationMode()).executableAddress(),
-        reinterpret_cast<void*>(1));
+        reinterpret_cast<void*>(callLinkInfo->callMode() == CallMode::Tail ? ReuseTheFrame : KeepTheFrame));
 }
 
 SlowPathReturnType JIT_OPERATION operationLinkPolymorphicCall(ExecState* execCallee, CallLinkInfo* callLinkInfo)

Modified: branches/jsc-tailcall/Source/_javascript_Core/jit/Repatch.cpp (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/jit/Repatch.cpp	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/jit/Repatch.cpp	2015-07-31 00:43:25 UTC (rev 187629)
@@ -1757,7 +1757,7 @@
             
             // If we cannot handle a callee, assume that it's better for this whole thing to be a
             // virtual call.
-            if (exec->argumentCountIncludingThis() < static_cast<size_t>(codeBlock->numParameters()) || CallLinkInfo::isVarargsCallType(callLinkInfo.callType())) {
+            if (exec->argumentCountIncludingThis() < static_cast<size_t>(codeBlock->numParameters()) || callLinkInfo.isVarargs()) {
                 linkVirtualFor(exec, callLinkInfo);
                 return;
             }
@@ -1880,7 +1880,7 @@
                 CCallHelpers::TrustedImm32(1),
                 CCallHelpers::Address(fastCountsBaseGPR, caseIndex * sizeof(uint32_t)));
         }
-        if (CallLinkInfo::isTailCallType(callLinkInfo.callType())) {
+        if (callLinkInfo.isTailCall()) {
             stubJit.prepareForTailCallSlow();
             calls[caseIndex].call = stubJit.nearTailCall();
         } else

Modified: branches/jsc-tailcall/Source/_javascript_Core/jit/ThunkGenerators.cpp (187628 => 187629)


--- branches/jsc-tailcall/Source/_javascript_Core/jit/ThunkGenerators.cpp	2015-07-31 00:37:38 UTC (rev 187628)
+++ branches/jsc-tailcall/Source/_javascript_Core/jit/ThunkGenerators.cpp	2015-07-31 00:43:25 UTC (rev 187629)
@@ -99,6 +99,7 @@
     emitPointerValidation(jit, GPRInfo::returnValueGPR);
     jit.emitFunctionEpilogue();
 
+    RELEASE_ASSERT(reinterpret_cast<void*>(KeepTheFrame) == reinterpret_cast<void*>(0));
     CCallHelpers::Jump doNotTrash = jit.branchTestPtr(CCallHelpers::Zero, GPRInfo::returnValueGPR2);
 
     jit.preserveReturnAddressAfterCall(GPRInfo::nonPreservedNonReturnGPR);
@@ -191,7 +192,7 @@
     
     // Make a tail call. This will return back to JIT code.
     emitPointerValidation(jit, GPRInfo::regT4);
-    if (CallLinkInfo::isTailCallType(callLinkInfo.callType())) {
+    if (callLinkInfo.isTailCall()) {
         jit.preserveReturnAddressAfterCall(GPRInfo::regT0);
         jit.prepareForTailCallSlow(GPRInfo::regT4);
     }
@@ -205,9 +206,8 @@
     LinkBuffer patchBuffer(*vm, jit, GLOBAL_THUNK_ID);
     return FINALIZE_CODE(
         patchBuffer,
-        ("Virtual %s%s slow path thunk at CodePtr(%p)",
-        callLinkInfo.specializationKind() == CodeForCall ? "call" : "construct",
-        callLinkInfo.registerPreservationMode() == MustPreserveRegisters ? " that preserves registers" : "",
+        ("Virtual %s slow path thunk at CodePtr(%p)",
+        callLinkInfo.callMode() == CallMode::Regular ? "call" : callLinkInfo.callMode() == CallMode::Tail ? "tail call" : "construct",
         callLinkInfo.callReturnLocation().dataLocation()));
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to