Better detection of duplicate compiled methods/invoke stubs.
Change-Id: I491ba30e0a7573d1c090aab9ff9ac26aae4d004e
diff --git a/src/compiler.cc b/src/compiler.cc
index b62c40b..ee771c5 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -304,18 +304,20 @@
}
void Compiler::CompileMethod(const Method* method) {
+ CompiledMethod* compiled_method = NULL;
if (method->IsNative()) {
- CompiledMethod* compiled_method = jni_compiler_.Compile(method);
+ compiled_method = jni_compiler_.Compile(method);
CHECK(compiled_method != NULL);
- compiled_methods_[method] = compiled_method;
- DCHECK_EQ(1U, compiled_methods_.count(method));
- DCHECK(GetCompiledMethod(method) != NULL) << PrettyMethod(method);
} else if (method->IsAbstract()) {
} else {
CompiledMethod* compiled_method = oatCompileMethod(*this, method, kThumb2);
CHECK(compiled_method != NULL);
+ }
+
+ if (compiled_method != NULL) {
+ CHECK(compiled_methods_.find(method) == compiled_methods_.end()) << PrettyMethod(method);
compiled_methods_[method] = compiled_method;
- DCHECK_EQ(1U, compiled_methods_.count(method));
+ DCHECK(compiled_methods_.find(method) != compiled_methods_.end()) << PrettyMethod(method);
DCHECK(GetCompiledMethod(method) != NULL) << PrettyMethod(method);
}
@@ -328,6 +330,8 @@
compiled_invoke_stub = art::arm::ArmCreateInvokeStub(method);
}
CHECK(compiled_invoke_stub != NULL);
+ // TODO: this fails if we have an abstract method defined in more than one input dex file.
+ CHECK(compiled_invoke_stubs_.find(method) == compiled_invoke_stubs_.end()) << PrettyMethod(method);
compiled_invoke_stubs_[method] = compiled_invoke_stub;
}
diff --git a/src/oat_writer.cc b/src/oat_writer.cc
index 931dbc1..8c48f73 100644
--- a/src/oat_writer.cc
+++ b/src/oat_writer.cc
@@ -386,9 +386,7 @@
return code_offset;
}
-size_t OatWriter::WriteCodeMethod(File* file,
- size_t code_offset,
- Method* method) {
+size_t OatWriter::WriteCodeMethod(File* file, size_t code_offset, Method* method) {
const CompiledMethod* compiled_method = compiler_->GetCompiledMethod(method);
if (compiled_method != NULL) {
uint32_t aligned_code_offset = compiled_method->AlignCode(code_offset);
@@ -484,7 +482,7 @@
const std::vector<uint8_t>& invoke_stub = compiled_invoke_stub->GetCode();
size_t invoke_stub_size = invoke_stub.size() * sizeof(invoke_stub[0]);
DCHECK((invoke_stub_size == 0 && method->GetOatInvokeStubOffset() == 0)
- || code_offset == method->GetOatInvokeStubOffset());
+ || code_offset == method->GetOatInvokeStubOffset()) << PrettyMethod(method);
if (!file->WriteFully(&invoke_stub[0], invoke_stub_size)) {
PLOG(ERROR) << "Failed to write invoke stub code for " << PrettyMethod(method);
return false;