Changeset 189079 in webkit


Ignore:
Timestamp:
Aug 27, 2015 6:13:39 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Create WebAssembly functions
https://bugs.webkit.org/show_bug.cgi?id=148373

Patch by Sukolsak Sakshuwong <Sukolsak Sakshuwong> on 2015-08-27
Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

Create functions from WebAssembly files generated by pack-asmjs
<https://github.com/WebAssembly/polyfill-prototype-1>.
WebAssembly functions created by this patch can only return 0.
Actual code generation will be implemented in subsequent patches.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::hash):
(JSC::CodeBlock::sourceCodeForTools):
(JSC::CodeBlock::dumpAssumingJITType):
(JSC::CodeBlock::dumpSource):
(JSC::CodeBlock::CodeBlock):
(JSC::CodeBlock::finalizeUnconditionally):
(JSC::CodeBlock::lineNumberForBytecodeOffset):
(JSC::CodeBlock::expressionRangeForBytecodeOffset):
(JSC::CodeBlock::install):
(JSC::CodeBlock::newReplacement):
(JSC::WebAssemblyCodeBlock::replacement):
(JSC::WebAssemblyCodeBlock::capabilityLevelInternal):
(JSC::CodeBlock::updateAllPredictions):
(JSC::CodeBlock::insertBasicBlockBoundariesForControlFlowProfiler):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::ownerExecutable):
(JSC::CodeBlock::ownerScriptExecutable):
(JSC::CodeBlock::codeType):
(JSC::WebAssemblyCodeBlock::WebAssemblyCodeBlock):

  • debugger/Debugger.cpp:

(JSC::Debugger::toggleBreakpoint):

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::sourceIDForCallFrame):

  • dfg/DFGByteCodeParser.cpp:

(JSC::DFG::ByteCodeParser::InlineStackEntry::executable):
(JSC::DFG::ByteCodeParser::inliningCost):
(JSC::DFG::ByteCodeParser::InlineStackEntry::InlineStackEntry):
(JSC::DFG::ByteCodeParser::parseCodeBlock):

  • dfg/DFGCapabilities.cpp:

(JSC::DFG::isSupportedForInlining):

  • dfg/DFGGraph.h:

(JSC::DFG::Graph::executableFor):

  • dfg/DFGOSREntry.cpp:

(JSC::DFG::prepareOSREntry):

  • inspector/ScriptCallStackFactory.cpp:

(Inspector::CreateScriptCallStackFunctor::operator()):

  • interpreter/Interpreter.cpp:

(JSC::eval):
(JSC::isWebAssemblyExecutable):
(JSC::GetStackTraceFunctor::operator()):
(JSC::UnwindFunctor::operator()):

  • interpreter/StackVisitor.cpp:

(JSC::StackVisitor::Frame::sourceURL):
(JSC::StackVisitor::Frame::computeLineAndColumn):

  • jit/JITOperations.cpp:
  • jit/Repatch.cpp:

(JSC::isWebAssemblyExecutable):
(JSC::linkPolymorphicCall):

  • llint/LLIntData.cpp:

(JSC::LLInt::Data::performAssertions):

  • llint/LLIntSlowPaths.cpp:

(JSC::LLInt::setUpCall):

  • llint/LowLevelInterpreter.asm:
  • runtime/CommonSlowPaths.cpp:

(JSC::SLOW_PATH_DECL):

  • runtime/Executable.cpp:

(JSC::WebAssemblyExecutable::WebAssemblyExecutable):
(JSC::WebAssemblyExecutable::destroy):
(JSC::WebAssemblyExecutable::visitChildren):
(JSC::WebAssemblyExecutable::clearCode):
(JSC::WebAssemblyExecutable::prepareForExecution):

  • runtime/Executable.h:

(JSC::ExecutableBase::isEvalExecutable):
(JSC::ExecutableBase::isFunctionExecutable):
(JSC::ExecutableBase::isProgramExecutable):
(JSC::ExecutableBase::isWebAssemblyExecutable):
(JSC::ExecutableBase::clearCodeVirtual):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::create):

  • runtime/JSFunction.h:
  • runtime/JSFunctionInlines.h:

(JSC::JSFunction::JSFunction):
(JSC::JSFunction::isBuiltinFunction):

  • runtime/JSType.h:
  • runtime/VM.cpp:

(JSC::VM::VM):

  • runtime/VM.h:
  • wasm/JSWASMModule.h:

(JSC::JSWASMModule::functions):

  • wasm/WASMFunctionParser.cpp:

(JSC::WASMFunctionParser::compile):

  • wasm/WASMFunctionParser.h:
  • wasm/WASMModuleParser.cpp:

(JSC::WASMModuleParser::WASMModuleParser):
(JSC::WASMModuleParser::parse):
(JSC::WASMModuleParser::parseFunctionDeclarationSection):
(JSC::WASMModuleParser::parseFunctionDefinition):
(JSC::WASMModuleParser::parseExportSection):
(JSC::parseWebAssembly):

  • wasm/WASMModuleParser.h:

Source/WebCore:

No new tests because it's a function rename.

  • testing/Internals.cpp:

(WebCore::Internals::parserMetaData):

Location:
trunk/Source
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r189077 r189079  
     12015-08-27  Sukolsak Sakshuwong  <sukolsak@gmail.com>
     2
     3        Create WebAssembly functions
     4        https://bugs.webkit.org/show_bug.cgi?id=148373
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Create functions from WebAssembly files generated by pack-asmjs
     9        <https://github.com/WebAssembly/polyfill-prototype-1>.
     10        WebAssembly functions created by this patch can only return 0.
     11        Actual code generation will be implemented in subsequent patches.
     12
     13        * bytecode/CodeBlock.cpp:
     14        (JSC::CodeBlock::hash):
     15        (JSC::CodeBlock::sourceCodeForTools):
     16        (JSC::CodeBlock::dumpAssumingJITType):
     17        (JSC::CodeBlock::dumpSource):
     18        (JSC::CodeBlock::CodeBlock):
     19        (JSC::CodeBlock::finalizeUnconditionally):
     20        (JSC::CodeBlock::lineNumberForBytecodeOffset):
     21        (JSC::CodeBlock::expressionRangeForBytecodeOffset):
     22        (JSC::CodeBlock::install):
     23        (JSC::CodeBlock::newReplacement):
     24        (JSC::WebAssemblyCodeBlock::replacement):
     25        (JSC::WebAssemblyCodeBlock::capabilityLevelInternal):
     26        (JSC::CodeBlock::updateAllPredictions):
     27        (JSC::CodeBlock::insertBasicBlockBoundariesForControlFlowProfiler):
     28        * bytecode/CodeBlock.h:
     29        (JSC::CodeBlock::ownerExecutable):
     30        (JSC::CodeBlock::ownerScriptExecutable):
     31        (JSC::CodeBlock::codeType):
     32        (JSC::WebAssemblyCodeBlock::WebAssemblyCodeBlock):
     33        * debugger/Debugger.cpp:
     34        (JSC::Debugger::toggleBreakpoint):
     35        * debugger/DebuggerCallFrame.cpp:
     36        (JSC::DebuggerCallFrame::sourceIDForCallFrame):
     37        * dfg/DFGByteCodeParser.cpp:
     38        (JSC::DFG::ByteCodeParser::InlineStackEntry::executable):
     39        (JSC::DFG::ByteCodeParser::inliningCost):
     40        (JSC::DFG::ByteCodeParser::InlineStackEntry::InlineStackEntry):
     41        (JSC::DFG::ByteCodeParser::parseCodeBlock):
     42        * dfg/DFGCapabilities.cpp:
     43        (JSC::DFG::isSupportedForInlining):
     44        * dfg/DFGGraph.h:
     45        (JSC::DFG::Graph::executableFor):
     46        * dfg/DFGOSREntry.cpp:
     47        (JSC::DFG::prepareOSREntry):
     48        * inspector/ScriptCallStackFactory.cpp:
     49        (Inspector::CreateScriptCallStackFunctor::operator()):
     50        * interpreter/Interpreter.cpp:
     51        (JSC::eval):
     52        (JSC::isWebAssemblyExecutable):
     53        (JSC::GetStackTraceFunctor::operator()):
     54        (JSC::UnwindFunctor::operator()):
     55        * interpreter/StackVisitor.cpp:
     56        (JSC::StackVisitor::Frame::sourceURL):
     57        (JSC::StackVisitor::Frame::computeLineAndColumn):
     58        * jit/JITOperations.cpp:
     59        * jit/Repatch.cpp:
     60        (JSC::isWebAssemblyExecutable):
     61        (JSC::linkPolymorphicCall):
     62        * llint/LLIntData.cpp:
     63        (JSC::LLInt::Data::performAssertions):
     64        * llint/LLIntSlowPaths.cpp:
     65        (JSC::LLInt::setUpCall):
     66        * llint/LowLevelInterpreter.asm:
     67        * runtime/CommonSlowPaths.cpp:
     68        (JSC::SLOW_PATH_DECL):
     69        * runtime/Executable.cpp:
     70        (JSC::WebAssemblyExecutable::WebAssemblyExecutable):
     71        (JSC::WebAssemblyExecutable::destroy):
     72        (JSC::WebAssemblyExecutable::visitChildren):
     73        (JSC::WebAssemblyExecutable::clearCode):
     74        (JSC::WebAssemblyExecutable::prepareForExecution):
     75        * runtime/Executable.h:
     76        (JSC::ExecutableBase::isEvalExecutable):
     77        (JSC::ExecutableBase::isFunctionExecutable):
     78        (JSC::ExecutableBase::isProgramExecutable):
     79        (JSC::ExecutableBase::isWebAssemblyExecutable):
     80        (JSC::ExecutableBase::clearCodeVirtual):
     81        * runtime/JSFunction.cpp:
     82        (JSC::JSFunction::create):
     83        * runtime/JSFunction.h:
     84        * runtime/JSFunctionInlines.h:
     85        (JSC::JSFunction::JSFunction):
     86        (JSC::JSFunction::isBuiltinFunction):
     87        * runtime/JSType.h:
     88        * runtime/VM.cpp:
     89        (JSC::VM::VM):
     90        * runtime/VM.h:
     91        * wasm/JSWASMModule.h:
     92        (JSC::JSWASMModule::functions):
     93        * wasm/WASMFunctionParser.cpp:
     94        (JSC::WASMFunctionParser::compile):
     95        * wasm/WASMFunctionParser.h:
     96        * wasm/WASMModuleParser.cpp:
     97        (JSC::WASMModuleParser::WASMModuleParser):
     98        (JSC::WASMModuleParser::parse):
     99        (JSC::WASMModuleParser::parseFunctionDeclarationSection):
     100        (JSC::WASMModuleParser::parseFunctionDefinition):
     101        (JSC::WASMModuleParser::parseExportSection):
     102        (JSC::parseWebAssembly):
     103        * wasm/WASMModuleParser.h:
     104
    11052015-08-27  Brent Fulgham  <bfulgham@apple.com>
    2106
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r188972 r189079  
    108108    if (!m_hash) {
    109109        RELEASE_ASSERT(isSafeToComputeHash());
    110         m_hash = CodeBlockHash(ownerExecutable()->source(), specializationKind());
     110        m_hash = CodeBlockHash(ownerScriptExecutable()->source(), specializationKind());
    111111    }
    112112    return m_hash;
     
    116116{
    117117    if (codeType() != FunctionCode)
    118         return ownerExecutable()->source().toUTF8();
     118        return ownerScriptExecutable()->source().toUTF8();
    119119   
    120120    SourceProvider* provider = source();
     
    156156    if (this->jitType() == JITCode::BaselineJIT && m_shouldAlwaysBeInlined)
    157157        out.print(" (ShouldAlwaysBeInlined)");
    158     if (ownerExecutable()->neverInline())
     158    if (ownerScriptExecutable()->neverInline())
    159159        out.print(" (NeverInline)");
    160     if (ownerExecutable()->didTryToEnterInLoop())
     160    if (ownerScriptExecutable()->didTryToEnterInLoop())
    161161        out.print(" (DidTryToEnterInLoop)");
    162     if (ownerExecutable()->isStrictMode())
     162    if (ownerScriptExecutable()->isStrictMode())
    163163        out.print(" (StrictMode)");
    164164    if (this->jitType() == JITCode::BaselineJIT && m_didFailFTLCompilation)
     
    553553void CodeBlock::dumpSource(PrintStream& out)
    554554{
    555     ScriptExecutable* executable = ownerExecutable();
     555    ScriptExecutable* executable = ownerScriptExecutable();
    556556    if (executable->isFunctionExecutable()) {
    557557        FunctionExecutable* functionExecutable = reinterpret_cast<FunctionExecutable*>(executable);
     
    17521752
    17531753    if (vm()->typeProfiler() || vm()->controlFlowProfiler())
    1754         vm()->functionHasExecutedCache()->removeUnexecutedRange(m_ownerExecutable->sourceID(), m_ownerExecutable->typeProfilingStartOffset(), m_ownerExecutable->typeProfilingEndOffset());
     1754        vm()->functionHasExecutedCache()->removeUnexecutedRange(ownerExecutable->sourceID(), ownerExecutable->typeProfilingStartOffset(), ownerExecutable->typeProfilingEndOffset());
    17551755
    17561756    setConstantRegisters(unlinkedCodeBlock->constantRegisters(), unlinkedCodeBlock->constantsSourceCodeRepresentation());
     
    17861786        UnlinkedFunctionExecutable* unlinkedExecutable = unlinkedCodeBlock->functionDecl(i);
    17871787        if (vm()->typeProfiler() || vm()->controlFlowProfiler())
    1788             vm()->functionHasExecutedCache()->insertUnexecutedRange(m_ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
     1788            vm()->functionHasExecutedCache()->insertUnexecutedRange(ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
    17891789        m_functionDecls[i].set(*m_vm, ownerExecutable, unlinkedExecutable->link(*m_vm, ownerExecutable->source()));
    17901790    }
     
    17941794        UnlinkedFunctionExecutable* unlinkedExecutable = unlinkedCodeBlock->functionExpr(i);
    17951795        if (vm()->typeProfiler() || vm()->controlFlowProfiler())
    1796             vm()->functionHasExecutedCache()->insertUnexecutedRange(m_ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
     1796            vm()->functionHasExecutedCache()->insertUnexecutedRange(ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
    17971797        m_functionExprs[i].set(*m_vm, ownerExecutable, unlinkedExecutable->link(*m_vm, ownerExecutable->source()));
    17981798    }
     
    19261926            instructions[i + opLength - 1] = objectAllocationProfile;
    19271927            objectAllocationProfile->initialize(*vm(),
    1928                 m_ownerExecutable.get(), m_globalObject->objectPrototype(), inferredInlineCapacity);
     1928                ownerExecutable, m_globalObject->objectPrototype(), inferredInlineCapacity);
    19291929            break;
    19301930        }
     
    21072107                    // Currently, the text offset that is used as identification is "f" in the function keyword
    21082108                    // and is stored on TypeLocation's m_divotForFunctionOffsetIfReturnStatement member variable.
    2109                     divotStart = divotEnd = m_ownerExecutable->typeProfilingStartOffset();
     2109                    divotStart = divotEnd = ownerExecutable->typeProfilingStartOffset();
    21102110                    shouldAnalyze = true;
    21112111                }
     
    21152115
    21162116            std::pair<TypeLocation*, bool> locationPair = vm()->typeProfiler()->typeLocationCache()->getTypeLocation(globalVariableID,
    2117                 m_ownerExecutable->sourceID(), divotStart, divotEnd, globalTypeSet, vm());
     2117                ownerExecutable->sourceID(), divotStart, divotEnd, globalTypeSet, vm());
    21182118            TypeLocation* location = locationPair.first;
    21192119            bool isNewLocation = locationPair.second;
    21202120
    21212121            if (flag == ProfileTypeBytecodeFunctionReturnStatement)
    2122                 location->m_divotForFunctionOffsetIfReturnStatement = m_ownerExecutable->typeProfilingStartOffset();
     2122                location->m_divotForFunctionOffsetIfReturnStatement = ownerExecutable->typeProfilingStartOffset();
    21232123
    21242124            if (shouldAnalyze && isNewLocation)
     
    21632163    m_heap->reportExtraMemoryAllocated(sizeof(CodeBlock) + m_instructions.size() * sizeof(Instruction));
    21642164}
     2165
     2166#if ENABLE(WEBASSEMBLY)
     2167CodeBlock::CodeBlock(WebAssemblyExecutable* ownerExecutable, VM& vm, JSGlobalObject* globalObject)
     2168    : m_globalObject(globalObject->vm(), ownerExecutable, globalObject)
     2169    , m_heap(&m_globalObject->vm().heap)
     2170    , m_numCalleeRegisters(0)
     2171    , m_numVars(0)
     2172    , m_isConstructor(false)
     2173    , m_shouldAlwaysBeInlined(false)
     2174    , m_didFailFTLCompilation(false)
     2175    , m_hasBeenCompiledWithFTL(false)
     2176    , m_hasDebuggerStatement(false)
     2177    , m_steppingMode(SteppingModeDisabled)
     2178    , m_numBreakpoints(0)
     2179    , m_ownerExecutable(m_globalObject->vm(), ownerExecutable, ownerExecutable)
     2180    , m_vm(&vm)
     2181    , m_isStrictMode(false)
     2182    , m_needsActivation(false)
     2183    , m_mayBeExecuting(false)
     2184    , m_codeType(FunctionCode)
     2185    , m_osrExitCounter(0)
     2186    , m_optimizationDelayCounter(0)
     2187    , m_reoptimizationRetryCounter(0)
     2188#if ENABLE(JIT)
     2189    , m_capabilityLevelState(DFG::CannotCompile)
     2190#endif
     2191{
     2192    ASSERT(m_heap->isDeferred());
     2193
     2194    m_heap->m_codeBlocks.add(this);
     2195    m_heap->reportExtraMemoryAllocated(sizeof(CodeBlock));
     2196}
     2197#endif
    21652198
    21662199CodeBlock::~CodeBlock()
     
    25092542{
    25102543    Interpreter* interpreter = m_vm->interpreter;
    2511     if (JITCode::couldBeInterpreted(jitType())) {
     2544    bool ownedByWebAssemblyExecutable = false;
     2545#if ENABLE(WEBASSEMBLY)
     2546    ownedByWebAssemblyExecutable = m_ownerExecutable->isWebAssemblyExecutable();
     2547#endif
     2548    if (JITCode::couldBeInterpreted(jitType()) && !ownedByWebAssemblyExecutable) {
    25122549        const Vector<unsigned>& propertyAccessInstructions = m_unlinkedCode->propertyAccessInstructions();
    25132550        for (size_t size = propertyAccessInstructions.size(), i = 0; i < size; ++i) {
     
    29142951{
    29152952    RELEASE_ASSERT(bytecodeOffset < instructions().size());
    2916     return m_ownerExecutable->firstLine() + m_unlinkedCode->lineNumberForBytecodeOffset(bytecodeOffset);
     2953    return ownerScriptExecutable()->firstLine() + m_unlinkedCode->lineNumberForBytecodeOffset(bytecodeOffset);
    29172954}
    29182955
     
    29332970    divot += m_sourceOffset;
    29342971    column += line ? 1 : firstLineColumnOffset();
    2935     line += m_ownerExecutable->firstLine();
     2972    line += ownerScriptExecutable()->firstLine();
    29362973}
    29372974
     
    30103047void CodeBlock::install()
    30113048{
    3012     ownerExecutable()->installCode(this);
     3049    ownerScriptExecutable()->installCode(this);
    30133050}
    30143051
    30153052PassRefPtr<CodeBlock> CodeBlock::newReplacement()
    30163053{
    3017     return ownerExecutable()->newReplacementCodeBlockFor(specializationKind());
     3054    return ownerScriptExecutable()->newReplacementCodeBlockFor(specializationKind());
    30183055}
    30193056
     
    30503087    return DFG::functionForCallCapabilityLevel(this);
    30513088}
     3089
     3090#if ENABLE(WEBASSEMBLY)
     3091CodeBlock* WebAssemblyCodeBlock::replacement()
     3092{
     3093    return nullptr;
     3094}
     3095
     3096DFG::CapabilityLevel WebAssemblyCodeBlock::capabilityLevelInternal()
     3097{
     3098    return DFG::CannotCompile;
     3099}
     3100#endif
    30523101#endif
    30533102
     
    36023651void CodeBlock::updateAllPredictions()
    36033652{
     3653#if ENABLE(WEBASSEMBLY)
     3654    if (m_ownerExecutable->isWebAssemblyExecutable())
     3655        return;
     3656#endif
    36043657    updateAllValueProfilePredictions();
    36053658    updateAllArrayPredictions();
     
    39193972            basicBlockEndOffset = instructions[endIdx + 1].u.operand - 1;
    39203973        } else {
    3921             basicBlockEndOffset = m_sourceOffset + m_ownerExecutable->source().length() - 1; // Offset before the closing brace.
     3974            basicBlockEndOffset = m_sourceOffset + ownerScriptExecutable()->source().length() - 1; // Offset before the closing brace.
    39223975            basicBlockStartOffset = std::min(basicBlockStartOffset, basicBlockEndOffset); // Some start offsets may be at the closing brace, ensure it is the offset before.
    39233976        }
     
    39474000        }
    39484001
    3949         BasicBlockLocation* basicBlockLocation = vm()->controlFlowProfiler()->getBasicBlockLocation(m_ownerExecutable->sourceID(), basicBlockStartOffset, basicBlockEndOffset);
     4002        BasicBlockLocation* basicBlockLocation = vm()->controlFlowProfiler()->getBasicBlockLocation(ownerScriptExecutable()->sourceID(), basicBlockStartOffset, basicBlockEndOffset);
    39504003
    39514004        // Find all functions that are enclosed within the range: [basicBlockStartOffset, basicBlockEndOffset]
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r188972 r189079  
    9797       
    9898    CodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock*, JSScope*, PassRefPtr<SourceProvider>, unsigned sourceOffset, unsigned firstLineColumnOffset);
     99#if ENABLE(WEBASSEMBLY)
     100    CodeBlock(WebAssemblyExecutable* ownerExecutable, VM&, JSGlobalObject*);
     101#endif
    99102
    100103    WriteBarrier<JSGlobalObject> m_globalObject;
     
    304307    void jettison(Profiler::JettisonReason, ReoptimizationMode = DontCountReoptimization, const FireDetail* = nullptr);
    305308   
    306     ScriptExecutable* ownerExecutable() const { return m_ownerExecutable.get(); }
     309    ExecutableBase* ownerExecutable() const { return m_ownerExecutable.get(); }
     310    ScriptExecutable* ownerScriptExecutable() const { return jsCast<ScriptExecutable*>(m_ownerExecutable.get()); }
    307311
    308312    void setVM(VM* vm) { m_vm = vm; }
     
    347351    }
    348352   
    349     CodeType codeType() const { return m_unlinkedCode->codeType(); }
     353    CodeType codeType() const
     354    {
     355#if ENABLE(WEBASSEMBLY)
     356        if (m_ownerExecutable->isWebAssemblyExecutable())
     357            return FunctionCode;
     358#endif
     359        return m_unlinkedCode->codeType();
     360    }
     361
    350362    PutPropertySlot::Context putByIdContext() const
    351363    {
     
    984996        };
    985997    };
    986     WriteBarrier<ScriptExecutable> m_ownerExecutable;
     998    WriteBarrier<ExecutableBase> m_ownerExecutable;
    987999    VM* m_vm;
    9881000
     
    11351147};
    11361148
     1149#if ENABLE(WEBASSEMBLY)
     1150class WebAssemblyCodeBlock : public CodeBlock {
     1151public:
     1152    WebAssemblyCodeBlock(CopyParsedBlockTag, WebAssemblyCodeBlock& other)
     1153        : CodeBlock(CopyParsedBlock, other)
     1154    {
     1155    }
     1156
     1157    WebAssemblyCodeBlock(WebAssemblyExecutable* ownerExecutable, VM& vm, JSGlobalObject* globalObject)
     1158        : CodeBlock(ownerExecutable, vm, globalObject)
     1159    {
     1160    }
     1161
     1162#if ENABLE(JIT)
     1163protected:
     1164    virtual CodeBlock* replacement() override;
     1165    virtual DFG::CapabilityLevel capabilityLevelInternal() override;
     1166#endif
     1167};
     1168#endif
     1169
    11371170inline Register& ExecState::r(int index)
    11381171{
  • trunk/Source/JavaScriptCore/debugger/Debugger.cpp

    r188846 r189079  
    228228void Debugger::toggleBreakpoint(CodeBlock* codeBlock, Breakpoint& breakpoint, BreakpointState enabledOrNot)
    229229{
    230     ScriptExecutable* executable = codeBlock->ownerExecutable();
     230    ScriptExecutable* executable = codeBlock->ownerScriptExecutable();
    231231
    232232    SourceID sourceID = static_cast<SourceID>(executable->sourceID());
  • trunk/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp

    r186860 r189079  
    243243    if (!codeBlock)
    244244        return noSourceID;
    245     return codeBlock->ownerExecutable()->sourceID();
     245    return codeBlock->ownerScriptExecutable()->sourceID();
    246246}
    247247
  • trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp

    r189009 r189079  
    940940        InlineCallFrame* m_inlineCallFrame;
    941941       
    942         ScriptExecutable* executable() { return m_codeBlock->ownerExecutable(); }
     942        ScriptExecutable* executable() { return m_codeBlock->ownerScriptExecutable(); }
    943943       
    944944        QueryableExitProfile m_exitProfile;
     
    12531253        dataLog("    Might compile function: ", mightCompileFunctionFor(codeBlock, kind), "\n");
    12541254        dataLog("    Is supported for inlining: ", isSupportedForInlining(codeBlock), "\n");
    1255         dataLog("    Needs activation: ", codeBlock->ownerExecutable()->needsActivation(), "\n");
    1256         dataLog("    Is inlining candidate: ", codeBlock->ownerExecutable()->isInliningCandidate(), "\n");
     1255        dataLog("    Needs activation: ", codeBlock->ownerScriptExecutable()->needsActivation(), "\n");
     1256        dataLog("    Is inlining candidate: ", codeBlock->ownerScriptExecutable()->isInliningCandidate(), "\n");
    12571257    }
    12581258    if (!canInline(capabilityLevel)) {
     
    44374437        // The owner is the machine code block, and we already have a barrier on that when the
    44384438        // plan finishes.
    4439         m_inlineCallFrame->executable.setWithoutWriteBarrier(codeBlock->ownerExecutable());
     4439        m_inlineCallFrame->executable.setWithoutWriteBarrier(codeBlock->ownerScriptExecutable());
    44404440        m_inlineCallFrame->setStackOffset(inlineCallFrameStart.offset() - JSStack::CallFrameHeaderSize);
    44414441        if (callee) {
     
    45304530        dataLog(
    45314531            ": needsActivation = ", codeBlock->needsActivation(),
    4532             ", isStrictMode = ", codeBlock->ownerExecutable()->isStrictMode(), "\n");
     4532            ", isStrictMode = ", codeBlock->ownerScriptExecutable()->isStrictMode(), "\n");
    45334533        codeBlock->baselineVersion()->dumpBytecode();
    45344534    }
  • trunk/Source/JavaScriptCore/dfg/DFGCapabilities.cpp

    r188545 r189079  
    4545bool isSupportedForInlining(CodeBlock* codeBlock)
    4646{
    47     return codeBlock->ownerExecutable()->isInliningCandidate();
     47#if ENABLE(WEBASSEMBLY)
     48    if (codeBlock->ownerExecutable()->isWebAssemblyExecutable())
     49        return false;
     50#endif
     51    return codeBlock->ownerScriptExecutable()->isInliningCandidate();
    4852}
    4953
  • trunk/Source/JavaScriptCore/dfg/DFGGraph.h

    r188979 r189079  
    346346    {
    347347        if (!inlineCallFrame)
    348             return m_codeBlock->ownerExecutable();
     348            return m_codeBlock->ownerScriptExecutable();
    349349       
    350350        return inlineCallFrame->executable.get();
  • trunk/Source/JavaScriptCore/dfg/DFGOSREntry.cpp

    r188311 r189079  
    113113   
    114114    if (bytecodeIndex)
    115         codeBlock->ownerExecutable()->setDidTryToEnterInLoop(true);
     115        codeBlock->ownerScriptExecutable()->setDidTryToEnterInLoop(true);
    116116   
    117117    if (codeBlock->jitType() != JITCode::DFGJIT) {
  • trunk/Source/JavaScriptCore/inspector/ScriptCallStackFactory.cpp

    r185532 r189079  
    6767
    6868        if (m_remainingCapacityForFrameCapture) {
     69#if ENABLE(WEBASSEMBLY)
     70            if (visitor->codeBlock()->ownerExecutable()->isWebAssemblyExecutable())
     71                return StackVisitor::Continue;
     72#endif
    6973            unsigned line;
    7074            unsigned column;
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r189009 r189079  
    169169
    170170        ThisTDZMode thisTDZMode = callerCodeBlock->unlinkedCodeBlock()->constructorKind() == ConstructorKind::Derived ? ThisTDZMode::AlwaysCheck : ThisTDZMode::CheckIfNeeded;
    171         eval = callerCodeBlock->evalCodeCache().getSlow(callFrame, callerCodeBlock->ownerExecutable(), callerCodeBlock->isStrictMode(), thisTDZMode, programSource, callerScopeChain);
     171        eval = callerCodeBlock->evalCodeCache().getSlow(callFrame, callerCodeBlock->ownerScriptExecutable(), callerCodeBlock->isStrictMode(), thisTDZMode, programSource, callerScopeChain);
    172172        if (!eval)
    173173            return jsUndefined();
     
    516516}
    517517
     518static inline bool isWebAssemblyExecutable(ExecutableBase* executable)
     519{
     520#if !ENABLE(WEBASSEMBLY)
     521    UNUSED_PARAM(executable);
     522    return false;
     523#else
     524    return executable->isWebAssemblyExecutable();
     525#endif
     526}
     527
    518528class GetStackTraceFunctor {
    519529public:
     
    529539        VM& vm = m_vm;
    530540        if (m_remainingCapacityForFrameCapture) {
    531             if (visitor->isJSFrame() && !visitor->codeBlock()->unlinkedCodeBlock()->isBuiltinFunction()) {
     541            if (visitor->isJSFrame()
     542                && !isWebAssemblyExecutable(visitor->codeBlock()->ownerExecutable())
     543                && !visitor->codeBlock()->unlinkedCodeBlock()->isBuiltinFunction()) {
    532544                CodeBlock* codeBlock = visitor->codeBlock();
    533545                StackFrame s = {
    534546                    Strong<JSObject>(vm, visitor->callee()),
    535547                    getStackFrameCodeType(visitor),
    536                     Strong<ScriptExecutable>(vm, codeBlock->ownerExecutable()),
     548                    Strong<ScriptExecutable>(vm, codeBlock->ownerScriptExecutable()),
    537549                    Strong<UnlinkedCodeBlock>(vm, codeBlock->unlinkedCodeBlock()),
    538550                    codeBlock->source(),
    539                     codeBlock->ownerExecutable()->firstLine(),
     551                    codeBlock->ownerScriptExecutable()->firstLine(),
    540552                    codeBlock->firstLineColumnOffset(),
    541553                    codeBlock->sourceOffset(),
     
    630642        unsigned bytecodeOffset = visitor->bytecodeOffset();
    631643
    632         if (m_isTermination || !(m_handler = m_codeBlock ? m_codeBlock->handlerForBytecodeOffset(bytecodeOffset) : nullptr)) {
     644        if (m_isTermination || !(m_handler = (m_codeBlock && !isWebAssemblyExecutable(m_codeBlock->ownerExecutable())) ? m_codeBlock->handlerForBytecodeOffset(bytecodeOffset) : nullptr)) {
    633645            if (!unwindCallFrame(visitor)) {
    634646                if (LegacyProfiler* profiler = vm.enabledProfiler())
  • trunk/Source/JavaScriptCore/interpreter/StackVisitor.cpp

    r188932 r189079  
    222222    case CodeType::Function:
    223223    case CodeType::Global: {
    224         String sourceURL = codeBlock()->ownerExecutable()->sourceURL();
     224        String sourceURL = codeBlock()->ownerScriptExecutable()->sourceURL();
    225225        if (!sourceURL.isEmpty())
    226226            traceLine = sourceURL.impl();
     
    293293    retrieveExpressionInfo(divot, unusedStartOffset, unusedEndOffset, divotLine, divotColumn);
    294294
    295     line = divotLine + codeBlock->ownerExecutable()->firstLine();
     295    line = divotLine + codeBlock->ownerScriptExecutable()->firstLine();
    296296    column = divotColumn + (divotLine ? 1 : codeBlock->firstLineColumnOffset());
    297297
    298     if (codeBlock->ownerExecutable()->hasOverrideLineNumber())
    299         line = codeBlock->ownerExecutable()->overrideLineNumber();
     298    if (codeBlock->ownerScriptExecutable()->hasOverrideLineNumber())
     299        line = codeBlock->ownerScriptExecutable()->overrideLineNumber();
    300300}
    301301
  • trunk/Source/JavaScriptCore/jit/JITOperations.cpp

    r189009 r189079  
    849849    MacroAssemblerCodePtr codePtr;
    850850    CodeBlock* codeBlock = 0;
    851     if (executable->isHostFunction())
     851    if (executable->isHostFunction()) {
    852852        codePtr = executable->entrypointFor(*vm, kind, MustCheckArity, callLinkInfo->registerPreservationMode());
    853     else {
     853#if ENABLE(WEBASSEMBLY)
     854    } else if (executable->isWebAssemblyExecutable()) {
     855        WebAssemblyExecutable* webAssemblyExecutable = static_cast<WebAssemblyExecutable*>(executable);
     856        webAssemblyExecutable->prepareForExecution(execCallee);
     857        codeBlock = webAssemblyExecutable->codeBlockForCall();
     858        ASSERT(codeBlock);
     859        ArityCheckMode arity;
     860        if (execCallee->argumentCountIncludingThis() < static_cast<size_t>(codeBlock->numParameters()))
     861            arity = MustCheckArity;
     862        else
     863            arity = ArityCheckNotRequired;
     864        codePtr = webAssemblyExecutable->entrypointFor(*vm, kind, arity, callLinkInfo->registerPreservationMode());
     865#endif
     866    } else {
    854867        FunctionExecutable* functionExecutable = static_cast<FunctionExecutable*>(executable);
    855868
     
    897910    ExecutableBase* executable = function->executable();
    898911    if (UNLIKELY(!executable->hasJITCodeFor(kind))) {
    899         FunctionExecutable* functionExecutable = static_cast<FunctionExecutable*>(executable);
    900 
    901         if (!isCall(kind) && functionExecutable->constructAbility() == ConstructAbility::CannotConstruct) {
    902             exec->vm().throwException(exec, createNotAConstructorError(exec, function));
    903             return reinterpret_cast<char*>(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress());
    904         }
    905 
    906         JSObject* error = functionExecutable->prepareForExecution(execCallee, function, scope, kind);
    907         if (error) {
    908             exec->vm().throwException(exec, error);
    909             return reinterpret_cast<char*>(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress());
     912        bool isWebAssemblyExecutable = false;
     913#if ENABLE(WEBASSEMBLY)
     914        isWebAssemblyExecutable = executable->isWebAssemblyExecutable();
     915#endif
     916        if (!isWebAssemblyExecutable) {
     917            FunctionExecutable* functionExecutable = static_cast<FunctionExecutable*>(executable);
     918
     919            if (!isCall(kind) && functionExecutable->constructAbility() == ConstructAbility::CannotConstruct) {
     920                exec->vm().throwException(exec, createNotAConstructorError(exec, function));
     921                return reinterpret_cast<char*>(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress());
     922            }
     923
     924            JSObject* error = functionExecutable->prepareForExecution(execCallee, function, scope, kind);
     925            if (error) {
     926                exec->vm().throwException(exec, error);
     927                return reinterpret_cast<char*>(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress());
     928            }
     929        } else {
     930#if ENABLE(WEBASSEMBLY)
     931            if (!isCall(kind)) {
     932                exec->vm().throwException(exec, createNotAConstructorError(exec, function));
     933                return reinterpret_cast<char*>(vm->getCTIStub(throwExceptionFromCallSlowPathGenerator).code().executableAddress());
     934            }
     935
     936            WebAssemblyExecutable* webAssemblyExecutable = static_cast<WebAssemblyExecutable*>(executable);
     937            webAssemblyExecutable->prepareForExecution(execCallee);
     938#endif
    910939        }
    911940    }
  • trunk/Source/JavaScriptCore/jit/Repatch.cpp

    r188932 r189079  
    17431743            codeBlock = nullptr;
    17441744        else {
    1745             codeBlock = jsCast<FunctionExecutable*>(variant.executable())->codeBlockForCall();
    1746            
     1745            ExecutableBase* executable = variant.executable();
     1746#if ENABLE(WEBASSEMBLY)
     1747            if (executable->isWebAssemblyExecutable())
     1748                codeBlock = jsCast<WebAssemblyExecutable*>(executable)->codeBlockForCall();
     1749            else
     1750#endif
     1751                codeBlock = jsCast<FunctionExecutable*>(executable)->codeBlockForCall();
    17471752            // If we cannot handle a callee, assume that it's better for this whole thing to be a
    17481753            // virtual call.
  • trunk/Source/JavaScriptCore/llint/LLIntData.cpp

    r182878 r189079  
    133133#endif
    134134    ASSERT(StringType == 6);
    135     ASSERT(ObjectType == 18);
    136     ASSERT(FinalObjectType == 19);
     135    ASSERT(ObjectType == 19);
     136    ASSERT(FinalObjectType == 20);
    137137    ASSERT(MasqueradesAsUndefined == 1);
    138138    ASSERT(ImplementsHasInstance == 2);
  • trunk/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp

    r189009 r189079  
    11171117    MacroAssemblerCodePtr codePtr;
    11181118    CodeBlock* codeBlock = 0;
    1119     if (executable->isHostFunction())
     1119    bool isWebAssemblyExecutable = false;
     1120#if ENABLE(WEBASSEMBLY)
     1121    isWebAssemblyExecutable = executable->isWebAssemblyExecutable();
     1122#endif
     1123
     1124    if (executable->isHostFunction()) {
    11201125        codePtr = executable->entrypointFor(vm, kind, MustCheckArity, RegisterPreservationNotRequired);
    1121     else {
     1126    } else if (!isWebAssemblyExecutable) {
    11221127        FunctionExecutable* functionExecutable = static_cast<FunctionExecutable*>(executable);
    11231128
     
    11361141            arity = ArityCheckNotRequired;
    11371142        codePtr = functionExecutable->entrypointFor(vm, kind, arity, RegisterPreservationNotRequired);
     1143    } else {
     1144#if ENABLE(WEBASSEMBLY)
     1145        WebAssemblyExecutable* webAssemblyExecutable = static_cast<WebAssemblyExecutable*>(executable);
     1146        webAssemblyExecutable->prepareForExecution(execCallee);
     1147        codeBlock = webAssemblyExecutable->codeBlockForCall();
     1148        ASSERT(codeBlock);
     1149        ArityCheckMode arity;
     1150        if (execCallee->argumentCountIncludingThis() < static_cast<size_t>(codeBlock->numParameters()))
     1151            arity = MustCheckArity;
     1152        else
     1153            arity = ArityCheckNotRequired;
     1154        codePtr = webAssemblyExecutable->entrypointFor(vm, kind, arity, RegisterPreservationNotRequired);
     1155#endif
    11381156    }
    11391157   
  • trunk/Source/JavaScriptCore/llint/LowLevelInterpreter.asm

    r188545 r189079  
    162162# Type constants.
    163163const StringType = 6
    164 const ObjectType = 18
    165 const FinalObjectType = 19
     164const ObjectType = 19
     165const FinalObjectType = 20
    166166
    167167# Type flags constants.
  • trunk/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp

    r188136 r189079  
    526526{
    527527    BEGIN();
    528     ScriptExecutable* ownerExecutable = exec->codeBlock()->ownerExecutable();
     528    ExecutableBase* ownerExecutable = exec->codeBlock()->ownerExecutable();
    529529    Heap::heap(ownerExecutable)->writeBarrier(ownerExecutable);
    530530    END();
  • trunk/Source/JavaScriptCore/runtime/Executable.cpp

    r188972 r189079  
    3232#include "JIT.h"
    3333#include "JSCInlines.h"
     34#include "JSWASMModule.h"
    3435#include "LLIntEntrypoint.h"
    3536#include "Parser.h"
    3637#include "ProfilerDatabase.h"
    3738#include "TypeProfiler.h"
     39#include "WASMFunctionParser.h"
    3840#include <wtf/CommaPrinter.h>
    3941#include <wtf/Vector.h>
     
    563565}
    564566
     567#if ENABLE(WEBASSEMBLY)
     568const ClassInfo WebAssemblyExecutable::s_info = { "WebAssemblyExecutable", &ExecutableBase::s_info, 0, CREATE_METHOD_TABLE(WebAssemblyExecutable) };
     569
     570WebAssemblyExecutable::WebAssemblyExecutable(VM& vm, const SourceCode& source, JSWASMModule* module, unsigned functionIndex)
     571    : ExecutableBase(vm, vm.webAssemblyExecutableStructure.get(), NUM_PARAMETERS_NOT_COMPILED)
     572    , m_source(source)
     573    , m_module(vm, this, module)
     574    , m_functionIndex(functionIndex)
     575{
     576}
     577
     578void WebAssemblyExecutable::destroy(JSCell* cell)
     579{
     580    static_cast<WebAssemblyExecutable*>(cell)->WebAssemblyExecutable::~WebAssemblyExecutable();
     581}
     582
     583void WebAssemblyExecutable::visitChildren(JSCell* cell, SlotVisitor& visitor)
     584{
     585    WebAssemblyExecutable* thisObject = jsCast<WebAssemblyExecutable*>(cell);
     586    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
     587    ExecutableBase::visitChildren(thisObject, visitor);
     588    if (thisObject->m_codeBlockForCall)
     589        thisObject->m_codeBlockForCall->visitAggregate(visitor);
     590    visitor.append(&thisObject->m_module);
     591}
     592
     593void WebAssemblyExecutable::clearCode()
     594{
     595    m_codeBlockForCall = nullptr;
     596    Base::clearCode();
     597}
     598
     599void WebAssemblyExecutable::prepareForExecution(ExecState* exec)
     600{
     601    if (hasJITCodeForCall())
     602        return;
     603
     604    VM& vm = exec->vm();
     605    DeferGC deferGC(vm.heap);
     606
     607    RefPtr<WebAssemblyCodeBlock> codeBlock = adoptRef(new WebAssemblyCodeBlock(
     608        this, vm, exec->lexicalGlobalObject()));
     609
     610    WASMFunctionParser::compile(vm, codeBlock.get(), m_module.get(), m_source, m_functionIndex);
     611
     612    m_jitCodeForCall = codeBlock->jitCode();
     613    m_jitCodeForCallWithArityCheck = MacroAssemblerCodePtr();
     614    m_jitCodeForCallWithArityCheckAndPreserveRegs = MacroAssemblerCodePtr();
     615    m_numParametersForCall = codeBlock->numParameters();
     616
     617    m_codeBlockForCall = codeBlock;
     618
     619    Heap::heap(this)->writeBarrier(this);
     620}
     621#endif
     622
    565623void ExecutableBase::dump(PrintStream& out) const
    566624{
  • trunk/Source/JavaScriptCore/runtime/Executable.h

    r188972 r189079  
    5151class EvalCodeBlock;
    5252class FunctionCodeBlock;
     53class JSScope;
     54class JSWASMModule;
    5355class LLIntOffsetsExtractor;
    5456class ProgramCodeBlock;
    55 class JSScope;
     57class WebAssemblyCodeBlock;
    5658   
    5759enum CompilationKind { FirstCompilation, OptimizingCompilation };
     
    9395    CodeBlockHash hashFor(CodeSpecializationKind) const;
    9496
    95     bool isEvalExecutable()
     97    bool isEvalExecutable() const
    9698    {
    9799        return type() == EvalExecutableType;
    98100    }
    99     bool isFunctionExecutable()
     101    bool isFunctionExecutable() const
    100102    {
    101103        return type() == FunctionExecutableType;
    102104    }
    103     bool isProgramExecutable()
     105    bool isProgramExecutable() const
    104106    {
    105107        return type() == ProgramExecutableType;
     
    111113        return m_numParametersForCall == NUM_PARAMETERS_IS_HOST;
    112114    }
     115
     116#if ENABLE(WEBASSEMBLY)
     117    bool isWebAssemblyExecutable() const
     118    {
     119        return type() == WebAssemblyExecutableType;
     120    }
     121#endif
    113122
    114123    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto) { return Structure::create(vm, globalObject, proto, TypeInfo(CellType, StructureFlags), info()); }
     
    559568    static void destroy(JSCell*);
    560569       
    561     UnlinkedFunctionExecutable* unlinkedExecutable()
     570    UnlinkedFunctionExecutable* unlinkedExecutable() const
    562571    {
    563572        return m_unlinkedExecutable.get();
     
    673682};
    674683
     684#if ENABLE(WEBASSEMBLY)
     685class WebAssemblyExecutable final : public ExecutableBase {
     686public:
     687    typedef ExecutableBase Base;
     688    static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
     689
     690    static WebAssemblyExecutable* create(VM& vm, const SourceCode& source, JSWASMModule* module, unsigned functionIndex)
     691    {
     692        WebAssemblyExecutable* executable = new (NotNull, allocateCell<WebAssemblyExecutable>(vm.heap)) WebAssemblyExecutable(vm, source, module, functionIndex);
     693        executable->finishCreation(vm);
     694        return executable;
     695    }
     696
     697    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
     698    {
     699        return Structure::create(vm, globalObject, proto, TypeInfo(WebAssemblyExecutableType, StructureFlags), info());
     700    }
     701
     702    static void destroy(JSCell*);
     703
     704    DECLARE_INFO;
     705
     706    void clearCode();
     707
     708    void prepareForExecution(ExecState*);
     709
     710    WebAssemblyCodeBlock* codeBlockForCall()
     711    {
     712        return m_codeBlockForCall.get();
     713    }
     714
     715private:
     716    WebAssemblyExecutable(VM&, const SourceCode&, JSWASMModule*, unsigned functionIndex);
     717
     718    static void visitChildren(JSCell*, SlotVisitor&);
     719
     720    SourceCode m_source;
     721    WriteBarrier<JSWASMModule> m_module;
     722    unsigned m_functionIndex;
     723
     724    RefPtr<WebAssemblyCodeBlock> m_codeBlockForCall;
     725};
     726#endif
     727
    675728inline void ExecutableBase::clearCodeVirtual(ExecutableBase* executable)
    676729{
     
    682735    case FunctionExecutableType:
    683736        return jsCast<FunctionExecutable*>(executable)->clearCode();
     737#if ENABLE(WEBASSEMBLY)
     738    case WebAssemblyExecutableType:
     739        return jsCast<WebAssemblyExecutable*>(executable)->clearCode();
     740#endif
    684741    default:
    685742        return jsCast<NativeExecutable*>(executable)->clearCode();
  • trunk/Source/JavaScriptCore/runtime/JSFunction.cpp

    r187205 r189079  
    6767    return result;
    6868}
     69
     70#if ENABLE(WEBASSEMBLY)
     71JSFunction* JSFunction::create(VM& vm, WebAssemblyExecutable* executable, JSScope* scope)
     72{
     73    JSFunction* function = new (NotNull, allocateCell<JSFunction>(vm.heap)) JSFunction(vm, executable, scope);
     74    ASSERT(function->structure()->globalObject());
     75    function->finishCreation(vm);
     76    return function;
     77}
     78#endif
    6979
    7080static inline NativeExecutable* getNativeExecutable(VM& vm, NativeFunction nativeFunction, Intrinsic intrinsic, NativeFunction nativeConstructor)
  • trunk/Source/JavaScriptCore/runtime/JSFunction.h

    r188545 r189079  
    4141class NativeExecutable;
    4242class SourceCode;
     43class WebAssemblyExecutable;
    4344namespace DFG {
    4445class SpeculativeJIT;
     
    7475
    7576    static JSFunction* create(VM&, FunctionExecutable*, JSScope*);
     77#if ENABLE(WEBASSEMBLY)
     78    static JSFunction* create(VM&, WebAssemblyExecutable*, JSScope*);
     79#endif
    7680
    7781    static JSFunction* createBuiltinFunction(VM&, FunctionExecutable*, JSGlobalObject*);
     
    144148    JSFunction(VM&, FunctionExecutable*, JSScope*, Structure*);
    145149
     150#if ENABLE(WEBASSEMBLY)
     151    JSFunction(VM&, WebAssemblyExecutable*, JSScope*);
     152#endif
     153
    146154    void finishCreation(VM&, NativeExecutable*, int length, const String& name);
    147155    using Base::finishCreation;
  • trunk/Source/JavaScriptCore/runtime/JSFunctionInlines.h

    r188545 r189079  
    5353}
    5454
     55#if ENABLE(WEBASSEMBLY)
     56inline JSFunction::JSFunction(VM& vm, WebAssemblyExecutable* executable, JSScope* scope)
     57    : Base(vm, scope, scope->globalObject()->functionStructure())
     58    , m_executable(vm, this, executable)
     59    , m_rareData()
     60{
     61}
     62#endif
     63
    5564inline FunctionExecutable* JSFunction::jsExecutable() const
    5665{
     
    6776inline bool JSFunction::isBuiltinFunction() const
    6877{
     78#if ENABLE(WEBASSEMBLY)
     79    if (m_executable->isWebAssemblyExecutable())
     80        return false;
     81#endif
    6982    return !isHostFunction() && jsExecutable()->isBuiltinFunction();
    7083}
  • trunk/Source/JavaScriptCore/runtime/JSType.h

    r181993 r189079  
    4343    ProgramExecutableType,
    4444    FunctionExecutableType,
     45    WebAssemblyExecutableType,
    4546
    4647    UnlinkedFunctionExecutableType,
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r189009 r189079  
    222222    programExecutableStructure.set(*this, ProgramExecutable::createStructure(*this, 0, jsNull()));
    223223    functionExecutableStructure.set(*this, FunctionExecutable::createStructure(*this, 0, jsNull()));
     224#if ENABLE(WEBASSEMBLY)
     225    webAssemblyExecutableStructure.set(*this, WebAssemblyExecutable::createStructure(*this, 0, jsNull()));
     226#endif
    224227    regExpStructure.set(*this, RegExp::createStructure(*this, 0, jsNull()));
    225228    symbolStructure.set(*this, Symbol::createStructure(*this, 0, jsNull()));
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r189009 r189079  
    280280    Strong<Structure> programExecutableStructure;
    281281    Strong<Structure> functionExecutableStructure;
     282#if ENABLE(WEBASSEMBLY)
     283    Strong<Structure> webAssemblyExecutableStructure;
     284#endif
    282285    Strong<Structure> regExpStructure;
    283286    Strong<Structure> symbolStructure;
  • trunk/Source/JavaScriptCore/wasm/JSWASMModule.h

    r188099 r189079  
    6565    Vector<WASMFunctionPointerTable>& functionPointerTables() { return m_functionPointerTables; }
    6666
     67    Vector<WriteBarrier<JSFunction>>& functions() { return m_functions; }
     68
    6769private:
    6870    JSWASMModule(VM& vm, Structure* structure)
  • trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp

    r188808 r189079  
    2929#if ENABLE(WEBASSEMBLY)
    3030
     31#include "CCallHelpers.h"
    3132#include "JSWASMModule.h"
     33#include "LinkBuffer.h"
    3234#include "WASMFunctionSyntaxChecker.h"
    3335
     
    5860    endOffsetInSource = parser.m_reader.offset();
    5961    return true;
     62}
     63
     64void WASMFunctionParser::compile(VM& vm, CodeBlock* codeBlock, JSWASMModule* module, const SourceCode&, size_t functionIndex)
     65{
     66    // FIXME: Actually compile the code.
     67    CCallHelpers jit(&vm, codeBlock);
     68    MacroAssembler::Label beginLabel = jit.label();
     69    jit.move(MacroAssembler::TrustedImm64(JSValue::encode(jsNumber(0))), GPRInfo::returnValueGPR);
     70    jit.ret();
     71    MacroAssembler::Label arityCheck = jit.label();
     72    jit.jump(beginLabel);
     73
     74    LinkBuffer patchBuffer(vm, jit, codeBlock, JITCompilationMustSucceed);
     75    MacroAssemblerCodePtr withArityCheck = patchBuffer.locationOf(arityCheck);
     76    MacroAssembler::CodeRef result = FINALIZE_CODE(patchBuffer, ("Baseline JIT code for WebAssembly"));
     77    codeBlock->setJITCode(adoptRef(new DirectJITCode(result, withArityCheck, JITCode::BaselineJIT)));
     78    codeBlock->capabilityLevel();
     79
     80    uint32_t signatureIndex = module->functionDeclarations()[functionIndex].signatureIndex;
     81    const WASMSignature& signature = module->signatures()[signatureIndex];
     82    codeBlock->setNumParameters(1 + signature.arguments.size());
    6083}
    6184
  • trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h

    r188808 r189079  
    3737namespace JSC {
    3838
     39class CodeBlock;
    3940class JSWASMModule;
     41class VM;
    4042
    4143class WASMFunctionParser {
    4244public:
    4345    static bool checkSyntax(JSWASMModule*, const SourceCode&, size_t functionIndex, unsigned startOffsetInSource, unsigned& endOffsetInSource, String& errorMessage);
     46    static void compile(VM&, CodeBlock*, JSWASMModule*, const SourceCode&, size_t functionIndex);
    4447
    4548private:
  • trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp

    r188778 r189079  
    5050namespace JSC {
    5151
    52 WASMModuleParser::WASMModuleParser(const SourceCode& source)
    53     : m_source(source)
     52WASMModuleParser::WASMModuleParser(VM& vm, JSGlobalObject* globalObject, const SourceCode& source)
     53    : m_vm(vm)
     54    , m_globalObject(vm, globalObject)
     55    , m_source(source)
    5456    , m_reader(static_cast<WebAssemblySourceProvider*>(source.provider())->data())
    5557{
    5658}
    5759
    58 JSWASMModule* WASMModuleParser::parse(VM& vm, JSGlobalObject* globalObject, String& errorMessage)
    59 {
    60     m_module.set(vm, JSWASMModule::create(vm, globalObject->wasmModuleStructure()));
     60JSWASMModule* WASMModuleParser::parse(String& errorMessage)
     61{
     62    m_module.set(m_vm, JSWASMModule::create(m_vm, m_globalObject->wasmModuleStructure()));
    6163    parseModule();
    6264    if (!m_errorMessage.isNull()) {
     
    218220    READ_COMPACT_UINT32_OR_FAIL(numberOfFunctionDeclarations, "Cannot read the number of function declarations.");
    219221    m_module->functionDeclarations().reserveInitialCapacity(numberOfFunctionDeclarations);
     222    m_module->functions().reserveInitialCapacity(numberOfFunctionDeclarations);
    220223    for (uint32_t i = 0; i < numberOfFunctionDeclarations; ++i) {
    221224        WASMFunctionDeclaration functionDeclaration;
     
    266269    }
    267270    m_reader.setOffset(endOffsetInSource);
     271
     272    WebAssemblyExecutable* webAssemblyExecutable = WebAssemblyExecutable::create(m_vm, m_source, m_module.get(), functionIndex);
     273    JSFunction* function = JSFunction::create(m_vm, webAssemblyExecutable, m_globalObject.get());
     274    m_module->functions().uncheckedAppend(WriteBarrier<JSFunction>(m_vm, m_module.get(), function));
    268275}
    269276
     
    286293            String exportName;
    287294            READ_STRING_OR_FAIL(exportName, "Cannot read the function export name.");
    288             // FIXME: Check that exportName is legal.
    289295            uint32_t functionIndex;
    290296            READ_COMPACT_UINT32_OR_FAIL(functionIndex, "Cannot read the function index.");
    291297            FAIL_IF_FALSE(functionIndex < m_module->functionDeclarations().size(), "The function index is incorrect.");
    292             // FIXME: Export the function.
     298            Identifier identifier = Identifier::fromString(&m_vm, exportName);
     299            m_module->putDirect(m_vm, identifier, m_module->functions()[functionIndex].get());
    293300        }
    294301        break;
     
    301308JSWASMModule* parseWebAssembly(ExecState* exec, const SourceCode& source, String& errorMessage)
    302309{
    303     WASMModuleParser WASMModuleParser(source);
    304     return WASMModuleParser.parse(exec->vm(), exec->lexicalGlobalObject(), errorMessage);
     310    WASMModuleParser moduleParser(exec->vm(), exec->lexicalGlobalObject(), source);
     311    return moduleParser.parse(errorMessage);
    305312}
    306313
  • trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h

    r188778 r189079  
    4343class WASMModuleParser {
    4444public:
    45     WASMModuleParser(const SourceCode&);
    46     JSWASMModule* parse(VM&, JSGlobalObject*, String& errorMessage);
     45    WASMModuleParser(VM&, JSGlobalObject*, const SourceCode&);
     46    JSWASMModule* parse(String& errorMessage);
    4747
    4848private:
     
    5858    void parseExportSection();
    5959
     60    VM& m_vm;
     61    Strong<JSGlobalObject> m_globalObject;
    6062    const SourceCode& m_source;
    6163    WASMReader m_reader;
  • trunk/Source/WebCore/ChangeLog

    r189063 r189079  
     12015-08-27  Sukolsak Sakshuwong  <sukolsak@gmail.com>
     2
     3        Create WebAssembly functions
     4        https://bugs.webkit.org/show_bug.cgi?id=148373
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        No new tests because it's a function rename.
     9
     10        * testing/Internals.cpp:
     11        (WebCore::Internals::parserMetaData):
     12
    1132015-08-27  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/Source/WebCore/testing/Internals.cpp

    r189052 r189079  
    14641464        exec->iterate(iter);
    14651465        CodeBlock* codeBlock = iter.codeBlock();
    1466         executable = codeBlock->ownerExecutable();
     1466        executable = codeBlock->ownerScriptExecutable();
    14671467    } else if (code.isFunction()) {
    14681468        JSFunction* funcObj = JSC::jsCast<JSFunction*>(code.toObject(exec));
Note: See TracChangeset for help on using the changeset viewer.