michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "jscntxt.h" michael@0: #include "jscompartment.h" michael@0: michael@0: #include "jit/Bailouts.h" michael@0: #include "jit/JitCompartment.h" michael@0: michael@0: using namespace js; michael@0: using namespace js::jit; michael@0: michael@0: #if defined(_WIN32) michael@0: # pragma pack(push, 1) michael@0: #endif michael@0: michael@0: namespace js { michael@0: namespace jit { michael@0: michael@0: class BailoutStack michael@0: { michael@0: uintptr_t frameClassId_; michael@0: mozilla::Array fpregs_; michael@0: mozilla::Array regs_; michael@0: union { michael@0: uintptr_t frameSize_; michael@0: uintptr_t tableOffset_; michael@0: }; michael@0: uintptr_t snapshotOffset_; michael@0: michael@0: public: michael@0: FrameSizeClass frameClass() const { michael@0: return FrameSizeClass::FromClass(frameClassId_); michael@0: } michael@0: uintptr_t tableOffset() const { michael@0: JS_ASSERT(frameClass() != FrameSizeClass::None()); michael@0: return tableOffset_; michael@0: } michael@0: uint32_t frameSize() const { michael@0: if (frameClass() == FrameSizeClass::None()) michael@0: return frameSize_; michael@0: return frameClass().frameSize(); michael@0: } michael@0: MachineState machine() { michael@0: return MachineState::FromBailout(regs_, fpregs_); michael@0: } michael@0: SnapshotOffset snapshotOffset() const { michael@0: JS_ASSERT(frameClass() == FrameSizeClass::None()); michael@0: return snapshotOffset_; michael@0: } michael@0: uint8_t *parentStackPointer() const { michael@0: if (frameClass() == FrameSizeClass::None()) michael@0: return (uint8_t *)this + sizeof(BailoutStack); michael@0: return (uint8_t *)this + offsetof(BailoutStack, snapshotOffset_); michael@0: } michael@0: }; michael@0: michael@0: } // namespace jit michael@0: } // namespace js michael@0: michael@0: #if defined(_WIN32) michael@0: # pragma pack(pop) michael@0: #endif michael@0: michael@0: IonBailoutIterator::IonBailoutIterator(const JitActivationIterator &activations, michael@0: BailoutStack *bailout) michael@0: : JitFrameIterator(activations), michael@0: machine_(bailout->machine()) michael@0: { michael@0: uint8_t *sp = bailout->parentStackPointer(); michael@0: uint8_t *fp = sp + bailout->frameSize(); michael@0: michael@0: current_ = fp; michael@0: type_ = JitFrame_IonJS; michael@0: topFrameSize_ = current_ - sp; michael@0: topIonScript_ = script()->ionScript(); michael@0: michael@0: if (bailout->frameClass() == FrameSizeClass::None()) { michael@0: snapshotOffset_ = bailout->snapshotOffset(); michael@0: return; michael@0: } michael@0: michael@0: // Compute the snapshot offset from the bailout ID. michael@0: JitActivation *activation = activations.activation()->asJit(); michael@0: JSRuntime *rt = activation->compartment()->runtimeFromMainThread(); michael@0: JitCode *code = rt->jitRuntime()->getBailoutTable(bailout->frameClass()); michael@0: uintptr_t tableOffset = bailout->tableOffset(); michael@0: uintptr_t tableStart = reinterpret_cast(code->raw()); michael@0: michael@0: JS_ASSERT(tableOffset >= tableStart && michael@0: tableOffset < tableStart + code->instructionsSize()); michael@0: JS_ASSERT((tableOffset - tableStart) % BAILOUT_TABLE_ENTRY_SIZE == 0); michael@0: michael@0: uint32_t bailoutId = ((tableOffset - tableStart) / BAILOUT_TABLE_ENTRY_SIZE) - 1; michael@0: JS_ASSERT(bailoutId < BAILOUT_TABLE_SIZE); michael@0: michael@0: snapshotOffset_ = topIonScript_->bailoutToSnapshot(bailoutId); michael@0: } michael@0: michael@0: IonBailoutIterator::IonBailoutIterator(const JitActivationIterator &activations, michael@0: InvalidationBailoutStack *bailout) michael@0: : JitFrameIterator(activations), michael@0: machine_(bailout->machine()) michael@0: { michael@0: returnAddressToFp_ = bailout->osiPointReturnAddress(); michael@0: topIonScript_ = bailout->ionScript(); michael@0: const OsiIndex *osiIndex = topIonScript_->getOsiIndex(returnAddressToFp_); michael@0: michael@0: current_ = (uint8_t*) bailout->fp(); michael@0: type_ = JitFrame_IonJS; michael@0: topFrameSize_ = current_ - bailout->sp(); michael@0: snapshotOffset_ = osiIndex->snapshotOffset(); michael@0: }