OSDN Git Service

Convert the internal and in-line natives to C++.
authorCarl Shapiro <cshapiro@google.com>
Wed, 13 Apr 2011 02:14:06 +0000 (19:14 -0700)
committerCarl Shapiro <cshapiro@google.com>
Wed, 13 Apr 2011 02:14:06 +0000 (19:14 -0700)
Change-Id: I2ece682bc3b4d3b55ab27c60fd84a0b3243d7ca6

49 files changed:
libdex/CmdUtils.h
libdex/DexCatch.h
libdex/DexClass.h
libdex/DexDataMap.h
libdex/DexFile.h
libdex/DexOpcodes.h
libdex/DexOptData.h
libdex/DexProto.h
libdex/DexUtf.h
libdex/InstrUtils.h
libdex/Leb128.h
libdex/ZipArchive.h
libdex/sha1.h
vm/Dvm.mk
vm/InlineNative.h
vm/UtfString.c
vm/UtfString.h
vm/interp/Stack.c
vm/interp/Stack.h
vm/native/InternalNative.cpp [moved from vm/native/InternalNative.c with 100% similarity]
vm/native/dalvik_bytecode_OpcodeInfo.cpp [moved from vm/native/dalvik_bytecode_OpcodeInfo.c with 96% similarity]
vm/native/dalvik_system_DexFile.cpp [moved from vm/native/dalvik_system_DexFile.c with 100% similarity]
vm/native/dalvik_system_VMDebug.cpp [moved from vm/native/dalvik_system_VMDebug.c with 96% similarity]
vm/native/dalvik_system_VMRuntime.cpp [moved from vm/native/dalvik_system_VMRuntime.c with 98% similarity]
vm/native/dalvik_system_VMStack.cpp [moved from vm/native/dalvik_system_VMStack.c with 81% similarity]
vm/native/dalvik_system_Zygote.cpp [moved from vm/native/dalvik_system_Zygote.c with 98% similarity]
vm/native/java_lang_Class.cpp [moved from vm/native/java_lang_Class.c with 99% similarity]
vm/native/java_lang_Double.cpp [moved from vm/native/java_lang_Double.c with 100% similarity]
vm/native/java_lang_Float.cpp [moved from vm/native/java_lang_Float.c with 100% similarity]
vm/native/java_lang_Math.cpp [moved from vm/native/java_lang_Math.c with 100% similarity]
vm/native/java_lang_Object.cpp [moved from vm/native/java_lang_Object.c with 100% similarity]
vm/native/java_lang_Runtime.cpp [moved from vm/native/java_lang_Runtime.c with 100% similarity]
vm/native/java_lang_String.cpp [moved from vm/native/java_lang_String.c with 100% similarity]
vm/native/java_lang_System.cpp [moved from vm/native/java_lang_System.c with 98% similarity]
vm/native/java_lang_Throwable.cpp [moved from vm/native/java_lang_Throwable.c with 100% similarity]
vm/native/java_lang_VMClassLoader.cpp [moved from vm/native/java_lang_VMClassLoader.c with 100% similarity]
vm/native/java_lang_VMThread.cpp [moved from vm/native/java_lang_VMThread.c with 100% similarity]
vm/native/java_lang_reflect_AccessibleObject.cpp [moved from vm/native/java_lang_reflect_AccessibleObject.c with 100% similarity]
vm/native/java_lang_reflect_Array.cpp [moved from vm/native/java_lang_reflect_Array.c with 98% similarity]
vm/native/java_lang_reflect_Constructor.cpp [moved from vm/native/java_lang_reflect_Constructor.c with 100% similarity]
vm/native/java_lang_reflect_Field.cpp [moved from vm/native/java_lang_reflect_Field.c with 100% similarity]
vm/native/java_lang_reflect_Method.cpp [moved from vm/native/java_lang_reflect_Method.c with 100% similarity]
vm/native/java_lang_reflect_Proxy.cpp [moved from vm/native/java_lang_reflect_Proxy.c with 100% similarity]
vm/native/java_util_concurrent_atomic_AtomicLong.cpp [moved from vm/native/java_util_concurrent_atomic_AtomicLong.c with 100% similarity]
vm/native/org_apache_harmony_dalvik_NativeTestTarget.cpp [moved from vm/native/org_apache_harmony_dalvik_NativeTestTarget.c with 100% similarity]
vm/native/org_apache_harmony_dalvik_ddmc_DdmServer.cpp [moved from vm/native/org_apache_harmony_dalvik_ddmc_DdmServer.c with 100% similarity]
vm/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cpp [moved from vm/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.c with 100% similarity]
vm/native/sun_misc_Unsafe.cpp [moved from vm/native/sun_misc_Unsafe.c with 100% similarity]
vm/reflect/Reflect.h

index 7a85287..3f05aff 100644 (file)
 #ifndef _LIBDEX_CMDUTILS
 #define _LIBDEX_CMDUTILS
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* encode the result of unzipping to a file */
 typedef enum UnzipToFileResult {
     kUTFRSuccess = 0,
@@ -70,4 +74,8 @@ UnzipToFileResult dexOpenAndMap(const char* fileName, const char* tempFileName,
 UnzipToFileResult dexUnzipToFile(const char* zipFileName,
     const char* outFileName, bool quiet);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_LIBDEX_CMDUTILS*/
index c0eec7c..7c40bc5 100644 (file)
 #include "DexFile.h"
 #include "Leb128.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Catch handler entry, used while iterating over catch_handler_items.
  */
@@ -159,4 +163,8 @@ DEX_INLINE bool dexFindCatchHandler(DexCatchIterator *pIterator,
     }
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
index 3d1e11b..6003fcf 100644 (file)
 #include "DexFile.h"
 #include "Leb128.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* expanded form of a class_data_item header */
 typedef struct DexClassDataHeader {
     u4 staticFieldsSize;
@@ -159,4 +163,8 @@ DEX_INLINE void dexReadClassDataMethod(const u1** pData, DexMethod* pMethod,
     *lastIndex = index;
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
index fa556d5..654933c 100644 (file)
 
 #include "DexFile.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct DexDataMap {
     u4 count;    /* number of items currently in the map */
     u4 max;      /* maximum number of items that may be held */
@@ -70,4 +74,8 @@ DEX_INLINE bool dexDataMapVerify0Ok(DexDataMap* map, u4 offset, u2 type) {
     return dexDataMapVerify(map, offset, type);
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_LIBDEX_DEXDATAMAP*/
index 45f9a91..6652286 100644 (file)
 #include "vm/Common.h"      // basic type defs, e.g. u1/u2/u4/u8, and LOG
 #include "libdex/SysUtil.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * gcc-style inline management -- ensures we have a copy of all functions
  * in the library, so code that links against us will work whether or not
@@ -960,4 +964,8 @@ const char* dexGetBoxedTypeDescriptor(PrimitiveType type);
  */
 PrimitiveType dexGetPrimitiveTypeFromDescriptorChar(char descriptorChar);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_LIBDEX_DEXFILE*/
index 07188b2..68b8498 100644 (file)
 
 #include "DexFile.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * kMaxOpcodeValue: the highest possible raw (unpacked) opcode value
  *
@@ -1133,4 +1137,8 @@ DEX_INLINE Opcode dexOpcodeFromCodeUnit(u2 codeUnit) {
  */
 const char* dexGetOpcodeName(Opcode op);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_LIBDEX_DEXOPCODES*/
index 69eda01..562553d 100644 (file)
 
 #include "libdex/DexFile.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Parse the optimized data tables in the given dex file.
  *
@@ -39,4 +43,8 @@ bool dexParseOptData(const u1* data, size_t length, DexFile* pDexFile);
  */
 u4 dexComputeOptChecksum(const DexOptHeader* pOptHeader);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* def _LIBDEX_DEXOPTDATA */
index 50d4bf3..a300d3f 100644 (file)
 
 #include "DexFile.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Single-thread single-string cache. This structure holds a pointer to
  * a string which is semi-automatically manipulated by some of the
@@ -226,6 +230,8 @@ u4 dexParameterIteratorNextIndex(DexParameterIterator* pIterator);
 const char* dexParameterIteratorNextDescriptor(
         DexParameterIterator* pIterator);
 
-
+#ifdef __cplusplus
+}
+#endif
 
 #endif /*_LIBDEX_DEXPROTO*/
index a7eb28c..88d98b0 100644 (file)
 
 #include "DexFile.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Retrieve the next UTF-16 character from a UTF-8 string.
  *
@@ -128,4 +132,8 @@ bool dexIsClassDescriptor(const char* s);
  * is for anything but "void". */
 bool dexIsFieldDescriptor(const char* s);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* def _LIBDEX_DEXUTF */
index f09429c..88804cf 100644 (file)
 #include "DexFile.h"
 #include "DexOpcodes.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Possible instruction formats associated with Dalvik opcodes.
  *
@@ -198,4 +202,8 @@ DEX_INLINE InstructionIndexType dexGetIndexTypeFromOpcode(Opcode opcode)
  */
 void dexDecodeInstruction(const u2* insns, DecodedInstruction* pDec);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_LIBDEX_INSTRUTILS*/
index 41799fe..3287c16 100644 (file)
 
 #include "DexFile.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Reads an unsigned LEB128 value, updating the given pointer to point
  * just past the end of the read value. This function tolerates
@@ -161,4 +165,8 @@ DEX_INLINE int unsignedLeb128Size(u4 data)
     return count;
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
index bf4edf9..872ceed 100644 (file)
@@ -23,6 +23,9 @@
 #include "SysUtil.h"
 #include "DexFile.h"            // need DEX_INLINE
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /*
  * Trivial typedef to ensure that ZipEntry is not treated as a simple
@@ -179,4 +182,8 @@ int dexZipExtractEntryToFile(const ZipArchive* pArchive,
 u4 dexInitCrc32(void);
 u4 dexComputeCrc32(u4 crc, const void* buf, size_t len);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_LIBDEX_ZIPARCHIVE*/
index 65cf667..0cef623 100644 (file)
@@ -4,6 +4,10 @@
 #ifndef _DALVIK_SHA1
 #define _DALVIK_SHA1
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct {
     unsigned long state[5];
     unsigned long count[2];
@@ -17,4 +21,8 @@ void SHA1Update(SHA1_CTX* context, const unsigned char* data,
     unsigned long len);
 void SHA1Final(unsigned char digest[HASHSIZE], SHA1_CTX* context);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_SHA1*/
index add2207..ca09183 100644 (file)
--- a/vm/Dvm.mk
+++ b/vm/Dvm.mk
@@ -148,35 +148,35 @@ LOCAL_SRC_FILES := \
        jdwp/JdwpSocket.c \
        mterp/Mterp.c.arm \
        mterp/out/InterpC-portable.c.arm \
-       native/InternalNative.c \
-       native/dalvik_bytecode_OpcodeInfo.c \
-       native/dalvik_system_DexFile.c \
-       native/dalvik_system_VMDebug.c \
-       native/dalvik_system_VMRuntime.c \
-       native/dalvik_system_VMStack.c \
-       native/dalvik_system_Zygote.c \
-       native/java_lang_Class.c \
-       native/java_lang_Double.c \
-       native/java_lang_Float.c \
-       native/java_lang_Math.c \
-       native/java_lang_Object.c \
-       native/java_lang_Runtime.c \
-       native/java_lang_String.c \
-       native/java_lang_System.c \
-       native/java_lang_Throwable.c \
-       native/java_lang_VMClassLoader.c \
-       native/java_lang_VMThread.c \
-       native/java_lang_reflect_AccessibleObject.c \
-       native/java_lang_reflect_Array.c \
-       native/java_lang_reflect_Constructor.c \
-       native/java_lang_reflect_Field.c \
-       native/java_lang_reflect_Method.c \
-       native/java_lang_reflect_Proxy.c \
-       native/java_util_concurrent_atomic_AtomicLong.c \
-       native/org_apache_harmony_dalvik_NativeTestTarget.c \
-       native/org_apache_harmony_dalvik_ddmc_DdmServer.c \
-       native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.c \
-       native/sun_misc_Unsafe.c \
+       native/InternalNative.cpp \
+       native/dalvik_bytecode_OpcodeInfo.cpp \
+       native/dalvik_system_DexFile.cpp \
+       native/dalvik_system_VMDebug.cpp \
+       native/dalvik_system_VMRuntime.cpp \
+       native/dalvik_system_VMStack.cpp \
+       native/dalvik_system_Zygote.cpp \
+       native/java_lang_Class.cpp \
+       native/java_lang_Double.cpp \
+       native/java_lang_Float.cpp \
+       native/java_lang_Math.cpp \
+       native/java_lang_Object.cpp \
+       native/java_lang_Runtime.cpp \
+       native/java_lang_String.cpp \
+       native/java_lang_System.cpp \
+       native/java_lang_Throwable.cpp \
+       native/java_lang_VMClassLoader.cpp \
+       native/java_lang_VMThread.cpp \
+       native/java_lang_reflect_AccessibleObject.cpp \
+       native/java_lang_reflect_Array.cpp \
+       native/java_lang_reflect_Constructor.cpp \
+       native/java_lang_reflect_Field.cpp \
+       native/java_lang_reflect_Method.cpp \
+       native/java_lang_reflect_Proxy.cpp \
+       native/java_util_concurrent_atomic_AtomicLong.cpp \
+       native/org_apache_harmony_dalvik_NativeTestTarget.cpp \
+       native/org_apache_harmony_dalvik_ddmc_DdmServer.cpp \
+       native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cpp \
+       native/sun_misc_Unsafe.cpp \
        oo/AccessCheck.c \
        oo/Array.c \
        oo/Class.c \
@@ -224,9 +224,9 @@ LOCAL_C_INCLUDES += \
        dalvik \
        dalvik/vm \
        external/zlib \
+       libcore/include \
        $(KERNEL_HEADERS)
 
-
 ifeq ($(dvm_simulator),true)
   LOCAL_LDLIBS += -lpthread -ldl
   ifeq ($(HOST_OS),linux)
index 4f86cef..bf08412 100644 (file)
@@ -125,6 +125,75 @@ bool dvmPerformInlineOp4Dbg(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
  */
 Method* dvmResolveInlineNative(int opIndex);
 
+/*
+ * The actual inline native definitions.
+ */
+bool javaLangString_charAt(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                           JValue* pResult);
+
+bool javaLangString_compareTo(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                              JValue* pResult);
+
+bool javaLangString_equals(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                           JValue* pResult);
+
+bool javaLangString_length(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                           JValue* pResult);
+
+bool javaLangString_isEmpty(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                            JValue* pResult);
+
+bool javaLangString_fastIndexOf_II(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                                   JValue* pResult);
+
+bool javaLangMath_abs_int(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                          JValue* pResult);
+
+bool javaLangMath_abs_long(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                           JValue* pResult);
+
+bool javaLangMath_abs_float(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                            JValue* pResult);
+
+bool javaLangMath_abs_double(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                             JValue* pResult);
+
+bool javaLangMath_min_int(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                          JValue* pResult);
+
+bool javaLangMath_max_int(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                          JValue* pResult);
+
+bool javaLangMath_sqrt(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                       JValue* pResult);
+
+bool javaLangMath_cos(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                      JValue* pResult);
+
+bool javaLangMath_sin(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
+                      JValue* pResult);
+
+bool javaLangFloat_floatToIntBits(u4 arg0, u4 arg1, u4 arg2, u4 arg,
+                                  JValue* pResult);
+
+bool javaLangFloat_floatToRawIntBits(u4 arg0, u4 arg1, u4 arg2, u4 arg,
+                                     JValue* pResult);
+
+bool javaLangFloat_intBitsToFloat(u4 arg0, u4 arg1, u4 arg2, u4 arg,
+                                  JValue* pResult);
+
+bool javaLangDouble_doubleToLongBits(u4 arg0, u4 arg1, u4 arg2, u4 arg,
+                                     JValue* pResult);
+
+bool javaLangDouble_longBitsToDouble(u4 arg0, u4 arg1, u4 arg2, u4 arg,
+                                     JValue* pResult);
+
+bool javaLangDouble_doubleToRawLongBits(u4 arg0, u4 arg1, u4 arg2,
+                                        u4 arg, JValue* pResult);
+
+bool javaLangDouble_longBitsToDouble(u4 arg0, u4 arg1, u4 arg2, u4 arg,
+                                     JValue* pResult);
+
 #ifdef __cplusplus
 }
 #endif
index 58545cd..ec35cdf 100644 (file)
@@ -418,7 +418,7 @@ int dvmHashcmpStrings(const void* vstrObj1, const void* vstrObj2)
                   len1 * sizeof(u2));
 }
 
-ArrayObject* dvmCreateStringArray(char** strings, size_t count)
+ArrayObject* dvmCreateStringArray(const char** strings, size_t count)
 {
     Thread* self = dvmThreadSelf();
 
index f0413a4..a1ee712 100644 (file)
@@ -67,7 +67,7 @@ u4 dvmComputeStringHash(const StringObject* strObj);
  *
  * Returns NULL and throws an exception on failure.
  */
-ArrayObject* dvmCreateStringArray(char** strings, size_t count);
+ArrayObject* dvmCreateStringArray(const char** strings, size_t count);
 
 /*
  * Create a java/lang/String from a C string.
index 97fbeb5..85e54ff 100644 (file)
@@ -971,37 +971,24 @@ ClassObject* dvmGetCaller3Class(const void* curFrame)
 }
 
 /*
- * Create a flat array of methods that comprise the current interpreter
- * stack trace.  Pass in the current frame ptr.
- *
- * Allocates a new array and fills it with method pointers.  Break frames
- * are skipped, but reflection invocations are not.  The caller must free
- * "*pArray".
+ * Fill a flat array of methods that comprise the current interpreter
+ * stack trace.  Pass in the current frame ptr.  Break frames are
+ * skipped, but reflection invocations are not.
  *
  * The current frame will be in element 0.
- *
- * Returns "true" on success, "false" on failure (e.g. malloc failed).
  */
-bool dvmCreateStackTraceArray(const void* fp, const Method*** pArray,
-    int* pLength)
+void dvmFillStackTraceArray(const void* fp, const Method** array, size_t length)
 {
-    const Method** array;
-    int idx, depth;
-
-    depth = dvmComputeExactFrameDepth(fp);
-    array = (const Method**) malloc(depth * sizeof(Method*));
-    if (array == NULL)
-        return false;
-
-    for (idx = 0; fp != NULL; fp = SAVEAREA_FROM_FP(fp)->prevFrame) {
-        if (!dvmIsBreakFrame((u4*)fp))
-            array[idx++] = SAVEAREA_FROM_FP(fp)->method;
+    assert(fp != NULL);
+    assert(array != NULL);
+    size_t i = 0;
+    while (fp != NULL) {
+        if (!dvmIsBreakFrame((u4*)fp)) {
+            assert(i < length);
+            array[i++] = SAVEAREA_FROM_FP(fp)->method;
+        }
+        fp = SAVEAREA_FROM_FP(fp)->prevFrame;
     }
-    assert(idx == depth);
-
-    *pArray = array;
-    *pLength = depth;
-    return true;
 }
 
 /*
index 403cae2..99bef1a 100644 (file)
@@ -266,11 +266,10 @@ ClassObject* dvmGetCaller2Class(const void* curFrame);
 ClassObject* dvmGetCaller3Class(const void* curFrame);
 
 /*
- * Allocate and fill an array of method pointers representing the current
- * stack trace (element 0 is current frame).
+ * Fill an array of method pointers representing the current stack
+ * trace (element 0 is current frame).
  */
-bool dvmCreateStackTraceArray(const void* fp, const Method*** pArray,
-    int* pLength);
+void dvmFillStackTraceArray(const void* fp, const Method** array, size_t length);
 
 /*
  * Common handling for stack overflow.
similarity index 96%
rename from vm/native/dalvik_bytecode_OpcodeInfo.c
rename to vm/native/dalvik_bytecode_OpcodeInfo.cpp
index cabd7b1..3861fef 100644 (file)
@@ -31,7 +31,7 @@
 static void Dalvik_dalvik_bytecode_OpcodeInfo_isInvoke(const u4* args,
     JValue* pResult)
 {
-    jint opcode = (jint) args[0];
+    Opcode opcode = static_cast<Opcode>(args[0]);
     int flags = dexGetFlagsFromOpcode(opcode);
     bool result = (flags & kInstrInvoke) != 0;
     RETURN_BOOLEAN(result);
similarity index 96%
rename from vm/native/dalvik_system_VMDebug.c
rename to vm/native/dalvik_system_VMDebug.cpp
index 146f562..cfd8ebc 100644 (file)
 #include "native/InternalNativePriv.h"
 #include "hprof/Hprof.h"
 
-#include <cutils/array.h>
 #include <string.h>
 #include <unistd.h>
-#include <errno.h>
 
 
 /*
@@ -51,30 +49,20 @@ static int getFileDescriptor(Object* obj)
  * static String[] getVmFeatureList()
  *
  * Return a set of strings describing available VM features (this is chiefly
- * of interest to DDMS).  Some features may be controlled by compile-time
- * or command-line flags.
+ * of interest to DDMS).
  */
 static void Dalvik_dalvik_system_VMDebug_getVmFeatureList(const u4* args,
     JValue* pResult)
 {
-    Array* features = arrayCreate();
-
-    /* VM responds to DDMS method profiling requests */
-    arrayAdd(features, "method-trace-profiling");
-    arrayAdd(features, "method-trace-profiling-streaming");
-    /* VM responds to DDMS heap dump requests */
-    arrayAdd(features, "hprof-heap-dump");
-    arrayAdd(features, "hprof-heap-dump-streaming");
-
-    char** strings = (char**) arrayUnwrap(features);
-    int count = arraySize(features);
-    ArrayObject* result = dvmCreateStringArray(strings, count);
+    const char* strings[] = { "method-trace-profiling",
+                              "method-trace-profiling-streaming",
+                              "hprof-heap-dump",
+                              "hprof-heap-dump-streaming" };
+    ArrayObject* result = dvmCreateStringArray(strings, NELEM(strings));
     dvmReleaseTrackedAlloc((Object*) result, dvmThreadSelf());
-    arrayFree(features);
     RETURN_PTR(result);
 }
 
-
 /* These must match the values in dalvik.system.VMDebug.
  */
 enum {
@@ -416,7 +404,7 @@ static void Dalvik_dalvik_system_VMDebug_getInstructionCount(const u4* args,
     ArrayObject* countArray = (ArrayObject*) args[0];
 
     if (countArray != NULL) {
-        int* storage = (int*) countArray->contents;
+        int* storage = (int*)(void*)countArray->contents;
         u4 length = countArray->length;
 
         /*
similarity index 98%
rename from vm/native/dalvik_system_VMRuntime.c
rename to vm/native/dalvik_system_VMRuntime.cpp
index 3642f90..c133e64 100644 (file)
@@ -145,7 +145,7 @@ static void Dalvik_dalvik_system_VMRuntime_clearGrowthLimit(const u4* args,
 static void Dalvik_dalvik_system_VMRuntime_properties(const u4* args,
     JValue* pResult)
 {
-    char** strings = (char**) arrayUnwrap(gDvm.properties);
+    const char** strings = (const char**) arrayUnwrap(gDvm.properties);
     int count = arraySize(gDvm.properties);
     ArrayObject* result = dvmCreateStringArray(strings, count);
     dvmReleaseTrackedAlloc((Object*) result, dvmThreadSelf());
similarity index 81%
rename from vm/native/dalvik_system_VMStack.c
rename to vm/native/dalvik_system_VMStack.cpp
index 045a100..05b439f 100644 (file)
@@ -18,9 +18,9 @@
  * dalvik.system.VMStack
  */
 #include "Dalvik.h"
+#include "UniquePtr.h"
 #include "native/InternalNativePriv.h"
 
-
 /*
  * public static ClassLoader getCallingClassLoader()
  *
@@ -81,36 +81,23 @@ static void Dalvik_dalvik_system_VMStack_getClasses(const u4* args,
     JValue* pResult)
 {
     /* note "maxSize" is unsigned, so -1 turns into a very large value */
-    unsigned int maxSize = args[0];
-    unsigned int size = 0;
-    const unsigned int kSkip = 2;
-    const Method** methods = NULL;
-    int methodCount;
+    size_t maxSize = args[0];
+    size_t size = 0;
+    const size_t kSkip = 2;
 
     /*
      * Get an array with the stack trace in it.
      */
-    if (!dvmCreateStackTraceArray(dvmThreadSelf()->curFrame, &methods,
-            &methodCount))
-    {
-        LOGE("Failed to create stack trace array\n");
-        dvmThrowInternalError(NULL);
-        RETURN_VOID();
-    }
-
-    //int i;
-    //LOGI("dvmCreateStackTraceArray results:\n");
-    //for (i = 0; i < methodCount; i++) {
-    //    LOGI(" %2d: %s.%s\n",
-    //        i, methods[i]->clazz->descriptor, methods[i]->name);
-    //}
+    void *fp = dvmThreadSelf()->curFrame;
+    size_t depth = dvmComputeExactFrameDepth(fp);
+    UniquePtr<const Method*[]> methods(new const Method*[depth]);
+    dvmFillStackTraceArray(fp, methods.get(), depth);
 
     /*
      * Run through the array and count up how many elements there are.
      */
-    unsigned int idx;
-    for (idx = kSkip; (int) idx < methodCount && size < maxSize; idx++) {
-        const Method* meth = methods[idx];
+    for (size_t i = kSkip; i < depth && size < maxSize; ++i) {
+        const Method* meth = methods[i];
 
         if (dvmIsReflectionMethod(meth))
             continue;
@@ -122,37 +109,36 @@ static void Dalvik_dalvik_system_VMStack_getClasses(const u4* args,
      * Create an array object to hold the classes.
      * TODO: can use gDvm.classJavaLangClassArray here?
      */
-    ClassObject* classArrayClass = NULL;
-    ArrayObject* classes = NULL;
-    classArrayClass = dvmFindArrayClass("[Ljava/lang/Class;", NULL);
+    ClassObject* classArrayClass = dvmFindArrayClass("[Ljava/lang/Class;",
+                                                     NULL);
     if (classArrayClass == NULL) {
-        LOGW("Unable to find java.lang.Class array class\n");
-        goto bail;
+        LOGW("Unable to find java.lang.Class array class");
+        return;
     }
-    classes = dvmAllocArray(classArrayClass, size, kObjectArrayRefWidth,
-                ALLOC_DEFAULT);
+    ArrayObject* classes = dvmAllocArray(classArrayClass,
+                                         size,
+                                         kObjectArrayRefWidth,
+                                         ALLOC_DEFAULT);
     if (classes == NULL) {
-        LOGW("Unable to allocate class array (%d elems)\n", size);
-        goto bail;
+        LOGW("Unable to allocate class array of %zd elements", size);
+        return;
     }
 
     /*
      * Fill in the array.
      */
-    unsigned int objCount = 0;
-    for (idx = kSkip; (int) idx < methodCount; idx++) {
-        if (dvmIsReflectionMethod(methods[idx])) {
+    size_t objCount = 0;
+    for (size_t i = kSkip; i < depth; ++i) {
+        if (dvmIsReflectionMethod(methods[i])) {
             continue;
         }
-        dvmSetObjectArrayElement(classes, objCount,
-                                 (Object *)methods[idx]->clazz);
+        Object* klass = (Object *)methods[i]->clazz;
+        dvmSetObjectArrayElement(classes, objCount, klass);
         objCount++;
     }
     assert(objCount == classes->length);
 
-bail:
-    free(methods);
-    dvmReleaseTrackedAlloc((Object*) classes, NULL);
+    dvmReleaseTrackedAlloc((Object*)classes, NULL);
     RETURN_PTR(classes);
 }
 
similarity index 98%
rename from vm/native/dalvik_system_Zygote.c
rename to vm/native/dalvik_system_Zygote.cpp
index 6f7e6fa..62cd0c2 100644 (file)
@@ -168,7 +168,7 @@ static int setgroupsIntarray(ArrayObject* gidArray)
 
     /* just in case gid_t and u4 are different... */
     gids = (gid_t *)alloca(sizeof(gid_t) * gidArray->length);
-    contents = (s4 *)gidArray->contents;
+    contents = (s4 *)(void *)gidArray->contents;
 
     for (i = 0 ; i < gidArray->length ; i++) {
         gids[i] = (gid_t) contents[i];
@@ -196,11 +196,11 @@ static int setrlimitsFromArray(ArrayObject* rlimits)
 
     memset (&rlim, 0, sizeof(rlim));
 
-    ArrayObject** tuples = (ArrayObject **)(rlimits->contents);
+    ArrayObject** tuples = (ArrayObject **)(void *)rlimits->contents;
 
     for (i = 0; i < rlimits->length; i++) {
         ArrayObject * rlimit_tuple = tuples[i];
-        s4* contents = (s4 *)rlimit_tuple->contents;
+        s4* contents = (s4 *)(void *)rlimit_tuple->contents;
         int err;
 
         if (rlimit_tuple->length != 3) {
similarity index 99%
rename from vm/native/java_lang_Class.c
rename to vm/native/java_lang_Class.cpp
index a3839a3..f05faef 100644 (file)
@@ -192,7 +192,7 @@ static void Dalvik_java_lang_Class_getDeclaredClasses(const u4* args,
         }
     } else if (publicOnly) {
         u4 count, newIdx, publicCount = 0;
-        ClassObject** pSource = (ClassObject**) classes->contents;
+        ClassObject** pSource = (ClassObject**)(void*)classes->contents;
         u4 length = classes->length;
 
         /* count up public classes */
similarity index 98%
rename from vm/native/java_lang_System.c
rename to vm/native/java_lang_System.cpp
index ad0b397..e6b2f1a 100644 (file)
@@ -51,7 +51,7 @@
 #endif
 
 #ifdef HAVE_MEMMOVE_WORDS
-extern void _memmove_words(void* dest, const void* src, size_t n);
+extern "C" void _memmove_words(void* dest, const void* src, size_t n);
 #define move16 _memmove_words
 #define move32 _memmove_words
 #else
@@ -252,8 +252,8 @@ static void Dalvik_java_lang_System_arraycopy(const u4* args, JValue* pResult)
             int copyCount;
             ClassObject*   clazz = NULL;
 
-            srcObj = ((Object**) srcArray->contents) + srcPos;
-            dstObj = ((Object**) dstArray->contents) + dstPos;
+            srcObj = ((Object**)(void*)srcArray->contents) + srcPos;
+            dstObj = ((Object**)(void*)dstArray->contents) + dstPos;
 
             if (length > 0 && srcObj[0] != NULL)
             {
similarity index 98%
rename from vm/native/java_lang_reflect_Array.c
rename to vm/native/java_lang_reflect_Array.cpp
index fe6647c..1de0ea1 100644 (file)
@@ -87,7 +87,7 @@ static void Dalvik_java_lang_reflect_Array_createMultiArray(const u4* args,
     numDim = dimArray->length;
     assert(numDim > 0 && numDim <= 255);
 
-    dimensions = (int*) dimArray->contents;
+    dimensions = (int*)(void*)dimArray->contents;
     for (i = 0; i < numDim; i++) {
         if (dimensions[i] < 0) {
             dvmThrowNegativeArraySizeException(dimensions[i]);
index 80e96fa..21523eb 100644 (file)
 #ifndef _DALVIK_REFLECT_REFLECT
 #define _DALVIK_REFLECT_REFLECT
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * During startup, validate the "box" classes, e.g. java/lang/Integer.
  */
@@ -260,4 +264,8 @@ bool dvmEncodedArrayIteratorHasNext(const EncodedArrayIterator* iterator);
 bool dvmEncodedArrayIteratorGetNext(EncodedArrayIterator* iterator,
         AnnotationValue* value);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_DALVIK_REFLECT_REFLECT*/