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