diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/vm/Activation-inl.h | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/vm/Activation-inl.h')
-rw-r--r-- | js/src/vm/Activation-inl.h | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/js/src/vm/Activation-inl.h b/js/src/vm/Activation-inl.h new file mode 100644 index 0000000000..76e054eb44 --- /dev/null +++ b/js/src/vm/Activation-inl.h @@ -0,0 +1,171 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim: set ts=8 sts=2 et sw=2 tw=80: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef vm_Activation_inl_h +#define vm_Activation_inl_h + +#include "vm/Activation.h" + +#include "mozilla/Assertions.h" // MOZ_ASSERT{,_IF}, MOZ_CRASH +#include "mozilla/Likely.h" // MOZ_UNLIKELY +#include "mozilla/Maybe.h" // mozilla::Maybe + +#include "jit/CalleeToken.h" // js::jit::CalleeToken +#include "vm/FrameIter.h" // js::FrameIter +#include "vm/JitActivation.h" // js::jit::JitActivation +#include "vm/JSContext.h" // JSContext +#include "vm/Stack.h" // js::AbstractFramePtr + +namespace js { + +inline ActivationEntryMonitor::ActivationEntryMonitor(JSContext* cx) + : cx_(cx), entryMonitor_(cx->entryMonitor) { + cx->entryMonitor = nullptr; +} + +inline ActivationEntryMonitor::ActivationEntryMonitor( + JSContext* cx, InterpreterFrame* entryFrame) + : ActivationEntryMonitor(cx) { + if (MOZ_UNLIKELY(entryMonitor_)) { + init(cx, entryFrame); + } +} + +inline ActivationEntryMonitor::ActivationEntryMonitor( + JSContext* cx, jit::CalleeToken entryToken) + : ActivationEntryMonitor(cx) { + if (MOZ_UNLIKELY(entryMonitor_)) { + init(cx, entryToken); + } +} + +inline ActivationEntryMonitor::~ActivationEntryMonitor() { + if (entryMonitor_) { + entryMonitor_->Exit(cx_); + } + + cx_->entryMonitor = entryMonitor_; +} + +inline Activation::Activation(JSContext* cx, Kind kind) + : cx_(cx), + compartment_(cx->compartment()), + prev_(cx->activation_), + prevProfiling_(prev_ ? prev_->mostRecentProfiling() : nullptr), + hideScriptedCallerCount_(0), + frameCache_(cx), + asyncStack_(cx, cx->asyncStackForNewActivations()), + asyncCause_(cx->asyncCauseForNewActivations), + asyncCallIsExplicit_(cx->asyncCallIsExplicit), + kind_(kind) { + cx->asyncStackForNewActivations() = nullptr; + cx->asyncCauseForNewActivations = nullptr; + cx->asyncCallIsExplicit = false; + cx->activation_ = this; +} + +inline Activation::~Activation() { + MOZ_ASSERT_IF(isProfiling(), this != cx_->profilingActivation_); + MOZ_ASSERT(cx_->activation_ == this); + MOZ_ASSERT(hideScriptedCallerCount_ == 0); + cx_->activation_ = prev_; + cx_->asyncCauseForNewActivations = asyncCause_; + cx_->asyncStackForNewActivations() = asyncStack_; + cx_->asyncCallIsExplicit = asyncCallIsExplicit_; +} + +inline bool Activation::isProfiling() const { + if (isInterpreter()) { + return asInterpreter()->isProfiling(); + } + + MOZ_ASSERT(isJit()); + return asJit()->isProfiling(); +} + +inline Activation* Activation::mostRecentProfiling() { + if (isProfiling()) { + return this; + } + return prevProfiling_; +} + +inline LiveSavedFrameCache* Activation::getLiveSavedFrameCache(JSContext* cx) { + if (!frameCache_.get().initialized() && !frameCache_.get().init(cx)) { + return nullptr; + } + return frameCache_.address(); +} + +/* static */ inline mozilla::Maybe<LiveSavedFrameCache::FramePtr> +LiveSavedFrameCache::FramePtr::create(const FrameIter& iter) { + if (iter.done()) { + return mozilla::Nothing(); + } + + if (iter.isPhysicalJitFrame()) { + return mozilla::Some(FramePtr(iter.physicalJitFrame())); + } + + if (!iter.hasUsableAbstractFramePtr()) { + return mozilla::Nothing(); + } + + auto afp = iter.abstractFramePtr(); + + if (afp.isInterpreterFrame()) { + return mozilla::Some(FramePtr(afp.asInterpreterFrame())); + } + if (afp.isWasmDebugFrame()) { + return mozilla::Some(FramePtr(afp.asWasmDebugFrame())); + } + if (afp.isRematerializedFrame()) { + return mozilla::Some(FramePtr(afp.asRematerializedFrame())); + } + + MOZ_CRASH("unexpected frame type"); +} + +struct LiveSavedFrameCache::FramePtr::HasCachedMatcher { + template <typename Frame> + bool operator()(Frame* f) const { + return f->hasCachedSavedFrame(); + } +}; + +inline bool LiveSavedFrameCache::FramePtr::hasCachedSavedFrame() const { + return ptr.match(HasCachedMatcher()); +} + +struct LiveSavedFrameCache::FramePtr::SetHasCachedMatcher { + template <typename Frame> + void operator()(Frame* f) { + f->setHasCachedSavedFrame(); + } +}; + +inline void LiveSavedFrameCache::FramePtr::setHasCachedSavedFrame() { + ptr.match(SetHasCachedMatcher()); +} + +struct LiveSavedFrameCache::FramePtr::ClearHasCachedMatcher { + template <typename Frame> + void operator()(Frame* f) { + f->clearHasCachedSavedFrame(); + } +}; + +inline void LiveSavedFrameCache::FramePtr::clearHasCachedSavedFrame() { + ptr.match(ClearHasCachedMatcher()); +} + +inline bool Activation::hasWasmExitFP() const { + return isJit() && asJit()->hasWasmExitFP(); +} + +} // namespace js + +#endif // vm_Activation_inl_h |