From 3262a82616c97393b650889244d3b3f7fd6b311b Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Tue, 18 Jan 2022 12:48:26 +0000 Subject: [PATCH] Bug 1746382 - Remove static string lookup from stencil instantiation. r=tcampbell Differential Revision: https://phabricator.services.mozilla.com/D135099 --- js/src/frontend/ParserAtom.cpp | 8 +++--- js/src/vm/JSAtom.cpp | 45 ++++++++++++++++++++-------------- js/src/vm/JSAtom.h | 12 ++++----- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/js/src/frontend/ParserAtom.cpp b/js/src/frontend/ParserAtom.cpp index 3fb11f4c2be7..2e76d7c60cfb 100644 --- a/js/src/frontend/ParserAtom.cpp +++ b/js/src/frontend/ParserAtom.cpp @@ -138,9 +138,9 @@ JSAtom* ParserAtom::instantiateAtom(JSContext* cx, ParserAtomIndex index, JSAtom* atom; if (hasLatin1Chars()) { - atom = AtomizeChars(cx, hash(), latin1Chars(), length()); + atom = AtomizeCharsNonStatic(cx, hash(), latin1Chars(), length()); } else { - atom = AtomizeChars(cx, hash(), twoByteChars(), length()); + atom = AtomizeCharsNonStatic(cx, hash(), twoByteChars(), length()); } if (!atom) { return nullptr; @@ -157,8 +157,8 @@ JSAtom* ParserAtom::instantiatePermanentAtom( MOZ_ASSERT(!cx->zone()); MOZ_ASSERT(hasLatin1Chars()); - JSAtom* atom = - PermanentlyAtomizeChars(cx, atomSet, hash(), latin1Chars(), length()); + JSAtom* atom = PermanentlyAtomizeCharsNonStatic(cx, atomSet, hash(), + latin1Chars(), length()); if (!atom) { return nullptr; } diff --git a/js/src/vm/JSAtom.cpp b/js/src/vm/JSAtom.cpp index be1a76210c74..5142941a1ea3 100644 --- a/js/src/vm/JSAtom.cpp +++ b/js/src/vm/JSAtom.cpp @@ -193,6 +193,10 @@ MOZ_ALWAYS_INLINE AtomSet::Ptr js::FrozenAtomSet::readonlyThreadsafeLookup( return mSet->readonlyThreadsafeLookup(l); } +static JSAtom* PermanentlyAtomizeChars(JSContext* cx, AtomSet& atomSet, + mozilla::HashNumber hash, + const Latin1Char* chars, size_t length); + bool JSRuntime::initializeAtoms(JSContext* cx) { JS::AutoAssertNoGC nogc; @@ -261,7 +265,7 @@ bool JSRuntime::initializeAtoms(JSContext* cx) { } for (const auto& info : symbolDescInfo) { - JSAtom* atom = PermanentlyAtomizeChars( + JSAtom* atom = PermanentlyAtomizeCharsNonStatic( cx, *atomSet, info.hash, reinterpret_cast(info.content), info.length); if (!atom) { @@ -816,39 +820,42 @@ template JSAtom* js::AtomizeChars(JSContext* cx, const char16_t* chars, /* |chars| must not point into an inline or short string. */ template -JSAtom* js::AtomizeChars(JSContext* cx, HashNumber hash, const CharT* chars, - size_t length) { - if (JSAtom* s = cx->staticStrings().lookup(chars, length)) { - return s; - } +JSAtom* js::AtomizeCharsNonStatic(JSContext* cx, HashNumber hash, + const CharT* chars, size_t length) { + MOZ_ASSERT(!cx->staticStrings().lookup(chars, length)); AtomHasher::Lookup lookup(hash, chars, length); return AtomizeAndCopyCharsFromLookup(cx, chars, length, lookup, Nothing()); } -template JSAtom* js::AtomizeChars(JSContext* cx, HashNumber hash, - const Latin1Char* chars, size_t length); +template JSAtom* js::AtomizeCharsNonStatic(JSContext* cx, HashNumber hash, + const Latin1Char* chars, + size_t length); -template JSAtom* js::AtomizeChars(JSContext* cx, HashNumber hash, - const char16_t* chars, size_t length); +template JSAtom* js::AtomizeCharsNonStatic(JSContext* cx, HashNumber hash, + const char16_t* chars, + size_t length); -template -JSAtom* js::PermanentlyAtomizeChars(JSContext* cx, AtomSet& atomSet, - HashNumber hash, const CharT* chars, - size_t length) { +static JSAtom* PermanentlyAtomizeChars(JSContext* cx, AtomSet& atomSet, + HashNumber hash, const Latin1Char* chars, + size_t length) { if (JSAtom* s = cx->staticStrings().lookup(chars, length)) { return s; } + return PermanentlyAtomizeCharsNonStatic(cx, atomSet, hash, chars, length); +} + +JSAtom* js::PermanentlyAtomizeCharsNonStatic(JSContext* cx, AtomSet& atomSet, + HashNumber hash, + const Latin1Char* chars, + size_t length) { + MOZ_ASSERT(!cx->staticStrings().lookup(chars, length)); + AtomHasher::Lookup lookup(hash, chars, length); return PermanentlyAtomizeAndCopyChars(cx, atomSet, chars, length, lookup); } -template JSAtom* js::PermanentlyAtomizeChars(JSContext* cx, AtomSet& atomSet, - HashNumber hash, - const Latin1Char* chars, - size_t length); - JSAtom* js::AtomizeUTF8Chars(JSContext* cx, const char* utf8Chars, size_t utf8ByteLength) { { diff --git a/js/src/vm/JSAtom.h b/js/src/vm/JSAtom.h index 1536509ab607..4d160d1daf94 100644 --- a/js/src/vm/JSAtom.h +++ b/js/src/vm/JSAtom.h @@ -49,13 +49,13 @@ extern JSAtom* AtomizeChars(JSContext* cx, const CharT* chars, size_t length); /* Atomize characters when the value of HashString is already known. */ template -extern JSAtom* AtomizeChars(JSContext* cx, mozilla::HashNumber hash, - const CharT* chars, size_t length); +extern JSAtom* AtomizeCharsNonStatic(JSContext* cx, mozilla::HashNumber hash, + const CharT* chars, size_t length); -template -extern JSAtom* PermanentlyAtomizeChars(JSContext* cx, AtomSet& atomSet, - mozilla::HashNumber hash, - const CharT* chars, size_t length); +extern JSAtom* PermanentlyAtomizeCharsNonStatic(JSContext* cx, AtomSet& atomSet, + mozilla::HashNumber hash, + const Latin1Char* chars, + size_t length); /** * Create an atom whose contents are those of the |utf8ByteLength| code units