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