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