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" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 21 | #include "oat_quick_method_header.h" |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 25 | inline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 26 | const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_)); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 27 | if (code == nullptr) { |
| 28 | return nullptr; |
| 29 | } |
| 30 | // Return a pointer to the packed struct before the code. |
| 31 | return reinterpret_cast<const OatQuickMethodHeader*>(code) - 1; |
| 32 | } |
| 33 | |
| 34 | inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const { |
| 35 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 36 | if (method_header == nullptr) { |
| 37 | return 0u; |
| 38 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 39 | return reinterpret_cast<const uint8_t*>(method_header) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 42 | inline uint32_t OatFile::OatMethod::GetQuickCodeSizeOffset() const { |
| 43 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 44 | if (method_header == nullptr) { |
| 45 | return 0u; |
| 46 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 47 | return reinterpret_cast<const uint8_t*>(&method_header->code_size_) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 50 | inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 51 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 52 | if (code == nullptr) { |
| 53 | return 0u; |
| 54 | } |
| 55 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FrameSizeInBytes(); |
| 56 | } |
| 57 | |
| 58 | inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 59 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 60 | if (code == nullptr) { |
| 61 | return 0u; |
| 62 | } |
| 63 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.CoreSpillMask(); |
| 64 | } |
| 65 | |
| 66 | inline uint32_t OatFile::OatMethod::GetFpSpillMask() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 67 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 68 | if (code == nullptr) { |
| 69 | return 0u; |
| 70 | } |
| 71 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FpSpillMask(); |
| 72 | } |
| 73 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 74 | inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const { |
| 75 | const uint8_t* vmap_table = GetVmapTable(); |
| 76 | return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u); |
| 77 | } |
| 78 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 79 | inline uint32_t OatFile::OatMethod::GetVmapTableOffsetOffset() const { |
| 80 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 81 | if (method_header == nullptr) { |
| 82 | return 0u; |
| 83 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 84 | return reinterpret_cast<const uint8_t*>(&method_header->vmap_table_offset_) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 87 | inline const uint8_t* OatFile::OatMethod::GetVmapTable() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 88 | const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_)); |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 89 | if (code == nullptr) { |
| 90 | return nullptr; |
| 91 | } |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 92 | uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].vmap_table_offset_; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 93 | if (UNLIKELY(offset == 0u)) { |
| 94 | return nullptr; |
| 95 | } |
| 96 | return reinterpret_cast<const uint8_t*>(code) - offset; |
| 97 | } |
| 98 | |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 99 | inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 100 | const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_)); |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 101 | if (code == nullptr) { |
| 102 | return 0u; |
| 103 | } |
| 104 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_; |
| 105 | } |
| 106 | |
| 107 | inline uint32_t OatFile::OatMethod::GetCodeOffset() const { |
| 108 | return (GetQuickCodeSize() == 0) ? 0 : code_offset_; |
| 109 | } |
| 110 | |
| 111 | inline const void* OatFile::OatMethod::GetQuickCode() const { |
| 112 | return GetOatPointer<const void*>(GetCodeOffset()); |
| 113 | } |
| 114 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 115 | } // namespace art |
| 116 | |
| 117 | #endif // ART_RUNTIME_OAT_FILE_INL_H_ |