oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 2 | * Copyright (C) 2013-2015 Apple Inc. All rights reserved. |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +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 "FTLOSRExitCompiler.h" |
| 28 | |
| 29 | #if ENABLE(FTL_JIT) |
| 30 | |
| 31 | #include "DFGOSRExitCompilerCommon.h" |
| 32 | #include "DFGOSRExitPreparation.h" |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 33 | #include "FTLExitArgumentForOperand.h" |
| 34 | #include "FTLJITCode.h" |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 35 | #include "FTLLocation.h" |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 36 | #include "FTLOSRExit.h" |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 37 | #include "FTLOperations.h" |
fpizlo@apple.com | 4075068 | 2014-03-13 22:18:50 +0000 | [diff] [blame] | 38 | #include "FTLState.h" |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 39 | #include "FTLSaveRestore.h" |
fpizlo@apple.com | b426f86 | 2014-02-10 02:51:13 +0000 | [diff] [blame] | 40 | #include "LinkBuffer.h" |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 41 | #include "MaxFrameExtentForSlowPathCall.h" |
commit-queue@webkit.org | a936a26 | 2014-01-14 15:20:19 +0000 | [diff] [blame] | 42 | #include "OperandsInlines.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 43 | #include "JSCInlines.h" |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 44 | |
| 45 | namespace JSC { namespace FTL { |
| 46 | |
| 47 | using namespace DFG; |
| 48 | |
basile_clement@apple.com | 3ed5a3a | 2015-09-04 18:24:38 +0000 | [diff] [blame] | 49 | static void reboxAccordingToFormat( |
| 50 | DataFormat format, AssemblyHelpers& jit, GPRReg value, GPRReg scratch1, GPRReg scratch2) |
| 51 | { |
| 52 | switch (format) { |
| 53 | case DataFormatInt32: { |
| 54 | jit.zeroExtend32ToPtr(value, value); |
| 55 | jit.or64(GPRInfo::tagTypeNumberRegister, value); |
| 56 | break; |
| 57 | } |
| 58 | |
| 59 | case DataFormatInt52: { |
| 60 | jit.rshift64(AssemblyHelpers::TrustedImm32(JSValue::int52ShiftAmount), value); |
| 61 | jit.moveDoubleTo64(FPRInfo::fpRegT0, scratch2); |
| 62 | jit.boxInt52(value, value, scratch1, FPRInfo::fpRegT0); |
| 63 | jit.move64ToDouble(scratch2, FPRInfo::fpRegT0); |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | case DataFormatStrictInt52: { |
| 68 | jit.moveDoubleTo64(FPRInfo::fpRegT0, scratch2); |
| 69 | jit.boxInt52(value, value, scratch1, FPRInfo::fpRegT0); |
| 70 | jit.move64ToDouble(scratch2, FPRInfo::fpRegT0); |
| 71 | break; |
| 72 | } |
| 73 | |
| 74 | case DataFormatBoolean: { |
| 75 | jit.zeroExtend32ToPtr(value, value); |
| 76 | jit.or32(MacroAssembler::TrustedImm32(ValueFalse), value); |
| 77 | break; |
| 78 | } |
| 79 | |
| 80 | case DataFormatJS: { |
| 81 | // Done already! |
| 82 | break; |
| 83 | } |
| 84 | |
| 85 | case DataFormatDouble: { |
| 86 | jit.moveDoubleTo64(FPRInfo::fpRegT0, scratch1); |
| 87 | jit.move64ToDouble(value, FPRInfo::fpRegT0); |
| 88 | jit.purifyNaN(FPRInfo::fpRegT0); |
| 89 | jit.boxDouble(FPRInfo::fpRegT0, value); |
| 90 | jit.move64ToDouble(scratch1, FPRInfo::fpRegT0); |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | default: |
| 95 | RELEASE_ASSERT_NOT_REACHED(); |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 100 | static void compileRecovery( |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 101 | CCallHelpers& jit, const ExitValue& value, |
| 102 | #if FTL_USES_B3 |
| 103 | Vector<B3::ValueRep>& valueReps, |
| 104 | #else // FTL_USES_B3 |
| 105 | StackMaps::Record* record, StackMaps& stackmaps, |
| 106 | #endif // FTL_USES_B3 |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 107 | char* registerScratch, |
| 108 | const HashMap<ExitTimeObjectMaterialization*, EncodedJSValue*>& materializationToPointer) |
| 109 | { |
| 110 | switch (value.kind()) { |
| 111 | case ExitValueDead: |
| 112 | jit.move(MacroAssembler::TrustedImm64(JSValue::encode(jsUndefined())), GPRInfo::regT0); |
| 113 | break; |
| 114 | |
| 115 | case ExitValueConstant: |
| 116 | jit.move(MacroAssembler::TrustedImm64(JSValue::encode(value.constant())), GPRInfo::regT0); |
| 117 | break; |
| 118 | |
| 119 | case ExitValueArgument: |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 120 | #if FTL_USES_B3 |
| 121 | Location::forValueRep(valueReps[value.exitArgument().argument()]).restoreInto( |
| 122 | jit, registerScratch, GPRInfo::regT0); |
| 123 | #else // FTL_USES_B3 |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 124 | record->locations[value.exitArgument().argument()].restoreInto( |
| 125 | jit, stackmaps, registerScratch, GPRInfo::regT0); |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 126 | #endif // FTL_USES_B3 |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 127 | break; |
| 128 | |
| 129 | case ExitValueInJSStack: |
| 130 | case ExitValueInJSStackAsInt32: |
| 131 | case ExitValueInJSStackAsInt52: |
| 132 | case ExitValueInJSStackAsDouble: |
| 133 | jit.load64(AssemblyHelpers::addressFor(value.virtualRegister()), GPRInfo::regT0); |
| 134 | break; |
| 135 | |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 136 | case ExitValueRecovery: |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 137 | #if FTL_USES_B3 |
| 138 | Location::forValueRep(valueReps[value.rightRecoveryArgument()]).restoreInto( |
| 139 | jit, registerScratch, GPRInfo::regT1); |
| 140 | Location::forValueRep(valueReps[value.leftRecoveryArgument()]).restoreInto( |
| 141 | jit, registerScratch, GPRInfo::regT0); |
| 142 | #else // FTL_USES_B3 |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 143 | record->locations[value.rightRecoveryArgument()].restoreInto( |
| 144 | jit, stackmaps, registerScratch, GPRInfo::regT1); |
| 145 | record->locations[value.leftRecoveryArgument()].restoreInto( |
| 146 | jit, stackmaps, registerScratch, GPRInfo::regT0); |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 147 | #endif // FTL_USES_B3 |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 148 | switch (value.recoveryOpcode()) { |
| 149 | case AddRecovery: |
| 150 | switch (value.recoveryFormat()) { |
basile_clement@apple.com | 3ed5a3a | 2015-09-04 18:24:38 +0000 | [diff] [blame] | 151 | case DataFormatInt32: |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 152 | jit.add32(GPRInfo::regT1, GPRInfo::regT0); |
| 153 | break; |
basile_clement@apple.com | 3ed5a3a | 2015-09-04 18:24:38 +0000 | [diff] [blame] | 154 | case DataFormatInt52: |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 155 | jit.add64(GPRInfo::regT1, GPRInfo::regT0); |
| 156 | break; |
| 157 | default: |
| 158 | RELEASE_ASSERT_NOT_REACHED(); |
| 159 | break; |
| 160 | } |
| 161 | break; |
| 162 | case SubRecovery: |
| 163 | switch (value.recoveryFormat()) { |
basile_clement@apple.com | 3ed5a3a | 2015-09-04 18:24:38 +0000 | [diff] [blame] | 164 | case DataFormatInt32: |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 165 | jit.sub32(GPRInfo::regT1, GPRInfo::regT0); |
| 166 | break; |
basile_clement@apple.com | 3ed5a3a | 2015-09-04 18:24:38 +0000 | [diff] [blame] | 167 | case DataFormatInt52: |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 168 | jit.sub64(GPRInfo::regT1, GPRInfo::regT0); |
| 169 | break; |
| 170 | default: |
| 171 | RELEASE_ASSERT_NOT_REACHED(); |
| 172 | break; |
| 173 | } |
| 174 | break; |
| 175 | default: |
| 176 | RELEASE_ASSERT_NOT_REACHED(); |
| 177 | break; |
| 178 | } |
| 179 | break; |
| 180 | |
| 181 | case ExitValueMaterializeNewObject: |
| 182 | jit.loadPtr(materializationToPointer.get(value.objectMaterialization()), GPRInfo::regT0); |
| 183 | break; |
| 184 | |
| 185 | default: |
| 186 | RELEASE_ASSERT_NOT_REACHED(); |
| 187 | break; |
| 188 | } |
| 189 | |
| 190 | reboxAccordingToFormat( |
basile_clement@apple.com | 3ed5a3a | 2015-09-04 18:24:38 +0000 | [diff] [blame] | 191 | value.dataFormat(), jit, GPRInfo::regT0, GPRInfo::regT1, GPRInfo::regT2); |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 192 | } |
| 193 | |
fpizlo@apple.com | 6bf1198 | 2013-11-03 18:24:20 +0000 | [diff] [blame] | 194 | static void compileStub( |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 195 | unsigned exitID, JITCode* jitCode, OSRExit& exit, VM* vm, CodeBlock* codeBlock) |
| 196 | { |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 197 | #if FTL_USES_B3 |
| 198 | UNUSED_PARAM(jitCode); |
| 199 | #else // FTL_USES_B3 |
sbarati@apple.com | cda241d | 2015-10-19 20:29:45 +0000 | [diff] [blame] | 200 | StackMaps::Record* record = &jitCode->stackmaps.records[exit.m_stackmapRecordIndex]; |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 201 | RELEASE_ASSERT(record->patchpointID == exit.m_descriptor->m_stackmapID); |
| 202 | #endif // FTL_USES_B3 |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 203 | |
msaboff@apple.com | cb9adb0 | 2013-11-07 23:45:56 +0000 | [diff] [blame] | 204 | // This code requires framePointerRegister is the same as callFrameRegister |
| 205 | static_assert(MacroAssembler::framePointerRegister == GPRInfo::callFrameRegister, "MacroAssembler::framePointerRegister and GPRInfo::callFrameRegister must be the same"); |
| 206 | |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 207 | CCallHelpers jit(vm, codeBlock); |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 208 | |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 209 | // We need scratch space to save all registers, to build up the JS stack, to deal with unwind |
| 210 | // fixup, pointers to all of the objects we materialize, and the elements inside those objects |
| 211 | // that we materialize. |
| 212 | |
| 213 | // Figure out how much space we need for those object allocations. |
| 214 | unsigned numMaterializations = 0; |
| 215 | size_t maxMaterializationNumArguments = 0; |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 216 | for (ExitTimeObjectMaterialization* materialization : exit.m_descriptor->m_materializations) { |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 217 | numMaterializations++; |
| 218 | |
| 219 | maxMaterializationNumArguments = std::max( |
| 220 | maxMaterializationNumArguments, |
| 221 | materialization->properties().size()); |
| 222 | } |
| 223 | |
| 224 | ScratchBuffer* scratchBuffer = vm->scratchBufferForSize( |
| 225 | sizeof(EncodedJSValue) * ( |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 226 | exit.m_descriptor->m_values.size() + numMaterializations + maxMaterializationNumArguments) + |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 227 | requiredScratchMemorySizeInBytes() + |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 228 | codeBlock->calleeSaveRegisters()->size() * sizeof(uint64_t)); |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 229 | EncodedJSValue* scratch = scratchBuffer ? static_cast<EncodedJSValue*>(scratchBuffer->dataBuffer()) : 0; |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 230 | EncodedJSValue* materializationPointers = scratch + exit.m_descriptor->m_values.size(); |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 231 | EncodedJSValue* materializationArguments = materializationPointers + numMaterializations; |
| 232 | char* registerScratch = bitwise_cast<char*>(materializationArguments + maxMaterializationNumArguments); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 233 | uint64_t* unwindScratch = bitwise_cast<uint64_t*>(registerScratch + requiredScratchMemorySizeInBytes()); |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 234 | |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 235 | HashMap<ExitTimeObjectMaterialization*, EncodedJSValue*> materializationToPointer; |
| 236 | unsigned materializationCount = 0; |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 237 | for (ExitTimeObjectMaterialization* materialization : exit.m_descriptor->m_materializations) { |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 238 | materializationToPointer.add( |
| 239 | materialization, materializationPointers + materializationCount++); |
| 240 | } |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 241 | |
| 242 | auto recoverValue = [&] (const ExitValue& value) { |
| 243 | compileRecovery( |
| 244 | jit, value, |
| 245 | #if FTL_USES_B3 |
| 246 | exit.m_valueReps, |
| 247 | #else // FTL_USES_B3 |
| 248 | record, jitCode->stackmaps, |
| 249 | #endif // FTL_USES_B3 |
| 250 | registerScratch, materializationToPointer); |
| 251 | }; |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 252 | |
fpizlo@apple.com | 720e05a | 2014-02-17 18:59:13 +0000 | [diff] [blame] | 253 | // Note that we come in here, the stack used to be as LLVM left it except that someone called pushToSave(). |
| 254 | // We don't care about the value they saved. But, we do appreciate the fact that they did it, because we use |
| 255 | // that slot for saveAllRegisters(). |
| 256 | |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 257 | saveAllRegisters(jit, registerScratch); |
| 258 | |
fpizlo@apple.com | 6895269 | 2014-03-23 18:56:56 +0000 | [diff] [blame] | 259 | // Bring the stack back into a sane form and assert that it's sane. |
fpizlo@apple.com | 720e05a | 2014-02-17 18:59:13 +0000 | [diff] [blame] | 260 | jit.popToRestore(GPRInfo::regT0); |
fpizlo@apple.com | 6895269 | 2014-03-23 18:56:56 +0000 | [diff] [blame] | 261 | jit.checkStackPointerAlignment(); |
fpizlo@apple.com | e5192ec | 2013-10-12 01:33:16 +0000 | [diff] [blame] | 262 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 263 | if (vm->m_perBytecodeProfiler && codeBlock->jitCode()->dfgCommon()->compilation) { |
| 264 | Profiler::Database& database = *vm->m_perBytecodeProfiler; |
| 265 | Profiler::Compilation* compilation = codeBlock->jitCode()->dfgCommon()->compilation.get(); |
| 266 | |
| 267 | Profiler::OSRExit* profilerExit = compilation->addOSRExit( |
| 268 | exitID, Profiler::OriginStack(database, codeBlock, exit.m_codeOrigin), |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 269 | exit.m_kind, exit.m_kind == UncountableInvalidation); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 270 | jit.add64(CCallHelpers::TrustedImm32(1), CCallHelpers::AbsoluteAddress(profilerExit->counterAddress())); |
| 271 | } |
| 272 | |
fpizlo@apple.com | e5192ec | 2013-10-12 01:33:16 +0000 | [diff] [blame] | 273 | // The remaining code assumes that SP/FP are in the same state that they were in the FTL's |
| 274 | // call frame. |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 275 | |
| 276 | // Get the call frame and tag thingies. |
msaboff@apple.com | cb9adb0 | 2013-11-07 23:45:56 +0000 | [diff] [blame] | 277 | // Restore the exiting function's callFrame value into a regT4 |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 278 | jit.move(MacroAssembler::TrustedImm64(TagTypeNumber), GPRInfo::tagTypeNumberRegister); |
| 279 | jit.move(MacroAssembler::TrustedImm64(TagMask), GPRInfo::tagMaskRegister); |
| 280 | |
| 281 | // Do some value profiling. |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 282 | if (exit.m_descriptor->m_profileDataFormat != DataFormatNone) { |
| 283 | #if FTL_USES_B3 |
| 284 | Location::forValueRep(exit.m_valueReps[0]).restoreInto(jit, registerScratch, GPRInfo::regT0); |
| 285 | #else // FTL_USES_B3 |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 286 | record->locations[0].restoreInto(jit, jitCode->stackmaps, registerScratch, GPRInfo::regT0); |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 287 | #endif // FTL_USES_B3 |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 288 | reboxAccordingToFormat( |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 289 | exit.m_descriptor->m_profileDataFormat, jit, GPRInfo::regT0, GPRInfo::regT1, GPRInfo::regT2); |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 290 | |
| 291 | if (exit.m_kind == BadCache || exit.m_kind == BadIndexingType) { |
| 292 | CodeOrigin codeOrigin = exit.m_codeOriginForExitProfile; |
| 293 | if (ArrayProfile* arrayProfile = jit.baselineCodeBlockFor(codeOrigin)->getArrayProfile(codeOrigin.bytecodeIndex)) { |
mhahnenberg@apple.com | b6f8519 | 2014-02-27 01:27:18 +0000 | [diff] [blame] | 294 | jit.load32(MacroAssembler::Address(GPRInfo::regT0, JSCell::structureIDOffset()), GPRInfo::regT1); |
| 295 | jit.store32(GPRInfo::regT1, arrayProfile->addressOfLastSeenStructureID()); |
| 296 | jit.load8(MacroAssembler::Address(GPRInfo::regT0, JSCell::indexingTypeOffset()), GPRInfo::regT1); |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 297 | jit.move(MacroAssembler::TrustedImm32(1), GPRInfo::regT2); |
| 298 | jit.lshift32(GPRInfo::regT1, GPRInfo::regT2); |
| 299 | jit.or32(GPRInfo::regT2, MacroAssembler::AbsoluteAddress(arrayProfile->addressOfArrayModes())); |
| 300 | } |
| 301 | } |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 302 | |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 303 | if (!!exit.m_descriptor->m_valueProfile) |
| 304 | jit.store64(GPRInfo::regT0, exit.m_descriptor->m_valueProfile.getSpecFailBucket(0)); |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 305 | } |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 306 | |
| 307 | // Materialize all objects. Don't materialize an object until all |
| 308 | // of the objects it needs have been materialized. We break cycles |
| 309 | // by populating objects late - we only consider an object as |
| 310 | // needing another object if the later is needed for the |
| 311 | // allocation of the former. |
| 312 | |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 313 | HashSet<ExitTimeObjectMaterialization*> toMaterialize; |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 314 | for (ExitTimeObjectMaterialization* materialization : exit.m_descriptor->m_materializations) |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 315 | toMaterialize.add(materialization); |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 316 | |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 317 | while (!toMaterialize.isEmpty()) { |
commit-queue@webkit.org | 877bfc3 | 2015-03-10 21:54:21 +0000 | [diff] [blame] | 318 | unsigned previousToMaterializeSize = toMaterialize.size(); |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 319 | |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 320 | Vector<ExitTimeObjectMaterialization*> worklist; |
| 321 | worklist.appendRange(toMaterialize.begin(), toMaterialize.end()); |
| 322 | for (ExitTimeObjectMaterialization* materialization : worklist) { |
| 323 | // Check if we can do anything about this right now. |
| 324 | bool allGood = true; |
| 325 | for (ExitPropertyValue value : materialization->properties()) { |
| 326 | if (!value.value().isObjectMaterialization()) |
| 327 | continue; |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 328 | if (!value.location().neededForMaterialization()) |
| 329 | continue; |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 330 | if (toMaterialize.contains(value.value().objectMaterialization())) { |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 331 | // Gotta skip this one, since it needs a |
| 332 | // materialization that hasn't been materialized. |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 333 | allGood = false; |
| 334 | break; |
| 335 | } |
| 336 | } |
| 337 | if (!allGood) |
| 338 | continue; |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 339 | |
| 340 | // All systems go for materializing the object. First we |
| 341 | // recover the values of all of its fields and then we |
| 342 | // call a function to actually allocate the beast. |
| 343 | // We only recover the fields that are needed for the allocation. |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 344 | for (unsigned propertyIndex = materialization->properties().size(); propertyIndex--;) { |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 345 | const ExitPropertyValue& property = materialization->properties()[propertyIndex]; |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 346 | if (!property.location().neededForMaterialization()) |
| 347 | continue; |
| 348 | |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 349 | recoverValue(property.value()); |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 350 | jit.storePtr(GPRInfo::regT0, materializationArguments + propertyIndex); |
| 351 | } |
| 352 | |
| 353 | // This call assumes that we don't pass arguments on the stack. |
| 354 | jit.setupArgumentsWithExecState( |
| 355 | CCallHelpers::TrustedImmPtr(materialization), |
| 356 | CCallHelpers::TrustedImmPtr(materializationArguments)); |
| 357 | jit.move(CCallHelpers::TrustedImmPtr(bitwise_cast<void*>(operationMaterializeObjectInOSR)), GPRInfo::nonArgGPR0); |
| 358 | jit.call(GPRInfo::nonArgGPR0); |
| 359 | jit.storePtr(GPRInfo::returnValueGPR, materializationToPointer.get(materialization)); |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 360 | |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 361 | // Let everyone know that we're done. |
| 362 | toMaterialize.remove(materialization); |
| 363 | } |
| 364 | |
| 365 | // We expect progress! This ensures that we crash rather than looping infinitely if there |
| 366 | // is something broken about this fixpoint. Or, this could happen if we ever violate the |
| 367 | // "materializations form a DAG" rule. |
| 368 | RELEASE_ASSERT(toMaterialize.size() < previousToMaterializeSize); |
| 369 | } |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 370 | |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 371 | // Now that all the objects have been allocated, we populate them |
| 372 | // with the correct values. This time we can recover all the |
| 373 | // fields, including those that are only needed for the allocation. |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 374 | for (ExitTimeObjectMaterialization* materialization : exit.m_descriptor->m_materializations) { |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 375 | for (unsigned propertyIndex = materialization->properties().size(); propertyIndex--;) { |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 376 | recoverValue(materialization->properties()[propertyIndex].value()); |
basile_clement@apple.com | d793029 | 2015-07-13 23:27:30 +0000 | [diff] [blame] | 377 | jit.storePtr(GPRInfo::regT0, materializationArguments + propertyIndex); |
| 378 | } |
| 379 | |
| 380 | // This call assumes that we don't pass arguments on the stack |
| 381 | jit.setupArgumentsWithExecState( |
| 382 | CCallHelpers::TrustedImmPtr(materialization), |
| 383 | CCallHelpers::TrustedImmPtr(materializationToPointer.get(materialization)), |
| 384 | CCallHelpers::TrustedImmPtr(materializationArguments)); |
| 385 | jit.move(CCallHelpers::TrustedImmPtr(bitwise_cast<void*>(operationPopulateObjectInOSR)), GPRInfo::nonArgGPR0); |
| 386 | jit.call(GPRInfo::nonArgGPR0); |
| 387 | } |
| 388 | |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 389 | // Save all state from wherever the exit data tells us it was, into the appropriate place in |
fpizlo@apple.com | 2a69df4 | 2014-09-20 18:45:54 +0000 | [diff] [blame] | 390 | // the scratch buffer. This also does the reboxing. |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 391 | |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 392 | for (unsigned index = exit.m_descriptor->m_values.size(); index--;) { |
| 393 | recoverValue(exit.m_descriptor->m_values[index]); |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 394 | jit.store64(GPRInfo::regT0, scratch + index); |
| 395 | } |
| 396 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 397 | // Henceforth we make it look like the exiting function was called through a register |
| 398 | // preservation wrapper. This implies that FP must be nudged down by a certain amount. Then |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 399 | // we restore the various things according to either exit.m_descriptor->m_values or by copying from the |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 400 | // old frame, and finally we save the various callee-save registers into where the |
| 401 | // restoration thunk would restore them from. |
| 402 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 403 | // Before we start messing with the frame, we need to set aside any registers that the |
| 404 | // FTL code was preserving. |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 405 | for (unsigned i = codeBlock->calleeSaveRegisters()->size(); i--;) { |
| 406 | RegisterAtOffset entry = codeBlock->calleeSaveRegisters()->at(i); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 407 | jit.load64( |
| 408 | MacroAssembler::Address(MacroAssembler::framePointerRegister, entry.offset()), |
| 409 | GPRInfo::regT0); |
| 410 | jit.store64(GPRInfo::regT0, unwindScratch + i); |
| 411 | } |
| 412 | |
| 413 | jit.load32(CCallHelpers::payloadFor(JSStack::ArgumentCount), GPRInfo::regT2); |
| 414 | |
| 415 | // Let's say that the FTL function had failed its arity check. In that case, the stack will |
| 416 | // contain some extra stuff. |
| 417 | // |
msaboff@apple.com | 21bd737 | 2015-09-18 16:21:08 +0000 | [diff] [blame] | 418 | // We compute the padded stack space: |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 419 | // |
| 420 | // paddedStackSpace = roundUp(codeBlock->numParameters - regT2 + 1) |
| 421 | // |
msaboff@apple.com | 21bd737 | 2015-09-18 16:21:08 +0000 | [diff] [blame] | 422 | // The stack will have regT2 + CallFrameHeaderSize stuff. |
| 423 | // We want to make the stack look like this, from higher addresses down: |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 424 | // |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 425 | // - argument padding |
| 426 | // - actual arguments |
| 427 | // - call frame header |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 428 | |
| 429 | // This code assumes that we're dealing with FunctionCode. |
| 430 | RELEASE_ASSERT(codeBlock->codeType() == FunctionCode); |
| 431 | |
| 432 | jit.add32( |
| 433 | MacroAssembler::TrustedImm32(-codeBlock->numParameters()), GPRInfo::regT2, |
| 434 | GPRInfo::regT3); |
fpizlo@apple.com | 0cec6dea | 2014-03-04 21:27:37 +0000 | [diff] [blame] | 435 | MacroAssembler::Jump arityIntact = jit.branch32( |
| 436 | MacroAssembler::GreaterThanOrEqual, GPRInfo::regT3, MacroAssembler::TrustedImm32(0)); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 437 | jit.neg32(GPRInfo::regT3); |
| 438 | jit.add32(MacroAssembler::TrustedImm32(1 + stackAlignmentRegisters() - 1), GPRInfo::regT3); |
| 439 | jit.and32(MacroAssembler::TrustedImm32(-stackAlignmentRegisters()), GPRInfo::regT3); |
| 440 | jit.add32(GPRInfo::regT3, GPRInfo::regT2); |
| 441 | arityIntact.link(&jit); |
| 442 | |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 443 | CodeBlock* baselineCodeBlock = jit.baselineCodeBlockFor(exit.m_codeOrigin); |
| 444 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 445 | // First set up SP so that our data doesn't get clobbered by signals. |
fpizlo@apple.com | 6895269 | 2014-03-23 18:56:56 +0000 | [diff] [blame] | 446 | unsigned conservativeStackDelta = |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 447 | (exit.m_descriptor->m_values.numberOfLocals() + baselineCodeBlock->calleeSaveSpaceAsVirtualRegisters()) * sizeof(Register) + |
fpizlo@apple.com | 6895269 | 2014-03-23 18:56:56 +0000 | [diff] [blame] | 448 | maxFrameExtentForSlowPathCall; |
| 449 | conservativeStackDelta = WTF::roundUpToMultipleOf( |
| 450 | stackAlignmentBytes(), conservativeStackDelta); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 451 | jit.addPtr( |
fpizlo@apple.com | 6895269 | 2014-03-23 18:56:56 +0000 | [diff] [blame] | 452 | MacroAssembler::TrustedImm32(-conservativeStackDelta), |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 453 | MacroAssembler::framePointerRegister, MacroAssembler::stackPointerRegister); |
fpizlo@apple.com | 6895269 | 2014-03-23 18:56:56 +0000 | [diff] [blame] | 454 | jit.checkStackPointerAlignment(); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 455 | |
msaboff@apple.com | 21bd737 | 2015-09-18 16:21:08 +0000 | [diff] [blame] | 456 | RegisterSet allFTLCalleeSaves = RegisterSet::ftlCalleeSaveRegisters(); |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 457 | RegisterAtOffsetList* baselineCalleeSaves = baselineCodeBlock->calleeSaveRegisters(); |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 458 | RegisterAtOffsetList* vmCalleeSaves = vm->getAllCalleeSaveRegisterOffsets(); |
| 459 | RegisterSet vmCalleeSavesToSkip = RegisterSet::stackRegisters(); |
| 460 | if (exit.m_isExceptionHandler) |
| 461 | jit.move(CCallHelpers::TrustedImmPtr(vm->calleeSaveRegistersBuffer), GPRInfo::regT1); |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 462 | |
| 463 | for (Reg reg = Reg::first(); reg <= Reg::last(); reg = reg.next()) { |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 464 | if (!allFTLCalleeSaves.get(reg)) { |
| 465 | if (exit.m_isExceptionHandler) |
| 466 | RELEASE_ASSERT(!vmCalleeSaves->find(reg)); |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 467 | continue; |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 468 | } |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 469 | unsigned unwindIndex = codeBlock->calleeSaveRegisters()->indexOf(reg); |
| 470 | RegisterAtOffset* baselineRegisterOffset = baselineCalleeSaves->find(reg); |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 471 | RegisterAtOffset* vmCalleeSave = nullptr; |
| 472 | if (exit.m_isExceptionHandler) |
| 473 | vmCalleeSave = vmCalleeSaves->find(reg); |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 474 | |
| 475 | if (reg.isGPR()) { |
| 476 | GPRReg regToLoad = baselineRegisterOffset ? GPRInfo::regT0 : reg.gpr(); |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 477 | RELEASE_ASSERT(regToLoad != GPRInfo::regT1); |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 478 | |
| 479 | if (unwindIndex == UINT_MAX) { |
| 480 | // The FTL compilation didn't preserve this register. This means that it also |
| 481 | // didn't use the register. So its value at the beginning of OSR exit should be |
| 482 | // preserved by the thunk. Luckily, we saved all registers into the register |
| 483 | // scratch buffer, so we can restore them from there. |
| 484 | jit.load64(registerScratch + offsetOfReg(reg), regToLoad); |
| 485 | } else { |
| 486 | // The FTL compilation preserved the register. Its new value is therefore |
| 487 | // irrelevant, but we can get the value that was preserved by using the unwind |
| 488 | // data. We've already copied all unwind-able preserved registers into the unwind |
| 489 | // scratch buffer, so we can get it from there. |
| 490 | jit.load64(unwindScratch + unwindIndex, regToLoad); |
| 491 | } |
| 492 | |
| 493 | if (baselineRegisterOffset) |
| 494 | jit.store64(regToLoad, MacroAssembler::Address(MacroAssembler::framePointerRegister, baselineRegisterOffset->offset())); |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 495 | if (vmCalleeSave && !vmCalleeSavesToSkip.get(vmCalleeSave->reg())) |
| 496 | jit.store64(regToLoad, MacroAssembler::Address(GPRInfo::regT1, vmCalleeSave->offset())); |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 497 | } else { |
| 498 | FPRReg fpRegToLoad = baselineRegisterOffset ? FPRInfo::fpRegT0 : reg.fpr(); |
| 499 | |
| 500 | if (unwindIndex == UINT_MAX) |
| 501 | jit.loadDouble(MacroAssembler::TrustedImmPtr(registerScratch + offsetOfReg(reg)), fpRegToLoad); |
| 502 | else |
| 503 | jit.loadDouble(MacroAssembler::TrustedImmPtr(unwindScratch + unwindIndex), fpRegToLoad); |
| 504 | |
| 505 | if (baselineRegisterOffset) |
| 506 | jit.storeDouble(fpRegToLoad, MacroAssembler::Address(MacroAssembler::framePointerRegister, baselineRegisterOffset->offset())); |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 507 | if (vmCalleeSave && !vmCalleeSavesToSkip.get(vmCalleeSave->reg())) |
| 508 | jit.storeDouble(fpRegToLoad, MacroAssembler::Address(GPRInfo::regT1, vmCalleeSave->offset())); |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 512 | if (exit.m_isExceptionHandler) { |
| 513 | RegisterAtOffset* vmCalleeSave = vmCalleeSaves->find(GPRInfo::tagTypeNumberRegister); |
| 514 | jit.store64(GPRInfo::tagTypeNumberRegister, MacroAssembler::Address(GPRInfo::regT1, vmCalleeSave->offset())); |
| 515 | |
| 516 | vmCalleeSave = vmCalleeSaves->find(GPRInfo::tagMaskRegister); |
| 517 | jit.store64(GPRInfo::tagMaskRegister, MacroAssembler::Address(GPRInfo::regT1, vmCalleeSave->offset())); |
| 518 | } |
| 519 | |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 520 | size_t baselineVirtualRegistersForCalleeSaves = baselineCodeBlock->calleeSaveSpaceAsVirtualRegisters(); |
| 521 | |
fpizlo@apple.com | 2a69df4 | 2014-09-20 18:45:54 +0000 | [diff] [blame] | 522 | // Now get state out of the scratch buffer and place it back into the stack. The values are |
| 523 | // already reboxed so we just move them. |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 524 | for (unsigned index = exit.m_descriptor->m_values.size(); index--;) { |
| 525 | VirtualRegister reg = exit.m_descriptor->m_values.virtualRegisterForIndex(index); |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 526 | |
| 527 | if (reg.isLocal() && reg.toLocal() < static_cast<int>(baselineVirtualRegistersForCalleeSaves)) |
| 528 | continue; |
| 529 | |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 530 | jit.load64(scratch + index, GPRInfo::regT0); |
msaboff@apple.com | 0208546 | 2015-09-10 17:47:16 +0000 | [diff] [blame] | 531 | jit.store64(GPRInfo::regT0, AssemblyHelpers::addressFor(reg)); |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | handleExitCounts(jit, exit); |
| 535 | reifyInlinedCallFrames(jit, exit); |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 536 | adjustAndJumpToTarget(jit, exit, exit.m_isExceptionHandler); |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 537 | |
benjamin@webkit.org | f766fd9 | 2014-07-08 04:23:30 +0000 | [diff] [blame] | 538 | LinkBuffer patchBuffer(*vm, jit, codeBlock); |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 539 | exit.m_code = FINALIZE_CODE_IF( |
mark.lam@apple.com | ee3c410 | 2015-10-14 18:57:07 +0000 | [diff] [blame] | 540 | shouldDumpDisassembly() || Options::verboseOSR() || Options::verboseFTLOSRExit(), |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 541 | patchBuffer, |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 542 | #if FTL_USES_B3 |
| 543 | ("FTL OSR exit #%u (%s, %s) from %s, with operands = %s", |
| 544 | exitID, toCString(exit.m_codeOrigin).data(), |
| 545 | exitKindToString(exit.m_kind), toCString(*codeBlock).data(), |
| 546 | toCString(ignoringContext<DumpContext>(exit.m_descriptor->m_values)).data()) |
| 547 | #else // FTL_USES_B3 |
fpizlo@apple.com | d2ceb39 | 2013-11-11 07:30:50 +0000 | [diff] [blame] | 548 | ("FTL OSR exit #%u (%s, %s) from %s, with operands = %s, and record = %s", |
| 549 | exitID, toCString(exit.m_codeOrigin).data(), |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 550 | exitKindToString(exit.m_kind), toCString(*codeBlock).data(), |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 551 | toCString(ignoringContext<DumpContext>(exit.m_descriptor->m_values)).data(), |
| 552 | toCString(*record).data()) |
| 553 | #endif // FTL_USES_B3 |
| 554 | ); |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 555 | } |
| 556 | |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 557 | extern "C" void* compileFTLOSRExit(ExecState* exec, unsigned exitID) |
| 558 | { |
| 559 | SamplingRegion samplingRegion("FTL OSR Exit Compilation"); |
mhahnenberg@apple.com | 2385e39 | 2014-02-27 01:09:39 +0000 | [diff] [blame] | 560 | |
mark.lam@apple.com | ee3c410 | 2015-10-14 18:57:07 +0000 | [diff] [blame] | 561 | if (shouldDumpDisassembly() || Options::verboseOSR() || Options::verboseFTLOSRExit()) |
mhahnenberg@apple.com | 2385e39 | 2014-02-27 01:09:39 +0000 | [diff] [blame] | 562 | dataLog("Compiling OSR exit with exitID = ", exitID, "\n"); |
fpizlo@apple.com | 41bed90 | 2014-02-25 22:18:21 +0000 | [diff] [blame] | 563 | |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 564 | CodeBlock* codeBlock = exec->codeBlock(); |
| 565 | |
| 566 | ASSERT(codeBlock); |
oliver@apple.com | 5a24fdd | 2013-07-25 04:00:54 +0000 | [diff] [blame] | 567 | ASSERT(codeBlock->jitType() == JITCode::FTLJIT); |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 568 | |
| 569 | VM* vm = &exec->vm(); |
| 570 | |
fpizlo@apple.com | fe6bd74 | 2013-09-17 20:56:57 +0000 | [diff] [blame] | 571 | // It's sort of preferable that we don't GC while in here. Anyways, doing so wouldn't |
| 572 | // really be profitable. |
| 573 | DeferGCForAWhile deferGC(vm->heap); |
| 574 | |
fpizlo@apple.com | ea92c20 | 2013-10-10 04:24:57 +0000 | [diff] [blame] | 575 | JITCode* jitCode = codeBlock->jitCode()->ftl(); |
| 576 | OSRExit& exit = jitCode->osrExit[exitID]; |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 577 | |
mark.lam@apple.com | ee3c410 | 2015-10-14 18:57:07 +0000 | [diff] [blame] | 578 | if (shouldDumpDisassembly() || Options::verboseOSR() || Options::verboseFTLOSRExit()) { |
fpizlo@apple.com | 09b14f9 | 2015-05-13 05:21:16 +0000 | [diff] [blame] | 579 | dataLog(" Owning block: ", pointerDump(codeBlock), "\n"); |
| 580 | dataLog(" Origin: ", exit.m_codeOrigin, "\n"); |
| 581 | if (exit.m_codeOriginForExitProfile != exit.m_codeOrigin) |
| 582 | dataLog(" Origin for exit profile: ", exit.m_codeOriginForExitProfile, "\n"); |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 583 | dataLog(" Exit stackmap ID: ", exit.m_descriptor->m_stackmapID, "\n"); |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 584 | dataLog(" Current call site index: ", exec->callSiteIndex().bits(), "\n"); |
| 585 | dataLog(" Exit is exception handler: ", exit.m_isExceptionHandler, |
sbarati@apple.com | b887f0d | 2015-12-01 00:55:32 +0000 | [diff] [blame] | 586 | " will arrive at exit from genericUnwind(): ", exit.willArriveAtOSRExitFromGenericUnwind(), |
sbarati@apple.com | 936707d | 2015-12-03 21:09:41 +0000 | [diff] [blame] | 587 | " will arrive at exit from lazy slow path: ", exit.m_exceptionType == ExceptionType::LazySlowPath, "\n"); |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 588 | dataLog(" Exit values: ", exit.m_descriptor->m_values, "\n"); |
| 589 | if (!exit.m_descriptor->m_materializations.isEmpty()) { |
fpizlo@apple.com | 09b14f9 | 2015-05-13 05:21:16 +0000 | [diff] [blame] | 590 | dataLog(" Materializations:\n"); |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 591 | for (ExitTimeObjectMaterialization* materialization : exit.m_descriptor->m_materializations) |
fpizlo@apple.com | 09b14f9 | 2015-05-13 05:21:16 +0000 | [diff] [blame] | 592 | dataLog(" ", pointerDump(materialization), "\n"); |
| 593 | } |
| 594 | } |
| 595 | |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 596 | prepareCodeOriginForOSRExit(exec, exit.m_codeOrigin); |
| 597 | |
fpizlo@apple.com | 6bf1198 | 2013-11-03 18:24:20 +0000 | [diff] [blame] | 598 | compileStub(exitID, jitCode, exit, vm, codeBlock); |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 599 | |
fpizlo@apple.com | 7a79726 | 2015-09-03 21:11:59 +0000 | [diff] [blame] | 600 | MacroAssembler::repatchJump( |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 601 | exit.codeLocationForRepatch(codeBlock), CodeLocationLabel(exit.m_code.code())); |
| 602 | |
| 603 | return exit.m_code.code().executableAddress(); |
| 604 | } |
| 605 | |
| 606 | } } // namespace JSC::FTL |
| 607 | |
| 608 | #endif // ENABLE(FTL_JIT) |
| 609 | |