Compile the garbage collector and heap profiler as C++.

Change-Id: I25d8fa821987a3dd6d7109d07fd42dbf2fe0e589
diff --git a/libdex/SysUtil.h b/libdex/SysUtil.h
index 4de0289..1f704f4 100644
--- a/libdex/SysUtil.h
+++ b/libdex/SysUtil.h
@@ -22,6 +22,10 @@
 
 #include <sys/types.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * System page size.  Normally you're expected to get this from
  * sysconf(_SC_PAGESIZE) or some system-specific define (usually PAGESIZE
@@ -119,4 +123,8 @@
  */
 int sysCopyFileToFile(int outFd, int inFd, size_t count);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_SYSUTIL*/
diff --git a/vm/AllocTracker.h b/vm/AllocTracker.h
index 84ac9b8..b6d668d 100644
--- a/vm/AllocTracker.h
+++ b/vm/AllocTracker.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_ALLOCTRACKER
 #define _DALVIK_ALLOCTRACKER
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* initialization */
 bool dvmAllocTrackerStartup(void);
 void dvmAllocTrackerShutdown(void);
@@ -60,4 +64,8 @@
  */
 void dvmDumpTrackedAllocations(bool enable);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_ALLOCTRACKER*/
diff --git a/vm/Atomic.h b/vm/Atomic.h
index 6c3a66f..713c5b4 100644
--- a/vm/Atomic.h
+++ b/vm/Atomic.h
@@ -23,6 +23,10 @@
 #include <cutils/atomic.h>          /* use common Android atomic ops */
 #include <cutils/atomic-inline.h>   /* and some uncommon ones */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * NOTE: Two "quasiatomic" operations on the exact same memory address
  * are guaranteed to operate atomically with respect to each other,
@@ -52,4 +56,8 @@
 int dvmQuasiAtomicCas64(int64_t oldvalue, int64_t newvalue,
         volatile int64_t* addr);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_ATOMIC*/
diff --git a/vm/BitVector.h b/vm/BitVector.h
index d1a0ca3..0d23350 100644
--- a/vm/BitVector.h
+++ b/vm/BitVector.h
@@ -20,6 +20,10 @@
 #ifndef _DALVIK_BITVECTOR
 #define _DALVIK_BITVECTOR
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Expanding bitmap, used for tracking resources.  Bits are numbered starting
  * from zero.
@@ -100,4 +104,8 @@
 /* Return the next position set to 1. -1 means end-of-vector reached */
 int dvmBitVectorIteratorNext(BitVectorIterator* iterator);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_BITVECTOR*/
diff --git a/vm/Common.h b/vm/Common.h
index 7d8424e..0ec9ec4 100644
--- a/vm/Common.h
+++ b/vm/Common.h
@@ -24,8 +24,16 @@
 # define LOG_TAG "dalvikvm"
 #endif
 
+#include <stdbool.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <assert.h>
+#include <endian.h>
+#include "utils/Log.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 #if !defined(NDEBUG) && defined(WITH_DALVIK_ASSERT)
 # undef assert
@@ -67,8 +75,6 @@
 /*
  * These match the definitions in the VM specification.
  */
-#ifdef HAVE_STDINT_H
-# include <stdint.h>    /* C99 */
 typedef uint8_t             u1;
 typedef uint16_t            u2;
 typedef uint32_t            u4;
@@ -77,16 +83,6 @@
 typedef int16_t             s2;
 typedef int32_t             s4;
 typedef int64_t             s8;
-#else
-typedef unsigned char       u1;
-typedef unsigned short      u2;
-typedef unsigned int        u4;
-typedef unsigned long long  u8;
-typedef signed char         s1;
-typedef signed short        s2;
-typedef signed int          s4;
-typedef signed long long    s8;
-#endif
 
 /*
  * Storage for primitive types and object references.
@@ -108,55 +104,10 @@
     void*   l;
 } JValue;
 
-/*
- * The <stdbool.h> definition uses _Bool, a type known to the compiler.
- */
-#ifdef HAVE_STDBOOL_H
-# include <stdbool.h>   /* C99 */
-#else
-# ifndef __bool_true_false_are_defined
-typedef enum { false=0, true=!false } bool;
-# define __bool_true_false_are_defined 1
-# endif
-#endif
-
 #define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
 
-
-#if defined(HAVE_ENDIAN_H)
-# include <endian.h>
-#else /*not HAVE_ENDIAN_H*/
-# define __BIG_ENDIAN 4321
-# define __LITTLE_ENDIAN 1234
-# if defined(HAVE_LITTLE_ENDIAN)
-#  define __BYTE_ORDER __LITTLE_ENDIAN
-# else
-#  define __BYTE_ORDER __BIG_ENDIAN
-# endif
-#endif /*not HAVE_ENDIAN_H*/
-
-
-#if 0
-/*
- * Pretend we have the Android logging macros.  These are replaced by the
- * Android logging implementation.
- */
-#define ANDROID_LOG_DEBUG 3
-#define LOGV(...)    LOG_PRI(2, 0, __VA_ARGS__)
-#define LOGD(...)    LOG_PRI(3, 0, __VA_ARGS__)
-#define LOGI(...)    LOG_PRI(4, 0, __VA_ARGS__)
-#define LOGW(...)    LOG_PRI(5, 0, __VA_ARGS__)
-#define LOGE(...)    LOG_PRI(6, 0, __VA_ARGS__)
-#define MIN_LOG_LEVEL   2
-
-#define LOG_PRI(priority, tag, ...) do {                            \
-        if (priority >= MIN_LOG_LEVEL) {                            \
-            dvmFprintf(stdout, "%s:%-4d ", __FILE__, __LINE__);     \
-            dvmFprintf(stdout, __VA_ARGS__);                        \
-        }                                                           \
-    } while(0)
-#else
-# include "utils/Log.h"
+#ifdef __cplusplus
+}
 #endif
 
 #endif /*_DALVIK_COMMON*/
diff --git a/vm/Dalvik.h b/vm/Dalvik.h
index 534ea2d..a47388a 100644
--- a/vm/Dalvik.h
+++ b/vm/Dalvik.h
@@ -20,8 +20,6 @@
 #ifndef _DALVIK_DALVIK
 #define _DALVIK_DALVIK
 
-#include <pthread.h>
-
 #include "Common.h"
 #include "Inlines.h"
 #include "Misc.h"
diff --git a/vm/Ddm.h b/vm/Ddm.h
index 01f5d18..af7f6e1 100644
--- a/vm/Ddm.h
+++ b/vm/Ddm.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_DDM
 #define _DALVIK_DDM
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Handle a packet full of DDM goodness.
  *
@@ -84,4 +88,8 @@
  */
 ArrayObject* dvmDdmGetRecentAllocations(void);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_DDM*/
diff --git a/vm/Debugger.h b/vm/Debugger.h
index 9a45b39..dd9679f 100644
--- a/vm/Debugger.h
+++ b/vm/Debugger.h
@@ -21,10 +21,14 @@
 #ifndef _DALVIK_DEBUGGER
 #define _DALVIK_DEBUGGER
 
+#include <pthread.h>
 #include "Common.h"
 #include "Misc.h"
 #include "jdwp/Jdwp.h"
-#include <pthread.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /* fwd decl */
 struct Object;
@@ -307,4 +311,8 @@
 #define CHUNK_TYPE(_name) \
     ((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_DEBUGGER*/
diff --git a/vm/Dvm.mk b/vm/Dvm.mk
index d655a3a..add2207 100644
--- a/vm/Dvm.mk
+++ b/vm/Dvm.mk
@@ -116,14 +116,14 @@
 	Sync.c \
 	Thread.c \
 	UtfString.c \
-	alloc/Alloc.c \
-	alloc/CardTable.c \
-	alloc/HeapBitmap.c.arm \
-	alloc/HeapDebug.c \
-	alloc/Heap.c.arm \
-	alloc/DdmHeap.c \
-	alloc/Verify.c \
-	alloc/Visit.c \
+	alloc/Alloc.cpp \
+	alloc/CardTable.cpp \
+	alloc/HeapBitmap.cpp.arm \
+	alloc/HeapDebug.cpp \
+	alloc/Heap.cpp.arm \
+	alloc/DdmHeap.cpp \
+	alloc/Verify.cpp \
+	alloc/Visit.cpp \
 	analysis/CodeVerify.c \
 	analysis/DexPrepare.c \
 	analysis/DexVerify.c \
@@ -132,11 +132,11 @@
 	analysis/RegisterMap.c \
 	analysis/VerifySubs.c \
 	analysis/VfyBasicBlock.c \
-	hprof/Hprof.c \
-	hprof/HprofClass.c \
-	hprof/HprofHeap.c \
-	hprof/HprofOutput.c \
-	hprof/HprofString.c \
+	hprof/Hprof.cpp \
+	hprof/HprofClass.cpp \
+	hprof/HprofHeap.cpp \
+	hprof/HprofOutput.cpp \
+	hprof/HprofString.cpp \
 	interp/Interp.c.arm \
 	interp/Stack.c \
 	jdwp/ExpandBuf.c \
@@ -195,11 +195,11 @@
 ifeq ($(WITH_COPYING_GC),true)
   LOCAL_CFLAGS += -DWITH_COPYING_GC
   LOCAL_SRC_FILES += \
-	alloc/Copying.c.arm
+	alloc/Copying.cpp.arm
 else
   LOCAL_SRC_FILES += \
-	alloc/HeapSource.c \
-	alloc/MarkSweep.c.arm
+	alloc/HeapSource.cpp \
+	alloc/MarkSweep.cpp.arm
 endif
 
 WITH_JIT := $(strip $(WITH_JIT))
diff --git a/vm/DvmDex.h b/vm/DvmDex.h
index ad82e54..937f09d 100644
--- a/vm/DvmDex.h
+++ b/vm/DvmDex.h
@@ -21,6 +21,10 @@
 #ifndef _DALVIK_DVMDEX
 #define _DALVIK_DVMDEX
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "libdex/DexFile.h"
 
 /* extern */
@@ -158,4 +162,8 @@
     pDvmDex->pResFields[fieldIdx] = field;
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_DVMDEX*/
diff --git a/vm/Exception.h b/vm/Exception.h
index 509d3b2..40f3482 100644
--- a/vm/Exception.h
+++ b/vm/Exception.h
@@ -20,6 +20,10 @@
 #ifndef _DALVIK_EXCEPTION
 #define _DALVIK_EXCEPTION
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Create a Throwable and throw an exception in the current thread (where
  * "throwing" just means "set the thread's exception pointer").
@@ -483,4 +487,8 @@
  */
 void dvmThrowVirtualMachineError(const char* msg);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_EXCEPTION*/
diff --git a/vm/Globals.h b/vm/Globals.h
index faafcc6..163ce99 100644
--- a/vm/Globals.h
+++ b/vm/Globals.h
@@ -33,6 +33,10 @@
 #include <stdarg.h>
 #include <pthread.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define MAX_BREAKPOINTS 20      /* used for a debugger optimization */
 
 /* private structures */
@@ -959,4 +963,8 @@
 
 #endif
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_GLOBALS*/
diff --git a/vm/Hash.h b/vm/Hash.h
index cfd7544..2c6bd5e 100644
--- a/vm/Hash.h
+++ b/vm/Hash.h
@@ -22,6 +22,10 @@
 #ifndef _DALVIK_HASH
 #define _DALVIK_HASH
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* compute the hash of an item with a specific type */
 typedef u4 (*HashCompute)(const void* item);
 
@@ -218,4 +222,8 @@
 void dvmHashTableProbeCount(HashTable* pHashTable, HashCalcFunc calcFunc,
     HashCompareFunc cmpFunc);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_HASH*/
diff --git a/vm/IndirectRefTable.h b/vm/IndirectRefTable.h
index 7248a7b..36d18ba 100644
--- a/vm/IndirectRefTable.h
+++ b/vm/IndirectRefTable.h
@@ -16,6 +16,11 @@
 
 #ifndef _DALVIK_INDIRECTREFTABLE
 #define _DALVIK_INDIRECTREFTABLE
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Maintain a table of indirect references.  Used for local/global JNI
  * references.
@@ -389,4 +394,8 @@
  */
 void dvmDumpIndirectRefTable(const IndirectRefTable* pRef, const char* descr);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_INDIRECTREFTABLE*/
diff --git a/vm/Init.h b/vm/Init.h
index ef56f26..9e38da9 100644
--- a/vm/Init.h
+++ b/vm/Init.h
@@ -20,6 +20,10 @@
 #ifndef _DALVIK_INIT
 #define _DALVIK_INIT
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Standard VM initialization, usually invoked through JNI.
  */
@@ -78,4 +82,8 @@
 #endif
     ;
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_INIT*/
diff --git a/vm/InlineNative.h b/vm/InlineNative.h
index 4ca90e2..4f86cef 100644
--- a/vm/InlineNative.h
+++ b/vm/InlineNative.h
@@ -20,6 +20,10 @@
 #ifndef _DALVIK_INLINENATIVE
 #define _DALVIK_INLINENATIVE
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* startup/shutdown */
 bool dvmInlineNativeStartup(void);
 void dvmInlineNativeShutdown(void);
@@ -121,4 +125,8 @@
  */
 Method* dvmResolveInlineNative(int opIndex);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_INLINENATIVE*/
diff --git a/vm/Intern.h b/vm/Intern.h
index 6630b69..b6e669a 100644
--- a/vm/Intern.h
+++ b/vm/Intern.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_INTERN
 #define _DALVIK_INTERN
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 bool dvmStringInternStartup(void);
 void dvmStringInternShutdown(void);
 StringObject* dvmLookupInternedString(StringObject* strObj);
@@ -26,4 +30,8 @@
 bool dvmIsWeakInternedString(const StringObject* strObj);
 void dvmGcDetachDeadInternedStrings(int (*isUnmarkedObject)(void *));
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_INTERN*/
diff --git a/vm/JarFile.h b/vm/JarFile.h
index 36849ec..0569ee2 100644
--- a/vm/JarFile.h
+++ b/vm/JarFile.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_JARFILE
 #define _DALVIK_JARFILE
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * This represents an open, scanned Jar file.  (It's actually for any Zip
  * archive that happens to hold a Dex file.)
@@ -68,4 +72,8 @@
  */
 DexCacheStatus dvmDexCacheStatus(const char *fileName);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_JARFILE*/
diff --git a/vm/JniInternal.h b/vm/JniInternal.h
index bc88cad..d81373f 100644
--- a/vm/JniInternal.h
+++ b/vm/JniInternal.h
@@ -21,6 +21,10 @@
 
 #include "jni.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* system init/shutdown */
 bool dvmJniStartup(void);
 void dvmJniShutdown(void);
@@ -197,4 +201,8 @@
  */
 void dvmDumpJniReferenceTables(void);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_JNIINTERNAL*/
diff --git a/vm/LinearAlloc.h b/vm/LinearAlloc.h
index aa33fe1..c06d2ab 100644
--- a/vm/LinearAlloc.h
+++ b/vm/LinearAlloc.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_LINEARALLOC
 #define _DALVIK_LINEARALLOC
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * If this is set, we create additional data structures and make many
  * additional mprotect() calls.
@@ -117,4 +121,8 @@
  */
 bool dvmLinearAllocContains(const void* start, size_t length);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_LINEARALLOC*/
diff --git a/vm/Misc.h b/vm/Misc.h
index c1c3d47..8981824 100644
--- a/vm/Misc.h
+++ b/vm/Misc.h
@@ -20,11 +20,14 @@
 #ifndef _DALVIK_MISC
 #define _DALVIK_MISC
 
-#include "Inlines.h"
-
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#include "Inlines.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /*
  * Used to shut up the compiler when a parameter isn't used.
@@ -299,4 +302,8 @@
  */
 const char* dvmPathToAbsolutePortion(const char* path);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_MISC*/
diff --git a/vm/Native.h b/vm/Native.h
index f60ccce..7599bcc 100644
--- a/vm/Native.h
+++ b/vm/Native.h
@@ -22,6 +22,10 @@
 #ifndef _DALVIK_NATIVE
 #define _DALVIK_NATIVE
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Method description; equivalent to a JNI struct.
  */
@@ -119,4 +123,8 @@
 void dvmLogNativeMethodExit(const Method* method, struct Thread* self,
         const JValue retval);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_NATIVE*/
diff --git a/vm/PointerSet.h b/vm/PointerSet.h
index ffc0635..6e43f67 100644
--- a/vm/PointerSet.h
+++ b/vm/PointerSet.h
@@ -20,6 +20,10 @@
 #ifndef _DALVIK_POINTERSET
 #define _DALVIK_POINTERSET
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct PointerSet;   /* private */
 typedef struct PointerSet PointerSet;
 
@@ -92,4 +96,8 @@
  */
 void dvmPointerSetDump(const PointerSet* pSet);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_POINTERSET*/
diff --git a/vm/Profile.h b/vm/Profile.h
index b821394..12063b9 100644
--- a/vm/Profile.h
+++ b/vm/Profile.h
@@ -24,6 +24,10 @@
 
 #include <stdio.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct Thread;      // extern
 
 
@@ -171,4 +175,8 @@
 #define METHOD_ACTION(_method)  (((unsigned int)(_method)) & METHOD_ACTION_MASK)
 #define METHOD_COMBINE(_method, _action)    ((_method) | (_action))
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_PROFILE*/
diff --git a/vm/Properties.h b/vm/Properties.h
index 138be41..6226d7f 100644
--- a/vm/Properties.h
+++ b/vm/Properties.h
@@ -19,10 +19,18 @@
 #ifndef _DALVIK_PROPERTIES
 #define _DALVIK_PROPERTIES
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Initialization.
  */
 bool dvmPropertiesStartup(void);
 void dvmPropertiesShutdown(void);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_PROPERTIES*/
diff --git a/vm/RawDexFile.h b/vm/RawDexFile.h
index cbcb3b6..f2c1b68 100644
--- a/vm/RawDexFile.h
+++ b/vm/RawDexFile.h
@@ -21,6 +21,10 @@
 #ifndef _DALVIK_RAWDEXFILE
 #define _DALVIK_RAWDEXFILE
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Structure representing a "raw" DEX file, in its unswapped unoptimized
  * state.
@@ -68,4 +72,8 @@
     return pRawDexFile->cacheFileName;
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_RAWDEXFILE*/
diff --git a/vm/ReferenceTable.h b/vm/ReferenceTable.h
index f434f55..35bc61b 100644
--- a/vm/ReferenceTable.h
+++ b/vm/ReferenceTable.h
@@ -23,6 +23,10 @@
 #ifndef _DALVIK_REFERENCETABLE
 #define _DALVIK_REFERENCETABLE
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Table definition.
  *
@@ -122,4 +126,8 @@
 void dvmDumpReferenceTableContents(Object* const* refs, size_t count,
     const char* descr);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_REFERENCETABLE*/
diff --git a/vm/SignalCatcher.h b/vm/SignalCatcher.h
index ece052c..f9e1dd7 100644
--- a/vm/SignalCatcher.h
+++ b/vm/SignalCatcher.h
@@ -19,7 +19,15 @@
 #ifndef _DALVIK_SIGNALCATCHER
 #define _DALVIK_SIGNALCATCHER
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 bool dvmSignalCatcherStartup(void);
 void dvmSignalCatcherShutdown(void);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_SIGNALCATCHER*/
diff --git a/vm/StdioConverter.h b/vm/StdioConverter.h
index ffbf807..37384eb 100644
--- a/vm/StdioConverter.h
+++ b/vm/StdioConverter.h
@@ -19,7 +19,15 @@
 #ifndef _DALVIK_STDOUTCONVERTER
 #define _DALVIK_STDOUTCONVERTER
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 bool dvmStdioConverterStartup(void);
 void dvmStdioConverterShutdown(void);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_STDOUTCONVERTER*/
diff --git a/vm/Sync.h b/vm/Sync.h
index 520366e..a039483 100644
--- a/vm/Sync.h
+++ b/vm/Sync.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_SYNC
 #define _DALVIK_SYNC
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Monitor shape field.  Used to distinguish immediate thin locks from
  * indirecting fat locks.
@@ -157,4 +161,8 @@
 int dvmRelativeCondWait(pthread_cond_t* cond, pthread_mutex_t* mutex,
                          s8 msec, s4 nsec);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_SYNC*/
diff --git a/vm/Thread.h b/vm/Thread.h
index 4ad3974..c42a9e8 100644
--- a/vm/Thread.h
+++ b/vm/Thread.h
@@ -26,6 +26,9 @@
 #include <errno.h>
 #include <cutils/sched_policy.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 #if defined(CHECK_MUTEX) && !defined(__USE_UNIX98)
 /* glibc lacks this unless you #define __USE_UNIX98 */
@@ -595,4 +598,8 @@
  */
 void dvmNukeThread(Thread* thread);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_THREAD*/
diff --git a/vm/UtfString.h b/vm/UtfString.h
index 793d8bc..f0413a4 100644
--- a/vm/UtfString.h
+++ b/vm/UtfString.h
@@ -21,6 +21,10 @@
 #ifndef _DALVIK_STRING
 #define _DALVIK_STRING
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * (This is private to UtfString.c, but we cheat a bit and also use it
  * for InlineNative.c.  Not really worth creating a separate header.)
@@ -145,4 +149,8 @@
  */
 int dvmHashcmpStrings(const void* vstrObj1, const void* vstrObj2);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_STRING*/
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 */
diff --git a/vm/analysis/CodeVerify.h b/vm/analysis/CodeVerify.h
index 9369537..4fbf700 100644
--- a/vm/analysis/CodeVerify.h
+++ b/vm/analysis/CodeVerify.h
@@ -23,6 +23,9 @@
 #include "analysis/VerifySubs.h"
 #include "analysis/VfyBasicBlock.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /*
  * Enumeration for register type values.  The "hi" piece of a 64-bit value
@@ -322,4 +325,8 @@
  */
 bool dvmVerifyCodeFlow(VerifierData* vdata);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_CODEVERIFY*/
diff --git a/vm/analysis/RegisterMap.h b/vm/analysis/RegisterMap.h
index 886d0b0..becb1de 100644
--- a/vm/analysis/RegisterMap.h
+++ b/vm/analysis/RegisterMap.h
@@ -25,6 +25,10 @@
 #include "analysis/VerifySubs.h"
 #include "analysis/CodeVerify.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Format enumeration for RegisterMap data area.
  */
@@ -263,4 +267,8 @@
 /* dump stats gathered during register map creation process */
 void dvmRegisterMapDumpStats(void);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_REGISTERMAP*/
diff --git a/vm/compiler/Compiler.h b/vm/compiler/Compiler.h
index 35d34b3..384cb14 100644
--- a/vm/compiler/Compiler.h
+++ b/vm/compiler/Compiler.h
@@ -14,12 +14,16 @@
  * limitations under the License.
  */
 
-#include <Thread.h>
-#include <setjmp.h>
-
 #ifndef _DALVIK_VM_COMPILER
 #define _DALVIK_VM_COMPILER
 
+#include <setjmp.h>
+#include "Thread.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Uncomment the following to enable JIT signature breakpoint
  * #define SIGNATURE_BREAKPOINT
@@ -241,4 +245,9 @@
 JitInstructionSetType dvmCompilerGetInterpretTemplateSet();
 u8 dvmGetRegResourceMask(int reg);
 void dvmDumpCFG(struct CompilationUnit *cUnit, const char *dirPrefix);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _DALVIK_VM_COMPILER */
diff --git a/vm/hprof/Hprof.c b/vm/hprof/Hprof.cpp
similarity index 100%
rename from vm/hprof/Hprof.c
rename to vm/hprof/Hprof.cpp
diff --git a/vm/hprof/Hprof.h b/vm/hprof/Hprof.h
index c62dd9c..1721a6e 100644
--- a/vm/hprof/Hprof.h
+++ b/vm/hprof/Hprof.h
@@ -18,6 +18,10 @@
 
 #include "Dalvik.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define HPROF_ID_SIZE (sizeof (u4))
 
 #define UNIQUE_ERROR() \
@@ -144,7 +148,7 @@
 
 
 /*
- * HprofString.c functions
+ * HprofString.cpp functions
  */
 
 hprof_string_id hprofLookupStringId(const char *str);
@@ -156,7 +160,7 @@
 
 
 /*
- * HprofClass.c functions
+ * HprofClass.cpp functions
  */
 
 hprof_class_object_id hprofLookupClassId(const ClassObject *clazz);
@@ -168,7 +172,7 @@
 
 
 /*
- * HprofHeap.c functions
+ * HprofHeap.cpp functions
  */
 
 int hprofStartHeapDump(hprof_context_t *ctx);
@@ -182,7 +186,7 @@
 int hprofDumpHeapObject(hprof_context_t *ctx, const Object *obj);
 
 /*
- * HprofOutput.c functions
+ * HprofOutput.cpp functions
  */
 
 void hprofContextInit(hprof_context_t *ctx, char *fileName, int fd,
@@ -215,18 +219,17 @@
             hprofAddU4ListToRecord((rec), (const u4 *)(values), (numValues))
 
 /*
- * Hprof.c functions
+ * Hprof.cpp functions
  */
 
 hprof_context_t* hprofStartup(const char *outputFileName, int fd,
     bool directToDdms);
 bool hprofShutdown(hprof_context_t *ctx);
 void hprofFreeContext(hprof_context_t *ctx);
-
-/*
- * HprofVisit.c functions
- */
-
 int hprofDumpHeap(const char* fileName, int fd, bool directToDdms);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif  // _DALVIK_HPROF_HPROF
diff --git a/vm/hprof/HprofClass.c b/vm/hprof/HprofClass.cpp
similarity index 100%
rename from vm/hprof/HprofClass.c
rename to vm/hprof/HprofClass.cpp
diff --git a/vm/hprof/HprofHeap.c b/vm/hprof/HprofHeap.cpp
similarity index 97%
rename from vm/hprof/HprofHeap.c
rename to vm/hprof/HprofHeap.cpp
index ee24a7a..8ec0100 100644
--- a/vm/hprof/HprofHeap.c
+++ b/vm/hprof/HprofHeap.cpp
@@ -129,7 +129,7 @@
 {
     hprof_record_t *rec = &ctx->curRec;
     int err;
-    hprof_heap_tag_t heapTag = ctx->gcScanState;
+    hprof_heap_tag_t heapTag = (hprof_heap_tag_t)ctx->gcScanState;
 
     if (heapTag == 0) {
         return 0;
@@ -382,7 +382,7 @@
                 /* Dump the elements, which are always objects or NULL.
                  */
                 hprofAddIdListToRecord(rec,
-                        (const hprof_object_id *)aobj->contents, length);
+                        (const hprof_object_id *)(void *)aobj->contents, length);
             } else {
                 hprof_basic_type t;
                 size_t size;
@@ -410,10 +410,10 @@
                     hprofAddU1ListToRecord(rec, (const u1 *)aobj->contents,
                             length);
                 } else if (size == 2) {
-                    hprofAddU2ListToRecord(rec, (const u2 *)aobj->contents,
+                    hprofAddU2ListToRecord(rec, (const u2 *)(void *)aobj->contents,
                             length);
                 } else if (size == 4) {
-                    hprofAddU4ListToRecord(rec, (const u4 *)aobj->contents,
+                    hprofAddU4ListToRecord(rec, (const u4 *)(void *)aobj->contents,
                             length);
                 } else if (size == 8) {
                     hprofAddU8ListToRecord(rec, (const u8 *)aobj->contents,
diff --git a/vm/hprof/HprofOutput.c b/vm/hprof/HprofOutput.cpp
similarity index 100%
rename from vm/hprof/HprofOutput.c
rename to vm/hprof/HprofOutput.cpp
diff --git a/vm/hprof/HprofString.c b/vm/hprof/HprofString.cpp
similarity index 100%
rename from vm/hprof/HprofString.c
rename to vm/hprof/HprofString.cpp
diff --git a/vm/interp/Jit.h b/vm/interp/Jit.h
index 7dbe9ac..67b9b4a 100644
--- a/vm/interp/Jit.h
+++ b/vm/interp/Jit.h
@@ -22,6 +22,10 @@
 #include "InterpDefs.h"
 #include "mterp/common/jit-config.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define JIT_MAX_TRACE_LEN 100
 
 #if defined (WITH_SELF_VERIFICATION)
@@ -166,4 +170,8 @@
 void dvmJitUpdateThreadStateAll(void);
 void dvmJitResumeTranslation(Thread* self, const u2* pc, const u4* fp);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_INTERP_JIT*/
diff --git a/vm/interp/Stack.h b/vm/interp/Stack.h
index 10c04a0..403cae2 100644
--- a/vm/interp/Stack.h
+++ b/vm/interp/Stack.h
@@ -23,6 +23,9 @@
 #include "jni.h"
 #include <stdarg.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /*
 Stack layout
@@ -279,4 +282,8 @@
 void dvmDumpThreadStack(const DebugOutputTarget* target, Thread* thread);
 void dvmDumpRunningThreadStack(const DebugOutputTarget* target, Thread* thread);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_INTERP_STACK*/
diff --git a/vm/native/InternalNative.h b/vm/native/InternalNative.h
index 7c82dc0..4d32de2 100644
--- a/vm/native/InternalNative.h
+++ b/vm/native/InternalNative.h
@@ -17,6 +17,10 @@
 #ifndef _DALVIK_NATIVE_INTERNALNATIVE
 #define _DALVIK_NATIVE_INTERNALNATIVE
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Some setup for internal native functions.
  */
@@ -29,4 +33,8 @@
 /* exception-throwing stub for abstract methods (DalvikNativeFunc) */
 void dvmAbstractMethodStub(const u4* args, JValue* pResult);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_NATIVE_INTERNALNATIVE*/
diff --git a/vm/native/InternalNativePriv.h b/vm/native/InternalNativePriv.h
index 440e60d..35ab44c 100644
--- a/vm/native/InternalNativePriv.h
+++ b/vm/native/InternalNativePriv.h
@@ -20,6 +20,10 @@
 #ifndef _DALVIK_NATIVE_INTERNALNATIVEPRIV
 #define _DALVIK_NATIVE_INTERNALNATIVEPRIV
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Return macros.  Note we use "->i" instead of "->z" for boolean; this
  * is because the interpreter expects everything to be a 32-bit value.
@@ -112,4 +116,8 @@
 extern const DalvikNativeMethod dvm_org_apache_harmony_dalvik_NativeTestTarget[];
 extern const DalvikNativeMethod dvm_sun_misc_Unsafe[];
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_NATIVE_INTERNALNATIVEPRIV*/
diff --git a/vm/oo/AccessCheck.h b/vm/oo/AccessCheck.h
index 105c9e1..8633d89 100644
--- a/vm/oo/AccessCheck.h
+++ b/vm/oo/AccessCheck.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_OO_ACCESSCHECK
 #define _DALVIK_OO_ACCESSCHECK
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Determine whether the "accessFrom" class is allowed to get at "clazz".
  */
@@ -40,4 +44,8 @@
  */
 bool dvmInSamePackage(const ClassObject* class1, const ClassObject* class2);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_OO_ACCESSCHECK*/
diff --git a/vm/oo/Array.h b/vm/oo/Array.h
index 9a873e6..585f896 100644
--- a/vm/oo/Array.h
+++ b/vm/oo/Array.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_OO_ARRAY
 #define _DALVIK_OO_ARRAY
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* width of an object reference, for arrays of objects */
 #define kObjectArrayRefWidth    sizeof(Object*)
 
@@ -167,4 +171,8 @@
  */
 size_t dvmArrayClassElementWidth(const ClassObject* clazz);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_OO_ARRAY*/
diff --git a/vm/oo/Class.h b/vm/oo/Class.h
index 3ad44bd..43a3954 100644
--- a/vm/oo/Class.h
+++ b/vm/oo/Class.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_OO_CLASS
 #define _DALVIK_OO_CLASS
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * The classpath and bootclasspath differ in that only the latter is
  * consulted when looking for classes needed by the VM.  When searching
@@ -285,4 +289,8 @@
  */
 size_t dvmClassObjectSize(const ClassObject *clazz);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_OO_CLASS*/
diff --git a/vm/oo/Object.h b/vm/oo/Object.h
index b32d5b9..86c0b95 100644
--- a/vm/oo/Object.h
+++ b/vm/oo/Object.h
@@ -21,9 +21,12 @@
 #ifndef _DALVIK_OO_OBJECT
 #define _DALVIK_OO_OBJECT
 
-#include <Atomic.h>
-
 #include <stddef.h>
+#include "Atomic.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /* fwd decl */
 struct DataObject;
@@ -779,4 +782,8 @@
 /* debugging */
 void dvmDumpObject(const Object* obj);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_OO_OBJECT*/
diff --git a/vm/oo/ObjectInlines.h b/vm/oo/ObjectInlines.h
index ef01834..1579a56 100644
--- a/vm/oo/ObjectInlines.h
+++ b/vm/oo/ObjectInlines.h
@@ -20,6 +20,10 @@
 #ifndef _DALVIK_OO_OBJECTINLINES
 #define _DALVIK_OO_OBJECTINLINES
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Store a single value in the array, and if the value isn't null,
  * note in the write barrier.
@@ -354,4 +358,8 @@
     }
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_OO_OBJECTINLINES*/
diff --git a/vm/oo/Resolve.h b/vm/oo/Resolve.h
index 70b2294..1403e77 100644
--- a/vm/oo/Resolve.h
+++ b/vm/oo/Resolve.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_OO_RESOLVE
 #define _DALVIK_OO_RESOLVE
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * "Direct" and "virtual" methods are stored independently.  The type of call
  * used to invoke the method determines which list we search, and whether
@@ -92,4 +96,8 @@
  */
 const char* dvmMethodTypeStr(MethodType methodType);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_OO_RESOLVE*/
diff --git a/vm/oo/TypeCheck.h b/vm/oo/TypeCheck.h
index 1397998..07bae47 100644
--- a/vm/oo/TypeCheck.h
+++ b/vm/oo/TypeCheck.h
@@ -19,6 +19,10 @@
 #ifndef _DALVIK_OO_TYPECHECK
 #define _DALVIK_OO_TYPECHECK
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* VM startup/shutdown */
 bool dvmInstanceofStartup(void);
 void dvmInstanceofShutdown(void);
@@ -75,4 +79,8 @@
 bool dvmCanPutArrayElement(const ClassObject* elemClass,
     const ClassObject* arrayClass);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_OO_TYPECHECK*/