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 { |
| 25 | const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode()); |
| 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 | |
| 41 | inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const { |
| 42 | const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode()); |
| 43 | if (code == nullptr) { |
| 44 | return 0u; |
| 45 | } |
| 46 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_; |
| 47 | } |
| 48 | |
| 49 | inline uint32_t OatFile::OatMethod::GetQuickCodeSizeOffset() const { |
| 50 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 51 | if (method_header == nullptr) { |
| 52 | return 0u; |
| 53 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 54 | return reinterpret_cast<const uint8_t*>(&method_header->code_size_) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 57 | inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const { |
| 58 | const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode()); |
| 59 | if (code == nullptr) { |
| 60 | return 0u; |
| 61 | } |
| 62 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FrameSizeInBytes(); |
| 63 | } |
| 64 | |
| 65 | inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const { |
| 66 | const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode()); |
| 67 | if (code == nullptr) { |
| 68 | return 0u; |
| 69 | } |
| 70 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.CoreSpillMask(); |
| 71 | } |
| 72 | |
| 73 | inline uint32_t OatFile::OatMethod::GetFpSpillMask() const { |
| 74 | const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode()); |
| 75 | if (code == nullptr) { |
| 76 | return 0u; |
| 77 | } |
| 78 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FpSpillMask(); |
| 79 | } |
| 80 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 81 | inline uint32_t OatFile::OatMethod::GetMappingTableOffset() const { |
| 82 | const uint8_t* mapping_table = GetMappingTable(); |
| 83 | return static_cast<uint32_t>(mapping_table != nullptr ? mapping_table - begin_ : 0u); |
| 84 | } |
| 85 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 86 | inline uint32_t OatFile::OatMethod::GetMappingTableOffsetOffset() const { |
| 87 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 88 | if (method_header == nullptr) { |
| 89 | return 0u; |
| 90 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 91 | return reinterpret_cast<const uint8_t*>(&method_header->mapping_table_offset_) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 94 | inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const { |
| 95 | const uint8_t* vmap_table = GetVmapTable(); |
| 96 | return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u); |
| 97 | } |
| 98 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 99 | inline uint32_t OatFile::OatMethod::GetVmapTableOffsetOffset() const { |
| 100 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 101 | if (method_header == nullptr) { |
| 102 | return 0u; |
| 103 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 104 | return reinterpret_cast<const uint8_t*>(&method_header->vmap_table_offset_) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 107 | inline const uint8_t* OatFile::OatMethod::GetMappingTable() const { |
| 108 | const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode()); |
| 109 | if (code == nullptr) { |
| 110 | return nullptr; |
| 111 | } |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 112 | uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].mapping_table_offset_; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 113 | if (UNLIKELY(offset == 0u)) { |
| 114 | return nullptr; |
| 115 | } |
| 116 | return reinterpret_cast<const uint8_t*>(code) - offset; |
| 117 | } |
| 118 | |
| 119 | inline const uint8_t* OatFile::OatMethod::GetVmapTable() const { |
| 120 | const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode()); |
| 121 | if (code == nullptr) { |
| 122 | return nullptr; |
| 123 | } |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 124 | uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].vmap_table_offset_; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 125 | if (UNLIKELY(offset == 0u)) { |
| 126 | return nullptr; |
| 127 | } |
| 128 | return reinterpret_cast<const uint8_t*>(code) - offset; |
| 129 | } |
| 130 | |
| 131 | } // namespace art |
| 132 | |
| 133 | #endif // ART_RUNTIME_OAT_FILE_INL_H_ |