blob: 7a6ebf8075c81eb4ed7f211a6de0fead0a662e3f [file] [log] [blame]
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +01001/*
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 Sehr9e734c72018-01-04 17:56:19 -080020#include "dex/dex_file_types.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070021#include "scoped_thread_state_change-inl.h"
David Srbecky052f8ca2018-04-26 15:42:54 +010022#include "stack_map.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010023#include "thread.h"
24
25namespace art {
26
Nicolas Geoffraya00b54b2019-12-03 14:36:42 +000027uint32_t OatQuickMethodHeader::ToDexPc(ArtMethod** frame,
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010028 const uintptr_t pc,
29 bool abort_on_failure) const {
Nicolas Geoffraya00b54b2019-12-03 14:36:42 +000030 ArtMethod* method = *frame;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010031 const void* entry_point = GetEntryPoint();
32 uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(entry_point);
David Srbeckyafc97bc2018-07-05 08:14:35 +000033 if (method->IsNative()) {
34 return dex::kDexNoIndex;
35 } else {
36 DCHECK(IsOptimized());
David Srbecky0d4567f2019-05-30 22:45:40 +010037 CodeInfo code_info = CodeInfo::DecodeInlineInfoOnly(this);
David Srbecky052f8ca2018-04-26 15:42:54 +010038 StackMap stack_map = code_info.GetStackMapForNativePcOffset(sought_offset);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010039 if (stack_map.IsValid()) {
David Srbecky052f8ca2018-04-26 15:42:54 +010040 return stack_map.GetDexPc();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010041 }
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010042 }
43 if (abort_on_failure) {
44 ScopedObjectAccess soa(Thread::Current());
45 LOG(FATAL) << "Failed to find Dex offset for PC offset "
46 << reinterpret_cast<void*>(sought_offset)
47 << "(PC " << reinterpret_cast<void*>(pc) << ", entry_point=" << entry_point
48 << " current entry_point=" << method->GetEntryPointFromQuickCompiledCode()
David Sehr709b0702016-10-13 09:12:37 -070049 << ") in " << method->PrettyMethod();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010050 }
Andreas Gampee2abbc62017-09-15 11:59:26 -070051 return dex::kDexNoIndex;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010052}
53
54uintptr_t OatQuickMethodHeader::ToNativeQuickPc(ArtMethod* method,
55 const uint32_t dex_pc,
56 bool is_for_catch_handler,
57 bool abort_on_failure) const {
58 const void* entry_point = GetEntryPoint();
Vladimir Marko9d07e3d2016-03-31 12:02:28 +010059 DCHECK(!method->IsNative());
60 DCHECK(IsOptimized());
61 // Search for the dex-to-pc mapping in stack maps.
David Srbecky0d4567f2019-05-30 22:45:40 +010062 CodeInfo code_info = CodeInfo::DecodeInlineInfoOnly(this);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010063
Vladimir Marko9d07e3d2016-03-31 12:02:28 +010064 // All stack maps are stored in the same CodeItem section, safepoint stack
65 // maps first, then catch stack maps. We use `is_for_catch_handler` to select
66 // the order of iteration.
67 StackMap stack_map =
David Srbecky052f8ca2018-04-26 15:42:54 +010068 LIKELY(is_for_catch_handler) ? code_info.GetCatchStackMapForDexPc(dex_pc)
69 : code_info.GetStackMapForDexPc(dex_pc);
Vladimir Marko9d07e3d2016-03-31 12:02:28 +010070 if (stack_map.IsValid()) {
71 return reinterpret_cast<uintptr_t>(entry_point) +
David Srbecky052f8ca2018-04-26 15:42:54 +010072 stack_map.GetNativePcOffset(kRuntimeISA);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010073 }
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010074 if (abort_on_failure) {
75 ScopedObjectAccess soa(Thread::Current());
76 LOG(FATAL) << "Failed to find native offset for dex pc 0x" << std::hex << dex_pc
David Sehr709b0702016-10-13 09:12:37 -070077 << " in " << method->PrettyMethod();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010078 }
79 return UINTPTR_MAX;
80}
81
82} // namespace art