summaryrefslogtreecommitdiffstats
path: root/compiler/oat_writer.h
diff options
context:
space:
mode:
authorVladimir Marko <vmarko@google.com>2014-04-08 14:00:50 +0100
committerVladimir Marko <vmarko@google.com>2014-04-22 17:50:49 +0100
commit96c6ab93336b972a38bd2448bcccf19188b8389b (patch)
tree87c4904182d6b087e59a7c18d4a6b5b42275ef45 /compiler/oat_writer.h
parent82b1a81890970a8b07f9132aeae537a6c43df6b0 (diff)
downloadandroid_art-96c6ab93336b972a38bd2448bcccf19188b8389b.tar.gz
android_art-96c6ab93336b972a38bd2448bcccf19188b8389b.tar.bz2
android_art-96c6ab93336b972a38bd2448bcccf19188b8389b.zip
Separate maps from code in oat file.
Write all GC maps first, then all mapping tables and then all vmap tables and only then align the offset to page size and write all method code chunks with headers. Bug: 11767815 Change-Id: Ic83555c8303c5be119afc43e95e58c0a32ff2a4f
Diffstat (limited to 'compiler/oat_writer.h')
-rw-r--r--compiler/oat_writer.h101
1 files changed, 56 insertions, 45 deletions
diff --git a/compiler/oat_writer.h b/compiler/oat_writer.h
index bab1a26d44..1abacd831a 100644
--- a/compiler/oat_writer.h
+++ b/compiler/oat_writer.h
@@ -50,16 +50,30 @@ class OutputStream;
// ...
// OatClass[C]
//
+// GcMap one variable sized blob with GC map.
+// GcMap GC maps are deduplicated.
+// ...
+// GcMap
+//
+// VmapTable one variable sized VmapTable blob (quick compiler only).
+// VmapTable VmapTables are deduplicated.
+// ...
+// VmapTable
+//
+// MappingTable one variable sized blob with MappingTable (quick compiler only).
+// MappingTable MappingTables are deduplicated.
+// ...
+// MappingTable
+//
// padding if necessary so that the following code will be page aligned
//
-// CompiledMethod one variable sized blob with the contents of each CompiledMethod
-// CompiledMethod
-// CompiledMethod
-// CompiledMethod
-// CompiledMethod
-// CompiledMethod
+// OatMethodHeader fixed size header for a CompiledMethod including the size of the MethodCode.
+// MethodCode one variable sized blob with the code of a CompiledMethod.
+// OatMethodHeader (OatMethodHeader, MethodCode) pairs are deduplicated.
+// MethodCode
// ...
-// CompiledMethod
+// OatMethodHeader
+// MethodCode
//
class OatWriter {
public:
@@ -96,43 +110,47 @@ class OatWriter {
}
private:
+ // The DataAccess classes are helper classes that provide access to members related to
+ // a given map, i.e. GC map, mapping table or vmap table. By abstracting these away
+ // we can share a lot of code for processing the maps with template classes below.
+ struct GcMapDataAccess;
+ struct MappingTableDataAccess;
+ struct VmapTableDataAccess;
+
+ // The function VisitDexMethods() below iterates through all the methods in all
+ // the compiled dex files in order of their definitions. The method visitor
+ // classes provide individual bits of processing for each of the passes we need to
+ // first collect the data we want to write to the oat file and then, in later passes,
+ // to actually write it.
+ class DexMethodVisitor;
+ class OatDexMethodVisitor;
+ class InitOatClassesMethodVisitor;
+ class InitCodeMethodVisitor;
+ template <typename DataAccess>
+ class InitMapMethodVisitor;
+ class InitImageMethodVisitor;
+ class WriteCodeMethodVisitor;
+ template <typename DataAccess>
+ class WriteMapMethodVisitor;
+
+ // Visit all the methods in all the compiled dex files in their definition order
+ // with a given DexMethodVisitor.
+ bool VisitDexMethods(DexMethodVisitor* visitor);
+
size_t InitOatHeader();
size_t InitOatDexFiles(size_t offset);
size_t InitDexFiles(size_t offset);
size_t InitOatClasses(size_t offset);
+ size_t InitOatMaps(size_t offset);
size_t InitOatCode(size_t offset)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
size_t InitOatCodeDexFiles(size_t offset)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- size_t InitOatCodeDexFile(size_t offset,
- size_t* oat_class_index,
- const DexFile& dex_file)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- size_t InitOatCodeClassDef(size_t offset,
- size_t oat_class_index, size_t class_def_index,
- const DexFile& dex_file,
- const DexFile::ClassDef& class_def)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- size_t InitOatCodeMethod(size_t offset, size_t oat_class_index, size_t class_def_index,
- size_t class_def_method_index, size_t* method_offsets_index,
- bool is_native, InvokeType type, uint32_t method_idx, const DexFile&)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
bool WriteTables(OutputStream* out, const size_t file_offset);
- size_t WriteCode(OutputStream* out, const size_t file_offset);
+ size_t WriteMaps(OutputStream* out, const size_t file_offset, size_t relative_offset);
+ size_t WriteCode(OutputStream* out, const size_t file_offset, size_t relative_offset);
size_t WriteCodeDexFiles(OutputStream* out, const size_t file_offset, size_t relative_offset);
- size_t WriteCodeDexFile(OutputStream* out, const size_t file_offset, size_t relative_offset,
- size_t* oat_class_index, const DexFile& dex_file);
- size_t WriteCodeClassDef(OutputStream* out, const size_t file_offset, size_t relative_offset,
- size_t oat_class_index, const DexFile& dex_file,
- const DexFile::ClassDef& class_def);
- size_t WriteCodeMethod(OutputStream* out, const size_t file_offset, size_t relative_offset,
- size_t oat_class_index, size_t class_def_method_index,
- size_t* method_offsets_index, bool is_static, uint32_t method_idx,
- const DexFile& dex_file);
-
- void ReportWriteFailure(const char* what, uint32_t method_idx, const DexFile& dex_file,
- const OutputStream& out) const;
class OatDexFile {
public:
@@ -159,7 +177,7 @@ class OatWriter {
class OatClass {
public:
explicit OatClass(size_t offset,
- std::vector<CompiledMethod*>* compiled_methods,
+ const std::vector<CompiledMethod*>& compiled_methods,
uint32_t num_non_null_compiled_methods,
mirror::Class::Status status);
~OatClass();
@@ -170,8 +188,8 @@ class OatWriter {
bool Write(OatWriter* oat_writer, OutputStream* out, const size_t file_offset) const;
CompiledMethod* GetCompiledMethod(size_t class_def_method_index) const {
- DCHECK(compiled_methods_ != NULL);
- return (*compiled_methods_)[class_def_method_index];
+ DCHECK_LT(class_def_method_index, compiled_methods_.size());
+ return compiled_methods_[class_def_method_index];
}
// Offset of start of OatClass from beginning of OatHeader. It is
@@ -182,7 +200,7 @@ class OatWriter {
size_t offset_;
// CompiledMethods for each class_def_method_index, or NULL if no method is available.
- std::vector<CompiledMethod*>* compiled_methods_;
+ std::vector<CompiledMethod*> compiled_methods_;
// Offset from OatClass::offset_ to the OatMethodOffsets for the
// class_def_method_index. If 0, it means the corresponding
@@ -265,7 +283,7 @@ class OatWriter {
uint32_t size_quick_resolution_trampoline_;
uint32_t size_quick_to_interpreter_bridge_;
uint32_t size_trampoline_alignment_;
- uint32_t size_code_size_;
+ uint32_t size_method_header_;
uint32_t size_code_;
uint32_t size_code_alignment_;
uint32_t size_mapping_table_;
@@ -281,13 +299,6 @@ class OatWriter {
uint32_t size_oat_class_method_bitmaps_;
uint32_t size_oat_class_method_offsets_;
- // Code mappings for deduplication. Deduplication is already done on a pointer basis by the
- // compiler driver, so we can simply compare the pointers to find out if things are duplicated.
- SafeMap<const std::vector<uint8_t>*, uint32_t> code_offsets_;
- SafeMap<const std::vector<uint8_t>*, uint32_t> vmap_table_offsets_;
- SafeMap<const std::vector<uint8_t>*, uint32_t> mapping_table_offsets_;
- SafeMap<const std::vector<uint8_t>*, uint32_t> gc_map_offsets_;
-
DISALLOW_COPY_AND_ASSIGN(OatWriter);
};