Debian Codegraph @

js/src/jit/Recover.cpp

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #include "jit/Recover.h"
8
9 #include "mozilla/Casting.h"
10
11 #include "jsmath.h"
12
13 #include "builtin/Object.h"
14 #include "builtin/String.h"
15 #include "jit/AtomicOperations.h"
16 #include "jit/Bailouts.h"
17 #include "jit/CompileInfo.h"
18 #include "jit/Ion.h"
19 #include "jit/JitSpewer.h"
20 #include "jit/JSJitFrameIter.h"
21 #include "jit/MIR-wasm.h"
22 #include "jit/MIR.h"
23 #include "jit/MIRGraph.h"
24 #include "jit/VMFunctions.h"
25 #include "js/ScalarType.h"
26 #include "util/DifferentialTesting.h"
27 #include "vm/BigIntType.h"
28 #include "vm/EqualityOperations.h"
29 #include "vm/Interpreter.h"
30 #include "vm/Iteration.h"
31 #include "vm/JSContext.h"
32 #include "vm/JSObject.h"
33 #include "vm/PlainObject.h" // js::PlainObject
34 #include "vm/StringType.h"
35 #include "vm/Watchtower.h"
36
37 #include "vm/Interpreter-inl.h"
38
39 using namespace js;
40 using namespace js::jit;
41
42 bool MNode::writeRecoverData(CompactBufferWriter& writer) const {
43 MOZ_CRASH("This instruction is not serializable");
44 }
45
46 void RInstruction::readRecoverData(CompactBufferReader& reader,
47 RInstructionStorage* raw) {
48 uint32_t op = reader.readUnsigned();
49 switch (Opcode(op)) {
50 #define MATCH_OPCODES_(op) \
51 case Recover_##op: \
52 static_assert(sizeof(R##op) <= sizeof(RInstructionStorage), \
53 "storage space must be big enough to store R" #op); \
54 static_assert(alignof(R##op) <= alignof(RInstructionStorage), \
55 "storage space must be aligned adequate to store R" #op); \
56 new (raw->addr()) R##op(reader); \
57 break;
58
59 RECOVER_OPCODE_LIST(MATCH_OPCODES_)
60 #undef MATCH_OPCODES_
61
62 case Recover_Invalid:
63 default:
64 MOZ_CRASH("Bad decoding of the previous instruction?");
65 }
66 }
67
68 bool MResumePoint::writeRecoverData(CompactBufferWriter& writer) const {
69 writer.writeUnsigned(uint32_t(RInstruction::Recover_ResumePoint));
70
71 MBasicBlock* bb = block();
72 bool hasFun = bb->info().hasFunMaybeLazy();
73 uint32_t nargs = bb->info().nargs();
74 JSScript* script = bb->info().script();
75 uint32_t exprStack = stackDepth() - bb->info().ninvoke();
76
77 #ifdef DEBUG
78 // Ensure that all snapshot which are encoded can safely be used for
79 // bailouts.
80 uint32_t numIntermediate = NumIntermediateValues(mode());
81 if (JSContext* cx = GetJitContext()->cx) {
82 if (!AssertBailoutStackDepth(cx, script, pc(), mode(),
83 exprStack - numIntermediate)) {
84 return false;
85 }
86 }
87 #endif
88
89 uint32_t formalArgs = CountArgSlots(script, hasFun, nargs);
90
91 // Test if we honor the maximum of arguments at all times. This is a sanity
92 // check and not an algorithm limit. So check might be a bit too loose. +4
93 // to account for scope chain, return value, this value and maybe
94 // arguments_object.
95 MOZ_ASSERT(formalArgs < SNAPSHOT_MAX_NARGS + 4);
96
97 #ifdef JS_JITSPEW
98 uint32_t implicit = StartArgSlot(script);
99 #endif
100 uint32_t nallocs = formalArgs + script->nfixed() + exprStack;
101
102 JitSpew(JitSpew_IonSnapshots,
103 "Starting frame; implicit %u, formals %u, fixed %zu, exprs %u",
104 implicit, formalArgs - implicit, script->nfixed(), exprStack);
105
106 uint32_t pcOff = script->pcToOffset(pc());
107 JitSpew(JitSpew_IonSnapshots, "Writing pc offset %u, mode %s, nslots %u",
108 pcOff, ResumeModeToString(mode()), nallocs);
109
110 uint32_t pcOffAndMode =
111 (pcOff << RResumePoint::PCOffsetShift) | uint32_t(mode());
112 MOZ_RELEASE_ASSERT((pcOffAndMode >> RResumePoint::PCOffsetShift) == pcOff,
113 "pcOff doesn't fit in pcOffAndMode");
114 writer.writeUnsigned(pcOffAndMode);
115
116 writer.writeUnsigned(nallocs);
117 return true;
118 }
119
120 RResumePoint::RResumePoint(CompactBufferReader& reader) {
121 pcOffsetAndMode_ = reader.readUnsigned();
122 numOperands_ = reader.readUnsigned();
123 JitSpew(JitSpew_IonSnapshots,
124 "Read RResumePoint (pc offset %u, mode %s, nslots %u)", pcOffset(),
125 ResumeModeToString(mode()), numOperands_);
126 }
127
128 bool RResumePoint::recover(JSContext* cx, SnapshotIterator& iter) const {
129 MOZ_CRASH("This instruction is not recoverable.");
130 }
131
132 bool MBitNot::writeRecoverData(CompactBufferWriter& writer) const {
133 // 64-bit int bitnots exist only when compiling wasm; they exist neither for
134 // JS nor asm.js. So we don't expect them here.
135 MOZ_ASSERT(type() != MIRType::Int64);
136 MOZ_ASSERT(canRecoverOnBailout());
137 writer.writeUnsigned(uint32_t(RInstruction::Recover_BitNot));
138 return true;
139 }
140
141 RBitNot::RBitNot(CompactBufferReader& reader) {}
142
143 bool RBitNot::recover(JSContext* cx, SnapshotIterator& iter) const {
144 RootedValue operand(cx, iter.read());
145 RootedValue result(cx);
146
147 if (!js::BitNot(cx, &operand, &result)) {
148 return false;
149 }
150
151 iter.storeInstructionResult(result);
152 return true;
153 }
154
155 bool MBitAnd::writeRecoverData(CompactBufferWriter& writer) const {
156 MOZ_ASSERT(canRecoverOnBailout());
157 writer.writeUnsigned(uint32_t(RInstruction::Recover_BitAnd));
158 return true;
159 }
160
161 RBitAnd::RBitAnd(CompactBufferReader& reader) {}
162
163 bool RBitAnd::recover(JSContext* cx, SnapshotIterator& iter) const {
164 RootedValue lhs(cx, iter.read());
165 RootedValue rhs(cx, iter.read());
166 RootedValue result(cx);
167 MOZ_ASSERT(!lhs.isObject() && !rhs.isObject());
168
169 if (!js::BitAnd(cx, &lhs, &rhs, &result)) {
170 return false;
171 }
172
173 iter.storeInstructionResult(result);
174 return true;
175 }
176
177 bool MBitOr::writeRecoverData(CompactBufferWriter& writer) const {
178 MOZ_ASSERT(canRecoverOnBailout());
179 writer.writeUnsigned(uint32_t(RInstruction::Recover_BitOr));
180 return true;
181 }
182
183 RBitOr::RBitOr(CompactBufferReader& reader) {}
184
185 bool RBitOr::recover(JSContext* cx, SnapshotIterator& iter) const {
186 RootedValue lhs(cx, iter.read());
187 RootedValue rhs(cx, iter.read());
188 RootedValue result(cx);
189 MOZ_ASSERT(!lhs.isObject() && !rhs.isObject());
190
191 if (!js::BitOr(cx, &lhs, &rhs, &result)) {
192 return false;
193 }
194
195 iter.storeInstructionResult(result);
196 return true;
197 }
198
199 bool MBitXor::writeRecoverData(CompactBufferWriter& writer) const {
200 MOZ_ASSERT(canRecoverOnBailout());
201 writer.writeUnsigned(uint32_t(RInstruction::Recover_BitXor));
202 return true;
203 }
204
205 RBitXor::RBitXor(CompactBufferReader& reader) {}
206
207 bool RBitXor::recover(JSContext* cx, SnapshotIterator& iter) const {
208 RootedValue lhs(cx, iter.read());
209 RootedValue rhs(cx, iter.read());
210 RootedValue result(cx);
211
212 if (!js::BitXor(cx, &lhs, &rhs, &result)) {
213 return false;
214 }
215
216 iter.storeInstructionResult(result);
217 return true;
218 }
219
220 bool MLsh::writeRecoverData(CompactBufferWriter& writer) const {
221 MOZ_ASSERT(canRecoverOnBailout());
222 writer.writeUnsigned(uint32_t(RInstruction::Recover_Lsh));
223 return true;
224 }
225
226 RLsh::RLsh(CompactBufferReader& reader) {}
227
228 bool RLsh::recover(JSContext* cx, SnapshotIterator& iter) const {
229 RootedValue lhs(cx, iter.read());
230 RootedValue rhs(cx, iter.read());
231 RootedValue result(cx);
232 MOZ_ASSERT(!lhs.isObject() && !rhs.isObject());
233
234 if (!js::BitLsh(cx, &lhs, &rhs, &result)) {
235 return false;
236 }
237
238 iter.storeInstructionResult(result);
239 return true;
240 }
241
242 bool MRsh::writeRecoverData(CompactBufferWriter& writer) const {
243 MOZ_ASSERT(canRecoverOnBailout());
244 writer.writeUnsigned(uint32_t(RInstruction::Recover_Rsh));
245 return true;
246 }
247
248 RRsh::RRsh(CompactBufferReader& reader) {}
249
250 bool RRsh::recover(JSContext* cx, SnapshotIterator& iter) const {
251 RootedValue lhs(cx, iter.read());
252 RootedValue rhs(cx, iter.read());
253 RootedValue result(cx);
254 MOZ_ASSERT(!lhs.isObject() && !rhs.isObject());
255
256 if (!js::BitRsh(cx, &lhs, &rhs, &result)) {
257 return false;
258 }
259
260 iter.storeInstructionResult(result);
261 return true;
262 }
263
264 bool MUrsh::writeRecoverData(CompactBufferWriter& writer) const {
265 MOZ_ASSERT(canRecoverOnBailout());
266 writer.writeUnsigned(uint32_t(RInstruction::Recover_Ursh));
267 return true;
268 }
269
270 RUrsh::RUrsh(CompactBufferReader& reader) {}
271
272 bool RUrsh::recover(JSContext* cx, SnapshotIterator& iter) const {
273 RootedValue lhs(cx, iter.read());
274 RootedValue rhs(cx, iter.read());
275 MOZ_ASSERT(!lhs.isObject() && !rhs.isObject());
276
277 RootedValue result(cx);
278 if (!js::UrshValues(cx, &lhs, &rhs, &result)) {
279 return false;
280 }
281
282 iter.storeInstructionResult(result);
283 return true;
284 }
285
286 bool MSignExtendInt32::writeRecoverData(CompactBufferWriter& writer) const {
287 MOZ_ASSERT(canRecoverOnBailout());
288 writer.writeUnsigned(uint32_t(RInstruction::Recover_SignExtendInt32));
289 MOZ_ASSERT(Mode(uint8_t(mode_)) == mode_);
290 writer.writeByte(uint8_t(mode_));
291 return true;
292 }
293
294 RSignExtendInt32::RSignExtendInt32(CompactBufferReader& reader) {
295 mode_ = reader.readByte();
296 }
297
298 bool RSignExtendInt32::recover(JSContext* cx, SnapshotIterator& iter) const {
299 RootedValue operand(cx, iter.read());
300
301 int32_t i;
302 if (!ToInt32(cx, operand, &i)) {
303 return false;
304 }
305
306 int32_t result;
307 switch (MSignExtendInt32::Mode(mode_)) {
308 case MSignExtendInt32::Byte:
309 result = static_cast<int8_t>(i);
310 break;
311 case MSignExtendInt32::Half:
312 result = static_cast<int16_t>(i);
313 break;
314 }
315
316 iter.storeInstructionResult(JS::Int32Value(result));
317 return true;
318 }
319
320 bool MAdd::writeRecoverData(CompactBufferWriter& writer) const {
321 MOZ_ASSERT(canRecoverOnBailout());
322 writer.writeUnsigned(uint32_t(RInstruction::Recover_Add));
323 writer.writeByte(type() == MIRType::Float32);
324 return true;
325 }
326
327 RAdd::RAdd(CompactBufferReader& reader) {
328 isFloatOperation_ = reader.readByte();
329 }
330
331 bool RAdd::recover(JSContext* cx, SnapshotIterator& iter) const {
332 RootedValue lhs(cx, iter.read());
333 RootedValue rhs(cx, iter.read());
334 RootedValue result(cx);
335
336 MOZ_ASSERT(!lhs.isObject() && !rhs.isObject());
337 if (!js::AddValues(cx, &lhs, &rhs, &result)) {
338 return false;
339 }
340
341 // MIRType::Float32 is a specialization embedding the fact that the result is
342 // rounded to a Float32.
343 if (isFloatOperation_ && !RoundFloat32(cx, result, &result)) {
344 return false;
345 }
346
347 iter.storeInstructionResult(result);
348 return true;
349 }
350
351 bool MSub::writeRecoverData(CompactBufferWriter& writer) const {
352 MOZ_ASSERT(canRecoverOnBailout());
353 writer.writeUnsigned(uint32_t(RInstruction::Recover_Sub));
354 writer.writeByte(type() == MIRType::Float32);
355 return true;
356 }
357
358 RSub::RSub(CompactBufferReader& reader) {
359 isFloatOperation_ = reader.readByte();
360 }
361
362 bool RSub::recover(JSContext* cx, SnapshotIterator& iter) const {
363 RootedValue lhs(cx, iter.read());
364 RootedValue rhs(cx, iter.read());
365 RootedValue result(cx);
366
367 MOZ_ASSERT(!lhs.isObject() && !rhs.isObject());
368 if (!js::SubValues(cx, &lhs, &rhs, &result)) {
369 return false;
370 }
371
372 // MIRType::Float32 is a specialization embedding the fact that the result is
373 // rounded to a Float32.
374 if (isFloatOperation_ && !RoundFloat32(cx, result, &result)) {
375 return false;
376 }
377
378 iter.storeInstructionResult(result);
379 return true;
380 }
381
382 bool MMul::writeRecoverData(CompactBufferWriter& writer) const {
383 MOZ_ASSERT(canRecoverOnBailout());
384 writer.writeUnsigned(uint32_t(RInstruction::Recover_Mul));
385 writer.writeByte(type() == MIRType::Float32);
386 MOZ_ASSERT(Mode(uint8_t(mode_)) == mode_);
387 writer.writeByte(uint8_t(mode_));
388 return true;
389 }
390
391 RMul::RMul(CompactBufferReader& reader) {
392 isFloatOperation_ = reader.readByte();
393 mode_ = reader.readByte();
394 }
395
396 bool RMul::recover(JSContext* cx, SnapshotIterator& iter) const {
397 RootedValue lhs(cx, iter.read());
398 RootedValue rhs(cx, iter.read());
399 RootedValue result(cx);
400
401 if (MMul::Mode(mode_) == MMul::Normal) {
402 if (!js::MulValues(cx, &lhs, &rhs, &result)) {
403 return false;
404 }
405
406 // MIRType::Float32 is a specialization embedding the fact that the
407 // result is rounded to a Float32.
408 if (isFloatOperation_ && !RoundFloat32(cx, result, &result)) {
409 return false;
410 }
411 } else {
412 MOZ_ASSERT(MMul::Mode(mode_) == MMul::Integer);
413 if (!js::math_imul_handle(cx, lhs, rhs, &result)) {
414 return false;
415 }
416 }
417
418 iter.storeInstructionResult(result);
419 return true;
420 }
421
422 bool MDiv::writeRecoverData(CompactBufferWriter& writer) const {
423 MOZ_ASSERT(canRecoverOnBailout());
424 writer.writeUnsigned(uint32_t(RInstruction::Recover_Div));
425 writer.writeByte(type() == MIRType::Float32);
426 return true;
427 }
428
429 RDiv::RDiv(CompactBufferReader& reader) {
430 isFloatOperation_ = reader.readByte();
431 }
432
433 bool RDiv::recover(JSContext* cx, SnapshotIterator& iter) const {
434 RootedValue lhs(cx, iter.read());
435 RootedValue rhs(cx, iter.read());
436 RootedValue result(cx);
437
438 if (!js::DivValues(cx, &lhs, &rhs, &result)) {
439 return false;
440 }
441
442 // MIRType::Float32 is a specialization embedding the fact that the result is
443 // rounded to a Float32.
444 if (isFloatOperation_ && !RoundFloat32(cx, result, &result)) {
445 return false;
446 }
447
448 iter.storeInstructionResult(result);
449 return true;
450 }
451
452 bool MMod::writeRecoverData(CompactBufferWriter& writer) const {
453 MOZ_ASSERT(canRecoverOnBailout());
454 writer.writeUnsigned(uint32_t(RInstruction::Recover_Mod));
455 return true;
456 }
457
458 RMod::RMod(CompactBufferReader& reader) {}
459
460 bool RMod::recover(JSContext* cx, SnapshotIterator& iter) const {
461 RootedValue lhs(cx, iter.read());
462 RootedValue rhs(cx, iter.read());
463 RootedValue result(cx);
464
465 MOZ_ASSERT(!lhs.isObject() && !rhs.isObject());
466 if (!js::ModValues(cx, &lhs, &rhs, &result)) {
467 return false;
468 }
469
470 iter.storeInstructionResult(result);
471 return true;
472 }
473
474 bool MNot::writeRecoverData(CompactBufferWriter& writer) const {
475 MOZ_ASSERT(canRecoverOnBailout());
476 writer.writeUnsigned(uint32_t(RInstruction::Recover_Not));
477 return true;
478 }
479
480 RNot::RNot(CompactBufferReader& reader) {}
481
482 bool RNot::recover(JSContext* cx, SnapshotIterator& iter) const {
483 Rooted<Value> value(cx);
484 if (!iter.readMaybeUnpackedBigInt(cx, &value)) {
485 return false;
486 }
487
488 bool result = !ToBoolean(value);
489 iter.storeInstructionResult(BooleanValue(result));
490 return true;
491 }
492
493 bool MBigIntAdd::writeRecoverData(CompactBufferWriter& writer) const {
494 MOZ_ASSERT(canRecoverOnBailout());
495 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntAdd));
496 return true;
497 }
498
499 RBigIntAdd::RBigIntAdd(CompactBufferReader& reader) {}
500
501 bool RBigIntAdd::recover(JSContext* cx, SnapshotIterator& iter) const {
502 Rooted<BigInt*> lhs(cx, iter.readBigInt());
503 Rooted<BigInt*> rhs(cx, iter.readBigInt());
504
505 BigInt* result = BigInt::add(cx, lhs, rhs);
506 if (!result) {
507 return false;
508 }
509
510 iter.storeInstructionResult(BigIntValue(result));
511 return true;
512 }
513
514 bool MBigIntSub::writeRecoverData(CompactBufferWriter& writer) const {
515 MOZ_ASSERT(canRecoverOnBailout());
516 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntSub));
517 return true;
518 }
519
520 RBigIntSub::RBigIntSub(CompactBufferReader& reader) {}
521
522 bool RBigIntSub::recover(JSContext* cx, SnapshotIterator& iter) const {
523 Rooted<BigInt*> lhs(cx, iter.readBigInt());
524 Rooted<BigInt*> rhs(cx, iter.readBigInt());
525
526 BigInt* result = BigInt::sub(cx, lhs, rhs);
527 if (!result) {
528 return false;
529 }
530
531 iter.storeInstructionResult(BigIntValue(result));
532 return true;
533 }
534
535 bool MBigIntMul::writeRecoverData(CompactBufferWriter& writer) const {
536 MOZ_ASSERT(canRecoverOnBailout());
537 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntMul));
538 return true;
539 }
540
541 RBigIntMul::RBigIntMul(CompactBufferReader& reader) {}
542
543 bool RBigIntMul::recover(JSContext* cx, SnapshotIterator& iter) const {
544 Rooted<BigInt*> lhs(cx, iter.readBigInt());
545 Rooted<BigInt*> rhs(cx, iter.readBigInt());
546
547 BigInt* result = BigInt::mul(cx, lhs, rhs);
548 if (!result) {
549 return false;
550 }
551
552 iter.storeInstructionResult(BigIntValue(result));
553 return true;
554 }
555
556 bool MBigIntDiv::writeRecoverData(CompactBufferWriter& writer) const {
557 MOZ_ASSERT(canRecoverOnBailout());
558 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntDiv));
559 return true;
560 }
561
562 RBigIntDiv::RBigIntDiv(CompactBufferReader& reader) {}
563
564 bool RBigIntDiv::recover(JSContext* cx, SnapshotIterator& iter) const {
565 Rooted<BigInt*> lhs(cx, iter.readBigInt());
566 Rooted<BigInt*> rhs(cx, iter.readBigInt());
567 MOZ_ASSERT(!rhs->isZero(),
568 "division by zero throws and therefore can't be recovered");
569
570 BigInt* result = BigInt::div(cx, lhs, rhs);
571 if (!result) {
572 return false;
573 }
574
575 iter.storeInstructionResult(BigIntValue(result));
576 return true;
577 }
578
579 bool MBigIntMod::writeRecoverData(CompactBufferWriter& writer) const {
580 MOZ_ASSERT(canRecoverOnBailout());
581 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntMod));
582 return true;
583 }
584
585 RBigIntMod::RBigIntMod(CompactBufferReader& reader) {}
586
587 bool RBigIntMod::recover(JSContext* cx, SnapshotIterator& iter) const {
588 Rooted<BigInt*> lhs(cx, iter.readBigInt());
589 Rooted<BigInt*> rhs(cx, iter.readBigInt());
590 MOZ_ASSERT(!rhs->isZero(),
591 "division by zero throws and therefore can't be recovered");
592
593 BigInt* result = BigInt::mod(cx, lhs, rhs);
594 if (!result) {
595 return false;
596 }
597
598 iter.storeInstructionResult(BigIntValue(result));
599 return true;
600 }
601
602 bool MBigIntPow::writeRecoverData(CompactBufferWriter& writer) const {
603 MOZ_ASSERT(canRecoverOnBailout());
604 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPow));
605 return true;
606 }
607
608 RBigIntPow::RBigIntPow(CompactBufferReader& reader) {}
609
610 bool RBigIntPow::recover(JSContext* cx, SnapshotIterator& iter) const {
611 Rooted<BigInt*> lhs(cx, iter.readBigInt());
612 Rooted<BigInt*> rhs(cx, iter.readBigInt());
613 MOZ_ASSERT(!rhs->isNegative(),
614 "negative exponent throws and therefore can't be recovered");
615
616 BigInt* result = BigInt::pow(cx, lhs, rhs);
617 if (!result) {
618 return false;
619 }
620
621 iter.storeInstructionResult(BigIntValue(result));
622 return true;
623 }
624
625 bool MBigIntBitAnd::writeRecoverData(CompactBufferWriter& writer) const {
626 MOZ_ASSERT(canRecoverOnBailout());
627 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntBitAnd));
628 return true;
629 }
630
631 RBigIntBitAnd::RBigIntBitAnd(CompactBufferReader& reader) {}
632
633 bool RBigIntBitAnd::recover(JSContext* cx, SnapshotIterator& iter) const {
634 Rooted<BigInt*> lhs(cx, iter.readBigInt());
635 Rooted<BigInt*> rhs(cx, iter.readBigInt());
636
637 BigInt* result = BigInt::bitAnd(cx, lhs, rhs);
638 if (!result) {
639 return false;
640 }
641
642 iter.storeInstructionResult(BigIntValue(result));
643 return true;
644 }
645
646 bool MBigIntBitOr::writeRecoverData(CompactBufferWriter& writer) const {
647 MOZ_ASSERT(canRecoverOnBailout());
648 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntBitOr));
649 return true;
650 }
651
652 RBigIntBitOr::RBigIntBitOr(CompactBufferReader& reader) {}
653
654 bool RBigIntBitOr::recover(JSContext* cx, SnapshotIterator& iter) const {
655 Rooted<BigInt*> lhs(cx, iter.readBigInt());
656 Rooted<BigInt*> rhs(cx, iter.readBigInt());
657
658 BigInt* result = BigInt::bitOr(cx, lhs, rhs);
659 if (!result) {
660 return false;
661 }
662
663 iter.storeInstructionResult(BigIntValue(result));
664 return true;
665 }
666
667 bool MBigIntBitXor::writeRecoverData(CompactBufferWriter& writer) const {
668 MOZ_ASSERT(canRecoverOnBailout());
669 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntBitXor));
670 return true;
671 }
672
673 RBigIntBitXor::RBigIntBitXor(CompactBufferReader& reader) {}
674
675 bool RBigIntBitXor::recover(JSContext* cx, SnapshotIterator& iter) const {
676 Rooted<BigInt*> lhs(cx, iter.readBigInt());
677 Rooted<BigInt*> rhs(cx, iter.readBigInt());
678
679 BigInt* result = BigInt::bitXor(cx, lhs, rhs);
680 if (!result) {
681 return false;
682 }
683
684 iter.storeInstructionResult(BigIntValue(result));
685 return true;
686 }
687
688 bool MBigIntLsh::writeRecoverData(CompactBufferWriter& writer) const {
689 MOZ_ASSERT(canRecoverOnBailout());
690 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntLsh));
691 return true;
692 }
693
694 RBigIntLsh::RBigIntLsh(CompactBufferReader& reader) {}
695
696 bool RBigIntLsh::recover(JSContext* cx, SnapshotIterator& iter) const {
697 Rooted<BigInt*> lhs(cx, iter.readBigInt());
698 Rooted<BigInt*> rhs(cx, iter.readBigInt());
699
700 BigInt* result = BigInt::lsh(cx, lhs, rhs);
701 if (!result) {
702 return false;
703 }
704
705 iter.storeInstructionResult(BigIntValue(result));
706 return true;
707 }
708
709 bool MBigIntRsh::writeRecoverData(CompactBufferWriter& writer) const {
710 MOZ_ASSERT(canRecoverOnBailout());
711 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntRsh));
712 return true;
713 }
714
715 RBigIntRsh::RBigIntRsh(CompactBufferReader& reader) {}
716
717 bool RBigIntRsh::recover(JSContext* cx, SnapshotIterator& iter) const {
718 Rooted<BigInt*> lhs(cx, iter.readBigInt());
719 Rooted<BigInt*> rhs(cx, iter.readBigInt());
720
721 BigInt* result = BigInt::rsh(cx, lhs, rhs);
722 if (!result) {
723 return false;
724 }
725
726 iter.storeInstructionResult(BigIntValue(result));
727 return true;
728 }
729
730 bool MBigIntIncrement::writeRecoverData(CompactBufferWriter& writer) const {
731 MOZ_ASSERT(canRecoverOnBailout());
732 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntIncrement));
733 return true;
734 }
735
736 RBigIntIncrement::RBigIntIncrement(CompactBufferReader& reader) {}
737
738 bool RBigIntIncrement::recover(JSContext* cx, SnapshotIterator& iter) const {
739 Rooted<BigInt*> operand(cx, iter.readBigInt());
740
741 BigInt* result = BigInt::inc(cx, operand);
742 if (!result) {
743 return false;
744 }
745
746 iter.storeInstructionResult(BigIntValue(result));
747 return true;
748 }
749
750 bool MBigIntDecrement::writeRecoverData(CompactBufferWriter& writer) const {
751 MOZ_ASSERT(canRecoverOnBailout());
752 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntDecrement));
753 return true;
754 }
755
756 RBigIntDecrement::RBigIntDecrement(CompactBufferReader& reader) {}
757
758 bool RBigIntDecrement::recover(JSContext* cx, SnapshotIterator& iter) const {
759 Rooted<BigInt*> operand(cx, iter.readBigInt());
760
761 BigInt* result = BigInt::dec(cx, operand);
762 if (!result) {
763 return false;
764 }
765
766 iter.storeInstructionResult(BigIntValue(result));
767 return true;
768 }
769
770 bool MBigIntNegate::writeRecoverData(CompactBufferWriter& writer) const {
771 MOZ_ASSERT(canRecoverOnBailout());
772 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntNegate));
773 return true;
774 }
775
776 RBigIntNegate::RBigIntNegate(CompactBufferReader& reader) {}
777
778 bool RBigIntNegate::recover(JSContext* cx, SnapshotIterator& iter) const {
779 Rooted<BigInt*> operand(cx, iter.readBigInt());
780
781 BigInt* result = BigInt::neg(cx, operand);
782 if (!result) {
783 return false;
784 }
785
786 iter.storeInstructionResult(BigIntValue(result));
787 return true;
788 }
789
790 bool MBigIntBitNot::writeRecoverData(CompactBufferWriter& writer) const {
791 MOZ_ASSERT(canRecoverOnBailout());
792 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntBitNot));
793 return true;
794 }
795
796 RBigIntBitNot::RBigIntBitNot(CompactBufferReader& reader) {}
797
798 bool RBigIntBitNot::recover(JSContext* cx, SnapshotIterator& iter) const {
799 Rooted<BigInt*> operand(cx, iter.readBigInt());
800
801 BigInt* result = BigInt::bitNot(cx, operand);
802 if (!result) {
803 return false;
804 }
805
806 iter.storeInstructionResult(BigIntValue(result));
807 return true;
808 }
809
810 bool MBigIntToIntPtr::writeRecoverData(CompactBufferWriter& writer) const {
811 MOZ_ASSERT(canRecoverOnBailout());
812 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntToIntPtr));
813 return true;
814 }
815
816 RBigIntToIntPtr::RBigIntToIntPtr(CompactBufferReader& reader) {}
817
818 bool RBigIntToIntPtr::recover(JSContext* cx, SnapshotIterator& iter) const {
819 Value input = iter.read();
820 MOZ_ASSERT(input.isBigInt());
821
822 iter.storeInstructionResult(input);
823 return true;
824 }
825
826 bool MIntPtrToBigInt::writeRecoverData(CompactBufferWriter& writer) const {
827 MOZ_ASSERT(canRecoverOnBailout());
828 writer.writeUnsigned(uint32_t(RInstruction::Recover_IntPtrToBigInt));
829 return true;
830 }
831
832 RIntPtrToBigInt::RIntPtrToBigInt(CompactBufferReader& reader) {}
833
834 bool RIntPtrToBigInt::recover(JSContext* cx, SnapshotIterator& iter) const {
835 BigInt* input = iter.readBigInt(cx);
836 if (!input) {
837 return false;
838 }
839
840 iter.storeInstructionResult(JS::BigIntValue(input));
841 return true;
842 }
843
844 bool MBigIntPtrAdd::writeRecoverData(CompactBufferWriter& writer) const {
845 MOZ_ASSERT(canRecoverOnBailout());
846 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrAdd));
847 return true;
848 }
849
850 RBigIntPtrAdd::RBigIntPtrAdd(CompactBufferReader& reader) {}
851
852 bool RBigIntPtrAdd::recover(JSContext* cx, SnapshotIterator& iter) const {
853 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
854 if (!lhs) {
855 return false;
856 }
857
858 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
859 if (!rhs) {
860 return false;
861 }
862
863 BigInt* result = BigInt::add(cx, lhs, rhs);
864 if (!result) {
865 return false;
866 }
867
868 iter.storeInstructionResult(JS::BigIntValue(result));
869 return true;
870 }
871
872 bool MBigIntPtrSub::writeRecoverData(CompactBufferWriter& writer) const {
873 MOZ_ASSERT(canRecoverOnBailout());
874 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrSub));
875 return true;
876 }
877
878 RBigIntPtrSub::RBigIntPtrSub(CompactBufferReader& reader) {}
879
880 bool RBigIntPtrSub::recover(JSContext* cx, SnapshotIterator& iter) const {
881 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
882 if (!lhs) {
883 return false;
884 }
885
886 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
887 if (!rhs) {
888 return false;
889 }
890
891 BigInt* result = BigInt::sub(cx, lhs, rhs);
892 if (!result) {
893 return false;
894 }
895
896 iter.storeInstructionResult(JS::BigIntValue(result));
897 return true;
898 }
899
900 bool MBigIntPtrMul::writeRecoverData(CompactBufferWriter& writer) const {
901 MOZ_ASSERT(canRecoverOnBailout());
902 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrMul));
903 return true;
904 }
905
906 RBigIntPtrMul::RBigIntPtrMul(CompactBufferReader& reader) {}
907
908 bool RBigIntPtrMul::recover(JSContext* cx, SnapshotIterator& iter) const {
909 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
910 if (!lhs) {
911 return false;
912 }
913
914 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
915 if (!rhs) {
916 return false;
917 }
918
919 BigInt* result = BigInt::mul(cx, lhs, rhs);
920 if (!result) {
921 return false;
922 }
923
924 iter.storeInstructionResult(JS::BigIntValue(result));
925 return true;
926 }
927
928 bool MBigIntPtrDiv::writeRecoverData(CompactBufferWriter& writer) const {
929 MOZ_ASSERT(canRecoverOnBailout());
930 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrDiv));
931 return true;
932 }
933
934 RBigIntPtrDiv::RBigIntPtrDiv(CompactBufferReader& reader) {}
935
936 bool RBigIntPtrDiv::recover(JSContext* cx, SnapshotIterator& iter) const {
937 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
938 if (!lhs) {
939 return false;
940 }
941
942 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
943 if (!rhs) {
944 return false;
945 }
946
947 BigInt* result = BigInt::div(cx, lhs, rhs);
948 if (!result) {
949 return false;
950 }
951
952 iter.storeInstructionResult(JS::BigIntValue(result));
953 return true;
954 }
955
956 bool MBigIntPtrMod::writeRecoverData(CompactBufferWriter& writer) const {
957 MOZ_ASSERT(canRecoverOnBailout());
958 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrMod));
959 return true;
960 }
961
962 RBigIntPtrMod::RBigIntPtrMod(CompactBufferReader& reader) {}
963
964 bool RBigIntPtrMod::recover(JSContext* cx, SnapshotIterator& iter) const {
965 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
966 if (!lhs) {
967 return false;
968 }
969
970 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
971 if (!rhs) {
972 return false;
973 }
974
975 BigInt* result = BigInt::mod(cx, lhs, rhs);
976 if (!result) {
977 return false;
978 }
979
980 iter.storeInstructionResult(JS::BigIntValue(result));
981 return true;
982 }
983
984 bool MBigIntPtrPow::writeRecoverData(CompactBufferWriter& writer) const {
985 MOZ_ASSERT(canRecoverOnBailout());
986 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrPow));
987 return true;
988 }
989
990 RBigIntPtrPow::RBigIntPtrPow(CompactBufferReader& reader) {}
991
992 bool RBigIntPtrPow::recover(JSContext* cx, SnapshotIterator& iter) const {
993 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
994 if (!lhs) {
995 return false;
996 }
997
998 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
999 if (!rhs) {
1000 return false;
1001 }
1002
1003 BigInt* result = BigInt::pow(cx, lhs, rhs);
1004 if (!result) {
1005 return false;
1006 }
1007
1008 iter.storeInstructionResult(JS::BigIntValue(result));
1009 return true;
1010 }
1011
1012 bool MBigIntPtrBitAnd::writeRecoverData(CompactBufferWriter& writer) const {
1013 MOZ_ASSERT(canRecoverOnBailout());
1014 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrBitAnd));
1015 return true;
1016 }
1017
1018 RBigIntPtrBitAnd::RBigIntPtrBitAnd(CompactBufferReader& reader) {}
1019
1020 bool RBigIntPtrBitAnd::recover(JSContext* cx, SnapshotIterator& iter) const {
1021 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
1022 if (!lhs) {
1023 return false;
1024 }
1025
1026 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
1027 if (!rhs) {
1028 return false;
1029 }
1030
1031 BigInt* result = BigInt::bitAnd(cx, lhs, rhs);
1032 if (!result) {
1033 return false;
1034 }
1035
1036 iter.storeInstructionResult(JS::BigIntValue(result));
1037 return true;
1038 }
1039
1040 bool MBigIntPtrBitOr::writeRecoverData(CompactBufferWriter& writer) const {
1041 MOZ_ASSERT(canRecoverOnBailout());
1042 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrBitOr));
1043 return true;
1044 }
1045
1046 RBigIntPtrBitOr::RBigIntPtrBitOr(CompactBufferReader& reader) {}
1047
1048 bool RBigIntPtrBitOr::recover(JSContext* cx, SnapshotIterator& iter) const {
1049 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
1050 if (!lhs) {
1051 return false;
1052 }
1053
1054 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
1055 if (!rhs) {
1056 return false;
1057 }
1058
1059 BigInt* result = BigInt::bitOr(cx, lhs, rhs);
1060 if (!result) {
1061 return false;
1062 }
1063
1064 iter.storeInstructionResult(JS::BigIntValue(result));
1065 return true;
1066 }
1067
1068 bool MBigIntPtrBitXor::writeRecoverData(CompactBufferWriter& writer) const {
1069 MOZ_ASSERT(canRecoverOnBailout());
1070 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrBitXor));
1071 return true;
1072 }
1073
1074 RBigIntPtrBitXor::RBigIntPtrBitXor(CompactBufferReader& reader) {}
1075
1076 bool RBigIntPtrBitXor::recover(JSContext* cx, SnapshotIterator& iter) const {
1077 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
1078 if (!lhs) {
1079 return false;
1080 }
1081
1082 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
1083 if (!rhs) {
1084 return false;
1085 }
1086
1087 BigInt* result = BigInt::bitXor(cx, lhs, rhs);
1088 if (!result) {
1089 return false;
1090 }
1091
1092 iter.storeInstructionResult(JS::BigIntValue(result));
1093 return true;
1094 }
1095
1096 bool MBigIntPtrLsh::writeRecoverData(CompactBufferWriter& writer) const {
1097 MOZ_ASSERT(canRecoverOnBailout());
1098 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrLsh));
1099 return true;
1100 }
1101
1102 RBigIntPtrLsh::RBigIntPtrLsh(CompactBufferReader& reader) {}
1103
1104 bool RBigIntPtrLsh::recover(JSContext* cx, SnapshotIterator& iter) const {
1105 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
1106 if (!lhs) {
1107 return false;
1108 }
1109
1110 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
1111 if (!rhs) {
1112 return false;
1113 }
1114
1115 BigInt* result = BigInt::lsh(cx, lhs, rhs);
1116 if (!result) {
1117 return false;
1118 }
1119
1120 iter.storeInstructionResult(JS::BigIntValue(result));
1121 return true;
1122 }
1123
1124 bool MBigIntPtrRsh::writeRecoverData(CompactBufferWriter& writer) const {
1125 MOZ_ASSERT(canRecoverOnBailout());
1126 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrRsh));
1127 return true;
1128 }
1129
1130 RBigIntPtrRsh::RBigIntPtrRsh(CompactBufferReader& reader) {}
1131
1132 bool RBigIntPtrRsh::recover(JSContext* cx, SnapshotIterator& iter) const {
1133 Rooted<BigInt*> lhs(cx, iter.readBigInt(cx));
1134 if (!lhs) {
1135 return false;
1136 }
1137
1138 Rooted<BigInt*> rhs(cx, iter.readBigInt(cx));
1139 if (!rhs) {
1140 return false;
1141 }
1142
1143 BigInt* result = BigInt::rsh(cx, lhs, rhs);
1144 if (!result) {
1145 return false;
1146 }
1147
1148 iter.storeInstructionResult(JS::BigIntValue(result));
1149 return true;
1150 }
1151
1152 bool MBigIntPtrBitNot::writeRecoverData(CompactBufferWriter& writer) const {
1153 MOZ_ASSERT(canRecoverOnBailout());
1154 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntPtrBitNot));
1155 return true;
1156 }
1157
1158 RBigIntPtrBitNot::RBigIntPtrBitNot(CompactBufferReader& reader) {}
1159
1160 bool RBigIntPtrBitNot::recover(JSContext* cx, SnapshotIterator& iter) const {
1161 Rooted<BigInt*> operand(cx, iter.readBigInt(cx));
1162 if (!operand) {
1163 return false;
1164 }
1165
1166 BigInt* result = BigInt::bitNot(cx, operand);
1167 if (!result) {
1168 return false;
1169 }
1170
1171 iter.storeInstructionResult(JS::BigIntValue(result));
1172 return true;
1173 }
1174
1175 bool MCompare::writeRecoverData(CompactBufferWriter& writer) const {
1176 MOZ_ASSERT(canRecoverOnBailout());
1177 writer.writeUnsigned(uint32_t(RInstruction::Recover_Compare));
1178
1179 static_assert(sizeof(JSOp) == sizeof(uint8_t));
1180 writer.writeByte(uint8_t(jsop_));
1181 return true;
1182 }
1183
1184 RCompare::RCompare(CompactBufferReader& reader) {
1185 jsop_ = JSOp(reader.readByte());
1186
1187 MOZ_ASSERT(IsEqualityOp(jsop_) || IsRelationalOp(jsop_));
1188 }
1189
1190 bool RCompare::recover(JSContext* cx, SnapshotIterator& iter) const {
1191 RootedValue lhs(cx, iter.read());
1192 RootedValue rhs(cx, iter.read());
1193
1194 bool result;
1195 switch (jsop_) {
1196 case JSOp::Eq:
1197 case JSOp::Ne:
1198 if (!js::LooselyEqual(cx, lhs, rhs, &result)) {
1199 return false;
1200 }
1201 if (jsop_ == JSOp::Ne) {
1202 result = !result;
1203 }
1204 break;
1205 case JSOp::StrictEq:
1206 case JSOp::StrictNe:
1207 if (!StrictlyEqual(cx, lhs, rhs, &result)) {
1208 return false;
1209 }
1210 if (jsop_ == JSOp::StrictNe) {
1211 result = !result;
1212 }
1213 break;
1214 case JSOp::Lt:
1215 if (!js::LessThan(cx, &lhs, &rhs, &result)) {
1216 return false;
1217 }
1218 break;
1219 case JSOp::Le:
1220 if (!js::LessThanOrEqual(cx, &lhs, &rhs, &result)) {
1221 return false;
1222 }
1223 break;
1224 case JSOp::Gt:
1225 if (!js::GreaterThan(cx, &lhs, &rhs, &result)) {
1226 return false;
1227 }
1228 break;
1229 case JSOp::Ge:
1230 if (!js::GreaterThanOrEqual(cx, &lhs, &rhs, &result)) {
1231 return false;
1232 }
1233 break;
1234 default:
1235 MOZ_CRASH("Unexpected op.");
1236 }
1237
1238 iter.storeInstructionResult(BooleanValue(result));
1239 return true;
1240 }
1241
1242 bool MStrictConstantCompareInt32::writeRecoverData(
1243 CompactBufferWriter& writer) const {
1244 MOZ_ASSERT(canRecoverOnBailout());
1245 writer.writeUnsigned(
1246 uint32_t(RInstruction::Recover_StrictConstantCompareInt32));
1247
1248 writer.writeByte(uint8_t(jsop_));
1249 writer.writeSigned(constant_);
1250 return true;
1251 }
1252
1253 RStrictConstantCompareInt32::RStrictConstantCompareInt32(
1254 CompactBufferReader& reader) {
1255 jsop_ = JSOp(reader.readByte());
1256 constant_ = reader.readSigned();
1257 MOZ_ASSERT(IsStrictEqualityOp(jsop_));
1258 }
1259
1260 bool RStrictConstantCompareInt32::recover(JSContext* cx,
1261 SnapshotIterator& iter) const {
1262 JS::Rooted<JS::Value> lhs(cx, iter.read());
1263
1264 iter.storeInstructionResult(
1265 BooleanValue(lhs.isNumber() && lhs.toNumber() == constant_));
1266 return true;
1267 }
1268
1269 bool MStrictConstantCompareBoolean::writeRecoverData(
1270 CompactBufferWriter& writer) const {
1271 MOZ_ASSERT(canRecoverOnBailout());
1272 writer.writeUnsigned(
1273 uint32_t(RInstruction::Recover_StrictConstantCompareBoolean));
1274
1275 writer.writeByte(uint8_t(jsop_));
1276 writer.writeUnsigned(constant_);
1277 return true;
1278 }
1279
1280 RStrictConstantCompareBoolean::RStrictConstantCompareBoolean(
1281 CompactBufferReader& reader) {
1282 jsop_ = JSOp(reader.readByte());
1283 constant_ = reader.readUnsigned();
1284 MOZ_ASSERT(IsStrictEqualityOp(jsop_));
1285 }
1286
1287 bool RStrictConstantCompareBoolean::recover(JSContext* cx,
1288 SnapshotIterator& iter) const {
1289 JS::Rooted<JS::Value> lhs(cx, iter.read());
1290
1291 iter.storeInstructionResult(
1292 BooleanValue(lhs.isBoolean() && lhs.toBoolean() == constant_));
1293 return true;
1294 }
1295
1296 bool MConcat::writeRecoverData(CompactBufferWriter& writer) const {
1297 MOZ_ASSERT(canRecoverOnBailout());
1298 writer.writeUnsigned(uint32_t(RInstruction::Recover_Concat));
1299 return true;
1300 }
1301
1302 RConcat::RConcat(CompactBufferReader& reader) {}
1303
1304 bool RConcat::recover(JSContext* cx, SnapshotIterator& iter) const {
1305 RootedValue lhs(cx, iter.read());
1306 RootedValue rhs(cx, iter.read());
1307 RootedValue result(cx);
1308
1309 MOZ_ASSERT(!lhs.isObject() && !rhs.isObject());
1310 if (!js::AddValues(cx, &lhs, &rhs, &result)) {
1311 return false;
1312 }
1313
1314 iter.storeInstructionResult(result);
1315 return true;
1316 }
1317
1318 RStringLength::RStringLength(CompactBufferReader& reader) {}
1319
1320 bool RStringLength::recover(JSContext* cx, SnapshotIterator& iter) const {
1321 JSString* string = iter.readString();
1322
1323 static_assert(JSString::MAX_LENGTH <= INT32_MAX,
1324 "Can cast string length to int32_t");
1325
1326 iter.storeInstructionResult(Int32Value(int32_t(string->length())));
1327 return true;
1328 }
1329
1330 bool MStringLength::writeRecoverData(CompactBufferWriter& writer) const {
1331 MOZ_ASSERT(canRecoverOnBailout());
1332 writer.writeUnsigned(uint32_t(RInstruction::Recover_StringLength));
1333 return true;
1334 }
1335
1336 bool MArgumentsLength::writeRecoverData(CompactBufferWriter& writer) const {
1337 MOZ_ASSERT(canRecoverOnBailout());
1338 writer.writeUnsigned(uint32_t(RInstruction::Recover_ArgumentsLength));
1339 return true;
1340 }
1341
1342 RArgumentsLength::RArgumentsLength(CompactBufferReader& reader) {}
1343
1344 bool RArgumentsLength::recover(JSContext* cx, SnapshotIterator& iter) const {
1345 uintptr_t numActualArgs = iter.frame()->numActualArgs();
1346
1347 static_assert(ARGS_LENGTH_MAX <= INT32_MAX,
1348 "Can cast arguments count to int32_t");
1349 MOZ_ASSERT(numActualArgs <= ARGS_LENGTH_MAX);
1350
1351 iter.storeInstructionResult(JS::Int32Value(int32_t(numActualArgs)));
1352 return true;
1353 }
1354
1355 bool MFloor::writeRecoverData(CompactBufferWriter& writer) const {
1356 MOZ_ASSERT(canRecoverOnBailout());
1357 writer.writeUnsigned(uint32_t(RInstruction::Recover_Floor));
1358 return true;
1359 }
1360
1361 RFloor::RFloor(CompactBufferReader& reader) {}
1362
1363 bool RFloor::recover(JSContext* cx, SnapshotIterator& iter) const {
1364 double num = iter.readNumber();
1365 double result = js::math_floor_impl(num);
1366
1367 iter.storeInstructionResult(NumberValue(result));
1368 return true;
1369 }
1370
1371 bool MCeil::writeRecoverData(CompactBufferWriter& writer) const {
1372 MOZ_ASSERT(canRecoverOnBailout());
1373 writer.writeUnsigned(uint32_t(RInstruction::Recover_Ceil));
1374 return true;
1375 }
1376
1377 RCeil::RCeil(CompactBufferReader& reader) {}
1378
1379 bool RCeil::recover(JSContext* cx, SnapshotIterator& iter) const {
1380 double num = iter.readNumber();
1381 double result = js::math_ceil_impl(num);
1382
1383 iter.storeInstructionResult(NumberValue(result));
1384 return true;
1385 }
1386
1387 bool MRound::writeRecoverData(CompactBufferWriter& writer) const {
1388 MOZ_ASSERT(canRecoverOnBailout());
1389 writer.writeUnsigned(uint32_t(RInstruction::Recover_Round));
1390 return true;
1391 }
1392
1393 RRound::RRound(CompactBufferReader& reader) {}
1394
1395 bool RRound::recover(JSContext* cx, SnapshotIterator& iter) const {
1396 double num = iter.readNumber();
1397 double result = js::math_round_impl(num);
1398
1399 iter.storeInstructionResult(NumberValue(result));
1400 return true;
1401 }
1402
1403 bool MTrunc::writeRecoverData(CompactBufferWriter& writer) const {
1404 MOZ_ASSERT(canRecoverOnBailout());
1405 writer.writeUnsigned(uint32_t(RInstruction::Recover_Trunc));
1406 return true;
1407 }
1408
1409 RTrunc::RTrunc(CompactBufferReader& reader) {}
1410
1411 bool RTrunc::recover(JSContext* cx, SnapshotIterator& iter) const {
1412 double num = iter.readNumber();
1413 double result = js::math_trunc_impl(num);
1414
1415 iter.storeInstructionResult(NumberValue(result));
1416 return true;
1417 }
1418
1419 bool MCharCodeAt::writeRecoverData(CompactBufferWriter& writer) const {
1420 MOZ_ASSERT(canRecoverOnBailout());
1421 writer.writeUnsigned(uint32_t(RInstruction::Recover_CharCodeAt));
1422 return true;
1423 }
1424
1425 RCharCodeAt::RCharCodeAt(CompactBufferReader& reader) {}
1426
1427 bool RCharCodeAt::recover(JSContext* cx, SnapshotIterator& iter) const {
1428 JSString* string = iter.readString();
1429
1430 // Int32 because |index| is computed from MBoundsCheck.
1431 int32_t index = iter.readInt32();
1432 MOZ_RELEASE_ASSERT(0 <= index && size_t(index) < string->length());
1433
1434 char16_t c;
1435 if (!string->getChar(cx, index, &c)) {
1436 return false;
1437 }
1438
1439 iter.storeInstructionResult(Int32Value(c));
1440 return true;
1441 }
1442
1443 bool MFromCharCode::writeRecoverData(CompactBufferWriter& writer) const {
1444 MOZ_ASSERT(canRecoverOnBailout());
1445 writer.writeUnsigned(uint32_t(RInstruction::Recover_FromCharCode));
1446 return true;
1447 }
1448
1449 RFromCharCode::RFromCharCode(CompactBufferReader& reader) {}
1450
1451 bool RFromCharCode::recover(JSContext* cx, SnapshotIterator& iter) const {
1452 // Number because |charCode| is computed from (recoverable) user input.
1453 int32_t charCode = JS::ToInt32(iter.readNumber());
1454
1455 JSString* str = StringFromCharCode(cx, charCode);
1456 if (!str) {
1457 return false;
1458 }
1459
1460 iter.storeInstructionResult(StringValue(str));
1461 return true;
1462 }
1463
1464 bool MFromCharCodeEmptyIfNegative::writeRecoverData(
1465 CompactBufferWriter& writer) const {
1466 MOZ_ASSERT(canRecoverOnBailout());
1467 writer.writeUnsigned(
1468 uint32_t(RInstruction::Recover_FromCharCodeEmptyIfNegative));
1469 return true;
1470 }
1471
1472 RFromCharCodeEmptyIfNegative::RFromCharCodeEmptyIfNegative(
1473 CompactBufferReader& reader) {}
1474
1475 bool RFromCharCodeEmptyIfNegative::recover(JSContext* cx,
1476 SnapshotIterator& iter) const {
1477 // Int32 because |charCode| is computed from MCharCodeAtOrNegative.
1478 int32_t charCode = iter.readInt32();
1479
1480 JSString* str;
1481 if (charCode < 0) {
1482 str = cx->emptyString();
1483 } else {
1484 str = StringFromCharCode(cx, charCode);
1485 if (!str) {
1486 return false;
1487 }
1488 }
1489
1490 iter.storeInstructionResult(StringValue(str));
1491 return true;
1492 }
1493
1494 bool MPow::writeRecoverData(CompactBufferWriter& writer) const {
1495 MOZ_ASSERT(canRecoverOnBailout());
1496 writer.writeUnsigned(uint32_t(RInstruction::Recover_Pow));
1497 return true;
1498 }
1499
1500 RPow::RPow(CompactBufferReader& reader) {}
1501
1502 bool RPow::recover(JSContext* cx, SnapshotIterator& iter) const {
1503 double base = iter.readNumber();
1504 double power = iter.readNumber();
1505 double result = ecmaPow(base, power);
1506
1507 iter.storeInstructionResult(NumberValue(result));
1508 return true;
1509 }
1510
1511 bool MPowHalf::writeRecoverData(CompactBufferWriter& writer) const {
1512 MOZ_ASSERT(canRecoverOnBailout());
1513 writer.writeUnsigned(uint32_t(RInstruction::Recover_PowHalf));
1514 return true;
1515 }
1516
1517 RPowHalf::RPowHalf(CompactBufferReader& reader) {}
1518
1519 bool RPowHalf::recover(JSContext* cx, SnapshotIterator& iter) const {
1520 double base = iter.readNumber();
1521 double power = 0.5;
1522 double result = ecmaPow(base, power);
1523
1524 iter.storeInstructionResult(NumberValue(result));
1525 return true;
1526 }
1527
1528 bool MMinMax::writeRecoverData(CompactBufferWriter& writer) const {
1529 MOZ_ASSERT(canRecoverOnBailout());
1530 writer.writeUnsigned(uint32_t(RInstruction::Recover_MinMax));
1531 writer.writeByte(isMax_);
1532 return true;
1533 }
1534
1535 RMinMax::RMinMax(CompactBufferReader& reader) { isMax_ = reader.readByte(); }
1536
1537 bool RMinMax::recover(JSContext* cx, SnapshotIterator& iter) const {
1538 double x = iter.readNumber();
1539 double y = iter.readNumber();
1540
1541 double result;
1542 if (isMax_) {
1543 result = js::math_max_impl(x, y);
1544 } else {
1545 result = js::math_min_impl(x, y);
1546 }
1547
1548 iter.storeInstructionResult(NumberValue(result));
1549 return true;
1550 }
1551
1552 bool MAbs::writeRecoverData(CompactBufferWriter& writer) const {
1553 MOZ_ASSERT(canRecoverOnBailout());
1554 writer.writeUnsigned(uint32_t(RInstruction::Recover_Abs));
1555 return true;
1556 }
1557
1558 RAbs::RAbs(CompactBufferReader& reader) {}
1559
1560 bool RAbs::recover(JSContext* cx, SnapshotIterator& iter) const {
1561 double num = iter.readNumber();
1562 double result = js::math_abs_impl(num);
1563
1564 iter.storeInstructionResult(NumberValue(result));
1565 return true;
1566 }
1567
1568 bool MSqrt::writeRecoverData(CompactBufferWriter& writer) const {
1569 MOZ_ASSERT(canRecoverOnBailout());
1570 writer.writeUnsigned(uint32_t(RInstruction::Recover_Sqrt));
1571 writer.writeByte(type() == MIRType::Float32);
1572 return true;
1573 }
1574
1575 RSqrt::RSqrt(CompactBufferReader& reader) {
1576 isFloatOperation_ = reader.readByte();
1577 }
1578
1579 bool RSqrt::recover(JSContext* cx, SnapshotIterator& iter) const {
1580 double num = iter.readNumber();
1581 double result = js::math_sqrt_impl(num);
1582
1583 // MIRType::Float32 is a specialization embedding the fact that the result is
1584 // rounded to a Float32.
1585 if (isFloatOperation_) {
1586 result = js::RoundFloat32(result);
1587 }
1588
1589 iter.storeInstructionResult(DoubleValue(result));
1590 return true;
1591 }
1592
1593 bool MAtan2::writeRecoverData(CompactBufferWriter& writer) const {
1594 MOZ_ASSERT(canRecoverOnBailout());
1595 writer.writeUnsigned(uint32_t(RInstruction::Recover_Atan2));
1596 return true;
1597 }
1598
1599 RAtan2::RAtan2(CompactBufferReader& reader) {}
1600
1601 bool RAtan2::recover(JSContext* cx, SnapshotIterator& iter) const {
1602 double y = iter.readNumber();
1603 double x = iter.readNumber();
1604 double result = js::ecmaAtan2(y, x);
1605
1606 iter.storeInstructionResult(DoubleValue(result));
1607 return true;
1608 }
1609
1610 bool MHypot::writeRecoverData(CompactBufferWriter& writer) const {
1611 MOZ_ASSERT(canRecoverOnBailout());
1612 writer.writeUnsigned(uint32_t(RInstruction::Recover_Hypot));
1613 writer.writeUnsigned(uint32_t(numOperands()));
1614 return true;
1615 }
1616
1617 RHypot::RHypot(CompactBufferReader& reader)
1618 : numOperands_(reader.readUnsigned()) {}
1619
1620 bool RHypot::recover(JSContext* cx, SnapshotIterator& iter) const {
1621 JS::RootedValueVector vec(cx);
1622
1623 if (!vec.reserve(numOperands_)) {
1624 return false;
1625 }
1626
1627 for (uint32_t i = 0; i < numOperands_; ++i) {
1628 vec.infallibleAppend(NumberValue(iter.readNumber()));
1629 }
1630
1631 RootedValue result(cx);
1632
1633 if (!js::math_hypot_handle(cx, vec, &result)) {
1634 return false;
1635 }
1636
1637 iter.storeInstructionResult(result);
1638 return true;
1639 }
1640
1641 bool MNearbyInt::writeRecoverData(CompactBufferWriter& writer) const {
1642 MOZ_ASSERT(canRecoverOnBailout());
1643 switch (roundingMode_) {
1644 case RoundingMode::Up:
1645 writer.writeUnsigned(uint32_t(RInstruction::Recover_Ceil));
1646 return true;
1647 case RoundingMode::Down:
1648 writer.writeUnsigned(uint32_t(RInstruction::Recover_Floor));
1649 return true;
1650 case RoundingMode::TowardsZero:
1651 writer.writeUnsigned(uint32_t(RInstruction::Recover_Trunc));
1652 return true;
1653 default:
1654 MOZ_CRASH("Unsupported rounding mode.");
1655 }
1656 }
1657
1658 RNearbyInt::RNearbyInt(CompactBufferReader& reader) {
1659 roundingMode_ = reader.readByte();
1660 }
1661
1662 bool RNearbyInt::recover(JSContext* cx, SnapshotIterator& iter) const {
1663 MOZ_CRASH("Unsupported rounding mode.");
1664 }
1665
1666 bool MSign::writeRecoverData(CompactBufferWriter& writer) const {
1667 MOZ_ASSERT(canRecoverOnBailout());
1668 writer.writeUnsigned(uint32_t(RInstruction::Recover_Sign));
1669 return true;
1670 }
1671
1672 RSign::RSign(CompactBufferReader& reader) {}
1673
1674 bool RSign::recover(JSContext* cx, SnapshotIterator& iter) const {
1675 double num = iter.readNumber();
1676 double result = js::math_sign_impl(num);
1677
1678 iter.storeInstructionResult(NumberValue(result));
1679 return true;
1680 }
1681
1682 bool MMathFunction::writeRecoverData(CompactBufferWriter& writer) const {
1683 MOZ_ASSERT(canRecoverOnBailout());
1684 switch (function_) {
1685 case UnaryMathFunction::Ceil:
1686 writer.writeUnsigned(uint32_t(RInstruction::Recover_Ceil));
1687 return true;
1688 case UnaryMathFunction::Floor:
1689 writer.writeUnsigned(uint32_t(RInstruction::Recover_Floor));
1690 return true;
1691 case UnaryMathFunction::Round:
1692 writer.writeUnsigned(uint32_t(RInstruction::Recover_Round));
1693 return true;
1694 case UnaryMathFunction::Trunc:
1695 writer.writeUnsigned(uint32_t(RInstruction::Recover_Trunc));
1696 return true;
1697 case UnaryMathFunction::SinNative:
1698 case UnaryMathFunction::SinFdlibm:
1699 case UnaryMathFunction::CosNative:
1700 case UnaryMathFunction::CosFdlibm:
1701 case UnaryMathFunction::TanNative:
1702 case UnaryMathFunction::TanFdlibm:
1703 case UnaryMathFunction::Log:
1704 case UnaryMathFunction::Exp:
1705 case UnaryMathFunction::ACos:
1706 case UnaryMathFunction::ASin:
1707 case UnaryMathFunction::ATan:
1708 case UnaryMathFunction::Log10:
1709 case UnaryMathFunction::Log2:
1710 case UnaryMathFunction::Log1P:
1711 case UnaryMathFunction::ExpM1:
1712 case UnaryMathFunction::CosH:
1713 case UnaryMathFunction::SinH:
1714 case UnaryMathFunction::TanH:
1715 case UnaryMathFunction::ACosH:
1716 case UnaryMathFunction::ASinH:
1717 case UnaryMathFunction::ATanH:
1718 case UnaryMathFunction::Cbrt:
1719 static_assert(sizeof(UnaryMathFunction) == sizeof(uint8_t));
1720 writer.writeUnsigned(uint32_t(RInstruction::Recover_MathFunction));
1721 writer.writeByte(uint8_t(function_));
1722 return true;
1723 }
1724 MOZ_CRASH("Unknown math function.");
1725 }
1726
1727 RMathFunction::RMathFunction(CompactBufferReader& reader) {
1728 function_ = UnaryMathFunction(reader.readByte());
1729 }
1730
1731 bool RMathFunction::recover(JSContext* cx, SnapshotIterator& iter) const {
1732 double num = iter.readNumber();
1733
1734 double result;
1735 switch (function_) {
1736 case UnaryMathFunction::SinNative:
1737 result = js::math_sin_native_impl(num);
1738 break;
1739 case UnaryMathFunction::SinFdlibm:
1740 result = js::math_sin_fdlibm_impl(num);
1741 break;
1742 case UnaryMathFunction::CosNative:
1743 result = js::math_cos_native_impl(num);
1744 break;
1745 case UnaryMathFunction::CosFdlibm:
1746 result = js::math_cos_fdlibm_impl(num);
1747 break;
1748 case UnaryMathFunction::TanNative:
1749 result = js::math_tan_native_impl(num);
1750 break;
1751 case UnaryMathFunction::TanFdlibm:
1752 result = js::math_tan_fdlibm_impl(num);
1753 break;
1754 case UnaryMathFunction::Log:
1755 result = js::math_log_impl(num);
1756 break;
1757 case UnaryMathFunction::Exp:
1758 result = js::math_exp_impl(num);
1759 break;
1760 case UnaryMathFunction::ACos:
1761 result = js::math_acos_impl(num);
1762 break;
1763 case UnaryMathFunction::ASin:
1764 result = js::math_asin_impl(num);
1765 break;
1766 case UnaryMathFunction::ATan:
1767 result = js::math_atan_impl(num);
1768 break;
1769 case UnaryMathFunction::Log10:
1770 result = js::math_log10_impl(num);
1771 break;
1772 case UnaryMathFunction::Log2:
1773 result = js::math_log2_impl(num);
1774 break;
1775 case UnaryMathFunction::Log1P:
1776 result = js::math_log1p_impl(num);
1777 break;
1778 case UnaryMathFunction::ExpM1:
1779 result = js::math_expm1_impl(num);
1780 break;
1781 case UnaryMathFunction::CosH:
1782 result = js::math_cosh_impl(num);
1783 break;
1784 case UnaryMathFunction::SinH:
1785 result = js::math_sinh_impl(num);
1786 break;
1787 case UnaryMathFunction::TanH:
1788 result = js::math_tanh_impl(num);
1789 break;
1790 case UnaryMathFunction::ACosH:
1791 result = js::math_acosh_impl(num);
1792 break;
1793 case UnaryMathFunction::ASinH:
1794 result = js::math_asinh_impl(num);
1795 break;
1796 case UnaryMathFunction::ATanH:
1797 result = js::math_atanh_impl(num);
1798 break;
1799 case UnaryMathFunction::Cbrt:
1800 result = js::math_cbrt_impl(num);
1801 break;
1802
1803 case UnaryMathFunction::Trunc:
1804 case UnaryMathFunction::Floor:
1805 case UnaryMathFunction::Ceil:
1806 case UnaryMathFunction::Round:
1807 // These have their own recover instructions.
1808 MOZ_CRASH("Unexpected rounding math function.");
1809 }
1810
1811 iter.storeInstructionResult(DoubleValue(result));
1812 return true;
1813 }
1814
1815 bool MRandom::writeRecoverData(CompactBufferWriter& writer) const {
1816 MOZ_ASSERT(this->canRecoverOnBailout());
1817 writer.writeUnsigned(uint32_t(RInstruction::Recover_Random));
1818 return true;
1819 }
1820
1821 bool MRandom::canRecoverOnBailout() const {
1822 return !js::SupportDifferentialTesting();
1823 }
1824
1825 RRandom::RRandom(CompactBufferReader& reader) {}
1826
1827 bool RRandom::recover(JSContext* cx, SnapshotIterator& iter) const {
1828 iter.storeInstructionResult(DoubleValue(math_random_impl(cx)));
1829 return true;
1830 }
1831
1832 bool MStringSplit::writeRecoverData(CompactBufferWriter& writer) const {
1833 MOZ_ASSERT(canRecoverOnBailout());
1834 writer.writeUnsigned(uint32_t(RInstruction::Recover_StringSplit));
1835 return true;
1836 }
1837
1838 RStringSplit::RStringSplit(CompactBufferReader& reader) {}
1839
1840 bool RStringSplit::recover(JSContext* cx, SnapshotIterator& iter) const {
1841 RootedString str(cx, iter.readString());
1842 RootedString sep(cx, iter.readString());
1843
1844 JSObject* res = StringSplitString(cx, str, sep, INT32_MAX);
1845 if (!res) {
1846 return false;
1847 }
1848
1849 iter.storeInstructionResult(ObjectValue(*res));
1850 return true;
1851 }
1852
1853 bool MNaNToZero::writeRecoverData(CompactBufferWriter& writer) const {
1854 MOZ_ASSERT(canRecoverOnBailout());
1855 writer.writeUnsigned(uint32_t(RInstruction::Recover_NaNToZero));
1856 return true;
1857 }
1858
1859 RNaNToZero::RNaNToZero(CompactBufferReader& reader) {}
1860
1861 bool RNaNToZero::recover(JSContext* cx, SnapshotIterator& iter) const {
1862 double v = iter.readNumber();
1863 if (std::isnan(v) || mozilla::IsNegativeZero(v)) {
1864 v = 0.0;
1865 }
1866
1867 iter.storeInstructionResult(DoubleValue(v));
1868 return true;
1869 }
1870
1871 bool MTypeOf::writeRecoverData(CompactBufferWriter& writer) const {
1872 MOZ_ASSERT(canRecoverOnBailout());
1873 writer.writeUnsigned(uint32_t(RInstruction::Recover_TypeOf));
1874 return true;
1875 }
1876
1877 RTypeOf::RTypeOf(CompactBufferReader& reader) {}
1878
1879 bool RTypeOf::recover(JSContext* cx, SnapshotIterator& iter) const {
1880 JS::Value v = iter.read();
1881
1882 iter.storeInstructionResult(Int32Value(TypeOfValue(v)));
1883 return true;
1884 }
1885
1886 bool MTypeOfName::writeRecoverData(CompactBufferWriter& writer) const {
1887 MOZ_ASSERT(canRecoverOnBailout());
1888 writer.writeUnsigned(uint32_t(RInstruction::Recover_TypeOfName));
1889 return true;
1890 }
1891
1892 RTypeOfName::RTypeOfName(CompactBufferReader& reader) {}
1893
1894 bool RTypeOfName::recover(JSContext* cx, SnapshotIterator& iter) const {
1895 // Int32 because |type| is computed from MTypeOf.
1896 int32_t type = iter.readInt32();
1897 MOZ_ASSERT(JSTYPE_UNDEFINED <= type && type < JSTYPE_LIMIT);
1898
1899 JSString* name = TypeName(JSType(type), *cx->runtime()->commonNames);
1900 iter.storeInstructionResult(StringValue(name));
1901 return true;
1902 }
1903
1904 bool MToDouble::writeRecoverData(CompactBufferWriter& writer) const {
1905 MOZ_ASSERT(canRecoverOnBailout());
1906 writer.writeUnsigned(uint32_t(RInstruction::Recover_ToDouble));
1907 return true;
1908 }
1909
1910 RToDouble::RToDouble(CompactBufferReader& reader) {}
1911
1912 bool RToDouble::recover(JSContext* cx, SnapshotIterator& iter) const {
1913 RootedValue v(cx, iter.read());
1914
1915 MOZ_ASSERT(!v.isObject());
1916 MOZ_ASSERT(!v.isSymbol());
1917 MOZ_ASSERT(!v.isBigInt());
1918
1919 double dbl;
1920 if (!ToNumber(cx, v, &dbl)) {
1921 return false;
1922 }
1923
1924 iter.storeInstructionResult(DoubleValue(dbl));
1925 return true;
1926 }
1927
1928 bool MToFloat32::writeRecoverData(CompactBufferWriter& writer) const {
1929 MOZ_ASSERT(canRecoverOnBailout());
1930 writer.writeUnsigned(uint32_t(RInstruction::Recover_ToFloat32));
1931 return true;
1932 }
1933
1934 RToFloat32::RToFloat32(CompactBufferReader& reader) {}
1935
1936 bool RToFloat32::recover(JSContext* cx, SnapshotIterator& iter) const {
1937 double num = iter.readNumber();
1938 double result = js::RoundFloat32(num);
1939
1940 iter.storeInstructionResult(DoubleValue(result));
1941 return true;
1942 }
1943
1944 bool MToFloat16::writeRecoverData(CompactBufferWriter& writer) const {
1945 MOZ_ASSERT(canRecoverOnBailout());
1946 writer.writeUnsigned(uint32_t(RInstruction::Recover_ToFloat16));
1947 return true;
1948 }
1949
1950 RToFloat16::RToFloat16(CompactBufferReader& reader) {}
1951
1952 bool RToFloat16::recover(JSContext* cx, SnapshotIterator& iter) const {
1953 double num = iter.readNumber();
1954 double result = js::RoundFloat16(num);
1955
1956 iter.storeInstructionResult(DoubleValue(result));
1957 return true;
1958 }
1959
1960 bool MTruncateToInt32::writeRecoverData(CompactBufferWriter& writer) const {
1961 MOZ_ASSERT(canRecoverOnBailout());
1962 writer.writeUnsigned(uint32_t(RInstruction::Recover_TruncateToInt32));
1963 return true;
1964 }
1965
1966 RTruncateToInt32::RTruncateToInt32(CompactBufferReader& reader) {}
1967
1968 bool RTruncateToInt32::recover(JSContext* cx, SnapshotIterator& iter) const {
1969 RootedValue value(cx, iter.read());
1970
1971 int32_t trunc;
1972 if (!JS::ToInt32(cx, value, &trunc)) {
1973 return false;
1974 }
1975
1976 iter.storeInstructionResult(Int32Value(trunc));
1977 return true;
1978 }
1979
1980 bool MNewObject::writeRecoverData(CompactBufferWriter& writer) const {
1981 MOZ_ASSERT(canRecoverOnBailout());
1982
1983 writer.writeUnsigned(uint32_t(RInstruction::Recover_NewObject));
1984
1985 // Recover instructions are only supported if we have a template object.
1986 MOZ_ASSERT(mode_ == MNewObject::ObjectCreate);
1987 return true;
1988 }
1989
1990 RNewObject::RNewObject(CompactBufferReader& reader) {}
1991
1992 bool RNewObject::recover(JSContext* cx, SnapshotIterator& iter) const {
1993 RootedObject templateObject(cx, iter.readObject());
1994
1995 // See CodeGenerator::visitNewObjectVMCall.
1996 // Note that recover instructions are only used if mode == ObjectCreate.
1997 JSObject* resultObject =
1998 ObjectCreateWithTemplate(cx, templateObject.as<PlainObject>());
1999 if (!resultObject) {
2000 return false;
2001 }
2002
2003 iter.storeInstructionResult(ObjectValue(*resultObject));
2004 return true;
2005 }
2006
2007 bool MNewPlainObject::writeRecoverData(CompactBufferWriter& writer) const {
2008 MOZ_ASSERT(canRecoverOnBailout());
2009 writer.writeUnsigned(uint32_t(RInstruction::Recover_NewPlainObject));
2010
2011 MOZ_ASSERT(gc::AllocKind(uint8_t(allocKind_)) == allocKind_);
2012 writer.writeByte(uint8_t(allocKind_));
2013 MOZ_ASSERT(gc::Heap(uint8_t(initialHeap_)) == initialHeap_);
2014 writer.writeByte(uint8_t(initialHeap_));
2015 return true;
2016 }
2017
2018 RNewPlainObject::RNewPlainObject(CompactBufferReader& reader) {
2019 allocKind_ = gc::AllocKind(reader.readByte());
2020 MOZ_ASSERT(gc::IsValidAllocKind(allocKind_));
2021 initialHeap_ = gc::Heap(reader.readByte());
2022 MOZ_ASSERT(initialHeap_ == gc::Heap::Default ||
2023 initialHeap_ == gc::Heap::Tenured);
2024 }
2025
2026 bool RNewPlainObject::recover(JSContext* cx, SnapshotIterator& iter) const {
2027 Rooted<SharedShape*> shape(cx, &iter.readGCCellPtr().as<Shape>().asShared());
2028
2029 // See CodeGenerator::visitNewPlainObject.
2030 JSObject* resultObject =
2031 NewPlainObjectOptimizedFallback(cx, shape, allocKind_, initialHeap_);
2032 if (!resultObject) {
2033 return false;
2034 }
2035
2036 iter.storeInstructionResult(ObjectValue(*resultObject));
2037 return true;
2038 }
2039
2040 bool MNewArrayObject::writeRecoverData(CompactBufferWriter& writer) const {
2041 MOZ_ASSERT(canRecoverOnBailout());
2042 writer.writeUnsigned(uint32_t(RInstruction::Recover_NewArrayObject));
2043
2044 writer.writeUnsigned(length_);
2045 MOZ_ASSERT(gc::Heap(uint8_t(initialHeap_)) == initialHeap_);
2046 writer.writeByte(uint8_t(initialHeap_));
2047 return true;
2048 }
2049
2050 RNewArrayObject::RNewArrayObject(CompactBufferReader& reader) {
2051 length_ = reader.readUnsigned();
2052 initialHeap_ = gc::Heap(reader.readByte());
2053 MOZ_ASSERT(initialHeap_ == gc::Heap::Default ||
2054 initialHeap_ == gc::Heap::Tenured);
2055 }
2056
2057 bool RNewArrayObject::recover(JSContext* cx, SnapshotIterator& iter) const {
2058 iter.read(); // Skip unused shape field.
2059
2060 NewObjectKind kind =
2061 initialHeap_ == gc::Heap::Tenured ? TenuredObject : GenericObject;
2062 JSObject* array = NewArrayOperation(cx, length_, kind);
2063 if (!array) {
2064 return false;
2065 }
2066
2067 iter.storeInstructionResult(ObjectValue(*array));
2068 return true;
2069 }
2070
2071 bool MNewTypedArray::writeRecoverData(CompactBufferWriter& writer) const {
2072 MOZ_ASSERT(canRecoverOnBailout());
2073 writer.writeUnsigned(uint32_t(RInstruction::Recover_NewTypedArray));
2074 return true;
2075 }
2076
2077 RNewTypedArray::RNewTypedArray(CompactBufferReader& reader) {}
2078
2079 bool RNewTypedArray::recover(JSContext* cx, SnapshotIterator& iter) const {
2080 RootedObject templateObject(cx, iter.readObject());
2081
2082 size_t length = templateObject.as<FixedLengthTypedArrayObject>()->length();
2083 MOZ_ASSERT(length <= INT32_MAX,
2084 "Template objects are only created for int32 lengths");
2085
2086 JSObject* resultObject =
2087 NewTypedArrayWithTemplateAndLength(cx, templateObject, length);
2088 if (!resultObject) {
2089 return false;
2090 }
2091
2092 iter.storeInstructionResult(ObjectValue(*resultObject));
2093 return true;
2094 }
2095
2096 bool MNewArray::writeRecoverData(CompactBufferWriter& writer) const {
2097 MOZ_ASSERT(canRecoverOnBailout());
2098 writer.writeUnsigned(uint32_t(RInstruction::Recover_NewArray));
2099 writer.writeUnsigned(length());
2100 return true;
2101 }
2102
2103 RNewArray::RNewArray(CompactBufferReader& reader) {
2104 count_ = reader.readUnsigned();
2105 }
2106
2107 bool RNewArray::recover(JSContext* cx, SnapshotIterator& iter) const {
2108 RootedObject templateObject(cx, iter.readObject());
2109 Rooted<Shape*> shape(cx, templateObject->shape());
2110
2111 ArrayObject* resultObject = NewArrayWithShape(cx, count_, shape);
2112 if (!resultObject) {
2113 return false;
2114 }
2115
2116 iter.storeInstructionResult(ObjectValue(*resultObject));
2117 return true;
2118 }
2119
2120 bool MNewIterator::writeRecoverData(CompactBufferWriter& writer) const {
2121 MOZ_ASSERT(canRecoverOnBailout());
2122 writer.writeUnsigned(uint32_t(RInstruction::Recover_NewIterator));
2123 writer.writeByte(type_);
2124 return true;
2125 }
2126
2127 RNewIterator::RNewIterator(CompactBufferReader& reader) {
2128 type_ = reader.readByte();
2129 }
2130
2131 bool RNewIterator::recover(JSContext* cx, SnapshotIterator& iter) const {
2132 RootedObject templateObject(cx, iter.readObject());
2133
2134 JSObject* resultObject = nullptr;
2135 switch (MNewIterator::Type(type_)) {
2136 case MNewIterator::ArrayIterator:
2137 resultObject = NewArrayIterator(cx);
2138 break;
2139 case MNewIterator::StringIterator:
2140 resultObject = NewStringIterator(cx);
2141 break;
2142 case MNewIterator::RegExpStringIterator:
2143 resultObject = NewRegExpStringIterator(cx);
2144 break;
2145 }
2146
2147 if (!resultObject) {
2148 return false;
2149 }
2150
2151 iter.storeInstructionResult(ObjectValue(*resultObject));
2152 return true;
2153 }
2154
2155 bool MLambda::writeRecoverData(CompactBufferWriter& writer) const {
2156 MOZ_ASSERT(canRecoverOnBailout());
2157 writer.writeUnsigned(uint32_t(RInstruction::Recover_Lambda));
2158 return true;
2159 }
2160
2161 RLambda::RLambda(CompactBufferReader& reader) {}
2162
2163 bool RLambda::recover(JSContext* cx, SnapshotIterator& iter) const {
2164 RootedObject scopeChain(cx, iter.readObject());
2165 RootedFunction fun(cx, &iter.readObject()->as<JSFunction>());
2166
2167 JSObject* resultObject = js::Lambda(cx, fun, scopeChain);
2168 if (!resultObject) {
2169 return false;
2170 }
2171
2172 iter.storeInstructionResult(ObjectValue(*resultObject));
2173 return true;
2174 }
2175
2176 bool MFunctionWithProto::writeRecoverData(CompactBufferWriter& writer) const {
2177 MOZ_ASSERT(canRecoverOnBailout());
2178 writer.writeUnsigned(uint32_t(RInstruction::Recover_FunctionWithProto));
2179 return true;
2180 }
2181
2182 RFunctionWithProto::RFunctionWithProto(CompactBufferReader& reader) {}
2183
2184 bool RFunctionWithProto::recover(JSContext* cx, SnapshotIterator& iter) const {
2185 RootedObject scopeChain(cx, iter.readObject());
2186 RootedObject prototype(cx, iter.readObject());
2187 RootedFunction fun(cx, &iter.readObject()->as<JSFunction>());
2188
2189 JSObject* resultObject =
2190 js::FunWithProtoOperation(cx, fun, scopeChain, prototype);
2191 if (!resultObject) {
2192 return false;
2193 }
2194
2195 iter.storeInstructionResult(ObjectValue(*resultObject));
2196 return true;
2197 }
2198
2199 bool MNewCallObject::writeRecoverData(CompactBufferWriter& writer) const {
2200 MOZ_ASSERT(canRecoverOnBailout());
2201 writer.writeUnsigned(uint32_t(RInstruction::Recover_NewCallObject));
2202 return true;
2203 }
2204
2205 RNewCallObject::RNewCallObject(CompactBufferReader& reader) {}
2206
2207 bool RNewCallObject::recover(JSContext* cx, SnapshotIterator& iter) const {
2208 Rooted<CallObject*> templateObj(cx, &iter.readObject()->as<CallObject>());
2209
2210 Rooted<SharedShape*> shape(cx, templateObj->sharedShape());
2211
2212 JSObject* resultObject = CallObject::createWithShape(cx, shape);
2213 if (!resultObject) {
2214 return false;
2215 }
2216
2217 iter.storeInstructionResult(ObjectValue(*resultObject));
2218 return true;
2219 }
2220
2221 bool MObjectKeys::canRecoverOnBailout() const {
2222 // Only claim that this operation can be recovered on bailout if some other
2223 // optimization already marked it as such.
2224 return isRecoveredOnBailout();
2225 }
2226
2227 bool MObjectKeys::writeRecoverData(CompactBufferWriter& writer) const {
2228 MOZ_ASSERT(canRecoverOnBailout());
2229 writer.writeUnsigned(uint32_t(RInstruction::Recover_ObjectKeys));
2230 return true;
2231 }
2232
2233 RObjectKeys::RObjectKeys(CompactBufferReader& reader) {}
2234
2235 bool RObjectKeys::recover(JSContext* cx, SnapshotIterator& iter) const {
2236 Rooted<JSObject*> obj(cx, iter.readObject());
2237
2238 JSObject* resultKeys = ObjectKeys(cx, obj);
2239 if (!resultKeys) {
2240 return false;
2241 }
2242
2243 iter.storeInstructionResult(ObjectValue(*resultKeys));
2244 return true;
2245 }
2246
2247 bool MObjectState::writeRecoverData(CompactBufferWriter& writer) const {
2248 MOZ_ASSERT(canRecoverOnBailout());
2249 writer.writeUnsigned(uint32_t(RInstruction::Recover_ObjectState));
2250 writer.writeUnsigned(numSlots());
2251 return true;
2252 }
2253
2254 RObjectState::RObjectState(CompactBufferReader& reader) {
2255 numSlots_ = reader.readUnsigned();
2256 }
2257
2258 bool RObjectState::recover(JSContext* cx, SnapshotIterator& iter) const {
2259 RootedObject object(cx, iter.readObject());
2260 Handle<NativeObject*> nativeObject = object.as<NativeObject>();
2261 MOZ_ASSERT(!Watchtower::watchesPropertyValueChange(nativeObject));
2262 MOZ_ASSERT(nativeObject->slotSpan() == numSlots());
2263
2264 for (size_t i = 0; i < numSlots(); i++) {
2265 Value val = iter.read();
2266 nativeObject->setSlot(i, val);
2267 }
2268
2269 iter.storeInstructionResult(ObjectValue(*object));
2270 return true;
2271 }
2272
2273 bool MArrayState::writeRecoverData(CompactBufferWriter& writer) const {
2274 MOZ_ASSERT(canRecoverOnBailout());
2275 writer.writeUnsigned(uint32_t(RInstruction::Recover_ArrayState));
2276 writer.writeUnsigned(numElements());
2277 return true;
2278 }
2279
2280 RArrayState::RArrayState(CompactBufferReader& reader) {
2281 numElements_ = reader.readUnsigned();
2282 }
2283
2284 bool RArrayState::recover(JSContext* cx, SnapshotIterator& iter) const {
2285 ArrayObject* object = &iter.readObject()->as<ArrayObject>();
2286
2287 // Int32 because |initLength| is computed from MConstant.
2288 uint32_t initLength = iter.readInt32();
2289
2290 MOZ_ASSERT(object->getDenseInitializedLength() == 0,
2291 "initDenseElement call below relies on this");
2292 object->setDenseInitializedLength(initLength);
2293
2294 for (size_t index = 0; index < numElements(); index++) {
2295 Value val = iter.read();
2296
2297 if (index >= initLength) {
2298 MOZ_ASSERT(val.isUndefined());
2299 continue;
2300 }
2301
2302 object->initDenseElement(index, val);
2303 }
2304
2305 iter.storeInstructionResult(ObjectValue(*object));
2306 return true;
2307 }
2308
2309 bool MAssertRecoveredOnBailout::writeRecoverData(
2310 CompactBufferWriter& writer) const {
2311 MOZ_ASSERT(canRecoverOnBailout());
2312 MOZ_RELEASE_ASSERT(input()->isRecoveredOnBailout() == mustBeRecovered_,
2313 "assertRecoveredOnBailout failed during compilation");
2314 writer.writeUnsigned(
2315 uint32_t(RInstruction::Recover_AssertRecoveredOnBailout));
2316 return true;
2317 }
2318
2319 RAssertRecoveredOnBailout::RAssertRecoveredOnBailout(
2320 CompactBufferReader& reader) {}
2321
2322 bool RAssertRecoveredOnBailout::recover(JSContext* cx,
2323 SnapshotIterator& iter) const {
2324 iter.read(); // skip the unused operand.
2325 iter.storeInstructionResult(UndefinedValue());
2326 return true;
2327 }
2328
2329 bool MStringReplace::writeRecoverData(CompactBufferWriter& writer) const {
2330 MOZ_ASSERT(canRecoverOnBailout());
2331 writer.writeUnsigned(uint32_t(RInstruction::Recover_StringReplace));
2332 writer.writeByte(isFlatReplacement_);
2333 return true;
2334 }
2335
2336 RStringReplace::RStringReplace(CompactBufferReader& reader) {
2337 isFlatReplacement_ = reader.readByte();
2338 }
2339
2340 bool RStringReplace::recover(JSContext* cx, SnapshotIterator& iter) const {
2341 RootedString string(cx, iter.readString());
2342 RootedString pattern(cx, iter.readString());
2343 RootedString replace(cx, iter.readString());
2344
2345 JSString* result =
2346 isFlatReplacement_
2347 ? js::StringFlatReplaceString(cx, string, pattern, replace)
2348 : js::str_replace_string_raw(cx, string, pattern, replace);
2349
2350 if (!result) {
2351 return false;
2352 }
2353
2354 iter.storeInstructionResult(StringValue(result));
2355 return true;
2356 }
2357
2358 bool MSubstr::writeRecoverData(CompactBufferWriter& writer) const {
2359 MOZ_ASSERT(canRecoverOnBailout());
2360 writer.writeUnsigned(uint32_t(RInstruction::Recover_Substr));
2361 return true;
2362 }
2363
2364 RSubstr::RSubstr(CompactBufferReader& reader) {}
2365
2366 bool RSubstr::recover(JSContext* cx, SnapshotIterator& iter) const {
2367 RootedString str(cx, iter.readString());
2368
2369 // Int32 because |begin| is computed from MStringTrimStartIndex, MConstant,
2370 // or CallSubstringKernelResult.
2371 int32_t begin = iter.readInt32();
2372
2373 // |length| is computed from MSub(truncated), MStringTrimEndIndex, or
2374 // CallSubstringKernelResult. The current MSub inputs won't overflow, so when
2375 // RSub recovers the MSub instruction, the input will be representable as an
2376 // Int32. This is only true as long as RSub calls |js::SubOperation|, which in
2377 // turn calls |JS::Value::setNumber|. We don't want to rely on this exact call
2378 // sequence, so instead use |readNumber| here and then release-assert the
2379 // number is exactly representable as an Int32.
2380 int32_t length = mozilla::ReleaseAssertedCast<int32_t>(iter.readNumber());
2381
2382 JSString* result = SubstringKernel(cx, str, begin, length);
2383 if (!result) {
2384 return false;
2385 }
2386
2387 iter.storeInstructionResult(StringValue(result));
2388 return true;
2389 }
2390
2391 bool MAtomicIsLockFree::writeRecoverData(CompactBufferWriter& writer) const {
2392 MOZ_ASSERT(canRecoverOnBailout());
2393 writer.writeUnsigned(uint32_t(RInstruction::Recover_AtomicIsLockFree));
2394 return true;
2395 }
2396
2397 RAtomicIsLockFree::RAtomicIsLockFree(CompactBufferReader& reader) {}
2398
2399 bool RAtomicIsLockFree::recover(JSContext* cx, SnapshotIterator& iter) const {
2400 double dsize = JS::ToInteger(iter.readNumber());
2401
2402 int32_t size;
2403 bool result = mozilla::NumberEqualsInt32(dsize, &size) &&
2404 AtomicOperations::isLockfreeJS(size);
2405 iter.storeInstructionResult(BooleanValue(result));
2406 return true;
2407 }
2408
2409 bool MInt64ToBigInt::writeRecoverData(CompactBufferWriter& writer) const {
2410 MOZ_ASSERT(canRecoverOnBailout());
2411 writer.writeUnsigned(uint32_t(RInstruction::Recover_Int64ToBigInt));
2412 writer.writeByte(isSigned());
2413 return true;
2414 }
2415
2416 RInt64ToBigInt::RInt64ToBigInt(CompactBufferReader& reader) {
2417 isSigned_ = bool(reader.readByte());
2418 }
2419
2420 bool RInt64ToBigInt::recover(JSContext* cx, SnapshotIterator& iter) const {
2421 int64_t n = iter.readInt64();
2422
2423 BigInt* result;
2424 if (isSigned_) {
2425 result = BigInt::createFromInt64(cx, n);
2426 } else {
2427 result = BigInt::createFromUint64(cx, uint64_t(n));
2428 }
2429 if (!result) {
2430 return false;
2431 }
2432
2433 iter.storeInstructionResult(JS::BigIntValue(result));
2434 return true;
2435 }
2436
2437 bool MBigIntAsIntN::writeRecoverData(CompactBufferWriter& writer) const {
2438 MOZ_ASSERT(canRecoverOnBailout());
2439 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntAsIntN));
2440 return true;
2441 }
2442
2443 RBigIntAsIntN::RBigIntAsIntN(CompactBufferReader& reader) {}
2444
2445 bool RBigIntAsIntN::recover(JSContext* cx, SnapshotIterator& iter) const {
2446 // Int32 because |bits| is computed from MGuardInt32IsNonNegative.
2447 int32_t bits = iter.readInt32();
2448 MOZ_ASSERT(bits >= 0);
2449
2450 RootedBigInt input(cx, iter.readBigInt());
2451
2452 BigInt* result = BigInt::asIntN(cx, input, bits);
2453 if (!result) {
2454 return false;
2455 }
2456
2457 iter.storeInstructionResult(JS::BigIntValue(result));
2458 return true;
2459 }
2460
2461 bool MBigIntAsUintN::writeRecoverData(CompactBufferWriter& writer) const {
2462 MOZ_ASSERT(canRecoverOnBailout());
2463 writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntAsUintN));
2464 return true;
2465 }
2466
2467 RBigIntAsUintN::RBigIntAsUintN(CompactBufferReader& reader) {}
2468
2469 bool RBigIntAsUintN::recover(JSContext* cx, SnapshotIterator& iter) const {
2470 // Int32 because |bits| is computed from MGuardInt32IsNonNegative.
2471 int32_t bits = iter.readInt32();
2472 MOZ_ASSERT(bits >= 0);
2473
2474 RootedBigInt input(cx, iter.readBigInt());
2475
2476 BigInt* result = BigInt::asUintN(cx, input, bits);
2477 if (!result) {
2478 return false;
2479 }
2480
2481 iter.storeInstructionResult(JS::BigIntValue(result));
2482 return true;
2483 }
2484
2485 bool MCreateArgumentsObject::writeRecoverData(
2486 CompactBufferWriter& writer) const {
2487 MOZ_ASSERT(canRecoverOnBailout());
2488 writer.writeUnsigned(uint32_t(RInstruction::Recover_CreateArgumentsObject));
2489 return true;
2490 }
2491
2492 RCreateArgumentsObject::RCreateArgumentsObject(CompactBufferReader& reader) {}
2493
2494 bool RCreateArgumentsObject::recover(JSContext* cx,
2495 SnapshotIterator& iter) const {
2496 RootedObject callObject(cx, iter.readObject());
2497 RootedObject result(
2498 cx, ArgumentsObject::createForIon(cx, iter.frame(), callObject));
2499 if (!result) {
2500 return false;
2501 }
2502
2503 iter.storeInstructionResult(JS::ObjectValue(*result));
2504 return true;
2505 }
2506
2507 bool MCreateInlinedArgumentsObject::writeRecoverData(
2508 CompactBufferWriter& writer) const {
2509 MOZ_ASSERT(canRecoverOnBailout());
2510 writer.writeUnsigned(
2511 uint32_t(RInstruction::Recover_CreateInlinedArgumentsObject));
2512 writer.writeUnsigned(numActuals());
2513 return true;
2514 }
2515
2516 RCreateInlinedArgumentsObject::RCreateInlinedArgumentsObject(
2517 CompactBufferReader& reader) {
2518 numActuals_ = reader.readUnsigned();
2519 }
2520
2521 bool RCreateInlinedArgumentsObject::recover(JSContext* cx,
2522 SnapshotIterator& iter) const {
2523 RootedObject callObject(cx, iter.readObject());
2524 RootedFunction callee(cx, &iter.readObject()->as<JSFunction>());
2525
2526 JS::RootedValueArray<ArgumentsObject::MaxInlinedArgs> argsArray(cx);
2527 for (uint32_t i = 0; i < numActuals_; i++) {
2528 argsArray[i].set(iter.read());
2529 }
2530
2531 ArgumentsObject* result = ArgumentsObject::createFromValueArray(
2532 cx, argsArray, callee, callObject, numActuals_);
2533 if (!result) {
2534 return false;
2535 }
2536
2537 iter.storeInstructionResult(JS::ObjectValue(*result));
2538 return true;
2539 }
2540
2541 bool MRest::writeRecoverData(CompactBufferWriter& writer) const {
2542 MOZ_ASSERT(canRecoverOnBailout());
2543 writer.writeUnsigned(uint32_t(RInstruction::Recover_Rest));
2544 writer.writeUnsigned(numFormals());
2545 return true;
2546 }
2547
2548 RRest::RRest(CompactBufferReader& reader) {
2549 numFormals_ = reader.readUnsigned();
2550 }
2551
2552 bool RRest::recover(JSContext* cx, SnapshotIterator& iter) const {
2553 JitFrameLayout* frame = iter.frame();
2554
2555 // Int32 because |numActuals| is computed from MArgumentsLength.
2556 uint32_t numActuals = iter.readInt32();
2557 MOZ_ASSERT(numActuals == frame->numActualArgs());
2558
2559 uint32_t numFormals = numFormals_;
2560
2561 uint32_t length = std::max(numActuals, numFormals) - numFormals;
2562 Value* src = frame->actualArgs() + numFormals;
2563 JSObject* rest = jit::InitRestParameter(cx, length, src, nullptr);
2564 if (!rest) {
2565 return false;
2566 }
2567
2568 iter.storeInstructionResult(ObjectValue(*rest));
2569 return true;
2570 }