Merge "Store the instruction set in the oat header, and use it in oatdump." into dalvik-dev
diff --git a/src/oat.cc b/src/oat.cc
index 1a884e3..e747a8b 100644
--- a/src/oat.cc
+++ b/src/oat.cc
@@ -23,10 +23,16 @@
const uint8_t OatHeader::kOatMagic[] = { 'o', 'a', 't', '\n' };
const uint8_t OatHeader::kOatVersion[] = { '0', '0', '1', '\0' };
-OatHeader::OatHeader(const std::vector<const DexFile*>* dex_files) {
+OatHeader::OatHeader() {
+ memset(this, 0, sizeof(*this));
+}
+
+OatHeader::OatHeader(InstructionSet instruction_set, const std::vector<const DexFile*>* dex_files) {
memcpy(magic_, kOatMagic, sizeof(kOatMagic));
memcpy(version_, kOatVersion, sizeof(kOatVersion));
adler32_checksum_ = adler32(0L, Z_NULL, 0);
+ instruction_set_ = instruction_set;
+ UpdateChecksum(&instruction_set_, sizeof(instruction_set_));
dex_file_count_ = dex_files->size();
UpdateChecksum(&dex_file_count_, sizeof(dex_file_count_));
executable_offset_ = 0;
@@ -63,6 +69,11 @@
adler32_checksum_ = adler32(adler32_checksum_, bytes, length);
}
+InstructionSet OatHeader::GetInstructionSet() const {
+ CHECK(IsValid());
+ return instruction_set_;
+}
+
uint32_t OatHeader::GetExecutableOffset() const {
DCHECK(IsValid());
DCHECK_ALIGNED(executable_offset_, kPageSize);
diff --git a/src/oat.h b/src/oat.h
index 23e25af..2f3cf9d 100644
--- a/src/oat.h
+++ b/src/oat.h
@@ -19,6 +19,7 @@
#include <vector>
+#include "constants.h"
#include "dex_file.h"
#include "macros.h"
@@ -26,8 +27,8 @@
class PACKED OatHeader {
public:
- OatHeader() {}
- OatHeader(const std::vector<const DexFile*>* dex_files);
+ OatHeader();
+ OatHeader(InstructionSet instruction_set, const std::vector<const DexFile*>* dex_files);
bool IsValid() const;
const char* GetMagic() const;
@@ -35,6 +36,7 @@
void UpdateChecksum(const void* data, size_t length);
uint32_t GetDexFileCount() const;
uint32_t GetExecutableOffset() const;
+ InstructionSet GetInstructionSet() const;
void SetExecutableOffset(uint32_t executable_offset);
private:
@@ -44,6 +46,8 @@
uint8_t magic_[4];
uint8_t version_[4];
uint32_t adler32_checksum_;
+
+ InstructionSet instruction_set_;
uint32_t dex_file_count_;
uint32_t executable_offset_;
diff --git a/src/oat_writer.cc b/src/oat_writer.cc
index a4a4a2c..9f416f1 100644
--- a/src/oat_writer.cc
+++ b/src/oat_writer.cc
@@ -41,7 +41,7 @@
oat_header_ = NULL;
executable_offset_padding_length_ = 0;
- size_t offset = InitOatHeader();
+ size_t offset = InitOatHeader(compiler.GetInstructionSet());
offset = InitOatDexFiles(offset);
offset = InitDexFiles(offset);
offset = InitOatClasses(offset);
@@ -57,9 +57,9 @@
STLDeleteElements(&oat_classes_);
}
-size_t OatWriter::InitOatHeader() {
+size_t OatWriter::InitOatHeader(InstructionSet instruction_set) {
// create the OatHeader
- oat_header_ = new OatHeader(dex_files_);
+ oat_header_ = new OatHeader(instruction_set, dex_files_);
size_t offset = sizeof(*oat_header_);
return offset;
}
diff --git a/src/oat_writer.h b/src/oat_writer.h
index abb1f2e..cdc061f 100644
--- a/src/oat_writer.h
+++ b/src/oat_writer.h
@@ -73,7 +73,7 @@
const Compiler& compiler);
~OatWriter();
- size_t InitOatHeader();
+ size_t InitOatHeader(InstructionSet instruction_set);
size_t InitOatDexFiles(size_t offset);
size_t InitDexFiles(size_t offset);
size_t InitOatClasses(size_t offset);
diff --git a/src/oatdump.cc b/src/oatdump.cc
index c7b8151..d2ceb5e 100644
--- a/src/oatdump.cc
+++ b/src/oatdump.cc
@@ -86,8 +86,8 @@
class OatDumper {
public:
explicit OatDumper(const OatFile& oat_file) : oat_file_(oat_file),
- oat_dex_files_(oat_file.GetOatDexFiles()), disassembler_(Disassembler::Create(kArm)) {
- // TODO: the disassembler should find the oat file instruction set from the oat header
+ oat_dex_files_(oat_file.GetOatDexFiles()),
+ disassembler_(Disassembler::Create(oat_file_.GetOatHeader().GetInstructionSet())) {
AddAllOffsets();
}
@@ -100,6 +100,9 @@
os << "CHECKSUM:\n";
os << StringPrintf("0x%08x\n\n", oat_header.GetChecksum());
+ os << "INSTRUCTION SET:\n";
+ os << oat_header.GetInstructionSet() << "\n\n";
+
os << "DEX FILE COUNT:\n";
os << oat_header.GetDexFileCount() << "\n\n";