зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1638470 - Remove the RuntimeScriptData::atoms array. r=mgaudet
This is now unused so strip out the code for it. Also remove the relavent code from Stencil. Depends on D75644 Differential Revision: https://phabricator.services.mozilla.com/D75645
This commit is contained in:
Родитель
13a54a78a3
Коммит
9443c95639
|
@ -16,14 +16,12 @@ using namespace js::frontend;
|
|||
|
||||
BCEScriptStencil::BCEScriptStencil(BytecodeEmitter& bce,
|
||||
UniquePtr<ImmutableScriptData> immutableData)
|
||||
: ScriptStencil(bce.cx), bce_(bce) {
|
||||
: ScriptStencil(bce.cx) {
|
||||
init(bce, std::move(immutableData));
|
||||
}
|
||||
|
||||
void BCEScriptStencil::init(BytecodeEmitter& bce,
|
||||
UniquePtr<ImmutableScriptData> immutableData) {
|
||||
natoms = 0;
|
||||
|
||||
immutableFlags = bce.sc->immutableFlags();
|
||||
|
||||
MOZ_ASSERT(bce.outermostScope().hasOnChain(ScopeKind::NonSyntactic) ==
|
||||
|
@ -54,5 +52,3 @@ void BCEScriptStencil::init(BytecodeEmitter& bce,
|
|||
}
|
||||
} /* isFunctionBox */
|
||||
}
|
||||
|
||||
void BCEScriptStencil::initAtomMap(GCPtrAtom* atoms) const {}
|
||||
|
|
|
@ -21,15 +21,11 @@ namespace js::frontend {
|
|||
struct BytecodeEmitter;
|
||||
|
||||
class BCEScriptStencil : public ScriptStencil {
|
||||
BytecodeEmitter& bce_;
|
||||
|
||||
void init(BytecodeEmitter& bce, UniquePtr<ImmutableScriptData> immutableData);
|
||||
|
||||
public:
|
||||
BCEScriptStencil(BytecodeEmitter& bce,
|
||||
UniquePtr<ImmutableScriptData> immutableData);
|
||||
|
||||
virtual void initAtomMap(GCPtrAtom* atoms) const override;
|
||||
};
|
||||
|
||||
} /* namespace js::frontend */
|
||||
|
|
|
@ -70,8 +70,6 @@ class SmooshScriptStencil : public ScriptStencil {
|
|||
|
||||
MOZ_MUST_USE bool init(JSContext* cx,
|
||||
UniquePtr<ImmutableScriptData> immutableData) {
|
||||
natoms = result_.atoms.len;
|
||||
|
||||
// A global script is a top-level context.
|
||||
bool isTopLevelContext = true;
|
||||
const JS::ReadOnlyCompileOptions& options = compilationInfo_.options;
|
||||
|
@ -127,13 +125,6 @@ class SmooshScriptStencil : public ScriptStencil {
|
|||
return true;
|
||||
}
|
||||
|
||||
virtual void initAtomMap(GCPtrAtom* atoms) const override {
|
||||
for (uint32_t i = 0; i < natoms; i++) {
|
||||
size_t index = result_.atoms.data[i];
|
||||
atoms[i] = allAtoms_[index];
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool createAtoms(JSContext* cx) {
|
||||
size_t numAtoms = result_.all_atoms_len;
|
||||
|
|
|
@ -353,7 +353,6 @@ class ScriptStencilBase {
|
|||
ScriptThingsVector gcThings;
|
||||
|
||||
// See `BaseScript::sharedData_`.
|
||||
uint32_t natoms = 0;
|
||||
js::UniquePtr<js::ImmutableScriptData> immutableScriptData = nullptr;
|
||||
|
||||
explicit ScriptStencilBase(JSContext* cx) : gcThings(cx) {}
|
||||
|
@ -378,10 +377,6 @@ class ScriptStencil : public ScriptStencilBase {
|
|||
// allocations within this stencil.
|
||||
JSScript* intoScript(JSContext* cx, CompilationInfo& compilationInfo,
|
||||
SourceExtent extent);
|
||||
|
||||
// Store all atoms into `atoms`
|
||||
// `atoms` is the pointer to `this.natoms`-length array of `GCPtrAtom`.
|
||||
virtual void initAtomMap(GCPtrAtom* atoms) const = 0;
|
||||
};
|
||||
|
||||
} /* namespace js::frontend */
|
||||
|
|
|
@ -1156,10 +1156,6 @@ void BaseScript::traceChildren(JSTracer* trc) {
|
|||
data_->trace(trc);
|
||||
}
|
||||
|
||||
if (sharedData_) {
|
||||
sharedData_->traceChildren(trc);
|
||||
}
|
||||
|
||||
// Scripts with bytecode may have optional data stored in per-runtime or
|
||||
// per-zone maps. Note that a failed compilation must not have entries since
|
||||
// the script itself will not be marked as having bytecode.
|
||||
|
|
|
@ -911,60 +911,24 @@ static XDRResult XDRImmutableScriptData(XDRState<mode>* xdr,
|
|||
return Ok();
|
||||
}
|
||||
|
||||
RuntimeScriptData::RuntimeScriptData(uint32_t natoms) : natoms_(natoms) {
|
||||
// Variable-length data begins immediately after RuntimeScriptData itself.
|
||||
Offset cursor = sizeof(RuntimeScriptData);
|
||||
|
||||
// Default-initialize trailing arrays.
|
||||
initElements<GCPtrAtom>(cursor, natoms);
|
||||
cursor += natoms * sizeof(GCPtrAtom);
|
||||
|
||||
// Check that we correctly recompute the expected values.
|
||||
MOZ_ASSERT(this->natoms() == natoms);
|
||||
|
||||
// Sanity check
|
||||
MOZ_ASSERT(endOffset() == cursor);
|
||||
}
|
||||
|
||||
template <XDRMode mode>
|
||||
/* static */
|
||||
XDRResult RuntimeScriptData::XDR(XDRState<mode>* xdr, HandleScript script) {
|
||||
uint32_t natoms = 0;
|
||||
|
||||
JSContext* cx = xdr->cx();
|
||||
RuntimeScriptData* rsd = nullptr;
|
||||
|
||||
if (mode == XDR_ENCODE) {
|
||||
rsd = script->sharedData();
|
||||
|
||||
natoms = rsd->natoms();
|
||||
}
|
||||
|
||||
MOZ_TRY(xdr->codeUint32(&natoms));
|
||||
|
||||
if (mode == XDR_DECODE) {
|
||||
if (!script->createScriptData(cx, natoms)) {
|
||||
if (!script->createScriptData(cx)) {
|
||||
return xdr->fail(JS::TranscodeResult_Throw);
|
||||
}
|
||||
|
||||
rsd = script->sharedData();
|
||||
}
|
||||
|
||||
{
|
||||
RootedAtom atom(cx);
|
||||
GCPtrAtom* vector = rsd->atoms();
|
||||
|
||||
for (uint32_t i = 0; i != natoms; ++i) {
|
||||
if (mode == XDR_ENCODE) {
|
||||
atom = vector[i];
|
||||
}
|
||||
MOZ_TRY(XDRAtom(xdr, &atom));
|
||||
if (mode == XDR_DECODE) {
|
||||
vector[i].init(atom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_TRY(XDRImmutableScriptData<mode>(xdr, rsd->isd_));
|
||||
|
||||
return Ok();
|
||||
|
@ -3968,36 +3932,10 @@ js::UniquePtr<ImmutableScriptData> js::ImmutableScriptData::new_(
|
|||
return result;
|
||||
}
|
||||
|
||||
RuntimeScriptData* js::RuntimeScriptData::new_(JSContext* cx, uint32_t natoms) {
|
||||
// Compute size including trailing arrays.
|
||||
CheckedInt<Offset> size = sizeof(RuntimeScriptData);
|
||||
size += CheckedInt<Offset>(natoms) * sizeof(GCPtrAtom);
|
||||
if (!size.isValid()) {
|
||||
ReportAllocationOverflow(cx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Allocate contiguous raw buffer
|
||||
void* raw = cx->pod_malloc<uint8_t>(size.value());
|
||||
MOZ_ASSERT(uintptr_t(raw) % alignof(RuntimeScriptData) == 0);
|
||||
if (!raw) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Constuct the RuntimeScriptData. Trailing arrays are uninitialized but
|
||||
// GCPtrs are put into a safe state.
|
||||
RuntimeScriptData* result = new (raw) RuntimeScriptData(natoms);
|
||||
|
||||
// Sanity check
|
||||
MOZ_ASSERT(result->endOffset() == size.value());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool JSScript::createScriptData(JSContext* cx, uint32_t natoms) {
|
||||
bool JSScript::createScriptData(JSContext* cx) {
|
||||
MOZ_ASSERT(!sharedData_);
|
||||
|
||||
RefPtr<RuntimeScriptData> rsd(RuntimeScriptData::new_(cx, natoms));
|
||||
RefPtr<RuntimeScriptData> rsd(cx->new_<RuntimeScriptData>());
|
||||
if (!rsd) {
|
||||
return false;
|
||||
}
|
||||
|
@ -4294,7 +4232,7 @@ bool JSScript::fullyInitFromStencil(JSContext* cx,
|
|||
});
|
||||
|
||||
/* The counts of indexed things must be checked during code generation. */
|
||||
MOZ_ASSERT(stencil.natoms <= INDEX_LIMIT);
|
||||
MOZ_ASSERT(stencil.gcThings.length() <= INDEX_LIMIT);
|
||||
|
||||
// Note: These flags should already be correct when the BaseScript was
|
||||
// allocated, except that lazy BinAST parsing has incomplete set of flags.
|
||||
|
@ -4871,11 +4809,7 @@ static JSScript* CopyScriptImpl(JSContext* cx, HandleScript src,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// The RuntimeScriptData can be reused by any zone in the Runtime as long as
|
||||
// we make sure to mark first (to sync Atom pointers).
|
||||
if (cx->zone() != src->zoneFromAnyThread()) {
|
||||
src->sharedData()->markForCrossZone(cx);
|
||||
}
|
||||
// The RuntimeScriptData can be reused by any zone in the Runtime.
|
||||
dst->initSharedData(src->sharedData());
|
||||
|
||||
return dst;
|
||||
|
@ -5041,32 +4975,14 @@ js::UniquePtr<ImmutableScriptData> ImmutableScriptData::new_(
|
|||
bool RuntimeScriptData::InitFromStencil(JSContext* cx, js::HandleScript script,
|
||||
frontend::ScriptStencil& stencil) {
|
||||
// Allocate RuntimeScriptData
|
||||
if (!script->createScriptData(cx, stencil.natoms)) {
|
||||
if (!script->createScriptData(cx)) {
|
||||
return false;
|
||||
}
|
||||
js::RuntimeScriptData* data = script->sharedData();
|
||||
|
||||
// Initialize trailing arrays
|
||||
stencil.initAtomMap(data->atoms());
|
||||
|
||||
script->initImmutableScriptData(std::move(stencil.immutableScriptData));
|
||||
return true;
|
||||
}
|
||||
|
||||
void RuntimeScriptData::traceChildren(JSTracer* trc) {
|
||||
MOZ_ASSERT(refCount() != 0);
|
||||
|
||||
for (uint32_t i = 0; i < natoms(); ++i) {
|
||||
TraceNullableEdge(trc, &atoms()[i], "atom");
|
||||
}
|
||||
}
|
||||
|
||||
void RuntimeScriptData::markForCrossZone(JSContext* cx) {
|
||||
for (uint32_t i = 0; i < natoms(); ++i) {
|
||||
cx->markAtom(atoms()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptWarmUpData::trace(JSTracer* trc) {
|
||||
uintptr_t tag = data_ & TagMask;
|
||||
switch (tag) {
|
||||
|
|
|
@ -1475,39 +1475,33 @@ class alignas(uintptr_t) PrivateScriptData final : public TrailingArray {
|
|||
PrivateScriptData& operator=(const PrivateScriptData&) = delete;
|
||||
};
|
||||
|
||||
// Script data that is shareable across a JSRuntime.
|
||||
class alignas(uintptr_t) RuntimeScriptData final : public TrailingArray {
|
||||
// Wrapper type for ImmutableScriptData to allow sharing across a JSRuntime.
|
||||
//
|
||||
// Note: This is distinct from ImmutableScriptData because it contains a mutable
|
||||
// ref-count while the ImmutableScriptData may live in read-only memory.
|
||||
//
|
||||
// Note: This is *not* directly inlined into the RuntimeScriptDataTable because
|
||||
// scripts point directly to object and table resizing moves entries. This
|
||||
// allows for fast finalization by decrementing the ref-count directly
|
||||
// without doing a hash-table lookup.
|
||||
class RuntimeScriptData {
|
||||
// This class is reference counted as follows: each pointer from a JSScript
|
||||
// counts as one reference plus there may be one reference from the shared
|
||||
// script data table.
|
||||
mozilla::Atomic<uint32_t, mozilla::SequentiallyConsistent> refCount_ = {};
|
||||
|
||||
uint32_t natoms_ = 0;
|
||||
|
||||
js::UniquePtr<ImmutableScriptData> isd_ = nullptr;
|
||||
|
||||
// NOTE: The raw bytes of this structure are used for hashing so use explicit
|
||||
// padding values as needed for predicatable results across compilers.
|
||||
// End of fields.
|
||||
|
||||
friend class ::JSScript;
|
||||
|
||||
private:
|
||||
// Layout helpers
|
||||
Offset atomsOffset() { return offsetOfAtoms(); }
|
||||
Offset endOffset() const {
|
||||
uintptr_t size = natoms_ * sizeof(GCPtrAtom);
|
||||
return offsetOfAtoms() + size;
|
||||
}
|
||||
|
||||
// Initialize to GC-safe state.
|
||||
explicit RuntimeScriptData(uint32_t natoms);
|
||||
|
||||
public:
|
||||
RuntimeScriptData() = default;
|
||||
|
||||
// Hash over the contents of RuntimeScriptData and its ImmutableScriptData.
|
||||
struct Hasher;
|
||||
|
||||
static RuntimeScriptData* new_(JSContext* cx, uint32_t natoms);
|
||||
|
||||
uint32_t refCount() const { return refCount_; }
|
||||
void AddRef() { refCount_++; }
|
||||
void Release() {
|
||||
|
@ -1519,32 +1513,14 @@ class alignas(uintptr_t) RuntimeScriptData final : public TrailingArray {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t natoms() const { return natoms_; }
|
||||
GCPtrAtom* atoms() {
|
||||
Offset offset = offsetOfAtoms();
|
||||
return offsetToPointer<GCPtrAtom>(offset);
|
||||
}
|
||||
|
||||
mozilla::Span<const GCPtrAtom> atomsSpan() const {
|
||||
Offset offset = offsetOfAtoms();
|
||||
return mozilla::MakeSpan(offsetToPointer<GCPtrAtom>(offset), natoms_);
|
||||
}
|
||||
|
||||
static constexpr size_t offsetOfAtoms() { return sizeof(RuntimeScriptData); }
|
||||
|
||||
static constexpr size_t offsetOfISD() {
|
||||
return offsetof(RuntimeScriptData, isd_);
|
||||
}
|
||||
|
||||
void traceChildren(JSTracer* trc);
|
||||
|
||||
template <XDRMode mode>
|
||||
static MOZ_MUST_USE XDRResult XDR(js::XDRState<mode>* xdr,
|
||||
js::HandleScript script);
|
||||
|
||||
// Mark this RuntimeScriptData for use in a new zone.
|
||||
void markForCrossZone(JSContext* cx);
|
||||
|
||||
static bool InitFromStencil(JSContext* cx, js::HandleScript script,
|
||||
js::frontend::ScriptStencil& stencil);
|
||||
|
||||
|
@ -1564,16 +1540,11 @@ struct RuntimeScriptData::Hasher {
|
|||
|
||||
static HashNumber hash(const Lookup& l) {
|
||||
mozilla::Span<const uint8_t> immutableData = l->isd_->immutableData();
|
||||
|
||||
HashNumber h =
|
||||
mozilla::HashBytes(immutableData.data(), immutableData.size());
|
||||
return mozilla::AddToHash(
|
||||
h, mozilla::HashBytes(l->atoms(), l->natoms() * sizeof(GCPtrAtom)));
|
||||
return mozilla::HashBytes(immutableData.data(), immutableData.size());
|
||||
}
|
||||
|
||||
static bool match(RuntimeScriptData* entry, const Lookup& lookup) {
|
||||
return (entry->atomsSpan() == lookup->atomsSpan()) &&
|
||||
(entry->isd_->immutableData() == lookup->isd_->immutableData());
|
||||
return (entry->isd_->immutableData() == lookup->isd_->immutableData());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2558,7 +2529,7 @@ class JSScript : public js::BaseScript {
|
|||
private:
|
||||
bool createJitScript(JSContext* cx);
|
||||
|
||||
bool createScriptData(JSContext* cx, uint32_t natoms);
|
||||
bool createScriptData(JSContext* cx);
|
||||
void initImmutableScriptData(js::UniquePtr<js::ImmutableScriptData>&& data) {
|
||||
MOZ_ASSERT(!sharedData_->isd_);
|
||||
sharedData_->isd_ = std::move(data);
|
||||
|
|
Загрузка…
Ссылка в новой задаче