js/src/jit/x86/Bailouts-x86.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit/x86/Bailouts-x86.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "jscntxt.h"
    1.11 +#include "jscompartment.h"
    1.12 +
    1.13 +#include "jit/Bailouts.h"
    1.14 +#include "jit/JitCompartment.h"
    1.15 +
    1.16 +using namespace js;
    1.17 +using namespace js::jit;
    1.18 +
    1.19 +#if defined(_WIN32)
    1.20 +# pragma pack(push, 1)
    1.21 +#endif
    1.22 +
    1.23 +namespace js {
    1.24 +namespace jit {
    1.25 +
    1.26 +class BailoutStack
    1.27 +{
    1.28 +    uintptr_t frameClassId_;
    1.29 +    mozilla::Array<double, FloatRegisters::Total> fpregs_;
    1.30 +    mozilla::Array<uintptr_t, Registers::Total> regs_;
    1.31 +    union {
    1.32 +        uintptr_t frameSize_;
    1.33 +        uintptr_t tableOffset_;
    1.34 +    };
    1.35 +    uintptr_t snapshotOffset_;
    1.36 +
    1.37 +  public:
    1.38 +    FrameSizeClass frameClass() const {
    1.39 +        return FrameSizeClass::FromClass(frameClassId_);
    1.40 +    }
    1.41 +    uintptr_t tableOffset() const {
    1.42 +        JS_ASSERT(frameClass() != FrameSizeClass::None());
    1.43 +        return tableOffset_;
    1.44 +    }
    1.45 +    uint32_t frameSize() const {
    1.46 +        if (frameClass() == FrameSizeClass::None())
    1.47 +            return frameSize_;
    1.48 +        return frameClass().frameSize();
    1.49 +    }
    1.50 +    MachineState machine() {
    1.51 +        return MachineState::FromBailout(regs_, fpregs_);
    1.52 +    }
    1.53 +    SnapshotOffset snapshotOffset() const {
    1.54 +        JS_ASSERT(frameClass() == FrameSizeClass::None());
    1.55 +        return snapshotOffset_;
    1.56 +    }
    1.57 +    uint8_t *parentStackPointer() const {
    1.58 +        if (frameClass() == FrameSizeClass::None())
    1.59 +            return (uint8_t *)this + sizeof(BailoutStack);
    1.60 +        return (uint8_t *)this + offsetof(BailoutStack, snapshotOffset_);
    1.61 +    }
    1.62 +};
    1.63 +
    1.64 +} // namespace jit
    1.65 +} // namespace js
    1.66 +
    1.67 +#if defined(_WIN32)
    1.68 +# pragma pack(pop)
    1.69 +#endif
    1.70 +
    1.71 +IonBailoutIterator::IonBailoutIterator(const JitActivationIterator &activations,
    1.72 +                                       BailoutStack *bailout)
    1.73 +  : JitFrameIterator(activations),
    1.74 +    machine_(bailout->machine())
    1.75 +{
    1.76 +    uint8_t *sp = bailout->parentStackPointer();
    1.77 +    uint8_t *fp = sp + bailout->frameSize();
    1.78 +
    1.79 +    current_ = fp;
    1.80 +    type_ = JitFrame_IonJS;
    1.81 +    topFrameSize_ = current_ - sp;
    1.82 +    topIonScript_ = script()->ionScript();
    1.83 +
    1.84 +    if (bailout->frameClass() == FrameSizeClass::None()) {
    1.85 +        snapshotOffset_ = bailout->snapshotOffset();
    1.86 +        return;
    1.87 +    }
    1.88 +
    1.89 +    // Compute the snapshot offset from the bailout ID.
    1.90 +    JitActivation *activation = activations.activation()->asJit();
    1.91 +    JSRuntime *rt = activation->compartment()->runtimeFromMainThread();
    1.92 +    JitCode *code = rt->jitRuntime()->getBailoutTable(bailout->frameClass());
    1.93 +    uintptr_t tableOffset = bailout->tableOffset();
    1.94 +    uintptr_t tableStart = reinterpret_cast<uintptr_t>(code->raw());
    1.95 +
    1.96 +    JS_ASSERT(tableOffset >= tableStart &&
    1.97 +              tableOffset < tableStart + code->instructionsSize());
    1.98 +    JS_ASSERT((tableOffset - tableStart) % BAILOUT_TABLE_ENTRY_SIZE == 0);
    1.99 +
   1.100 +    uint32_t bailoutId = ((tableOffset - tableStart) / BAILOUT_TABLE_ENTRY_SIZE) - 1;
   1.101 +    JS_ASSERT(bailoutId < BAILOUT_TABLE_SIZE);
   1.102 +
   1.103 +    snapshotOffset_ = topIonScript_->bailoutToSnapshot(bailoutId);
   1.104 +}
   1.105 +
   1.106 +IonBailoutIterator::IonBailoutIterator(const JitActivationIterator &activations,
   1.107 +                                       InvalidationBailoutStack *bailout)
   1.108 +  : JitFrameIterator(activations),
   1.109 +    machine_(bailout->machine())
   1.110 +{
   1.111 +    returnAddressToFp_ = bailout->osiPointReturnAddress();
   1.112 +    topIonScript_ = bailout->ionScript();
   1.113 +    const OsiIndex *osiIndex = topIonScript_->getOsiIndex(returnAddressToFp_);
   1.114 +
   1.115 +    current_ = (uint8_t*) bailout->fp();
   1.116 +    type_ = JitFrame_IonJS;
   1.117 +    topFrameSize_ = current_ - bailout->sp();
   1.118 +    snapshotOffset_ = osiIndex->snapshotOffset();
   1.119 +}

mercurial