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