blob: 6eadd87d3837d76b2bd716c597c7b70f011a7e74 [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#ifndef ART_RUNTIME_OAT_QUICK_METHOD_HEADER_H_
18#define ART_RUNTIME_OAT_QUICK_METHOD_HEADER_H_
19
20#include "arch/instruction_set.h"
21#include "base/macros.h"
22#include "quick/quick_method_frame_info.h"
23#include "stack_map.h"
24
25namespace art {
26
27class ArtMethod;
28
29// OatQuickMethodHeader precedes the raw code chunk generated by the compiler.
30class PACKED(4) OatQuickMethodHeader {
31 public:
32 OatQuickMethodHeader(uint32_t mapping_table_offset = 0U,
33 uint32_t vmap_table_offset = 0U,
34 uint32_t gc_map_offset = 0U,
35 uint32_t frame_size_in_bytes = 0U,
36 uint32_t core_spill_mask = 0U,
37 uint32_t fp_spill_mask = 0U,
38 uint32_t code_size = 0U);
39
40 ~OatQuickMethodHeader();
41
42 OatQuickMethodHeader& operator=(const OatQuickMethodHeader&) = default;
43
44 uintptr_t NativeQuickPcOffset(const uintptr_t pc) const {
45 return pc - reinterpret_cast<uintptr_t>(GetEntryPoint());
46 }
47
48 bool IsOptimized() const {
49 return gc_map_offset_ == 0 && vmap_table_offset_ != 0;
50 }
51
52 CodeInfo GetOptimizedCodeInfo() const {
53 DCHECK(IsOptimized());
54 const void* data = reinterpret_cast<const void*>(code_ - vmap_table_offset_);
55 return CodeInfo(data);
56 }
57
58 const uint8_t* GetCode() const {
59 return code_;
60 }
61
62 const uint8_t* GetNativeGcMap() const {
63 return (gc_map_offset_ == 0) ? nullptr : code_ - gc_map_offset_;
64 }
65
66 const uint8_t* GetMappingTable() const {
67 return (mapping_table_offset_ == 0) ? nullptr : code_ - mapping_table_offset_;
68 }
69
70 const uint8_t* GetVmapTable() const {
71 CHECK(!IsOptimized()) << "Unimplemented vmap table for optimizing compiler";
72 return (vmap_table_offset_ == 0) ? nullptr : code_ - vmap_table_offset_;
73 }
74
75 bool Contains(uintptr_t pc) const {
76 uintptr_t code_start = reinterpret_cast<uintptr_t>(code_);
77 return code_start <= pc && pc <= (code_start + code_size_);
78 }
79
80 const uint8_t* GetEntryPoint() const {
81 // When the runtime architecture is ARM, `kRuntimeISA` is set to `kArm`
82 // (not `kThumb2`), *but* we always generate code for the Thumb-2
83 // instruction set anyway. Thumb-2 requires the entrypoint to be of
84 // offset 1.
85 static_assert(kRuntimeISA != kThumb2, "kThumb2 cannot be a runtime ISA");
86 return (kRuntimeISA == kArm)
87 ? reinterpret_cast<uint8_t*>(reinterpret_cast<uintptr_t>(code_) | 1)
88 : code_;
89 }
90
91 template <bool kCheckFrameSize = true>
92 uint32_t GetFrameSizeInBytes() {
93 uint32_t result = frame_info_.FrameSizeInBytes();
94 if (kCheckFrameSize) {
95 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
96 }
97 return result;
98 }
99
100 QuickMethodFrameInfo GetFrameInfo() const {
101 return frame_info_;
102 }
103
104 uintptr_t ToNativeQuickPc(ArtMethod* method,
105 const uint32_t dex_pc,
106 bool is_for_catch_handler,
107 bool abort_on_failure = true) const;
108
109 uint32_t ToDexPc(ArtMethod* method, const uintptr_t pc, bool abort_on_failure = true) const;
110
111 // The offset in bytes from the start of the mapping table to the end of the header.
112 uint32_t mapping_table_offset_;
113 // The offset in bytes from the start of the vmap table to the end of the header.
114 uint32_t vmap_table_offset_;
115 // The offset in bytes from the start of the gc map to the end of the header.
116 uint32_t gc_map_offset_;
117 // The stack frame information.
118 QuickMethodFrameInfo frame_info_;
119 // The code size in bytes.
120 uint32_t code_size_;
121 // The actual code.
122 uint8_t code_[0];
123};
124
125} // namespace art
126
127#endif // ART_RUNTIME_OAT_QUICK_METHOD_HEADER_H_