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/mips32/Bailouts-mips32.h"
8 
9 #include "jit/JitFrames.h"
10 #include "jit/JitRuntime.h"
11 #include "jit/ScriptFromCalleeToken.h"
12 #include "vm/JSContext.h"
13 #include "vm/Realm.h"
14 
15 #include "vm/JSScript-inl.h"
16 
17 using namespace js;
18 using namespace js::jit;
19 
BailoutFrameInfo(const JitActivationIterator & activations,BailoutStack * bailout)20 BailoutFrameInfo::BailoutFrameInfo(const JitActivationIterator& activations,
21                                    BailoutStack* bailout)
22     : machine_(bailout->machine()) {
23   uint8_t* sp = bailout->parentStackPointer();
24   framePointer_ = sp + bailout->frameSize();
25   topFrameSize_ = framePointer_ - sp;
26 
27   JSScript* script =
28       ScriptFromCalleeToken(((JitFrameLayout*)framePointer_)->calleeToken());
29   JitActivation* activation = activations.activation()->asJit();
30   topIonScript_ = script->ionScript();
31 
32   attachOnJitActivation(activations);
33 
34   if (bailout->frameClass() == FrameSizeClass::None()) {
35     snapshotOffset_ = bailout->snapshotOffset();
36     return;
37   }
38 
39   // Compute the snapshot offset from the bailout ID.
40   JSRuntime* rt = activation->compartment()->runtimeFromMainThread();
41   TrampolinePtr code = rt->jitRuntime()->getBailoutTable(bailout->frameClass());
42 #ifdef DEBUG
43   uint32_t tableSize =
44       rt->jitRuntime()->getBailoutTableSize(bailout->frameClass());
45 #endif
46   uintptr_t tableOffset = bailout->tableOffset();
47   uintptr_t tableStart = reinterpret_cast<uintptr_t>(code.value);
48 
49   MOZ_ASSERT(tableOffset >= tableStart && tableOffset < tableStart + tableSize);
50   MOZ_ASSERT((tableOffset - tableStart) % BAILOUT_TABLE_ENTRY_SIZE == 0);
51 
52   uint32_t bailoutId =
53       ((tableOffset - tableStart) / BAILOUT_TABLE_ENTRY_SIZE) - 1;
54   MOZ_ASSERT(bailoutId < BAILOUT_TABLE_SIZE);
55 
56   snapshotOffset_ = topIonScript_->bailoutToSnapshot(bailoutId);
57 }
58