X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=vm%2FMisc.h;h=4c425760d1816080647d49cdc1476ac62865b7ec;hb=c5d0614f778e0f26db913fdc7320f08e9417e984;hp=4dc983ecad000d8a4f57da2a04c2caafaa370d8b;hpb=069d9de889ab4b1edc54d1a39e0579018d269c82;p=android-x86%2Fdalvik.git diff --git a/vm/Misc.h b/vm/Misc.h index 4dc983eca..4c425760d 100644 --- a/vm/Misc.h +++ b/vm/Misc.h @@ -17,15 +17,18 @@ /* * Miscellaneous utility functions. */ -#ifndef _DALVIK_MISC -#define _DALVIK_MISC +#ifndef DALVIK_MISC_H_ +#define DALVIK_MISC_H_ -#include "Inlines.h" +#include +#include #include #include #include +#include "Inlines.h" + /* * Used to shut up the compiler when a parameter isn't used. */ @@ -64,7 +67,7 @@ INLINE u4 dvmFloatToU4(float val) { * * If "tag" is NULL the default tag ("dalvikvm") will be used. */ -typedef enum { kHexDumpLocal, kHexDumpMem } HexDumpMode; +enum HexDumpMode { kHexDumpLocal, kHexDumpMem }; void dvmPrintHexDumpEx(int priority, const char* tag, const void* vaddr, size_t length, HexDumpMode mode); @@ -87,17 +90,19 @@ INLINE void dvmPrintHexDumpDbg(const void* vaddr, size_t length,const char* tag) #endif } +enum DebugTargetKind { + kDebugTargetUnknown = 0, + kDebugTargetLog, + kDebugTargetFile, +}; + /* * We pass one of these around when we want code to be able to write debug * info to either the log or to a file (or stdout/stderr). */ -typedef struct DebugOutputTarget { +struct DebugOutputTarget { /* where to? */ - enum { - kDebugTargetUnknown = 0, - kDebugTargetLog, - kDebugTargetFile, - } which; + DebugTargetKind which; /* additional bits */ union { @@ -109,7 +114,7 @@ typedef struct DebugOutputTarget { FILE* fp; } file; } data; -} DebugOutputTarget; +}; /* * Fill in a DebugOutputTarget struct. @@ -140,7 +145,28 @@ char* dvmDotToSlash(const char* str); * of 'descriptor'. So "I" would be "int", "[[I" would be "int[][]", * "[Ljava/lang/String;" would be "java.lang.String[]", and so forth. */ -char* dvmHumanReadableDescriptor(const char* descriptor); +std::string dvmHumanReadableDescriptor(const char* descriptor); + +/** + * Returns a human-readable string form of the name of the class of + * the given object. So given a java.lang.String, the output would + * be "java.lang.String". Given an array of int, the output would be "int[]". + * Given String.class, the output would be "java.lang.Class". + */ +std::string dvmHumanReadableType(const Object* obj); + +/** + * Returns a human-readable string of the form "package.Class.fieldName". + */ +struct Field; +std::string dvmHumanReadableField(const Field* field); + +/** + * Returns a human-readable string of the form "package.Class.methodName" + * or "package.Class.methodName(Ljava/lang/String;I)V". + */ +struct Method; +std::string dvmHumanReadableMethod(const Method* method, bool withSignature); /* * Return a newly-allocated string for the "dot version" of the class @@ -255,11 +281,12 @@ bool dvmSetCloseOnExec(int fd); * get from the abort may point at the wrong call site. Best to leave * it undecorated. */ -void dvmAbort(void); +extern "C" void dvmAbort(void); +void dvmPrintNativeBackTrace(void); #if (!HAVE_STRLCPY) /* Implementation of strlcpy() for platforms that don't already have it. */ -size_t strlcpy(char *dst, const char *src, size_t size); +extern "C" size_t strlcpy(char *dst, const char *src, size_t size); #endif /* @@ -272,11 +299,12 @@ void *dvmAllocRegion(size_t size, int prot, const char *name); /* * Get some per-thread stats from /proc/self/task/N/stat. */ -typedef struct { +struct ProcStatData { + char state; /* process state, e.g. 'R', 'S', 'D' */ unsigned long utime; /* number of jiffies scheduled in user mode */ unsigned long stime; /* number of jiffies scheduled in kernel mode */ int processor; /* number of CPU that last executed thread */ -} ProcStatData; +}; bool dvmGetThreadStats(ProcStatData* pData, pid_t tid); /* @@ -298,4 +326,21 @@ bool dvmGetThreadStats(ProcStatData* pData, pid_t tid); */ const char* dvmPathToAbsolutePortion(const char* path); -#endif /*_DALVIK_MISC*/ +/** + * Returns a string corresponding to printf-like formatting of the arguments. + */ +std::string StringPrintf(const char* fmt, ...) + __attribute__((__format__ (__printf__, 1, 2))); + +/** + * Appends a printf-like formatting of the arguments to 'dst'. + */ +void StringAppendF(std::string* dst, const char* fmt, ...) + __attribute__((__format__ (__printf__, 2, 3))); + +/** + * Appends a printf-like formatting of the arguments to 'dst'. + */ +void StringAppendV(std::string* dst, const char* format, va_list ap); + +#endif // DALVIK_MISC_H_