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 #include "jscntxt.h"
8 #include "jscompartment.h"
9
10 #include "jit/arm/Assembler-arm.h"
11 #include "jit/Bailouts.h"
12 #include "jit/JitCompartment.h"
13
14 using namespace js;
15 using namespace js::jit;
16
17 namespace js {
18 namespace jit {
19
20 class BailoutStack
21 {
22 uintptr_t frameClassId_;
23 // This is pushed in the bailout handler. Both entry points into the handler
24 // inserts their own value int lr, which is then placed onto the stack along
25 // with frameClassId_ above. This should be migrated to ip.
26 public:
27 union {
28 uintptr_t frameSize_;
29 uintptr_t tableOffset_;
30 };
31
32 protected: // Silence Clang warning about unused private fields.
33 RegisterDump::FPUArray fpregs_;
34 RegisterDump::GPRArray regs_;
35
36 uintptr_t snapshotOffset_;
37 uintptr_t padding_;
38
39 public:
frameClass() const40 FrameSizeClass frameClass() const {
41 return FrameSizeClass::FromClass(frameClassId_);
42 }
tableOffset() const43 uintptr_t tableOffset() const {
44 MOZ_ASSERT(frameClass() != FrameSizeClass::None());
45 return tableOffset_;
46 }
frameSize() const47 uint32_t frameSize() const {
48 if (frameClass() == FrameSizeClass::None())
49 return frameSize_;
50 return frameClass().frameSize();
51 }
machine()52 MachineState machine() {
53 return MachineState::FromBailout(regs_, fpregs_);
54 }
snapshotOffset() const55 SnapshotOffset snapshotOffset() const {
56 MOZ_ASSERT(frameClass() == FrameSizeClass::None());
57 return snapshotOffset_;
58 }
parentStackPointer() const59 uint8_t* parentStackPointer() const {
60 if (frameClass() == FrameSizeClass::None())
61 return (uint8_t*)this + sizeof(BailoutStack);
62 return (uint8_t*)this + offsetof(BailoutStack, snapshotOffset_);
63 }
64 };
65
66 // Make sure the compiler doesn't add extra padding.
67 static_assert((sizeof(BailoutStack) % 8) == 0, "BailoutStack should be 8-byte aligned.");
68
69 } // namespace jit
70 } // namespace js
71
BailoutFrameInfo(const JitActivationIterator & activations,BailoutStack * bailout)72 BailoutFrameInfo::BailoutFrameInfo(const JitActivationIterator& activations,
73 BailoutStack* bailout)
74 : machine_(bailout->machine())
75 {
76 uint8_t* sp = bailout->parentStackPointer();
77 framePointer_ = sp + bailout->frameSize();
78 topFrameSize_ = framePointer_ - sp;
79
80 JSScript* script = ScriptFromCalleeToken(((JitFrameLayout*) framePointer_)->calleeToken());
81 JitActivation* activation = activations.activation()->asJit();
82 topIonScript_ = script->ionScript();
83
84 attachOnJitActivation(activations);
85
86 if (bailout->frameClass() == FrameSizeClass::None()) {
87 snapshotOffset_ = bailout->snapshotOffset();
88 return;
89 }
90
91 // Compute the snapshot offset from the bailout ID.
92 JSRuntime* rt = activation->compartment()->runtimeFromMainThread();
93 JitCode* code = rt->jitRuntime()->getBailoutTable(bailout->frameClass());
94 uintptr_t tableOffset = bailout->tableOffset();
95 uintptr_t tableStart = reinterpret_cast<uintptr_t>(Assembler::BailoutTableStart(code->raw()));
96
97 MOZ_ASSERT(tableOffset >= tableStart &&
98 tableOffset < tableStart + code->instructionsSize());
99 MOZ_ASSERT((tableOffset - tableStart) % BAILOUT_TABLE_ENTRY_SIZE == 0);
100
101 uint32_t bailoutId = ((tableOffset - tableStart) / BAILOUT_TABLE_ENTRY_SIZE) - 1;
102 MOZ_ASSERT(bailoutId < BAILOUT_TABLE_SIZE);
103
104 snapshotOffset_ = topIonScript_->bailoutToSnapshot(bailoutId);
105 }
106
BailoutFrameInfo(const JitActivationIterator & activations,InvalidationBailoutStack * bailout)107 BailoutFrameInfo::BailoutFrameInfo(const JitActivationIterator& activations,
108 InvalidationBailoutStack* bailout)
109 : machine_(bailout->machine())
110 {
111 framePointer_ = (uint8_t*) bailout->fp();
112 topFrameSize_ = framePointer_ - bailout->sp();
113 topIonScript_ = bailout->ionScript();
114 attachOnJitActivation(activations);
115
116 uint8_t* returnAddressToFp_ = bailout->osiPointReturnAddress();
117 const OsiIndex* osiIndex = topIonScript_->getOsiIndex(returnAddressToFp_);
118 snapshotOffset_ = osiIndex->snapshotOffset();
119 }
120