Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | #include "oat_quick_method_header.h" |
| 18 | |
| 19 | #include "art_method.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 20 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 21 | #include "thread.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 25 | OatQuickMethodHeader::OatQuickMethodHeader(uint32_t vmap_table_offset, |
| 26 | uint32_t method_info_offset, |
| 27 | uint32_t frame_size_in_bytes, |
| 28 | uint32_t core_spill_mask, |
| 29 | uint32_t fp_spill_mask, |
| 30 | uint32_t code_size) |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 31 | : vmap_table_offset_(vmap_table_offset), |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 32 | method_info_offset_(method_info_offset), |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 33 | frame_info_(frame_size_in_bytes, core_spill_mask, fp_spill_mask), |
| 34 | code_size_(code_size) {} |
| 35 | |
| 36 | OatQuickMethodHeader::~OatQuickMethodHeader() {} |
| 37 | |
| 38 | uint32_t OatQuickMethodHeader::ToDexPc(ArtMethod* method, |
| 39 | const uintptr_t pc, |
| 40 | bool abort_on_failure) const { |
| 41 | const void* entry_point = GetEntryPoint(); |
| 42 | uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(entry_point); |
| 43 | if (IsOptimized()) { |
| 44 | CodeInfo code_info = GetOptimizedCodeInfo(); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 45 | CodeInfoEncoding encoding = code_info.ExtractEncoding(); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 46 | StackMap stack_map = code_info.GetStackMapForNativePcOffset(sought_offset, encoding); |
| 47 | if (stack_map.IsValid()) { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 48 | return stack_map.GetDexPc(encoding.stack_map.encoding); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 49 | } |
| 50 | } else { |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 51 | DCHECK(method->IsNative()); |
| 52 | return DexFile::kDexNoIndex; |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 53 | } |
| 54 | if (abort_on_failure) { |
| 55 | ScopedObjectAccess soa(Thread::Current()); |
| 56 | LOG(FATAL) << "Failed to find Dex offset for PC offset " |
| 57 | << reinterpret_cast<void*>(sought_offset) |
| 58 | << "(PC " << reinterpret_cast<void*>(pc) << ", entry_point=" << entry_point |
| 59 | << " current entry_point=" << method->GetEntryPointFromQuickCompiledCode() |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 60 | << ") in " << method->PrettyMethod(); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 61 | } |
| 62 | return DexFile::kDexNoIndex; |
| 63 | } |
| 64 | |
| 65 | uintptr_t OatQuickMethodHeader::ToNativeQuickPc(ArtMethod* method, |
| 66 | const uint32_t dex_pc, |
| 67 | bool is_for_catch_handler, |
| 68 | bool abort_on_failure) const { |
| 69 | const void* entry_point = GetEntryPoint(); |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 70 | DCHECK(!method->IsNative()); |
| 71 | DCHECK(IsOptimized()); |
| 72 | // Search for the dex-to-pc mapping in stack maps. |
| 73 | CodeInfo code_info = GetOptimizedCodeInfo(); |
| 74 | CodeInfoEncoding encoding = code_info.ExtractEncoding(); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 75 | |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 76 | // All stack maps are stored in the same CodeItem section, safepoint stack |
| 77 | // maps first, then catch stack maps. We use `is_for_catch_handler` to select |
| 78 | // the order of iteration. |
| 79 | StackMap stack_map = |
| 80 | LIKELY(is_for_catch_handler) ? code_info.GetCatchStackMapForDexPc(dex_pc, encoding) |
| 81 | : code_info.GetStackMapForDexPc(dex_pc, encoding); |
| 82 | if (stack_map.IsValid()) { |
| 83 | return reinterpret_cast<uintptr_t>(entry_point) + |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 84 | stack_map.GetNativePcOffset(encoding.stack_map.encoding, kRuntimeISA); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 85 | } |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 86 | if (abort_on_failure) { |
| 87 | ScopedObjectAccess soa(Thread::Current()); |
| 88 | LOG(FATAL) << "Failed to find native offset for dex pc 0x" << std::hex << dex_pc |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 89 | << " in " << method->PrettyMethod(); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 90 | } |
| 91 | return UINTPTR_MAX; |
| 92 | } |
| 93 | |
| 94 | } // namespace art |