Bug 1548510 part 1 - Remove unnecessary GeckoProfilerRuntime::strings lock. r=jonco

This lock was necessary when the JITs used these strings (off-thread Ion compilation),
but now the lock was just adding overhead to each script we finalize etc.

This replaces ExclusiveData<> with MainThreadData<> to assert on-main-thread in debug
builds.

Differential Revision: https://phabricator.services.mozilla.com/D29798

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan de Mooij 2019-05-03 10:11:16 +00:00
Родитель f5ae35ca10
Коммит 48c9eed618
2 изменённых файлов: 14 добавлений и 19 удалений

Просмотреть файл

@ -34,7 +34,7 @@ GeckoProfilerThread::GeckoProfilerThread()
GeckoProfilerRuntime::GeckoProfilerRuntime(JSRuntime* rt)
: rt(rt),
strings(mutexid::GeckoProfilerStrings),
strings_(),
slowAssertions(false),
enabled_(false),
eventMarker_(nullptr) {
@ -154,13 +154,11 @@ void GeckoProfilerRuntime::enable(bool enabled) {
/* Lookup the string for the function/script, creating one if necessary */
const char* GeckoProfilerRuntime::profileString(JSScript* script,
JSFunction* maybeFun) {
auto locked = strings.lock();
ProfileStringMap::AddPtr s = locked->lookupForAdd(script);
ProfileStringMap::AddPtr s = strings().lookupForAdd(script);
if (!s) {
auto str = allocProfileString(script, maybeFun);
if (!str || !locked->add(s, script, std::move(str))) {
if (!str || !strings().add(s, script, std::move(str))) {
return nullptr;
}
}
@ -176,9 +174,8 @@ void GeckoProfilerRuntime::onScriptFinalized(JSScript* script) {
* off, we still want to remove the string, so no check of enabled() is
* done.
*/
auto locked = strings.lock();
if (ProfileStringMap::Ptr entry = locked->lookup(script)) {
locked->remove(entry);
if (ProfileStringMap::Ptr entry = strings().lookup(script)) {
strings().remove(entry);
}
}
@ -331,8 +328,7 @@ void GeckoProfilerThread::trace(JSTracer* trc) {
}
void GeckoProfilerRuntime::fixupStringsMapAfterMovingGC() {
auto locked = strings.lock();
for (ProfileStringMap::Enum e(locked.get()); !e.empty(); e.popFront()) {
for (ProfileStringMap::Enum e(strings()); !e.empty(); e.popFront()) {
JSScript* script = e.front().key();
if (IsForwarded(script)) {
script = Forwarded(script);
@ -343,11 +339,10 @@ void GeckoProfilerRuntime::fixupStringsMapAfterMovingGC() {
#ifdef JSGC_HASH_TABLE_CHECKS
void GeckoProfilerRuntime::checkStringsMapAfterMovingGC() {
auto locked = strings.lock();
for (auto r = locked->all(); !r.empty(); r.popFront()) {
for (auto r = strings().all(); !r.empty(); r.popFront()) {
JSScript* script = r.front().key();
CheckGCThingAfterMovingGC(script);
auto ptr = locked->lookup(script);
auto ptr = strings().lookup(script);
MOZ_RELEASE_ASSERT(ptr.found() && &*ptr == &r.front());
}
}

Просмотреть файл

@ -13,7 +13,7 @@
#include <stddef.h>
#include "js/ProfilingStack.h"
#include "threading/ExclusiveData.h"
#include "threading/ProtectedData.h"
#include "vm/JSScript.h"
#include "vm/MutexIDs.h"
@ -109,7 +109,7 @@ using ProfileStringMap = HashMap<JSScript*, UniqueChars,
class GeckoProfilerRuntime {
JSRuntime* rt;
ExclusiveData<ProfileStringMap> strings;
MainThreadData<ProfileStringMap> strings_;
bool slowAssertions;
uint32_t enabled_;
void (*eventMarker_)(const char*);
@ -131,6 +131,8 @@ class GeckoProfilerRuntime {
void markEvent(const char* event);
ProfileStringMap& strings() { return strings_.ref(); }
/* meant to be used for testing, not recommended to call in normal code */
size_t stringsCount();
void stringsReset();
@ -143,11 +145,9 @@ class GeckoProfilerRuntime {
#endif
};
inline size_t GeckoProfilerRuntime::stringsCount() {
return strings.lock()->count();
}
inline size_t GeckoProfilerRuntime::stringsCount() { return strings().count(); }
inline void GeckoProfilerRuntime::stringsReset() { strings.lock()->clear(); }
inline void GeckoProfilerRuntime::stringsReset() { strings().clear(); }
/*
* This class is used in RunScript() to push the marker onto the sampling stack