blob: 9c2378d42d4e14d8abd7fa6963ee20eda780ab57 [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"
Mathieu Chartier0795f232016-09-27 18:43:30 -070020#include "scoped_thread_state_change-inl.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010021#include "thread.h"
22
23namespace art {
24
25OatQuickMethodHeader::OatQuickMethodHeader(
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010026 uint32_t vmap_table_offset,
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010027 uint32_t frame_size_in_bytes,
28 uint32_t core_spill_mask,
29 uint32_t fp_spill_mask,
30 uint32_t code_size)
Vladimir Marko9d07e3d2016-03-31 12:02:28 +010031 : vmap_table_offset_(vmap_table_offset),
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010032 frame_info_(frame_size_in_bytes, core_spill_mask, fp_spill_mask),
33 code_size_(code_size) {}
34
35OatQuickMethodHeader::~OatQuickMethodHeader() {}
36
37uint32_t OatQuickMethodHeader::ToDexPc(ArtMethod* method,
38 const uintptr_t pc,
39 bool abort_on_failure) const {
40 const void* entry_point = GetEntryPoint();
41 uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(entry_point);
42 if (IsOptimized()) {
43 CodeInfo code_info = GetOptimizedCodeInfo();
David Srbecky09ed0982016-02-12 21:58:43 +000044 CodeInfoEncoding encoding = code_info.ExtractEncoding();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010045 StackMap stack_map = code_info.GetStackMapForNativePcOffset(sought_offset, encoding);
46 if (stack_map.IsValid()) {
David Srbecky09ed0982016-02-12 21:58:43 +000047 return stack_map.GetDexPc(encoding.stack_map_encoding);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010048 }
49 } else {
Vladimir Marko9d07e3d2016-03-31 12:02:28 +010050 DCHECK(method->IsNative());
51 return DexFile::kDexNoIndex;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010052 }
53 if (abort_on_failure) {
54 ScopedObjectAccess soa(Thread::Current());
55 LOG(FATAL) << "Failed to find Dex offset for PC offset "
56 << reinterpret_cast<void*>(sought_offset)
57 << "(PC " << reinterpret_cast<void*>(pc) << ", entry_point=" << entry_point
58 << " current entry_point=" << method->GetEntryPointFromQuickCompiledCode()
David Sehr709b0702016-10-13 09:12:37 -070059 << ") in " << method->PrettyMethod();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010060 }
61 return DexFile::kDexNoIndex;
62}
63
64uintptr_t OatQuickMethodHeader::ToNativeQuickPc(ArtMethod* method,
65 const uint32_t dex_pc,
66 bool is_for_catch_handler,
67 bool abort_on_failure) const {
68 const void* entry_point = GetEntryPoint();
Vladimir Marko9d07e3d2016-03-31 12:02:28 +010069 DCHECK(!method->IsNative());
70 DCHECK(IsOptimized());
71 // Search for the dex-to-pc mapping in stack maps.
72 CodeInfo code_info = GetOptimizedCodeInfo();
73 CodeInfoEncoding encoding = code_info.ExtractEncoding();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010074
Vladimir Marko9d07e3d2016-03-31 12:02:28 +010075 // All stack maps are stored in the same CodeItem section, safepoint stack
76 // maps first, then catch stack maps. We use `is_for_catch_handler` to select
77 // the order of iteration.
78 StackMap stack_map =
79 LIKELY(is_for_catch_handler) ? code_info.GetCatchStackMapForDexPc(dex_pc, encoding)
80 : code_info.GetStackMapForDexPc(dex_pc, encoding);
81 if (stack_map.IsValid()) {
82 return reinterpret_cast<uintptr_t>(entry_point) +
83 stack_map.GetNativePcOffset(encoding.stack_map_encoding);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010084 }
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010085 if (abort_on_failure) {
86 ScopedObjectAccess soa(Thread::Current());
87 LOG(FATAL) << "Failed to find native offset for dex pc 0x" << std::hex << dex_pc
David Sehr709b0702016-10-13 09:12:37 -070088 << " in " << method->PrettyMethod();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010089 }
90 return UINTPTR_MAX;
91}
92
93} // namespace art