From 096aac1e3285df984de6770049aa93205a988d43 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Mon, 13 Feb 2017 09:07:26 -0800 Subject: [PATCH] Bug 1287006 - Adjust js/ code to not pass Maybe (or any class containing a Maybe member) by value, only by reference or pointer. r=luke --HG-- extra : rebase_source : b26cb2a94fdc218ea7f40931060eecfc50353d48 --- .../shared/heapsnapshot/DeserializedNode.h | 2 +- js/public/TrackedOptimizationInfo.h | 2 +- js/src/frontend/BytecodeCompiler.cpp | 20 ++--- js/src/frontend/BytecodeCompiler.h | 8 +- js/src/frontend/BytecodeEmitter.cpp | 5 +- js/src/frontend/BytecodeEmitter.h | 2 +- js/src/frontend/Parser.cpp | 7 +- js/src/frontend/Parser.h | 6 +- js/src/jit/shared/Assembler-shared.h | 2 +- js/src/jsscript.cpp | 2 +- js/src/jsscript.h | 2 +- js/src/shell/js.cpp | 2 +- js/src/vm/ArrayBufferObject.cpp | 15 ++-- js/src/vm/ArrayBufferObject.h | 2 +- js/src/wasm/WasmAST.h | 13 +-- js/src/wasm/WasmBaselineCompile.cpp | 88 +++++++++---------- js/src/wasm/WasmBinaryToText.cpp | 16 ++-- js/src/wasm/WasmIonCompile.cpp | 64 +++++++------- js/src/wasm/WasmJS.cpp | 2 +- js/src/wasm/WasmJS.h | 2 +- js/src/wasm/WasmModule.cpp | 4 +- js/src/wasm/WasmTypes.h | 2 +- 22 files changed, 138 insertions(+), 130 deletions(-) diff --git a/devtools/shared/heapsnapshot/DeserializedNode.h b/devtools/shared/heapsnapshot/DeserializedNode.h index 60d1fb408a68..dcc0362702fd 100644 --- a/devtools/shared/heapsnapshot/DeserializedNode.h +++ b/devtools/shared/heapsnapshot/DeserializedNode.h @@ -78,7 +78,7 @@ struct DeserializedNode { const char16_t* typeName, uint64_t size, EdgeVector&& edges, - Maybe allocationStack, + const Maybe& allocationStack, const char* className, const char* filename, HeapSnapshot& owner) diff --git a/js/public/TrackedOptimizationInfo.h b/js/public/TrackedOptimizationInfo.h index 7d8f110cc39d..552eacc5cd4a 100644 --- a/js/public/TrackedOptimizationInfo.h +++ b/js/public/TrackedOptimizationInfo.h @@ -301,7 +301,7 @@ struct ForEachTrackedOptimizationTypeInfoOp // The location parameter is the only one that may need escaping if being // quoted. virtual void readType(const char* keyedBy, const char* name, - const char* location, mozilla::Maybe lineno) = 0; + const char* location, const mozilla::Maybe& lineno) = 0; // Called once per entry. virtual void operator()(TrackedTypeSite site, const char* mirType) = 0; diff --git a/js/src/frontend/BytecodeCompiler.cpp b/js/src/frontend/BytecodeCompiler.cpp index 9ca819ad45c2..b21fc22c6112 100644 --- a/js/src/frontend/BytecodeCompiler.cpp +++ b/js/src/frontend/BytecodeCompiler.cpp @@ -65,18 +65,18 @@ class MOZ_STACK_CLASS BytecodeCompiler ModuleObject* compileModule(); bool compileStandaloneFunction(MutableHandleFunction fun, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, - Maybe parameterListEnd); + const Maybe& parameterListEnd); ScriptSourceObject* sourceObjectPtr() const; private: JSScript* compileScript(HandleObject environment, SharedContext* sc); bool checkLength(); - bool createScriptSource(Maybe parameterListEnd); + bool createScriptSource(const Maybe& parameterListEnd); bool maybeCompressSource(); bool canLazilyParse(); bool createParser(); - bool createSourceAndParser(Maybe parameterListEnd = Nothing()); + bool createSourceAndParser(const Maybe& parameterListEnd = Nothing()); bool createScript(); bool emplaceEmitter(Maybe& emitter, SharedContext* sharedContext); bool handleParseFailure(const Directives& newDirectives); @@ -162,7 +162,7 @@ BytecodeCompiler::checkLength() } bool -BytecodeCompiler::createScriptSource(Maybe parameterListEnd) +BytecodeCompiler::createScriptSource(const Maybe& parameterListEnd) { if (!checkLength()) return false; @@ -233,7 +233,7 @@ BytecodeCompiler::createParser() } bool -BytecodeCompiler::createSourceAndParser(Maybe parameterListEnd /* = Nothing() */) +BytecodeCompiler::createSourceAndParser(const Maybe& parameterListEnd /* = Nothing() */) { return createScriptSource(parameterListEnd) && maybeCompressSource() && @@ -431,7 +431,7 @@ bool BytecodeCompiler::compileStandaloneFunction(MutableHandleFunction fun, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, - Maybe parameterListEnd) + const Maybe& parameterListEnd) { MOZ_ASSERT(fun); MOZ_ASSERT(fun->isTenured()); @@ -486,7 +486,7 @@ BytecodeCompiler::sourceObjectPtr() const ScriptSourceObject* frontend::CreateScriptSourceObject(JSContext* cx, const ReadOnlyCompileOptions& options, - Maybe parameterListEnd /* = Nothing() */) + const Maybe& parameterListEnd /* = Nothing() */) { ScriptSource* ss = cx->new_(); if (!ss) @@ -684,7 +684,7 @@ bool frontend::CompileStandaloneFunction(JSContext* cx, MutableHandleFunction fun, const ReadOnlyCompileOptions& options, JS::SourceBufferHolder& srcBuf, - Maybe parameterListEnd, + const Maybe& parameterListEnd, HandleScope enclosingScope /* = nullptr */) { RootedScope scope(cx, enclosingScope); @@ -700,7 +700,7 @@ bool frontend::CompileStandaloneGenerator(JSContext* cx, MutableHandleFunction fun, const ReadOnlyCompileOptions& options, JS::SourceBufferHolder& srcBuf, - Maybe parameterListEnd) + const Maybe& parameterListEnd) { RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope()); @@ -713,7 +713,7 @@ bool frontend::CompileStandaloneAsyncFunction(JSContext* cx, MutableHandleFunction fun, const ReadOnlyCompileOptions& options, JS::SourceBufferHolder& srcBuf, - Maybe parameterListEnd) + const Maybe& parameterListEnd) { RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope()); diff --git a/js/src/frontend/BytecodeCompiler.h b/js/src/frontend/BytecodeCompiler.h index d4f63bfb4b1a..32a4e7ae94d8 100644 --- a/js/src/frontend/BytecodeCompiler.h +++ b/js/src/frontend/BytecodeCompiler.h @@ -69,20 +69,20 @@ MOZ_MUST_USE bool CompileStandaloneFunction(JSContext* cx, MutableHandleFunction fun, const ReadOnlyCompileOptions& options, JS::SourceBufferHolder& srcBuf, - mozilla::Maybe parameterListEnd, + const mozilla::Maybe& parameterListEnd, HandleScope enclosingScope = nullptr); MOZ_MUST_USE bool CompileStandaloneGenerator(JSContext* cx, MutableHandleFunction fun, const ReadOnlyCompileOptions& options, JS::SourceBufferHolder& srcBuf, - mozilla::Maybe parameterListEnd); + const mozilla::Maybe& parameterListEnd); MOZ_MUST_USE bool CompileStandaloneAsyncFunction(JSContext* cx, MutableHandleFunction fun, const ReadOnlyCompileOptions& options, JS::SourceBufferHolder& srcBuf, - mozilla::Maybe parameterListEnd); + const mozilla::Maybe& parameterListEnd); MOZ_MUST_USE bool CompileAsyncFunctionBody(JSContext* cx, MutableHandleFunction fun, @@ -91,7 +91,7 @@ CompileAsyncFunctionBody(JSContext* cx, MutableHandleFunction fun, ScriptSourceObject* CreateScriptSourceObject(JSContext* cx, const ReadOnlyCompileOptions& options, - mozilla::Maybe parameterListEnd = mozilla::Nothing()); + const mozilla::Maybe& parameterListEnd = mozilla::Nothing()); /* * True if str consists of an IdentifierStart character, followed by one or diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index f38b280a3bbb..19a048fdf729 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -1771,7 +1771,7 @@ class MOZ_STACK_CLASS TryEmitter } public: - bool emitFinally(Maybe finallyPos = Nothing()) { + bool emitFinally(const Maybe& finallyPos = Nothing()) { MOZ_ASSERT(hasFinally()); if (state_ == Try) { @@ -5149,7 +5149,8 @@ BytecodeEmitter::emitIteratorNext(ParseNode* pn, bool allowSelfHosted) } bool -BytecodeEmitter::emitIteratorClose(Maybe yieldStarTryStart, bool allowSelfHosted) +BytecodeEmitter::emitIteratorClose(const Maybe& yieldStarTryStart, + bool allowSelfHosted) { MOZ_ASSERT(allowSelfHosted || emitterMode != BytecodeEmitter::SelfHosting, ".close() on iterators is prohibited in self-hosted code because it " diff --git a/js/src/frontend/BytecodeEmitter.h b/js/src/frontend/BytecodeEmitter.h index 59d63f6bd8d3..dbfe469c083c 100644 --- a/js/src/frontend/BytecodeEmitter.h +++ b/js/src/frontend/BytecodeEmitter.h @@ -680,7 +680,7 @@ struct MOZ_STACK_CLASS BytecodeEmitter // onto the stack. MOZ_MUST_USE bool emitIteratorNext(ParseNode* pn, bool allowSelfHosted = false); MOZ_MUST_USE bool emitIteratorClose( - mozilla::Maybe yieldStarTryStart = mozilla::Nothing(), + const mozilla::Maybe& yieldStarTryStart = mozilla::Nothing(), bool allowSelfHosted = false); template diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 2d9d415a1294..45c9defb862c 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -2294,7 +2294,7 @@ template <> ParseNode* Parser::standaloneFunction(HandleFunction fun, HandleScope enclosingScope, - Maybe parameterListEnd, + const Maybe& parameterListEnd, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, Directives inheritedDirectives, @@ -3398,7 +3398,7 @@ bool Parser::functionFormalParametersAndBody(InHandling inHandling, YieldHandling yieldHandling, Node pn, FunctionSyntaxKind kind, - Maybe parameterListEnd /* = Nothing() */, + const Maybe& parameterListEnd /* = Nothing() */, bool isStandaloneFunction /* = false */) { // Given a properly initialized parse context, try to parse an actual @@ -4037,7 +4037,8 @@ Parser::PossibleError::transferErrorsTo(PossibleError* other) template <> bool -Parser::checkDestructuringName(ParseNode* expr, Maybe maybeDecl) +Parser::checkDestructuringName(ParseNode* expr, + const Maybe& maybeDecl) { MOZ_ASSERT(!handler.isUnparenthesizedDestructuringPattern(expr)); diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index 3d645be5554f..0f76e4be7c43 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -1092,7 +1092,7 @@ class Parser final : public ParserBase, private JS::AutoGCRooter // Parse a function, used for the Function, GeneratorFunction, and // AsyncFunction constructors. Node standaloneFunction(HandleFunction fun, HandleScope enclosingScope, - mozilla::Maybe parameterListEnd, + const mozilla::Maybe& parameterListEnd, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, Directives inheritedDirectives, Directives* newDirectives); @@ -1111,7 +1111,7 @@ class Parser final : public ParserBase, private JS::AutoGCRooter // ParseContext is already on the stack. bool functionFormalParametersAndBody(InHandling inHandling, YieldHandling yieldHandling, Node pn, FunctionSyntaxKind kind, - mozilla::Maybe parameterListEnd = mozilla::Nothing(), + const mozilla::Maybe& parameterListEnd = mozilla::Nothing(), bool isStandaloneFunction = false); // Match the current token against the BindingIdentifier production with @@ -1435,7 +1435,7 @@ class Parser final : public ParserBase, private JS::AutoGCRooter // error if not passed a name. bool checkDestructuringArray(Node arrayPattern, const mozilla::Maybe& maybeDecl); bool checkDestructuringObject(Node objectPattern, const mozilla::Maybe& maybeDecl); - bool checkDestructuringName(Node expr, mozilla::Maybe maybeDecl); + bool checkDestructuringName(Node expr, const mozilla::Maybe& maybeDecl); Node newNumber(const Token& tok) { return handler.newNumber(tok.number(), tok.decimalPoint(), tok.pos); diff --git a/js/src/jit/shared/Assembler-shared.h b/js/src/jit/shared/Assembler-shared.h index 6190d64bb63a..eff2704dd791 100644 --- a/js/src/jit/shared/Assembler-shared.h +++ b/js/src/jit/shared/Assembler-shared.h @@ -695,7 +695,7 @@ class MemoryAccessDesc public: explicit MemoryAccessDesc(Scalar::Type type, uint32_t align, uint32_t offset, - mozilla::Maybe trapOffset, + const mozilla::Maybe& trapOffset, unsigned numSimdElems = 0, jit::MemoryBarrierBits barrierBefore = jit::MembarNobits, jit::MemoryBarrierBits barrierAfter = jit::MembarNobits) diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index acc3212b6391..cf3e5427ad17 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -2163,7 +2163,7 @@ FormatIntroducedFilename(JSContext* cx, const char* filename, unsigned lineno, bool ScriptSource::initFromOptions(JSContext* cx, const ReadOnlyCompileOptions& options, - Maybe parameterListEnd) + const Maybe& parameterListEnd) { MOZ_ASSERT(!filename_); MOZ_ASSERT(!introducerFilename_); diff --git a/js/src/jsscript.h b/js/src/jsscript.h index c6f2569199ca..ae9cb6405830 100644 --- a/js/src/jsscript.h +++ b/js/src/jsscript.h @@ -476,7 +476,7 @@ class ScriptSource } MOZ_MUST_USE bool initFromOptions(JSContext* cx, const ReadOnlyCompileOptions& options, - mozilla::Maybe parameterListEnd = mozilla::Nothing()); + const mozilla::Maybe& parameterListEnd = mozilla::Nothing()); MOZ_MUST_USE bool setSourceCopy(JSContext* cx, JS::SourceBufferHolder& srcBuf, SourceCompressionTask* tok); diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index ebb731c4e18d..f943e2fb651a 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -5305,7 +5305,7 @@ class SprintOptimizationTypeInfoOp : public JS::ForEachTrackedOptimizationTypeIn { } void readType(const char* keyedBy, const char* name, - const char* location, Maybe lineno) override + const char* location, const Maybe& lineno) override { if (hadError_) return; diff --git a/js/src/vm/ArrayBufferObject.cpp b/js/src/vm/ArrayBufferObject.cpp index 97ebe348f211..6ef5bc6113f7 100644 --- a/js/src/vm/ArrayBufferObject.cpp +++ b/js/src/vm/ArrayBufferObject.cpp @@ -513,14 +513,15 @@ class js::WasmArrayRawBuffer size_t mappedSize_; protected: - WasmArrayRawBuffer(uint8_t* buffer, uint32_t length, Maybe maxSize, size_t mappedSize) + WasmArrayRawBuffer(uint8_t* buffer, uint32_t length, const Maybe& maxSize, + size_t mappedSize) : maxSize_(maxSize), mappedSize_(mappedSize) { MOZ_ASSERT(buffer == dataPointer()); } public: - static WasmArrayRawBuffer* Allocate(uint32_t numBytes, Maybe maxSize); + static WasmArrayRawBuffer* Allocate(uint32_t numBytes, const Maybe& maxSize); static void Release(void* mem); uint8_t* dataPointer() { @@ -622,7 +623,7 @@ class js::WasmArrayRawBuffer }; /* static */ WasmArrayRawBuffer* -WasmArrayRawBuffer::Allocate(uint32_t numBytes, Maybe maxSize) +WasmArrayRawBuffer::Allocate(uint32_t numBytes, const Maybe& maxSize) { size_t mappedSize; #ifdef WASM_HUGE_MEMORY @@ -704,7 +705,8 @@ ArrayBufferObject::BufferContents::wasmBuffer() const #define ROUND_UP(v, a) ((v) % (a) == 0 ? (v) : v + a - ((v) % (a))) /* static */ ArrayBufferObject* -ArrayBufferObject::createForWasm(JSContext* cx, uint32_t initialSize, Maybe maxSize) +ArrayBufferObject::createForWasm(JSContext* cx, uint32_t initialSize, + const Maybe& maybeMaxSize) { MOZ_ASSERT(initialSize % wasm::PageSize == 0); MOZ_RELEASE_ASSERT(wasm::HaveSignalHandlers()); @@ -712,10 +714,11 @@ ArrayBufferObject::createForWasm(JSContext* cx, uint32_t initialSize, Maybe maxSize = maybeMaxSize; + if (sizeof(void*) == 4 && maybeMaxSize) { static const uint32_t OneGiB = 1 << 30; uint32_t clamp = Max(OneGiB, initialSize); - maxSize = Some(Min(clamp, maxSize.value())); + maxSize = Some(Min(clamp, maybeMaxSize.value())); } RootedArrayBufferObject buffer(cx, ArrayBufferObject::createEmpty(cx)); diff --git a/js/src/vm/ArrayBufferObject.h b/js/src/vm/ArrayBufferObject.h index b1de70317707..fcd0e242b76c 100644 --- a/js/src/vm/ArrayBufferObject.h +++ b/js/src/vm/ArrayBufferObject.h @@ -336,7 +336,7 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared // WebAssembly support: static ArrayBufferObject* createForWasm(JSContext* cx, uint32_t initialSize, - mozilla::Maybe maxSize); + const mozilla::Maybe& maxSize); static MOZ_MUST_USE bool prepareForAsmJS(JSContext* cx, Handle buffer, bool needGuard); size_t wasmMappedSize() const; diff --git a/js/src/wasm/WasmAST.h b/js/src/wasm/WasmAST.h index e0d02f9b377a..1154c44df4dd 100644 --- a/js/src/wasm/WasmAST.h +++ b/js/src/wasm/WasmAST.h @@ -627,7 +627,7 @@ class AstGlobal : public AstNode {} explicit AstGlobal(AstName name, ValType type, bool isMutable, - Maybe init = Maybe()) + const Maybe& init = Maybe()) : name_(name), isMutable_(isMutable), type_(type), init_(init) {} @@ -656,10 +656,11 @@ class AstImport : public AstNode AstImport(AstName name, AstName module, AstName field, AstRef funcSig) : name_(name), module_(module), field_(field), kind_(DefinitionKind::Function), funcSig_(funcSig) {} - AstImport(AstName name, AstName module, AstName field, DefinitionKind kind, Limits limits) + AstImport(AstName name, AstName module, AstName field, DefinitionKind kind, + const Limits& limits) : name_(name), module_(module), field_(field), kind_(kind), limits_(limits) {} - AstImport(AstName name, AstName module, AstName field, AstGlobal global) + AstImport(AstName name, AstName module, AstName field, const AstGlobal& global) : name_(name), module_(module), field_(field), kind_(DefinitionKind::Global), global_(global) {} @@ -753,7 +754,7 @@ struct AstResizable Limits limits; bool imported; - AstResizable(Limits limits, bool imported, AstName name = AstName()) + AstResizable(const Limits& limits, bool imported, AstName name = AstName()) : name(name), limits(limits), imported(imported) @@ -805,7 +806,7 @@ class AstModule : public AstNode bool init() { return sigMap_.init(); } - bool addMemory(AstName name, Limits memory) { + bool addMemory(AstName name, const Limits& memory) { return memories_.append(AstResizable(memory, false, name)); } bool hasMemory() const { @@ -814,7 +815,7 @@ class AstModule : public AstNode const AstResizableVector& memories() const { return memories_; } - bool addTable(AstName name, Limits table) { + bool addTable(AstName name, const Limits& table) { return tables_.append(AstResizable(table, false, name)); } bool hasTable() const { diff --git a/js/src/wasm/WasmBaselineCompile.cpp b/js/src/wasm/WasmBaselineCompile.cpp index e5f70b733e1e..7c337e6f9b36 100644 --- a/js/src/wasm/WasmBaselineCompile.cpp +++ b/js/src/wasm/WasmBaselineCompile.cpp @@ -3302,10 +3302,10 @@ class BaseCompiler // ptr and dest may be the same iff dest is I32. // This may destroy ptr even if ptr and dest are not the same. - MOZ_MUST_USE bool load(MemoryAccessDesc& access, RegI32 ptr, bool omitBoundsCheck, AnyReg dest, + MOZ_MUST_USE bool load(MemoryAccessDesc* access, RegI32 ptr, bool omitBoundsCheck, AnyReg dest, RegI32 tmp1, RegI32 tmp2, RegI32 tmp3) { - checkOffset(&access, ptr); + checkOffset(access, ptr); OutOfLineCode* ool = nullptr; #ifndef WASM_HUGE_MEMORY @@ -3314,48 +3314,48 @@ class BaseCompiler #endif #if defined(JS_CODEGEN_X64) - Operand srcAddr(HeapReg, ptr, TimesOne, access.offset()); + Operand srcAddr(HeapReg, ptr, TimesOne, access->offset()); if (dest.tag == AnyReg::I64) - masm.wasmLoadI64(access, srcAddr, dest.i64()); + masm.wasmLoadI64(*access, srcAddr, dest.i64()); else - masm.wasmLoad(access, srcAddr, dest.any()); + masm.wasmLoad(*access, srcAddr, dest.any()); #elif defined(JS_CODEGEN_X86) - Operand srcAddr(ptr, access.offset()); + Operand srcAddr(ptr, access->offset()); if (dest.tag == AnyReg::I64) { MOZ_ASSERT(dest.i64() == abiReturnRegI64); - masm.wasmLoadI64(access, srcAddr, dest.i64()); + masm.wasmLoadI64(*access, srcAddr, dest.i64()); } else { - bool byteRegConflict = access.byteSize() == 1 && !singleByteRegs_.has(dest.i32()); + bool byteRegConflict = access->byteSize() == 1 && !singleByteRegs_.has(dest.i32()); AnyRegister out = byteRegConflict ? AnyRegister(ScratchRegX86) : dest.any(); - masm.wasmLoad(access, srcAddr, out); + masm.wasmLoad(*access, srcAddr, out); if (byteRegConflict) masm.mov(ScratchRegX86, dest.i32()); } #elif defined(JS_CODEGEN_ARM) - if (IsUnaligned(access)) { + if (IsUnaligned(*access)) { switch (dest.tag) { case AnyReg::I64: - masm.wasmUnalignedLoadI64(access, ptr, ptr, dest.i64(), tmp1); + masm.wasmUnalignedLoadI64(*access, ptr, ptr, dest.i64(), tmp1); break; case AnyReg::F32: - masm.wasmUnalignedLoadFP(access, ptr, ptr, dest.f32(), tmp1, tmp2, Register::Invalid()); + masm.wasmUnalignedLoadFP(*access, ptr, ptr, dest.f32(), tmp1, tmp2, Register::Invalid()); break; case AnyReg::F64: - masm.wasmUnalignedLoadFP(access, ptr, ptr, dest.f64(), tmp1, tmp2, tmp3); + masm.wasmUnalignedLoadFP(*access, ptr, ptr, dest.f64(), tmp1, tmp2, tmp3); break; default: - masm.wasmUnalignedLoad(access, ptr, ptr, dest.i32(), tmp1); + masm.wasmUnalignedLoad(*access, ptr, ptr, dest.i32(), tmp1); break; } } else { if (dest.tag == AnyReg::I64) - masm.wasmLoadI64(access, ptr, ptr, dest.i64()); + masm.wasmLoadI64(*access, ptr, ptr, dest.i64()); else - masm.wasmLoad(access, ptr, ptr, dest.any()); + masm.wasmLoad(*access, ptr, ptr, dest.any()); } #else MOZ_CRASH("BaseCompiler platform hook: load"); @@ -3366,7 +3366,7 @@ class BaseCompiler return true; } - MOZ_MUST_USE size_t storeTemps(MemoryAccessDesc& access, ValType srcType) { + MOZ_MUST_USE size_t storeTemps(const MemoryAccessDesc& access, ValType srcType) { #if defined(JS_CODEGEN_ARM) if (IsUnaligned(access) && srcType != ValType::I32) return 1; @@ -3376,10 +3376,10 @@ class BaseCompiler // ptr and src must not be the same register. // This may destroy ptr and src. - MOZ_MUST_USE bool store(MemoryAccessDesc access, RegI32 ptr, bool omitBoundsCheck, AnyReg src, + MOZ_MUST_USE bool store(MemoryAccessDesc* access, RegI32 ptr, bool omitBoundsCheck, AnyReg src, RegI32 tmp) { - checkOffset(&access, ptr); + checkOffset(access, ptr); Label rejoin; #ifndef WASM_HUGE_MEMORY @@ -3390,58 +3390,58 @@ class BaseCompiler // Emit the store #if defined(JS_CODEGEN_X64) MOZ_ASSERT(tmp == Register::Invalid()); - Operand dstAddr(HeapReg, ptr, TimesOne, access.offset()); + Operand dstAddr(HeapReg, ptr, TimesOne, access->offset()); - masm.wasmStore(access, src.any(), dstAddr); + masm.wasmStore(*access, src.any(), dstAddr); #elif defined(JS_CODEGEN_X86) MOZ_ASSERT(tmp == Register::Invalid()); - Operand dstAddr(ptr, access.offset()); + Operand dstAddr(ptr, access->offset()); - if (access.type() == Scalar::Int64) { - masm.wasmStoreI64(access, src.i64(), dstAddr); + if (access->type() == Scalar::Int64) { + masm.wasmStoreI64(*access, src.i64(), dstAddr); } else { AnyRegister value; if (src.tag == AnyReg::I64) { - if (access.byteSize() == 1 && !singleByteRegs_.has(src.i64().low)) { + if (access->byteSize() == 1 && !singleByteRegs_.has(src.i64().low)) { masm.mov(src.i64().low, ScratchRegX86); value = AnyRegister(ScratchRegX86); } else { value = AnyRegister(src.i64().low); } - } else if (access.byteSize() == 1 && !singleByteRegs_.has(src.i32())) { + } else if (access->byteSize() == 1 && !singleByteRegs_.has(src.i32())) { masm.mov(src.i32(), ScratchRegX86); value = AnyRegister(ScratchRegX86); } else { value = src.any(); } - masm.wasmStore(access, value, dstAddr); + masm.wasmStore(*access, value, dstAddr); } #elif defined(JS_CODEGEN_ARM) - if (IsUnaligned(access)) { + if (IsUnaligned(*access)) { switch (src.tag) { case AnyReg::I64: - masm.wasmUnalignedStoreI64(access, src.i64(), ptr, ptr, tmp); + masm.wasmUnalignedStoreI64(*access, src.i64(), ptr, ptr, tmp); break; case AnyReg::F32: - masm.wasmUnalignedStoreFP(access, src.f32(), ptr, ptr, tmp); + masm.wasmUnalignedStoreFP(*access, src.f32(), ptr, ptr, tmp); break; case AnyReg::F64: - masm.wasmUnalignedStoreFP(access, src.f64(), ptr, ptr, tmp); + masm.wasmUnalignedStoreFP(*access, src.f64(), ptr, ptr, tmp); break; default: MOZ_ASSERT(tmp == Register::Invalid()); - masm.wasmUnalignedStore(access, src.i32(), ptr, ptr); + masm.wasmUnalignedStore(*access, src.i32(), ptr, ptr); break; } } else { MOZ_ASSERT(tmp == Register::Invalid()); - if (access.type() == Scalar::Int64) - masm.wasmStoreI64(access, src.i64(), ptr, ptr); + if (access->type() == Scalar::Int64) + masm.wasmStoreI64(*access, src.i64(), ptr, ptr); else if (src.tag == AnyReg::I64) - masm.wasmStore(access, AnyRegister(src.i64().low), ptr, ptr); + masm.wasmStore(*access, AnyRegister(src.i64().low), ptr, ptr); else - masm.wasmStore(access, src.any(), ptr, ptr); + masm.wasmStore(*access, src.any(), ptr, ptr); } #else MOZ_CRASH("BaseCompiler platform hook: store"); @@ -6299,7 +6299,7 @@ BaseCompiler::emitLoad(ValType type, Scalar::Type viewType) #else RegI32 rv = rp; #endif - if (!load(access, rp, omitBoundsCheck, AnyReg(rv), tmp1, tmp2, tmp3)) + if (!load(&access, rp, omitBoundsCheck, AnyReg(rv), tmp1, tmp2, tmp3)) return false; pushI32(rv); if (rp != rv) @@ -6317,7 +6317,7 @@ BaseCompiler::emitLoad(ValType type, Scalar::Type viewType) rp = popMemoryAccess(&access, &omitBoundsCheck); rv = needI64(); #endif - if (!load(access, rp, omitBoundsCheck, AnyReg(rv), tmp1, tmp2, tmp3)) + if (!load(&access, rp, omitBoundsCheck, AnyReg(rv), tmp1, tmp2, tmp3)) return false; pushI64(rv); freeI32(rp); @@ -6326,7 +6326,7 @@ BaseCompiler::emitLoad(ValType type, Scalar::Type viewType) case ValType::F32: { RegI32 rp = popMemoryAccess(&access, &omitBoundsCheck); RegF32 rv = needF32(); - if (!load(access, rp, omitBoundsCheck, AnyReg(rv), tmp1, tmp2, tmp3)) + if (!load(&access, rp, omitBoundsCheck, AnyReg(rv), tmp1, tmp2, tmp3)) return false; pushF32(rv); freeI32(rp); @@ -6335,7 +6335,7 @@ BaseCompiler::emitLoad(ValType type, Scalar::Type viewType) case ValType::F64: { RegI32 rp = popMemoryAccess(&access, &omitBoundsCheck); RegF64 rv = needF64(); - if (!load(access, rp, omitBoundsCheck, AnyReg(rv), tmp1, tmp2, tmp3)) + if (!load(&access, rp, omitBoundsCheck, AnyReg(rv), tmp1, tmp2, tmp3)) return false; pushF64(rv); freeI32(rp); @@ -6379,7 +6379,7 @@ BaseCompiler::emitStore(ValType resultType, Scalar::Type viewType) case ValType::I32: { RegI32 rv = popI32(); RegI32 rp = popMemoryAccess(&access, &omitBoundsCheck); - if (!store(access, rp, omitBoundsCheck, AnyReg(rv), tmp)) + if (!store(&access, rp, omitBoundsCheck, AnyReg(rv), tmp)) return false; freeI32(rp); freeI32(rv); @@ -6388,7 +6388,7 @@ BaseCompiler::emitStore(ValType resultType, Scalar::Type viewType) case ValType::I64: { RegI64 rv = popI64(); RegI32 rp = popMemoryAccess(&access, &omitBoundsCheck); - if (!store(access, rp, omitBoundsCheck, AnyReg(rv), tmp)) + if (!store(&access, rp, omitBoundsCheck, AnyReg(rv), tmp)) return false; freeI32(rp); freeI64(rv); @@ -6397,7 +6397,7 @@ BaseCompiler::emitStore(ValType resultType, Scalar::Type viewType) case ValType::F32: { RegF32 rv = popF32(); RegI32 rp = popMemoryAccess(&access, &omitBoundsCheck); - if (!store(access, rp, omitBoundsCheck, AnyReg(rv), tmp)) + if (!store(&access, rp, omitBoundsCheck, AnyReg(rv), tmp)) return false; freeI32(rp); freeF32(rv); @@ -6406,7 +6406,7 @@ BaseCompiler::emitStore(ValType resultType, Scalar::Type viewType) case ValType::F64: { RegF64 rv = popF64(); RegI32 rp = popMemoryAccess(&access, &omitBoundsCheck); - if (!store(access, rp, omitBoundsCheck, AnyReg(rv), tmp)) + if (!store(&access, rp, omitBoundsCheck, AnyReg(rv), tmp)) return false; freeI32(rp); freeF64(rv); diff --git a/js/src/wasm/WasmBinaryToText.cpp b/js/src/wasm/WasmBinaryToText.cpp index d0563642e7b5..d803b233c5a4 100644 --- a/js/src/wasm/WasmBinaryToText.cpp +++ b/js/src/wasm/WasmBinaryToText.cpp @@ -1377,20 +1377,22 @@ RenderGlobalSection(WasmRenderContext& c, const AstModule& module) } static bool -RenderResizableMemory(WasmRenderContext& c, Limits memory) +RenderResizableMemory(WasmRenderContext& c, const Limits& memory) { if (!c.buffer.append("(memory ")) return false; - MOZ_ASSERT(memory.initial % PageSize == 0); - memory.initial /= PageSize; + Limits resizedMemory = memory; - if (memory.maximum) { - MOZ_ASSERT(*memory.maximum % PageSize == 0); - *memory.maximum /= PageSize; + MOZ_ASSERT(resizedMemory.initial % PageSize == 0); + resizedMemory.initial /= PageSize; + + if (resizedMemory.maximum) { + MOZ_ASSERT(*resizedMemory.maximum % PageSize == 0); + *resizedMemory.maximum /= PageSize; } - if (!RenderLimits(c, memory)) + if (!RenderLimits(c, resizedMemory)) return false; return c.buffer.append(")"); diff --git a/js/src/wasm/WasmIonCompile.cpp b/js/src/wasm/WasmIonCompile.cpp index bc95242196aa..72f97475e3ba 100644 --- a/js/src/wasm/WasmIonCompile.cpp +++ b/js/src/wasm/WasmIonCompile.cpp @@ -719,74 +719,74 @@ class FunctionCompiler } public: - MDefinition* load(MDefinition* base, MemoryAccessDesc access, ValType result) + MDefinition* load(MDefinition* base, MemoryAccessDesc* access, ValType result) { if (inDeadCode()) return nullptr; MInstruction* load = nullptr; - if (access.isPlainAsmJS()) { - MOZ_ASSERT(access.offset() == 0); - load = MAsmJSLoadHeap::New(alloc(), base, access.type()); + if (access->isPlainAsmJS()) { + MOZ_ASSERT(access->offset() == 0); + load = MAsmJSLoadHeap::New(alloc(), base, access->type()); } else { - checkOffsetAndBounds(&access, &base); - load = MWasmLoad::New(alloc(), base, access, ToMIRType(result)); + checkOffsetAndBounds(access, &base); + load = MWasmLoad::New(alloc(), base, *access, ToMIRType(result)); } curBlock_->add(load); return load; } - void store(MDefinition* base, MemoryAccessDesc access, MDefinition* v) + void store(MDefinition* base, MemoryAccessDesc* access, MDefinition* v) { if (inDeadCode()) return; MInstruction* store = nullptr; - if (access.isPlainAsmJS()) { - MOZ_ASSERT(access.offset() == 0); - store = MAsmJSStoreHeap::New(alloc(), base, access.type(), v); + if (access->isPlainAsmJS()) { + MOZ_ASSERT(access->offset() == 0); + store = MAsmJSStoreHeap::New(alloc(), base, access->type(), v); } else { - checkOffsetAndBounds(&access, &base); - store = MWasmStore::New(alloc(), base, access, v); + checkOffsetAndBounds(access, &base); + store = MWasmStore::New(alloc(), base, *access, v); } curBlock_->add(store); } - MDefinition* atomicCompareExchangeHeap(MDefinition* base, MemoryAccessDesc access, + MDefinition* atomicCompareExchangeHeap(MDefinition* base, MemoryAccessDesc* access, MDefinition* oldv, MDefinition* newv) { if (inDeadCode()) return nullptr; - checkOffsetAndBounds(&access, &base); - auto* cas = MAsmJSCompareExchangeHeap::New(alloc(), base, access, oldv, newv, tlsPointer_); + checkOffsetAndBounds(access, &base); + auto* cas = MAsmJSCompareExchangeHeap::New(alloc(), base, *access, oldv, newv, tlsPointer_); curBlock_->add(cas); return cas; } - MDefinition* atomicExchangeHeap(MDefinition* base, MemoryAccessDesc access, + MDefinition* atomicExchangeHeap(MDefinition* base, MemoryAccessDesc* access, MDefinition* value) { if (inDeadCode()) return nullptr; - checkOffsetAndBounds(&access, &base); - auto* cas = MAsmJSAtomicExchangeHeap::New(alloc(), base, access, value, tlsPointer_); + checkOffsetAndBounds(access, &base); + auto* cas = MAsmJSAtomicExchangeHeap::New(alloc(), base, *access, value, tlsPointer_); curBlock_->add(cas); return cas; } MDefinition* atomicBinopHeap(js::jit::AtomicOp op, - MDefinition* base, MemoryAccessDesc access, + MDefinition* base, MemoryAccessDesc* access, MDefinition* v) { if (inDeadCode()) return nullptr; - checkOffsetAndBounds(&access, &base); - auto* binop = MAsmJSAtomicBinopHeap::New(alloc(), op, base, access, v, tlsPointer_); + checkOffsetAndBounds(access, &base); + auto* binop = MAsmJSAtomicBinopHeap::New(alloc(), op, base, *access, v, tlsPointer_); curBlock_->add(binop); return binop; } @@ -2319,7 +2319,7 @@ EmitLoad(FunctionCompiler& f, ValType type, Scalar::Type viewType) return false; MemoryAccessDesc access(viewType, addr.align, addr.offset, f.trapIfNotAsmJS()); - f.iter().setResult(f.load(addr.base, access, type)); + f.iter().setResult(f.load(addr.base, &access, type)); return true; } @@ -2333,7 +2333,7 @@ EmitStore(FunctionCompiler& f, ValType resultType, Scalar::Type viewType) MemoryAccessDesc access(viewType, addr.align, addr.offset, f.trapIfNotAsmJS()); - f.store(addr.base, access, value); + f.store(addr.base, &access, value); return true; } @@ -2347,7 +2347,7 @@ EmitTeeStore(FunctionCompiler& f, ValType resultType, Scalar::Type viewType) MemoryAccessDesc access(viewType, addr.align, addr.offset, f.trapIfNotAsmJS()); - f.store(addr.base, access, value); + f.store(addr.base, &access, value); return true; } @@ -2368,7 +2368,7 @@ EmitTeeStoreWithCoercion(FunctionCompiler& f, ValType resultType, Scalar::Type v MemoryAccessDesc access(viewType, addr.align, addr.offset, f.trapIfNotAsmJS()); - f.store(addr.base, access, value); + f.store(addr.base, &access, value); return true; } @@ -2441,7 +2441,7 @@ EmitAtomicsLoad(FunctionCompiler& f) MemoryAccessDesc access(viewType, addr.align, addr.offset, Some(f.trapOffset()), 0, MembarBeforeLoad, MembarAfterLoad); - f.iter().setResult(f.load(addr.base, access, ValType::I32)); + f.iter().setResult(f.load(addr.base, &access, ValType::I32)); return true; } @@ -2457,7 +2457,7 @@ EmitAtomicsStore(FunctionCompiler& f) MemoryAccessDesc access(viewType, addr.align, addr.offset, Some(f.trapOffset()), 0, MembarBeforeStore, MembarAfterStore); - f.store(addr.base, access, value); + f.store(addr.base, &access, value); f.iter().setResult(value); return true; } @@ -2474,7 +2474,7 @@ EmitAtomicsBinOp(FunctionCompiler& f) MemoryAccessDesc access(viewType, addr.align, addr.offset, Some(f.trapOffset())); - f.iter().setResult(f.atomicBinopHeap(op, addr.base, access, value)); + f.iter().setResult(f.atomicBinopHeap(op, addr.base, &access, value)); return true; } @@ -2490,7 +2490,7 @@ EmitAtomicsCompareExchange(FunctionCompiler& f) MemoryAccessDesc access(viewType, addr.align, addr.offset, Some(f.trapOffset())); - f.iter().setResult(f.atomicCompareExchangeHeap(addr.base, access, oldValue, newValue)); + f.iter().setResult(f.atomicCompareExchangeHeap(addr.base, &access, oldValue, newValue)); return true; } @@ -2505,7 +2505,7 @@ EmitAtomicsExchange(FunctionCompiler& f) MemoryAccessDesc access(viewType, addr.align, addr.offset, Some(f.trapOffset())); - f.iter().setResult(f.atomicExchangeHeap(addr.base, access, value)); + f.iter().setResult(f.atomicExchangeHeap(addr.base, &access, value)); return true; } @@ -2728,7 +2728,7 @@ EmitSimdLoad(FunctionCompiler& f, ValType resultType, unsigned numElems) MemoryAccessDesc access(viewType, addr.align, addr.offset, Some(f.trapOffset()), numElems); - f.iter().setResult(f.load(addr.base, access, resultType)); + f.iter().setResult(f.load(addr.base, &access, resultType)); return true; } @@ -2748,7 +2748,7 @@ EmitSimdStore(FunctionCompiler& f, ValType resultType, unsigned numElems) MemoryAccessDesc access(viewType, addr.align, addr.offset, Some(f.trapOffset()), numElems); - f.store(addr.base, access, value); + f.store(addr.base, &access, value); return true; } diff --git a/js/src/wasm/WasmJS.cpp b/js/src/wasm/WasmJS.cpp index 7e760f15732d..367e1c79e30f 100644 --- a/js/src/wasm/WasmJS.cpp +++ b/js/src/wasm/WasmJS.cpp @@ -1491,7 +1491,7 @@ WasmTableObject::trace(JSTracer* trc, JSObject* obj) } /* static */ WasmTableObject* -WasmTableObject::create(JSContext* cx, Limits limits) +WasmTableObject::create(JSContext* cx, const Limits& limits) { RootedObject proto(cx, &cx->global()->getPrototype(JSProto_WasmTable).toObject()); diff --git a/js/src/wasm/WasmJS.h b/js/src/wasm/WasmJS.h index c77e51cb2f50..701ff57bc0f7 100644 --- a/js/src/wasm/WasmJS.h +++ b/js/src/wasm/WasmJS.h @@ -276,7 +276,7 @@ class WasmTableObject : public NativeObject // Note that, after creation, a WasmTableObject's table() is not initialized // and must be initialized before use. - static WasmTableObject* create(JSContext* cx, wasm::Limits limits); + static WasmTableObject* create(JSContext* cx, const wasm::Limits& limits); wasm::Table& table() const; }; diff --git a/js/src/wasm/WasmModule.cpp b/js/src/wasm/WasmModule.cpp index 2cf8b95b4465..bbf926a2ebe1 100644 --- a/js/src/wasm/WasmModule.cpp +++ b/js/src/wasm/WasmModule.cpp @@ -604,8 +604,8 @@ Module::instantiateFunctions(JSContext* cx, Handle funcImports) } static bool -CheckLimits(JSContext* cx, uint32_t declaredMin, Maybe declaredMax, uint32_t actualLength, - Maybe actualMax, bool isAsmJS, const char* kind) +CheckLimits(JSContext* cx, uint32_t declaredMin, const Maybe& declaredMax, uint32_t actualLength, + const Maybe& actualMax, bool isAsmJS, const char* kind) { if (isAsmJS) { MOZ_ASSERT(actualLength >= declaredMin); diff --git a/js/src/wasm/WasmTypes.h b/js/src/wasm/WasmTypes.h index 4c2b41a2b789..77ce333593ee 100644 --- a/js/src/wasm/WasmTypes.h +++ b/js/src/wasm/WasmTypes.h @@ -1106,7 +1106,7 @@ struct TableDesc Limits limits; TableDesc() = default; - TableDesc(TableKind kind, Limits limits) + TableDesc(TableKind kind, const Limits& limits) : kind(kind), external(false), globalDataOffset(UINT32_MAX),