Bumping manifests a=b2g-bump
[gecko.git] / js / public / ProfilingFrameIterator.h
blob5ef9eb810cab4ccf1c642b7e1be11803c4f59d6f
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 #ifndef js_ProfilingFrameIterator_h
8 #define js_ProfilingFrameIterator_h
10 #include "mozilla/Alignment.h"
12 #include <stdint.h>
14 #include "js/Utility.h"
16 class JSAtom;
17 struct JSRuntime;
19 namespace js {
20 class Activation;
21 class AsmJSProfilingFrameIterator;
24 namespace JS {
26 // This iterator can be used to walk the stack of a thread suspended at an
27 // arbitrary pc. To provide acurate results, profiling must have been enabled
28 // (via EnableRuntimeProfilingStack) before executing the callstack being
29 // unwound.
30 class JS_PUBLIC_API(ProfilingFrameIterator)
32 js::Activation* activation_;
34 static const unsigned StorageSpace = 6 * sizeof(void*);
35 mozilla::AlignedStorage<StorageSpace> storage_;
36 js::AsmJSProfilingFrameIterator& asmJSIter() {
37 MOZ_ASSERT(!done());
38 return *reinterpret_cast<js::AsmJSProfilingFrameIterator*>(storage_.addr());
40 const js::AsmJSProfilingFrameIterator& asmJSIter() const {
41 MOZ_ASSERT(!done());
42 return *reinterpret_cast<const js::AsmJSProfilingFrameIterator*>(storage_.addr());
45 void settle();
47 public:
48 struct RegisterState
50 RegisterState() : pc(nullptr), sp(nullptr), lr(nullptr) {}
51 void* pc;
52 void* sp;
53 void* lr;
56 ProfilingFrameIterator(JSRuntime* rt, const RegisterState& state);
57 ~ProfilingFrameIterator();
58 void operator++();
59 bool done() const { return !activation_; }
61 // Assuming the stack grows down (we do), the return value:
62 // - always points into the stack
63 // - is weakly monotonically increasing (may be equal for successive frames)
64 // - will compare greater than newer native and psuedo-stack frame addresses
65 // and less than older native and psuedo-stack frame addresses
66 void* stackAddress() const;
68 // Return a label suitable for regexp-matching as performed by
69 // browser/devtools/profiler/cleopatra/js/parserWorker.js
70 const char* label() const;
72 private:
73 void iteratorConstruct(const RegisterState& state);
74 void iteratorConstruct();
75 void iteratorDestroy();
76 bool iteratorDone();
79 } // namespace JS
81 #endif /* js_ProfilingFrameIterator_h */