blob: 4e93c9c47da6203d08d82d184fe7c0c32a2c397a [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
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/*
18 * Common defines for all Dalvik code.
19 */
20#ifndef DALVIK_COMMON_H_
21#define DALVIK_COMMON_H_
22
23#include <stdbool.h>
24#include <stdint.h>
25#include <stdio.h>
26#include <assert.h>
27#include "../logging.h"
28
29// From Common.h
30#define MIN(x,y) (((x) < (y)) ? (x) : (y))
31#define MAX(x,y) (((x) > (y)) ? (x) : (y))
32
33typedef uint8_t u1;
34typedef uint16_t u2;
35typedef uint32_t u4;
36typedef uint64_t u8;
37typedef int8_t s1;
38typedef int16_t s2;
39typedef int32_t s4;
40typedef int64_t s8;
41typedef unsigned long long u8;
42
43struct Object;
44
45union JValue {
46 u1 z;
47 s1 b;
48 u2 c;
49 s2 s;
50 s4 i;
51 s8 j;
52 float f;
53 double d;
54 Object* l;
55};
56
57
58// From libdex/DexOpcodes.h
59#define kNumPackedOpcodes 0x200
60#define kPackedSwitchSignature 0x0100
61#define kSparseSwitchSignature 0x0200
62#define kArrayDataSignature 0x0300
63enum Opcode {
64 // BEGIN(libdex-opcode-enum); GENERATED AUTOMATICALLY BY opcode-gen
65 OP_NOP = 0x00,
66 OP_MOVE = 0x01,
67 OP_MOVE_FROM16 = 0x02,
68 OP_MOVE_16 = 0x03,
69 OP_MOVE_WIDE = 0x04,
70 OP_MOVE_WIDE_FROM16 = 0x05,
71 OP_MOVE_WIDE_16 = 0x06,
72 OP_MOVE_OBJECT = 0x07,
73 OP_MOVE_OBJECT_FROM16 = 0x08,
74 OP_MOVE_OBJECT_16 = 0x09,
75 OP_MOVE_RESULT = 0x0a,
76 OP_MOVE_RESULT_WIDE = 0x0b,
77 OP_MOVE_RESULT_OBJECT = 0x0c,
78 OP_MOVE_EXCEPTION = 0x0d,
79 OP_RETURN_VOID = 0x0e,
80 OP_RETURN = 0x0f,
81 OP_RETURN_WIDE = 0x10,
82 OP_RETURN_OBJECT = 0x11,
83 OP_CONST_4 = 0x12,
84 OP_CONST_16 = 0x13,
85 OP_CONST = 0x14,
86 OP_CONST_HIGH16 = 0x15,
87 OP_CONST_WIDE_16 = 0x16,
88 OP_CONST_WIDE_32 = 0x17,
89 OP_CONST_WIDE = 0x18,
90 OP_CONST_WIDE_HIGH16 = 0x19,
91 OP_CONST_STRING = 0x1a,
92 OP_CONST_STRING_JUMBO = 0x1b,
93 OP_CONST_CLASS = 0x1c,
94 OP_MONITOR_ENTER = 0x1d,
95 OP_MONITOR_EXIT = 0x1e,
96 OP_CHECK_CAST = 0x1f,
97 OP_INSTANCE_OF = 0x20,
98 OP_ARRAY_LENGTH = 0x21,
99 OP_NEW_INSTANCE = 0x22,
100 OP_NEW_ARRAY = 0x23,
101 OP_FILLED_NEW_ARRAY = 0x24,
102 OP_FILLED_NEW_ARRAY_RANGE = 0x25,
103 OP_FILL_ARRAY_DATA = 0x26,
104 OP_THROW = 0x27,
105 OP_GOTO = 0x28,
106 OP_GOTO_16 = 0x29,
107 OP_GOTO_32 = 0x2a,
108 OP_PACKED_SWITCH = 0x2b,
109 OP_SPARSE_SWITCH = 0x2c,
110 OP_CMPL_FLOAT = 0x2d,
111 OP_CMPG_FLOAT = 0x2e,
112 OP_CMPL_DOUBLE = 0x2f,
113 OP_CMPG_DOUBLE = 0x30,
114 OP_CMP_LONG = 0x31,
115 OP_IF_EQ = 0x32,
116 OP_IF_NE = 0x33,
117 OP_IF_LT = 0x34,
118 OP_IF_GE = 0x35,
119 OP_IF_GT = 0x36,
120 OP_IF_LE = 0x37,
121 OP_IF_EQZ = 0x38,
122 OP_IF_NEZ = 0x39,
123 OP_IF_LTZ = 0x3a,
124 OP_IF_GEZ = 0x3b,
125 OP_IF_GTZ = 0x3c,
126 OP_IF_LEZ = 0x3d,
127 OP_UNUSED_3E = 0x3e,
128 OP_UNUSED_3F = 0x3f,
129 OP_UNUSED_40 = 0x40,
130 OP_UNUSED_41 = 0x41,
131 OP_UNUSED_42 = 0x42,
132 OP_UNUSED_43 = 0x43,
133 OP_AGET = 0x44,
134 OP_AGET_WIDE = 0x45,
135 OP_AGET_OBJECT = 0x46,
136 OP_AGET_BOOLEAN = 0x47,
137 OP_AGET_BYTE = 0x48,
138 OP_AGET_CHAR = 0x49,
139 OP_AGET_SHORT = 0x4a,
140 OP_APUT = 0x4b,
141 OP_APUT_WIDE = 0x4c,
142 OP_APUT_OBJECT = 0x4d,
143 OP_APUT_BOOLEAN = 0x4e,
144 OP_APUT_BYTE = 0x4f,
145 OP_APUT_CHAR = 0x50,
146 OP_APUT_SHORT = 0x51,
147 OP_IGET = 0x52,
148 OP_IGET_WIDE = 0x53,
149 OP_IGET_OBJECT = 0x54,
150 OP_IGET_BOOLEAN = 0x55,
151 OP_IGET_BYTE = 0x56,
152 OP_IGET_CHAR = 0x57,
153 OP_IGET_SHORT = 0x58,
154 OP_IPUT = 0x59,
155 OP_IPUT_WIDE = 0x5a,
156 OP_IPUT_OBJECT = 0x5b,
157 OP_IPUT_BOOLEAN = 0x5c,
158 OP_IPUT_BYTE = 0x5d,
159 OP_IPUT_CHAR = 0x5e,
160 OP_IPUT_SHORT = 0x5f,
161 OP_SGET = 0x60,
162 OP_SGET_WIDE = 0x61,
163 OP_SGET_OBJECT = 0x62,
164 OP_SGET_BOOLEAN = 0x63,
165 OP_SGET_BYTE = 0x64,
166 OP_SGET_CHAR = 0x65,
167 OP_SGET_SHORT = 0x66,
168 OP_SPUT = 0x67,
169 OP_SPUT_WIDE = 0x68,
170 OP_SPUT_OBJECT = 0x69,
171 OP_SPUT_BOOLEAN = 0x6a,
172 OP_SPUT_BYTE = 0x6b,
173 OP_SPUT_CHAR = 0x6c,
174 OP_SPUT_SHORT = 0x6d,
175 OP_INVOKE_VIRTUAL = 0x6e,
176 OP_INVOKE_SUPER = 0x6f,
177 OP_INVOKE_DIRECT = 0x70,
178 OP_INVOKE_STATIC = 0x71,
179 OP_INVOKE_INTERFACE = 0x72,
180 OP_UNUSED_73 = 0x73,
181 OP_INVOKE_VIRTUAL_RANGE = 0x74,
182 OP_INVOKE_SUPER_RANGE = 0x75,
183 OP_INVOKE_DIRECT_RANGE = 0x76,
184 OP_INVOKE_STATIC_RANGE = 0x77,
185 OP_INVOKE_INTERFACE_RANGE = 0x78,
186 OP_UNUSED_79 = 0x79,
187 OP_UNUSED_7A = 0x7a,
188 OP_NEG_INT = 0x7b,
189 OP_NOT_INT = 0x7c,
190 OP_NEG_LONG = 0x7d,
191 OP_NOT_LONG = 0x7e,
192 OP_NEG_FLOAT = 0x7f,
193 OP_NEG_DOUBLE = 0x80,
194 OP_INT_TO_LONG = 0x81,
195 OP_INT_TO_FLOAT = 0x82,
196 OP_INT_TO_DOUBLE = 0x83,
197 OP_LONG_TO_INT = 0x84,
198 OP_LONG_TO_FLOAT = 0x85,
199 OP_LONG_TO_DOUBLE = 0x86,
200 OP_FLOAT_TO_INT = 0x87,
201 OP_FLOAT_TO_LONG = 0x88,
202 OP_FLOAT_TO_DOUBLE = 0x89,
203 OP_DOUBLE_TO_INT = 0x8a,
204 OP_DOUBLE_TO_LONG = 0x8b,
205 OP_DOUBLE_TO_FLOAT = 0x8c,
206 OP_INT_TO_BYTE = 0x8d,
207 OP_INT_TO_CHAR = 0x8e,
208 OP_INT_TO_SHORT = 0x8f,
209 OP_ADD_INT = 0x90,
210 OP_SUB_INT = 0x91,
211 OP_MUL_INT = 0x92,
212 OP_DIV_INT = 0x93,
213 OP_REM_INT = 0x94,
214 OP_AND_INT = 0x95,
215 OP_OR_INT = 0x96,
216 OP_XOR_INT = 0x97,
217 OP_SHL_INT = 0x98,
218 OP_SHR_INT = 0x99,
219 OP_USHR_INT = 0x9a,
220 OP_ADD_LONG = 0x9b,
221 OP_SUB_LONG = 0x9c,
222 OP_MUL_LONG = 0x9d,
223 OP_DIV_LONG = 0x9e,
224 OP_REM_LONG = 0x9f,
225 OP_AND_LONG = 0xa0,
226 OP_OR_LONG = 0xa1,
227 OP_XOR_LONG = 0xa2,
228 OP_SHL_LONG = 0xa3,
229 OP_SHR_LONG = 0xa4,
230 OP_USHR_LONG = 0xa5,
231 OP_ADD_FLOAT = 0xa6,
232 OP_SUB_FLOAT = 0xa7,
233 OP_MUL_FLOAT = 0xa8,
234 OP_DIV_FLOAT = 0xa9,
235 OP_REM_FLOAT = 0xaa,
236 OP_ADD_DOUBLE = 0xab,
237 OP_SUB_DOUBLE = 0xac,
238 OP_MUL_DOUBLE = 0xad,
239 OP_DIV_DOUBLE = 0xae,
240 OP_REM_DOUBLE = 0xaf,
241 OP_ADD_INT_2ADDR = 0xb0,
242 OP_SUB_INT_2ADDR = 0xb1,
243 OP_MUL_INT_2ADDR = 0xb2,
244 OP_DIV_INT_2ADDR = 0xb3,
245 OP_REM_INT_2ADDR = 0xb4,
246 OP_AND_INT_2ADDR = 0xb5,
247 OP_OR_INT_2ADDR = 0xb6,
248 OP_XOR_INT_2ADDR = 0xb7,
249 OP_SHL_INT_2ADDR = 0xb8,
250 OP_SHR_INT_2ADDR = 0xb9,
251 OP_USHR_INT_2ADDR = 0xba,
252 OP_ADD_LONG_2ADDR = 0xbb,
253 OP_SUB_LONG_2ADDR = 0xbc,
254 OP_MUL_LONG_2ADDR = 0xbd,
255 OP_DIV_LONG_2ADDR = 0xbe,
256 OP_REM_LONG_2ADDR = 0xbf,
257 OP_AND_LONG_2ADDR = 0xc0,
258 OP_OR_LONG_2ADDR = 0xc1,
259 OP_XOR_LONG_2ADDR = 0xc2,
260 OP_SHL_LONG_2ADDR = 0xc3,
261 OP_SHR_LONG_2ADDR = 0xc4,
262 OP_USHR_LONG_2ADDR = 0xc5,
263 OP_ADD_FLOAT_2ADDR = 0xc6,
264 OP_SUB_FLOAT_2ADDR = 0xc7,
265 OP_MUL_FLOAT_2ADDR = 0xc8,
266 OP_DIV_FLOAT_2ADDR = 0xc9,
267 OP_REM_FLOAT_2ADDR = 0xca,
268 OP_ADD_DOUBLE_2ADDR = 0xcb,
269 OP_SUB_DOUBLE_2ADDR = 0xcc,
270 OP_MUL_DOUBLE_2ADDR = 0xcd,
271 OP_DIV_DOUBLE_2ADDR = 0xce,
272 OP_REM_DOUBLE_2ADDR = 0xcf,
273 OP_ADD_INT_LIT16 = 0xd0,
274 OP_RSUB_INT = 0xd1,
275 OP_MUL_INT_LIT16 = 0xd2,
276 OP_DIV_INT_LIT16 = 0xd3,
277 OP_REM_INT_LIT16 = 0xd4,
278 OP_AND_INT_LIT16 = 0xd5,
279 OP_OR_INT_LIT16 = 0xd6,
280 OP_XOR_INT_LIT16 = 0xd7,
281 OP_ADD_INT_LIT8 = 0xd8,
282 OP_RSUB_INT_LIT8 = 0xd9,
283 OP_MUL_INT_LIT8 = 0xda,
284 OP_DIV_INT_LIT8 = 0xdb,
285 OP_REM_INT_LIT8 = 0xdc,
286 OP_AND_INT_LIT8 = 0xdd,
287 OP_OR_INT_LIT8 = 0xde,
288 OP_XOR_INT_LIT8 = 0xdf,
289 OP_SHL_INT_LIT8 = 0xe0,
290 OP_SHR_INT_LIT8 = 0xe1,
291 OP_USHR_INT_LIT8 = 0xe2,
292 OP_IGET_VOLATILE = 0xe3,
293 OP_IPUT_VOLATILE = 0xe4,
294 OP_SGET_VOLATILE = 0xe5,
295 OP_SPUT_VOLATILE = 0xe6,
296 OP_IGET_OBJECT_VOLATILE = 0xe7,
297 OP_IGET_WIDE_VOLATILE = 0xe8,
298 OP_IPUT_WIDE_VOLATILE = 0xe9,
299 OP_SGET_WIDE_VOLATILE = 0xea,
300 OP_SPUT_WIDE_VOLATILE = 0xeb,
301 OP_BREAKPOINT = 0xec,
302 OP_THROW_VERIFICATION_ERROR = 0xed,
303 OP_EXECUTE_INLINE = 0xee,
304 OP_EXECUTE_INLINE_RANGE = 0xef,
305 OP_INVOKE_OBJECT_INIT_RANGE = 0xf0,
306 OP_RETURN_VOID_BARRIER = 0xf1,
307 OP_IGET_QUICK = 0xf2,
308 OP_IGET_WIDE_QUICK = 0xf3,
309 OP_IGET_OBJECT_QUICK = 0xf4,
310 OP_IPUT_QUICK = 0xf5,
311 OP_IPUT_WIDE_QUICK = 0xf6,
312 OP_IPUT_OBJECT_QUICK = 0xf7,
313 OP_INVOKE_VIRTUAL_QUICK = 0xf8,
314 OP_INVOKE_VIRTUAL_QUICK_RANGE = 0xf9,
315 OP_INVOKE_SUPER_QUICK = 0xfa,
316 OP_INVOKE_SUPER_QUICK_RANGE = 0xfb,
317 OP_IPUT_OBJECT_VOLATILE = 0xfc,
318 OP_SGET_OBJECT_VOLATILE = 0xfd,
319 OP_SPUT_OBJECT_VOLATILE = 0xfe,
320};
321
322// From alloc/CardTable.h
323#define GC_CARD_SHIFT 7
324
325// From all/Alloc.h
326/* flags for dvmMalloc */
327enum {
328 ALLOC_DEFAULT = 0x00,
329 ALLOC_DONT_TRACK = 0x01, /* don't add to internal tracking list */
330 ALLOC_NON_MOVING = 0x02,
331};
332
333
334// From oo/Object.h
335struct ClassObject;
336struct ArrayObject;
337struct DvmDex;
338struct Method;
339
340struct Object {
341 ClassObject* clazz;
342 u4 lock;
343 Method** vtable;
344 int vtableCount;
345 u4 accessFlags;
346};
347
348struct ArrayObject : Object {
349 u4 length;
350 u8 contents[1];
351};
352
353struct ClassObject : Object {
354 const char* descriptor;
355 DvmDex* pDvmDex;
356 ClassObject* super;
357};
358
359// From InstrUtils.h
360enum InstructionFormat {
361 kFmt00x = 0, // unknown format (also used for "breakpoint" opcode)
362 kFmt10x, // op
363 kFmt12x, // op vA, vB
364 kFmt11n, // op vA, #+B
365 kFmt11x, // op vAA
366 kFmt10t, // op +AA
367 kFmt20bc, // [opt] op AA, thing@BBBB
368 kFmt20t, // op +AAAA
369 kFmt22x, // op vAA, vBBBB
370 kFmt21t, // op vAA, +BBBB
371 kFmt21s, // op vAA, #+BBBB
372 kFmt21h, // op vAA, #+BBBB00000[00000000]
373 kFmt21c, // op vAA, thing@BBBB
374 kFmt23x, // op vAA, vBB, vCC
375 kFmt22b, // op vAA, vBB, #+CC
376 kFmt22t, // op vA, vB, +CCCC
377 kFmt22s, // op vA, vB, #+CCCC
378 kFmt22c, // op vA, vB, thing@CCCC
379 kFmt22cs, // [opt] op vA, vB, field offset CCCC
380 kFmt30t, // op +AAAAAAAA
381 kFmt32x, // op vAAAA, vBBBB
382 kFmt31i, // op vAA, #+BBBBBBBB
383 kFmt31t, // op vAA, +BBBBBBBB
384 kFmt31c, // op vAA, string@BBBBBBBB
385 kFmt35c, // op {vC,vD,vE,vF,vG}, thing@BBBB
386 kFmt35ms, // [opt] invoke-virtual+super
387 kFmt3rc, // op {vCCCC .. v(CCCC+AA-1)}, thing@BBBB
388 kFmt3rms, // [opt] invoke-virtual+super/range
389 kFmt51l, // op vAA, #+BBBBBBBBBBBBBBBB
390 kFmt35mi, // [opt] inline invoke
391 kFmt3rmi, // [opt] inline invoke/range
392 kFmt33x, // exop vAA, vBB, vCCCC
393 kFmt32s, // exop vAA, vBB, #+CCCC
394 kFmt40sc, // [opt] exop AAAA, thing@BBBBBBBB
395 kFmt41c, // exop vAAAA, thing@BBBBBBBB
396 kFmt52c, // exop vAAAA, vBBBB, thing@CCCCCCCC
397 kFmt5rc, // exop {vCCCC .. v(CCCC+AAAA-1)}, thing@BBBBBBBB
398};
399
400enum InstructionIndexType {
401 kIndexUnknown = 0,
402 kIndexNone, // has no index
403 kIndexVaries, // "It depends." Used for throw-verification-error
404 kIndexTypeRef, // type reference index
405 kIndexStringRef, // string reference index
406 kIndexMethodRef, // method reference index
407 kIndexFieldRef, // field reference index
408 kIndexInlineMethod, // inline method index (for inline linked methods)
409 kIndexVtableOffset, // vtable offset (for static linked methods)
410 kIndexFieldOffset // field offset (for static linked fields)
411};
412
413typedef u1 InstructionWidth;
414
415typedef u1 OpcodeFlags;
416enum OpcodeFlagsBits {
417 kInstrCanBranch = 1, // conditional or unconditional branch
418 kInstrCanContinue = 1 << 1, // flow can continue to next statement
419 kInstrCanSwitch = 1 << 2, // switch statement
420 kInstrCanThrow = 1 << 3, // could cause an exception to be thrown
421 kInstrCanReturn = 1 << 4, // returns, no additional statements
422 kInstrInvoke = 1 << 5, // a flavor of invoke
423};
424
425struct InstructionInfoTables {
426 u1* formats; /* InstructionFormat elements */
427 u1* indexTypes; /* InstructionIndexType elements */
428 OpcodeFlags* flags;
429 InstructionWidth* widths;
430};
431
432extern InstructionInfoTables gDexOpcodeInfo;
433
434struct DecodedInstruction {
435 u4 vA;
436 u4 vB;
437 u8 vB_wide; /* for kFmt51l */
438 u4 vC;
439 u4 arg[5]; /* vC/D/E/F/G in invoke or filled-new-array */
440 Opcode opcode;
441 InstructionIndexType indexType;
442};
443
444#define DEX_INLINE inline
445#define INLINE inline
446
447DEX_INLINE size_t dexGetWidthFromOpcode(Opcode opcode)
448{
449 assert((u4) opcode < kNumPackedOpcodes);
450 return gDexOpcodeInfo.widths[opcode];
451}
452
453size_t dexGetWidthFromInstruction(const u2* insns);
454
455DEX_INLINE OpcodeFlags dexGetFlagsFromOpcode(Opcode opcode)
456{
457 assert((u4) opcode < kNumPackedOpcodes);
458 return gDexOpcodeInfo.flags[opcode];
459}
460
461DEX_INLINE bool dexIsGoto(OpcodeFlags flags)
462{
463 return (flags & (kInstrCanBranch | kInstrCanContinue)) == kInstrCanBranch;
464}
465
466DEX_INLINE InstructionFormat dexGetFormatFromOpcode(Opcode opcode)
467{
468 assert((u4) opcode < kNumPackedOpcodes);
469 return (InstructionFormat) gDexOpcodeInfo.formats[opcode];
470}
471
472DEX_INLINE InstructionIndexType dexGetIndexTypeFromOpcode(Opcode opcode)
473{
474 assert((u4) opcode < kNumPackedOpcodes);
475 return (InstructionIndexType) gDexOpcodeInfo.indexTypes[opcode];
476}
477
478void dexDecodeInstruction(const u2* insns, DecodedInstruction* pDec);
479
480// From DexOpcodes
481const char* dexGetOpcodeName(Opcode op);
482
483DEX_INLINE Opcode dexOpcodeFromCodeUnit(u2 codeUnit) {
484 int lowByte = codeUnit & 0xff;
485 if (lowByte != 0xff) {
486 return (Opcode) lowByte;
487 } else {
488 return (Opcode) ((codeUnit >> 8) | 0x100);
489 }
490}
491
492// From DexFile
493struct DexFile;
494struct DexTry {
495 u4 startAddr; /* start address, in 16-bit code units */
496 u2 insnCount; /* instruction count, in 16-bit code units */
497 u2 handlerOff; /* offset in encoded handler data to handlers */
498};
499struct DexCode {
500 u2 registersSize;
501 u2 insSize;
502 u2 outsSize;
503 u2 triesSize;
504 u4 debugInfoOff; /* file offset to debug info stream */
505 u4 insnsSize; /* size of the insns array, in u2 units */
506 u2 insns[1];
507};
508
509DEX_INLINE const DexTry* dexGetTries(const DexCode* pCode) {
510 const u2* insnsEnd = &pCode->insns[pCode->insnsSize];
511
512 // Round to four bytes.
513 if ((((u4) insnsEnd) & 3) != 0) {
514 insnsEnd++;
515 }
516
517 return (const DexTry*) insnsEnd;
518}
519
520enum {
521 ACC_PUBLIC = 0x00000001, // class, field, method, ic
522 ACC_PRIVATE = 0x00000002, // field, method, ic
523 ACC_PROTECTED = 0x00000004, // field, method, ic
524 ACC_STATIC = 0x00000008, // field, method, ic
525 ACC_FINAL = 0x00000010, // class, field, method, ic
526 ACC_SYNCHRONIZED = 0x00000020, // method (only allowed on natives)
527 ACC_SUPER = 0x00000020, // class (not used in Dalvik)
528 ACC_VOLATILE = 0x00000040, // field
529 ACC_BRIDGE = 0x00000040, // method (1.5)
530 ACC_TRANSIENT = 0x00000080, // field
531 ACC_VARARGS = 0x00000080, // method (1.5)
532 ACC_NATIVE = 0x00000100, // method
533 ACC_INTERFACE = 0x00000200, // class, ic
534 ACC_ABSTRACT = 0x00000400, // class, method, ic
535 ACC_STRICT = 0x00000800, // method
536 ACC_SYNTHETIC = 0x00001000, // field, method, ic
537 ACC_ANNOTATION = 0x00002000, // class, ic (1.5)
538 ACC_ENUM = 0x00004000, // class, field, ic (1.5)
539 ACC_CONSTRUCTOR = 0x00010000, // method (Dalvik only)
540 ACC_DECLARED_SYNCHRONIZED =
541 0x00020000, // method (Dalvik only)
542 ACC_CLASS_MASK =
543 (ACC_PUBLIC | ACC_FINAL | ACC_INTERFACE | ACC_ABSTRACT
544 | ACC_SYNTHETIC | ACC_ANNOTATION | ACC_ENUM),
545 ACC_INNER_CLASS_MASK =
546 (ACC_CLASS_MASK | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC),
547 ACC_FIELD_MASK =
548 (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC | ACC_FINAL
549 | ACC_VOLATILE | ACC_TRANSIENT | ACC_SYNTHETIC | ACC_ENUM),
550 ACC_METHOD_MASK =
551 (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC | ACC_FINAL
552 | ACC_SYNCHRONIZED | ACC_BRIDGE | ACC_VARARGS | ACC_NATIVE
553 | ACC_ABSTRACT | ACC_STRICT | ACC_SYNTHETIC | ACC_CONSTRUCTOR
554 | ACC_DECLARED_SYNCHRONIZED),
555};
556
557// From DexProto
558struct DexProto {
559 const DexFile* dexFile; /* file the idx refers to */
560 u4 protoIdx; /* index into proto_ids table of dexFile */
561};
562char* dexProtoCopyMethodDescriptor(const DexProto* pProto);
563
564// From DexCatch.h
565struct DexCatchHandler {
566 u4 typeIdx; /* type index of the caught exception type */
567 u4 address; /* handler address */
568};
569struct DexCatchIterator {
570 const u1* pEncodedData;
571 bool catchesAll;
572 u4 countRemaining;
573 DexCatchHandler handler;
574};
575bool dexFindCatchHandler(DexCatchIterator *pIterator,
576 const DexCode* pCode, u4 address);
577DexCatchHandler* dexCatchIteratorNext(DexCatchIterator* pIterator);
578u4 dexGetFirstHandlerOffset(const DexCode* pCode);
579u4 dexGetHandlersSize(const DexCode* pCode);
580u4 dexCatchIteratorGetEndOffset(DexCatchIterator* pIterator,
581 const DexCode* pCode);
582void dexCatchIteratorInit(DexCatchIterator* pIterator,
583 const DexCode* pCode, u4 offset);
584
585
586
587// From DvmDex.h
588struct Field;
589struct StringObject;
590struct DvmDex {
591 struct Method** pResMethods;
592 struct ClassObject** pResClasses;
593 struct Field** pResFields;
594 struct StringObject** pResStrings;
595};
596
597// from oo/Object.h
598struct Method {
599 ClassObject* clazz;
600 u2 methodIndex;
601 u2 registersSize;
602 u2 outsSize;
603 u2 insSize;
604 u4 accessFlags;
605 const char* name;
606 const char* shorty;
607 DexProto prototype;
608 void* compiledInsns;
609 DvmDex* pDvmDex;
610 u2* insns;
611 struct Method** pResMethods;
612};
613
614struct Field {
615 ClassObject* clazz; /* class in which the field is declared */
616 const char* name;
617 const char* signature; /* e.g. "I", "[C", "Landroid/os/Debug;" */
618 u4 accessFlags;
619};
620
621struct InstField : Field {
622 int byteOffset;
623};
624/*
625 * Static field.
626 */
627struct StaticField : Field {
628 JValue value; /* initially set from DEX for primitives */
629};
630
631INLINE bool dvmIsVolatileField(const Field* field) {
632 return (field->accessFlags & ACC_VOLATILE) != 0;
633}
634
635INLINE bool dvmIsBytecodeMethod(const Method* method) {
636 return (method->accessFlags & (ACC_NATIVE | ACC_ABSTRACT)) == 0;
637}
638
639INLINE const DexCode* dvmGetMethodCode(const Method* meth) {
640 if (dvmIsBytecodeMethod(meth)) {
641 return (const DexCode*)
642 (((const u1*) meth->insns) - offsetof(DexCode, insns));
643 } else {
644 return NULL;
645 }
646}
647
648// From Thread.h
649struct Thread {
650
651 u4 threadId;
652 u1* cardTable;
653 Object* exception;
654
655 /* Runtime support function pointers */
656 void* (*pMemcpy)(void*, const void*, size_t);
657 float (*pI2f)(int);
658 int (*pF2iz)(float);
659 float (*pD2f)(double);
660 double (*pF2d)(float);
661 double (*pI2d)(int);
662 int (*pD2iz)(double);
663 float (*pL2f)(long);
664 double (*pL2d)(long);
665 s8 (*pArtF2l)(float);
666 s8 (*pArtD2l)(double);
667 float (*pFadd)(float, float);
668 float (*pFsub)(float, float);
669 float (*pFdiv)(float, float);
670 float (*pFmul)(float, float);
671 float (*pFmodf)(float, float);
672 double (*pDadd)(double, double);
673 double (*pDsub)(double, double);
674 double (*pDdiv)(double, double);
675 double (*pDmul)(double, double);
676 double (*pFmod)(double, double);
677 int (*pIdivmod)(int, int);
678 int (*pIdiv)(int, int);
679 long long (*pLdivmod)(long long, long long);
680 bool (*pArtUnlockObject)(struct Thread*, struct Object*);
681 bool (*pArtCanPutArrayElementNoThrow)(const ClassObject*,
682 const ClassObject*);
683 int (*pArtInstanceofNonTrivialNoThrow)
684 (const ClassObject*, const ClassObject*);
685 int (*pArtInstanceofNonTrivial) (const ClassObject*, const ClassObject*);
686 ArrayObject* (*pArtAllocArrayByClass)(ClassObject*, size_t, int);
687 Method* (*pArtFindInterfaceMethodInCache)(ClassObject*, u4, const Method*,
688 DvmDex*);
689 bool (*pArtUnlockObjectNoThrow)(Thread*, Object*);
690 void (*pArtLockObjectNoThrow)(Thread*, Object*);
691 Object* (*pArtAllocObjectNoThrow)(ClassObject*, int);
692 void (*pArtThrowException)(Thread*, Object*);
693 bool (*pArtHandleFillArrayDataNoThrow)(ArrayObject*, const u2*);
694
695};
696
697// From Sync.h
698#define LW_LOCK_OWNER_SHIFT 3
699#define LW_HASH_STATE_SHIFT 1
700#define LW_HASH_STATE_MASK 0x3
701#define LW_SHAPE_THIN 0
702
703
704#include "Compiler.h"
705
706#endif