| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | */ |
| Andy McFadden | b51ea11 | 2009-05-08 16:50:17 -0700 | [diff] [blame] | 16 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 17 | /* |
| 18 | * Declaration of the fundamental Object type and refinements thereof, plus |
| 19 | * some functions for manipulating them. |
| 20 | */ |
| 21 | #ifndef _DALVIK_OO_OBJECT |
| 22 | #define _DALVIK_OO_OBJECT |
| 23 | |
| Andy McFadden | 861b338 | 2010-03-05 15:58:31 -0800 | [diff] [blame] | 24 | #include <Atomic.h> |
| 25 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 26 | #include <stddef.h> |
| 27 | |
| 28 | /* fwd decl */ |
| 29 | struct DataObject; |
| Barry Hayes | 2c98747 | 2009-04-06 10:03:48 -0700 | [diff] [blame] | 30 | struct InitiatingLoaderList; |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 31 | struct ClassObject; |
| 32 | struct StringObject; |
| 33 | struct ArrayObject; |
| 34 | struct Method; |
| 35 | struct ExceptionEntry; |
| 36 | struct LineNumEntry; |
| 37 | struct StaticField; |
| 38 | struct InstField; |
| 39 | struct Field; |
| 40 | struct RegisterMap; |
| 41 | typedef struct DataObject DataObject; |
| Barry Hayes | 2c98747 | 2009-04-06 10:03:48 -0700 | [diff] [blame] | 42 | typedef struct InitiatingLoaderList InitiatingLoaderList; |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 43 | typedef struct ClassObject ClassObject; |
| 44 | typedef struct StringObject StringObject; |
| 45 | typedef struct ArrayObject ArrayObject; |
| 46 | typedef struct Method Method; |
| 47 | typedef struct ExceptionEntry ExceptionEntry; |
| 48 | typedef struct LineNumEntry LineNumEntry; |
| 49 | typedef struct StaticField StaticField; |
| 50 | typedef struct InstField InstField; |
| 51 | typedef struct Field Field; |
| 52 | typedef struct RegisterMap RegisterMap; |
| 53 | |
| 54 | /* |
| 55 | * Native function pointer type. |
| 56 | * |
| 57 | * "args[0]" holds the "this" pointer for virtual methods. |
| 58 | * |
| 59 | * The "Bridge" form is a super-set of the "Native" form; in many places |
| 60 | * they are used interchangeably. Currently, all functions have all |
| 61 | * arguments passed in, but some functions only care about the first two. |
| 62 | * Passing extra arguments to a C function is (mostly) harmless. |
| 63 | */ |
| 64 | typedef void (*DalvikBridgeFunc)(const u4* args, JValue* pResult, |
| 65 | const Method* method, struct Thread* self); |
| 66 | typedef void (*DalvikNativeFunc)(const u4* args, JValue* pResult); |
| 67 | |
| 68 | |
| 69 | /* vm-internal access flags and related definitions */ |
| 70 | typedef enum AccessFlags { |
| 71 | ACC_MIRANDA = 0x8000, // method (internal to VM) |
| 72 | JAVA_FLAGS_MASK = 0xffff, // bits set from Java sources (low 16) |
| 73 | } AccessFlags; |
| 74 | |
| 75 | /* Use the top 16 bits of the access flags field for |
| 76 | * other class flags. Code should use the *CLASS_FLAG*() |
| 77 | * macros to set/get these flags. |
| 78 | */ |
| 79 | typedef enum ClassFlags { |
| 80 | CLASS_ISFINALIZABLE = (1<<31), // class/ancestor overrides finalize() |
| 81 | CLASS_ISARRAY = (1<<30), // class is a "[*" |
| 82 | CLASS_ISOBJECTARRAY = (1<<29), // class is a "[L*" or "[[*" |
| 83 | CLASS_ISREFERENCE = (1<<28), // class is a soft/weak/phantom ref |
| 84 | // only ISREFERENCE is set --> soft |
| 85 | CLASS_ISWEAKREFERENCE = (1<<27), // class is a weak reference |
| 86 | CLASS_ISPHANTOMREFERENCE = (1<<26), // class is a phantom reference |
| 87 | |
| 88 | CLASS_MULTIPLE_DEFS = (1<<25), // DEX verifier: defs in multiple DEXs |
| 89 | |
| 90 | /* unlike the others, these can be present in the optimized DEX file */ |
| 91 | CLASS_ISOPTIMIZED = (1<<17), // class may contain opt instrs |
| 92 | CLASS_ISPREVERIFIED = (1<<16), // class has been pre-verified |
| 93 | } ClassFlags; |
| 94 | |
| 95 | /* bits we can reasonably expect to see set in a DEX access flags field */ |
| 96 | #define EXPECTED_FILE_FLAGS \ |
| 97 | (ACC_CLASS_MASK | CLASS_ISPREVERIFIED | CLASS_ISOPTIMIZED) |
| 98 | |
| Andy McFadden | b51ea11 | 2009-05-08 16:50:17 -0700 | [diff] [blame] | 99 | /* |
| 100 | * Get/set class flags. |
| 101 | */ |
| 102 | #define SET_CLASS_FLAG(clazz, flag) \ |
| 103 | do { (clazz)->accessFlags |= (flag); } while (0) |
| 104 | |
| 105 | #define CLEAR_CLASS_FLAG(clazz, flag) \ |
| 106 | do { (clazz)->accessFlags &= ~(flag); } while (0) |
| 107 | |
| 108 | #define IS_CLASS_FLAG_SET(clazz, flag) \ |
| 109 | (((clazz)->accessFlags & (flag)) != 0) |
| 110 | |
| 111 | #define GET_CLASS_FLAG_GROUP(clazz, flags) \ |
| 112 | ((u4)((clazz)->accessFlags & (flags))) |
| 113 | |
| 114 | /* |
| 115 | * Use the top 16 bits of the access flags field for other method flags. |
| 116 | * Code should use the *METHOD_FLAG*() macros to set/get these flags. |
| 117 | */ |
| 118 | typedef enum MethodFlags { |
| 119 | METHOD_ISWRITABLE = (1<<31), // the method's code is writable |
| 120 | } MethodFlags; |
| 121 | |
| 122 | /* |
| 123 | * Get/set method flags. |
| 124 | */ |
| 125 | #define SET_METHOD_FLAG(method, flag) \ |
| 126 | do { (method)->accessFlags |= (flag); } while (0) |
| 127 | |
| 128 | #define CLEAR_METHOD_FLAG(method, flag) \ |
| 129 | do { (method)->accessFlags &= ~(flag); } while (0) |
| 130 | |
| 131 | #define IS_METHOD_FLAG_SET(method, flag) \ |
| 132 | (((method)->accessFlags & (flag)) != 0) |
| 133 | |
| 134 | #define GET_METHOD_FLAG_GROUP(method, flags) \ |
| 135 | ((u4)((method)->accessFlags & (flags))) |
| 136 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 137 | /* current state of the class, increasing as we progress */ |
| 138 | typedef enum ClassStatus { |
| 139 | CLASS_ERROR = -1, |
| 140 | |
| 141 | CLASS_NOTREADY = 0, |
| Barry Hayes | c49db85 | 2010-05-14 13:43:34 -0700 | [diff] [blame] | 142 | CLASS_IDX = 1, /* loaded, DEX idx in super or ifaces */ |
| 143 | CLASS_LOADED = 2, /* DEX idx values resolved */ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 144 | CLASS_RESOLVED = 3, /* part of linking */ |
| 145 | CLASS_VERIFYING = 4, /* in the process of being verified */ |
| 146 | CLASS_VERIFIED = 5, /* logically part of linking; done pre-init */ |
| 147 | CLASS_INITIALIZING = 6, /* class init in progress */ |
| 148 | CLASS_INITIALIZED = 7, /* ready to go */ |
| 149 | } ClassStatus; |
| 150 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 151 | /* |
| 152 | * Primitive type identifiers. We use these values as indexes into an |
| 153 | * array of synthesized classes, so these start at zero and count up. |
| 154 | * The order is arbitrary (mimics table in doc for newarray opcode), |
| 155 | * but can't be changed without shuffling some reflection tables. |
| 156 | * |
| 157 | * PRIM_VOID can't be used as an array type, but we include it here for |
| 158 | * other uses (e.g. Void.TYPE). |
| 159 | */ |
| 160 | typedef enum PrimitiveType { |
| 161 | PRIM_NOT = -1, /* value is not a primitive type */ |
| 162 | PRIM_BOOLEAN = 0, |
| 163 | PRIM_CHAR = 1, |
| 164 | PRIM_FLOAT = 2, |
| 165 | PRIM_DOUBLE = 3, |
| 166 | PRIM_BYTE = 4, |
| 167 | PRIM_SHORT = 5, |
| 168 | PRIM_INT = 6, |
| 169 | PRIM_LONG = 7, |
| 170 | PRIM_VOID = 8, |
| 171 | |
| 172 | PRIM_MAX |
| 173 | } PrimitiveType; |
| 174 | #define PRIM_TYPE_TO_LETTER "ZCFDBSIJV" /* must match order in enum */ |
| 175 | |
| 176 | /* |
| Barry Hayes | eac47ed | 2009-06-22 11:45:20 -0700 | [diff] [blame] | 177 | * Definitions for packing refOffsets in ClassObject. |
| 178 | */ |
| 179 | /* |
| 180 | * A magic value for refOffsets. Ignore the bits and walk the super |
| 181 | * chain when this is the value. |
| 182 | * [This is an unlikely "natural" value, since it would be 30 non-ref instance |
| 183 | * fields followed by 2 ref instance fields.] |
| 184 | */ |
| 185 | #define CLASS_WALK_SUPER ((unsigned int)(3)) |
| 186 | #define CLASS_SMALLEST_OFFSET (sizeof(struct Object)) |
| 187 | #define CLASS_BITS_PER_WORD (sizeof(unsigned long int) * 8) |
| 188 | #define CLASS_OFFSET_ALIGNMENT 4 |
| 189 | #define CLASS_HIGH_BIT ((unsigned int)1 << (CLASS_BITS_PER_WORD - 1)) |
| 190 | /* |
| Barry Hayes | 6daaac1 | 2009-07-08 10:01:56 -0700 | [diff] [blame] | 191 | * Given an offset, return the bit number which would encode that offset. |
| 192 | * Local use only. |
| 193 | */ |
| 194 | #define _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) \ |
| 195 | (((unsigned int)(byteOffset) - CLASS_SMALLEST_OFFSET) / \ |
| 196 | CLASS_OFFSET_ALIGNMENT) |
| 197 | /* |
| 198 | * Is the given offset too large to be encoded? |
| 199 | */ |
| 200 | #define CLASS_CAN_ENCODE_OFFSET(byteOffset) \ |
| 201 | (_CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) < CLASS_BITS_PER_WORD) |
| 202 | /* |
| 203 | * Return a single bit, encoding the offset. |
| 204 | * Undefined if the offset is too large, as defined above. |
| Barry Hayes | eac47ed | 2009-06-22 11:45:20 -0700 | [diff] [blame] | 205 | */ |
| 206 | #define CLASS_BIT_FROM_OFFSET(byteOffset) \ |
| Barry Hayes | 6daaac1 | 2009-07-08 10:01:56 -0700 | [diff] [blame] | 207 | (CLASS_HIGH_BIT >> _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset)) |
| Barry Hayes | eac47ed | 2009-06-22 11:45:20 -0700 | [diff] [blame] | 208 | /* |
| 209 | * Return an offset, given a bit number as returned from CLZ. |
| 210 | */ |
| 211 | #define CLASS_OFFSET_FROM_CLZ(rshift) \ |
| 212 | (((int)(rshift) * CLASS_OFFSET_ALIGNMENT) + CLASS_SMALLEST_OFFSET) |
| 213 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 214 | |
| 215 | /* |
| 216 | * Used for iftable in ClassObject. |
| 217 | */ |
| 218 | typedef struct InterfaceEntry { |
| 219 | /* pointer to interface class */ |
| 220 | ClassObject* clazz; |
| 221 | |
| 222 | /* |
| 223 | * Index into array of vtable offsets. This points into the ifviPool, |
| 224 | * which holds the vtables for all interfaces declared by this class. |
| 225 | */ |
| 226 | int* methodIndexArray; |
| 227 | } InterfaceEntry; |
| 228 | |
| 229 | |
| 230 | |
| 231 | /* |
| 232 | * There are three types of objects: |
| 233 | * Class objects - an instance of java.lang.Class |
| 234 | * Array objects - an object created with a "new array" instruction |
| 235 | * Data objects - an object that is neither of the above |
| 236 | * |
| 237 | * We also define String objects. At present they're equivalent to |
| 238 | * DataObject, but that may change. (Either way, they make some of the |
| 239 | * code more obvious.) |
| 240 | * |
| 241 | * All objects have an Object header followed by type-specific data. |
| 242 | */ |
| 243 | typedef struct Object { |
| 244 | /* ptr to class object */ |
| 245 | ClassObject* clazz; |
| 246 | |
| Carl Shapiro | 8d7f9b2 | 2009-12-21 20:23:45 -0800 | [diff] [blame] | 247 | /* |
| 248 | * A word containing either a "thin" lock or a "fat" monitor. See |
| 249 | * the comments in Sync.c for a description of its layout. |
| 250 | */ |
| 251 | u4 lock; |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 252 | } Object; |
| 253 | |
| 254 | /* |
| 255 | * Properly initialize an Object. |
| 256 | * void DVM_OBJECT_INIT(Object *obj, ClassObject *clazz_) |
| 257 | */ |
| 258 | #define DVM_OBJECT_INIT(obj, clazz_) \ |
| 259 | do { (obj)->clazz = (clazz_); DVM_LOCK_INIT(&(obj)->lock); } while (0) |
| 260 | |
| 261 | /* |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 262 | * Data objects have an Object header followed by their instance data. |
| 263 | */ |
| 264 | struct DataObject { |
| 265 | Object obj; /* MUST be first item */ |
| 266 | |
| 267 | /* variable #of u4 slots; u8 uses 2 slots */ |
| 268 | u4 instanceData[1]; |
| 269 | }; |
| 270 | |
| 271 | /* |
| 272 | * Strings are used frequently enough that we may want to give them their |
| 273 | * own unique type. |
| 274 | * |
| 275 | * Using a dedicated type object to access the instance data provides a |
| 276 | * performance advantage but makes the java/lang/String.java implementation |
| 277 | * fragile. |
| 278 | * |
| 279 | * Currently this is just equal to DataObject, and we pull the fields out |
| 280 | * like we do for any other object. |
| 281 | */ |
| 282 | struct StringObject { |
| 283 | Object obj; /* MUST be first item */ |
| 284 | |
| 285 | /* variable #of u4 slots; u8 uses 2 slots */ |
| 286 | u4 instanceData[1]; |
| 287 | }; |
| 288 | |
| 289 | |
| 290 | /* |
| 291 | * Array objects have these additional fields. |
| 292 | * |
| 293 | * We don't currently store the size of each element. Usually it's implied |
| 294 | * by the instruction. If necessary, the width can be derived from |
| Elliott Hughes | beea0b7 | 2009-11-13 11:20:15 -0800 | [diff] [blame] | 295 | * the first char of obj->clazz->descriptor. |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 296 | */ |
| 297 | struct ArrayObject { |
| 298 | Object obj; /* MUST be first item */ |
| 299 | |
| 300 | /* number of elements; immutable after init */ |
| 301 | u4 length; |
| 302 | |
| 303 | /* |
| 304 | * Array contents; actual size is (length * sizeof(type)). This is |
| 305 | * declared as u8 so that the compiler inserts any necessary padding |
| 306 | * (e.g. for EABI); the actual allocation may be smaller than 8 bytes. |
| 307 | */ |
| 308 | u8 contents[1]; |
| 309 | }; |
| 310 | |
| 311 | /* |
| Barry Hayes | 2c98747 | 2009-04-06 10:03:48 -0700 | [diff] [blame] | 312 | * For classes created early and thus probably in the zygote, the |
| 313 | * InitiatingLoaderList is kept in gDvm. Later classes use the structure in |
| 314 | * Object Class. This helps keep zygote pages shared. |
| 315 | */ |
| 316 | struct InitiatingLoaderList { |
| 317 | /* a list of initiating loader Objects; grown and initialized on demand */ |
| 318 | Object** initiatingLoaders; |
| 319 | /* count of loaders in the above list */ |
| 320 | int initiatingLoaderCount; |
| 321 | }; |
| 322 | |
| 323 | /* |
| Barry Hayes | 03aa70a | 2010-03-01 15:49:41 -0800 | [diff] [blame] | 324 | * Generic field header. We pass this around when we want a generic Field |
| 325 | * pointer (e.g. for reflection stuff). Testing the accessFlags for |
| 326 | * ACC_STATIC allows a proper up-cast. |
| 327 | */ |
| 328 | struct Field { |
| 329 | ClassObject* clazz; /* class in which the field is declared */ |
| 330 | const char* name; |
| 331 | const char* signature; /* e.g. "I", "[C", "Landroid/os/Debug;" */ |
| 332 | u4 accessFlags; |
| 333 | #ifdef PROFILE_FIELD_ACCESS |
| 334 | u4 gets; |
| 335 | u4 puts; |
| 336 | #endif |
| 337 | }; |
| 338 | |
| 339 | /* |
| 340 | * Static field. |
| 341 | */ |
| 342 | struct StaticField { |
| 343 | Field field; /* MUST be first item */ |
| 344 | JValue value; /* initially set from DEX for primitives */ |
| 345 | }; |
| 346 | |
| 347 | /* |
| 348 | * Instance field. |
| 349 | */ |
| 350 | struct InstField { |
| 351 | Field field; /* MUST be first item */ |
| 352 | |
| 353 | /* |
| 354 | * This field indicates the byte offset from the beginning of the |
| 355 | * (Object *) to the actual instance data; e.g., byteOffset==0 is |
| 356 | * the same as the object pointer (bug!), and byteOffset==4 is 4 |
| 357 | * bytes farther. |
| 358 | */ |
| 359 | int byteOffset; |
| 360 | }; |
| 361 | |
| 362 | /* |
| Andy McFadden | b51ea11 | 2009-05-08 16:50:17 -0700 | [diff] [blame] | 363 | * This defines the amount of space we leave for field slots in the |
| 364 | * java.lang.Class definition. If we alter the class to have more than |
| 365 | * this many fields, the VM will abort at startup. |
| 366 | */ |
| 367 | #define CLASS_FIELD_SLOTS 4 |
| 368 | |
| 369 | /* |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 370 | * Class objects have many additional fields. This is used for both |
| 371 | * classes and interfaces, including synthesized classes (arrays and |
| 372 | * primitive types). |
| 373 | * |
| 374 | * Class objects are unusual in that they have some fields allocated with |
| 375 | * the system malloc (or LinearAlloc), rather than on the GC heap. This is |
| 376 | * handy during initialization, but does require special handling when |
| 377 | * discarding java.lang.Class objects. |
| 378 | * |
| 379 | * The separation of methods (direct vs. virtual) and fields (class vs. |
| 380 | * instance) used in Dalvik works out pretty well. The only time it's |
| 381 | * annoying is when enumerating or searching for things with reflection. |
| 382 | */ |
| 383 | struct ClassObject { |
| 384 | Object obj; /* MUST be first item */ |
| 385 | |
| 386 | /* leave space for instance data; we could access fields directly if we |
| 387 | freeze the definition of java/lang/Class */ |
| 388 | u4 instanceData[CLASS_FIELD_SLOTS]; |
| 389 | |
| 390 | /* UTF-8 descriptor for the class; from constant pool, or on heap |
| 391 | if generated ("[C") */ |
| 392 | const char* descriptor; |
| 393 | char* descriptorAlloc; |
| 394 | |
| 395 | /* access flags; low 16 bits are defined by VM spec */ |
| 396 | u4 accessFlags; |
| 397 | |
| 398 | /* VM-unique class serial number, nonzero, set very early */ |
| 399 | u4 serialNumber; |
| 400 | |
| 401 | /* DexFile from which we came; needed to resolve constant pool entries */ |
| 402 | /* (will be NULL for VM-generated, e.g. arrays and primitive classes) */ |
| 403 | DvmDex* pDvmDex; |
| 404 | |
| 405 | /* state of class initialization */ |
| 406 | ClassStatus status; |
| 407 | |
| 408 | /* if class verify fails, we must return same error on subsequent tries */ |
| 409 | ClassObject* verifyErrorClass; |
| 410 | |
| 411 | /* threadId, used to check for recursive <clinit> invocation */ |
| 412 | u4 initThreadId; |
| 413 | |
| 414 | /* |
| 415 | * Total object size; used when allocating storage on gc heap. (For |
| 416 | * interfaces and abstract classes this will be zero.) |
| 417 | */ |
| 418 | size_t objectSize; |
| 419 | |
| 420 | /* arrays only: class object for base element, for instanceof/checkcast |
| 421 | (for String[][][], this will be String) */ |
| 422 | ClassObject* elementClass; |
| 423 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 424 | /* arrays only: number of dimensions, e.g. int[][] is 2 */ |
| 425 | int arrayDim; |
| 426 | |
| 427 | /* primitive type index, or PRIM_NOT (-1); set for generated prim classes */ |
| 428 | PrimitiveType primitiveType; |
| 429 | |
| 430 | /* superclass, or NULL if this is java.lang.Object */ |
| 431 | ClassObject* super; |
| 432 | |
| 433 | /* defining class loader, or NULL for the "bootstrap" system loader */ |
| 434 | Object* classLoader; |
| 435 | |
| 436 | /* initiating class loader list */ |
| Barry Hayes | 2c98747 | 2009-04-06 10:03:48 -0700 | [diff] [blame] | 437 | /* NOTE: for classes with low serialNumber, these are unused, and the |
| 438 | values are kept in a table in gDvm. */ |
| 439 | InitiatingLoaderList initiatingLoaderList; |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 440 | |
| 441 | /* array of interfaces this class implements directly */ |
| 442 | int interfaceCount; |
| 443 | ClassObject** interfaces; |
| 444 | |
| 445 | /* static, private, and <init> methods */ |
| 446 | int directMethodCount; |
| 447 | Method* directMethods; |
| 448 | |
| 449 | /* virtual methods defined in this class; invoked through vtable */ |
| 450 | int virtualMethodCount; |
| 451 | Method* virtualMethods; |
| 452 | |
| 453 | /* |
| 454 | * Virtual method table (vtable), for use by "invoke-virtual". The |
| 455 | * vtable from the superclass is copied in, and virtual methods from |
| 456 | * our class either replace those from the super or are appended. |
| 457 | */ |
| 458 | int vtableCount; |
| 459 | Method** vtable; |
| 460 | |
| 461 | /* |
| 462 | * Interface table (iftable), one entry per interface supported by |
| 463 | * this class. That means one entry for each interface we support |
| 464 | * directly, indirectly via superclass, or indirectly via |
| 465 | * superinterface. This will be null if neither we nor our superclass |
| 466 | * implement any interfaces. |
| 467 | * |
| 468 | * Why we need this: given "class Foo implements Face", declare |
| 469 | * "Face faceObj = new Foo()". Invoke faceObj.blah(), where "blah" is |
| 470 | * part of the Face interface. We can't easily use a single vtable. |
| 471 | * |
| 472 | * For every interface a concrete class implements, we create a list of |
| 473 | * virtualMethod indices for the methods in the interface. |
| 474 | */ |
| 475 | int iftableCount; |
| 476 | InterfaceEntry* iftable; |
| 477 | |
| 478 | /* |
| 479 | * The interface vtable indices for iftable get stored here. By placing |
| 480 | * them all in a single pool for each class that implements interfaces, |
| 481 | * we decrease the number of allocations. |
| 482 | */ |
| 483 | int ifviPoolCount; |
| 484 | int* ifviPool; |
| 485 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 486 | /* instance fields |
| 487 | * |
| 488 | * These describe the layout of the contents of a DataObject-compatible |
| 489 | * Object. Note that only the fields directly defined by this class |
| 490 | * are listed in ifields; fields defined by a superclass are listed |
| 491 | * in the superclass's ClassObject.ifields. |
| 492 | * |
| 493 | * All instance fields that refer to objects are guaranteed to be |
| 494 | * at the beginning of the field list. ifieldRefCount specifies |
| 495 | * the number of reference fields. |
| 496 | */ |
| 497 | int ifieldCount; |
| 498 | int ifieldRefCount; // number of fields that are object refs |
| 499 | InstField* ifields; |
| 500 | |
| Barry Hayes | eac47ed | 2009-06-22 11:45:20 -0700 | [diff] [blame] | 501 | /* bitmap of offsets of ifields */ |
| 502 | u4 refOffsets; |
| 503 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 504 | /* source file name, if known */ |
| 505 | const char* sourceFile; |
| Barry Hayes | 03aa70a | 2010-03-01 15:49:41 -0800 | [diff] [blame] | 506 | |
| 507 | /* static fields */ |
| 508 | int sfieldCount; |
| 509 | StaticField sfields[]; /* MUST be last item */ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 510 | }; |
| 511 | |
| 512 | /* |
| 513 | * A method. We create one of these for every method in every class |
| 514 | * we load, so try to keep the size to a minimum. |
| 515 | * |
| 516 | * Much of this comes from and could be accessed in the data held in shared |
| 517 | * memory. We hold it all together here for speed. Everything but the |
| 518 | * pointers could be held in a shared table generated by the optimizer; |
| 519 | * if we're willing to convert them to offsets and take the performance |
| 520 | * hit (e.g. "meth->insns" becomes "baseAddr + meth->insnsOffset") we |
| 521 | * could move everything but "nativeFunc". |
| 522 | */ |
| 523 | struct Method { |
| 524 | /* the class we are a part of */ |
| 525 | ClassObject* clazz; |
| 526 | |
| 527 | /* access flags; low 16 bits are defined by spec (could be u2?) */ |
| 528 | u4 accessFlags; |
| 529 | |
| 530 | /* |
| 531 | * For concrete virtual methods, this is the offset of the method |
| 532 | * in "vtable". |
| 533 | * |
| 534 | * For abstract methods in an interface class, this is the offset |
| 535 | * of the method in "iftable[n]->methodIndexArray". |
| 536 | */ |
| 537 | u2 methodIndex; |
| 538 | |
| 539 | /* |
| 540 | * Method bounds; not needed for an abstract method. |
| 541 | * |
| 542 | * For a native method, we compute the size of the argument list, and |
| 543 | * set "insSize" and "registerSize" equal to it. |
| 544 | */ |
| 545 | u2 registersSize; /* ins + locals */ |
| 546 | u2 outsSize; |
| 547 | u2 insSize; |
| 548 | |
| 549 | /* method name, e.g. "<init>" or "eatLunch" */ |
| 550 | const char* name; |
| 551 | |
| 552 | /* |
| 553 | * Method prototype descriptor string (return and argument types). |
| 554 | * |
| 555 | * TODO: This currently must specify the DexFile as well as the proto_ids |
| 556 | * index, because generated Proxy classes don't have a DexFile. We can |
| 557 | * remove the DexFile* and reduce the size of this struct if we generate |
| 558 | * a DEX for proxies. |
| 559 | */ |
| 560 | DexProto prototype; |
| 561 | |
| 562 | /* short-form method descriptor string */ |
| 563 | const char* shorty; |
| 564 | |
| 565 | /* |
| 566 | * The remaining items are not used for abstract or native methods. |
| 567 | * (JNI is currently hijacking "insns" as a function pointer, set |
| 568 | * after the first call. For internal-native this stays null.) |
| 569 | */ |
| 570 | |
| 571 | /* the actual code */ |
| 572 | const u2* insns; /* instructions, in memory-mapped .dex */ |
| 573 | |
| 574 | /* cached JNI argument and return-type hints */ |
| 575 | int jniArgInfo; |
| 576 | |
| 577 | /* |
| 578 | * Native method ptr; could be actual function or a JNI bridge. We |
| 579 | * don't currently discriminate between DalvikBridgeFunc and |
| 580 | * DalvikNativeFunc; the former takes an argument superset (i.e. two |
| 581 | * extra args) which will be ignored. If necessary we can use |
| 582 | * insns==NULL to detect JNI bridge vs. internal native. |
| 583 | */ |
| 584 | DalvikBridgeFunc nativeFunc; |
| 585 | |
| 586 | /* |
| 587 | * Register map data, if available. This will point into the DEX file |
| 588 | * if the data was computed during pre-verification, or into the |
| 589 | * linear alloc area if not. |
| 590 | */ |
| 591 | const RegisterMap* registerMap; |
| 592 | |
| 593 | #ifdef WITH_PROFILER |
| 594 | bool inProfile; |
| 595 | #endif |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 596 | }; |
| 597 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 598 | |
| 599 | /* |
| 600 | * Find a method within a class. The superclass is not searched. |
| 601 | */ |
| 602 | Method* dvmFindDirectMethodByDescriptor(const ClassObject* clazz, |
| 603 | const char* methodName, const char* signature); |
| 604 | Method* dvmFindVirtualMethodByDescriptor(const ClassObject* clazz, |
| 605 | const char* methodName, const char* signature); |
| 606 | Method* dvmFindVirtualMethodByName(const ClassObject* clazz, |
| 607 | const char* methodName); |
| 608 | Method* dvmFindDirectMethod(const ClassObject* clazz, const char* methodName, |
| 609 | const DexProto* proto); |
| 610 | Method* dvmFindVirtualMethod(const ClassObject* clazz, const char* methodName, |
| 611 | const DexProto* proto); |
| 612 | |
| 613 | |
| 614 | /* |
| 615 | * Find a method within a class hierarchy. |
| 616 | */ |
| 617 | Method* dvmFindDirectMethodHierByDescriptor(const ClassObject* clazz, |
| 618 | const char* methodName, const char* descriptor); |
| 619 | Method* dvmFindVirtualMethodHierByDescriptor(const ClassObject* clazz, |
| 620 | const char* methodName, const char* signature); |
| 621 | Method* dvmFindDirectMethodHier(const ClassObject* clazz, |
| 622 | const char* methodName, const DexProto* proto); |
| 623 | Method* dvmFindVirtualMethodHier(const ClassObject* clazz, |
| 624 | const char* methodName, const DexProto* proto); |
| Andy McFadden | 1d9206d | 2009-07-15 14:34:49 -0700 | [diff] [blame] | 625 | Method* dvmFindMethodHier(const ClassObject* clazz, const char* methodName, |
| 626 | const DexProto* proto); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 627 | |
| 628 | /* |
| 629 | * Find the implementation of "meth" in "clazz". |
| 630 | * |
| 631 | * Returns NULL and throws an exception if not found. |
| 632 | */ |
| 633 | const Method* dvmGetVirtualizedMethod(const ClassObject* clazz, |
| 634 | const Method* meth); |
| 635 | |
| 636 | /* |
| 637 | * Get the source file associated with a method. |
| 638 | */ |
| 639 | const char* dvmGetMethodSourceFile(const Method* meth); |
| 640 | |
| 641 | /* |
| 642 | * Find a field within a class. The superclass is not searched. |
| 643 | */ |
| 644 | InstField* dvmFindInstanceField(const ClassObject* clazz, |
| 645 | const char* fieldName, const char* signature); |
| 646 | StaticField* dvmFindStaticField(const ClassObject* clazz, |
| 647 | const char* fieldName, const char* signature); |
| 648 | |
| 649 | /* |
| 650 | * Find a field in a class/interface hierarchy. |
| 651 | */ |
| 652 | InstField* dvmFindInstanceFieldHier(const ClassObject* clazz, |
| 653 | const char* fieldName, const char* signature); |
| 654 | StaticField* dvmFindStaticFieldHier(const ClassObject* clazz, |
| 655 | const char* fieldName, const char* signature); |
| Andy McFadden | 1d9206d | 2009-07-15 14:34:49 -0700 | [diff] [blame] | 656 | Field* dvmFindFieldHier(const ClassObject* clazz, const char* fieldName, |
| 657 | const char* signature); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 658 | |
| 659 | /* |
| 660 | * Find a field and return the byte offset from the object pointer. Only |
| 661 | * searches the specified class, not the superclass. |
| 662 | * |
| 663 | * Returns -1 on failure. |
| 664 | */ |
| 665 | INLINE int dvmFindFieldOffset(const ClassObject* clazz, |
| 666 | const char* fieldName, const char* signature) |
| 667 | { |
| 668 | InstField* pField = dvmFindInstanceField(clazz, fieldName, signature); |
| 669 | if (pField == NULL) |
| 670 | return -1; |
| 671 | else |
| 672 | return pField->byteOffset; |
| 673 | } |
| 674 | |
| 675 | /* |
| 676 | * Field access functions. Pass in the word offset from Field->byteOffset. |
| 677 | * |
| 678 | * We guarantee that long/double field data is 64-bit aligned, so it's safe |
| 679 | * to access them with ldrd/strd on ARM. |
| 680 | * |
| 681 | * The VM treats all fields as 32 or 64 bits, so the field set functions |
| 682 | * write 32 bits even if the underlying type is smaller. |
| 683 | */ |
| 684 | #define BYTE_OFFSET(_ptr, _offset) ((void*) (((u1*)(_ptr)) + (_offset))) |
| 685 | |
| 686 | INLINE JValue* dvmFieldPtr(const Object* obj, int offset) { |
| 687 | return ((JValue*)BYTE_OFFSET(obj, offset)); |
| 688 | } |
| 689 | |
| 690 | INLINE bool dvmGetFieldBoolean(const Object* obj, int offset) { |
| 691 | return ((JValue*)BYTE_OFFSET(obj, offset))->z; |
| 692 | } |
| 693 | INLINE s1 dvmGetFieldByte(const Object* obj, int offset) { |
| 694 | return ((JValue*)BYTE_OFFSET(obj, offset))->b; |
| 695 | } |
| 696 | INLINE s2 dvmGetFieldShort(const Object* obj, int offset) { |
| 697 | return ((JValue*)BYTE_OFFSET(obj, offset))->s; |
| 698 | } |
| 699 | INLINE u2 dvmGetFieldChar(const Object* obj, int offset) { |
| 700 | return ((JValue*)BYTE_OFFSET(obj, offset))->c; |
| 701 | } |
| 702 | INLINE s4 dvmGetFieldInt(const Object* obj, int offset) { |
| 703 | return ((JValue*)BYTE_OFFSET(obj, offset))->i; |
| 704 | } |
| 705 | INLINE s8 dvmGetFieldLong(const Object* obj, int offset) { |
| 706 | return ((JValue*)BYTE_OFFSET(obj, offset))->j; |
| 707 | } |
| 708 | INLINE float dvmGetFieldFloat(const Object* obj, int offset) { |
| 709 | return ((JValue*)BYTE_OFFSET(obj, offset))->f; |
| 710 | } |
| 711 | INLINE double dvmGetFieldDouble(const Object* obj, int offset) { |
| 712 | return ((JValue*)BYTE_OFFSET(obj, offset))->d; |
| 713 | } |
| 714 | INLINE Object* dvmGetFieldObject(const Object* obj, int offset) { |
| 715 | return ((JValue*)BYTE_OFFSET(obj, offset))->l; |
| 716 | } |
| Andy McFadden | 861b338 | 2010-03-05 15:58:31 -0800 | [diff] [blame] | 717 | INLINE s8 dvmGetFieldLongVolatile(const Object* obj, int offset) { |
| 718 | const s8* addr = BYTE_OFFSET(obj, offset); |
| 719 | return android_quasiatomic_read_64((s8*)addr); |
| 720 | } |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 721 | |
| 722 | INLINE void dvmSetFieldBoolean(Object* obj, int offset, bool val) { |
| 723 | ((JValue*)BYTE_OFFSET(obj, offset))->i = val; |
| 724 | } |
| 725 | INLINE void dvmSetFieldByte(Object* obj, int offset, s1 val) { |
| 726 | ((JValue*)BYTE_OFFSET(obj, offset))->i = val; |
| 727 | } |
| 728 | INLINE void dvmSetFieldShort(Object* obj, int offset, s2 val) { |
| 729 | ((JValue*)BYTE_OFFSET(obj, offset))->i = val; |
| 730 | } |
| 731 | INLINE void dvmSetFieldChar(Object* obj, int offset, u2 val) { |
| 732 | ((JValue*)BYTE_OFFSET(obj, offset))->i = val; |
| 733 | } |
| 734 | INLINE void dvmSetFieldInt(Object* obj, int offset, s4 val) { |
| 735 | ((JValue*)BYTE_OFFSET(obj, offset))->i = val; |
| 736 | } |
| 737 | INLINE void dvmSetFieldLong(Object* obj, int offset, s8 val) { |
| 738 | ((JValue*)BYTE_OFFSET(obj, offset))->j = val; |
| 739 | } |
| 740 | INLINE void dvmSetFieldFloat(Object* obj, int offset, float val) { |
| 741 | ((JValue*)BYTE_OFFSET(obj, offset))->f = val; |
| 742 | } |
| 743 | INLINE void dvmSetFieldDouble(Object* obj, int offset, double val) { |
| 744 | ((JValue*)BYTE_OFFSET(obj, offset))->d = val; |
| 745 | } |
| 746 | INLINE void dvmSetFieldObject(Object* obj, int offset, Object* val) { |
| 747 | ((JValue*)BYTE_OFFSET(obj, offset))->l = val; |
| 748 | } |
| Andy McFadden | 861b338 | 2010-03-05 15:58:31 -0800 | [diff] [blame] | 749 | INLINE void dvmSetFieldLongVolatile(Object* obj, int offset, s8 val) { |
| 750 | s8* addr = BYTE_OFFSET(obj, offset); |
| 751 | android_quasiatomic_swap_64(val, addr); |
| 752 | } |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 753 | |
| 754 | /* |
| 755 | * Static field access functions. |
| 756 | */ |
| 757 | INLINE JValue* dvmStaticFieldPtr(const StaticField* sfield) { |
| 758 | return (JValue*)&sfield->value; |
| 759 | } |
| 760 | |
| 761 | INLINE bool dvmGetStaticFieldBoolean(const StaticField* sfield) { |
| 762 | return sfield->value.z; |
| 763 | } |
| 764 | INLINE s1 dvmGetStaticFieldByte(const StaticField* sfield) { |
| 765 | return sfield->value.b; |
| 766 | } |
| 767 | INLINE s2 dvmGetStaticFieldShort(const StaticField* sfield) { |
| 768 | return sfield->value.s; |
| 769 | } |
| 770 | INLINE u2 dvmGetStaticFieldChar(const StaticField* sfield) { |
| 771 | return sfield->value.c; |
| 772 | } |
| 773 | INLINE s4 dvmGetStaticFieldInt(const StaticField* sfield) { |
| 774 | return sfield->value.i; |
| 775 | } |
| 776 | INLINE s8 dvmGetStaticFieldLong(const StaticField* sfield) { |
| 777 | return sfield->value.j; |
| 778 | } |
| 779 | INLINE float dvmGetStaticFieldFloat(const StaticField* sfield) { |
| 780 | return sfield->value.f; |
| 781 | } |
| 782 | INLINE double dvmGetStaticFieldDouble(const StaticField* sfield) { |
| 783 | return sfield->value.d; |
| 784 | } |
| 785 | INLINE Object* dvmGetStaticFieldObject(const StaticField* sfield) { |
| 786 | return sfield->value.l; |
| 787 | } |
| Andy McFadden | 861b338 | 2010-03-05 15:58:31 -0800 | [diff] [blame] | 788 | INLINE s8 dvmGetStaticFieldLongVolatile(const StaticField* sfield) { |
| 789 | const s8* addr = &sfield->value.j; |
| 790 | return android_quasiatomic_read_64((s8*)addr); |
| 791 | } |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 792 | |
| 793 | INLINE void dvmSetStaticFieldBoolean(StaticField* sfield, bool val) { |
| 794 | sfield->value.i = val; |
| 795 | } |
| 796 | INLINE void dvmSetStaticFieldByte(StaticField* sfield, s1 val) { |
| 797 | sfield->value.i = val; |
| 798 | } |
| 799 | INLINE void dvmSetStaticFieldShort(StaticField* sfield, s2 val) { |
| 800 | sfield->value.i = val; |
| 801 | } |
| 802 | INLINE void dvmSetStaticFieldChar(StaticField* sfield, u2 val) { |
| 803 | sfield->value.i = val; |
| 804 | } |
| 805 | INLINE void dvmSetStaticFieldInt(StaticField* sfield, s4 val) { |
| 806 | sfield->value.i = val; |
| 807 | } |
| 808 | INLINE void dvmSetStaticFieldLong(StaticField* sfield, s8 val) { |
| 809 | sfield->value.j = val; |
| 810 | } |
| 811 | INLINE void dvmSetStaticFieldFloat(StaticField* sfield, float val) { |
| 812 | sfield->value.f = val; |
| 813 | } |
| 814 | INLINE void dvmSetStaticFieldDouble(StaticField* sfield, double val) { |
| 815 | sfield->value.d = val; |
| 816 | } |
| 817 | INLINE void dvmSetStaticFieldObject(StaticField* sfield, Object* val) { |
| 818 | sfield->value.l = val; |
| 819 | } |
| Andy McFadden | 861b338 | 2010-03-05 15:58:31 -0800 | [diff] [blame] | 820 | INLINE void dvmSetStaticFieldLongVolatile(StaticField* sfield, s8 val) { |
| 821 | s8* addr = &sfield->value.j; |
| 822 | android_quasiatomic_swap_64(val, addr); |
| 823 | } |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 824 | |
| 825 | /* |
| 826 | * Helpers. |
| 827 | */ |
| 828 | INLINE bool dvmIsPublicMethod(const Method* method) { |
| 829 | return (method->accessFlags & ACC_PUBLIC) != 0; |
| 830 | } |
| 831 | INLINE bool dvmIsPrivateMethod(const Method* method) { |
| 832 | return (method->accessFlags & ACC_PRIVATE) != 0; |
| 833 | } |
| 834 | INLINE bool dvmIsStaticMethod(const Method* method) { |
| 835 | return (method->accessFlags & ACC_STATIC) != 0; |
| 836 | } |
| 837 | INLINE bool dvmIsSynchronizedMethod(const Method* method) { |
| 838 | return (method->accessFlags & ACC_SYNCHRONIZED) != 0; |
| 839 | } |
| 840 | INLINE bool dvmIsDeclaredSynchronizedMethod(const Method* method) { |
| 841 | return (method->accessFlags & ACC_DECLARED_SYNCHRONIZED) != 0; |
| 842 | } |
| 843 | INLINE bool dvmIsFinalMethod(const Method* method) { |
| 844 | return (method->accessFlags & ACC_FINAL) != 0; |
| 845 | } |
| 846 | INLINE bool dvmIsNativeMethod(const Method* method) { |
| 847 | return (method->accessFlags & ACC_NATIVE) != 0; |
| 848 | } |
| 849 | INLINE bool dvmIsAbstractMethod(const Method* method) { |
| 850 | return (method->accessFlags & ACC_ABSTRACT) != 0; |
| 851 | } |
| 852 | INLINE bool dvmIsMirandaMethod(const Method* method) { |
| 853 | return (method->accessFlags & ACC_MIRANDA) != 0; |
| 854 | } |
| 855 | INLINE bool dvmIsConstructorMethod(const Method* method) { |
| 856 | return *method->name == '<'; |
| 857 | } |
| 858 | /* Dalvik puts private, static, and constructors into non-virtual table */ |
| 859 | INLINE bool dvmIsDirectMethod(const Method* method) { |
| 860 | return dvmIsPrivateMethod(method) || |
| 861 | dvmIsStaticMethod(method) || |
| 862 | dvmIsConstructorMethod(method); |
| 863 | } |
| 864 | /* Get whether the given method has associated bytecode. This is the |
| 865 | * case for methods which are neither native nor abstract. */ |
| 866 | INLINE bool dvmIsBytecodeMethod(const Method* method) { |
| 867 | return (method->accessFlags & (ACC_NATIVE | ACC_ABSTRACT)) == 0; |
| 868 | } |
| 869 | |
| 870 | INLINE bool dvmIsProtectedField(const Field* field) { |
| 871 | return (field->accessFlags & ACC_PROTECTED) != 0; |
| 872 | } |
| 873 | INLINE bool dvmIsStaticField(const Field* field) { |
| 874 | return (field->accessFlags & ACC_STATIC) != 0; |
| 875 | } |
| 876 | INLINE bool dvmIsFinalField(const Field* field) { |
| 877 | return (field->accessFlags & ACC_FINAL) != 0; |
| 878 | } |
| Andy McFadden | 861b338 | 2010-03-05 15:58:31 -0800 | [diff] [blame] | 879 | INLINE bool dvmIsVolatileField(const Field* field) { |
| 880 | return (field->accessFlags & ACC_VOLATILE) != 0; |
| 881 | } |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 882 | |
| 883 | INLINE bool dvmIsInterfaceClass(const ClassObject* clazz) { |
| 884 | return (clazz->accessFlags & ACC_INTERFACE) != 0; |
| 885 | } |
| 886 | INLINE bool dvmIsPublicClass(const ClassObject* clazz) { |
| 887 | return (clazz->accessFlags & ACC_PUBLIC) != 0; |
| 888 | } |
| 889 | INLINE bool dvmIsFinalClass(const ClassObject* clazz) { |
| 890 | return (clazz->accessFlags & ACC_FINAL) != 0; |
| 891 | } |
| 892 | INLINE bool dvmIsAbstractClass(const ClassObject* clazz) { |
| 893 | return (clazz->accessFlags & ACC_ABSTRACT) != 0; |
| 894 | } |
| 895 | INLINE bool dvmIsAnnotationClass(const ClassObject* clazz) { |
| 896 | return (clazz->accessFlags & ACC_ANNOTATION) != 0; |
| 897 | } |
| 898 | INLINE bool dvmIsPrimitiveClass(const ClassObject* clazz) { |
| 899 | return clazz->primitiveType != PRIM_NOT; |
| 900 | } |
| 901 | |
| 902 | /* linked, here meaning prepared and resolved */ |
| 903 | INLINE bool dvmIsClassLinked(const ClassObject* clazz) { |
| 904 | return clazz->status >= CLASS_RESOLVED; |
| 905 | } |
| 906 | /* has class been verified? */ |
| 907 | INLINE bool dvmIsClassVerified(const ClassObject* clazz) { |
| 908 | return clazz->status >= CLASS_VERIFIED; |
| 909 | } |
| 910 | |
| 911 | /* |
| 912 | * Get the associated code struct for a method. This returns NULL |
| 913 | * for non-bytecode methods. |
| 914 | */ |
| 915 | INLINE const DexCode* dvmGetMethodCode(const Method* meth) { |
| 916 | if (dvmIsBytecodeMethod(meth)) { |
| 917 | /* |
| 918 | * The insns field for a bytecode method actually points at |
| 919 | * &(DexCode.insns), so we can subtract back to get at the |
| 920 | * DexCode in front. |
| 921 | */ |
| 922 | return (const DexCode*) |
| 923 | (((const u1*) meth->insns) - offsetof(DexCode, insns)); |
| 924 | } else { |
| 925 | return NULL; |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | /* |
| 930 | * Get the size of the insns associated with a method. This returns 0 |
| 931 | * for non-bytecode methods. |
| 932 | */ |
| 933 | INLINE u4 dvmGetMethodInsnsSize(const Method* meth) { |
| 934 | const DexCode* pCode = dvmGetMethodCode(meth); |
| 935 | return (pCode == NULL) ? 0 : pCode->insnsSize; |
| 936 | } |
| 937 | |
| 938 | /* debugging */ |
| 939 | void dvmDumpObject(const Object* obj); |
| 940 | |
| 941 | #endif /*_DALVIK_OO_OBJECT*/ |