blob: 3ed2a91be6980cac2d4bcea17afaf59ad039de83 [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 Geoffray524e7ea2015-10-16 17:13:34 +010027uint32_t OatQuickMethodHeader::ToDexPc(ArtMethod* method,
28 const uintptr_t pc,
29 bool abort_on_failure) const {
30 const void* entry_point = GetEntryPoint();
31 uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(entry_point);
David Srbeckyafc97bc2018-07-05 08:14:35 +000032 if (method->IsNative()) {
33 return dex::kDexNoIndex;
34 } else {
35 DCHECK(IsOptimized());
David Srbecky6ee06e92018-07-25 21:45:54 +010036 CodeInfo code_info(this, CodeInfo::DecodeFlags::InlineInfoOnly);
David Srbecky052f8ca2018-04-26 15:42:54 +010037 StackMap stack_map = code_info.GetStackMapForNativePcOffset(sought_offset);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010038 if (stack_map.IsValid()) {
David Srbecky052f8ca2018-04-26 15:42:54 +010039 return stack_map.GetDexPc();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010040 }
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010041 }
42 if (abort_on_failure) {
43 ScopedObjectAccess soa(Thread::Current());
44 LOG(FATAL) << "Failed to find Dex offset for PC offset "
45 << reinterpret_cast<void*>(sought_offset)
46 << "(PC " << reinterpret_cast<void*>(pc) << ", entry_point=" << entry_point
47 << " current entry_point=" << method->GetEntryPointFromQuickCompiledCode()
David Sehr709b0702016-10-13 09:12:37 -070048 << ") in " << method->PrettyMethod();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010049 }
Andreas Gampee2abbc62017-09-15 11:59:26 -070050 return dex::kDexNoIndex;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010051}
52
53uintptr_t OatQuickMethodHeader::ToNativeQuickPc(ArtMethod* method,
54 const uint32_t dex_pc,
55 bool is_for_catch_handler,
56 bool abort_on_failure) const {
57 const void* entry_point = GetEntryPoint();
Vladimir Marko9d07e3d2016-03-31 12:02:28 +010058 DCHECK(!method->IsNative());
59 DCHECK(IsOptimized());
60 // Search for the dex-to-pc mapping in stack maps.
David Srbecky6ee06e92018-07-25 21:45:54 +010061 CodeInfo code_info(this, CodeInfo::DecodeFlags::InlineInfoOnly);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010062
Vladimir Marko9d07e3d2016-03-31 12:02:28 +010063 // All stack maps are stored in the same CodeItem section, safepoint stack
64 // maps first, then catch stack maps. We use `is_for_catch_handler` to select
65 // the order of iteration.
66 StackMap stack_map =
David Srbecky052f8ca2018-04-26 15:42:54 +010067 LIKELY(is_for_catch_handler) ? code_info.GetCatchStackMapForDexPc(dex_pc)
68 : code_info.GetStackMapForDexPc(dex_pc);
Vladimir Marko9d07e3d2016-03-31 12:02:28 +010069 if (stack_map.IsValid()) {
70 return reinterpret_cast<uintptr_t>(entry_point) +
David Srbecky052f8ca2018-04-26 15:42:54 +010071 stack_map.GetNativePcOffset(kRuntimeISA);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010072 }
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010073 if (abort_on_failure) {
74 ScopedObjectAccess soa(Thread::Current());
75 LOG(FATAL) << "Failed to find native offset for dex pc 0x" << std::hex << dex_pc
David Sehr709b0702016-10-13 09:12:37 -070076 << " in " << method->PrettyMethod();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010077 }
78 return UINTPTR_MAX;
79}
80
81} // namespace art