1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ART_RUNTIME_QUICK_INLINE_METHOD_ANALYSER_H_
#define ART_RUNTIME_QUICK_INLINE_METHOD_ANALYSER_H_
#include "base/macros.h"
#include "base/mutex.h"
#include "dex_file.h"
#include "dex_instruction.h"
#include "method_reference.h"
/*
* NOTE: This code is part of the quick compiler. It lives in the runtime
* only to allow the debugger to check whether a method has been inlined.
*/
namespace art {
namespace verifier {
class MethodVerifier;
} // namespace verifier
enum InlineMethodOpcode : uint16_t {
kIntrinsicDoubleCvt,
kIntrinsicFloatCvt,
kIntrinsicFloat2Int,
kIntrinsicDouble2Long,
kIntrinsicFloatIsInfinite,
kIntrinsicDoubleIsInfinite,
kIntrinsicFloatIsNaN,
kIntrinsicDoubleIsNaN,
kIntrinsicReverseBits,
kIntrinsicReverseBytes,
kIntrinsicBitCount,
kIntrinsicCompare,
kIntrinsicHighestOneBit,
kIntrinsicLowestOneBit,
kIntrinsicNumberOfLeadingZeros,
kIntrinsicNumberOfTrailingZeros,
kIntrinsicRotateRight,
kIntrinsicRotateLeft,
kIntrinsicSignum,
kIntrinsicAbsInt,
kIntrinsicAbsLong,
kIntrinsicAbsFloat,
kIntrinsicAbsDouble,
kIntrinsicMinMaxInt,
kIntrinsicMinMaxLong,
kIntrinsicMinMaxFloat,
kIntrinsicMinMaxDouble,
kIntrinsicCos,
kIntrinsicSin,
kIntrinsicAcos,
kIntrinsicAsin,
kIntrinsicAtan,
kIntrinsicAtan2,
kIntrinsicCbrt,
kIntrinsicCosh,
kIntrinsicExp,
kIntrinsicExpm1,
kIntrinsicHypot,
kIntrinsicLog,
kIntrinsicLog10,
kIntrinsicNextAfter,
kIntrinsicSinh,
kIntrinsicTan,
kIntrinsicTanh,
kIntrinsicSqrt,
kIntrinsicCeil,
kIntrinsicFloor,
kIntrinsicRint,
kIntrinsicRoundFloat,
kIntrinsicRoundDouble,
kIntrinsicReferenceGetReferent,
kIntrinsicCharAt,
kIntrinsicCompareTo,
kIntrinsicEquals,
kIntrinsicGetCharsNoCheck,
kIntrinsicIsEmptyOrLength,
kIntrinsicIndexOf,
kIntrinsicNewStringFromBytes,
kIntrinsicNewStringFromChars,
kIntrinsicNewStringFromString,
kIntrinsicCurrentThread,
kIntrinsicPeek,
kIntrinsicPoke,
kIntrinsicCas,
kIntrinsicUnsafeGet,
kIntrinsicUnsafePut,
// 1.8.
kIntrinsicUnsafeGetAndAddInt,
kIntrinsicUnsafeGetAndAddLong,
kIntrinsicUnsafeGetAndSetInt,
kIntrinsicUnsafeGetAndSetLong,
kIntrinsicUnsafeGetAndSetObject,
kIntrinsicUnsafeLoadFence,
kIntrinsicUnsafeStoreFence,
kIntrinsicUnsafeFullFence,
kIntrinsicSystemArrayCopyCharArray,
kIntrinsicSystemArrayCopy,
kInlineOpNop,
kInlineOpReturnArg,
kInlineOpNonWideConst,
kInlineOpIGet,
kInlineOpIPut,
kInlineOpConstructor,
kInlineStringInit,
};
std::ostream& operator<<(std::ostream& os, const InlineMethodOpcode& rhs);
enum InlineMethodFlags : uint16_t {
kNoInlineMethodFlags = 0x0000,
kInlineIntrinsic = 0x0001,
kInlineSpecial = 0x0002,
};
// IntrinsicFlags are stored in InlineMethod::d::raw_data
enum IntrinsicFlags {
kIntrinsicFlagNone = 0,
// kIntrinsicMinMaxInt
kIntrinsicFlagMax = kIntrinsicFlagNone,
kIntrinsicFlagMin = 1,
// kIntrinsicIsEmptyOrLength
kIntrinsicFlagLength = kIntrinsicFlagNone,
kIntrinsicFlagIsEmpty = kIntrinsicFlagMin,
// kIntrinsicIndexOf
kIntrinsicFlagBase0 = kIntrinsicFlagMin,
// kIntrinsicUnsafeGet, kIntrinsicUnsafePut, kIntrinsicUnsafeCas
kIntrinsicFlagIsLong = kIntrinsicFlagMin,
// kIntrinsicUnsafeGet, kIntrinsicUnsafePut
kIntrinsicFlagIsVolatile = 2,
// kIntrinsicUnsafePut, kIntrinsicUnsafeCas
kIntrinsicFlagIsObject = 4,
// kIntrinsicUnsafePut
kIntrinsicFlagIsOrdered = 8,
// kIntrinsicDoubleCvt, kIntrinsicFloatCvt.
kIntrinsicFlagToFloatingPoint = kIntrinsicFlagMin,
};
struct InlineIGetIPutData {
// The op_variant below is DexMemAccessType but the runtime doesn't know that enumeration.
uint16_t op_variant : 3;
uint16_t method_is_static : 1;
uint16_t object_arg : 4;
uint16_t src_arg : 4; // iput only
uint16_t return_arg_plus1 : 4; // iput only, method argument to return + 1, 0 = return void.
uint16_t field_idx;
uint32_t is_volatile : 1;
uint32_t field_offset : 31;
};
static_assert(sizeof(InlineIGetIPutData) == sizeof(uint64_t), "Invalid size of InlineIGetIPutData");
struct InlineReturnArgData {
uint16_t arg;
uint16_t is_wide : 1;
uint16_t is_object : 1;
uint16_t reserved : 14;
uint32_t reserved2;
};
static_assert(sizeof(InlineReturnArgData) == sizeof(uint64_t),
"Invalid size of InlineReturnArgData");
struct InlineConstructorData {
// There can be up to 3 IPUTs, unused fields are marked with kNoDexIndex16.
uint16_t iput0_field_index;
uint16_t iput1_field_index;
uint16_t iput2_field_index;
uint16_t iput0_arg : 4;
uint16_t iput1_arg : 4;
uint16_t iput2_arg : 4;
uint16_t reserved : 4;
};
static_assert(sizeof(InlineConstructorData) == sizeof(uint64_t),
"Invalid size of InlineConstructorData");
struct InlineMethod {
InlineMethodOpcode opcode;
InlineMethodFlags flags;
union {
uint64_t data;
InlineIGetIPutData ifield_data;
InlineReturnArgData return_data;
InlineConstructorData constructor_data;
} d;
};
class InlineMethodAnalyser {
public:
/**
* Analyse method code to determine if the method is a candidate for inlining.
* If it is, record the inlining data.
*
* @param verifier the method verifier holding data about the method to analyse.
* @param method placeholder for the inline method data.
* @return true if the method is a candidate for inlining, false otherwise.
*/
static bool AnalyseMethodCode(verifier::MethodVerifier* verifier, InlineMethod* result)
SHARED_REQUIRES(Locks::mutator_lock_);
static bool AnalyseMethodCode(ArtMethod* method, InlineMethod* result)
SHARED_REQUIRES(Locks::mutator_lock_);
static constexpr bool IsInstructionIGet(Instruction::Code opcode) {
return Instruction::IGET <= opcode && opcode <= Instruction::IGET_SHORT;
}
static constexpr bool IsInstructionIPut(Instruction::Code opcode) {
return Instruction::IPUT <= opcode && opcode <= Instruction::IPUT_SHORT;
}
static constexpr uint16_t IGetVariant(Instruction::Code opcode) {
return opcode - Instruction::IGET;
}
static constexpr uint16_t IPutVariant(Instruction::Code opcode) {
return opcode - Instruction::IPUT;
}
// Determines whether the method is a synthetic accessor (method name starts with "access$").
static bool IsSyntheticAccessor(MethodReference ref);
private:
static bool AnalyseMethodCode(const DexFile::CodeItem* code_item,
const MethodReference& method_ref,
bool is_static,
ArtMethod* method,
InlineMethod* result)
SHARED_REQUIRES(Locks::mutator_lock_);
static bool AnalyseReturnMethod(const DexFile::CodeItem* code_item, InlineMethod* result);
static bool AnalyseConstMethod(const DexFile::CodeItem* code_item, InlineMethod* result);
static bool AnalyseIGetMethod(const DexFile::CodeItem* code_item,
const MethodReference& method_ref,
bool is_static,
ArtMethod* method,
InlineMethod* result)
SHARED_REQUIRES(Locks::mutator_lock_);
static bool AnalyseIPutMethod(const DexFile::CodeItem* code_item,
const MethodReference& method_ref,
bool is_static,
ArtMethod* method,
InlineMethod* result)
SHARED_REQUIRES(Locks::mutator_lock_);
// Can we fast path instance field access in a verified accessor?
// If yes, computes field's offset and volatility and whether the method is static or not.
static bool ComputeSpecialAccessorInfo(ArtMethod* method,
uint32_t field_idx,
bool is_put,
InlineIGetIPutData* result)
SHARED_REQUIRES(Locks::mutator_lock_);
};
} // namespace art
#endif // ART_RUNTIME_QUICK_INLINE_METHOD_ANALYSER_H_
|