Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
7 #include "jscntxt.h"
8 #include "jscompartment.h"
10 #include "jit/Bailouts.h"
11 #include "jit/JitCompartment.h"
13 using namespace js;
14 using namespace js::jit;
16 namespace js {
17 namespace jit {
19 class BailoutStack
20 {
21 uintptr_t frameClassId_;
22 // This is pushed in the bailout handler. Both entry points into the handler
23 // inserts their own value int lr, which is then placed onto the stack along
24 // with frameClassId_ above. This should be migrated to ip.
25 public:
26 union {
27 uintptr_t frameSize_;
28 uintptr_t tableOffset_;
29 };
31 protected: // Silence Clang warning about unused private fields.
32 mozilla::Array<double, FloatRegisters::Total> fpregs_;
33 mozilla::Array<uintptr_t, Registers::Total> regs_;
35 uintptr_t snapshotOffset_;
36 uintptr_t padding_;
38 public:
39 FrameSizeClass frameClass() const {
40 return FrameSizeClass::FromClass(frameClassId_);
41 }
42 uintptr_t tableOffset() const {
43 JS_ASSERT(frameClass() != FrameSizeClass::None());
44 return tableOffset_;
45 }
46 uint32_t frameSize() const {
47 if (frameClass() == FrameSizeClass::None())
48 return frameSize_;
49 return frameClass().frameSize();
50 }
51 MachineState machine() {
52 return MachineState::FromBailout(regs_, fpregs_);
53 }
54 SnapshotOffset snapshotOffset() const {
55 JS_ASSERT(frameClass() == FrameSizeClass::None());
56 return snapshotOffset_;
57 }
58 uint8_t *parentStackPointer() const {
59 if (frameClass() == FrameSizeClass::None())
60 return (uint8_t *)this + sizeof(BailoutStack);
61 return (uint8_t *)this + offsetof(BailoutStack, snapshotOffset_);
62 }
63 };
65 // Make sure the compiler doesn't add extra padding.
66 static_assert((sizeof(BailoutStack) % 8) == 0, "BailoutStack should be 8-byte aligned.");
68 } // namespace jit
69 } // namespace js
71 IonBailoutIterator::IonBailoutIterator(const JitActivationIterator &activations,
72 BailoutStack *bailout)
73 : JitFrameIterator(activations),
74 machine_(bailout->machine())
75 {
76 uint8_t *sp = bailout->parentStackPointer();
77 uint8_t *fp = sp + bailout->frameSize();
79 current_ = fp;
80 type_ = JitFrame_IonJS;
81 topFrameSize_ = current_ - sp;
82 topIonScript_ = script()->ionScript();
84 if (bailout->frameClass() == FrameSizeClass::None()) {
85 snapshotOffset_ = bailout->snapshotOffset();
86 return;
87 }
89 // Compute the snapshot offset from the bailout ID.
90 JitActivation *activation = activations.activation()->asJit();
91 JSRuntime *rt = activation->compartment()->runtimeFromMainThread();
92 JitCode *code = rt->jitRuntime()->getBailoutTable(bailout->frameClass());
93 uintptr_t tableOffset = bailout->tableOffset();
94 uintptr_t tableStart = reinterpret_cast<uintptr_t>(code->raw());
96 JS_ASSERT(tableOffset >= tableStart &&
97 tableOffset < tableStart + code->instructionsSize());
98 JS_ASSERT((tableOffset - tableStart) % BAILOUT_TABLE_ENTRY_SIZE == 0);
100 uint32_t bailoutId = ((tableOffset - tableStart) / BAILOUT_TABLE_ENTRY_SIZE) - 1;
101 JS_ASSERT(bailoutId < BAILOUT_TABLE_SIZE);
103 snapshotOffset_ = topIonScript_->bailoutToSnapshot(bailoutId);
104 }
106 IonBailoutIterator::IonBailoutIterator(const JitActivationIterator &activations,
107 InvalidationBailoutStack *bailout)
108 : JitFrameIterator(activations),
109 machine_(bailout->machine())
110 {
111 returnAddressToFp_ = bailout->osiPointReturnAddress();
112 topIonScript_ = bailout->ionScript();
113 const OsiIndex *osiIndex = topIonScript_->getOsiIndex(returnAddressToFp_);
115 current_ = (uint8_t*) bailout->fp();
116 type_ = JitFrame_IonJS;
117 topFrameSize_ = current_ - bailout->sp();
118 snapshotOffset_ = osiIndex->snapshotOffset();
119 }