зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1505690 - Replace JSScript::vtuneMethodId_ with a HashMap. r=sstangl
MOZ_VTUNE is defined on Nightly (because of --enable-profiling). With the HashMap we only have some memory/perf overhead when we're actually using VTune's JIT code profiler. Differential Revision: https://phabricator.services.mozilla.com/D11292 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
cf769d5a6d
Коммит
579b4656ca
|
@ -3172,10 +3172,6 @@ JSScript::JSScript(JS::Realm* realm, uint8_t* stubEntry, HandleObject sourceObje
|
|||
MOZ_ASSERT(sourceStart <= sourceEnd);
|
||||
MOZ_ASSERT(sourceEnd <= toStringEnd);
|
||||
|
||||
#ifdef MOZ_VTUNE
|
||||
vtuneMethodId_ = vtune::GenerateUniqueMethodID();
|
||||
#endif
|
||||
|
||||
setSourceObject(sourceObject);
|
||||
}
|
||||
|
||||
|
@ -3225,6 +3221,33 @@ JSScript::Create(JSContext* cx, const ReadOnlyCompileOptions& options,
|
|||
return script;
|
||||
}
|
||||
|
||||
#ifdef MOZ_VTUNE
|
||||
uint32_t
|
||||
JSScript::vtuneMethodID()
|
||||
{
|
||||
if (!realm()->scriptVTuneIdMap) {
|
||||
auto map = MakeUnique<ScriptVTuneIdMap>();
|
||||
if (!map) {
|
||||
MOZ_CRASH("Failed to allocate ScriptVTuneIdMap");
|
||||
}
|
||||
|
||||
realm()->scriptVTuneIdMap = std::move(map);
|
||||
}
|
||||
|
||||
ScriptVTuneIdMap::AddPtr p = realm()->scriptVTuneIdMap->lookupForAdd(this);
|
||||
if (p) {
|
||||
return p->value();
|
||||
}
|
||||
|
||||
uint32_t id = vtune::GenerateUniqueMethodID();
|
||||
if (!realm()->scriptVTuneIdMap->add(p, this, id)) {
|
||||
MOZ_CRASH("Failed to add vtune method id");
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool
|
||||
JSScript::initScriptName(JSContext* cx)
|
||||
{
|
||||
|
@ -3614,6 +3637,13 @@ JSScript::finalize(FreeOp* fop)
|
|||
destroyScriptCounts();
|
||||
destroyDebugScript(fop);
|
||||
|
||||
#ifdef MOZ_VTUNE
|
||||
if (realm()->scriptVTuneIdMap) {
|
||||
// Note: we should only get here if the VTune JIT profiler is running.
|
||||
realm()->scriptVTuneIdMap->remove(this);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data_) {
|
||||
JS_POISON(data_, 0xdb, computedSizeOfData(), MemCheckKind::MakeNoAccess);
|
||||
fop->free_(data_);
|
||||
|
|
|
@ -219,6 +219,13 @@ using ScriptNameMap = HashMap<JSScript*,
|
|||
DefaultHasher<JSScript*>,
|
||||
SystemAllocPolicy>;
|
||||
|
||||
#ifdef MOZ_VTUNE
|
||||
using ScriptVTuneIdMap = HashMap<JSScript*,
|
||||
uint32_t,
|
||||
DefaultHasher<JSScript*>,
|
||||
SystemAllocPolicy>;
|
||||
#endif
|
||||
|
||||
class DebugScript
|
||||
{
|
||||
friend class ::JSScript;
|
||||
|
@ -1626,12 +1633,6 @@ class JSScript : public js::gc::TenuredCell
|
|||
uint32_t toStringStart_ = 0;
|
||||
uint32_t toStringEnd_ = 0;
|
||||
|
||||
#ifdef MOZ_VTUNE
|
||||
// Unique Method ID passed to the VTune profiler, or 0 if unset.
|
||||
// Allows attribution of different jitcode to the same source script.
|
||||
uint32_t vtuneMethodId_ = 0;
|
||||
#endif
|
||||
|
||||
// Number of times the script has been called or has had backedges taken.
|
||||
// When running in ion, also increased for any inlined scripts. Reset if
|
||||
// the script's JIT code is forcibly discarded.
|
||||
|
@ -1705,6 +1706,8 @@ class JSScript : public js::gc::TenuredCell
|
|||
// See comments below.
|
||||
ArgsHasVarBinding = 1 << 21,
|
||||
};
|
||||
// Note: don't make this a bitfield! It makes it hard to read these flags
|
||||
// from JIT code.
|
||||
uint32_t immutableFlags_ = 0;
|
||||
|
||||
// Mutable flags typically store information about runtime or deoptimization
|
||||
|
@ -1775,6 +1778,8 @@ class JSScript : public js::gc::TenuredCell
|
|||
HideScriptFromDebugger = 1 << 19,
|
||||
};
|
||||
private:
|
||||
// Note: don't make this a bitfield! It makes it hard to read these flags
|
||||
// from JIT code.
|
||||
uint32_t mutableFlags_ = 0;
|
||||
|
||||
// 16-bit fields.
|
||||
|
@ -2394,7 +2399,9 @@ class JSScript : public js::gc::TenuredCell
|
|||
const char* maybeForwardedFilename() const { return maybeForwardedScriptSource()->filename(); }
|
||||
|
||||
#ifdef MOZ_VTUNE
|
||||
uint32_t vtuneMethodID() const { return vtuneMethodId_; }
|
||||
// Unique Method ID passed to the VTune profiler. Allows attribution of
|
||||
// different jitcode to the same source script.
|
||||
uint32_t vtuneMethodID();
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
|
|
@ -405,6 +405,10 @@ Realm::finishRoots()
|
|||
|
||||
clearScriptCounts();
|
||||
clearScriptNames();
|
||||
|
||||
#ifdef MOZ_VTUNE
|
||||
scriptVTuneIdMap.reset();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -588,6 +592,17 @@ Realm::fixupScriptMapsAfterMovingGC()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MOZ_VTUNE
|
||||
if (scriptVTuneIdMap) {
|
||||
for (ScriptVTuneIdMap::Enum e(*scriptVTuneIdMap); !e.empty(); e.popFront()) {
|
||||
JSScript* script = e.front().key();
|
||||
if (!IsAboutToBeFinalizedUnbarriered(&script) && script != e.front().key()) {
|
||||
e.rekeyFront(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef JSGC_HASH_TABLE_CHECKS
|
||||
|
@ -630,6 +645,18 @@ Realm::checkScriptMapsAfterMovingGC()
|
|||
MOZ_RELEASE_ASSERT(ptr.found() && &*ptr == &r.front());
|
||||
}
|
||||
}
|
||||
|
||||
# ifdef MOZ_VTUNE
|
||||
if (scriptVTuneIdMap) {
|
||||
for (auto r = scriptVTuneIdMap->all(); !r.empty(); r.popFront()) {
|
||||
JSScript* script = r.front().key();
|
||||
MOZ_ASSERT(script->realm() == this);
|
||||
CheckGCThingAfterMovingGC(script);
|
||||
auto ptr = scriptVTuneIdMap->lookup(script);
|
||||
MOZ_RELEASE_ASSERT(ptr.found() && &*ptr == &r.front());
|
||||
}
|
||||
}
|
||||
# endif // MOZ_VTUNE
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -421,6 +421,9 @@ class JS::Realm : public JS::shadow::Realm
|
|||
js::UniquePtr<js::ScriptCountsMap> scriptCountsMap;
|
||||
js::UniquePtr<js::ScriptNameMap> scriptNameMap;
|
||||
js::UniquePtr<js::DebugScriptMap> debugScriptMap;
|
||||
#ifdef MOZ_VTUNE
|
||||
js::UniquePtr<js::ScriptVTuneIdMap> scriptVTuneIdMap;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Lazily initialized script source object to use for scripts cloned
|
||||
|
|
|
@ -119,7 +119,7 @@ MarkRegExp(const js::jit::JitCode* code, bool match_only)
|
|||
}
|
||||
|
||||
void
|
||||
MarkScript(const js::jit::JitCode* code, const JSScript* script, const char* module)
|
||||
MarkScript(const js::jit::JitCode* code, JSScript* script, const char* module)
|
||||
{
|
||||
if (!IsProfilingActive())
|
||||
return;
|
||||
|
|
|
@ -33,7 +33,7 @@ void MarkStub(const js::jit::JitCode* code, const char* name);
|
|||
void MarkRegExp(const js::jit::JitCode* code, bool match_only);
|
||||
|
||||
void MarkScript(const js::jit::JitCode* code,
|
||||
const JSScript* script,
|
||||
JSScript* script,
|
||||
const char* module);
|
||||
|
||||
void MarkWasm(unsigned methodId,
|
||||
|
|
Загрузка…
Ссылка в новой задаче