[llvm-commits] [vmkit] r50643 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathVMStackWalker.cpp Classpath/ClasspathVMThrowable.cpp VMCore/JavaBacktrace.cpp VMCore/JavaJIT.h
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Mon May 5 05:33:28 PDT 2008
Author: geoffray
Date: Mon May 5 07:33:18 2008
New Revision: 50643
URL: http://llvm.org/viewvc/llvm-project?rev=50643&view=rev
Log:
Implement a glibc-like backtrace function.
Modified:
vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp
vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaBacktrace.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h
Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp?rev=50643&r1=50642&r2=50643&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp Mon May 5 07:33:18 2008
@@ -8,7 +8,6 @@
//
//===----------------------------------------------------------------------===//
-#include <execinfo.h>
#include <string.h>
#include "types.h"
@@ -52,7 +51,7 @@
#endif
) {
int* ips[100];
- int real_size = backtrace((void**)(void*)ips, 100);
+ int real_size = JavaJIT::getBacktrace((void**)(void*)ips, 100);
int i = 0;
int first = 0;
CommonClass* cl = Classpath::vmStackWalker;
Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp?rev=50643&r1=50642&r2=50643&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp Mon May 5 07:33:18 2008
@@ -27,11 +27,8 @@
#include "NativeUtil.h"
#include "Reader.h"
-#include <execinfo.h>
-
using namespace jnjvm;
-extern "C" int backtrace_fp(int** ips, int size, int**);
extern "C" JavaMethod* ip_to_meth(int* ip);
extern "C" {
@@ -44,13 +41,11 @@
jobject throwable) {
//int** fp = (int**)__builtin_frame_address(0);
Jnjvm* vm = JavaThread::get()->isolate;
- int** stack = (int**)alloca(sizeof(int*) * 100);
- int real_size = backtrace((void**)stack, 100);
- ArrayUInt32* obj = ArrayUInt32::acons(real_size, JavaArray::ofInt, vm);
- memcpy(obj->elements, stack, real_size * sizeof(int));
- JavaObject* vmThrowable = (*Classpath::newVMThrowable)(vm);
- Classpath::initVMThrowable->invokeIntSpecial(vm, vmThrowable);
- (*Classpath::vmDataVMThrowable)(vmThrowable, obj);
+ int** stack = (int**)malloc(sizeof(int*) * 100);
+ int real_size = JavaJIT::getBacktrace((void**)stack, 100);
+ stack[real_size] = 0;
+ JavaObject* vmThrowable = Classpath::newVMThrowable->doNew(vm);
+ ((JavaObject**)((uint64)vmThrowable + Classpath::vmDataVMThrowable->ptrOffset))[0] = (JavaObject*)stack;
return (jobject)vmThrowable;
}
@@ -80,9 +75,9 @@
return res;
}
-ArrayObject* recGetStackTrace(int** stack, uint32 size, uint32 first, uint32 rec) {
+ArrayObject* recGetStackTrace(int** stack, uint32 first, uint32 rec) {
Jnjvm* vm = JavaThread::get()->isolate;
- if (size != first) {
+ if (stack[first] != 0) {
#ifdef MULTIPLE_GC
int *begIp = (int*)mvm::Thread::get()->GC->begOf(stack[first]);
#else
@@ -90,11 +85,11 @@
#endif
JavaMethod* meth = ip_to_meth(begIp);
if (meth) {
- ArrayObject* res = recGetStackTrace(stack, size, first + 1, rec + 1);
+ ArrayObject* res = recGetStackTrace(stack, first + 1, rec + 1);
res->setAt(rec, consStackElement(meth, stack[first]));
return res;
} else {
- return recGetStackTrace(stack, size, first + 1, rec);
+ return recGetStackTrace(stack, first + 1, rec);
}
} else {
return ArrayObject::acons(rec, JavaArray::ofObject, vm);
@@ -106,13 +101,12 @@
JNIEnv *env,
#endif
jobject vmthrow, jobject throwable) {
- ArrayUInt32* array = (ArrayUInt32*)(*Classpath::vmDataVMThrowable)((JavaObject*)vmthrow).PointerVal;
- uint32* stack = array->elements;
+ int** stack = (int**)(ArrayUInt32*)(*Classpath::vmDataVMThrowable)((JavaObject*)vmthrow).PointerVal;
CommonClass* cl = ((JavaObject*)throwable)->classOf;
uint32 first = 0;
sint32 i = 0;
- while (i < array->size) {
+ while (stack[i] != 0) {
#ifdef MULTIPLE_GC
int *begIp = (int*)mvm::Thread::get()->GC->begOf((void*)stack[i++]);
#else
@@ -124,7 +118,8 @@
break;
}
}
- return (jobject)recGetStackTrace((int**)(uint32**)stack, array->size, first, 0);
+ free(stack);
+ return (jobject)recGetStackTrace((int**)(uint32**)stack, first, 0);
}
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaBacktrace.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaBacktrace.cpp?rev=50643&r1=50642&r2=50643&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaBacktrace.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaBacktrace.cpp Mon May 5 07:33:18 2008
@@ -9,7 +9,6 @@
#include <stdio.h>
#include <dlfcn.h>
-#include <execinfo.h>
#include "llvm/Function.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
@@ -38,9 +37,26 @@
return 0;
}
+#if defined(__MACH__) && !defined(__i386__)
+#define FRAME_IP(fp) (fp[2])
+#else
+#define FRAME_IP(fp) (fp[1])
+#endif
+
+
+int JavaJIT::getBacktrace(void** stack, int size) {
+ void** blah = (void**)__builtin_frame_address(1);
+ int cpt = 0;
+ while (blah && cpt < size) {
+ stack[cpt++] = (void**)FRAME_IP(blah);
+ blah = (void**)blah[0];
+ }
+ return cpt;
+}
+
void JavaJIT::printBacktrace() {
int* ips[100];
- int real_size = backtrace((void**)(void*)ips, 100);
+ int real_size = getBacktrace((void**)(void*)ips, 100);
int n = 0;
while (n < real_size) {
mvm::Code* code = mvm::Code::getCodeFromPointer(ips[n++]);
@@ -72,7 +88,7 @@
Class* JavaJIT::getCallingClass() {
int* ips[10];
- int real_size = backtrace((void**)(void*)ips, 10);
+ int real_size = getBacktrace((void**)(void*)ips, 10);
int n = 0;
int i = 0;
while (n < real_size) {
@@ -94,7 +110,7 @@
Class* JavaJIT::getCallingClassWalker() {
int* ips[10];
- int real_size = backtrace((void**)(void*)ips, 10);
+ int real_size = getBacktrace((void**)(void*)ips, 10);
int n = 0;
int i = 0;
while (n < real_size) {
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h?rev=50643&r1=50642&r2=50643&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h Mon May 5 07:33:18 2008
@@ -276,6 +276,7 @@
static Class* getCallingClassWalker();
static JavaObject* getCallingClassLoader();
static void printBacktrace();
+ static int getBacktrace(void** array, int size);
#ifdef WITH_TRACER
static llvm::Function* markAndTraceLLVM;
More information about the llvm-commits
mailing list