2014-07-21 19:58:12 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
|
|
* 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 js_ProfilingFrameIterator_h
|
|
|
|
#define js_ProfilingFrameIterator_h
|
|
|
|
|
2017-01-31 02:56:05 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-04-03 00:50:08 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2014-07-21 19:58:12 +04:00
|
|
|
|
2015-05-12 00:16:44 +03:00
|
|
|
#include "jsbytecode.h"
|
2016-10-14 19:13:47 +03:00
|
|
|
#include "js/GCAPI.h"
|
2015-06-18 08:05:42 +03:00
|
|
|
#include "js/TypeDecls.h"
|
2014-07-21 19:58:12 +04:00
|
|
|
#include "js/Utility.h"
|
|
|
|
|
2016-08-11 15:39:22 +03:00
|
|
|
struct JSContext;
|
2014-07-21 19:58:12 +04:00
|
|
|
struct JSRuntime;
|
2015-05-12 00:16:44 +03:00
|
|
|
class JSScript;
|
2014-08-26 22:03:04 +04:00
|
|
|
|
|
|
|
namespace js {
|
|
|
|
class Activation;
|
2015-01-16 04:11:22 +03:00
|
|
|
namespace jit {
|
|
|
|
class JitActivation;
|
|
|
|
class JitProfilingFrameIterator;
|
2015-04-03 00:50:08 +03:00
|
|
|
class JitcodeGlobalEntry;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace jit
|
2015-12-29 02:39:21 +03:00
|
|
|
namespace wasm {
|
|
|
|
class ProfilingFrameIterator;
|
|
|
|
} // namespace wasm
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace js
|
2014-07-21 19:58:12 +04:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2015-05-12 00:16:44 +03:00
|
|
|
struct ForEachTrackedOptimizationAttemptOp;
|
|
|
|
struct ForEachTrackedOptimizationTypeInfoOp;
|
|
|
|
|
2014-07-21 19:58:12 +04:00
|
|
|
// This iterator can be used to walk the stack of a thread suspended at an
|
2017-06-02 20:34:05 +03:00
|
|
|
// arbitrary pc. To provide accurate results, profiling must have been enabled
|
2014-07-21 19:58:12 +04:00
|
|
|
// (via EnableRuntimeProfilingStack) before executing the callstack being
|
|
|
|
// unwound.
|
2016-10-14 19:13:47 +03:00
|
|
|
//
|
|
|
|
// Note that the caller must not do anything that could cause GC to happen while
|
|
|
|
// the iterator is alive, since this could invalidate Ion code and cause its
|
|
|
|
// contents to become out of date.
|
2017-01-31 02:56:05 +03:00
|
|
|
class MOZ_NON_PARAM JS_PUBLIC_API(ProfilingFrameIterator)
|
2014-07-21 19:58:12 +04:00
|
|
|
{
|
2017-02-08 21:18:41 +03:00
|
|
|
JSContext* cx_;
|
2015-02-26 00:43:39 +03:00
|
|
|
uint32_t sampleBufferGen_;
|
2015-03-29 01:22:11 +03:00
|
|
|
js::Activation* activation_;
|
2014-07-21 19:58:12 +04:00
|
|
|
|
2015-12-03 06:40:09 +03:00
|
|
|
static const unsigned StorageSpace = 8 * sizeof(void*);
|
2017-01-31 02:56:05 +03:00
|
|
|
alignas(void*) unsigned char storage_[StorageSpace];
|
|
|
|
|
|
|
|
void* storage() { return storage_; }
|
|
|
|
const void* storage() const { return storage_; }
|
|
|
|
|
2016-11-02 20:22:37 +03:00
|
|
|
js::wasm::ProfilingFrameIterator& wasmIter() {
|
2014-10-01 21:17:51 +04:00
|
|
|
MOZ_ASSERT(!done());
|
2016-11-02 20:22:37 +03:00
|
|
|
MOZ_ASSERT(isWasm());
|
2017-01-31 02:56:05 +03:00
|
|
|
return *static_cast<js::wasm::ProfilingFrameIterator*>(storage());
|
2014-07-21 19:58:12 +04:00
|
|
|
}
|
2016-11-02 20:22:37 +03:00
|
|
|
const js::wasm::ProfilingFrameIterator& wasmIter() const {
|
2014-10-01 21:17:51 +04:00
|
|
|
MOZ_ASSERT(!done());
|
2016-11-02 20:22:37 +03:00
|
|
|
MOZ_ASSERT(isWasm());
|
2017-01-31 02:56:05 +03:00
|
|
|
return *static_cast<const js::wasm::ProfilingFrameIterator*>(storage());
|
2014-07-21 19:58:12 +04:00
|
|
|
}
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
js::jit::JitProfilingFrameIterator& jitIter() {
|
2015-01-16 04:11:22 +03:00
|
|
|
MOZ_ASSERT(!done());
|
|
|
|
MOZ_ASSERT(isJit());
|
2017-01-31 02:56:05 +03:00
|
|
|
return *static_cast<js::jit::JitProfilingFrameIterator*>(storage());
|
2015-01-16 04:11:22 +03:00
|
|
|
}
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
const js::jit::JitProfilingFrameIterator& jitIter() const {
|
2015-01-16 04:11:22 +03:00
|
|
|
MOZ_ASSERT(!done());
|
|
|
|
MOZ_ASSERT(isJit());
|
2017-01-31 02:56:05 +03:00
|
|
|
return *static_cast<const js::jit::JitProfilingFrameIterator*>(storage());
|
2015-01-16 04:11:22 +03:00
|
|
|
}
|
|
|
|
|
2014-07-21 19:58:12 +04:00
|
|
|
void settle();
|
|
|
|
|
2015-02-26 00:43:39 +03:00
|
|
|
bool hasSampleBufferGen() const {
|
|
|
|
return sampleBufferGen_ != UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
2014-07-21 19:58:12 +04:00
|
|
|
public:
|
|
|
|
struct RegisterState
|
|
|
|
{
|
2017-03-23 01:26:05 +03:00
|
|
|
RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr), lr(nullptr) {}
|
2015-03-29 01:22:11 +03:00
|
|
|
void* pc;
|
|
|
|
void* sp;
|
2017-03-23 01:26:05 +03:00
|
|
|
void* fp;
|
2015-03-29 01:22:11 +03:00
|
|
|
void* lr;
|
2014-07-21 19:58:12 +04:00
|
|
|
};
|
|
|
|
|
2016-08-11 15:39:22 +03:00
|
|
|
ProfilingFrameIterator(JSContext* cx, const RegisterState& state,
|
2015-02-26 00:43:39 +03:00
|
|
|
uint32_t sampleBufferGen = UINT32_MAX);
|
2014-07-21 19:58:12 +04:00
|
|
|
~ProfilingFrameIterator();
|
|
|
|
void operator++();
|
|
|
|
bool done() const { return !activation_; }
|
|
|
|
|
2014-07-29 18:56:21 +04:00
|
|
|
// Assuming the stack grows down (we do), the return value:
|
|
|
|
// - always points into the stack
|
|
|
|
// - is weakly monotonically increasing (may be equal for successive frames)
|
|
|
|
// - will compare greater than newer native and psuedo-stack frame addresses
|
|
|
|
// and less than older native and psuedo-stack frame addresses
|
2015-03-29 01:22:11 +03:00
|
|
|
void* stackAddress() const;
|
2014-07-29 18:56:21 +04:00
|
|
|
|
2015-01-16 04:11:22 +03:00
|
|
|
enum FrameKind
|
|
|
|
{
|
|
|
|
Frame_Baseline,
|
|
|
|
Frame_Ion,
|
2016-11-02 20:22:37 +03:00
|
|
|
Frame_Wasm
|
2015-01-16 04:11:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Frame
|
|
|
|
{
|
|
|
|
FrameKind kind;
|
2015-03-29 01:22:11 +03:00
|
|
|
void* stackAddress;
|
|
|
|
void* returnAddress;
|
|
|
|
void* activation;
|
2016-11-21 13:26:31 +03:00
|
|
|
const char* label;
|
2016-11-21 13:26:33 +03:00
|
|
|
} JS_HAZ_GC_INVALIDATED;
|
2015-04-03 00:50:08 +03:00
|
|
|
|
2016-11-02 20:22:37 +03:00
|
|
|
bool isWasm() const;
|
2015-04-03 00:50:08 +03:00
|
|
|
bool isJit() const;
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
uint32_t extractStack(Frame* frames, uint32_t offset, uint32_t end) const;
|
2014-08-26 22:03:04 +04:00
|
|
|
|
2015-04-03 00:50:08 +03:00
|
|
|
mozilla::Maybe<Frame> getPhysicalFrameWithoutLabel() const;
|
|
|
|
|
2014-08-26 22:03:04 +04:00
|
|
|
private:
|
2015-04-03 00:50:08 +03:00
|
|
|
mozilla::Maybe<Frame> getPhysicalFrameAndEntry(js::jit::JitcodeGlobalEntry* entry) const;
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void iteratorConstruct(const RegisterState& state);
|
2014-08-26 22:03:04 +04:00
|
|
|
void iteratorConstruct();
|
|
|
|
void iteratorDestroy();
|
|
|
|
bool iteratorDone();
|
2016-12-07 06:23:48 +03:00
|
|
|
} JS_HAZ_GC_INVALIDATED;
|
2014-07-21 19:58:12 +04:00
|
|
|
|
2015-03-03 01:46:13 +03:00
|
|
|
JS_FRIEND_API(bool)
|
2016-08-11 15:39:22 +03:00
|
|
|
IsProfilingEnabledForContext(JSContext* cx);
|
2015-03-03 01:46:13 +03:00
|
|
|
|
2015-02-26 00:43:39 +03:00
|
|
|
/**
|
|
|
|
* After each sample run, this method should be called with the latest sample
|
|
|
|
* buffer generation, and the lapCount. It will update corresponding fields on
|
|
|
|
* JSRuntime.
|
|
|
|
*
|
|
|
|
* See fields |profilerSampleBufferGen|, |profilerSampleBufferLapCount| on
|
|
|
|
* JSRuntime for documentation about what these values are used for.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void)
|
2016-08-11 15:39:22 +03:00
|
|
|
UpdateJSContextProfilerSampleBufferGen(JSContext* cx, uint32_t generation,
|
2015-02-26 00:43:39 +03:00
|
|
|
uint32_t lapCount);
|
|
|
|
|
2015-04-03 00:50:08 +03:00
|
|
|
struct ForEachProfiledFrameOp
|
|
|
|
{
|
2015-05-12 00:16:44 +03:00
|
|
|
// A handle to the underlying JitcodeGlobalEntry, so as to avoid repeated
|
|
|
|
// lookups on JitcodeGlobalTable.
|
|
|
|
class MOZ_STACK_CLASS FrameHandle
|
|
|
|
{
|
2016-08-11 15:39:22 +03:00
|
|
|
friend JS_PUBLIC_API(void) ForEachProfiledFrame(JSContext* cx, void* addr,
|
2015-05-12 00:16:44 +03:00
|
|
|
ForEachProfiledFrameOp& op);
|
2015-05-12 00:16:44 +03:00
|
|
|
|
|
|
|
JSRuntime* rt_;
|
|
|
|
js::jit::JitcodeGlobalEntry& entry_;
|
|
|
|
void* addr_;
|
|
|
|
void* canonicalAddr_;
|
|
|
|
const char* label_;
|
|
|
|
uint32_t depth_;
|
|
|
|
mozilla::Maybe<uint8_t> optsIndex_;
|
|
|
|
|
|
|
|
FrameHandle(JSRuntime* rt, js::jit::JitcodeGlobalEntry& entry, void* addr,
|
|
|
|
const char* label, uint32_t depth);
|
|
|
|
|
|
|
|
void updateHasTrackedOptimizations();
|
|
|
|
|
|
|
|
public:
|
|
|
|
const char* label() const { return label_; }
|
|
|
|
uint32_t depth() const { return depth_; }
|
|
|
|
bool hasTrackedOptimizations() const { return optsIndex_.isSome(); }
|
|
|
|
void* canonicalAddress() const { return canonicalAddr_; }
|
|
|
|
|
2017-03-11 07:52:55 +03:00
|
|
|
JS_PUBLIC_API(ProfilingFrameIterator::FrameKind) frameKind() const;
|
|
|
|
JS_PUBLIC_API(void) forEachOptimizationAttempt(ForEachTrackedOptimizationAttemptOp& op,
|
|
|
|
JSScript** scriptOut,
|
|
|
|
jsbytecode** pcOut) const;
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
forEachOptimizationTypeInfo(ForEachTrackedOptimizationTypeInfoOp& op) const;
|
2015-05-12 00:16:44 +03:00
|
|
|
};
|
|
|
|
|
2015-04-03 00:50:08 +03:00
|
|
|
// Called once per frame.
|
2015-05-12 00:16:44 +03:00
|
|
|
virtual void operator()(const FrameHandle& frame) = 0;
|
2015-04-03 00:50:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
2016-08-11 15:39:22 +03:00
|
|
|
ForEachProfiledFrame(JSContext* cx, void* addr, ForEachProfiledFrameOp& op);
|
2015-04-03 00:50:08 +03:00
|
|
|
|
2014-07-21 19:58:12 +04:00
|
|
|
} // namespace JS
|
|
|
|
|
|
|
|
#endif /* js_ProfilingFrameIterator_h */
|