Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_OAT_FILE_INL_H_ |
| 18 | #define ART_RUNTIME_OAT_FILE_INL_H_ |
| 19 | |
| 20 | #include "oat_file.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 24 | inline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 25 | const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_)); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 26 | if (code == nullptr) { |
| 27 | return nullptr; |
| 28 | } |
| 29 | // Return a pointer to the packed struct before the code. |
| 30 | return reinterpret_cast<const OatQuickMethodHeader*>(code) - 1; |
| 31 | } |
| 32 | |
| 33 | inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const { |
| 34 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 35 | if (method_header == nullptr) { |
| 36 | return 0u; |
| 37 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 38 | return reinterpret_cast<const uint8_t*>(method_header) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 41 | inline uint32_t OatFile::OatMethod::GetQuickCodeSizeOffset() const { |
| 42 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 43 | if (method_header == nullptr) { |
| 44 | return 0u; |
| 45 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 46 | return reinterpret_cast<const uint8_t*>(&method_header->code_size_) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 49 | inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 50 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 51 | if (code == nullptr) { |
| 52 | return 0u; |
| 53 | } |
| 54 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FrameSizeInBytes(); |
| 55 | } |
| 56 | |
| 57 | inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 58 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 59 | if (code == nullptr) { |
| 60 | return 0u; |
| 61 | } |
| 62 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.CoreSpillMask(); |
| 63 | } |
| 64 | |
| 65 | inline uint32_t OatFile::OatMethod::GetFpSpillMask() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 66 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 67 | if (code == nullptr) { |
| 68 | return 0u; |
| 69 | } |
| 70 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FpSpillMask(); |
| 71 | } |
| 72 | |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 73 | inline const uint8_t* OatFile::OatMethod::GetGcMap() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 74 | const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_)); |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 75 | if (code == nullptr) { |
| 76 | return nullptr; |
| 77 | } |
| 78 | uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].gc_map_offset_; |
| 79 | if (UNLIKELY(offset == 0u)) { |
| 80 | return nullptr; |
| 81 | } |
| 82 | return reinterpret_cast<const uint8_t*>(code) - offset; |
| 83 | } |
| 84 | |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 85 | inline uint32_t OatFile::OatMethod::GetGcMapOffset() const { |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 86 | const uint8_t* gc_map = GetGcMap(); |
| 87 | return static_cast<uint32_t>(gc_map != nullptr ? gc_map - begin_ : 0u); |
| 88 | } |
| 89 | |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 90 | inline uint32_t OatFile::OatMethod::GetGcMapOffsetOffset() const { |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 91 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 92 | if (method_header == nullptr) { |
| 93 | return 0u; |
| 94 | } |
| 95 | return reinterpret_cast<const uint8_t*>(&method_header->gc_map_offset_) - begin_; |
| 96 | } |
| 97 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 98 | inline uint32_t OatFile::OatMethod::GetMappingTableOffset() const { |
| 99 | const uint8_t* mapping_table = GetMappingTable(); |
| 100 | return static_cast<uint32_t>(mapping_table != nullptr ? mapping_table - begin_ : 0u); |
| 101 | } |
| 102 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 103 | inline uint32_t OatFile::OatMethod::GetMappingTableOffsetOffset() const { |
| 104 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 105 | if (method_header == nullptr) { |
| 106 | return 0u; |
| 107 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 108 | return reinterpret_cast<const uint8_t*>(&method_header->mapping_table_offset_) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 111 | inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const { |
| 112 | const uint8_t* vmap_table = GetVmapTable(); |
| 113 | return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u); |
| 114 | } |
| 115 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 116 | inline uint32_t OatFile::OatMethod::GetVmapTableOffsetOffset() const { |
| 117 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 118 | if (method_header == nullptr) { |
| 119 | return 0u; |
| 120 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 121 | return reinterpret_cast<const uint8_t*>(&method_header->vmap_table_offset_) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 124 | inline const uint8_t* OatFile::OatMethod::GetMappingTable() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 125 | const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_)); |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 126 | if (code == nullptr) { |
| 127 | return nullptr; |
| 128 | } |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 129 | uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].mapping_table_offset_; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 130 | if (UNLIKELY(offset == 0u)) { |
| 131 | return nullptr; |
| 132 | } |
| 133 | return reinterpret_cast<const uint8_t*>(code) - offset; |
| 134 | } |
| 135 | |
| 136 | inline const uint8_t* OatFile::OatMethod::GetVmapTable() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 137 | const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_)); |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 138 | if (code == nullptr) { |
| 139 | return nullptr; |
| 140 | } |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 141 | uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].vmap_table_offset_; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 142 | if (UNLIKELY(offset == 0u)) { |
| 143 | return nullptr; |
| 144 | } |
| 145 | return reinterpret_cast<const uint8_t*>(code) - offset; |
| 146 | } |
| 147 | |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 148 | inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 149 | const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_)); |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 150 | if (code == nullptr) { |
| 151 | return 0u; |
| 152 | } |
| 153 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_; |
| 154 | } |
| 155 | |
| 156 | inline uint32_t OatFile::OatMethod::GetCodeOffset() const { |
| 157 | return (GetQuickCodeSize() == 0) ? 0 : code_offset_; |
| 158 | } |
| 159 | |
| 160 | inline const void* OatFile::OatMethod::GetQuickCode() const { |
| 161 | return GetOatPointer<const void*>(GetCodeOffset()); |
| 162 | } |
| 163 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 164 | } // namespace art |
| 165 | |
| 166 | #endif // ART_RUNTIME_OAT_FILE_INL_H_ |