[vmkit-commits] [vmkit] r63134 - in /vmkit/trunk: include/mvm/Threads/Thread.h lib/JnJVM/Classpath/ClasspathConstructor.cpp lib/JnJVM/Classpath/ClasspathField.cpp lib/JnJVM/Classpath/ClasspathMethod.cpp lib/JnJVM/Classpath/ClasspathVMThrowable.cpp lib/JnJVM/VMCore/JavaThread.cpp lib/JnJVM/VMCore/JavaUpcalls.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Jan 27 13:24:02 PST 2009


Author: geoffray
Date: Tue Jan 27 15:24:02 2009
New Revision: 63134

URL: http://llvm.org/viewvc/llvm-project?rev=63134&view=rev
Log:
Better stack trace handling: our previous implementation relied on x86 getting
the caller frame address not the current frame address.


Modified:
    vmkit/trunk/include/mvm/Threads/Thread.h
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathField.cpp
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp

Modified: vmkit/trunk/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=63134&r1=63133&r2=63134&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Tue Jan 27 15:24:02 2009
@@ -79,12 +79,21 @@
 };
 
 
-#if defined(__MACH__) && !defined(__i386__)
+#if defined(__MACH__) && defined(__PPC__)
 #define FRAME_IP(fp) (fp[2])
 #else
 #define FRAME_IP(fp) (fp[1])
 #endif
 
+// Apparently gcc for i386 and family considers __builtin_frame_address(0) to
+// return the caller, not the current function.
+#if defined(__i386__) || defined(i386) || defined(_M_IX86) || \
+    defined(__x86_64__) || defined(_M_AMD64)
+#define FRAME_PTR() __builtin_frame_address(0)
+#else
+#define FRAME_PTR() (((void**)__builtin_frame_address(0))[0])
+#endif
+
 /// Thread - This class is the base of custom virtual machines' Thread classes.
 /// It provides static functions to manage threads. An instance of this class
 /// contains all thread-specific informations.

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp?rev=63134&r1=63133&r2=63134&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp Tue Jan 27 15:24:02 2009
@@ -73,7 +73,6 @@
 
   jobject res = 0;
 
-  BEGIN_NATIVE_EXCEPTION(0)
   
   Jnjvm* vm = JavaThread::get()->getJVM();
   JavaMethod* meth = cons->getInternalMethod();
@@ -83,9 +82,12 @@
   sint32 size = sign->nbArguments;
 
   // Allocate a buffer to store the arguments.
-  uintptr_t buf = (uintptr_t)alloca(size * sizeof(uint64));
+  uintptr_t buf = size ? (uintptr_t)alloca(size * sizeof(uint64)) : 0;
   // Record the beginning of the buffer.
   void* startBuf = (void*)buf;
+  
+  // Do it after alloca
+  BEGIN_NATIVE_EXCEPTION(0)
 
   if (nbArgs == size) {
     UserCommonClass* _cl = 

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathField.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathField.cpp?rev=63134&r1=63133&r2=63134&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathField.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathField.cpp Tue Jan 27 15:24:02 2009
@@ -502,12 +502,15 @@
 #endif
 JavaObjectField* Field, jobject obj, jobject val) {
   
-  BEGIN_NATIVE_EXCEPTION(0)
   
   Jnjvm* vm = JavaThread::get()->getJVM();
   UserClass* cl = Field->getClass();
   JavaField* field = Field->getInternalField();
   uintptr_t buf = (uintptr_t)alloca(sizeof(uint64));
+  
+  // Do it after alloca
+  BEGIN_NATIVE_EXCEPTION(0)
+  
   void* _buf = (void*)buf;
   const Typedef* type = field->getSignature();
   ((JavaObject*)val)->decapsulePrimitive(vm, buf, type);

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp?rev=63134&r1=63133&r2=63134&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp Tue Jan 27 15:24:02 2009
@@ -93,7 +93,6 @@
   
   JavaObject* res = 0;
 
-  BEGIN_NATIVE_EXCEPTION(0)
 
   Jnjvm* vm = JavaThread::get()->getJVM();
 
@@ -105,7 +104,10 @@
   sint32 size = sign->nbArguments;
   JavaObject* obj = (JavaObject*)_obj;
 
-  uintptr_t buf = (uintptr_t)alloca(size * sizeof(uint64)); 
+  uintptr_t buf = size ? (uintptr_t)alloca(size * sizeof(uint64)) : 0;
+  
+  BEGIN_NATIVE_EXCEPTION(0)
+
   void* _buf = (void*)buf;
   if (nbArgs == size) {
     UserCommonClass* _cl = 

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp?rev=63134&r1=63133&r2=63134&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp Tue Jan 27 15:24:02 2009
@@ -103,7 +103,9 @@
     field->getObjectField((JavaObject*)vmthrow);
   
   std::vector<void*>::iterator i = stack->begin(), e = stack->end();
-  uint32 index = 0;
+  // remove the VMThrowable.fillInStackTrace method
+  uint32 index = 1;
+  ++i;
   while (i != e) {
     JavaMethod* meth = vm->IPToMethod<JavaMethod>(*i);
     assert(meth && "Wrong stack trace");

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp?rev=63134&r1=63133&r2=63134&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp Tue Jan 27 15:24:02 2009
@@ -72,12 +72,11 @@
 }
 
 void JavaThread::startNative(int level) {
-  // Call to this function.
-  void** cur = (void**)__builtin_frame_address(0);
+  // Caller of this function.
+  void** cur = (void**)FRAME_PTR();
   
-  // Caller (for native Classpath functions).
-  //if (level)
-  cur = (void**)cur[0];
+  while (level--)
+    cur = (void**)cur[0];
 
   // When entering, the number of addresses should be odd.
   // Enable this when finalization gets proper support.
@@ -87,21 +86,21 @@
 }
 
 void JavaThread::startJava() {
-  // Call to this function.
-  void** cur = (void**)__builtin_frame_address(0);
+  // Caller of this function.
+  void** cur = (void**)FRAME_PTR();
   
-  // Caller in JavaMetaJIT.cpp
-  cur = (void**)cur[0];
-
   addresses.push_back(cur);
 }
 
 UserClass* JavaThread::getCallingClass(uint32 level) {
   // I'm a native function, so try to look at the last Java method.
-  // First Get the caller of this method.
+  // First take the getCallingClass address.
   void** addr = (void**)addresses.back();
+  
+  // Caller of getCallingClass.
+  addr = (void**)addr[0];
 
-  // Get the caller of the Java getCallingClass method.
+  // Get the caller of the caller of the Java getCallingClass method.
   if (level)
     addr = (void**)addr[0];
   void* ip = FRAME_IP(addr);
@@ -130,7 +129,7 @@
       // We end walking the stack when we cross a native -> Java call. Here
       // the iterator points to a native -> Java call. We dereference addr twice
       // because a native -> Java call always contains the signature function.
-    } while (((void***)addr)[0][0] != *it);
+    } while (((void***)addr)[0] != *it);
   }
 }
 
@@ -158,7 +157,7 @@
       // We end walking the stack when we cross a native -> Java call. Here
       // the iterator points to a native -> Java call. We dereference addr twice
       // because a native -> Java call always contains the signature function.
-    } while (((void***)addr)[0][0] != *it);
+    } while (((void***)addr)[0] != *it);
   }
   return 0;
 }
@@ -185,7 +184,7 @@
       // We end walking the stack when we cross a native -> Java call. Here
       // the iterator points to a native -> Java call. We dereference addr twice
       // because a native -> Java call always contains the signature function.
-    } while (((void***)addr)[0][0] != *it);
+    } while (((void***)addr)[0] != *it);
   }
 
   return 0;
@@ -221,7 +220,7 @@
   std::vector<void*>::iterator it = addresses.end();
   Jnjvm* vm = getJVM();
 
-  void** addr = (void**)__builtin_frame_address(0);
+  void** addr = (void**)FRAME_PTR();
 
   // Loop until we cross the first Java frame.
   while (it != addresses.begin()) {
@@ -246,7 +245,7 @@
       // End walking the stack when we cross a native -> Java call. Here
       // the iterator points to a native -> Java call. We dereference addr twice
       // because a native -> Java call always contains the signature function.
-    } while (((void***)addr)[0][0] != *it);
+    } while (((void***)addr)[0] != *it);
   }
 
   while (addr < baseSP && addr < addr[0]) {

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=63134&r1=63133&r2=63134&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Tue Jan 27 15:24:02 2009
@@ -294,7 +294,7 @@
   BEGIN_NATIVE_EXCEPTION(0)
   JavaThread* th = JavaThread::get();
   Jnjvm* vm = th->getJVM();
-  UserClass* cl = th->getCallingClassLevel(index - 1);
+  UserClass* cl = th->getCallingClassLevel(index);
   if (cl) res = cl->getClassDelegatee(vm);
   END_NATIVE_EXCEPTION
 





More information about the vmkit-commits mailing list