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" |
Santiago Aboy Solanes | 69a87e3 | 2022-03-08 16:43:54 +0000 | [diff] [blame] | 24 | #include "runtime-inl.h" |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 28 | inline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const { |
Peter Collingbourne | 584b197 | 2022-02-08 17:48:42 -0800 | [diff] [blame] | 29 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 30 | if (code == nullptr) { |
| 31 | return nullptr; |
| 32 | } |
| 33 | // Return a pointer to the packed struct before the code. |
| 34 | return reinterpret_cast<const OatQuickMethodHeader*>(code) - 1; |
| 35 | } |
| 36 | |
| 37 | inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const { |
| 38 | const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); |
| 39 | if (method_header == nullptr) { |
| 40 | return 0u; |
| 41 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 42 | return reinterpret_cast<const uint8_t*>(method_header) - begin_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 45 | inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 46 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 47 | if (code == nullptr) { |
| 48 | return 0u; |
| 49 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 50 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FrameSizeInBytes(); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 54 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 55 | if (code == nullptr) { |
| 56 | return 0u; |
| 57 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 58 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().CoreSpillMask(); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | inline uint32_t OatFile::OatMethod::GetFpSpillMask() const { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 62 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 63 | if (code == nullptr) { |
| 64 | return 0u; |
| 65 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 66 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FpSpillMask(); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 69 | inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const { |
| 70 | const uint8_t* vmap_table = GetVmapTable(); |
| 71 | return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u); |
| 72 | } |
| 73 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 74 | inline const uint8_t* OatFile::OatMethod::GetVmapTable() const { |
Peter Collingbourne | 584b197 | 2022-02-08 17:48:42 -0800 | [diff] [blame] | 75 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 76 | if (code == nullptr) { |
| 77 | return nullptr; |
| 78 | } |
David Srbecky | 113d6ea | 2021-03-02 22:49:46 +0000 | [diff] [blame] | 79 | uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeInfoOffset(); |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 80 | if (UNLIKELY(offset == 0u)) { |
| 81 | return nullptr; |
| 82 | } |
| 83 | return reinterpret_cast<const uint8_t*>(code) - offset; |
| 84 | } |
| 85 | |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 86 | inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const { |
Peter Collingbourne | 584b197 | 2022-02-08 17:48:42 -0800 | [diff] [blame] | 87 | const void* code = EntryPointToCodePointer(GetQuickCode()); |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 88 | if (code == nullptr) { |
| 89 | return 0u; |
| 90 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 91 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeSize(); |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 94 | inline const void* OatFile::OatMethod::GetQuickCode() const { |
Peter Collingbourne | 584b197 | 2022-02-08 17:48:42 -0800 | [diff] [blame] | 95 | if (code_offset_ == 0) { |
| 96 | return nullptr; |
| 97 | } |
| 98 | return reinterpret_cast<const void *>(begin_ + code_offset_); |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Santiago Aboy Solanes | 69a87e3 | 2022-03-08 16:43:54 +0000 | [diff] [blame] | 101 | inline const OatFile::BssMappingInfo* OatFile::FindBcpMappingInfo(const DexFile* dex_file) const { |
| 102 | ArrayRef<const OatFile::BssMappingInfo> mapping_info_vector(GetBcpBssInfo()); |
| 103 | ArrayRef<const DexFile* const> bcp_dexfiles( |
| 104 | Runtime::Current()->GetClassLinker()->GetBootClassPath()); |
| 105 | // Create a sub array to limit search range. |
| 106 | bcp_dexfiles = bcp_dexfiles.SubArray(/*pos=*/ 0u, mapping_info_vector.size()); |
| 107 | auto it = std::find(bcp_dexfiles.begin(), bcp_dexfiles.end(), dex_file); |
| 108 | if (it != bcp_dexfiles.end()) { |
| 109 | return &mapping_info_vector[std::distance(bcp_dexfiles.begin(), it)]; |
| 110 | } else { |
| 111 | return nullptr; |
| 112 | } |
| 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_ |