Allow builtin JS functions to be intrinsics
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Mar 2016 21:04:21 +0000 (21:04 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Mar 2016 21:04:21 +0000 (21:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155960

Reviewed by Mark Lam.

Source/JavaScriptCore:

Builtin functions can now be recognized as intrinsics inside
the DFG. This gives us the flexibility to either lower a builtin
as an intrinsic in the DFG or as a normal function call.
Because we may decide to not lower it as an intrinsic, the DFG
inliner could still inline the function call.

You can annotate a builtin function like so to make
it be recognized as an intrinsic.
```
[intrinsic=FooIntrinsic] function foo() { ... }
```
where FooIntrinsic is an enum value of the Intrinsic enum.

So in the future if we write RegExp.prototype.test as a builtin, we would do:
``` RegExpPrototype.js
[intrinsic=RegExpTestIntrinsic] function test() { ... }
```

* Scripts/builtins/builtins_generate_combined_implementation.py:
(BuiltinsCombinedImplementationGenerator.generate_secondary_header_includes):
* Scripts/builtins/builtins_generate_separate_implementation.py:
(BuiltinsSeparateImplementationGenerator.generate_secondary_header_includes):
* Scripts/builtins/builtins_generator.py:
(BuiltinsGenerator.generate_embedded_code_string_section_for_function):
* Scripts/builtins/builtins_model.py:
(BuiltinObject.__init__):
(BuiltinFunction):
(BuiltinFunction.__init__):
(BuiltinFunction.fromString):
(BuiltinFunction.__str__):
* Scripts/builtins/builtins_templates.py:
* bytecode/UnlinkedFunctionExecutable.cpp:
(JSC::UnlinkedFunctionExecutable::visitChildren):
(JSC::UnlinkedFunctionExecutable::link):
* bytecode/UnlinkedFunctionExecutable.h:
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::attemptToInlineCall):
* runtime/Executable.cpp:
(JSC::ExecutableBase::clearCode):
(JSC::NativeExecutable::destroy):
(JSC::ScriptExecutable::ScriptExecutable):
(JSC::EvalExecutable::create):
(JSC::EvalExecutable::EvalExecutable):
(JSC::ProgramExecutable::ProgramExecutable):
(JSC::ModuleProgramExecutable::ModuleProgramExecutable):
(JSC::FunctionExecutable::FunctionExecutable):
(JSC::ExecutableBase::intrinsic): Deleted.
(JSC::NativeExecutable::intrinsic): Deleted.
* runtime/Executable.h:
(JSC::ExecutableBase::ExecutableBase):
(JSC::ExecutableBase::hasJITCodeFor):
(JSC::ExecutableBase::intrinsic):
(JSC::ExecutableBase::intrinsicFor):
(JSC::ScriptExecutable::finishCreation):
* runtime/Intrinsic.h:

Source/WebCore:

* ForwardingHeaders/runtime/Intrinsic.h: Added.

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

14 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/Scripts/builtins/builtins_generate_combined_implementation.py
Source/JavaScriptCore/Scripts/builtins/builtins_generate_separate_implementation.py
Source/JavaScriptCore/Scripts/builtins/builtins_generator.py
Source/JavaScriptCore/Scripts/builtins/builtins_model.py
Source/JavaScriptCore/Scripts/builtins/builtins_templates.py
Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.cpp
Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.h
Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
Source/JavaScriptCore/runtime/Executable.cpp
Source/JavaScriptCore/runtime/Executable.h
Source/JavaScriptCore/runtime/Intrinsic.h
Source/WebCore/ChangeLog
Source/WebCore/ForwardingHeaders/runtime/Intrinsic.h [new file with mode: 0644]

index 6a66a97..74a905e 100644 (file)
@@ -1,3 +1,66 @@
+2016-03-29  Saam barati  <sbarati@apple.com>
+
+        Allow builtin JS functions to be intrinsics
+        https://bugs.webkit.org/show_bug.cgi?id=155960
+
+        Reviewed by Mark Lam.
+
+        Builtin functions can now be recognized as intrinsics inside
+        the DFG. This gives us the flexibility to either lower a builtin
+        as an intrinsic in the DFG or as a normal function call.
+        Because we may decide to not lower it as an intrinsic, the DFG
+        inliner could still inline the function call.
+
+        You can annotate a builtin function like so to make
+        it be recognized as an intrinsic.
+        ```
+        [intrinsic=FooIntrinsic] function foo() { ... }
+        ```
+        where FooIntrinsic is an enum value of the Intrinsic enum.
+
+        So in the future if we write RegExp.prototype.test as a builtin, we would do:
+        ``` RegExpPrototype.js
+        [intrinsic=RegExpTestIntrinsic] function test() { ... }
+        ```
+
+        * Scripts/builtins/builtins_generate_combined_implementation.py:
+        (BuiltinsCombinedImplementationGenerator.generate_secondary_header_includes):
+        * Scripts/builtins/builtins_generate_separate_implementation.py:
+        (BuiltinsSeparateImplementationGenerator.generate_secondary_header_includes):
+        * Scripts/builtins/builtins_generator.py:
+        (BuiltinsGenerator.generate_embedded_code_string_section_for_function):
+        * Scripts/builtins/builtins_model.py:
+        (BuiltinObject.__init__):
+        (BuiltinFunction):
+        (BuiltinFunction.__init__):
+        (BuiltinFunction.fromString):
+        (BuiltinFunction.__str__):
+        * Scripts/builtins/builtins_templates.py:
+        * bytecode/UnlinkedFunctionExecutable.cpp:
+        (JSC::UnlinkedFunctionExecutable::visitChildren):
+        (JSC::UnlinkedFunctionExecutable::link):
+        * bytecode/UnlinkedFunctionExecutable.h:
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::attemptToInlineCall):
+        * runtime/Executable.cpp:
+        (JSC::ExecutableBase::clearCode):
+        (JSC::NativeExecutable::destroy):
+        (JSC::ScriptExecutable::ScriptExecutable):
+        (JSC::EvalExecutable::create):
+        (JSC::EvalExecutable::EvalExecutable):
+        (JSC::ProgramExecutable::ProgramExecutable):
+        (JSC::ModuleProgramExecutable::ModuleProgramExecutable):
+        (JSC::FunctionExecutable::FunctionExecutable):
+        (JSC::ExecutableBase::intrinsic): Deleted.
+        (JSC::NativeExecutable::intrinsic): Deleted.
+        * runtime/Executable.h:
+        (JSC::ExecutableBase::ExecutableBase):
+        (JSC::ExecutableBase::hasJITCodeFor):
+        (JSC::ExecutableBase::intrinsic):
+        (JSC::ExecutableBase::intrinsicFor):
+        (JSC::ScriptExecutable::finishCreation):
+        * runtime/Intrinsic.h:
+
 2016-03-29  Joseph Pecoraro  <pecoraro@apple.com>
 
         JSC::Debugger cleanup after recent changes
index 094434b..5331031 100644 (file)
@@ -86,6 +86,9 @@ class BuiltinsCombinedImplementationGenerator(BuiltinsGenerator):
             (["JavaScriptCore", "WebCore"],
                 ("JavaScriptCore", "runtime/VM.h"),
             ),
+            (["JavaScriptCore", "WebCore"],
+                ("JavaScriptCore", "runtime/Intrinsic.h"),
+            ),
         ]
 
         return '\n'.join(self.generate_includes_from_entries(header_includes))
index 0443975..7789fe3 100644 (file)
@@ -101,6 +101,9 @@ class BuiltinsSeparateImplementationGenerator(BuiltinsGenerator):
             (["WebCore"],
                 ("WebCore", "bindings/js/WebCoreJSClientData.h"),
             ),
+            (["JavaScriptCore", "WebCore"],
+                ("JavaScriptCore", "runtime/Intrinsic.h"),
+            ),
         ]
 
         return '\n'.join(self.generate_includes_from_entries(header_includes))
index 21ac4c1..92ecbee 100644 (file)
@@ -129,12 +129,14 @@ class BuiltinsGenerator:
             'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code',
             'embeddedSource': embeddedSource,
             'embeddedSourceLength': embeddedSourceLength,
-            'canConstruct': constructAbility
+            'canConstruct': constructAbility,
+            'intrinsic': function.intrinsic
         }
 
         lines = []
         lines.append("const JSC::ConstructAbility s_%(codeName)sConstructAbility = JSC::ConstructAbility::%(canConstruct)s;" % args);
         lines.append("const int s_%(codeName)sLength = %(embeddedSourceLength)d;" % args);
+        lines.append("static const JSC::Intrinsic s_%(codeName)sIntrinsic = JSC::%(intrinsic)s;" % args);
         lines.append("const char* s_%(codeName)s =\n%(embeddedSource)s\n;" % args);
         return '\n'.join(lines)
 
index cdd5f90..54c2354 100755 (executable)
@@ -40,7 +40,8 @@ _FRAMEWORK_CONFIG_MAP = {
     },
 }
 
-functionHeadRegExp = re.compile(r"(?:function|constructor)\s+\w+\s*\(.*?\)", re.MULTILINE | re.S)
+functionHeadRegExp = re.compile(r"(\[intrinsic=\w+\]\s+)?(?:function|constructor)\s+\w+\s*\(.*?\)", re.MULTILINE | re.S)
+functionIntrinsicRegExp = re.compile(r"^\[intrinsic=(\w+)\]\s+", re.MULTILINE | re.S)
 functionNameRegExp = re.compile(r"(?:function|constructor)\s+(\w+)\s*\(", re.MULTILINE | re.S)
 functionIsConstructorRegExp = re.compile(r"^constructor", re.MULTILINE | re.S)
 functionParameterFinder = re.compile(r"^(?:function|constructor)\s+(?:\w+)\s*\(((?:\s*\w+)?\s*(?:\s*,\s*\w+)*)?\s*\)", re.MULTILINE | re.S)
@@ -93,16 +94,24 @@ class BuiltinObject:
 
 
 class BuiltinFunction:
-    def __init__(self, function_name, function_source, is_constructor, parameters):
+    def __init__(self, function_name, function_source, is_constructor, parameters, intrinsic):
         self.function_name = function_name
         self.function_source = function_source
         self.is_constructor = is_constructor
         self.parameters = parameters
+        self.intrinsic = intrinsic
         self.object = None  # Set by the owning BuiltinObject
 
     @staticmethod
     def fromString(function_string):
         function_source = multilineCommentRegExp.sub("", function_string)
+
+        intrinsic = "NoIntrinsic"
+        intrinsicMatch = functionIntrinsicRegExp.search(function_source)
+        if intrinsicMatch:
+            intrinsic = intrinsicMatch.group(1)
+            function_source = functionIntrinsicRegExp.sub("", function_source)
+
         if os.getenv("CONFIGURATION", "Debug").startswith("Debug"):
             function_source = lineWithOnlySingleLineCommentRegExp.sub("", function_source)
             function_source = lineWithTrailingSingleLineCommentRegExp.sub("\n", function_source)
@@ -114,7 +123,7 @@ class BuiltinFunction:
         if len(parameters[0]) == 0:
             parameters = []
 
-        return BuiltinFunction(function_name, function_source, is_constructor, parameters)
+        return BuiltinFunction(function_name, function_source, is_constructor, parameters, intrinsic)
 
     def __str__(self):
         interface = "%s(%s)" % (self.function_name, ', '.join(self.parameters))
index 67cdd5d..5c0fc46 100644 (file)
@@ -89,7 +89,7 @@ ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
 #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\
 JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\
 {\\
-    return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source()); \
+    return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source(), Nullopt, s_##codeName##Intrinsic); \
 }
 ${macroPrefix}_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
 #undef DEFINE_BUILTIN_GENERATOR
@@ -100,7 +100,7 @@ ${macroPrefix}_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
 #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\
 JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\
 {\\
-    return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source()); \
+    return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source(), Nullopt, s_##codeName##Intrinsic); \
 }
 ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
 #undef DEFINE_BUILTIN_GENERATOR
@@ -112,7 +112,7 @@ ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
 JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\
 {\\
     JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \\
-    return clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Executable()->link(vm, clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Source()); \\
+    return clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Executable()->link(vm, clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Source(), Nullopt, s_##codeName##Intrinsic); \\
 }
 ${macroPrefix}_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
 #undef DEFINE_BUILTIN_GENERATOR
@@ -124,7 +124,7 @@ ${macroPrefix}_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
 JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\
 {\\
     JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \\
-    return clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Executable()->link(vm, clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Source()); \\
+    return clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Executable()->link(vm, clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Source(), Nullopt, s_##codeName##Intrinsic); \\
 }
 ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
 #undef DEFINE_BUILTIN_GENERATOR
index 5233033..2b2cdd9 100644 (file)
@@ -127,7 +127,7 @@ void UnlinkedFunctionExecutable::visitChildren(JSCell* cell, SlotVisitor& visito
     visitor.append(&thisObject->m_unlinkedCodeBlockForConstruct);
 }
 
-FunctionExecutable* UnlinkedFunctionExecutable::link(VM& vm, const SourceCode& ownerSource, int overrideLineNumber)
+FunctionExecutable* UnlinkedFunctionExecutable::link(VM& vm, const SourceCode& ownerSource, Optional<int> overrideLineNumber, Intrinsic intrinsic)
 {
     SourceCode source = m_sourceOverride ? SourceCode(m_sourceOverride) : ownerSource;
     unsigned firstLine = source.firstLine() + m_firstLineOffset;
@@ -155,9 +155,9 @@ FunctionExecutable* UnlinkedFunctionExecutable::link(VM& vm, const SourceCode& o
         }
     }
 
-    FunctionExecutable* result = FunctionExecutable::create(vm, code, this, firstLine, firstLine + lineCount, startColumn, endColumn);
-    if (overrideLineNumber != -1)
-        result->setOverrideLineNumber(overrideLineNumber);
+    FunctionExecutable* result = FunctionExecutable::create(vm, code, this, firstLine, firstLine + lineCount, startColumn, endColumn, intrinsic);
+    if (overrideLineNumber)
+        result->setOverrideLineNumber(*overrideLineNumber);
 
     if (UNLIKELY(hasFunctionOverride)) {
         result->overrideParameterAndTypeProfilingStartEndOffsets(
index a861a96..697f12c 100644 (file)
@@ -34,6 +34,7 @@
 #include "ExpressionRangeInfo.h"
 #include "HandlerInfo.h"
 #include "Identifier.h"
+#include "Intrinsic.h"
 #include "JSCell.h"
 #include "JSString.h"
 #include "ParserModes.h"
@@ -107,7 +108,7 @@ public:
         const Identifier&, ExecState&, const SourceCode&, JSObject*& exception, 
         int overrideLineNumber);
 
-    JS_EXPORT_PRIVATE FunctionExecutable* link(VM&, const SourceCode&, int overrideLineNumber = -1);
+    JS_EXPORT_PRIVATE FunctionExecutable* link(VM&, const SourceCode&, Optional<int> overrideLineNumber = Nullopt, Intrinsic = NoIntrinsic);
 
     void clearCode()
     {
index 4c4b750..a6a87e5 100644 (file)
@@ -1570,12 +1570,6 @@ bool ByteCodeParser::attemptToInlineCall(Node* callTargetNode, int resultOperand
     if (!inliningBalance)
         return false;
     
-    bool didInsertChecks = false;
-    auto insertChecksWithAccounting = [&] () {
-        insertChecks(nullptr);
-        didInsertChecks = true;
-    };
-    
     if (verbose)
         dataLog("    Considering callee ", callee, "\n");
     
@@ -1587,6 +1581,13 @@ bool ByteCodeParser::attemptToInlineCall(Node* callTargetNode, int resultOperand
     // exit to: LoadVarargs is effectful and it's part of the op_call_varargs, so we can't exit without
     // calling LoadVarargs twice.
     if (!InlineCallFrame::isVarargs(kind)) {
+
+        bool didInsertChecks = false;
+        auto insertChecksWithAccounting = [&] () {
+            insertChecks(nullptr);
+            didInsertChecks = true;
+        };
+    
         if (InternalFunction* function = callee.internalFunction()) {
             if (handleConstantInternalFunction(callTargetNode, resultOperand, function, registerOffset, argumentCountIncludingThis, specializationKind, insertChecksWithAccounting)) {
                 RELEASE_ASSERT(didInsertChecks);
@@ -1608,8 +1609,9 @@ bool ByteCodeParser::attemptToInlineCall(Node* callTargetNode, int resultOperand
                 inliningBalance--;
                 return true;
             }
+
             RELEASE_ASSERT(!didInsertChecks);
-            return false;
+            // We might still try to inline the Intrinsic because it might be a builtin JS function.
         }
     }
     
index a993dfa..2fdb532 100644 (file)
@@ -101,20 +101,6 @@ void ExecutableBase::clearCode()
     ASSERT(classInfo() == NativeExecutable::info());
 }
 
-#if ENABLE(DFG_JIT)
-Intrinsic ExecutableBase::intrinsic() const
-{
-    if (const NativeExecutable* nativeExecutable = jsDynamicCast<const NativeExecutable*>(this))
-        return nativeExecutable->intrinsic();
-    return NoIntrinsic;
-}
-#else
-Intrinsic ExecutableBase::intrinsic() const
-{
-    return NoIntrinsic;
-}
-#endif
-
 const ClassInfo NativeExecutable::s_info = { "NativeExecutable", &ExecutableBase::s_info, 0, CREATE_METHOD_TABLE(NativeExecutable) };
 
 void NativeExecutable::destroy(JSCell* cell)
@@ -122,17 +108,10 @@ void NativeExecutable::destroy(JSCell* cell)
     static_cast<NativeExecutable*>(cell)->NativeExecutable::~NativeExecutable();
 }
 
-#if ENABLE(DFG_JIT)
-Intrinsic NativeExecutable::intrinsic() const
-{
-    return m_intrinsic;
-}
-#endif
-
 const ClassInfo ScriptExecutable::s_info = { "ScriptExecutable", &ExecutableBase::s_info, 0, CREATE_METHOD_TABLE(ScriptExecutable) };
 
-ScriptExecutable::ScriptExecutable(Structure* structure, VM& vm, const SourceCode& source, bool isInStrictContext, DerivedContextType derivedContextType, bool isInArrowFunctionContext)
-    : ExecutableBase(vm, structure, NUM_PARAMETERS_NOT_COMPILED)
+ScriptExecutable::ScriptExecutable(Structure* structure, VM& vm, const SourceCode& source, bool isInStrictContext, DerivedContextType derivedContextType, bool isInArrowFunctionContext, Intrinsic intrinsic)
+    : ExecutableBase(vm, structure, NUM_PARAMETERS_NOT_COMPILED, intrinsic)
     , m_features(isInStrictContext ? StrictModeFeature : 0)
     , m_didTryToEnterInLoop(false)
     , m_hasCapturedVariables(false)
@@ -436,7 +415,7 @@ EvalExecutable* EvalExecutable::create(ExecState* exec, const SourceCode& source
 }
 
 EvalExecutable::EvalExecutable(ExecState* exec, const SourceCode& source, bool inStrictContext, DerivedContextType derivedContextType, bool isArrowFunctionContext)
-    : ScriptExecutable(exec->vm().evalExecutableStructure.get(), exec->vm(), source, inStrictContext, derivedContextType, isArrowFunctionContext)
+    : ScriptExecutable(exec->vm().evalExecutableStructure.get(), exec->vm(), source, inStrictContext, derivedContextType, isArrowFunctionContext, NoIntrinsic)
 {
 }
 
@@ -448,7 +427,7 @@ void EvalExecutable::destroy(JSCell* cell)
 const ClassInfo ProgramExecutable::s_info = { "ProgramExecutable", &ScriptExecutable::s_info, 0, CREATE_METHOD_TABLE(ProgramExecutable) };
 
 ProgramExecutable::ProgramExecutable(ExecState* exec, const SourceCode& source)
-    : ScriptExecutable(exec->vm().programExecutableStructure.get(), exec->vm(), source, false, DerivedContextType::None, false)
+    : ScriptExecutable(exec->vm().programExecutableStructure.get(), exec->vm(), source, false, DerivedContextType::None, false, NoIntrinsic)
 {
     m_typeProfilingStartOffset = 0;
     m_typeProfilingEndOffset = source.length() - 1;
@@ -464,7 +443,7 @@ void ProgramExecutable::destroy(JSCell* cell)
 const ClassInfo ModuleProgramExecutable::s_info = { "ModuleProgramExecutable", &ScriptExecutable::s_info, 0, CREATE_METHOD_TABLE(ModuleProgramExecutable) };
 
 ModuleProgramExecutable::ModuleProgramExecutable(ExecState* exec, const SourceCode& source)
-    : ScriptExecutable(exec->vm().moduleProgramExecutableStructure.get(), exec->vm(), source, false, DerivedContextType::None, false)
+    : ScriptExecutable(exec->vm().moduleProgramExecutableStructure.get(), exec->vm(), source, false, DerivedContextType::None, false, NoIntrinsic)
 {
     m_typeProfilingStartOffset = 0;
     m_typeProfilingEndOffset = source.length() - 1;
@@ -495,8 +474,8 @@ void ModuleProgramExecutable::destroy(JSCell* cell)
 
 const ClassInfo FunctionExecutable::s_info = { "FunctionExecutable", &ScriptExecutable::s_info, 0, CREATE_METHOD_TABLE(FunctionExecutable) };
 
-FunctionExecutable::FunctionExecutable(VM& vm, const SourceCode& source, UnlinkedFunctionExecutable* unlinkedExecutable, unsigned firstLine, unsigned lastLine, unsigned startColumn, unsigned endColumn)
-    : ScriptExecutable(vm.functionExecutableStructure.get(), vm, source, unlinkedExecutable->isInStrictContext(), unlinkedExecutable->derivedContextType(), false)
+FunctionExecutable::FunctionExecutable(VM& vm, const SourceCode& source, UnlinkedFunctionExecutable* unlinkedExecutable, unsigned firstLine, unsigned lastLine, unsigned startColumn, unsigned endColumn, Intrinsic intrinsic)
+    : ScriptExecutable(vm.functionExecutableStructure.get(), vm, source, unlinkedExecutable->isInStrictContext(), unlinkedExecutable->derivedContextType(), false, intrinsic)
     , m_unlinkedExecutable(vm, this, unlinkedExecutable)
 {
     RELEASE_ASSERT(!source.isNull());
index 3e6090b..95f077a 100644 (file)
@@ -75,10 +75,11 @@ protected:
     static const int NUM_PARAMETERS_IS_HOST = 0;
     static const int NUM_PARAMETERS_NOT_COMPILED = -1;
 
-    ExecutableBase(VM& vm, Structure* structure, int numParameters)
+    ExecutableBase(VM& vm, Structure* structure, int numParameters, Intrinsic intrinsic)
         : JSCell(vm, structure)
         , m_numParametersForCall(numParameters)
         , m_numParametersForConstruct(numParameters)
+        , m_intrinsic(intrinsic)
     {
     }
 
@@ -231,7 +232,7 @@ public:
     }
 
     // Intrinsics are only for calls, currently.
-    Intrinsic intrinsic() const;
+    Intrinsic intrinsic() const { return m_intrinsic; }
         
     Intrinsic intrinsicFor(CodeSpecializationKind kind) const
     {
@@ -243,6 +244,7 @@ public:
     void dump(PrintStream&) const;
         
 protected:
+    Intrinsic m_intrinsic;
     RefPtr<JITCode> m_jitCodeForCall;
     RefPtr<JITCode> m_jitCodeForConstruct;
     MacroAssemblerCodePtr m_jitCodeForCallWithArityCheck;
@@ -259,8 +261,8 @@ public:
     static NativeExecutable* create(VM& vm, PassRefPtr<JITCode> callThunk, NativeFunction function, PassRefPtr<JITCode> constructThunk, NativeFunction constructor, Intrinsic intrinsic, const String& name)
     {
         NativeExecutable* executable;
-        executable = new (NotNull, allocateCell<NativeExecutable>(vm.heap)) NativeExecutable(vm, function, constructor);
-        executable->finishCreation(vm, callThunk, constructThunk, intrinsic, name);
+        executable = new (NotNull, allocateCell<NativeExecutable>(vm.heap)) NativeExecutable(vm, function, constructor, intrinsic);
+        executable->finishCreation(vm, callThunk, constructThunk, name);
         return executable;
     }
 
@@ -296,20 +298,19 @@ public:
     const String& name() const { return m_name; }
 
 protected:
-    void finishCreation(VM& vm, PassRefPtr<JITCode> callThunk, PassRefPtr<JITCode> constructThunk, Intrinsic intrinsic, const String& name)
+    void finishCreation(VM& vm, PassRefPtr<JITCode> callThunk, PassRefPtr<JITCode> constructThunk, const String& name)
     {
         Base::finishCreation(vm);
         m_jitCodeForCall = callThunk;
         m_jitCodeForConstruct = constructThunk;
-        m_intrinsic = intrinsic;
         m_name = name;
     }
 
 private:
     friend class ExecutableBase;
 
-    NativeExecutable(VM& vm, NativeFunction function, NativeFunction constructor)
-        : ExecutableBase(vm, vm.nativeExecutableStructure.get(), NUM_PARAMETERS_IS_HOST)
+    NativeExecutable(VM& vm, NativeFunction function, NativeFunction constructor, Intrinsic intrinsic)
+        : ExecutableBase(vm, vm.nativeExecutableStructure.get(), NUM_PARAMETERS_IS_HOST, intrinsic)
         , m_function(function)
         , m_constructor(constructor)
     {
@@ -399,7 +400,7 @@ private:
     JSObject* prepareForExecutionImpl(ExecState*, JSFunction*, JSScope*, CodeSpecializationKind);
 
 protected:
-    ScriptExecutable(Structure*, VM&, const SourceCode&, bool isInStrictContext, DerivedContextType, bool isInArrowFunctionContext);
+    ScriptExecutable(Structure*, VM&, const SourceCode&, bool isInStrictContext, DerivedContextType, bool isInArrowFunctionContext, Intrinsic);
 
     void finishCreation(VM& vm)
     {
@@ -580,9 +581,9 @@ public:
 
     static FunctionExecutable* create(
         VM& vm, const SourceCode& source, UnlinkedFunctionExecutable* unlinkedExecutable, 
-        unsigned firstLine, unsigned lastLine, unsigned startColumn, unsigned endColumn)
+        unsigned firstLine, unsigned lastLine, unsigned startColumn, unsigned endColumn, Intrinsic intrinsic)
     {
-        FunctionExecutable* executable = new (NotNull, allocateCell<FunctionExecutable>(vm.heap)) FunctionExecutable(vm, source, unlinkedExecutable, firstLine, lastLine, startColumn, endColumn);
+        FunctionExecutable* executable = new (NotNull, allocateCell<FunctionExecutable>(vm.heap)) FunctionExecutable(vm, source, unlinkedExecutable, firstLine, lastLine, startColumn, endColumn, intrinsic);
         executable->finishCreation(vm);
         return executable;
     }
@@ -697,7 +698,7 @@ private:
     friend class ExecutableBase;
     FunctionExecutable(
         VM&, const SourceCode&, UnlinkedFunctionExecutable*, unsigned firstLine, 
-        unsigned lastLine, unsigned startColumn, unsigned endColumn);
+        unsigned lastLine, unsigned startColumn, unsigned endColumn, Intrinsic);
     
     void finishCreation(VM&);
 
index 218d2ef..d8de006 100644 (file)
@@ -28,7 +28,7 @@
 
 namespace JSC {
 
-enum Intrinsic {
+enum JS_EXPORT_PRIVATE Intrinsic {
     // Call intrinsics.
     NoIntrinsic,
     AbsIntrinsic,
index cd0b456..707eb5d 100644 (file)
@@ -1,3 +1,12 @@
+2016-03-29  Saam barati  <sbarati@apple.com>
+
+        Allow builtin JS functions to be intrinsics
+        https://bugs.webkit.org/show_bug.cgi?id=155960
+
+        Reviewed by Mark Lam.
+
+        * ForwardingHeaders/runtime/Intrinsic.h: Added.
+
 2016-03-29  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [Cocoa] Rename ScrollbarPainter variables to ScrollerImp
diff --git a/Source/WebCore/ForwardingHeaders/runtime/Intrinsic.h b/Source/WebCore/ForwardingHeaders/runtime/Intrinsic.h
new file mode 100644 (file)
index 0000000..0a27357
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef WebCore_FWD_Intrinsic_h
+#define WebCore_FWD_Intrinsic_h
+#include <JavaScriptCore/Intrinsic.h>
+#endif