Object cycles should not prevent allocation elimination/sinking
[WebKit-https.git] / Source / JavaScriptCore / ftl / FTLOSRExitCompiler.cpp
1 /*
2  * Copyright (C) 2013-2015 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 "FTLOSRExitCompiler.h"
28
29 #if ENABLE(FTL_JIT)
30
31 #include "DFGOSRExitCompilerCommon.h"
32 #include "DFGOSRExitPreparation.h"
33 #include "FTLExitArgumentForOperand.h"
34 #include "FTLJITCode.h"
35 #include "FTLOSRExit.h"
36 #include "FTLOperations.h"
37 #include "FTLState.h"
38 #include "FTLSaveRestore.h"
39 #include "LinkBuffer.h"
40 #include "MaxFrameExtentForSlowPathCall.h"
41 #include "OperandsInlines.h"
42 #include "JSCInlines.h"
43 #include "RegisterPreservationWrapperGenerator.h"
44 #include "RepatchBuffer.h"
45
46 namespace JSC { namespace FTL {
47
48 using namespace DFG;
49
50 static void compileRecovery(
51     CCallHelpers& jit, const ExitValue& value, StackMaps::Record* record, StackMaps& stackmaps,
52     char* registerScratch,
53     const HashMap<ExitTimeObjectMaterialization*, EncodedJSValue*>& materializationToPointer)
54 {
55     switch (value.kind()) {
56     case ExitValueDead:
57         jit.move(MacroAssembler::TrustedImm64(JSValue::encode(jsUndefined())), GPRInfo::regT0);
58         break;
59             
60     case ExitValueConstant:
61         jit.move(MacroAssembler::TrustedImm64(JSValue::encode(value.constant())), GPRInfo::regT0);
62         break;
63             
64     case ExitValueArgument:
65         record->locations[value.exitArgument().argument()].restoreInto(
66             jit, stackmaps, registerScratch, GPRInfo::regT0);
67         break;
68             
69     case ExitValueInJSStack:
70     case ExitValueInJSStackAsInt32:
71     case ExitValueInJSStackAsInt52:
72     case ExitValueInJSStackAsDouble:
73         jit.load64(AssemblyHelpers::addressFor(value.virtualRegister()), GPRInfo::regT0);
74         break;
75             
76     case ExitValueRecovery:
77         record->locations[value.rightRecoveryArgument()].restoreInto(
78             jit, stackmaps, registerScratch, GPRInfo::regT1);
79         record->locations[value.leftRecoveryArgument()].restoreInto(
80             jit, stackmaps, registerScratch, GPRInfo::regT0);
81         switch (value.recoveryOpcode()) {
82         case AddRecovery:
83             switch (value.recoveryFormat()) {
84             case ValueFormatInt32:
85                 jit.add32(GPRInfo::regT1, GPRInfo::regT0);
86                 break;
87             case ValueFormatInt52:
88                 jit.add64(GPRInfo::regT1, GPRInfo::regT0);
89                 break;
90             default:
91                 RELEASE_ASSERT_NOT_REACHED();
92                 break;
93             }
94             break;
95         case SubRecovery:
96             switch (value.recoveryFormat()) {
97             case ValueFormatInt32:
98                 jit.sub32(GPRInfo::regT1, GPRInfo::regT0);
99                 break;
100             case ValueFormatInt52:
101                 jit.sub64(GPRInfo::regT1, GPRInfo::regT0);
102                 break;
103             default:
104                 RELEASE_ASSERT_NOT_REACHED();
105                 break;
106             }
107             break;
108         default:
109             RELEASE_ASSERT_NOT_REACHED();
110             break;
111         }
112         break;
113         
114     case ExitValueMaterializeNewObject:
115         jit.loadPtr(materializationToPointer.get(value.objectMaterialization()), GPRInfo::regT0);
116         break;
117             
118     default:
119         RELEASE_ASSERT_NOT_REACHED();
120         break;
121     }
122         
123     reboxAccordingToFormat(
124         value.valueFormat(), jit, GPRInfo::regT0, GPRInfo::regT1, GPRInfo::regT2);
125 }
126
127 static void compileStub(
128     unsigned exitID, JITCode* jitCode, OSRExit& exit, VM* vm, CodeBlock* codeBlock)
129 {
130     StackMaps::Record* record = nullptr;
131     
132     for (unsigned i = jitCode->stackmaps.records.size(); i--;) {
133         record = &jitCode->stackmaps.records[i];
134         if (record->patchpointID == exit.m_stackmapID)
135             break;
136     }
137     
138     RELEASE_ASSERT(record->patchpointID == exit.m_stackmapID);
139     
140     // This code requires framePointerRegister is the same as callFrameRegister
141     static_assert(MacroAssembler::framePointerRegister == GPRInfo::callFrameRegister, "MacroAssembler::framePointerRegister and GPRInfo::callFrameRegister must be the same");
142
143     CCallHelpers jit(vm, codeBlock);
144     
145     // We need scratch space to save all registers, to build up the JS stack, to deal with unwind
146     // fixup, pointers to all of the objects we materialize, and the elements inside those objects
147     // that we materialize.
148     
149     // Figure out how much space we need for those object allocations.
150     unsigned numMaterializations = 0;
151     size_t maxMaterializationNumArguments = 0;
152     for (ExitTimeObjectMaterialization* materialization : exit.m_materializations) {
153         numMaterializations++;
154         
155         maxMaterializationNumArguments = std::max(
156             maxMaterializationNumArguments,
157             materialization->properties().size());
158     }
159     
160     ScratchBuffer* scratchBuffer = vm->scratchBufferForSize(
161         sizeof(EncodedJSValue) * (
162             exit.m_values.size() + numMaterializations + maxMaterializationNumArguments) +
163         requiredScratchMemorySizeInBytes() +
164         jitCode->unwindInfo.m_registers.size() * sizeof(uint64_t));
165     EncodedJSValue* scratch = scratchBuffer ? static_cast<EncodedJSValue*>(scratchBuffer->dataBuffer()) : 0;
166     EncodedJSValue* materializationPointers = scratch + exit.m_values.size();
167     EncodedJSValue* materializationArguments = materializationPointers + numMaterializations;
168     char* registerScratch = bitwise_cast<char*>(materializationArguments + maxMaterializationNumArguments);
169     uint64_t* unwindScratch = bitwise_cast<uint64_t*>(registerScratch + requiredScratchMemorySizeInBytes());
170     
171     HashMap<ExitTimeObjectMaterialization*, EncodedJSValue*> materializationToPointer;
172     unsigned materializationCount = 0;
173     for (ExitTimeObjectMaterialization* materialization : exit.m_materializations) {
174         materializationToPointer.add(
175             materialization, materializationPointers + materializationCount++);
176     }
177     
178     // Note that we come in here, the stack used to be as LLVM left it except that someone called pushToSave().
179     // We don't care about the value they saved. But, we do appreciate the fact that they did it, because we use
180     // that slot for saveAllRegisters().
181
182     saveAllRegisters(jit, registerScratch);
183     
184     // Bring the stack back into a sane form and assert that it's sane.
185     jit.popToRestore(GPRInfo::regT0);
186     jit.checkStackPointerAlignment();
187     
188     if (vm->m_perBytecodeProfiler && codeBlock->jitCode()->dfgCommon()->compilation) {
189         Profiler::Database& database = *vm->m_perBytecodeProfiler;
190         Profiler::Compilation* compilation = codeBlock->jitCode()->dfgCommon()->compilation.get();
191         
192         Profiler::OSRExit* profilerExit = compilation->addOSRExit(
193             exitID, Profiler::OriginStack(database, codeBlock, exit.m_codeOrigin),
194             exit.m_kind, exit.m_kind == UncountableInvalidation);
195         jit.add64(CCallHelpers::TrustedImm32(1), CCallHelpers::AbsoluteAddress(profilerExit->counterAddress()));
196     }
197
198     // The remaining code assumes that SP/FP are in the same state that they were in the FTL's
199     // call frame.
200     
201     // Get the call frame and tag thingies.
202     // Restore the exiting function's callFrame value into a regT4
203     jit.move(MacroAssembler::TrustedImm64(TagTypeNumber), GPRInfo::tagTypeNumberRegister);
204     jit.move(MacroAssembler::TrustedImm64(TagMask), GPRInfo::tagMaskRegister);
205     
206     // Do some value profiling.
207     if (exit.m_profileValueFormat != InvalidValueFormat) {
208         record->locations[0].restoreInto(jit, jitCode->stackmaps, registerScratch, GPRInfo::regT0);
209         reboxAccordingToFormat(
210             exit.m_profileValueFormat, jit, GPRInfo::regT0, GPRInfo::regT1, GPRInfo::regT2);
211         
212         if (exit.m_kind == BadCache || exit.m_kind == BadIndexingType) {
213             CodeOrigin codeOrigin = exit.m_codeOriginForExitProfile;
214             if (ArrayProfile* arrayProfile = jit.baselineCodeBlockFor(codeOrigin)->getArrayProfile(codeOrigin.bytecodeIndex)) {
215                 jit.load32(MacroAssembler::Address(GPRInfo::regT0, JSCell::structureIDOffset()), GPRInfo::regT1);
216                 jit.store32(GPRInfo::regT1, arrayProfile->addressOfLastSeenStructureID());
217                 jit.load8(MacroAssembler::Address(GPRInfo::regT0, JSCell::indexingTypeOffset()), GPRInfo::regT1);
218                 jit.move(MacroAssembler::TrustedImm32(1), GPRInfo::regT2);
219                 jit.lshift32(GPRInfo::regT1, GPRInfo::regT2);
220                 jit.or32(GPRInfo::regT2, MacroAssembler::AbsoluteAddress(arrayProfile->addressOfArrayModes()));
221             }
222         }
223
224         if (!!exit.m_valueProfile)
225             jit.store64(GPRInfo::regT0, exit.m_valueProfile.getSpecFailBucket(0));
226     }
227
228     // Materialize all objects. Don't materialize an object until all
229     // of the objects it needs have been materialized. We break cycles
230     // by populating objects late - we only consider an object as
231     // needing another object if the later is needed for the
232     // allocation of the former.
233
234     HashSet<ExitTimeObjectMaterialization*> toMaterialize;
235     for (ExitTimeObjectMaterialization* materialization : exit.m_materializations)
236         toMaterialize.add(materialization);
237
238     while (!toMaterialize.isEmpty()) {
239         unsigned previousToMaterializeSize = toMaterialize.size();
240
241         Vector<ExitTimeObjectMaterialization*> worklist;
242         worklist.appendRange(toMaterialize.begin(), toMaterialize.end());
243         for (ExitTimeObjectMaterialization* materialization : worklist) {
244             // Check if we can do anything about this right now.
245             bool allGood = true;
246             for (ExitPropertyValue value : materialization->properties()) {
247                 if (!value.value().isObjectMaterialization())
248                     continue;
249                 if (!value.location().neededForMaterialization())
250                     continue;
251                 if (toMaterialize.contains(value.value().objectMaterialization())) {
252                     // Gotta skip this one, since it needs a
253                     // materialization that hasn't been materialized.
254                     allGood = false;
255                     break;
256                 }
257             }
258             if (!allGood)
259                 continue;
260
261             // All systems go for materializing the object. First we
262             // recover the values of all of its fields and then we
263             // call a function to actually allocate the beast.
264             // We only recover the fields that are needed for the allocation.
265             for (unsigned propertyIndex = materialization->properties().size(); propertyIndex--;) {
266                 const ExitPropertyValue& property = materialization->properties()[propertyIndex];
267                 const ExitValue& value = property.value();
268                 if (!property.location().neededForMaterialization())
269                     continue;
270
271                 compileRecovery(
272                     jit, value, record, jitCode->stackmaps, registerScratch,
273                     materializationToPointer);
274                 jit.storePtr(GPRInfo::regT0, materializationArguments + propertyIndex);
275             }
276             
277             // This call assumes that we don't pass arguments on the stack.
278             jit.setupArgumentsWithExecState(
279                 CCallHelpers::TrustedImmPtr(materialization),
280                 CCallHelpers::TrustedImmPtr(materializationArguments));
281             jit.move(CCallHelpers::TrustedImmPtr(bitwise_cast<void*>(operationMaterializeObjectInOSR)), GPRInfo::nonArgGPR0);
282             jit.call(GPRInfo::nonArgGPR0);
283             jit.storePtr(GPRInfo::returnValueGPR, materializationToPointer.get(materialization));
284
285             // Let everyone know that we're done.
286             toMaterialize.remove(materialization);
287         }
288         
289         // We expect progress! This ensures that we crash rather than looping infinitely if there
290         // is something broken about this fixpoint. Or, this could happen if we ever violate the
291         // "materializations form a DAG" rule.
292         RELEASE_ASSERT(toMaterialize.size() < previousToMaterializeSize);
293     }
294
295     // Now that all the objects have been allocated, we populate them
296     // with the correct values. This time we can recover all the
297     // fields, including those that are only needed for the allocation.
298     for (ExitTimeObjectMaterialization* materialization : exit.m_materializations) {
299         for (unsigned propertyIndex = materialization->properties().size(); propertyIndex--;) {
300             const ExitValue& value = materialization->properties()[propertyIndex].value();
301             compileRecovery(
302                 jit, value, record, jitCode->stackmaps, registerScratch,
303                 materializationToPointer);
304             jit.storePtr(GPRInfo::regT0, materializationArguments + propertyIndex);
305         }
306
307         // This call assumes that we don't pass arguments on the stack
308         jit.setupArgumentsWithExecState(
309             CCallHelpers::TrustedImmPtr(materialization),
310             CCallHelpers::TrustedImmPtr(materializationToPointer.get(materialization)),
311             CCallHelpers::TrustedImmPtr(materializationArguments));
312         jit.move(CCallHelpers::TrustedImmPtr(bitwise_cast<void*>(operationPopulateObjectInOSR)), GPRInfo::nonArgGPR0);
313         jit.call(GPRInfo::nonArgGPR0);
314     }
315
316     // Save all state from wherever the exit data tells us it was, into the appropriate place in
317     // the scratch buffer. This also does the reboxing.
318     
319     for (unsigned index = exit.m_values.size(); index--;) {
320         compileRecovery(
321             jit, exit.m_values[index], record, jitCode->stackmaps, registerScratch,
322             materializationToPointer);
323         jit.store64(GPRInfo::regT0, scratch + index);
324     }
325     
326     // Henceforth we make it look like the exiting function was called through a register
327     // preservation wrapper. This implies that FP must be nudged down by a certain amount. Then
328     // we restore the various things according to either exit.m_values or by copying from the
329     // old frame, and finally we save the various callee-save registers into where the
330     // restoration thunk would restore them from.
331     
332     ptrdiff_t offset = registerPreservationOffset();
333     RegisterSet toSave = registersToPreserve();
334     
335     // Before we start messing with the frame, we need to set aside any registers that the
336     // FTL code was preserving.
337     for (unsigned i = jitCode->unwindInfo.m_registers.size(); i--;) {
338         RegisterAtOffset entry = jitCode->unwindInfo.m_registers[i];
339         jit.load64(
340             MacroAssembler::Address(MacroAssembler::framePointerRegister, entry.offset()),
341             GPRInfo::regT0);
342         jit.store64(GPRInfo::regT0, unwindScratch + i);
343     }
344     
345     jit.load32(CCallHelpers::payloadFor(JSStack::ArgumentCount), GPRInfo::regT2);
346     
347     // Let's say that the FTL function had failed its arity check. In that case, the stack will
348     // contain some extra stuff.
349     //
350     // First we compute the padded stack space:
351     //
352     //     paddedStackSpace = roundUp(codeBlock->numParameters - regT2 + 1)
353     //
354     // The stack will have regT2 + CallFrameHeaderSize stuff, but above it there will be
355     // paddedStackSpace gunk used by the arity check fail restoration thunk. When that happens
356     // we want to make the stack look like this, from higher addresses down:
357     //
358     //     - register preservation return PC
359     //     - preserved registers
360     //     - arity check fail return PC
361     //     - argument padding
362     //     - actual arguments
363     //     - call frame header
364     //
365     // So that the actual call frame header appears to return to the arity check fail return
366     // PC, and that then returns to the register preservation thunk. The arity check thunk that
367     // we return to will have the padding size encoded into it. It will then know to return
368     // into the register preservation thunk, which uses the argument count to figure out where
369     // registers are preserved.
370
371     // This code assumes that we're dealing with FunctionCode.
372     RELEASE_ASSERT(codeBlock->codeType() == FunctionCode);
373     
374     jit.add32(
375         MacroAssembler::TrustedImm32(-codeBlock->numParameters()), GPRInfo::regT2,
376         GPRInfo::regT3);
377     MacroAssembler::Jump arityIntact = jit.branch32(
378         MacroAssembler::GreaterThanOrEqual, GPRInfo::regT3, MacroAssembler::TrustedImm32(0));
379     jit.neg32(GPRInfo::regT3);
380     jit.add32(MacroAssembler::TrustedImm32(1 + stackAlignmentRegisters() - 1), GPRInfo::regT3);
381     jit.and32(MacroAssembler::TrustedImm32(-stackAlignmentRegisters()), GPRInfo::regT3);
382     jit.add32(GPRInfo::regT3, GPRInfo::regT2);
383     arityIntact.link(&jit);
384
385     // First set up SP so that our data doesn't get clobbered by signals.
386     unsigned conservativeStackDelta =
387         registerPreservationOffset() +
388         exit.m_values.numberOfLocals() * sizeof(Register) +
389         maxFrameExtentForSlowPathCall;
390     conservativeStackDelta = WTF::roundUpToMultipleOf(
391         stackAlignmentBytes(), conservativeStackDelta);
392     jit.addPtr(
393         MacroAssembler::TrustedImm32(-conservativeStackDelta),
394         MacroAssembler::framePointerRegister, MacroAssembler::stackPointerRegister);
395     jit.checkStackPointerAlignment();
396     
397     jit.subPtr(
398         MacroAssembler::TrustedImm32(registerPreservationOffset()),
399         MacroAssembler::framePointerRegister);
400     
401     // Copy the old frame data into its new location.
402     jit.add32(MacroAssembler::TrustedImm32(JSStack::CallFrameHeaderSize), GPRInfo::regT2);
403     jit.move(MacroAssembler::framePointerRegister, GPRInfo::regT1);
404     MacroAssembler::Label loop = jit.label();
405     jit.sub32(MacroAssembler::TrustedImm32(1), GPRInfo::regT2);
406     jit.load64(MacroAssembler::Address(GPRInfo::regT1, offset), GPRInfo::regT0);
407     jit.store64(GPRInfo::regT0, GPRInfo::regT1);
408     jit.addPtr(MacroAssembler::TrustedImm32(sizeof(Register)), GPRInfo::regT1);
409     jit.branchTest32(MacroAssembler::NonZero, GPRInfo::regT2).linkTo(loop, &jit);
410     
411     // At this point regT1 points to where we would save our registers. Save them here.
412     ptrdiff_t currentOffset = 0;
413     for (Reg reg = Reg::first(); reg <= Reg::last(); reg = reg.next()) {
414         if (!toSave.get(reg))
415             continue;
416         currentOffset += sizeof(Register);
417         unsigned unwindIndex = jitCode->unwindInfo.indexOf(reg);
418         if (unwindIndex == UINT_MAX) {
419             // The FTL compilation didn't preserve this register. This means that it also
420             // didn't use the register. So its value at the beginning of OSR exit should be
421             // preserved by the thunk. Luckily, we saved all registers into the register
422             // scratch buffer, so we can restore them from there.
423             jit.load64(registerScratch + offsetOfReg(reg), GPRInfo::regT0);
424         } else {
425             // The FTL compilation preserved the register. Its new value is therefore
426             // irrelevant, but we can get the value that was preserved by using the unwind
427             // data. We've already copied all unwind-able preserved registers into the unwind
428             // scratch buffer, so we can get it from there.
429             jit.load64(unwindScratch + unwindIndex, GPRInfo::regT0);
430         }
431         jit.store64(GPRInfo::regT0, AssemblyHelpers::Address(GPRInfo::regT1, currentOffset));
432     }
433     
434     // We need to make sure that we return into the register restoration thunk. This works
435     // differently depending on whether or not we had arity issues.
436     MacroAssembler::Jump arityIntactForReturnPC = jit.branch32(
437         MacroAssembler::GreaterThanOrEqual,
438         CCallHelpers::payloadFor(JSStack::ArgumentCount),
439         MacroAssembler::TrustedImm32(codeBlock->numParameters()));
440     
441     // The return PC in the call frame header points at exactly the right arity restoration
442     // thunk. We don't want to change that. But the arity restoration thunk's frame has a
443     // return PC and we want to reroute that to our register restoration thunk. The arity
444     // restoration's return PC just just below regT1, and the register restoration's return PC
445     // is right at regT1.
446     jit.loadPtr(MacroAssembler::Address(GPRInfo::regT1, -static_cast<ptrdiff_t>(sizeof(Register))), GPRInfo::regT0);
447     jit.storePtr(GPRInfo::regT0, GPRInfo::regT1);
448     jit.storePtr(
449         MacroAssembler::TrustedImmPtr(vm->getCTIStub(registerRestorationThunkGenerator).code().executableAddress()),
450         MacroAssembler::Address(GPRInfo::regT1, -static_cast<ptrdiff_t>(sizeof(Register))));
451     
452     MacroAssembler::Jump arityReturnPCReady = jit.jump();
453
454     arityIntactForReturnPC.link(&jit);
455     
456     jit.loadPtr(MacroAssembler::Address(MacroAssembler::framePointerRegister, CallFrame::returnPCOffset()), GPRInfo::regT0);
457     jit.storePtr(GPRInfo::regT0, GPRInfo::regT1);
458     jit.storePtr(
459         MacroAssembler::TrustedImmPtr(vm->getCTIStub(registerRestorationThunkGenerator).code().executableAddress()),
460         MacroAssembler::Address(MacroAssembler::framePointerRegister, CallFrame::returnPCOffset()));
461     
462     arityReturnPCReady.link(&jit);
463     
464     // Now get state out of the scratch buffer and place it back into the stack. The values are
465     // already reboxed so we just move them.
466     for (unsigned index = exit.m_values.size(); index--;) {
467         int operand = exit.m_values.operandForIndex(index);
468         
469         jit.load64(scratch + index, GPRInfo::regT0);
470         jit.store64(GPRInfo::regT0, AssemblyHelpers::addressFor(static_cast<VirtualRegister>(operand)));
471     }
472     
473     handleExitCounts(jit, exit);
474     reifyInlinedCallFrames(jit, exit);
475     adjustAndJumpToTarget(jit, exit);
476     
477     LinkBuffer patchBuffer(*vm, jit, codeBlock);
478     exit.m_code = FINALIZE_CODE_IF(
479         shouldShowDisassembly() || Options::verboseOSR() || Options::verboseFTLOSRExit(),
480         patchBuffer,
481         ("FTL OSR exit #%u (%s, %s) from %s, with operands = %s, and record = %s",
482             exitID, toCString(exit.m_codeOrigin).data(),
483             exitKindToString(exit.m_kind), toCString(*codeBlock).data(),
484             toCString(ignoringContext<DumpContext>(exit.m_values)).data(),
485             toCString(*record).data()));
486 }
487
488 extern "C" void* compileFTLOSRExit(ExecState* exec, unsigned exitID)
489 {
490     SamplingRegion samplingRegion("FTL OSR Exit Compilation");
491
492     if (shouldShowDisassembly() || Options::verboseOSR() || Options::verboseFTLOSRExit())
493         dataLog("Compiling OSR exit with exitID = ", exitID, "\n");
494     
495     CodeBlock* codeBlock = exec->codeBlock();
496     
497     ASSERT(codeBlock);
498     ASSERT(codeBlock->jitType() == JITCode::FTLJIT);
499     
500     VM* vm = &exec->vm();
501     
502     // It's sort of preferable that we don't GC while in here. Anyways, doing so wouldn't
503     // really be profitable.
504     DeferGCForAWhile deferGC(vm->heap);
505
506     JITCode* jitCode = codeBlock->jitCode()->ftl();
507     OSRExit& exit = jitCode->osrExit[exitID];
508     
509     if (shouldShowDisassembly() || Options::verboseOSR() || Options::verboseFTLOSRExit()) {
510         dataLog("    Owning block: ", pointerDump(codeBlock), "\n");
511         dataLog("    Origin: ", exit.m_codeOrigin, "\n");
512         if (exit.m_codeOriginForExitProfile != exit.m_codeOrigin)
513             dataLog("    Origin for exit profile: ", exit.m_codeOriginForExitProfile, "\n");
514         dataLog("    Exit values: ", exit.m_values, "\n");
515         if (!exit.m_materializations.isEmpty()) {
516             dataLog("    Materializations:\n");
517             for (ExitTimeObjectMaterialization* materialization : exit.m_materializations)
518                 dataLog("        ", pointerDump(materialization), "\n");
519         }
520     }
521
522     prepareCodeOriginForOSRExit(exec, exit.m_codeOrigin);
523     
524     compileStub(exitID, jitCode, exit, vm, codeBlock);
525     
526     RepatchBuffer repatchBuffer(codeBlock);
527     repatchBuffer.relink(
528         exit.codeLocationForRepatch(codeBlock), CodeLocationLabel(exit.m_code.code()));
529     
530     return exit.m_code.code().executableAddress();
531 }
532
533 } } // namespace JSC::FTL
534
535 #endif // ENABLE(FTL_JIT)
536