Add a SafeMap equivalent to std::map but without the error-prone operator[].
Change-Id: Iae5ba2091c55a34dbd1005cf3d25fce2a8d5c1f9
diff --git a/src/compiler/CompilerIR.h b/src/compiler/CompilerIR.h
index 0fc26de..88593bd 100644
--- a/src/compiler/CompilerIR.h
+++ b/src/compiler/CompilerIR.h
@@ -17,10 +17,12 @@
#ifndef ART_SRC_COMPILER_COMPILER_IR_H_
#define ART_SRC_COMPILER_COMPILER_IR_H_
+#include <vector>
+
#include "codegen/Optimizer.h"
#include "CompilerUtility.h"
-#include <vector>
#include "oat_compilation_unit.h"
+#include "safe_map.h"
namespace art {
@@ -519,8 +521,8 @@
const u2* insns;
u4 insnsSize;
bool disableDataflow; // Skip dataflow analysis if possible
- std::map<unsigned int, BasicBlock*> blockMap; // findBlock lookup cache
- std::map<unsigned int, LIR*> boundaryMap; // boundary lookup cache
+ SafeMap<unsigned int, BasicBlock*> blockMap; // findBlock lookup cache
+ SafeMap<unsigned int, LIR*> boundaryMap; // boundary lookup cache
int defCount; // Used to estimate number of SSA names
// If non-empty, apply optimizer/debug flags only to matching methods.
diff --git a/src/compiler/Frontend.cc b/src/compiler/Frontend.cc
index 309bcf8..dbaf323 100644
--- a/src/compiler/Frontend.cc
+++ b/src/compiler/Frontend.cc
@@ -136,8 +136,7 @@
bottomBlock->lastMIRInsn = origBlock->lastMIRInsn;
/* Add it to the quick lookup cache */
- cUnit->blockMap.insert(std::make_pair(bottomBlock->startOffset,
- bottomBlock));
+ cUnit->blockMap.Put(bottomBlock->startOffset, bottomBlock);
/* Handle the taken path */
bottomBlock->taken = origBlock->taken;
@@ -211,7 +210,7 @@
GrowableList* blockList = &cUnit->blockList;
BasicBlock* bb;
unsigned int i;
- std::map<unsigned int, BasicBlock*>::iterator it;
+ SafeMap<unsigned int, BasicBlock*>::iterator it;
it = cUnit->blockMap.find(codeOffset);
if (it != cUnit->blockMap.end()) {
@@ -239,7 +238,7 @@
bb = oatNewBB(cUnit, kDalvikByteCode, cUnit->numBlocks++);
oatInsertGrowableList(cUnit, &cUnit->blockList, (intptr_t) bb);
bb->startOffset = codeOffset;
- cUnit->blockMap.insert(std::make_pair(bb->startOffset, bb));
+ cUnit->blockMap.Put(bb->startOffset, bb);
return bb;
}
@@ -853,7 +852,7 @@
curBlock->startOffset = 0;
oatInsertGrowableList(cUnit.get(), &cUnit->blockList, (intptr_t) curBlock);
/* Add first block to the fast lookup cache */
- cUnit->blockMap.insert(std::make_pair(curBlock->startOffset, curBlock));
+ cUnit->blockMap.Put(curBlock->startOffset, curBlock);
entryBlock->fallThrough = curBlock;
oatInsertGrowableList(cUnit.get(), curBlock->predecessors,
(intptr_t)entryBlock);
diff --git a/src/compiler/codegen/CodegenUtil.cc b/src/compiler/codegen/CodegenUtil.cc
index 00e78ec..777cf57 100644
--- a/src/compiler/codegen/CodegenUtil.cc
+++ b/src/compiler/codegen/CodegenUtil.cc
@@ -857,7 +857,7 @@
*/
LIR* insertCaseLabel(CompilationUnit* cUnit, int vaddr, int keyVal)
{
- std::map<unsigned int, LIR*>::iterator it;
+ SafeMap<unsigned int, LIR*>::iterator it;
it = cUnit->boundaryMap.find(vaddr);
if (it == cUnit->boundaryMap.end()) {
LOG(FATAL) << "Error: didn't find vaddr 0x" << std::hex << vaddr;
diff --git a/src/compiler/codegen/MethodCodegenDriver.cc b/src/compiler/codegen/MethodCodegenDriver.cc
index 0b8a19d..dd47359 100644
--- a/src/compiler/codegen/MethodCodegenDriver.cc
+++ b/src/compiler/codegen/MethodCodegenDriver.cc
@@ -883,8 +883,7 @@
oatGetDalvikDisassembly(cUnit, mir->dalvikInsn, "") : NULL;
boundaryLIR = newLIR1(cUnit, kPseudoDalvikByteCodeBoundary,
(intptr_t) instStr);
- cUnit->boundaryMap.insert(std::make_pair(mir->offset,
- (LIR*)boundaryLIR));
+ cUnit->boundaryMap.Overwrite(mir->offset, boundaryLIR);
/* Remember the first LIR for this block */
if (headLIR == NULL) {
headLIR = boundaryLIR;
diff --git a/src/compiler/codegen/arm/Thumb2/Gen.cc b/src/compiler/codegen/arm/Thumb2/Gen.cc
index fa51266..5451d57 100644
--- a/src/compiler/codegen/arm/Thumb2/Gen.cc
+++ b/src/compiler/codegen/arm/Thumb2/Gen.cc
@@ -133,8 +133,7 @@
oatGetDalvikDisassembly(cUnit, mir->dalvikInsn, "") : NULL;
boundaryLIR = newLIR1(cUnit, kPseudoDalvikByteCodeBoundary,
(intptr_t) instStr);
- cUnit->boundaryMap.insert(std::make_pair(mir->offset,
- (LIR*)boundaryLIR));
+ cUnit->boundaryMap.Put(mir->offset, boundaryLIR);
/* Don't generate the SSA annotation unless verbose mode is on */
if (cUnit->printMe && mir->ssaRep) {
char* ssaString = oatGetSSAString(cUnit, mir->ssaRep);