usingnamespace js; usingnamespace js::wasm; using mozilla::CheckedInt;
Table::Table(JSContext* cx, const TableDesc& desc,
Handle<WasmTableObject*> maybeObject, FuncRefVector&& functions)
: maybeObject_(maybeObject),
observers_(cx->zone()),
functions_(std::move(functions)),
addressType_(desc.addressType()),
elemType_(desc.elemType()),
isAsmJS_(desc.isAsmJS),
length_(desc.initialLength()),
maximum_(desc.maximumLength()) { // Acquire a strong reference to the type definition this table may be // referencing.
elemType_.AddRef();
MOZ_ASSERT(repr() == TableRepr::Func);
MOZ_ASSERT(length_ <= MaxTableElemsRuntime);
}
Table::Table(JSContext* cx, const TableDesc& desc,
Handle<WasmTableObject*> maybeObject, TableAnyRefVector&& objects)
: maybeObject_(maybeObject),
observers_(cx->zone()),
objects_(std::move(objects)),
addressType_(desc.addressType()),
elemType_(desc.elemType()),
isAsmJS_(desc.isAsmJS),
length_(desc.initialLength()),
maximum_(desc.maximumLength()) { // Acquire a strong reference to the type definition this table may be // referencing.
elemType_.AddRef();
MOZ_ASSERT(repr() == TableRepr::Ref);
MOZ_ASSERT(length_ <= MaxTableElemsRuntime);
}
Table::~Table() { // Release the strong reference, if any.
elemType_.Release();
}
/* static */
SharedTable Table::create(JSContext* cx, const TableDesc& desc,
Handle<WasmTableObject*> maybeObject) { // Tables are initialized with init_expr values at Instance::init or // WasmTableObject::create.
switch (desc.elemType().tableRepr()) { case TableRepr::Func: {
FuncRefVector functions; if (!functions.resize(desc.initialLength())) {
ReportOutOfMemory(cx); return nullptr;
} return SharedTable(
cx->new_<Table>(cx, desc, maybeObject, std::move(functions)));
} case TableRepr::Ref: {
TableAnyRefVector objects; if (!objects.resize(desc.initialLength())) {
ReportOutOfMemory(cx); return nullptr;
} return SharedTable(
cx->new_<Table>(cx, desc, maybeObject, std::move(objects)));
}
}
MOZ_CRASH("switch is exhaustive");
}
void Table::tracePrivate(JSTracer* trc) { // If this table has a WasmTableObject, then this method is only called by // WasmTableObject's trace hook so maybeObject_ must already be marked. // TraceEdge is called so that the pointer can be updated during a moving // GC.
TraceEdge(trc, &maybeObject_, "wasm table object");
switch (repr()) { case TableRepr::Func: { if (isAsmJS_) { #ifdef DEBUG for (uint32_t i = 0; i < length_; i++) {
MOZ_ASSERT(!functions_[i].instance);
} #endif break;
}
for (uint32_t i = 0; i < length_; i++) { if (functions_[i].instance) {
wasm::TraceInstanceEdge(trc, functions_[i].instance, "wasm table instance");
} else {
MOZ_ASSERT(!functions_[i].code);
}
} break;
} case TableRepr::Ref: {
objects_.trace(trc); break;
}
}
}
void Table::trace(JSTracer* trc) { // The trace hook of WasmTableObject will call Table::tracePrivate at // which point we can mark the rest of the children. If there is no // WasmTableObject, call Table::tracePrivate directly. Redirecting through // the WasmTableObject avoids marking the entire Table on each incoming // edge (once per dependent Instance). if (maybeObject_) {
TraceEdge(trc, &maybeObject_, "wasm table object");
} else {
tracePrivate(trc);
}
}
// Tables can store references to wasm functions from other instances. To // preserve the === function identity required by the JS embedding spec, we // must set the element to the function's underlying // CodeRange.funcCheckedCallEntry and Instance so that Table.get()s always // produce the same function object as was imported.
setFuncRef(address, fun->wasmCheckedCallEntry(), &fun->wasmInstance());
}
if (dst.instance) {
MOZ_ASSERT(dst.code);
MOZ_ASSERT(dst.instance->objectUnbarriered()->isTenured(), "no postWriteBarrier (Table::copy)");
} else {
MOZ_ASSERT(!dst.code);
} break;
} case TableRepr::Ref:
setAnyRef(dstIndex, srcTable.getAnyRef(srcIndex)); break;
}
}
uint32_t Table::grow(uint32_t delta) { // This isn't just an optimization: movingGrowable() assumes that // onMovingGrowTable does not fire when length == maximum. if (!delta) { return length_;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.