1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2014 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_RUNTIME_OAT_OAT_FILE_INL_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_RUNTIME_OAT_OAT_FILE_INL_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include "oat_file.h" 21*795d594fSAndroid Build Coastguard Worker 22*795d594fSAndroid Build Coastguard Worker #include "base/utils.h" 23*795d594fSAndroid Build Coastguard Worker #include "oat_quick_method_header.h" 24*795d594fSAndroid Build Coastguard Worker #include "runtime-inl.h" 25*795d594fSAndroid Build Coastguard Worker 26*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN { 27*795d594fSAndroid Build Coastguard Worker GetOatQuickMethodHeader()28*795d594fSAndroid Build Coastguard Workerinline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const { 29*795d594fSAndroid Build Coastguard Worker const void* code = EntryPointToCodePointer(GetQuickCode()); 30*795d594fSAndroid Build Coastguard Worker if (code == nullptr) { 31*795d594fSAndroid Build Coastguard Worker return nullptr; 32*795d594fSAndroid Build Coastguard Worker } 33*795d594fSAndroid Build Coastguard Worker // Return a pointer to the packed struct before the code. 34*795d594fSAndroid Build Coastguard Worker return reinterpret_cast<const OatQuickMethodHeader*>(code) - 1; 35*795d594fSAndroid Build Coastguard Worker } 36*795d594fSAndroid Build Coastguard Worker GetOatQuickMethodHeaderOffset()37*795d594fSAndroid Build Coastguard Workerinline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const { 38*795d594fSAndroid Build Coastguard Worker const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader(); 39*795d594fSAndroid Build Coastguard Worker if (method_header == nullptr) { 40*795d594fSAndroid Build Coastguard Worker return 0u; 41*795d594fSAndroid Build Coastguard Worker } 42*795d594fSAndroid Build Coastguard Worker return reinterpret_cast<const uint8_t*>(method_header) - begin_; 43*795d594fSAndroid Build Coastguard Worker } 44*795d594fSAndroid Build Coastguard Worker GetFrameSizeInBytes()45*795d594fSAndroid Build Coastguard Workerinline size_t OatFile::OatMethod::GetFrameSizeInBytes() const { 46*795d594fSAndroid Build Coastguard Worker const void* code = EntryPointToCodePointer(GetQuickCode()); 47*795d594fSAndroid Build Coastguard Worker if (code == nullptr) { 48*795d594fSAndroid Build Coastguard Worker return 0u; 49*795d594fSAndroid Build Coastguard Worker } 50*795d594fSAndroid Build Coastguard Worker return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FrameSizeInBytes(); 51*795d594fSAndroid Build Coastguard Worker } 52*795d594fSAndroid Build Coastguard Worker GetCoreSpillMask()53*795d594fSAndroid Build Coastguard Workerinline uint32_t OatFile::OatMethod::GetCoreSpillMask() const { 54*795d594fSAndroid Build Coastguard Worker const void* code = EntryPointToCodePointer(GetQuickCode()); 55*795d594fSAndroid Build Coastguard Worker if (code == nullptr) { 56*795d594fSAndroid Build Coastguard Worker return 0u; 57*795d594fSAndroid Build Coastguard Worker } 58*795d594fSAndroid Build Coastguard Worker return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().CoreSpillMask(); 59*795d594fSAndroid Build Coastguard Worker } 60*795d594fSAndroid Build Coastguard Worker GetFpSpillMask()61*795d594fSAndroid Build Coastguard Workerinline uint32_t OatFile::OatMethod::GetFpSpillMask() const { 62*795d594fSAndroid Build Coastguard Worker const void* code = EntryPointToCodePointer(GetQuickCode()); 63*795d594fSAndroid Build Coastguard Worker if (code == nullptr) { 64*795d594fSAndroid Build Coastguard Worker return 0u; 65*795d594fSAndroid Build Coastguard Worker } 66*795d594fSAndroid Build Coastguard Worker return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FpSpillMask(); 67*795d594fSAndroid Build Coastguard Worker } 68*795d594fSAndroid Build Coastguard Worker GetVmapTableOffset()69*795d594fSAndroid Build Coastguard Workerinline uint32_t OatFile::OatMethod::GetVmapTableOffset() const { 70*795d594fSAndroid Build Coastguard Worker const uint8_t* vmap_table = GetVmapTable(); 71*795d594fSAndroid Build Coastguard Worker return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u); 72*795d594fSAndroid Build Coastguard Worker } 73*795d594fSAndroid Build Coastguard Worker GetVmapTable()74*795d594fSAndroid Build Coastguard Workerinline const uint8_t* OatFile::OatMethod::GetVmapTable() const { 75*795d594fSAndroid Build Coastguard Worker const void* code = EntryPointToCodePointer(GetQuickCode()); 76*795d594fSAndroid Build Coastguard Worker if (code == nullptr) { 77*795d594fSAndroid Build Coastguard Worker return nullptr; 78*795d594fSAndroid Build Coastguard Worker } 79*795d594fSAndroid Build Coastguard Worker uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeInfoOffset(); 80*795d594fSAndroid Build Coastguard Worker if (UNLIKELY(offset == 0u)) { 81*795d594fSAndroid Build Coastguard Worker return nullptr; 82*795d594fSAndroid Build Coastguard Worker } 83*795d594fSAndroid Build Coastguard Worker return reinterpret_cast<const uint8_t*>(code) - offset; 84*795d594fSAndroid Build Coastguard Worker } 85*795d594fSAndroid Build Coastguard Worker GetQuickCodeSize()86*795d594fSAndroid Build Coastguard Workerinline uint32_t OatFile::OatMethod::GetQuickCodeSize() const { 87*795d594fSAndroid Build Coastguard Worker const void* code = EntryPointToCodePointer(GetQuickCode()); 88*795d594fSAndroid Build Coastguard Worker if (code == nullptr) { 89*795d594fSAndroid Build Coastguard Worker return 0u; 90*795d594fSAndroid Build Coastguard Worker } 91*795d594fSAndroid Build Coastguard Worker return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeSize(); 92*795d594fSAndroid Build Coastguard Worker } 93*795d594fSAndroid Build Coastguard Worker GetQuickCode()94*795d594fSAndroid Build Coastguard Workerinline const void* OatFile::OatMethod::GetQuickCode() const { 95*795d594fSAndroid Build Coastguard Worker if (code_offset_ == 0) { 96*795d594fSAndroid Build Coastguard Worker return nullptr; 97*795d594fSAndroid Build Coastguard Worker } 98*795d594fSAndroid Build Coastguard Worker return reinterpret_cast<const void *>(begin_ + code_offset_); 99*795d594fSAndroid Build Coastguard Worker } 100*795d594fSAndroid Build Coastguard Worker FindBcpMappingInfo(const DexFile * dex_file)101*795d594fSAndroid Build Coastguard Workerinline const OatFile::BssMappingInfo* OatFile::FindBcpMappingInfo(const DexFile* dex_file) const { 102*795d594fSAndroid Build Coastguard Worker ArrayRef<const OatFile::BssMappingInfo> mapping_info_vector(GetBcpBssInfo()); 103*795d594fSAndroid Build Coastguard Worker ArrayRef<const DexFile* const> bcp_dexfiles( 104*795d594fSAndroid Build Coastguard Worker Runtime::Current()->GetClassLinker()->GetBootClassPath()); 105*795d594fSAndroid Build Coastguard Worker // Create a sub array to limit search range. 106*795d594fSAndroid Build Coastguard Worker bcp_dexfiles = bcp_dexfiles.SubArray(/*pos=*/ 0u, mapping_info_vector.size()); 107*795d594fSAndroid Build Coastguard Worker auto it = std::find(bcp_dexfiles.begin(), bcp_dexfiles.end(), dex_file); 108*795d594fSAndroid Build Coastguard Worker if (it != bcp_dexfiles.end()) { 109*795d594fSAndroid Build Coastguard Worker return &mapping_info_vector[std::distance(bcp_dexfiles.begin(), it)]; 110*795d594fSAndroid Build Coastguard Worker } else { 111*795d594fSAndroid Build Coastguard Worker return nullptr; 112*795d594fSAndroid Build Coastguard Worker } 113*795d594fSAndroid Build Coastguard Worker } 114*795d594fSAndroid Build Coastguard Worker 115*795d594fSAndroid Build Coastguard Worker } // namespace art 116*795d594fSAndroid Build Coastguard Worker 117*795d594fSAndroid Build Coastguard Worker #endif // ART_RUNTIME_OAT_OAT_FILE_INL_H_ 118