Compile the garbage collector and heap profiler as C++.
Change-Id: I25d8fa821987a3dd6d7109d07fd42dbf2fe0e589
diff --git a/vm/alloc/Alloc.c b/vm/alloc/Alloc.cpp
similarity index 100%
rename from vm/alloc/Alloc.c
rename to vm/alloc/Alloc.cpp
diff --git a/vm/alloc/Alloc.h b/vm/alloc/Alloc.h
index aeba3f5..fc62ed0 100644
--- a/vm/alloc/Alloc.h
+++ b/vm/alloc/Alloc.h
@@ -21,6 +21,10 @@
#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Initialization.
*/
@@ -143,4 +147,8 @@
*/
bool dvmIsHeapAddress(void *address);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*_DALVIK_ALLOC_ALLOC*/
diff --git a/vm/alloc/CardTable.c b/vm/alloc/CardTable.cpp
similarity index 100%
rename from vm/alloc/CardTable.c
rename to vm/alloc/CardTable.cpp
diff --git a/vm/alloc/CardTable.h b/vm/alloc/CardTable.h
index 96131d1..1c15a54 100644
--- a/vm/alloc/CardTable.h
+++ b/vm/alloc/CardTable.h
@@ -23,6 +23,10 @@
#ifndef _DALVIK_ALLOC_CARDTABLE
#define _DALVIK_ALLOC_CARDTABLE
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define GC_CARD_SHIFT 7
#define GC_CARD_SIZE (1 << GC_CARD_SHIFT)
#define GC_CARD_CLEAN 0
@@ -70,4 +74,8 @@
*/
void dvmVerifyCardTable(void);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*_DALVIK_ALLOC_CARDTABLE*/
diff --git a/vm/alloc/Copying.c b/vm/alloc/Copying.cpp
similarity index 100%
rename from vm/alloc/Copying.c
rename to vm/alloc/Copying.cpp
diff --git a/vm/alloc/DdmHeap.c b/vm/alloc/DdmHeap.cpp
similarity index 98%
rename from vm/alloc/DdmHeap.c
rename to vm/alloc/DdmHeap.cpp
index b377b1b..8008113 100644
--- a/vm/alloc/DdmHeap.c
+++ b/vm/alloc/DdmHeap.cpp
@@ -357,7 +357,7 @@
*/
#define HPSx_CHUNK_SIZE (16384 - 16)
-void dlmalloc_walk_heap(void(*)(const void*, size_t, const void*, size_t, void*),void*);
+extern "C" void dlmalloc_walk_heap(void(*)(const void*, size_t, const void*, size_t, void*),void*);
static void
walkHeap(bool merge, bool native)
diff --git a/vm/alloc/DdmHeap.h b/vm/alloc/DdmHeap.h
index c3e11dc..32b96f9 100644
--- a/vm/alloc/DdmHeap.h
+++ b/vm/alloc/DdmHeap.h
@@ -19,6 +19,10 @@
#ifndef _DALVIK_ALLOC_DDMHEAP
#define _DALVIK_ALLOC_DDMHEAP
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Sends the current heap info to the DDM server.
* Should be called after a GC when gcHeap->ddmHpifWhen
@@ -38,4 +42,8 @@
*/
void dvmDdmSendHeapSegments(bool shouldLock, bool native);
+#ifdef __cplusplus
+}
+#endif
+
#endif // _DALVIK_ALLOC_DDMHEAP
diff --git a/vm/alloc/Heap.c b/vm/alloc/Heap.cpp
similarity index 98%
rename from vm/alloc/Heap.c
rename to vm/alloc/Heap.cpp
index f38eb12..9ca0ebf 100644
--- a/vm/alloc/Heap.c
+++ b/vm/alloc/Heap.cpp
@@ -37,7 +37,7 @@
static const GcSpec kGcForMallocSpec = {
true, /* isPartial */
false, /* isConcurrent */
- PRESERVE,
+ true, /* doPreserve */
"GC_FOR_ALLOC"
};
@@ -46,7 +46,7 @@
static const GcSpec kGcConcurrentSpec = {
true, /* isPartial */
true, /* isConcurrent */
- PRESERVE,
+ true, /* doPreserve */
"GC_CONCURRENT"
};
@@ -55,7 +55,7 @@
static const GcSpec kGcExplicitSpec = {
false, /* isPartial */
true, /* isConcurrent */
- PRESERVE,
+ true, /* doPreserve */
"GC_EXPLICIT"
};
@@ -64,7 +64,7 @@
static const GcSpec kGcBeforeOomSpec = {
false, /* isPartial */
false, /* isConcurrent */
- CLEAR,
+ false, /* doPreserve */
"GC_BEFORE_OOM"
};
@@ -622,7 +622,7 @@
* weakly-reachable objects discovered while tracing.
*/
dvmHeapProcessReferences(&gcHeap->softReferences,
- spec->softReferencePolicy == CLEAR,
+ spec->doPreserve == false,
&gcHeap->weakReferences,
&gcHeap->finalizerReferences,
&gcHeap->phantomReferences);
diff --git a/vm/alloc/Heap.h b/vm/alloc/Heap.h
index 01a50d2..4333486 100644
--- a/vm/alloc/Heap.h
+++ b/vm/alloc/Heap.h
@@ -25,7 +25,7 @@
/* If true, the trace is run concurrently with the mutator. */
bool isConcurrent;
/* Toggles for the soft reference clearing policy. */
- enum { CLEAR, PRESERVE } softReferencePolicy;
+ bool doPreserve;
/* A name for this garbage collection mode. */
const char *reason;
} GcSpec;
diff --git a/vm/alloc/HeapBitmap.c b/vm/alloc/HeapBitmap.cpp
similarity index 100%
rename from vm/alloc/HeapBitmap.c
rename to vm/alloc/HeapBitmap.cpp
diff --git a/vm/alloc/HeapBitmap.h b/vm/alloc/HeapBitmap.h
index fecc2a9..dd374cc 100644
--- a/vm/alloc/HeapBitmap.h
+++ b/vm/alloc/HeapBitmap.h
@@ -19,6 +19,10 @@
#include <limits.h>
#include <stdint.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define HB_OBJECT_ALIGNMENT 8
#define HB_BITS_PER_WORD (sizeof(unsigned long) * CHAR_BIT)
@@ -127,4 +131,8 @@
uintptr_t base, uintptr_t max,
BitmapSweepCallback *callback, void *callbackArg);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _DALVIK_HEAP_BITMAP */
diff --git a/vm/alloc/HeapDebug.c b/vm/alloc/HeapDebug.cpp
similarity index 100%
rename from vm/alloc/HeapDebug.c
rename to vm/alloc/HeapDebug.cpp
diff --git a/vm/alloc/HeapDebug.h b/vm/alloc/HeapDebug.h
index f36b7ab..3dd1d54 100644
--- a/vm/alloc/HeapDebug.h
+++ b/vm/alloc/HeapDebug.h
@@ -16,6 +16,10 @@
#ifndef _DALVIK_HEAPDEBUG
#define _DALVIK_HEAPDEBUG
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef enum HeapDebugInfoType {
kVirtualHeapSize = 0,
kNativeHeapSize = 1,
@@ -29,4 +33,8 @@
*/
int dvmGetHeapDebugInfo(HeapDebugInfoType info);
+#ifdef __cplusplus
+}
+#endif
+
#endif // _DALVIK_HEAPDEBUG
diff --git a/vm/alloc/HeapInternal.h b/vm/alloc/HeapInternal.h
index 1d1be07..8529422 100644
--- a/vm/alloc/HeapInternal.h
+++ b/vm/alloc/HeapInternal.h
@@ -85,7 +85,10 @@
#define LOGD_HEAP(...) LOG(LOG_DEBUG, HEAP_LOG_TAG, __VA_ARGS__)
#endif
#define LOGI_HEAP(...) \
- (!gDvm.zygote ? LOG(LOG_INFO, HEAP_LOG_TAG, __VA_ARGS__) : (void)0)
+ do { \
+ if (!gDvm.zygote) { LOG(LOG_INFO, HEAP_LOG_TAG, __VA_ARGS__); } \
+ } while (0)
+
#define LOGW_HEAP(...) LOG(LOG_WARN, HEAP_LOG_TAG, __VA_ARGS__)
#define LOGE_HEAP(...) LOG(LOG_ERROR, HEAP_LOG_TAG, __VA_ARGS__)
diff --git a/vm/alloc/HeapSource.c b/vm/alloc/HeapSource.cpp
similarity index 99%
rename from vm/alloc/HeapSource.c
rename to vm/alloc/HeapSource.cpp
index 4b61358..50303b7 100644
--- a/vm/alloc/HeapSource.c
+++ b/vm/alloc/HeapSource.cpp
@@ -15,10 +15,12 @@
*/
#include <cutils/mspace.h>
-#include <stdint.h> // for SIZE_MAX
+#include <stdint.h>
#include <sys/mman.h>
#include <errno.h>
+#define SIZE_MAX UINT_MAX // TODO: get SIZE_MAX from stdint.h
+
#include "Dalvik.h"
#include "alloc/Heap.h"
#include "alloc/HeapInternal.h"
@@ -27,8 +29,8 @@
#include "alloc/HeapBitmapInlines.h"
// TODO: find a real header file for these.
-extern int dlmalloc_trim(size_t);
-extern void dlmalloc_walk_free_pages(void(*)(void*, void*, void*), void*);
+extern "C" int dlmalloc_trim(size_t);
+extern "C" void dlmalloc_walk_free_pages(void(*)(void*, void*, void*), void*);
static void snapIdealFootprint(void);
static void setIdealFootprint(size_t max);
diff --git a/vm/alloc/MarkSweep.c b/vm/alloc/MarkSweep.cpp
similarity index 98%
rename from vm/alloc/MarkSweep.c
rename to vm/alloc/MarkSweep.cpp
index 8e924d5..9b527cb 100644
--- a/vm/alloc/MarkSweep.c
+++ b/vm/alloc/MarkSweep.cpp
@@ -144,7 +144,7 @@
* marking. Marks white objects but does not push them on the mark
* stack.
*/
-static void rootMarkObjectVisitor(void *addr, RootType type, u4 thread,
+static void rootMarkObjectVisitor(void *addr, u4 thread, RootType type,
void *arg)
{
Object *obj;
@@ -363,7 +363,7 @@
* Callback applied to root references during root remarking. Marks
* white objects and pushes them on the mark stack.
*/
-static void rootReMarkObjectVisitor(void *addr, RootType type, u4 thread,
+static void rootReMarkObjectVisitor(void *addr, u4 thread, RootType type,
void *arg)
{
Object *obj;
@@ -492,7 +492,7 @@
markObject((const Object *)obj->clazz, ctx);
if (IS_CLASS_FLAG_SET(obj->clazz, CLASS_ISOBJECTARRAY)) {
const ArrayObject *array = (const ArrayObject *)obj;
- const Object **contents = (const Object **)array->contents;
+ const Object **contents = (const Object **)(void *)array->contents;
size_t i;
for (i = 0; i < array->length; ++i) {
markObject(contents[i], ctx);
diff --git a/vm/alloc/Verify.c b/vm/alloc/Verify.cpp
similarity index 100%
rename from vm/alloc/Verify.c
rename to vm/alloc/Verify.cpp
diff --git a/vm/alloc/Visit.c b/vm/alloc/Visit.cpp
similarity index 100%
rename from vm/alloc/Visit.c
rename to vm/alloc/Visit.cpp
diff --git a/vm/alloc/Visit.h b/vm/alloc/Visit.h
index a66839d..1616889 100644
--- a/vm/alloc/Visit.h
+++ b/vm/alloc/Visit.h
@@ -19,6 +19,10 @@
#include "Dalvik.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef enum {
ROOT_UNKNOWN = 0,
ROOT_JNI_GLOBAL,
@@ -58,4 +62,8 @@
*/
void dvmVisitRoots(RootVisitor *visitor, void *arg);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _DALVIK_ALLOC_VISIT */
diff --git a/vm/alloc/VisitInlines.h b/vm/alloc/VisitInlines.h
index 7f90678..eb889af 100644
--- a/vm/alloc/VisitInlines.h
+++ b/vm/alloc/VisitInlines.h
@@ -120,7 +120,7 @@
(*visitor)(&obj->clazz, arg);
if (IS_CLASS_FLAG_SET(obj->clazz, CLASS_ISOBJECTARRAY)) {
ArrayObject *array = (ArrayObject *)obj;
- Object **contents = (Object **)array->contents;
+ Object **contents = (Object **)(void *)array->contents;
size_t i;
for (i = 0; i < array->length; ++i) {
(*visitor)(&contents[i], arg);
diff --git a/vm/alloc/WriteBarrier.h b/vm/alloc/WriteBarrier.h
index dd8f129..4c660a0 100644
--- a/vm/alloc/WriteBarrier.h
+++ b/vm/alloc/WriteBarrier.h
@@ -17,6 +17,10 @@
#ifndef _DALVIK_ALLOC_WRITEBARRIER
#define _DALVIK_ALLOC_WRITEBARRIER
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Note writes to the heap. These functions must be called if a field
* of an Object in the heap changes, and before any GC safe-point. The
@@ -50,4 +54,8 @@
dvmMarkCard((Object *)obj);
}
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _DALVIK_ALLOC_WRITEBARRIER */