2013-08-20 10:45:26 +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_ProfilingStack_h
|
|
|
|
#define js_ProfilingStack_h
|
|
|
|
|
|
|
|
#include "jsbytecode.h"
|
|
|
|
#include "jstypes.h"
|
2015-06-18 08:05:42 +03:00
|
|
|
#include "js/TypeDecls.h"
|
2013-08-20 10:45:26 +04:00
|
|
|
|
|
|
|
#include "js/Utility.h"
|
|
|
|
|
|
|
|
struct JSRuntime;
|
2016-04-13 12:03:44 +03:00
|
|
|
class JSTracer;
|
2013-08-20 10:45:26 +04:00
|
|
|
|
|
|
|
namespace js {
|
|
|
|
|
|
|
|
// A call stack can be specified to the JS engine such that all JS entry/exits
|
|
|
|
// to functions push/pop an entry to/from the specified stack.
|
|
|
|
//
|
2017-01-25 01:08:15 +03:00
|
|
|
// For more detailed information, see vm/GeckoProfiler.h.
|
2013-08-20 10:45:26 +04:00
|
|
|
//
|
|
|
|
class ProfileEntry
|
|
|
|
{
|
|
|
|
// All fields are marked volatile to prevent the compiler from re-ordering
|
|
|
|
// instructions. Namely this sequence:
|
|
|
|
//
|
|
|
|
// entry[size] = ...;
|
|
|
|
// size++;
|
|
|
|
//
|
|
|
|
// If the size modification were somehow reordered before the stores, then
|
|
|
|
// if a sample were taken it would be examining bogus information.
|
|
|
|
//
|
2014-05-29 02:44:41 +04:00
|
|
|
// A ProfileEntry represents both a C++ profile entry and a JS one.
|
|
|
|
|
|
|
|
// Descriptive string of this entry.
|
|
|
|
const char * volatile string;
|
|
|
|
|
|
|
|
// Stack pointer for non-JS entries, the script pointer otherwise.
|
|
|
|
void * volatile spOrScript;
|
|
|
|
|
|
|
|
// Line number for non-JS entries, the bytecode offset otherwise.
|
2016-09-13 15:06:46 +03:00
|
|
|
int32_t volatile lineOrPcOffset;
|
2014-05-29 02:44:41 +04:00
|
|
|
|
|
|
|
// General purpose storage describing this frame.
|
2014-06-04 22:37:49 +04:00
|
|
|
uint32_t volatile flags_;
|
2013-08-20 10:45:26 +04:00
|
|
|
|
|
|
|
public:
|
2014-05-29 02:44:41 +04:00
|
|
|
// These traits are bit masks. Make sure they're powers of 2.
|
2016-08-18 19:35:00 +03:00
|
|
|
enum Flags : uint32_t {
|
2014-05-29 02:44:41 +04:00
|
|
|
// Indicate whether a profile entry represents a CPP frame. If not set,
|
|
|
|
// a JS frame is assumed by default. You're not allowed to publicly
|
2015-09-19 12:19:07 +03:00
|
|
|
// change the frame type. Instead, initialize the ProfileEntry as either
|
|
|
|
// a JS or CPP frame with `initJsFrame` or `initCppFrame` respectively.
|
2014-05-29 02:44:41 +04:00
|
|
|
IS_CPP_ENTRY = 0x01,
|
|
|
|
|
|
|
|
// Indicate that copying the frame label is not necessary when taking a
|
|
|
|
// sample of the pseudostack.
|
2014-06-04 22:37:49 +04:00
|
|
|
FRAME_LABEL_COPY = 0x02,
|
|
|
|
|
2015-01-16 04:11:22 +03:00
|
|
|
// This ProfileEntry is a dummy entry indicating the start of a run
|
|
|
|
// of JS pseudostack entries.
|
|
|
|
BEGIN_PSEUDO_JS = 0x04,
|
|
|
|
|
|
|
|
// This flag is used to indicate that an interpreter JS entry has OSR-ed
|
|
|
|
// into baseline.
|
|
|
|
OSR = 0x08,
|
2014-07-29 18:56:22 +04:00
|
|
|
|
2015-09-14 12:57:00 +03:00
|
|
|
// Union of all flags.
|
|
|
|
ALL = IS_CPP_ENTRY|FRAME_LABEL_COPY|BEGIN_PSEUDO_JS|OSR,
|
|
|
|
|
2014-06-04 22:37:49 +04:00
|
|
|
// Mask for removing all flags except the category information.
|
2015-09-14 12:57:00 +03:00
|
|
|
CATEGORY_MASK = ~ALL
|
2014-05-29 02:44:41 +04:00
|
|
|
};
|
2014-04-11 19:58:55 +04:00
|
|
|
|
2016-03-22 12:17:20 +03:00
|
|
|
// Keep these in sync with devtools/client/performance/modules/categories.js
|
2015-01-26 01:22:08 +03:00
|
|
|
enum class Category : uint32_t {
|
2015-01-16 04:11:22 +03:00
|
|
|
OTHER = 0x10,
|
|
|
|
CSS = 0x20,
|
|
|
|
JS = 0x40,
|
|
|
|
GC = 0x80,
|
|
|
|
CC = 0x100,
|
|
|
|
NETWORK = 0x200,
|
|
|
|
GRAPHICS = 0x400,
|
|
|
|
STORAGE = 0x800,
|
|
|
|
EVENTS = 0x1000,
|
2014-05-31 05:41:11 +04:00
|
|
|
|
|
|
|
FIRST = OTHER,
|
|
|
|
LAST = EVENTS
|
2015-01-26 01:22:08 +03:00
|
|
|
};
|
2014-05-24 01:12:29 +04:00
|
|
|
|
2015-09-14 12:57:00 +03:00
|
|
|
static_assert((static_cast<int>(Category::FIRST) & Flags::ALL) == 0,
|
|
|
|
"The category bitflags should not intersect with the other flags!");
|
|
|
|
|
2017-01-25 01:08:15 +03:00
|
|
|
// All of these methods are marked with the 'volatile' keyword because the
|
|
|
|
// Gecko Profiler's representation of the stack is stored such that all
|
|
|
|
// ProfileEntry instances are volatile. These methods would not be
|
|
|
|
// available unless they were marked as volatile as well.
|
2013-08-20 10:45:26 +04:00
|
|
|
|
2014-05-29 02:44:41 +04:00
|
|
|
bool isCpp() const volatile { return hasFlag(IS_CPP_ENTRY); }
|
|
|
|
bool isJs() const volatile { return !isCpp(); }
|
|
|
|
|
2014-08-18 23:20:39 +04:00
|
|
|
bool isCopyLabel() const volatile { return hasFlag(FRAME_LABEL_COPY); }
|
2014-05-29 02:44:41 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void setLabel(const char* aString) volatile { string = aString; }
|
|
|
|
const char* label() const volatile { return string; }
|
2014-05-29 02:44:41 +04:00
|
|
|
|
2015-09-19 12:19:07 +03:00
|
|
|
void initJsFrame(JSScript* aScript, jsbytecode* aPc) volatile {
|
2014-06-04 22:37:49 +04:00
|
|
|
flags_ = 0;
|
2014-05-29 02:44:41 +04:00
|
|
|
spOrScript = aScript;
|
|
|
|
setPC(aPc);
|
|
|
|
}
|
2015-09-19 12:19:07 +03:00
|
|
|
void initCppFrame(void* aSp, uint32_t aLine) volatile {
|
2014-06-04 22:37:49 +04:00
|
|
|
flags_ = IS_CPP_ENTRY;
|
2014-05-29 02:44:41 +04:00
|
|
|
spOrScript = aSp;
|
2016-09-13 15:06:46 +03:00
|
|
|
lineOrPcOffset = static_cast<int32_t>(aLine);
|
2013-08-20 10:45:26 +04:00
|
|
|
}
|
|
|
|
|
2014-05-31 05:41:11 +04:00
|
|
|
void setFlag(uint32_t flag) volatile {
|
2014-05-29 02:44:41 +04:00
|
|
|
MOZ_ASSERT(flag != IS_CPP_ENTRY);
|
2014-06-04 22:37:49 +04:00
|
|
|
flags_ |= flag;
|
2014-05-20 23:25:25 +04:00
|
|
|
}
|
2014-05-31 05:41:11 +04:00
|
|
|
void unsetFlag(uint32_t flag) volatile {
|
2014-05-29 02:44:41 +04:00
|
|
|
MOZ_ASSERT(flag != IS_CPP_ENTRY);
|
2014-06-04 22:37:49 +04:00
|
|
|
flags_ &= ~flag;
|
2014-05-29 02:44:41 +04:00
|
|
|
}
|
2014-05-31 05:41:11 +04:00
|
|
|
bool hasFlag(uint32_t flag) const volatile {
|
2014-06-04 22:37:49 +04:00
|
|
|
return bool(flags_ & flag);
|
|
|
|
}
|
2014-06-04 22:37:49 +04:00
|
|
|
|
2014-06-04 22:37:49 +04:00
|
|
|
uint32_t flags() const volatile {
|
|
|
|
return flags_;
|
2014-05-20 23:25:25 +04:00
|
|
|
}
|
2015-09-14 22:15:12 +03:00
|
|
|
|
2014-06-04 22:37:49 +04:00
|
|
|
uint32_t category() const volatile {
|
|
|
|
return flags_ & CATEGORY_MASK;
|
|
|
|
}
|
2015-09-14 22:15:12 +03:00
|
|
|
void setCategory(Category c) volatile {
|
2015-09-19 12:19:07 +03:00
|
|
|
MOZ_ASSERT(c >= Category::FIRST);
|
|
|
|
MOZ_ASSERT(c <= Category::LAST);
|
2015-09-14 22:15:12 +03:00
|
|
|
flags_ &= ~CATEGORY_MASK;
|
|
|
|
setFlag(static_cast<uint32_t>(c));
|
|
|
|
}
|
2014-05-27 05:51:50 +04:00
|
|
|
|
2015-01-16 04:11:22 +03:00
|
|
|
void setOSR() volatile {
|
|
|
|
MOZ_ASSERT(isJs());
|
|
|
|
setFlag(OSR);
|
|
|
|
}
|
|
|
|
void unsetOSR() volatile {
|
|
|
|
MOZ_ASSERT(isJs());
|
|
|
|
unsetFlag(OSR);
|
|
|
|
}
|
|
|
|
bool isOSR() const volatile {
|
|
|
|
return hasFlag(OSR);
|
|
|
|
}
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void* stackAddress() const volatile {
|
2014-05-29 02:44:41 +04:00
|
|
|
MOZ_ASSERT(!isJs());
|
|
|
|
return spOrScript;
|
|
|
|
}
|
2016-09-13 15:06:46 +03:00
|
|
|
JSScript* script() const volatile;
|
2014-05-29 02:44:41 +04:00
|
|
|
uint32_t line() const volatile {
|
|
|
|
MOZ_ASSERT(!isJs());
|
2016-09-13 15:06:46 +03:00
|
|
|
return static_cast<uint32_t>(lineOrPcOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that the pointer returned might be invalid.
|
|
|
|
JSScript* rawScript() const volatile {
|
|
|
|
MOZ_ASSERT(isJs());
|
|
|
|
return (JSScript*)spOrScript;
|
2014-05-29 02:44:41 +04:00
|
|
|
}
|
2013-08-20 10:45:26 +04:00
|
|
|
|
2017-01-25 01:08:15 +03:00
|
|
|
// We can't know the layout of JSScript, so look in vm/GeckoProfiler.cpp.
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_FRIEND_API(jsbytecode*) pc() const volatile;
|
|
|
|
JS_FRIEND_API(void) setPC(jsbytecode* pc) volatile;
|
2013-08-20 10:45:26 +04:00
|
|
|
|
2016-04-13 12:03:44 +03:00
|
|
|
void trace(JSTracer* trc);
|
|
|
|
|
2014-05-29 02:44:41 +04:00
|
|
|
// The offset of a pc into a script's code can actually be 0, so to
|
|
|
|
// signify a nullptr pc, use a -1 index. This is checked against in
|
|
|
|
// pc() and setPC() to set/get the right pc.
|
|
|
|
static const int32_t NullPCOffset = -1;
|
2014-02-24 21:27:58 +04:00
|
|
|
|
2014-05-29 02:44:41 +04:00
|
|
|
static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); }
|
|
|
|
static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); }
|
2016-09-13 15:06:46 +03:00
|
|
|
static size_t offsetOfLineOrPcOffset() { return offsetof(ProfileEntry, lineOrPcOffset); }
|
2014-06-04 22:37:49 +04:00
|
|
|
static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); }
|
2013-08-20 10:45:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
2016-08-11 15:39:22 +03:00
|
|
|
SetContextProfilingStack(JSContext* cx, ProfileEntry* stack, uint32_t* size,
|
2013-08-20 10:45:26 +04:00
|
|
|
uint32_t max);
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
2016-08-11 15:39:22 +03:00
|
|
|
EnableContextProfilingStack(JSContext* cx, bool enabled);
|
2013-08-20 10:45:26 +04:00
|
|
|
|
2014-03-03 23:36:08 +04:00
|
|
|
JS_FRIEND_API(void)
|
2016-08-11 15:39:22 +03:00
|
|
|
RegisterContextProfilingEventMarker(JSContext* cx, void (*fn)(const char*));
|
2014-03-03 23:36:08 +04:00
|
|
|
|
2013-08-20 10:45:26 +04:00
|
|
|
JS_FRIEND_API(jsbytecode*)
|
2016-08-11 15:39:22 +03:00
|
|
|
ProfilingGetPC(JSContext* cx, JSScript* script, void* ip);
|
2013-08-20 10:45:26 +04:00
|
|
|
|
|
|
|
} // namespace js
|
|
|
|
|
|
|
|
#endif /* js_ProfilingStack_h */
|