Debian Codegraph @

js/src/jit/JitFrames.h

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 #ifndef jit_JitFrames_h
8 #define jit_JitFrames_h
9
10 #include "mozilla/Assertions.h"
11
12 #include <stddef.h>
13 #include <stdint.h>
14
15 #include "jit/CalleeToken.h"
16 #include "jit/MachineState.h"
17 #include "jit/Registers.h"
18 #include "js/Id.h"
19 #include "js/TypeDecls.h"
20 #include "js/Value.h"
21
22 namespace js {
23
24 namespace wasm {
25 class Instance;
26 }
27
28 namespace jit {
29
30 enum class FrameType;
31 enum class VMFunctionId;
32 class IonScript;
33 class JitActivation;
34 class JitFrameLayout;
35 struct SafepointSlotEntry;
36 struct VMFunctionData;
37
38 // [SMDOC] JIT Frame Layout
39 //
40 // Frame Headers:
41 //
42 // In between every two frames lies a small header describing both frames. This
43 // header, minimally, contains a returnAddress word and a descriptor word (See
44 // CommonFrameLayout). The descriptor describes the type of the older (caller)
45 // frame, whereas the returnAddress describes the address the newer (callee)
46 // frame will return to. For JitFrameLayout, the descriptor also stores the
47 // number of arguments passed from the caller to the callee frame.
48 //
49 // Special Frames:
50 //
51 // Two special frame types exist:
52 // - Entry frames begin a JitActivation, and therefore there is exactly one
53 // per activation of EnterJit or EnterBaseline. These reuse JitFrameLayout.
54 // - Exit frames are necessary to leave JIT code and enter C++, and thus,
55 // C++ code will always begin iterating from the topmost exit frame.
56 //
57 // Approximate Layout:
58 //
59 // The layout of an Ion frame on the C stack is roughly:
60 // argN _
61 // ... \ - These are jsvals
62 // arg0 /
63 // -3 this _/
64 // -2 callee
65 // -1 descriptor
66 // 0 returnAddress
67 // .. locals ..
68
69 // [SMDOC] Frame Descriptor Layout
70 //
71 // A frame descriptor word has the following data:
72 //
73 // high bits: [ numActualArgs |
74 // has-cached-saved-frame bit |
75 // low bits: frame type ]
76 //
77 // * numActualArgs: for JitFrameLayout, the number of arguments passed by the
78 // caller.
79 // * Has-cache-saved-frame bit: Used to power the LiveSavedFrameCache
80 // optimization. See the comment in Activation.h
81 // * Frame Type: BaselineJS, Exit, etc. (jit::FrameType)
82 //
83
84 static const uintptr_t FRAMETYPE_BITS = 4;
85 static const uintptr_t FRAMETYPE_MASK = (1 << FRAMETYPE_BITS) - 1;
86 static const uintptr_t HASCACHEDSAVEDFRAME_BIT = 1 << FRAMETYPE_BITS;
87 static const uintptr_t NUMACTUALARGS_SHIFT =
88 FRAMETYPE_BITS + 1 /* HASCACHEDSAVEDFRAME_BIT */;
89
90 struct BaselineBailoutInfo;
91
92 enum class ExceptionResumeKind : int32_t {
93 // There is no exception handler in this activation.
94 // Return from the entry frame.
95 EntryFrame,
96
97 // The exception was caught in baseline.
98 // Restore state and jump to the catch block.
99 Catch,
100
101 // A finally block must be executed in baseline.
102 // Stash the exception on the stack and jump to the finally block.
103 Finally,
104
105 // We are forcing an early return with a specific return value.
106 // This is used by the debugger and when closing generators.
107 // Immediately return from the current frame with the given value.
108 ForcedReturnBaseline,
109 ForcedReturnIon,
110
111 // This frame is currently executing in Ion, but we must bail out
112 // to baseline before handling the exception.
113 // Jump to the bailout tail stub.
114 Bailout,
115
116 // Return to the wasm interpreter entry frame.
117 WasmInterpEntry,
118
119 // The exception was caught by a wasm catch handler.
120 // Restore state and jump to it.
121 WasmCatch
122 };
123
124 // Data needed to recover from an exception.
125 struct ResumeFromException {
126 uint8_t* framePointer;
127 uint8_t* stackPointer;
128 uint8_t* target;
129 ExceptionResumeKind kind;
130 wasm::Instance* instance;
131
132 // Value to push when resuming into a |finally| block.
133 // Also used by Wasm to send the exception object to the throw stub.
134 JS::Value exception;
135
136 // Exception stack to push when resuming into a |finally| block.
137 JS::Value exceptionStack;
138
139 BaselineBailoutInfo* bailoutInfo;
140
141 static size_t offsetOfFramePointer() {
142 return offsetof(ResumeFromException, framePointer);
143 }
144 static size_t offsetOfStackPointer() {
145 return offsetof(ResumeFromException, stackPointer);
146 }
147 static size_t offsetOfTarget() {
148 return offsetof(ResumeFromException, target);
149 }
150 static size_t offsetOfKind() { return offsetof(ResumeFromException, kind); }
151 static size_t offsetOfInstance() {
152 return offsetof(ResumeFromException, instance);
153 }
154 static size_t offsetOfException() {
155 return offsetof(ResumeFromException, exception);
156 }
157 static size_t offsetOfExceptionStack() {
158 return offsetof(ResumeFromException, exceptionStack);
159 }
160 static size_t offsetOfBailoutInfo() {
161 return offsetof(ResumeFromException, bailoutInfo);
162 }
163 };
164
165 #if defined(JS_CODEGEN_ARM64)
166 static_assert(sizeof(ResumeFromException) % 16 == 0,
167 "ResumeFromException should be aligned");
168 #endif
169
170 void HandleException(ResumeFromException* rfe);
171
172 void EnsureUnwoundJitExitFrame(JitActivation* act, JitFrameLayout* frame);
173
174 void TraceJitActivations(JSContext* cx, JSTracer* trc);
175
176 // Trace weak pointers in baseline stubs in activations for zones that are
177 // currently being swept.
178 void TraceWeakJitActivationsInSweepingZones(JSContext* cx, JSTracer* trc);
179
180 void UpdateJitActivationsForMinorGC(JSRuntime* rt);
181 void UpdateJitActivationsForCompactingGC(JSRuntime* rt);
182
183 static inline uint32_t MakeFrameDescriptor(FrameType type) {
184 return uint32_t(type);
185 }
186
187 // For JitFrameLayout, the descriptor also stores the number of arguments passed
188 // by the caller. Note that |type| is the type of the *older* frame and |argc|
189 // is the number of arguments passed to the *newer* frame.
190 static inline uint32_t MakeFrameDescriptorForJitCall(FrameType type,
191 uint32_t argc) {
192 uint32_t descriptor = (argc << NUMACTUALARGS_SHIFT) | uint32_t(type);
193 MOZ_ASSERT((descriptor >> NUMACTUALARGS_SHIFT) == argc,
194 "argc must fit in descriptor");
195 return descriptor;
196 }
197
198 // Returns the JSScript associated with the topmost JIT frame.
199 JSScript* GetTopJitJSScript(JSContext* cx);
200
201 #if defined(JS_CODEGEN_ARM64)
202 uint8_t* alignDoubleSpill(uint8_t* pointer);
203 #else
204 inline uint8_t* alignDoubleSpill(uint8_t* pointer) {
205 // This is a no-op on most platforms.
206 return pointer;
207 }
208 #endif
209
210 // Layout of the frame prefix. This assumes the stack architecture grows down.
211 // If this is ever not the case, we'll have to refactor.
212 class CommonFrameLayout {
213 uint8_t* callerFramePtr_;
214 uint8_t* returnAddress_;
215 uintptr_t descriptor_;
216
217 public:
218 static constexpr size_t offsetOfDescriptor() {
219 return offsetof(CommonFrameLayout, descriptor_);
220 }
221 uintptr_t descriptor() const { return descriptor_; }
222 static constexpr size_t offsetOfReturnAddress() {
223 return offsetof(CommonFrameLayout, returnAddress_);
224 }
225 FrameType prevType() const { return FrameType(descriptor_ & FRAMETYPE_MASK); }
226 void changePrevType(FrameType type) {
227 descriptor_ &= ~FRAMETYPE_MASK;
228 descriptor_ |= uintptr_t(type);
229 }
230 bool hasCachedSavedFrame() const {
231 return descriptor_ & HASCACHEDSAVEDFRAME_BIT;
232 }
233 void setHasCachedSavedFrame() { descriptor_ |= HASCACHEDSAVEDFRAME_BIT; }
234 void clearHasCachedSavedFrame() { descriptor_ &= ~HASCACHEDSAVEDFRAME_BIT; }
235 uint8_t* returnAddress() const { return returnAddress_; }
236 void setReturnAddress(uint8_t* addr) { returnAddress_ = addr; }
237
238 uint8_t* callerFramePtr() const { return callerFramePtr_; }
239 static constexpr size_t offsetOfCallerFramePtr() {
240 return offsetof(CommonFrameLayout, callerFramePtr_);
241 }
242 static constexpr size_t bytesPoppedAfterCall() {
243 // The return address and frame pointer are popped by the callee/call.
244 return 2 * sizeof(void*);
245 }
246 };
247
248 class JitFrameLayout : public CommonFrameLayout {
249 CalleeToken calleeToken_;
250
251 public:
252 CalleeToken calleeToken() const { return calleeToken_; }
253 void replaceCalleeToken(CalleeToken calleeToken) {
254 calleeToken_ = calleeToken;
255 }
256
257 static constexpr size_t offsetOfCalleeToken() {
258 return offsetof(JitFrameLayout, calleeToken_);
259 }
260 static constexpr size_t offsetOfThis() { return sizeof(JitFrameLayout); }
261 static constexpr size_t offsetOfActualArgs() {
262 return offsetOfThis() + sizeof(JS::Value);
263 }
264 static constexpr size_t offsetOfActualArg(size_t arg) {
265 return offsetOfActualArgs() + arg * sizeof(JS::Value);
266 }
267
268 JS::Value& thisv() {
269 MOZ_ASSERT(CalleeTokenIsFunction(calleeToken()));
270 return thisAndActualArgs()[0];
271 }
272 JS::Value* thisAndActualArgs() {
273 MOZ_ASSERT(CalleeTokenIsFunction(calleeToken()));
274 return (JS::Value*)(this + 1);
275 }
276 JS::Value* actualArgs() { return thisAndActualArgs() + 1; }
277 uintptr_t numActualArgs() const {
278 return descriptor() >> NUMACTUALARGS_SHIFT;
279 }
280
281 // Computes a reference to a stack or argument slot, where a slot is a
282 // distance from the base frame pointer, as would be used for LStackSlot
283 // or LArgument.
284 uintptr_t* slotRef(SafepointSlotEntry where);
285
286 static inline size_t Size() { return sizeof(JitFrameLayout); }
287 };
288
289 class BaselineInterpreterEntryFrameLayout : public JitFrameLayout {
290 public:
291 static inline size_t Size() {
292 return sizeof(BaselineInterpreterEntryFrameLayout);
293 }
294 };
295
296 class RectifierFrameLayout : public JitFrameLayout {
297 public:
298 static inline size_t Size() { return sizeof(RectifierFrameLayout); }
299 };
300
301 class TrampolineNativeFrameLayout : public JitFrameLayout {
302 public:
303 static inline size_t Size() { return sizeof(TrampolineNativeFrameLayout); }
304
305 template <typename T>
306 T* getFrameData() {
307 uint8_t* raw = reinterpret_cast<uint8_t*>(this) - sizeof(T);
308 return reinterpret_cast<T*>(raw);
309 }
310 };
311
312 class WasmToJSJitFrameLayout : public JitFrameLayout {
313 public:
314 static inline size_t Size() { return sizeof(WasmToJSJitFrameLayout); }
315 };
316
317 class IonICCallFrameLayout : public CommonFrameLayout {
318 protected:
319 // Pointer to root the stub's JitCode.
320 JitCode* stubCode_;
321
322 public:
323 static constexpr size_t LocallyTracedValueOffset = sizeof(void*);
324
325 JitCode** stubCode() { return &stubCode_; }
326 static size_t Size() { return sizeof(IonICCallFrameLayout); }
327
328 inline Value* locallyTracedValuePtr(size_t index) {
329 uint8_t* fp = reinterpret_cast<uint8_t*>(this);
330 return reinterpret_cast<Value*>(fp - LocallyTracedValueOffset -
331 index * sizeof(Value));
332 }
333 };
334
335 enum class ExitFrameType : uint8_t {
336 CallNative = 0x0,
337 ConstructNative = 0x1,
338 IonDOMGetter = 0x2,
339 IonDOMSetter = 0x3,
340 IonDOMMethod = 0x4,
341 IonOOLNative = 0x5,
342 IonOOLProxy = 0x6,
343 WasmGenericJitEntry = 0x7,
344 DirectWasmJitCall = 0x8,
345 UnwoundJit = 0x9,
346 InterpreterStub = 0xA,
347 LazyLink = 0xB,
348 Bare = 0xC,
349
350 // This must be the last value in this enum. See ExitFooterFrame::data_.
351 VMFunction = 0xD
352 };
353
354 // GC related data used to keep alive data surrounding the Exit frame.
355 class ExitFooterFrame {
356 // Stores either the ExitFrameType or, for a VMFunction call,
357 // `ExitFrameType::VMFunction + VMFunctionId`.
358 uintptr_t data_;
359
360 #ifdef DEBUG
361 void assertValidVMFunctionId() const;
362 #else
363 void assertValidVMFunctionId() const {}
364 #endif
365
366 public:
367 static constexpr size_t Size() { return sizeof(ExitFooterFrame); }
368 void setUnwoundJitExitFrame() {
369 data_ = uintptr_t(ExitFrameType::UnwoundJit);
370 }
371 ExitFrameType type() const {
372 if (data_ >= uintptr_t(ExitFrameType::VMFunction)) {
373 return ExitFrameType::VMFunction;
374 }
375 return ExitFrameType(data_);
376 }
377 VMFunctionId functionId() const {
378 MOZ_ASSERT(type() == ExitFrameType::VMFunction);
379 assertValidVMFunctionId();
380 return static_cast<VMFunctionId>(data_ - size_t(ExitFrameType::VMFunction));
381 }
382
383 // This should only be called for function()->outParam == Type_Handle
384 template <typename T>
385 T* outParam() {
386 uint8_t* address = reinterpret_cast<uint8_t*>(this);
387 return reinterpret_cast<T*>(address - sizeof(T));
388 }
389 };
390
391 class NativeExitFrameLayout;
392 class IonOOLNativeExitFrameLayout;
393 class IonOOLProxyExitFrameLayout;
394 class IonDOMExitFrameLayout;
395
396 // this is the frame layout when we are exiting ion code, and about to enter
397 // platform ABI code
398 class ExitFrameLayout : public CommonFrameLayout {
399 inline uint8_t* top() { return reinterpret_cast<uint8_t*>(this + 1); }
400
401 public:
402 static constexpr size_t Size() { return sizeof(ExitFrameLayout); }
403 static constexpr size_t SizeWithFooter() {
404 return Size() + ExitFooterFrame::Size();
405 }
406
407 inline ExitFooterFrame* footer() {
408 uint8_t* sp = reinterpret_cast<uint8_t*>(this);
409 return reinterpret_cast<ExitFooterFrame*>(sp - ExitFooterFrame::Size());
410 }
411
412 // argBase targets the point which precedes the exit frame. Arguments of VM
413 // each wrapper are pushed before the exit frame. This correspond exactly
414 // to the value of the argBase register of the generateVMWrapper function.
415 inline uint8_t* argBase() {
416 MOZ_ASSERT(isWrapperExit());
417 return top();
418 }
419
420 inline bool isWrapperExit() {
421 return footer()->type() == ExitFrameType::VMFunction;
422 }
423 inline bool isBareExit() { return footer()->type() == ExitFrameType::Bare; }
424 inline bool isUnwoundJitExit() {
425 return footer()->type() == ExitFrameType::UnwoundJit;
426 }
427
428 // See the various exit frame layouts below.
429 template <typename T>
430 inline bool is() {
431 return footer()->type() == T::Type();
432 }
433 template <typename T>
434 inline T* as() {
435 MOZ_ASSERT(this->is<T>());
436 return reinterpret_cast<T*>(footer());
437 }
438 };
439
440 // Cannot inherit implementation since we need to extend the top of
441 // ExitFrameLayout.
442 class NativeExitFrameLayout {
443 protected: // only to silence a clang warning about unused private fields
444 ExitFooterFrame footer_;
445 ExitFrameLayout exit_;
446 uintptr_t argc_;
447
448 // We need to split the Value into 2 fields of 32 bits, otherwise the C++
449 // compiler may add some padding between the fields.
450 uint32_t loCalleeResult_;
451 uint32_t hiCalleeResult_;
452
453 public:
454 static inline size_t Size() { return sizeof(NativeExitFrameLayout); }
455
456 static size_t offsetOfResult() {
457 return offsetof(NativeExitFrameLayout, loCalleeResult_);
458 }
459 inline JS::Value* vp() {
460 return reinterpret_cast<JS::Value*>(&loCalleeResult_);
461 }
462 inline uintptr_t argc() const { return argc_; }
463 };
464
465 class CallNativeExitFrameLayout : public NativeExitFrameLayout {
466 public:
467 static ExitFrameType Type() { return ExitFrameType::CallNative; }
468 };
469
470 class ConstructNativeExitFrameLayout : public NativeExitFrameLayout {
471 public:
472 static ExitFrameType Type() { return ExitFrameType::ConstructNative; }
473 };
474
475 template <>
476 inline bool ExitFrameLayout::is<NativeExitFrameLayout>() {
477 return is<CallNativeExitFrameLayout>() ||
478 is<ConstructNativeExitFrameLayout>();
479 }
480
481 class IonOOLNativeExitFrameLayout {
482 protected: // only to silence a clang warning about unused private fields
483 ExitFooterFrame footer_;
484 ExitFrameLayout exit_;
485
486 // pointer to root the stub's JitCode
487 JitCode* stubCode_;
488
489 uintptr_t argc_;
490
491 // We need to split the Value into 2 fields of 32 bits, otherwise the C++
492 // compiler may add some padding between the fields.
493 uint32_t loCalleeResult_;
494 uint32_t hiCalleeResult_;
495
496 // Split Value for |this| and args above.
497 uint32_t loThis_;
498 uint32_t hiThis_;
499
500 public:
501 static ExitFrameType Type() { return ExitFrameType::IonOOLNative; }
502
503 static inline size_t Size(size_t argc) {
504 // The frame accounts for the callee/result and |this|, so we only need
505 // args.
506 return sizeof(IonOOLNativeExitFrameLayout) + (argc * sizeof(JS::Value));
507 }
508
509 static size_t offsetOfResult() {
510 return offsetof(IonOOLNativeExitFrameLayout, loCalleeResult_);
511 }
512
513 inline JitCode** stubCode() { return &stubCode_; }
514 inline JS::Value* vp() {
515 return reinterpret_cast<JS::Value*>(&loCalleeResult_);
516 }
517 inline JS::Value* thisp() { return reinterpret_cast<JS::Value*>(&loThis_); }
518 inline uintptr_t argc() const { return argc_; }
519 };
520
521 // ProxyGetProperty(JSContext* cx, HandleObject proxy, HandleId id,
522 // MutableHandleValue vp)
523 // ProxyCallProperty(JSContext* cx, HandleObject proxy, HandleId id,
524 // MutableHandleValue vp)
525 // ProxySetProperty(JSContext* cx, HandleObject proxy, HandleId id,
526 // MutableHandleValue vp, bool strict)
527 class IonOOLProxyExitFrameLayout {
528 protected: // only to silence a clang warning about unused private fields
529 ExitFooterFrame footer_;
530 ExitFrameLayout exit_;
531
532 // The proxy object.
533 JSObject* proxy_;
534
535 // id for HandleId
536 jsid id_;
537
538 // space for MutableHandleValue result
539 // use two uint32_t so compiler doesn't align.
540 uint32_t vp0_;
541 uint32_t vp1_;
542
543 // pointer to root the stub's JitCode
544 JitCode* stubCode_;
545
546 public:
547 static ExitFrameType Type() { return ExitFrameType::IonOOLProxy; }
548
549 static inline size_t Size() { return sizeof(IonOOLProxyExitFrameLayout); }
550
551 static size_t offsetOfResult() {
552 return offsetof(IonOOLProxyExitFrameLayout, vp0_);
553 }
554
555 inline JitCode** stubCode() { return &stubCode_; }
556 inline JS::Value* vp() { return reinterpret_cast<JS::Value*>(&vp0_); }
557 inline jsid* id() { return &id_; }
558 inline JSObject** proxy() { return &proxy_; }
559 };
560
561 class IonDOMExitFrameLayout {
562 protected: // only to silence a clang warning about unused private fields
563 ExitFooterFrame footer_;
564 ExitFrameLayout exit_;
565 JSObject* thisObj;
566
567 // We need to split the Value into 2 fields of 32 bits, otherwise the C++
568 // compiler may add some padding between the fields.
569 uint32_t loCalleeResult_;
570 uint32_t hiCalleeResult_;
571
572 public:
573 static ExitFrameType GetterType() { return ExitFrameType::IonDOMGetter; }
574 static ExitFrameType SetterType() { return ExitFrameType::IonDOMSetter; }
575
576 static inline size_t Size() { return sizeof(IonDOMExitFrameLayout); }
577
578 static size_t offsetOfResult() {
579 return offsetof(IonDOMExitFrameLayout, loCalleeResult_);
580 }
581 inline JS::Value* vp() {
582 return reinterpret_cast<JS::Value*>(&loCalleeResult_);
583 }
584 inline JSObject** thisObjAddress() { return &thisObj; }
585 inline bool isMethodFrame();
586 };
587
588 struct IonDOMMethodExitFrameLayoutTraits;
589
590 class IonDOMMethodExitFrameLayout {
591 protected: // only to silence a clang warning about unused private fields
592 ExitFooterFrame footer_;
593 ExitFrameLayout exit_;
594 // This must be the last thing pushed, so as to stay common with
595 // IonDOMExitFrameLayout.
596 JSObject* thisObj_;
597 JS::Value* argv_;
598 uintptr_t argc_;
599
600 // We need to split the Value into 2 fields of 32 bits, otherwise the C++
601 // compiler may add some padding between the fields.
602 uint32_t loCalleeResult_;
603 uint32_t hiCalleeResult_;
604
605 friend struct IonDOMMethodExitFrameLayoutTraits;
606
607 public:
608 static ExitFrameType Type() { return ExitFrameType::IonDOMMethod; }
609
610 static inline size_t Size() { return sizeof(IonDOMMethodExitFrameLayout); }
611
612 static size_t offsetOfResult() {
613 return offsetof(IonDOMMethodExitFrameLayout, loCalleeResult_);
614 }
615
616 inline JS::Value* vp() {
617 // The code in visitCallDOMNative depends on this static assert holding
618 static_assert(
619 offsetof(IonDOMMethodExitFrameLayout, loCalleeResult_) ==
620 (offsetof(IonDOMMethodExitFrameLayout, argc_) + sizeof(uintptr_t)));
621 return reinterpret_cast<JS::Value*>(&loCalleeResult_);
622 }
623 inline JSObject** thisObjAddress() { return &thisObj_; }
624 inline uintptr_t argc() { return argc_; }
625 };
626
627 inline bool IonDOMExitFrameLayout::isMethodFrame() {
628 return footer_.type() == IonDOMMethodExitFrameLayout::Type();
629 }
630
631 template <>
632 inline bool ExitFrameLayout::is<IonDOMExitFrameLayout>() {
633 ExitFrameType type = footer()->type();
634 return type == IonDOMExitFrameLayout::GetterType() ||
635 type == IonDOMExitFrameLayout::SetterType() ||
636 type == IonDOMMethodExitFrameLayout::Type();
637 }
638
639 template <>
640 inline IonDOMExitFrameLayout* ExitFrameLayout::as<IonDOMExitFrameLayout>() {
641 MOZ_ASSERT(is<IonDOMExitFrameLayout>());
642 return reinterpret_cast<IonDOMExitFrameLayout*>(footer());
643 }
644
645 struct IonDOMMethodExitFrameLayoutTraits {
646 static const size_t offsetOfArgcFromArgv =
647 offsetof(IonDOMMethodExitFrameLayout, argc_) -
648 offsetof(IonDOMMethodExitFrameLayout, argv_);
649 };
650
651 // Cannot inherit implementation since we need to extend the top of
652 // ExitFrameLayout.
653 class CalledFromJitExitFrameLayout {
654 protected: // silence clang warning about unused private fields
655 ExitFooterFrame footer_;
656 JitFrameLayout exit_;
657
658 public:
659 static inline size_t Size() { return sizeof(CalledFromJitExitFrameLayout); }
660 inline JitFrameLayout* jsFrame() { return &exit_; }
661 static size_t offsetOfExitFrame() {
662 return offsetof(CalledFromJitExitFrameLayout, exit_);
663 }
664 };
665
666 class LazyLinkExitFrameLayout : public CalledFromJitExitFrameLayout {
667 public:
668 static ExitFrameType Type() { return ExitFrameType::LazyLink; }
669 };
670
671 class InterpreterStubExitFrameLayout : public CalledFromJitExitFrameLayout {
672 public:
673 static ExitFrameType Type() { return ExitFrameType::InterpreterStub; }
674 };
675
676 class WasmGenericJitEntryFrameLayout : CalledFromJitExitFrameLayout {
677 public:
678 static ExitFrameType Type() { return ExitFrameType::WasmGenericJitEntry; }
679 };
680
681 template <>
682 inline bool ExitFrameLayout::is<CalledFromJitExitFrameLayout>() {
683 return is<InterpreterStubExitFrameLayout>() ||
684 is<LazyLinkExitFrameLayout>() || is<WasmGenericJitEntryFrameLayout>();
685 }
686
687 template <>
688 inline CalledFromJitExitFrameLayout*
689 ExitFrameLayout::as<CalledFromJitExitFrameLayout>() {
690 MOZ_ASSERT(is<CalledFromJitExitFrameLayout>());
691 uint8_t* sp = reinterpret_cast<uint8_t*>(this);
692 sp -= CalledFromJitExitFrameLayout::offsetOfExitFrame();
693 return reinterpret_cast<CalledFromJitExitFrameLayout*>(sp);
694 }
695
696 class DirectWasmJitCallFrameLayout {
697 protected: // silence clang warning about unused private fields
698 ExitFooterFrame footer_;
699 ExitFrameLayout exit_;
700
701 public:
702 static ExitFrameType Type() { return ExitFrameType::DirectWasmJitCall; }
703 };
704
705 class ICStub;
706
707 class BaselineStubFrameLayout : public CommonFrameLayout {
708 // Info on the stack
709 //
710 // +-----------------------+
711 // |BaselineStubFrameLayout|
712 // +-----------------------+
713 // | - Descriptor | => Marks end of FrameType::BaselineJS
714 // | - Return address |
715 // | - CallerFramePtr |
716 // +-----------------------+
717 // | - StubPtr | Technically this last field is not part
718 // +-----------------------+ of the frame layout.
719
720 public:
721 static constexpr size_t ICStubOffset = sizeof(void*);
722 static constexpr int ICStubOffsetFromFP = -int(ICStubOffset);
723 static constexpr size_t LocallyTracedValueOffset = 2 * sizeof(void*);
724
725 static inline size_t Size() { return sizeof(BaselineStubFrameLayout); }
726
727 ICStub* maybeStubPtr() {
728 uint8_t* fp = reinterpret_cast<uint8_t*>(this);
729 return *reinterpret_cast<ICStub**>(fp - ICStubOffset);
730 }
731 void setStubPtr(ICStub* stub) {
732 MOZ_ASSERT(stub);
733 uint8_t* fp = reinterpret_cast<uint8_t*>(this);
734 *reinterpret_cast<ICStub**>(fp - ICStubOffset) = stub;
735 }
736
737 inline Value* locallyTracedValuePtr(size_t index) {
738 uint8_t* fp = reinterpret_cast<uint8_t*>(this);
739 return reinterpret_cast<Value*>(fp - LocallyTracedValueOffset -
740 index * sizeof(Value));
741 }
742 };
743
744 // An invalidation bailout stack is at the stack pointer for the callee frame.
745 class InvalidationBailoutStack {
746 RegisterDump::FPUArray fpregs_;
747 RegisterDump::GPRArray regs_;
748 IonScript* ionScript_;
749 uint8_t* osiPointReturnAddress_;
750
751 public:
752 uint8_t* sp() const {
753 return (uint8_t*)this + sizeof(InvalidationBailoutStack);
754 }
755 JitFrameLayout* fp() const;
756 MachineState machine() { return MachineState::FromBailout(regs_, fpregs_); }
757
758 IonScript* ionScript() const { return ionScript_; }
759 uint8_t* osiPointReturnAddress() const { return osiPointReturnAddress_; }
760 static size_t offsetOfFpRegs() {
761 return offsetof(InvalidationBailoutStack, fpregs_);
762 }
763 static size_t offsetOfRegs() {
764 return offsetof(InvalidationBailoutStack, regs_);
765 }
766
767 void checkInvariants() const;
768 };
769
770 // Baseline requires one slot for this/argument type checks.
771 static const uint32_t MinJITStackSize = 1;
772
773 } /* namespace jit */
774 } /* namespace js */
775
776 #endif /* jit_JitFrames_h */