summaryrefslogtreecommitdiff
path: root/src/compiler/codegen
diff options
context:
space:
mode:
author buzbee <buzbee@google.com> 2012-10-02 14:42:41 -0700
committer buzbee <buzbee@google.com> 2012-10-02 14:47:03 -0700
commit6459e7cb35ca83ffc2f266dddeb83673bc07ecd4 (patch)
tree59e96c590c48158c3b5474ba2f1a2e09b1ec5721 /src/compiler/codegen
parent3e96a16c27c986275f60afe682d0b2a3064f45c9 (diff)
Enable bitcode verification for debug builds
Turn bitcode function verification on for debug Quick and Portable builds. Also in this CL, some sanity checking for the dex2pc table and a temporary workaround for excessive filename lengths for bitcode file dumps. Change-Id: I430ed28824b078c03be7826cb13876cdcb8a0fec
Diffstat (limited to 'src/compiler/codegen')
-rw-r--r--src/compiler/codegen/CodegenUtil.cc35
-rw-r--r--src/compiler/codegen/MethodBitcode.cc13
2 files changed, 47 insertions, 1 deletions
diff --git a/src/compiler/codegen/CodegenUtil.cc b/src/compiler/codegen/CodegenUtil.cc
index 22aacc2497..ccc2a83f7e 100644
--- a/src/compiler/codegen/CodegenUtil.cc
+++ b/src/compiler/codegen/CodegenUtil.cc
@@ -764,6 +764,40 @@ int assignLiteralOffsetCommon(LIR* lir, int offset)
return offset;
}
+// Make sure we have a code address for every declared catch entry
+bool verifyCatchEntries(CompilationUnit* cUnit)
+{
+ bool success = true;
+ for (std::set<uint32_t>::const_iterator it = cUnit->catches.begin(); it != cUnit->catches.end(); ++it) {
+ uint32_t dexPc = *it;
+ bool found = false;
+ for (size_t i = 0; i < cUnit->dex2pcMappingTable.size(); i += 2) {
+ if (dexPc == cUnit->dex2pcMappingTable[i+1]) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ LOG(INFO) << "Missing native PC for catch entry @ 0x" << std::hex << dexPc;
+ success = false;
+ }
+ }
+ // Now, try in the other direction
+ for (size_t i = 0; i < cUnit->dex2pcMappingTable.size(); i += 2) {
+ uint32_t dexPc = cUnit->dex2pcMappingTable[i+1];
+ if (cUnit->catches.find(dexPc) == cUnit->catches.end()) {
+ LOG(INFO) << "Unexpected catch entry @ dex pc 0x" << std::hex << dexPc;
+ success = false;
+ }
+ }
+ if (!success) {
+ LOG(INFO) << "Bad dex2pcMapping table in " << PrettyMethod(cUnit->method_idx, *cUnit->dex_file);
+ LOG(INFO) << "Entries @ decode: " << cUnit->catches.size() << ", Entries in table: "
+ << cUnit->dex2pcMappingTable.size()/2;
+ }
+ return success;
+}
+
void createMappingTables(CompilationUnit* cUnit)
{
for (LIR* tgtLIR = (LIR *) cUnit->firstLIRInsn; tgtLIR != NULL; tgtLIR = NEXT_LIR(tgtLIR)) {
@@ -776,6 +810,7 @@ void createMappingTables(CompilationUnit* cUnit)
cUnit->dex2pcMappingTable.push_back(tgtLIR->dalvikOffset);
}
}
+ DCHECK(verifyCatchEntries(cUnit));
cUnit->combinedMappingTable.push_back(cUnit->pc2dexMappingTable.size() +
cUnit->dex2pcMappingTable.size());
cUnit->combinedMappingTable.push_back(cUnit->pc2dexMappingTable.size());
diff --git a/src/compiler/codegen/MethodBitcode.cc b/src/compiler/codegen/MethodBitcode.cc
index cff4ee5112..a9e134f287 100644
--- a/src/compiler/codegen/MethodBitcode.cc
+++ b/src/compiler/codegen/MethodBitcode.cc
@@ -540,10 +540,16 @@ void setShadowFrameEntry(CompilationUnit* cUnit, llvm::Value* newVal)
if (index == -1) {
return;
}
+ llvm::Type* ty = newVal->getType();
greenland::IntrinsicHelper::IntrinsicId id =
greenland::IntrinsicHelper::SetShadowFrameEntry;
llvm::Function* func = cUnit->intrinsic_helper->GetIntrinsicFunction(id);
llvm::Value* tableSlot = cUnit->irb->getInt32(index);
+ // If newVal is a Null pointer, we'll see it here as a const int. Replace
+ if (!ty->isPointerTy()) {
+ // TODO: assert newVal created w/ dex_lang_const_int(0) or dex_lang_const_float(0)
+ newVal = cUnit->irb->GetJNull();
+ }
llvm::Value* args[] = { newVal, tableSlot };
cUnit->irb->CreateCall(func, args);
}
@@ -2112,9 +2118,14 @@ void oatMethodMIR2Bitcode(CompilationUnit* cUnit)
std::string errmsg;
std::string fname(PrettyMethod(cUnit->method_idx, *cUnit->dex_file));
oatReplaceSpecialChars(fname);
- // TODO: make configurable
+ // TODO: make configurable change naming mechanism to avoid fname length issues.
fname = StringPrintf("/sdcard/Bitcode/%s.bc", fname.c_str());
+ if (fname.size() > 240) {
+ LOG(INFO) << "Warning: bitcode filename too long. Truncated.";
+ fname.resize(240);
+ }
+
llvm::OwningPtr<llvm::tool_output_file> out_file(
new llvm::tool_output_file(fname.c_str(), errmsg,
llvm::raw_fd_ostream::F_Binary));