]>
Commit | Line | Data |
---|---|---|
6fe7ccc8 | 1 | /* |
81345200 | 2 | * Copyright (C) 2011, 2012, 2013, 2014 Apple Inc. All rights reserved. |
6fe7ccc8 A |
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 "DFGDriver.h" | |
28 | ||
93a37866 A |
29 | #include "JSObject.h" |
30 | #include "JSString.h" | |
31 | ||
81345200 | 32 | #include "CodeBlock.h" |
ed1e77d3 | 33 | #include "DFGFunctionWhitelist.h" |
81345200 A |
34 | #include "DFGJITCode.h" |
35 | #include "DFGPlan.h" | |
36 | #include "DFGThunks.h" | |
37 | #include "DFGWorklist.h" | |
38 | #include "JITCode.h" | |
39 | #include "JSCInlines.h" | |
93a37866 | 40 | #include "Options.h" |
81345200 | 41 | #include "SamplingTool.h" |
ed1e77d3 | 42 | #include "TypeProfilerLog.h" |
81345200 A |
43 | #include <wtf/Atomics.h> |
44 | ||
45 | #if ENABLE(FTL_JIT) | |
46 | #include "FTLThunks.h" | |
47 | #endif | |
6fe7ccc8 A |
48 | |
49 | namespace JSC { namespace DFG { | |
50 | ||
93a37866 A |
51 | static unsigned numCompilations; |
52 | ||
53 | unsigned getNumCompilations() | |
54 | { | |
55 | return numCompilations; | |
56 | } | |
57 | ||
81345200 A |
58 | #if ENABLE(DFG_JIT) |
59 | static CompilationResult compileImpl( | |
60 | VM& vm, CodeBlock* codeBlock, CodeBlock* profiledDFGCodeBlock, CompilationMode mode, | |
61 | unsigned osrEntryBytecodeIndex, const Operands<JSValue>& mustHandleValues, | |
62 | PassRefPtr<DeferredCompilationCallback> callback) | |
6fe7ccc8 A |
63 | { |
64 | SamplingRegion samplingRegion("DFG Compilation (Driver)"); | |
65 | ||
ed1e77d3 A |
66 | if (!Options::bytecodeRangeToDFGCompile().isInRange(codeBlock->instructionCount()) |
67 | || !FunctionWhitelist::ensureGlobalWhitelist().contains(codeBlock)) | |
68 | return CompilationFailed; | |
69 | ||
93a37866 A |
70 | numCompilations++; |
71 | ||
6fe7ccc8 A |
72 | ASSERT(codeBlock); |
73 | ASSERT(codeBlock->alternative()); | |
81345200 A |
74 | ASSERT(codeBlock->alternative()->jitType() == JITCode::BaselineJIT); |
75 | ASSERT(!profiledDFGCodeBlock || profiledDFGCodeBlock->jitType() == JITCode::DFGJIT); | |
93a37866 | 76 | |
81345200 A |
77 | if (logCompilationChanges(mode)) |
78 | dataLog("DFG(Driver) compiling ", *codeBlock, " with ", mode, ", number of instructions = ", codeBlock->instructionCount(), "\n"); | |
6fe7ccc8 | 79 | |
81345200 A |
80 | // Make sure that any stubs that the DFG is going to use are initialized. We want to |
81 | // make sure that all JIT code generation does finalization on the main thread. | |
82 | vm.getCTIStub(osrExitGenerationThunkGenerator); | |
83 | vm.getCTIStub(throwExceptionFromCallSlowPathGenerator); | |
84 | if (mode == DFGMode) { | |
85 | vm.getCTIStub(linkCallThunkGenerator); | |
86 | vm.getCTIStub(linkConstructThunkGenerator); | |
ed1e77d3 | 87 | vm.getCTIStub(linkPolymorphicCallThunkGenerator); |
81345200 A |
88 | vm.getCTIStub(virtualCallThunkGenerator); |
89 | vm.getCTIStub(virtualConstructThunkGenerator); | |
90 | } else { | |
91 | vm.getCTIStub(linkCallThatPreservesRegsThunkGenerator); | |
92 | vm.getCTIStub(linkConstructThatPreservesRegsThunkGenerator); | |
ed1e77d3 | 93 | vm.getCTIStub(linkPolymorphicCallThatPreservesRegsThunkGenerator); |
81345200 A |
94 | vm.getCTIStub(virtualCallThatPreservesRegsThunkGenerator); |
95 | vm.getCTIStub(virtualConstructThatPreservesRegsThunkGenerator); | |
93a37866 A |
96 | } |
97 | ||
ed1e77d3 A |
98 | if (vm.typeProfiler()) |
99 | vm.typeProfilerLog()->processLogEntries(ASCIILiteral("Preparing for DFG compilation.")); | |
100 | ||
81345200 A |
101 | RefPtr<Plan> plan = adoptRef( |
102 | new Plan(codeBlock, profiledDFGCodeBlock, mode, osrEntryBytecodeIndex, mustHandleValues)); | |
93a37866 | 103 | |
ed1e77d3 | 104 | plan->callback = callback; |
81345200 A |
105 | if (Options::enableConcurrentJIT()) { |
106 | Worklist* worklist = ensureGlobalWorklistFor(mode); | |
81345200 A |
107 | if (logCompilationChanges(mode)) |
108 | dataLog("Deferring DFG compilation of ", *codeBlock, " with queue length ", worklist->queueLength(), ".\n"); | |
109 | worklist->enqueue(plan); | |
110 | return CompilationDeferred; | |
6fe7ccc8 A |
111 | } |
112 | ||
81345200 A |
113 | plan->compileInThread(*vm.dfgState, 0); |
114 | return plan->finalizeWithoutNotifyingCallback(); | |
6fe7ccc8 | 115 | } |
81345200 A |
116 | #else // ENABLE(DFG_JIT) |
117 | static CompilationResult compileImpl( | |
118 | VM&, CodeBlock*, CodeBlock*, CompilationMode, unsigned, const Operands<JSValue>&, | |
119 | PassRefPtr<DeferredCompilationCallback>) | |
6fe7ccc8 | 120 | { |
81345200 | 121 | return CompilationFailed; |
6fe7ccc8 | 122 | } |
81345200 | 123 | #endif // ENABLE(DFG_JIT) |
6fe7ccc8 | 124 | |
81345200 A |
125 | CompilationResult compile( |
126 | VM& vm, CodeBlock* codeBlock, CodeBlock* profiledDFGCodeBlock, CompilationMode mode, | |
127 | unsigned osrEntryBytecodeIndex, const Operands<JSValue>& mustHandleValues, | |
128 | PassRefPtr<DeferredCompilationCallback> passedCallback) | |
6fe7ccc8 | 129 | { |
81345200 A |
130 | RefPtr<DeferredCompilationCallback> callback = passedCallback; |
131 | CompilationResult result = compileImpl( | |
132 | vm, codeBlock, profiledDFGCodeBlock, mode, osrEntryBytecodeIndex, mustHandleValues, | |
133 | callback); | |
134 | if (result != CompilationDeferred) | |
135 | callback->compilationDidComplete(codeBlock, result); | |
136 | return result; | |
6fe7ccc8 A |
137 | } |
138 | ||
139 | } } // namespace JSC::DFG |