#ifndef _DALVIK_INDIRECTREFTABLE
#define _DALVIK_INDIRECTREFTABLE
+
/*
* Maintain a table of indirect references. Used for local/global JNI
* references.
*
* For convenience these match up with enum jobjectRefType from jni.h.
*/
-typedef enum IndirectRefKind {
+enum IndirectRefKind {
kIndirectKindInvalid = 0,
kIndirectKindLocal = 1,
kIndirectKindGlobal = 2,
kIndirectKindWeakGlobal = 3
-} IndirectRefKind;
+};
/*
* Extended debugging structure. We keep a parallel array of these, one
* per slot in the table.
*/
#define kIRTPrevCount 4
-typedef struct IndirectRefSlot {
+struct IndirectRefSlot {
u4 serial; /* slot serial */
Object* previous[kIRTPrevCount];
-} IndirectRefSlot;
+};
/*
* Table definition.
* add a "synchronized lookup" call that takes the mutex as an argument,
* and either locks or doesn't lock based on internal details.
*/
-typedef union IRTSegmentState {
+union IRTSegmentState {
u4 all;
struct {
u4 topIndex:16; /* index of first unused entry */
u4 numHoles:16; /* #of holes in entire table */
} parts;
-} IRTSegmentState;
-typedef struct IndirectRefTable {
+};
+struct IndirectRefTable {
/* semi-public - read/write by interpreter in native call handler */
IRTSegmentState segmentState;
// TODO: want hole-filling stats (#of holes filled, total entries scanned)
// for performance evaluation.
-} IndirectRefTable;
+};
/* use as initial value for "cookie", and when table has only one segment */
#define IRT_FIRST_SEGMENT 0
}
/*
+ * Return a string constant describing the indirect ref type.
+ */
+const char* dvmIndirectRefTypeName(IndirectRef iref);
+
+/*
* Initialize an IndirectRefTable.
*
* If "initialCount" != "maxCount", the table will expand as required.
/* extra debugging checks */
bool dvmGetFromIndirectRefTableCheck(IndirectRefTable* pRef, IndirectRef iref);
+/* magic failure value; must not pass dvmIsValidObject() */
+#define kInvalidIndirectRefObject ((Object*)0xdead4321)
+
/*
* Given an IndirectRef in the table, return the Object it refers to.
*
- * Returns NULL if iref is invalid.
+ * Returns kInvalidIndirectRefObject if iref is invalid.
*/
INLINE Object* dvmGetFromIndirectRefTable(IndirectRefTable* pRef,
IndirectRef iref)
{
if (!dvmGetFromIndirectRefTableCheck(pRef, iref))
- return NULL;
+ return kInvalidIndirectRefObject;
int idx = dvmIndirectRefToIndex(iref);
return pRef->table[idx];