Bug 1743357 - Part 1: Add support for owned-borrow for CompilationStencil. r=nbp

Differential Revision: https://phabricator.services.mozilla.com/D132355
This commit is contained in:
Tooru Fujisawa 2021-11-30 16:09:25 +00:00
Родитель b87567e7b1
Коммит bbd2a9d7d8
3 изменённых файлов: 114 добавлений и 29 удалений

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

@ -997,8 +997,14 @@ struct CompilationStencil {
// See: JS::StencilAddRef/Release
mutable mozilla::Atomic<uintptr_t> refCount{0};
private:
// On-heap ExtensibleCompilationStencil that this CompilationStencil owns,
// and this CompilationStencil borrows each data from.
UniquePtr<ExtensibleCompilationStencil> ownedBorrowStencil;
public:
// Set to true if any pointer/span contains external data instead of
// LifoAlloc or owned memory.
// LifoAlloc or owned ExtensibleCompilationStencil.
bool hasExternalDependency = false;
// Value of CanLazilyParse(CompilationInput) on compilation.
@ -1067,6 +1073,21 @@ struct CompilationStencil {
explicit CompilationStencil(ScriptSource* source)
: alloc(LifoAllocChunkSize), source(source) {}
// Take the ownership of on-heap ExtensibleCompilationStencil and
// borrow from it.
explicit CompilationStencil(
UniquePtr<ExtensibleCompilationStencil>&& extensibleStencil);
protected:
void borrowFromExtensibleCompilationStencil(
ExtensibleCompilationStencil& extensibleStencil);
#ifdef DEBUG
void assertBorrowingFromExtensibleCompilationStencil(
const ExtensibleCompilationStencil& extensibleStencil) const;
#endif
public:
static FunctionKey toFunctionKey(const SourceExtent& extent) {
// In eval("x=>1"), the arrow function will have a sourceStart of 0 which
// conflicts with the NullFunctionKey, so shift all keys by 1 instead.
@ -1358,6 +1379,10 @@ class MOZ_STACK_CLASS BorrowingCompilationStencil : public CompilationStencil {
// LifoAlloc) and RefPtrs since we are not the unique owner.
inline size_t CompilationStencil::sizeOfExcludingThis(
mozilla::MallocSizeOf mallocSizeOf) const {
if (ownedBorrowStencil) {
return ownedBorrowStencil->sizeOfIncludingThis(mallocSizeOf);
}
size_t moduleMetadataSize =
moduleMetadata ? moduleMetadata->sizeOfIncludingThis(mallocSizeOf) : 0;
size_t asmJSSize = asmJS ? asmJS->sizeOfIncludingThis(mallocSizeOf) : 0;

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

@ -51,7 +51,6 @@ namespace frontend {
struct CompilationAtomCache;
struct CompilationStencil;
class BorrowingCompilationStencil;
template <typename CharT>
class SpecificParserAtomLookup;
@ -619,7 +618,7 @@ bool InstantiateMarkedAtoms(JSContext* cx, const ParserAtomSpan& entries,
* associated with a given compile session.
*/
class ParserAtomsTable {
friend class BorrowingCompilationStencil;
friend struct CompilationStencil;
private:
const WellKnownParserAtoms& wellKnownTable_;

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

@ -1829,6 +1829,85 @@ static void FunctionsFromExistingLazy(CompilationInput& input,
}
}
void CompilationStencil::borrowFromExtensibleCompilationStencil(
ExtensibleCompilationStencil& extensibleStencil) {
canLazilyParse = extensibleStencil.canLazilyParse;
functionKey = extensibleStencil.functionKey;
// Borrow the vector content as span.
scriptData = extensibleStencil.scriptData;
scriptExtra = extensibleStencil.scriptExtra;
gcThingData = extensibleStencil.gcThingData;
scopeData = extensibleStencil.scopeData;
scopeNames = extensibleStencil.scopeNames;
regExpData = extensibleStencil.regExpData;
bigIntData = extensibleStencil.bigIntData;
objLiteralData = extensibleStencil.objLiteralData;
// Borrow the parser atoms as span.
parserAtomData = extensibleStencil.parserAtoms.entries_;
// Borrow container.
sharedData.setBorrow(&extensibleStencil.sharedData);
// Share ref-counted data.
source = extensibleStencil.source;
asmJS = extensibleStencil.asmJS;
moduleMetadata = extensibleStencil.moduleMetadata;
}
#ifdef DEBUG
template <typename SpanT, typename VecT>
void AssertBorrowingSpan(const SpanT& span, const VecT& vec) {
MOZ_ASSERT(span.size() == vec.length());
MOZ_ASSERT(span.data() == vec.begin());
}
void CompilationStencil::assertBorrowingFromExtensibleCompilationStencil(
const ExtensibleCompilationStencil& extensibleStencil) const {
MOZ_ASSERT(canLazilyParse == extensibleStencil.canLazilyParse);
MOZ_ASSERT(functionKey == extensibleStencil.functionKey);
AssertBorrowingSpan(scriptData, extensibleStencil.scriptData);
AssertBorrowingSpan(scriptExtra, extensibleStencil.scriptExtra);
AssertBorrowingSpan(gcThingData, extensibleStencil.gcThingData);
AssertBorrowingSpan(scopeData, extensibleStencil.scopeData);
AssertBorrowingSpan(scopeNames, extensibleStencil.scopeNames);
AssertBorrowingSpan(regExpData, extensibleStencil.regExpData);
AssertBorrowingSpan(bigIntData, extensibleStencil.bigIntData);
AssertBorrowingSpan(objLiteralData, extensibleStencil.objLiteralData);
AssertBorrowingSpan(parserAtomData, extensibleStencil.parserAtoms.entries_);
MOZ_ASSERT(sharedData.isBorrow());
MOZ_ASSERT(sharedData.asBorrow() == &extensibleStencil.sharedData);
MOZ_ASSERT(source == extensibleStencil.source);
MOZ_ASSERT(asmJS == extensibleStencil.asmJS);
MOZ_ASSERT(moduleMetadata == extensibleStencil.moduleMetadata);
}
#endif
CompilationStencil::CompilationStencil(
UniquePtr<ExtensibleCompilationStencil>&& extensibleStencil)
: alloc(LifoAllocChunkSize) {
ownedBorrowStencil = std::move(extensibleStencil);
hasExternalDependency = false;
borrowFromExtensibleCompilationStencil(*ownedBorrowStencil);
#ifdef DEBUG
assertNoExternalDependency();
#endif
}
/* static */
bool CompilationStencil::instantiateStencils(JSContext* cx,
CompilationInput& input,
@ -2210,32 +2289,7 @@ BorrowingCompilationStencil::BorrowingCompilationStencil(
: CompilationStencil(extensibleStencil.source) {
hasExternalDependency = true;
canLazilyParse = extensibleStencil.canLazilyParse;
functionKey = extensibleStencil.functionKey;
// Borrow the vector content as span.
scriptData = extensibleStencil.scriptData;
scriptExtra = extensibleStencil.scriptExtra;
gcThingData = extensibleStencil.gcThingData;
scopeData = extensibleStencil.scopeData;
scopeNames = extensibleStencil.scopeNames;
regExpData = extensibleStencil.regExpData;
bigIntData = extensibleStencil.bigIntData;
objLiteralData = extensibleStencil.objLiteralData;
// Borrow the parser atoms as span.
parserAtomData = extensibleStencil.parserAtoms.entries_;
// Borrow container.
sharedData.setBorrow(&extensibleStencil.sharedData);
// Share ref-counted data.
source = extensibleStencil.source;
asmJS = extensibleStencil.asmJS;
moduleMetadata = extensibleStencil.moduleMetadata;
borrowFromExtensibleCompilationStencil(extensibleStencil);
}
SharedDataContainer::~SharedDataContainer() {
@ -2422,6 +2476,13 @@ bool SharedDataContainer::addExtraWithoutShare(
#ifdef DEBUG
void CompilationStencil::assertNoExternalDependency() const {
if (ownedBorrowStencil) {
ownedBorrowStencil->assertNoExternalDependency();
assertBorrowingFromExtensibleCompilationStencil(*ownedBorrowStencil);
return;
}
MOZ_ASSERT_IF(!scriptData.empty(), alloc.contains(scriptData.data()));
MOZ_ASSERT_IF(!scriptExtra.empty(), alloc.contains(scriptExtra.data()));