#ifndef _LIBDEX_CMDUTILS
#define _LIBDEX_CMDUTILS
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* encode the result of unzipping to a file */
typedef enum UnzipToFileResult {
kUTFRSuccess = 0,
UnzipToFileResult dexUnzipToFile(const char* zipFileName,
const char* outFileName, bool quiet);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*_LIBDEX_CMDUTILS*/
#include "DexFile.h"
#include "Leb128.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Catch handler entry, used while iterating over catch_handler_items.
*/
}
}
+#ifdef __cplusplus
+}
+#endif
+
#endif
#include "DexFile.h"
#include "Leb128.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* expanded form of a class_data_item header */
typedef struct DexClassDataHeader {
u4 staticFieldsSize;
*lastIndex = index;
}
+#ifdef __cplusplus
+}
+#endif
+
#endif
#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 */
return dexDataMapVerify(map, offset, type);
}
+#ifdef __cplusplus
+}
+#endif
+
#endif /*_LIBDEX_DEXDATAMAP*/
#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
*/
PrimitiveType dexGetPrimitiveTypeFromDescriptorChar(char descriptorChar);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*_LIBDEX_DEXFILE*/
#include "DexFile.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* kMaxOpcodeValue: the highest possible raw (unpacked) opcode value
*
*/
const char* dexGetOpcodeName(Opcode op);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*_LIBDEX_DEXOPCODES*/
#include "libdex/DexFile.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Parse the optimized data tables in the given dex file.
*
*/
u4 dexComputeOptChecksum(const DexOptHeader* pOptHeader);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* def _LIBDEX_DEXOPTDATA */
#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
const char* dexParameterIteratorNextDescriptor(
DexParameterIterator* pIterator);
-
+#ifdef __cplusplus
+}
+#endif
#endif /*_LIBDEX_DEXPROTO*/
#include "DexFile.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Retrieve the next UTF-16 character from a UTF-8 string.
*
* is for anything but "void". */
bool dexIsFieldDescriptor(const char* s);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* def _LIBDEX_DEXUTF */
#include "DexFile.h"
#include "DexOpcodes.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Possible instruction formats associated with Dalvik opcodes.
*
*/
void dexDecodeInstruction(const u2* insns, DecodedInstruction* pDec);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*_LIBDEX_INSTRUTILS*/
#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
return count;
}
+#ifdef __cplusplus
+}
+#endif
+
#endif
#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
u4 dexInitCrc32(void);
u4 dexComputeCrc32(u4 crc, const void* buf, size_t len);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*_LIBDEX_ZIPARCHIVE*/
#ifndef _DALVIK_SHA1
#define _DALVIK_SHA1
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct {
unsigned long state[5];
unsigned long count[2];
unsigned long len);
void SHA1Final(unsigned char digest[HASHSIZE], SHA1_CTX* context);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*_DALVIK_SHA1*/
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 \
dalvik \
dalvik/vm \
external/zlib \
+ libcore/include \
$(KERNEL_HEADERS)
-
ifeq ($(dvm_simulator),true)
LOCAL_LDLIBS += -lpthread -ldl
ifeq ($(HOST_OS),linux)
*/
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
len1 * sizeof(u2));
}
-ArrayObject* dvmCreateStringArray(char** strings, size_t count)
+ArrayObject* dvmCreateStringArray(const char** strings, size_t count)
{
Thread* self = dvmThreadSelf();
*
* 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.
}
/*
- * 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;
}
/*
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.
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);
#include "native/InternalNativePriv.h"
#include "hprof/Hprof.h"
-#include <cutils/array.h>
#include <string.h>
#include <unistd.h>
-#include <errno.h>
/*
* 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 {
ArrayObject* countArray = (ArrayObject*) args[0];
if (countArray != NULL) {
- int* storage = (int*) countArray->contents;
+ int* storage = (int*)(void*)countArray->contents;
u4 length = countArray->length;
/*
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());
* dalvik.system.VMStack
*/
#include "Dalvik.h"
+#include "UniquePtr.h"
#include "native/InternalNativePriv.h"
-
/*
* public static ClassLoader getCallingClassLoader()
*
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;
* 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);
}
/* 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];
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) {
}
} 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 */
#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
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)
{
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]);
#ifndef _DALVIK_REFLECT_REFLECT
#define _DALVIK_REFLECT_REFLECT
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* During startup, validate the "box" classes, e.g. java/lang/Integer.
*/
bool dvmEncodedArrayIteratorGetNext(EncodedArrayIterator* iterator,
AnnotationValue* value);
+#ifdef __cplusplus
+}
+#endif
+
#endif /*_DALVIK_REFLECT_REFLECT*/