Bug 1665015 - Use SystemAllocPolicy for ObjLiteralWriterBase and ObjLiteralAtomVector. r=tcampbell

Differential Revision: https://phabricator.services.mozilla.com/D90243
This commit is contained in:
Tooru Fujisawa 2020-09-15 14:54:10 +00:00
parent b9f69c11b9
commit 2e3005ac3c
2 changed files with 57 additions and 49 deletions

View File

@ -1656,7 +1656,7 @@ bool BytecodeEmitter::iteratorResultShape(GCThingIndex* shape) {
ObjLiteralFlags flags{ObjLiteralFlag::NoValues};
ObjLiteralIndex objIndex(compilationInfo.stencil.objLiteralData.length());
if (!compilationInfo.stencil.objLiteralData.emplaceBack(cx)) {
if (!compilationInfo.stencil.objLiteralData.emplaceBack()) {
js::ReportOutOfMemory(cx);
return false;
}
@ -1669,12 +1669,12 @@ bool BytecodeEmitter::iteratorResultShape(GCThingIndex* shape) {
const ParserAtom* propName = cx->parserNames().*name;
uint32_t propNameIndex = 0;
if (!data.addAtom(propName, &propNameIndex)) {
if (!data.addAtom(cx, propName, &propNameIndex)) {
return false;
}
data.writer().setPropName(propNameIndex);
if (!data.writer().propWithUndefinedValue()) {
if (!data.writer().propWithUndefinedValue(cx)) {
return false;
}
}
@ -4622,7 +4622,7 @@ bool BytecodeEmitter::emitCallSiteObjectArray(ListNode* cookedOrRaw,
}
ObjLiteralIndex objIndex(compilationInfo.stencil.objLiteralData.length());
if (!compilationInfo.stencil.objLiteralData.emplaceBack(cx)) {
if (!compilationInfo.stencil.objLiteralData.emplaceBack()) {
js::ReportOutOfMemory(cx);
return false;
}
@ -8835,7 +8835,7 @@ bool BytecodeEmitter::emitPropertyList(ListNode* obj, PropertyEmitter& pe,
bool BytecodeEmitter::emitPropertyListObjLiteral(ListNode* obj,
ObjLiteralFlags flags) {
ObjLiteralIndex objIndex(compilationInfo.stencil.objLiteralData.length());
if (!compilationInfo.stencil.objLiteralData.emplaceBack(cx)) {
if (!compilationInfo.stencil.objLiteralData.emplaceBack()) {
js::ReportOutOfMemory(cx);
return false;
}
@ -8851,7 +8851,7 @@ bool BytecodeEmitter::emitPropertyListObjLiteral(ListNode* obj,
if (key->is<NameNode>()) {
uint32_t propNameIndex = 0;
if (!data.addAtom(key->as<NameNode>().atom(), &propNameIndex)) {
if (!data.addAtom(cx, key->as<NameNode>().atom(), &propNameIndex)) {
return false;
}
data.writer().setPropName(propNameIndex);
@ -8867,7 +8867,7 @@ bool BytecodeEmitter::emitPropertyListObjLiteral(ListNode* obj,
}
if (noValues) {
if (!data.writer().propWithUndefinedValue()) {
if (!data.writer().propWithUndefinedValue(cx)) {
return false;
}
} else {
@ -8904,7 +8904,7 @@ bool BytecodeEmitter::emitDestructuringRestExclusionSetObjLiteral(
ObjLiteralFlags flags{ObjLiteralFlag::NoValues};
ObjLiteralIndex objIndex(compilationInfo.stencil.objLiteralData.length());
if (!compilationInfo.stencil.objLiteralData.emplaceBack(cx)) {
if (!compilationInfo.stencil.objLiteralData.emplaceBack()) {
js::ReportOutOfMemory(cx);
return false;
}
@ -8927,12 +8927,12 @@ bool BytecodeEmitter::emitDestructuringRestExclusionSetObjLiteral(
}
uint32_t propNameIndex = 0;
if (!data.addAtom(atom, &propNameIndex)) {
if (!data.addAtom(cx, atom, &propNameIndex)) {
return false;
}
data.writer().setPropName(propNameIndex);
if (!data.writer().propWithUndefinedValue()) {
if (!data.writer().propWithUndefinedValue(cx)) {
return false;
}
}
@ -8957,7 +8957,7 @@ bool BytecodeEmitter::emitDestructuringRestExclusionSetObjLiteral(
bool BytecodeEmitter::emitObjLiteralArray(ParseNode* arrayHead, bool isCow) {
ObjLiteralIndex objIndex(compilationInfo.stencil.objLiteralData.length());
if (!compilationInfo.stencil.objLiteralData.emplaceBack(cx)) {
if (!compilationInfo.stencil.objLiteralData.emplaceBack()) {
js::ReportOutOfMemory(cx);
return false;
}
@ -9012,32 +9012,32 @@ bool BytecodeEmitter::emitObjLiteralValue(ObjLiteralStencil* data,
} else {
v.setDouble(numValue);
}
if (!data->writer().propWithConstNumericValue(v)) {
if (!data->writer().propWithConstNumericValue(cx, v)) {
return false;
}
} else if (value->isKind(ParseNodeKind::TrueExpr)) {
if (!data->writer().propWithTrueValue()) {
if (!data->writer().propWithTrueValue(cx)) {
return false;
}
} else if (value->isKind(ParseNodeKind::FalseExpr)) {
if (!data->writer().propWithFalseValue()) {
if (!data->writer().propWithFalseValue(cx)) {
return false;
}
} else if (value->isKind(ParseNodeKind::NullExpr)) {
if (!data->writer().propWithNullValue()) {
if (!data->writer().propWithNullValue(cx)) {
return false;
}
} else if (value->isKind(ParseNodeKind::RawUndefinedExpr)) {
if (!data->writer().propWithUndefinedValue()) {
if (!data->writer().propWithUndefinedValue(cx)) {
return false;
}
} else if (value->isKind(ParseNodeKind::StringExpr) ||
value->isKind(ParseNodeKind::TemplateStringExpr)) {
uint32_t valueAtomIndex = 0;
if (!data->addAtom(value->as<NameNode>().atom(), &valueAtomIndex)) {
if (!data->addAtom(cx, value->as<NameNode>().atom(), &valueAtomIndex)) {
return false;
}
if (!data->writer().propWithAtomValue(valueAtomIndex)) {
if (!data->writer().propWithAtomValue(cx, valueAtomIndex)) {
return false;
}
} else {

View File

@ -260,16 +260,17 @@ struct ObjLiteralWriterBase {
static const int OP_SHIFT = 24;
protected:
Vector<uint8_t, 64> code_;
Vector<uint8_t, 64, js::SystemAllocPolicy> code_;
public:
explicit ObjLiteralWriterBase(JSContext* cx) : code_(cx) {}
ObjLiteralWriterBase() = default;
uint32_t curOffset() const { return code_.length(); }
MOZ_MUST_USE bool prepareBytes(size_t len, uint8_t** p) {
MOZ_MUST_USE bool prepareBytes(JSContext* cx, size_t len, uint8_t** p) {
size_t offset = code_.length();
if (!code_.growByUninitialized(len)) {
js::ReportOutOfMemory(cx);
return false;
}
*p = &code_[offset];
@ -277,9 +278,9 @@ struct ObjLiteralWriterBase {
}
template <typename T>
MOZ_MUST_USE bool pushRawData(T data) {
MOZ_MUST_USE bool pushRawData(JSContext* cx, T data) {
uint8_t* p = nullptr;
if (!prepareBytes(sizeof(T), &p)) {
if (!prepareBytes(cx, sizeof(T), &p)) {
return false;
}
mozilla::NativeEndian::copyAndSwapToLittleEndian(reinterpret_cast<void*>(p),
@ -287,22 +288,23 @@ struct ObjLiteralWriterBase {
return true;
}
MOZ_MUST_USE bool pushOpAndName(ObjLiteralOpcode op, ObjLiteralKey key) {
MOZ_MUST_USE bool pushOpAndName(JSContext* cx, ObjLiteralOpcode op,
ObjLiteralKey key) {
uint32_t data = (key.rawIndex() & ATOM_INDEX_MASK) |
(key.isArrayIndex() ? INDEXED_PROP : 0) |
(static_cast<uint8_t>(op) << OP_SHIFT);
return pushRawData(data);
return pushRawData(cx, data);
}
MOZ_MUST_USE bool pushValueArg(const JS::Value& value) {
MOZ_MUST_USE bool pushValueArg(JSContext* cx, const JS::Value& value) {
MOZ_ASSERT(value.isNumber() || value.isNullOrUndefined() ||
value.isBoolean());
uint64_t data = value.asRawBits();
return pushRawData(data);
return pushRawData(cx, data);
}
MOZ_MUST_USE bool pushAtomArg(uint32_t atomIndex) {
return pushRawData(atomIndex);
MOZ_MUST_USE bool pushAtomArg(JSContext* cx, uint32_t atomIndex) {
return pushRawData(cx, atomIndex);
}
};
@ -313,8 +315,7 @@ struct ObjLiteralWriterBase {
// within the writer.
struct ObjLiteralWriter : private ObjLiteralWriterBase {
public:
explicit ObjLiteralWriter(JSContext* cx)
: ObjLiteralWriterBase(cx), flags_() {}
ObjLiteralWriter() = default;
void clear() { code_.clear(); }
@ -342,26 +343,27 @@ struct ObjLiteralWriter : private ObjLiteralWriterBase {
nextKey_ = ObjLiteralKey::none();
}
MOZ_MUST_USE bool propWithConstNumericValue(const JS::Value& value) {
MOZ_MUST_USE bool propWithConstNumericValue(JSContext* cx,
const JS::Value& value) {
MOZ_ASSERT(value.isNumber());
return pushOpAndName(ObjLiteralOpcode::ConstValue, nextKey_) &&
pushValueArg(value);
return pushOpAndName(cx, ObjLiteralOpcode::ConstValue, nextKey_) &&
pushValueArg(cx, value);
}
MOZ_MUST_USE bool propWithAtomValue(uint32_t value) {
return pushOpAndName(ObjLiteralOpcode::ConstAtom, nextKey_) &&
pushAtomArg(value);
MOZ_MUST_USE bool propWithAtomValue(JSContext* cx, uint32_t value) {
return pushOpAndName(cx, ObjLiteralOpcode::ConstAtom, nextKey_) &&
pushAtomArg(cx, value);
}
MOZ_MUST_USE bool propWithNullValue() {
return pushOpAndName(ObjLiteralOpcode::Null, nextKey_);
MOZ_MUST_USE bool propWithNullValue(JSContext* cx) {
return pushOpAndName(cx, ObjLiteralOpcode::Null, nextKey_);
}
MOZ_MUST_USE bool propWithUndefinedValue() {
return pushOpAndName(ObjLiteralOpcode::Undefined, nextKey_);
MOZ_MUST_USE bool propWithUndefinedValue(JSContext* cx) {
return pushOpAndName(cx, ObjLiteralOpcode::Undefined, nextKey_);
}
MOZ_MUST_USE bool propWithTrueValue() {
return pushOpAndName(ObjLiteralOpcode::True, nextKey_);
MOZ_MUST_USE bool propWithTrueValue(JSContext* cx) {
return pushOpAndName(cx, ObjLiteralOpcode::True, nextKey_);
}
MOZ_MUST_USE bool propWithFalseValue() {
return pushOpAndName(ObjLiteralOpcode::False, nextKey_);
MOZ_MUST_USE bool propWithFalseValue(JSContext* cx) {
return pushOpAndName(cx, ObjLiteralOpcode::False, nextKey_);
}
static bool arrayIndexInRange(int32_t i) {
@ -549,7 +551,8 @@ struct ObjLiteralReader : private ObjLiteralReaderBase {
}
};
typedef Vector<const frontend::ParserAtom*, 4> ObjLiteralAtomVector;
typedef Vector<const frontend::ParserAtom*, 4, js::SystemAllocPolicy>
ObjLiteralAtomVector;
JSObject* InterpretObjLiteral(JSContext* cx,
frontend::CompilationInfo& compilationInfo,
@ -571,13 +574,18 @@ class ObjLiteralStencil {
ObjLiteralAtomVector atoms_;
public:
explicit ObjLiteralStencil(JSContext* cx) : writer_(cx), atoms_(cx) {}
ObjLiteralStencil() = default;
ObjLiteralWriter& writer() { return writer_; }
bool addAtom(const frontend::ParserAtom* atom, uint32_t* index) {
bool addAtom(JSContext* cx, const frontend::ParserAtom* atom,
uint32_t* index) {
*index = atoms_.length();
return atoms_.append(atom);
if (!atoms_.append(atom)) {
js::ReportOutOfMemory(cx);
return false;
}
return true;
}
JSObject* create(JSContext* cx, frontend::CompilationInfo& info) const;