Bug 1231224 part 2 - Fix MTableSwitch methods to handle OOM. r=h4writer

This commit is contained in:
Jan de Mooij 2015-12-10 13:22:14 -05:00
Родитель 45be0649a9
Коммит 86e6d30178
3 изменённых файлов: 44 добавлений и 22 удалений

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

@ -1129,12 +1129,20 @@ class FunctionCompiler
if (!switchBlock)
return true;
MTableSwitch* mir = switchBlock->lastIns()->toTableSwitch();
size_t defaultIndex = mir->addDefault(defaultBlock);
size_t defaultIndex;
if (!mir->addDefault(defaultBlock, &defaultIndex))
return false;
for (unsigned i = 0; i < cases.length(); i++) {
if (!cases[i])
mir->addCase(defaultIndex);
else
mir->addCase(mir->addSuccessor(cases[i]));
if (!cases[i]) {
if (!mir->addCase(defaultIndex))
return false;
} else {
size_t caseIndex;
if (!mir->addSuccessor(cases[i], &caseIndex))
return false;
if (!mir->addCase(caseIndex))
return false;
}
}
if (curBlock_) {
MBasicBlock* next;

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

@ -3422,8 +3422,12 @@ IonBuilder::tableSwitch(JSOp op, jssrcnote* sn)
MBasicBlock* defaultcase = newBlock(current, defaultpc);
if (!defaultcase)
return ControlStatus_Error;
tableswitch->addDefault(defaultcase);
tableswitch->addBlock(defaultcase);
if (!tableswitch->addDefault(defaultcase))
return ControlStatus_Error;
if (!tableswitch->addBlock(defaultcase))
return ControlStatus_Error;
// Create cases
jsbytecode* casepc = nullptr;
@ -3451,14 +3455,22 @@ IonBuilder::tableSwitch(JSOp op, jssrcnote* sn)
if (!caseblock)
return ControlStatus_Error;
tableswitch->addBlock(caseblock);
if (!tableswitch->addBlock(caseblock))
return ControlStatus_Error;
// Add constant to indicate which case this is for use by
// processNextTableSwitchCase.
MConstant* constant = MConstant::New(alloc(), Int32Value(i + low));
caseblock->add(constant);
}
tableswitch->addCase(tableswitch->addSuccessor(caseblock));
size_t caseIndex;
if (!tableswitch->addSuccessor(caseblock, &caseIndex))
return ControlStatus_Error;
if (!tableswitch->addCase(caseIndex))
return ControlStatus_Error;
pc2 += JUMP_OFFSET_LEN;
}
@ -5884,7 +5896,8 @@ IonBuilder::inlineCalls(CallInfo& callInfo, const ObjectVector& targets, BoolVec
// Connect the inline path to the returnBlock.
ObjectGroup* funcGroup = target->isSingleton() ? nullptr : target->group();
dispatch->addCase(target, funcGroup, inlineBlock);
if (!dispatch->addCase(target, funcGroup, inlineBlock))
return false;
MDefinition* retVal = inlineReturnBlock->peek(-1);
retPhi->addInput(retVal);

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

@ -2536,11 +2536,11 @@ class MTableSwitch final
return successors_.length();
}
size_t addSuccessor(MBasicBlock* successor) {
bool addSuccessor(MBasicBlock* successor, size_t* index) {
MOZ_ASSERT(successors_.length() < (size_t)(high_ - low_ + 2));
MOZ_ASSERT(!successors_.empty());
successors_.append(successor);
return successors_.length() - 1;
*index = successors_.length();
return successors_.append(successor);
}
MBasicBlock* getSuccessor(size_t i) const override {
@ -2581,14 +2581,15 @@ class MTableSwitch final
return high() - low() + 1;
}
size_t addDefault(MBasicBlock* block) {
bool addDefault(MBasicBlock* block, size_t* index = nullptr) {
MOZ_ASSERT(successors_.empty());
successors_.append(block);
return 0;
if (index)
*index = 0;
return successors_.append(block);
}
void addCase(size_t successorIndex) {
cases_.append(successorIndex);
bool addCase(size_t successorIndex) {
return cases_.append(successorIndex);
}
MBasicBlock* getBlock(size_t i) const {
@ -2596,8 +2597,8 @@ class MTableSwitch final
return blocks_[i];
}
void addBlock(MBasicBlock* block) {
blocks_.append(block);
bool addBlock(MBasicBlock* block) {
return blocks_.append(block);
}
MDefinition* getOperand(size_t index) const override {
@ -10646,8 +10647,8 @@ class MDispatchInstruction
}
public:
void addCase(JSFunction* func, ObjectGroup* funcGroup, MBasicBlock* block) {
map_.append(Entry(func, funcGroup, block));
bool addCase(JSFunction* func, ObjectGroup* funcGroup, MBasicBlock* block) {
return map_.append(Entry(func, funcGroup, block));
}
uint32_t numCases() const {
return map_.length();