diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/jit/jit_code_cache.cc | 3 | ||||
-rw-r--r-- | runtime/oat.h | 4 | ||||
-rw-r--r-- | runtime/oat_file-inl.h | 8 | ||||
-rw-r--r-- | runtime/oat_file.h | 1 | ||||
-rw-r--r-- | runtime/oat_quick_method_header.h | 54 |
5 files changed, 46 insertions, 24 deletions
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc index a9823e5638..c1b9a1a7de 100644 --- a/runtime/jit/jit_code_cache.cc +++ b/runtime/jit/jit_code_cache.cc @@ -990,7 +990,8 @@ uint8_t* JitCodeCache::CommitCodeInternal(Thread* self, } new (method_header) OatQuickMethodHeader( - (stack_map != nullptr) ? code_ptr - stack_map : 0u); + (stack_map != nullptr) ? code_ptr - stack_map : 0u, + code_size); DCHECK(!Runtime::Current()->IsAotCompiler()); if (has_should_deoptimize_flag) { diff --git a/runtime/oat.h b/runtime/oat.h index bd4a6e3ef3..b824729b3d 100644 --- a/runtime/oat.h +++ b/runtime/oat.h @@ -31,8 +31,8 @@ class InstructionSetFeatures; class PACKED(4) OatHeader { public: static constexpr uint8_t kOatMagic[] = { 'o', 'a', 't', '\n' }; - // Last oat version changed reason: Remove code size from OatQuickMethodHeader. - static constexpr uint8_t kOatVersion[] = { '1', '6', '8', '\0' }; + // Last oat version changed reason: Add code size to CodeInfo. + static constexpr uint8_t kOatVersion[] = { '1', '6', '7', '\0' }; static constexpr const char* kDex2OatCmdLineKey = "dex2oat-cmdline"; static constexpr const char* kDebuggableKey = "debuggable"; diff --git a/runtime/oat_file-inl.h b/runtime/oat_file-inl.h index 6ff86b84f3..b71c4e89d1 100644 --- a/runtime/oat_file-inl.h +++ b/runtime/oat_file-inl.h @@ -41,6 +41,14 @@ inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const { return reinterpret_cast<const uint8_t*>(method_header) - begin_; } +inline uint32_t OatFile::OatMethod::GetQuickCodeSizeOffset() const { + const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); + if (method_header == nullptr) { + return 0u; + } + return reinterpret_cast<const uint8_t*>(method_header->GetCodeSizeAddr()) - begin_; +} + inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const { const void* code = EntryPointToCodePointer(GetQuickCode()); if (code == nullptr) { diff --git a/runtime/oat_file.h b/runtime/oat_file.h index e2c66335c8..04b666c507 100644 --- a/runtime/oat_file.h +++ b/runtime/oat_file.h @@ -155,6 +155,7 @@ class OatFile { // Returns size of quick code. uint32_t GetQuickCodeSize() const; + uint32_t GetQuickCodeSizeOffset() const; // Returns OatQuickMethodHeader for debugging. Most callers should // use more specific methods such as GetQuickCodeSize. diff --git a/runtime/oat_quick_method_header.h b/runtime/oat_quick_method_header.h index 745be40245..6c123c4eb5 100644 --- a/runtime/oat_quick_method_header.h +++ b/runtime/oat_quick_method_header.h @@ -31,8 +31,12 @@ class ArtMethod; class PACKED(4) OatQuickMethodHeader { public: OatQuickMethodHeader() = default; - OatQuickMethodHeader(uint32_t code_info_offset) : code_info_offset_(code_info_offset) { - DCHECK_NE(code_info_offset, 0u); + OatQuickMethodHeader(uint32_t vmap_table_offset, + uint32_t code_size) + : vmap_table_offset_(vmap_table_offset), + code_size_(code_size) { + DCHECK_NE(vmap_table_offset, 0u); + DCHECK_NE(code_size, 0u); } static OatQuickMethodHeader* FromCodePointer(const void* code_ptr) { @@ -56,17 +60,17 @@ class PACKED(4) OatQuickMethodHeader { } bool IsOptimized() const { - return true; + return (code_size_ & kCodeSizeMask) != 0 && vmap_table_offset_ != 0; } const uint8_t* GetOptimizedCodeInfoPtr() const { - DCHECK_NE(code_info_offset_, 0u); - return code_ - GetVmapTableOffset(); + DCHECK(IsOptimized()); + return code_ - vmap_table_offset_; } uint8_t* GetOptimizedCodeInfoPtr() { - DCHECK_NE(code_info_offset_, 0u); - return code_ - GetVmapTableOffset(); + DCHECK(IsOptimized()); + return code_ - vmap_table_offset_; } const uint8_t* GetCode() const { @@ -74,26 +78,32 @@ class PACKED(4) OatQuickMethodHeader { } uint32_t GetCodeSize() const { - return CodeInfo::DecodeCodeSize(GetOptimizedCodeInfoPtr()); + DCHECK(IsOptimized()); + size_t code_size1 = code_size_ & kCodeSizeMask; + size_t code_size2 = CodeInfo::DecodeCodeSize(GetOptimizedCodeInfoPtr()); + DCHECK_EQ(code_size1, code_size2); + return code_size2; + } + + const uint32_t* GetCodeSizeAddr() const { + return &code_size_; } uint32_t GetVmapTableOffset() const { - return code_info_offset_ & kCodeInfoMask; + return vmap_table_offset_; } void SetVmapTableOffset(uint32_t offset) { - DCHECK(!HasShouldDeoptimizeFlag()); - code_info_offset_ = offset; - DCHECK_EQ(GetVmapTableOffset(), offset); + vmap_table_offset_ = offset; } const uint32_t* GetVmapTableOffsetAddr() const { - return &code_info_offset_; + return &vmap_table_offset_; } const uint8_t* GetVmapTable() const { CHECK(!IsOptimized()) << "Unimplemented vmap table for optimizing compiler"; - return (code_info_offset_ == 0) ? nullptr : code_ - code_info_offset_; + return (vmap_table_offset_ == 0) ? nullptr : code_ - vmap_table_offset_; } bool Contains(uintptr_t pc) const { @@ -139,21 +149,23 @@ class PACKED(4) OatQuickMethodHeader { uint32_t ToDexPc(ArtMethod* method, const uintptr_t pc, bool abort_on_failure = true) const; void SetHasShouldDeoptimizeFlag() { - DCHECK_EQ(code_info_offset_ & kShouldDeoptimizeMask, 0u); - code_info_offset_ |= kShouldDeoptimizeMask; + DCHECK_EQ(code_size_ & kShouldDeoptimizeMask, 0u); + code_size_ |= kShouldDeoptimizeMask; } bool HasShouldDeoptimizeFlag() const { - return (code_info_offset_ & kShouldDeoptimizeMask) != 0; + return (code_size_ & kShouldDeoptimizeMask) != 0; } private: static constexpr uint32_t kShouldDeoptimizeMask = 0x80000000; - static constexpr uint32_t kCodeInfoMask = ~kShouldDeoptimizeMask; + static constexpr uint32_t kCodeSizeMask = ~kShouldDeoptimizeMask; - // The offset in bytes from the start of the code_info to the end of the header. - // The highest bit is used to store the should_deoptimize flag. - uint32_t code_info_offset_ = 0u; + // The offset in bytes from the start of the vmap table to the end of the header. + uint32_t vmap_table_offset_ = 0u; + // The code size in bytes. The highest bit is used to signify if the compiled + // code with the method header has should_deoptimize flag. + uint32_t code_size_ = 0u; // The actual code. uint8_t code_[0]; }; |