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