From 0d92a4072c00434e95a03642a4944acf81a81cc3 Mon Sep 17 00:00:00 2001 From: Carl Shapiro Date: Tue, 7 Jun 2011 17:32:01 -0700 Subject: [PATCH] Favor Object* over void* for the heap bitmap interfaces. Change-Id: I615dbff3e81a1128dc3ba43d6d426c370ae3abcf --- vm/alloc/Alloc.cpp | 8 ++------ vm/alloc/CardTable.cpp | 16 +++++++--------- vm/alloc/HeapBitmap.cpp | 8 ++++---- vm/alloc/HeapBitmap.h | 4 ++-- vm/alloc/MarkSweep.cpp | 9 ++++----- vm/alloc/Verify.cpp | 21 ++++++++++----------- vm/hprof/Hprof.cpp | 10 +++------- 7 files changed, 32 insertions(+), 44 deletions(-) diff --git a/vm/alloc/Alloc.cpp b/vm/alloc/Alloc.cpp index 1dbac532e..46b21c0b7 100644 --- a/vm/alloc/Alloc.cpp +++ b/vm/alloc/Alloc.cpp @@ -320,11 +320,9 @@ struct CountContext { size_t count; }; -static void countInstancesOfClassCallback(void *ptr, void *arg) +static void countInstancesOfClassCallback(Object *obj, void *arg) { CountContext *ctx = (CountContext *)arg; - const Object *obj = (const Object *)ptr; - assert(ctx != NULL); if (obj->clazz == ctx->clazz) { ctx->count += 1; @@ -341,11 +339,9 @@ size_t dvmCountInstancesOfClass(const ClassObject *clazz) return ctx.count; } -static void countAssignableInstancesOfClassCallback(void *ptr, void *arg) +static void countAssignableInstancesOfClassCallback(Object *obj, void *arg) { CountContext *ctx = (CountContext *)arg; - const Object *obj = (const Object *)ptr; - assert(ctx != NULL); if (obj->clazz != NULL && dvmInstanceof(obj->clazz, ctx->clazz)) { ctx->count += 1; diff --git a/vm/alloc/CardTable.cpp b/vm/alloc/CardTable.cpp index ec8ba9703..65861c658 100644 --- a/vm/alloc/CardTable.cpp +++ b/vm/alloc/CardTable.cpp @@ -300,16 +300,15 @@ static void dumpReferencesVisitor(void *pObj, void *arg) } } -static void dumpReferencesCallback(void *ptr, void *arg) +static void dumpReferencesCallback(Object *obj, void *arg) { - Object *obj = (Object *)arg; - if (ptr == obj) { + if (obj == (Object *)arg) { return; } - dvmVisitObject(dumpReferencesVisitor, (Object *)ptr, &obj); - if (obj == NULL) { - LOGD("Found %p in the heap @ %p", arg, ptr); - dvmDumpObject((Object *)ptr); + dvmVisitObject(dumpReferencesVisitor, obj, &arg); + if (arg == NULL) { + LOGD("Found %p in the heap @ %p", arg, obj); + dvmDumpObject(obj); } } @@ -395,9 +394,8 @@ static bool isPushedOnMarkStack(const Object *obj) * references specially as it is permissible for these objects to be * gray and on an unmarked card. */ -static void verifyCardTableCallback(void *ptr, void *arg) +static void verifyCardTableCallback(Object *obj, void *arg) { - Object *obj = (Object *)ptr; WhiteReferenceCounter ctx = { (HeapBitmap *)arg, 0 }; dvmVisitObject(countWhiteReferenceVisitor, obj, &ctx); diff --git a/vm/alloc/HeapBitmap.cpp b/vm/alloc/HeapBitmap.cpp index 02b715f1c..cf02708c7 100644 --- a/vm/alloc/HeapBitmap.cpp +++ b/vm/alloc/HeapBitmap.cpp @@ -108,8 +108,8 @@ void dvmHeapBitmapWalk(const HeapBitmap *bitmap, BitmapCallback *callback, uintptr_t ptrBase = HB_INDEX_TO_OFFSET(i) + bitmap->base; while (word != 0) { const int shift = CLZ(word); - void *addr = (void *)(ptrBase + shift * HB_OBJECT_ALIGNMENT); - (*callback)(addr, arg); + Object* obj = (Object *)(ptrBase + shift * HB_OBJECT_ALIGNMENT); + (*callback)(obj, arg); word &= ~(highBit >> shift); } } @@ -147,8 +147,8 @@ void dvmHeapBitmapScanWalk(HeapBitmap *bitmap, void *finger = (void *)(HB_INDEX_TO_OFFSET(i + 1) + bitmap->base); while (word != 0) { const int shift = CLZ(word); - void *addr = (void *)(ptrBase + shift * HB_OBJECT_ALIGNMENT); - (*callback)(addr, finger, arg); + Object *obj = (Object *)(ptrBase + shift * HB_OBJECT_ALIGNMENT); + (*callback)(obj, finger, arg); word &= ~(highBit >> shift); } end = HB_OFFSET_TO_INDEX(bitmap->max - bitmap->base); diff --git a/vm/alloc/HeapBitmap.h b/vm/alloc/HeapBitmap.h index 90cfea931..eba59988e 100644 --- a/vm/alloc/HeapBitmap.h +++ b/vm/alloc/HeapBitmap.h @@ -73,8 +73,8 @@ struct HeapBitmap { /* * Callback types used by the walking routines. */ -typedef void BitmapCallback(void *addr, void *arg); -typedef void BitmapScanCallback(void *addr, void *finger, void *arg); +typedef void BitmapCallback(Object *obj, void *arg); +typedef void BitmapScanCallback(Object *obj, void *finger, void *arg); typedef void BitmapSweepCallback(size_t numPtrs, void **ptrs, void *arg); /* diff --git a/vm/alloc/MarkSweep.cpp b/vm/alloc/MarkSweep.cpp index 710f2e661..309bd03c7 100644 --- a/vm/alloc/MarkSweep.cpp +++ b/vm/alloc/MarkSweep.cpp @@ -293,11 +293,10 @@ static void verifyImmuneObjectsVisitor(void *addr, void *arg) * Visitor that searches for immune objects and verifies that all * threatened referents are marked. */ -static void verifyImmuneObjectsCallback(void *addr, void *arg) +static void verifyImmuneObjectsCallback(Object *obj, void *arg) { - assert(addr != NULL); + assert(obj != NULL); assert(arg != NULL); - Object *obj = (Object *)addr; GcMarkContext *ctx = (GcMarkContext *)arg; if (obj->clazz == NULL) { LOGI("uninitialized object @ %p (has null clazz pointer)", obj); @@ -686,11 +685,11 @@ void dvmHeapScanImmuneObjects(const GcMarkContext *ctx) * to the address corresponding to the lowest address in the next word * of bits in the bitmap. */ -static void scanBitmapCallback(void *addr, void *finger, void *arg) +static void scanBitmapCallback(Object *obj, void *finger, void *arg) { GcMarkContext *ctx = (GcMarkContext *)arg; ctx->finger = (void *)finger; - scanObject((Object *)addr, ctx); + scanObject(obj, ctx); } /* Given bitmaps with the root set marked, find and mark all diff --git a/vm/alloc/Verify.cpp b/vm/alloc/Verify.cpp index 1a8307aff..6d830c7d7 100644 --- a/vm/alloc/Verify.cpp +++ b/vm/alloc/Verify.cpp @@ -38,16 +38,15 @@ static void dumpReferencesVisitor(void *pObj, void *arg) * Visitor applied to each bitmap element to search for things that * point to an object. Logs a message when a match is found. */ -static void dumpReferencesCallback(void *ptr, void *arg) +static void dumpReferencesCallback(Object *obj, void *arg) { - Object *obj = (Object *)arg; - if (ptr == obj) { + if (obj == (Object *)arg) { return; } - dvmVisitObject(dumpReferencesVisitor, (Object *)ptr, &obj); - if (obj == NULL) { - LOGD("Found %p in the heap @ %p", arg, ptr); - dvmDumpObject((Object *)ptr); + dvmVisitObject(dumpReferencesVisitor, obj, &arg); + if (arg == NULL) { + LOGD("Found %p in the heap @ %p", arg, obj); + dvmDumpObject(obj); } } @@ -108,8 +107,8 @@ static void verifyReference(void *addr, void *arg) */ void dvmVerifyObject(const Object *obj) { - Object *arg = (Object *)obj; - dvmVisitObject(verifyReference, (Object *)obj, &arg); + Object *arg = const_cast(obj); + dvmVisitObject(verifyReference, arg, &arg); if (arg == NULL) { dumpReferences(obj); dvmAbort(); @@ -119,9 +118,9 @@ void dvmVerifyObject(const Object *obj) /* * Helper function to call dvmVerifyObject from a bitmap walker. */ -static void verifyBitmapCallback(void *ptr, void *arg) +static void verifyBitmapCallback(Object *obj, void *arg) { - dvmVerifyObject((Object *)ptr); + dvmVerifyObject(obj); } /* diff --git a/vm/hprof/Hprof.cpp b/vm/hprof/Hprof.cpp index ff8e87287..4a6b1a69a 100644 --- a/vm/hprof/Hprof.cpp +++ b/vm/hprof/Hprof.cpp @@ -214,15 +214,11 @@ static void hprofRootVisitor(void *addr, u4 threadId, RootType type, void *arg) /* * Visitor invoked on every heap object. */ -static void hprofBitmapCallback(void *ptr, void *arg) +static void hprofBitmapCallback(Object *obj, void *arg) { - Object *obj; - hprof_context_t *ctx; - - assert(ptr != NULL); + assert(obj != NULL); assert(arg != NULL); - obj = (Object *)ptr; - ctx = (hprof_context_t *)arg; + hprof_context_t *ctx = (hprof_context_t *)arg; hprofDumpHeapObject(ctx, obj); } -- 2.11.0