Bug 1782770 - wasm: Don't make extra copy of FuncType for debugging. r=yury

Now that we transfer all type definitions to Metadata, we can
remove the special debugging case where we would transfer all
function types. Instead, we can just transfer the funcTypeIndex
and find the function type in Metadata.

Differential Revision: https://phabricator.services.mozilla.com/D153500
This commit is contained in:
Ryan Hunt 2022-08-12 17:21:56 +00:00
Родитель 4ed81efbb9
Коммит f3a70ff9e6
8 изменённых файлов: 19 добавлений и 37 удалений

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

@ -372,8 +372,6 @@ struct MetadataCacheablePod {
WASM_DECLARE_CACHEABLE_POD(MetadataCacheablePod)
typedef uint8_t ModuleHash[8];
using FuncArgTypesVector = Vector<ValTypeVector, 0, SystemAllocPolicy>;
using FuncReturnTypesVector = Vector<ValTypeVector, 0, SystemAllocPolicy>;
struct Metadata : public ShareableBase<Metadata>, public MetadataCacheablePod {
TypeDefVector types;
@ -393,8 +391,7 @@ struct Metadata : public ShareableBase<Metadata>, public MetadataCacheablePod {
// Debug-enabled code is not serialized.
bool debugEnabled;
FuncArgTypesVector debugFuncArgTypes;
FuncReturnTypesVector debugFuncReturnTypes;
Uint32Vector debugFuncTypeIndices;
ModuleHash debugHash;
explicit Metadata(ModuleKind kind = ModuleKind::Wasm)
@ -416,12 +413,11 @@ struct Metadata : public ShareableBase<Metadata>, public MetadataCacheablePod {
return types[funcExport.typeIndex()].funcType();
}
// Invariant: The result of getFuncResultType can only be used as long as
// Metadata is live, because the returned ResultType may encode a pointer to
// debugFuncReturnTypes.
ResultType getFuncResultType(uint32_t funcIndex) const {
return ResultType::Vector(debugFuncReturnTypes[funcIndex]);
};
size_t debugNumFuncs() const { return debugFuncTypeIndices.length(); }
const FuncType& debugFuncType(uint32_t funcIndex) const {
MOZ_ASSERT(debugEnabled);
return types[debugFuncTypeIndices[funcIndex]].funcType();
}
// AsmJSMetadata derives Metadata iff isAsmJS(). Mostly this distinction is
// encapsulated within AsmJS.cpp, but the additional virtual functions allow

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

@ -318,7 +318,7 @@ void DebugState::adjustEnterAndLeaveFrameTrapsState(JSContext* cx,
}
MOZ_RELEASE_ASSERT(&instance->metadata() == &metadata());
uint32_t numFuncs = metadata().debugFuncReturnTypes.length();
uint32_t numFuncs = metadata().debugNumFuncs();
if (enabled) {
MOZ_ASSERT(enterAndLeaveFrameTrapsCounter_ > 0);
for (uint32_t funcIdx = 0; funcIdx < numFuncs; funcIdx++) {
@ -372,8 +372,9 @@ void DebugState::ensureEnterFrameTrapsState(JSContext* cx, Instance* instance,
bool DebugState::debugGetLocalTypes(uint32_t funcIndex, ValTypeVector* locals,
size_t* argsLength,
StackResults* stackResults) {
const ValTypeVector& args = metadata().debugFuncArgTypes[funcIndex];
const ValTypeVector& results = metadata().debugFuncReturnTypes[funcIndex];
const FuncType& funcType = metadata().debugFuncType(funcIndex);
const ValTypeVector& args = funcType.args();
const ValTypeVector& results = funcType.results();
ResultType resultType(ResultType::Vector(results));
*argsLength = args.length();
*stackResults = ABIResultIter::HasStackResults(resultType)

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

@ -150,12 +150,6 @@ class DebugState {
ValTypeVector* locals,
size_t* argsLength,
StackResults* stackResults);
// Invariant: the result of getDebugResultType can only be used as long as
// code_->metadata() is live. See MetaData::getFuncResultType for more
// information.
ResultType debugGetResultType(uint32_t funcIndex) const {
return metadata().getFuncResultType(funcIndex);
}
[[nodiscard]] bool getGlobal(Instance& instance, uint32_t globalIndex,
MutableHandleValue vp);

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

@ -26,6 +26,7 @@
#include "wasm/WasmStubs.h"
#include "vm/NativeObject-inl.h"
#include "wasm/WasmInstance-inl.h"
using namespace js;
using namespace js::jit;
@ -134,7 +135,8 @@ bool DebugFrame::updateReturnJSValue(JSContext* cx) {
MutableHandleValue::fromMarkedLocation(&cachedReturnJSValue_);
rval.setUndefined();
flags_.hasCachedReturnJSValue = true;
ResultType resultType = instance()->debug().debugGetResultType(funcIndex());
ResultType resultType = ResultType::Vector(
instance()->metadata().debugFuncType(funcIndex()).results());
Maybe<char*> stackResultsLoc;
if (ABIResultIter::HasStackResults(resultType)) {
stackResultsLoc = Some(static_cast<char*>(stackResultsPointer_));

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

@ -1074,21 +1074,11 @@ SharedMetadata ModuleGenerator::finishMetadata(const Bytes& bytecode) {
metadata_->debugEnabled = true;
const size_t numFuncs = moduleEnv_->funcs.length();
if (!metadata_->debugFuncArgTypes.resize(numFuncs)) {
return nullptr;
}
if (!metadata_->debugFuncReturnTypes.resize(numFuncs)) {
if (!metadata_->debugFuncTypeIndices.resize(numFuncs)) {
return nullptr;
}
for (size_t i = 0; i < numFuncs; i++) {
if (!metadata_->debugFuncArgTypes[i].appendAll(
moduleEnv_->funcs[i].type->args())) {
return nullptr;
}
if (!metadata_->debugFuncReturnTypes[i].appendAll(
moduleEnv_->funcs[i].type->results())) {
return nullptr;
}
metadata_->debugFuncTypeIndices[i] = moduleEnv_->funcs[i].typeIndex;
}
static_assert(sizeof(ModuleHash) <= sizeof(mozilla::SHA1Sum::Hash),

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

@ -1404,7 +1404,7 @@ bool Instance::init(JSContext* cx, const JSFunctionVector& funcImports,
// Add debug filtering table.
if (metadata().debugEnabled) {
size_t numFuncs = metadata().debugFuncReturnTypes.length();
size_t numFuncs = metadata().debugNumFuncs();
size_t numWords = std::max<size_t>((numFuncs + 31) / 32, 1);
debugFilter_ = (uint32_t*)js_calloc(numWords, sizeof(uint32_t));
if (!debugFilter_) {

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

@ -794,8 +794,7 @@ CoderResult CodeMetadata(Coder<mode>& coder,
CoderArg<mode, wasm::Metadata> item) {
WASM_VERIFY_SERIALIZATION_FOR_SIZE(wasm::Metadata, 464);
if constexpr (mode == MODE_ENCODE) {
MOZ_ASSERT(!item->debugEnabled && item->debugFuncArgTypes.empty() &&
item->debugFuncReturnTypes.empty());
MOZ_ASSERT(!item->debugEnabled && item->debugFuncTypeIndices.empty());
MOZ_ASSERT(!item->isAsmJS());
}
@ -814,8 +813,7 @@ CoderResult CodeMetadata(Coder<mode>& coder,
if constexpr (mode == MODE_DECODE) {
item->debugEnabled = false;
item->debugFuncArgTypes.clear();
item->debugFuncReturnTypes.clear();
item->debugFuncTypeIndices.clear();
}
return Ok();

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

@ -32,6 +32,7 @@
#include "wasm/WasmInstance.h"
#include "jit/MacroAssembler-inl.h"
#include "wasm/WasmInstance-inl.h"
using namespace js;
using namespace js::jit;