|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
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_BaselineDebugModeOSR_h |
|
8 #define jit_BaselineDebugModeOSR_h |
|
9 |
|
10 #ifdef JS_ION |
|
11 |
|
12 #include "jit/BaselineFrame.h" |
|
13 #include "jit/BaselineIC.h" |
|
14 #include "jit/BaselineJIT.h" |
|
15 |
|
16 namespace js { |
|
17 namespace jit { |
|
18 |
|
19 // Note that this file and the corresponding .cpp implement debug mode |
|
20 // on-stack recompilation. This is to be distinguished from ordinary |
|
21 // Baseline->Ion OSR, which is used to jump into compiled loops. |
|
22 |
|
23 // |
|
24 // A volatile location due to recompilation of an on-stack baseline script |
|
25 // (e.g., for debug mode toggling). |
|
26 // |
|
27 // It is usually used in fallback stubs which may trigger on-stack |
|
28 // recompilation by calling out into the VM. Example use: |
|
29 // |
|
30 // DebugModeOSRVolatileStub<FallbackStubT *> stub(frame, stub_) |
|
31 // |
|
32 // // Call out to the VM |
|
33 // // Other effectful operations like TypeScript::Monitor |
|
34 // |
|
35 // if (stub.invalid()) |
|
36 // return true; |
|
37 // |
|
38 // // First use of stub after VM call. |
|
39 // |
|
40 template <typename T> |
|
41 class DebugModeOSRVolatileStub |
|
42 { |
|
43 T stub_; |
|
44 BaselineFrame *frame_; |
|
45 uint32_t pcOffset_; |
|
46 |
|
47 public: |
|
48 DebugModeOSRVolatileStub(BaselineFrame *frame, ICFallbackStub *stub) |
|
49 : stub_(static_cast<T>(stub)), |
|
50 frame_(frame), |
|
51 pcOffset_(stub->icEntry()->pcOffset()) |
|
52 { } |
|
53 |
|
54 bool invalid() const { |
|
55 ICEntry &entry = frame_->script()->baselineScript()->icEntryFromPCOffset(pcOffset_); |
|
56 return stub_ != entry.fallbackStub(); |
|
57 } |
|
58 |
|
59 operator const T&() const { MOZ_ASSERT(!invalid()); return stub_; } |
|
60 T operator->() const { MOZ_ASSERT(!invalid()); return stub_; } |
|
61 T *address() { MOZ_ASSERT(!invalid()); return &stub_; } |
|
62 const T *address() const { MOZ_ASSERT(!invalid()); return &stub_; } |
|
63 T &get() { MOZ_ASSERT(!invalid()); return stub_; } |
|
64 const T &get() const { MOZ_ASSERT(!invalid()); return stub_; } |
|
65 |
|
66 bool operator!=(const T &other) const { MOZ_ASSERT(!invalid()); return stub_ != other; } |
|
67 bool operator==(const T &other) const { MOZ_ASSERT(!invalid()); return stub_ == other; } |
|
68 }; |
|
69 |
|
70 // |
|
71 // Auxiliary info to help the DebugModeOSRHandler fix up state. |
|
72 // |
|
73 struct BaselineDebugModeOSRInfo |
|
74 { |
|
75 uint8_t *resumeAddr; |
|
76 jsbytecode *pc; |
|
77 PCMappingSlotInfo slotInfo; |
|
78 ICEntry::Kind frameKind; |
|
79 |
|
80 // Filled in by SyncBaselineDebugModeOSRInfo. |
|
81 uintptr_t stackAdjust; |
|
82 Value valueR0; |
|
83 Value valueR1; |
|
84 |
|
85 BaselineDebugModeOSRInfo(jsbytecode *pc, ICEntry::Kind kind) |
|
86 : resumeAddr(nullptr), |
|
87 pc(pc), |
|
88 slotInfo(0), |
|
89 frameKind(kind), |
|
90 stackAdjust(0), |
|
91 valueR0(UndefinedValue()), |
|
92 valueR1(UndefinedValue()) |
|
93 { } |
|
94 |
|
95 void popValueInto(PCMappingSlotInfo::SlotLocation loc, Value *vp); |
|
96 }; |
|
97 |
|
98 bool |
|
99 RecompileOnStackBaselineScriptsForDebugMode(JSContext *cx, JSCompartment *comp); |
|
100 |
|
101 } // namespace jit |
|
102 } // namespace js |
|
103 |
|
104 #endif // JS_ION |
|
105 |
|
106 #endif // jit_BaselineDebugModeOSR_h |