Skip to content

Commit

Permalink
Backed out 5 changesets (bug 1797024, bug 1786834) for causing build …
Browse files Browse the repository at this point in the history
…bustages on ParserAtom.cpp. CLOSED TREE

Backed out changeset ea88488b0626 (bug 1797024)
Backed out changeset c4fcaed9709c (bug 1797024)
Backed out changeset 149d939edcea (bug 1797024)
Backed out changeset 3280c912570a (bug 1786834)
Backed out changeset ba594d0b12b0 (bug 1786834)
  • Loading branch information
Stanca Serban committed Nov 11, 2022
1 parent fb79183 commit 1296645
Show file tree
Hide file tree
Showing 23 changed files with 265 additions and 224 deletions.
2 changes: 1 addition & 1 deletion js/src/builtin/TestingUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ bool js::SetSourceOptions(JSContext* cx, ErrorContext* ec, ScriptSource* source,
if (!chars) {
return false;
}
if (!source->setSourceMapURL(ec, std::move(chars))) {
if (!source->setSourceMapURL(cx, ec, std::move(chars))) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/src/debugger/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ bool DebuggerSource::CallData::setSourceMapURL() {
}

AutoReportFrontendContext ec(cx);
if (!ss->setSourceMapURL(&ec, std::move(chars))) {
if (!ss->setSourceMapURL(cx, &ec, std::move(chars))) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions js/src/frontend/BytecodeCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class MOZ_STACK_CLASS ScriptCompiler : public SourceAwareCompiler<Unit> {
return true;
}

return stencilOut->source->assignSource(ec, input.options, srcBuf);
return stencilOut->source->assignSource(cx, ec, input.options, srcBuf);
}

[[nodiscard]] static bool TrySmoosh(
Expand Down Expand Up @@ -634,7 +634,7 @@ bool SourceAwareCompiler<Unit>::createSourceAndParser(JSContext* cx,

errorContext = ec;

if (!compilationState_.source->assignSource(ec, options, sourceBuffer_)) {
if (!compilationState_.source->assignSource(cx, ec, options, sourceBuffer_)) {
return false;
}

Expand Down Expand Up @@ -1132,7 +1132,7 @@ static GetCachedResult GetCachedLazyFunctionStencilMaybeInstantiate(
}

if (output.is<UniquePtr<ExtensibleCompilationStencil>>()) {
auto extensible = cx->make_unique<ExtensibleCompilationStencil>(input);
auto extensible = cx->make_unique<ExtensibleCompilationStencil>(cx, input);
if (!extensible) {
return GetCachedResult::Error;
}
Expand Down
7 changes: 4 additions & 3 deletions js/src/frontend/CompilationStencil.h
Original file line number Diff line number Diff line change
Expand Up @@ -1282,10 +1282,11 @@ struct ExtensibleCompilationStencil {

RefPtr<StencilAsmJSContainer> asmJS;

explicit ExtensibleCompilationStencil(ScriptSource* source);
explicit ExtensibleCompilationStencil(JSContext* cx, ScriptSource* source);

explicit ExtensibleCompilationStencil(CompilationInput& input);
ExtensibleCompilationStencil(const JS::ReadOnlyCompileOptions& options,
ExtensibleCompilationStencil(JSContext* cx, CompilationInput& input);
ExtensibleCompilationStencil(JSContext* cx,
const JS::ReadOnlyCompileOptions& options,
RefPtr<ScriptSource> source);

ExtensibleCompilationStencil(ExtensibleCompilationStencil&& other) noexcept
Expand Down
90 changes: 33 additions & 57 deletions js/src/frontend/ParserAtom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#include "util/Text.h" // AsciiDigitToNumber
#include "util/Unicode.h"
#include "vm/JSContext.h"
#include "vm/MutexIDs.h" // mutexid
#include "vm/Printer.h" // Sprinter, QuoteString
#include "vm/Printer.h" // Sprinter, QuoteString
#include "vm/Runtime.h"
#include "vm/SelfHosting.h" // ExtendedUnclonedSelfHostedFunctionNamePrefix
#include "vm/StaticStrings.h"
Expand Down Expand Up @@ -326,7 +325,8 @@ void ParserAtomsTable::dumpCharsNoQuote(js::GenericPrinter& out,
}
#endif

ParserAtomsTable::ParserAtomsTable(LifoAlloc& alloc) : alloc_(&alloc) {}
ParserAtomsTable::ParserAtomsTable(JSRuntime* rt, LifoAlloc& alloc)
: wellKnownTable_(*rt->commonParserNames), alloc_(&alloc) {}

TaggedParserAtomIndex ParserAtomsTable::addEntry(ErrorContext* ec,
EntryMap::AddPtr& addPtr,
Expand Down Expand Up @@ -376,15 +376,14 @@ TaggedParserAtomIndex ParserAtomsTable::internAscii(ErrorContext* ec,
TaggedParserAtomIndex ParserAtomsTable::internLatin1(
ErrorContext* ec, const Latin1Char* latin1Ptr, uint32_t length) {
// Check for tiny strings which are abundant in minified code.
if (auto tiny = WellKnownParserAtoms::getSingleton().lookupTinyIndex(
latin1Ptr, length)) {
if (auto tiny = wellKnownTable_.lookupTinyIndex(latin1Ptr, length)) {
return tiny;
}

// Check for well-known atom.
InflatedChar16Sequence<Latin1Char> seq(latin1Ptr, length);
SpecificParserAtomLookup<Latin1Char> lookup(seq);
if (auto wk = WellKnownParserAtoms::getSingleton().lookupChar16Seq(lookup)) {
if (auto wk = wellKnownTable_.lookupChar16Seq(lookup)) {
return wk;
}

Expand Down Expand Up @@ -542,8 +541,7 @@ static inline bool IsLatin1(mozilla::Utf8Unit c1, mozilla::Utf8Unit c2) {

TaggedParserAtomIndex ParserAtomsTable::internUtf8(
ErrorContext* ec, const mozilla::Utf8Unit* utf8Ptr, uint32_t nbyte) {
if (auto tiny = WellKnownParserAtoms::getSingleton().lookupTinyIndexUTF8(
utf8Ptr, nbyte)) {
if (auto tiny = wellKnownTable_.lookupTinyIndexUTF8(utf8Ptr, nbyte)) {
return tiny;
}

Expand All @@ -564,7 +562,7 @@ TaggedParserAtomIndex ParserAtomsTable::internUtf8(
// NOTE: Well-known are all ASCII so have been handled above.
InflatedChar16Sequence<mozilla::Utf8Unit> seq(utf8Ptr, nbyte);
SpecificParserAtomLookup<mozilla::Utf8Unit> lookup(seq);
MOZ_ASSERT(!WellKnownParserAtoms::getSingleton().lookupChar16Seq(lookup));
MOZ_ASSERT(!wellKnownTable_.lookupChar16Seq(lookup));
EntryMap::AddPtr addPtr = entryMap_.lookupForAdd(lookup);
if (addPtr) {
return addPtr->value();
Expand All @@ -590,15 +588,14 @@ TaggedParserAtomIndex ParserAtomsTable::internChar16(ErrorContext* ec,
const char16_t* char16Ptr,
uint32_t length) {
// Check for tiny strings which are abundant in minified code.
if (auto tiny = WellKnownParserAtoms::getSingleton().lookupTinyIndex(
char16Ptr, length)) {
if (auto tiny = wellKnownTable_.lookupTinyIndex(char16Ptr, length)) {
return tiny;
}

// Check against well-known.
InflatedChar16Sequence<char16_t> seq(char16Ptr, length);
SpecificParserAtomLookup<char16_t> lookup(seq);
if (auto wk = WellKnownParserAtoms::getSingleton().lookupChar16Seq(lookup)) {
if (auto wk = wellKnownTable_.lookupChar16Seq(lookup)) {
return wk;
}

Expand Down Expand Up @@ -1211,16 +1208,6 @@ bool InstantiateMarkedAtomsAsPermanent(JSContext* cx, ErrorContext* ec,
return true;
}

/* static */
WellKnownParserAtoms WellKnownParserAtoms::singleton_;

WellKnownParserAtoms::WellKnownParserAtoms()
#ifdef DEBUG
: initLock_(mutexid::WellKnownParserAtomsInit)
#endif
{
}

template <typename CharT>
TaggedParserAtomIndex WellKnownParserAtoms::lookupChar16Seq(
const SpecificParserAtomLookup<CharT>& lookup) const {
Expand Down Expand Up @@ -1251,7 +1238,8 @@ TaggedParserAtomIndex WellKnownParserAtoms::lookupTinyIndexUTF8(
return lookupTinyIndex(reinterpret_cast<const Latin1Char*>(utf8Ptr), nbyte);
}

bool WellKnownParserAtoms::initSingle(const WellKnownAtomInfo& info,
bool WellKnownParserAtoms::initSingle(JSContext* cx,
const WellKnownAtomInfo& info,
TaggedParserAtomIndex index) {
unsigned int len = info.length;
const Latin1Char* str = reinterpret_cast<const Latin1Char*>(info.content);
Expand All @@ -1271,76 +1259,64 @@ bool WellKnownParserAtoms::initSingle(const WellKnownAtomInfo& info,

// Save name for returning after moving entry into set.
if (!wellKnownMap_.putNew(lookup, &info, index)) {
js::ReportOutOfMemory(cx);
return false;
}

return true;
}

bool WellKnownParserAtoms::init() {
#ifdef DEBUG
LockGuard<Mutex> guard(initLock_);
MOZ_ASSERT(!initialized_);
initialized_ = true;
#endif
MOZ_ASSERT(wellKnownMap_.empty());

bool WellKnownParserAtoms::init(JSContext* cx) {
// Add well-known strings to the HashMap. The HashMap is used for dynamic
// lookups later and does not change once this init method is complete.
#define COMMON_NAME_INIT_(_, NAME, _2) \
if (!initSingle(GetWellKnownAtomInfo(WellKnownAtomId::NAME), \
TaggedParserAtomIndex::WellKnown::NAME())) { \
return false; \
#define COMMON_NAME_INIT_(_, NAME, _2) \
if (!initSingle(cx, GetWellKnownAtomInfo(WellKnownAtomId::NAME), \
TaggedParserAtomIndex::WellKnown::NAME())) { \
return false; \
}
FOR_EACH_NONTINY_COMMON_PROPERTYNAME(COMMON_NAME_INIT_)
#undef COMMON_NAME_INIT_
#define COMMON_NAME_INIT_(NAME, _) \
if (!initSingle(GetWellKnownAtomInfo(WellKnownAtomId::NAME), \
TaggedParserAtomIndex::WellKnown::NAME())) { \
return false; \
#define COMMON_NAME_INIT_(NAME, _) \
if (!initSingle(cx, GetWellKnownAtomInfo(WellKnownAtomId::NAME), \
TaggedParserAtomIndex::WellKnown::NAME())) { \
return false; \
}
JS_FOR_EACH_PROTOTYPE(COMMON_NAME_INIT_)
#undef COMMON_NAME_INIT_
#define COMMON_NAME_INIT_(NAME) \
if (!initSingle(GetWellKnownAtomInfo(WellKnownAtomId::NAME), \
TaggedParserAtomIndex::WellKnown::NAME())) { \
return false; \
#define COMMON_NAME_INIT_(NAME) \
if (!initSingle(cx, GetWellKnownAtomInfo(WellKnownAtomId::NAME), \
TaggedParserAtomIndex::WellKnown::NAME())) { \
return false; \
}
JS_FOR_EACH_WELL_KNOWN_SYMBOL(COMMON_NAME_INIT_)
#undef COMMON_NAME_INIT_

return true;
}

void WellKnownParserAtoms::free() {
initialized_ = false;
wellKnownMap_.clear();
}

/* static */ bool WellKnownParserAtoms::initSingleton() {
return singleton_.init();
}

/* static */ void WellKnownParserAtoms::freeSingleton() { singleton_.free(); }

} /* namespace frontend */
} /* namespace js */

bool JSRuntime::initializeParserAtoms(JSContext* cx) {
MOZ_ASSERT(!commonParserNames);

if (parentRuntime) {
commonParserNames = parentRuntime->commonParserNames;
return true;
}

if (!js::frontend::WellKnownParserAtoms::initSingleton()) {
js::ReportOutOfMemory(cx);
UniquePtr<js::frontend::WellKnownParserAtoms> names(
js_new<js::frontend::WellKnownParserAtoms>());
if (!names || !names->init(cx)) {
return false;
}

commonParserNames = names.release();
return true;
}

void JSRuntime::finishParserAtoms() {
if (!parentRuntime) {
js::frontend::WellKnownParserAtoms::freeSingleton();
js_delete(commonParserNames.ref());
}
}
30 changes: 8 additions & 22 deletions js/src/frontend/ParserAtom.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
#include "js/TypeDecls.h" // Latin1Char
#include "js/Utility.h" // UniqueChars
#include "js/Vector.h" // Vector
#include "threading/Mutex.h" // Mutex
#include "util/Text.h" // InflatedChar16Sequence
#include "vm/CommonPropertyNames.h"
#include "vm/StaticStrings.h"
#include "vm/WellKnownAtom.h" // WellKnownAtomId, WellKnownAtomInfo

struct JS_PUBLIC_API JSContext;
struct JSRuntime;

class JSAtom;
class JSString;
Expand Down Expand Up @@ -572,34 +572,18 @@ using ParserAtomSpan = mozilla::Span<ParserAtom*>;
* constant time.
*/
class WellKnownParserAtoms {
static WellKnownParserAtoms singleton_;

#ifdef DEBUG
js::Mutex initLock_ MOZ_UNANNOTATED;
bool initialized_ = false;
#endif

WellKnownParserAtoms();

public:
// Common property and prototype names are tracked in a hash table. This table
// does not key for any items already in a direct-indexing tiny atom table.
using EntryMap = HashMap<const WellKnownAtomInfo*, TaggedParserAtomIndex,
WellKnownAtomInfoHasher, js::SystemAllocPolicy>;
EntryMap wellKnownMap_;

bool initSingle(const WellKnownAtomInfo& info, TaggedParserAtomIndex index);

bool init();
void free();
bool initSingle(JSContext* cx, const WellKnownAtomInfo& info,
TaggedParserAtomIndex index);

public:
static bool initSingleton();
static void freeSingleton();

static WellKnownParserAtoms& getSingleton() {
MOZ_ASSERT(!singleton_.wellKnownMap_.empty());
return singleton_;
}
bool init(JSContext* cx);

// Maximum length of any well known atoms. This can be increased if needed.
static constexpr size_t MaxWellKnownLength = 32;
Expand Down Expand Up @@ -675,6 +659,8 @@ class ParserAtomsTable {
friend struct CompilationStencil;

private:
const WellKnownParserAtoms& wellKnownTable_;

LifoAlloc* alloc_;

// The ParserAtom are owned by the LifoAlloc.
Expand All @@ -684,7 +670,7 @@ class ParserAtomsTable {
ParserAtomVector entries_;

public:
explicit ParserAtomsTable(LifoAlloc& alloc);
ParserAtomsTable(JSRuntime* rt, LifoAlloc& alloc);
ParserAtomsTable(ParserAtomsTable&&) = default;
ParserAtomsTable& operator=(ParserAtomsTable&& other) noexcept {
entryMap_ = std::move(other.entryMap_);
Expand Down
16 changes: 9 additions & 7 deletions js/src/frontend/Stencil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2760,29 +2760,31 @@ bool CompilationStencil::deserializeStencils(JSContext* cx, ErrorContext* ec,
return true;
}

ExtensibleCompilationStencil::ExtensibleCompilationStencil(ScriptSource* source)
ExtensibleCompilationStencil::ExtensibleCompilationStencil(JSContext* cx,
ScriptSource* source)
: alloc(CompilationStencil::LifoAllocChunkSize),
source(source),
parserAtoms(alloc) {}
parserAtoms(cx->runtime(), alloc) {}

ExtensibleCompilationStencil::ExtensibleCompilationStencil(
CompilationInput& input)
JSContext* cx, CompilationInput& input)
: canLazilyParse(CanLazilyParse(input.options)),
alloc(CompilationStencil::LifoAllocChunkSize),
source(input.source),
parserAtoms(alloc) {}
parserAtoms(cx->runtime(), alloc) {}

ExtensibleCompilationStencil::ExtensibleCompilationStencil(
const JS::ReadOnlyCompileOptions& options, RefPtr<ScriptSource> source)
JSContext* cx, const JS::ReadOnlyCompileOptions& options,
RefPtr<ScriptSource> source)
: canLazilyParse(CanLazilyParse(options)),
alloc(CompilationStencil::LifoAllocChunkSize),
source(std::move(source)),
parserAtoms(alloc) {}
parserAtoms(cx->runtime(), alloc) {}

CompilationState::CompilationState(JSContext* cx,
LifoAllocScope& parserAllocScope,
CompilationInput& input)
: ExtensibleCompilationStencil(input),
: ExtensibleCompilationStencil(cx, input),
directives(input.options.forceStrictMode()),
usedNames(cx),
parserAllocScope(parserAllocScope),
Expand Down
4 changes: 2 additions & 2 deletions js/src/frontend/StencilXdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ XDRResult StencilXDR::codeSource(XDRState<mode>* xdr,
}
MOZ_TRY(xdr->codeCharsZ(chars));
if (mode == XDR_DECODE) {
if (!source->setFilename(ec, std::move(chars.ref<UniqueChars>()))) {
if (!source->setFilename(cx, ec, std::move(chars.ref<UniqueChars>()))) {
return xdr->fail(JS::TranscodeResult::Throw);
}
}
Expand Down Expand Up @@ -1268,7 +1268,7 @@ XDRResult StencilXDR::codeSource(XDRState<mode>* xdr,
MOZ_TRY(xdr->codeCharsZ(chars));
if (mode == XDR_DECODE) {
if (!source->setSourceMapURL(
ec, std::move(chars.ref<UniqueTwoByteChars>()))) {
cx, ec, std::move(chars.ref<UniqueTwoByteChars>()))) {
return xdr->fail(JS::TranscodeResult::Throw);
}
}
Expand Down
Loading

0 comments on commit 1296645

Please sign in to comment.