fpizlo@apple.com | 594887a | 2011-09-06 09:23:55 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 8ff092f | 2013-01-29 08:01:03 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. |
fpizlo@apple.com | 594887a | 2011-09-06 09:23:55 +0000 | [diff] [blame] | 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 | |
allan.jensen@nokia.com | 3c6f152 | 2012-08-12 11:47:34 +0000 | [diff] [blame] | 29 | #include "JSObject.h" |
| 30 | #include "JSString.h" |
ggaren@apple.com | b11e787 | 2012-08-30 22:50:00 +0000 | [diff] [blame] | 31 | |
oliver@apple.com | 75afc4f | 2013-07-25 04:00:22 +0000 | [diff] [blame] | 32 | #include "CodeBlock.h" |
oliver@apple.com | 90fce82 | 2013-07-25 04:00:13 +0000 | [diff] [blame] | 33 | #include "DFGJITCode.h" |
| 34 | #include "DFGPlan.h" |
| 35 | #include "DFGThunks.h" |
oliver@apple.com | 284cc3d | 2013-07-25 04:00:33 +0000 | [diff] [blame] | 36 | #include "DFGWorklist.h" |
oliver@apple.com | 90fce82 | 2013-07-25 04:00:13 +0000 | [diff] [blame] | 37 | #include "JITCode.h" |
fpizlo@apple.com | a4b4cbe | 2013-01-12 04:47:03 +0000 | [diff] [blame] | 38 | #include "Operations.h" |
commit-queue@webkit.org | fbda60c | 2012-07-03 19:19:22 +0000 | [diff] [blame] | 39 | #include "Options.h" |
oliver@apple.com | 75afc4f | 2013-07-25 04:00:22 +0000 | [diff] [blame] | 40 | #include "SamplingTool.h" |
oliver@apple.com | 284cc3d | 2013-07-25 04:00:33 +0000 | [diff] [blame] | 41 | #include <wtf/Atomics.h> |
fpizlo@apple.com | 594887a | 2011-09-06 09:23:55 +0000 | [diff] [blame] | 42 | |
carlosgc@webkit.org | 13f6daf2 | 2013-07-30 06:42:00 +0000 | [diff] [blame] | 43 | #if ENABLE(FTL_JIT) |
| 44 | #include "FTLThunks.h" |
| 45 | #endif |
| 46 | |
fpizlo@apple.com | 594887a | 2011-09-06 09:23:55 +0000 | [diff] [blame] | 47 | namespace JSC { namespace DFG { |
| 48 | |
fpizlo@apple.com | 16e2cbf | 2012-06-22 23:32:59 +0000 | [diff] [blame] | 49 | static unsigned numCompilations; |
| 50 | |
| 51 | unsigned getNumCompilations() |
| 52 | { |
| 53 | return numCompilations; |
| 54 | } |
| 55 | |
fpizlo@apple.com | 1342e7a | 2013-08-29 19:28:55 +0000 | [diff] [blame] | 56 | #if ENABLE(DFG_JIT) |
fpizlo@apple.com | 6931c47 | 2013-08-29 23:45:26 +0000 | [diff] [blame] | 57 | static CompilationResult compileImpl( |
fpizlo@apple.com | 532f1e5 | 2013-09-04 06:26:04 +0000 | [diff] [blame] | 58 | VM& vm, CodeBlock* codeBlock, CompilationMode mode, unsigned osrEntryBytecodeIndex, |
| 59 | const Operands<JSValue>& mustHandleValues, |
| 60 | PassRefPtr<DeferredCompilationCallback> callback, Worklist* worklist) |
fpizlo@apple.com | 594887a | 2011-09-06 09:23:55 +0000 | [diff] [blame] | 61 | { |
fpizlo@apple.com | 8ce62fd | 2011-11-06 11:39:12 +0000 | [diff] [blame] | 62 | SamplingRegion samplingRegion("DFG Compilation (Driver)"); |
| 63 | |
fpizlo@apple.com | 16e2cbf | 2012-06-22 23:32:59 +0000 | [diff] [blame] | 64 | numCompilations++; |
| 65 | |
fpizlo@apple.com | 7c3918d | 2011-11-16 00:26:30 +0000 | [diff] [blame] | 66 | ASSERT(codeBlock); |
| 67 | ASSERT(codeBlock->alternative()); |
oliver@apple.com | 5a24fdd | 2013-07-25 04:00:54 +0000 | [diff] [blame] | 68 | ASSERT(codeBlock->alternative()->jitType() == JITCode::BaselineJIT); |
fpizlo@apple.com | 0fd7ec9 | 2012-08-19 21:59:12 +0000 | [diff] [blame] | 69 | |
oliver@apple.com | 07f66d4 | 2013-07-25 04:00:58 +0000 | [diff] [blame] | 70 | if (!Options::useDFGJIT() || !MacroAssembler::supportsFloatingPoint()) |
oliver@apple.com | 75afc4f | 2013-07-25 04:00:22 +0000 | [diff] [blame] | 71 | return CompilationFailed; |
msaboff@apple.com | 7b4d207 | 2013-05-04 07:30:35 +0000 | [diff] [blame] | 72 | |
| 73 | if (!Options::bytecodeRangeToDFGCompile().isInRange(codeBlock->instructionCount())) |
oliver@apple.com | 75afc4f | 2013-07-25 04:00:22 +0000 | [diff] [blame] | 74 | return CompilationFailed; |
oliver@apple.com | acdde49 | 2013-07-25 04:02:57 +0000 | [diff] [blame] | 75 | |
fpizlo@apple.com | 3fa6f5d | 2013-02-09 19:33:00 +0000 | [diff] [blame] | 76 | if (logCompilationChanges()) |
fpizlo@apple.com | 532f1e5 | 2013-09-04 06:26:04 +0000 | [diff] [blame] | 77 | dataLog("DFG(Driver) compiling ", *codeBlock, " with ", mode, ", number of instructions = ", codeBlock->instructionCount(), "\n"); |
fpizlo@apple.com | 7c3918d | 2011-11-16 00:26:30 +0000 | [diff] [blame] | 78 | |
oliver@apple.com | 90fce82 | 2013-07-25 04:00:13 +0000 | [diff] [blame] | 79 | // Make sure that any stubs that the DFG is going to use are initialized. We want to |
fpizlo@apple.com | 50cd41c | 2013-10-10 22:57:10 +0000 | [diff] [blame] | 80 | // make sure that all JIT code generation does finalization on the main thread. |
oliver@apple.com | 284cc3d | 2013-07-25 04:00:33 +0000 | [diff] [blame] | 81 | vm.getCTIStub(osrExitGenerationThunkGenerator); |
| 82 | vm.getCTIStub(throwExceptionFromCallSlowPathGenerator); |
| 83 | vm.getCTIStub(linkCallThunkGenerator); |
| 84 | vm.getCTIStub(linkConstructThunkGenerator); |
| 85 | vm.getCTIStub(linkClosureCallThunkGenerator); |
| 86 | vm.getCTIStub(virtualCallThunkGenerator); |
| 87 | vm.getCTIStub(virtualConstructThunkGenerator); |
oliver@apple.com | 90fce82 | 2013-07-25 04:00:13 +0000 | [diff] [blame] | 88 | #if ENABLE(FTL_JIT) |
fpizlo@apple.com | 50cd41c | 2013-10-10 22:57:10 +0000 | [diff] [blame] | 89 | vm.getCTIStub(FTL::osrExitGenerationWithoutStackMapThunkGenerator); |
oliver@apple.com | 90fce82 | 2013-07-25 04:00:13 +0000 | [diff] [blame] | 90 | #endif |
| 91 | |
oliver@apple.com | 75afc4f | 2013-07-25 04:00:22 +0000 | [diff] [blame] | 92 | RefPtr<Plan> plan = adoptRef( |
fpizlo@apple.com | 532f1e5 | 2013-09-04 06:26:04 +0000 | [diff] [blame] | 93 | new Plan(codeBlock, mode, osrEntryBytecodeIndex, mustHandleValues)); |
fpizlo@apple.com | 0fd7ec9 | 2012-08-19 21:59:12 +0000 | [diff] [blame] | 94 | |
fpizlo@apple.com | 1342e7a | 2013-08-29 19:28:55 +0000 | [diff] [blame] | 95 | if (worklist) { |
fpizlo@apple.com | 62b6af8 | 2013-08-29 18:25:36 +0000 | [diff] [blame] | 96 | plan->callback = callback; |
oliver@apple.com | 284cc3d | 2013-07-25 04:00:33 +0000 | [diff] [blame] | 97 | if (logCompilationChanges()) |
fpizlo@apple.com | 1342e7a | 2013-08-29 19:28:55 +0000 | [diff] [blame] | 98 | dataLog("Deferring DFG compilation of ", *codeBlock, " with queue length ", worklist->queueLength(), ".\n"); |
| 99 | worklist->enqueue(plan); |
oliver@apple.com | 284cc3d | 2013-07-25 04:00:33 +0000 | [diff] [blame] | 100 | return CompilationDeferred; |
| 101 | } |
| 102 | |
| 103 | plan->compileInThread(*vm.dfgState); |
fpizlo@apple.com | 62b6af8 | 2013-08-29 18:25:36 +0000 | [diff] [blame] | 104 | return plan->finalizeWithoutNotifyingCallback(); |
oliver@apple.com | 75afc4f | 2013-07-25 04:00:22 +0000 | [diff] [blame] | 105 | } |
fpizlo@apple.com | 1342e7a | 2013-08-29 19:28:55 +0000 | [diff] [blame] | 106 | #else // ENABLE(DFG_JIT) |
fpizlo@apple.com | 6931c47 | 2013-08-29 23:45:26 +0000 | [diff] [blame] | 107 | static CompilationResult compileImpl( |
fpizlo@apple.com | 532f1e5 | 2013-09-04 06:26:04 +0000 | [diff] [blame] | 108 | VM&, CodeBlock*, CompilationMode, unsigned, const Operands<JSValue>&, |
fpizlo@apple.com | 6931c47 | 2013-08-29 23:45:26 +0000 | [diff] [blame] | 109 | PassRefPtr<DeferredCompilationCallback>, Worklist*) |
fpizlo@apple.com | 1342e7a | 2013-08-29 19:28:55 +0000 | [diff] [blame] | 110 | { |
| 111 | return CompilationFailed; |
| 112 | } |
fpizlo@apple.com | 594887a | 2011-09-06 09:23:55 +0000 | [diff] [blame] | 113 | #endif // ENABLE(DFG_JIT) |
| 114 | |
fpizlo@apple.com | 6931c47 | 2013-08-29 23:45:26 +0000 | [diff] [blame] | 115 | CompilationResult compile( |
fpizlo@apple.com | 532f1e5 | 2013-09-04 06:26:04 +0000 | [diff] [blame] | 116 | VM& vm, CodeBlock* codeBlock, CompilationMode mode, unsigned osrEntryBytecodeIndex, |
| 117 | const Operands<JSValue>& mustHandleValues, |
| 118 | PassRefPtr<DeferredCompilationCallback> passedCallback, Worklist* worklist) |
fpizlo@apple.com | 1342e7a | 2013-08-29 19:28:55 +0000 | [diff] [blame] | 119 | { |
| 120 | RefPtr<DeferredCompilationCallback> callback = passedCallback; |
fpizlo@apple.com | 6931c47 | 2013-08-29 23:45:26 +0000 | [diff] [blame] | 121 | CompilationResult result = compileImpl( |
fpizlo@apple.com | 532f1e5 | 2013-09-04 06:26:04 +0000 | [diff] [blame] | 122 | vm, codeBlock, mode, osrEntryBytecodeIndex, mustHandleValues, callback, worklist); |
fpizlo@apple.com | 1342e7a | 2013-08-29 19:28:55 +0000 | [diff] [blame] | 123 | if (result != CompilationDeferred) |
| 124 | callback->compilationDidComplete(codeBlock, result); |
| 125 | return result; |
| 126 | } |
| 127 | |
| 128 | } } // namespace JSC::DFG |