]> git.saurik.com Git - apple/javascriptcore.git/blob - ftl/FTLOSREntry.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / ftl / FTLOSREntry.cpp
1 /*
2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "FTLOSREntry.h"
28
29 #include "CallFrame.h"
30 #include "CodeBlock.h"
31 #include "DFGJITCode.h"
32 #include "FTLForOSREntryJITCode.h"
33 #include "JSStackInlines.h"
34 #include "OperandsInlines.h"
35 #include "JSCInlines.h"
36
37 #if ENABLE(FTL_JIT)
38
39 namespace JSC { namespace FTL {
40
41 void* prepareOSREntry(
42 ExecState* exec, CodeBlock* dfgCodeBlock, CodeBlock* entryCodeBlock,
43 unsigned bytecodeIndex, unsigned streamIndex)
44 {
45 VM& vm = exec->vm();
46 CodeBlock* baseline = dfgCodeBlock->baselineVersion();
47 ExecutableBase* executable = dfgCodeBlock->ownerExecutable();
48 DFG::JITCode* dfgCode = dfgCodeBlock->jitCode()->dfg();
49 ForOSREntryJITCode* entryCode = entryCodeBlock->jitCode()->ftlForOSREntry();
50
51 if (Options::verboseOSR()) {
52 dataLog(
53 "FTL OSR from ", *dfgCodeBlock, " to ", *entryCodeBlock, " at bc#",
54 bytecodeIndex, ".\n");
55 }
56
57 if (bytecodeIndex)
58 jsCast<ScriptExecutable*>(executable)->setDidTryToEnterInLoop(true);
59
60 if (bytecodeIndex != entryCode->bytecodeIndex()) {
61 if (Options::verboseOSR())
62 dataLog(" OSR failed because we don't have an entrypoint for bc#", bytecodeIndex, "; ours is for bc#", entryCode->bytecodeIndex(), "\n");
63 return 0;
64 }
65
66 Operands<JSValue> values;
67 dfgCode->reconstruct(
68 exec, dfgCodeBlock, CodeOrigin(bytecodeIndex), streamIndex, values);
69
70 if (Options::verboseOSR())
71 dataLog(" Values at entry: ", values, "\n");
72
73 for (int argument = values.numberOfArguments(); argument--;) {
74 JSValue valueOnStack = exec->r(virtualRegisterForArgument(argument).offset()).jsValue();
75 JSValue reconstructedValue = values.argument(argument);
76 if (valueOnStack == reconstructedValue || !argument)
77 continue;
78 dataLog("Mismatch between reconstructed values and the the value on the stack for argument arg", argument, " for ", *entryCodeBlock, " at bc#", bytecodeIndex, ":\n");
79 dataLog(" Value on stack: ", valueOnStack, "\n");
80 dataLog(" Reconstructed value: ", reconstructedValue, "\n");
81 RELEASE_ASSERT_NOT_REACHED();
82 }
83
84 RELEASE_ASSERT(
85 static_cast<int>(values.numberOfLocals()) == baseline->m_numCalleeRegisters);
86
87 EncodedJSValue* scratch = static_cast<EncodedJSValue*>(
88 entryCode->entryBuffer()->dataBuffer());
89
90 for (int local = values.numberOfLocals(); local--;)
91 scratch[local] = JSValue::encode(values.local(local));
92
93 int stackFrameSize = entryCode->common.requiredRegisterCountForExecutionAndExit();
94 if (!vm.interpreter->stack().ensureCapacityFor(&exec->registers()[virtualRegisterForLocal(stackFrameSize - 1).offset()])) {
95 if (Options::verboseOSR())
96 dataLog(" OSR failed because stack growth failed.\n");
97 return 0;
98 }
99
100 exec->setCodeBlock(entryCodeBlock);
101
102 void* result = entryCode->addressForCall(
103 vm, executable, ArityCheckNotRequired,
104 RegisterPreservationNotRequired).executableAddress();
105 if (Options::verboseOSR())
106 dataLog(" Entry will succeed, going to address", RawPointer(result), "\n");
107
108 return result;
109 }
110
111 } } // namespace JSC::FTL
112
113 #endif // ENABLE(FTL_JIT)
114
115