[vmkit-commits] [vmkit] r86467 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h include/mvm/GC/GC.h include/mvm/JIT.h include/mvm/Threads/Thread.h lib/JnJVM/Classpath/ClasspathVMRuntime.inc lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/VMCore/JavaThread.cpp lib/JnJVM/VMCore/JavaThread.h lib/JnJVM/VMCore/Jni.cpp lib/JnJVM/VMCore/Jnjvm.cpp lib/Mvm/CommonThread/Sigsegv.cpp lib/Mvm/CommonThread/ctthread.cpp lib/Mvm/Compiler/JIT.cpp lib/Mvm/Runtime/Object.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sun Nov 8 07:18:16 PST 2009


Author: geoffray
Date: Sun Nov  8 09:18:15 2009
New Revision: 86467

URL: http://llvm.org/viewvc/llvm-project?rev=86467&view=rev
Log:
Bugfixes for the chain of known frames and definitely move
to shared printBacktrace and scanStack functionalities between VMs.


Modified:
    vmkit/trunk/include/jnjvm/JnjvmModule.h
    vmkit/trunk/include/mvm/GC/GC.h
    vmkit/trunk/include/mvm/JIT.h
    vmkit/trunk/include/mvm/Threads/Thread.h
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.inc
    vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h
    vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/Mvm/CommonThread/Sigsegv.cpp
    vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
    vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
    vmkit/trunk/lib/Mvm/Runtime/Object.cpp

Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=86467&r1=86466&r2=86467&view=diff

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Sun Nov  8 09:18:15 2009
@@ -499,12 +499,6 @@
 
 };
 
-class JavaJITStackScanner : public mvm::JITStackScanner {
-public:
-  virtual llvm::GCFunctionInfo* IPToGCFunctionInfo(mvm::VirtualMachine* vm,
-                                                   void* ip);
-};
-
 class JavaJITMethodInfo : public mvm::JITMethodInfo {
 protected:
   JavaMethod* meth;
@@ -580,7 +574,7 @@
 #ifdef WITH_LLVM_GCC
   virtual mvm::StackScanner* createStackScanner() {
     if (useCooperativeGC())
-      return new JavaJITStackScanner();
+      return new mvm::PreciseStackScanner();
     
     return new mvm::UnpreciseStackScanner();
   }

Modified: vmkit/trunk/include/mvm/GC/GC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/GC/GC.h?rev=86467&r1=86466&r2=86467&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/GC/GC.h (original)
+++ vmkit/trunk/include/mvm/GC/GC.h Sun Nov  8 09:18:15 2009
@@ -67,7 +67,7 @@
   virtual void scanStack(mvm::Thread* th);
 };
 
-class CamlStackScanner : public StackScanner {
+class PreciseStackScanner : public StackScanner {
 public:
   virtual void scanStack(mvm::Thread* th);
 };

Modified: vmkit/trunk/include/mvm/JIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=86467&r1=86466&r2=86467&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Sun Nov  8 09:18:15 2009
@@ -202,13 +202,6 @@
    static const char* getHostTriple();
 };
 
-class JITStackScanner : public StackScanner {
-public:
-  virtual void scanStack(mvm::Thread* th);
-  virtual llvm::GCFunctionInfo* IPToGCFunctionInfo(VirtualMachine* vm,
-                                                   void* ip) = 0;
-};
-
 class JITMethodInfo : public MethodInfo {
   llvm::GCFunctionInfo* GCInfo;
 public:

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

==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Sun Nov  8 09:18:15 2009
@@ -336,10 +336,9 @@
     return cpt;
   }
 
-  /// printBacktraceAfterSignal - Print the backtrace during a signal
-  /// handler.
+  /// printBacktrace - Print the backtrace.
   ///
-  virtual void printBacktraceAfterSignal() {}
+  void printBacktrace();
 
   /// addresses - The list of return addresses which represent native/app cross
   /// calls.

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.inc?rev=86467&r1=86466&r2=86467&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.inc (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.inc Sun Nov  8 09:18:15 2009
@@ -98,14 +98,14 @@
     uint32 num = 0;
     uint32* old = 0;
     void* oldBuf = 0;
-    jmp_buf buf;
     mvm::KnownFrame Frame;
+    jmp_buf buf;
     
-    if (setjmp((jumpbuf_t)buf) == 0) {
+    if (setjmp(buf) == 0) {
       // Push an unmeaningful value in the addresses field to let the
       // stack consistent with Java frames/native frames.
       th->addresses.push_back(0);
-      jnjvmStartJNI(&num, &old, (void*)buf, &oldBuf, &Frame);
+      jnjvmStartJNI(&num, &old, (void*)&buf, &oldBuf, &Frame);
       onLoad(&vm->javavmEnv, res);
     }
 

Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=86467&r1=86466&r2=86467&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Sun Nov  8 09:18:15 2009
@@ -296,13 +296,6 @@
   return res;
 }
 
-llvm::GCFunctionInfo*
-JavaJITStackScanner::IPToGCFunctionInfo(mvm::VirtualMachine* vm, void* ip) {
-  mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-  JavaMethod* method = (JavaMethod*)MI->getMetaInfo();
-  return method->getInfo<LLVMMethodInfo>()->GCInfo;
-}
-
 // Helper function to run an executable with a JIT
 extern "C" int StartJnjvmWithJIT(int argc, char** argv, char* mainClass) {
   llvm::llvm_shutdown_obj X; 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp Sun Nov  8 09:18:15 2009
@@ -34,6 +34,7 @@
   state = StateRunning;
   pendingException = 0;
   internalPendingException = 0;
+  lastKnownFrame = 0;
   jniEnv = isolate->jniEnv;
   localJNIRefs = new JNILocalReferences();
   currentAddedReferences = 0;
@@ -311,76 +312,6 @@
   }
 }
 
-
-void JavaThread::printBacktrace() {
-  std::vector<void*>::iterator it = addresses.end();
-  Jnjvm* vm = getJVM();
-
-  assert((mvm::Thread::get() == this || waitOnSP()) &&
-         "No last sp on foreign thread");
-  
-  void** addr = mvm::Thread::get() == this ? (void**)FRAME_PTR() :
-                                             (void**)waitOnSP();
-  assert(addr && "No address to start with");
-
-  void** oldAddr = addr;
-
-  // Loop until we cross the first Java frame.
-  while (it != addresses.begin()) {
-    
-    --it;
-    // Until we hit the last Java frame.
-    do {
-      void* ip = FRAME_IP(addr);
-      mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-      MI->print(ip, addr);
-      oldAddr = addr;
-      addr = (void**)addr[0];
-    } while (oldAddr != (void**)*it && addr != (void**)*it);
-    
-    // Set the iterator to the next native -> Java call.
-    --it;
-
-    // See if we're from JNI.
-    if (*it == 0) {
-      --it;
-      addr = (void**)*it;
-      --it;
-      if (*it == 0) {
-        void* ip = FRAME_IP(addr);
-        mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-        MI->print(ip, addr);
-        addr = (void**)addr[0];
-        continue;
-      }
-    }
-
-    do {
-      void* ip = FRAME_IP(addr);
-      bool isStub = ((unsigned char*)ip)[0] == 0xCE;
-      if (isStub) ip = addr[2];
-      mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-      MI->print(ip, addr);
-      addr = (void**)addr[0];
-      // 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 (addr < baseSP && addr < addr[0]) {
-    void* ip = FRAME_IP(addr);
-    mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-    MI->print(ip, addr);
-    addr = (void**)addr[0];
-  }
-
-}
-
-void JavaThread::printBacktraceAfterSignal() {
-  printBacktrace();
-}
-
 JavaObject** JNILocalReferences::addJNIReference(JavaThread* th,
                                                  JavaObject* obj) {
   llvm_gcroot(obj, 0);

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h Sun Nov  8 09:18:15 2009
@@ -56,6 +56,7 @@
 
 #define END_JNI_EXCEPTION \
   } catch(...) { \
+    th->lastKnownFrame = th->lastKnownFrame->previousFrame; \
     th->endNative(); \
     th->addresses.pop_back(); \
     th->enterUncooperativeCode(SP); \
@@ -63,12 +64,14 @@
   }
 
 #define RETURN_FROM_JNI(a) {\
+  th->lastKnownFrame = th->lastKnownFrame->previousFrame; \
   th->endNative(); \
   th->addresses.pop_back(); \
   th->enterUncooperativeCode(SP); \
   return (a); } \
 
 #define RETURN_VOID_FROM_JNI {\
+  th->lastKnownFrame = th->lastKnownFrame->previousFrame; \
   th->endNative(); \
   th->addresses.pop_back(); \
   th->enterUncooperativeCode(SP); \
@@ -300,16 +303,6 @@
   ///
   void getJavaFrameContext(std::vector<void*>& context);
 
-  /// printBacktrace - Prints the backtrace of this thread.
-  ///
-  void printBacktrace() __attribute__ ((noinline));
-
-  /// printBacktraceAfterSignal - Prints the backtrace of this thread while
-  /// in a signal handler.
-  ///
-  virtual void printBacktraceAfterSignal() __attribute__ ((noinline));
-
-
 private:
   /// internalClearException - Clear the C++ and Java exceptions
   /// currently pending.

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp Sun Nov  8 09:18:15 2009
@@ -170,6 +170,7 @@
   
   th->endNative();
   th->addresses.pop_back();
+  th->lastKnownFrame = th->lastKnownFrame->previousFrame;
   th->enterUncooperativeCode(SP);
   th->throwFromJNI();
   

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sun Nov  8 09:18:15 2009
@@ -1422,7 +1422,7 @@
 public:
 #ifdef WITH_LLVM_GCC
   virtual mvm::StackScanner* createStackScanner() {
-    return new mvm::CamlStackScanner();
+    return new mvm::PreciseStackScanner();
   }
 #endif
 };

Modified: vmkit/trunk/lib/Mvm/CommonThread/Sigsegv.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/Sigsegv.cpp?rev=86467&r1=86466&r2=86467&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/Sigsegv.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/Sigsegv.cpp Sun Nov  8 09:18:15 2009
@@ -57,7 +57,7 @@
     fprintf(stderr, "I received a SIGSEGV: either the VM code or an external\n"
                     "native method is bogus. Aborting...\n");
   }
-  th->printBacktraceAfterSignal();
+  th->printBacktrace();
   abort();
   
 #if defined(__i386__)

Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=86467&r1=86466&r2=86467&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Sun Nov  8 09:18:15 2009
@@ -61,6 +61,31 @@
   addresses.push_back(cur);
 }
 
+void Thread::printBacktrace() {
+  VirtualMachine* vm = MyVM;
+  void** addr = mvm::Thread::get() == this ? (void**)FRAME_PTR() :
+                                             (void**)waitOnSP();
+  mvm::KnownFrame* currentKnownFrame = lastKnownFrame;
+  while (addr < baseSP && addr < addr[0]) {   
+    void* ip = FRAME_IP(addr);
+    mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
+    MI->print(ip, addr);
+    
+    if (currentKnownFrame && addr == currentKnownFrame->currentFP) {
+      currentKnownFrame = currentKnownFrame->previousFrame;
+      if  (currentKnownFrame) {
+        addr = (void**)currentKnownFrame->currentFP;
+        currentKnownFrame = currentKnownFrame->previousFrame;
+      } else {
+        addr = (void**)addr[0];
+      }
+    } else {
+      addr = (void**)addr[0];
+    }
+  }
+}
+
+
 uintptr_t Thread::baseAddr = 0;
 
 // These could be set at runtime.

Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=86467&r1=86466&r2=86467&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Sun Nov  8 09:18:15 2009
@@ -543,70 +543,6 @@
   }
 }
 
-void JITStackScanner::scanStack(mvm::Thread* th) {
-  std::vector<void*>::iterator it = th->addresses.end();
-  VirtualMachine* vm = th->MyVM;
-
-  void** addr = mvm::Thread::get() == th ? 
-    (void**)FRAME_PTR() : (void**)th->waitOnSP();
-  assert(addr && "No address to start with");
-  void** oldAddr = addr;
-  DEBUG(fprintf(stderr, "%p trace %p\n", (void*)mvm::Thread::get(), (void*)th));
-  DEBUG(th->printBacktraceAfterSignal());
-
-  // Loop until we cross the first Java frame.
-  while (it != th->addresses.begin()) {
-    
-    --it;
-    // Until we hit the last Java frame.
-    do {
-      void* ip = FRAME_IP(addr);
-      mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-      MI->scan(0, ip, addr);
-      oldAddr = addr;
-      addr = (void**)addr[0];
-    } while (oldAddr != (void**)*it && addr != (void**)*it);
-    
-    // Set the iterator to the next native -> Java call.
-    --it;
-
-    // See if we're from JNI.
-    if (*it == 0) {
-      --it;
-      addr = (void**)*it;
-      --it;
-      if (*it == 0) {
-        void* ip = FRAME_IP(addr);
-        mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-        MI->scan(0, ip, addr);
-        addr = (void**)addr[0];
-        continue;
-      }
-    }
-
-    do {
-      void* ip = FRAME_IP(addr);
-      bool isStub = ((unsigned char*)ip)[0] == 0xCE;
-      if (isStub) ip = addr[2];
-      mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-      MI->scan(0, ip, addr);
-      
-      addr = (void**)addr[0];
-      // 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 (addr < th->baseSP && addr < addr[0]) {
-    void* ip = FRAME_IP(addr);
-    mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-    MI->scan(0, ip, addr);
-    addr = (void**)addr[0];
-  }
-
-}
-
 void JITMethodInfo::scan(void* TL, void* ip, void* addr) {
   if (GCInfo) {
     DEBUG(llvm::errs() << GCInfo->getFunction().getName() << '\n');

Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=86467&r1=86466&r2=86467&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sun Nov  8 09:18:15 2009
@@ -261,64 +261,33 @@
   return free(obj); 
 }
 
-void CamlStackScanner::scanStack(mvm::Thread* th) {
+void PreciseStackScanner::scanStack(mvm::Thread* th) {
   VirtualMachine* vm = th->MyVM;
-  std::vector<void*>::iterator it = th->addresses.end();
+  
+  void** addr = mvm::Thread::get() == th ? 
+    (void**)FRAME_PTR() : (void**)th->waitOnSP();
+  assert(addr && "No address to start with");
 
-  void** addr = mvm::Thread::get() == th ? (void**)FRAME_PTR() :
-                                           (void**)th->waitOnSP();
-  void** oldAddr = addr;
-
-  // Loop until we cross the first Java frame.
-  while (it != th->addresses.begin()) {
-    
-    --it;
-    // Until we hit the last Java frame.
-    do {
-      void* ip = FRAME_IP(addr);
-      mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-      MI->scan(0, ip, addr);
-      oldAddr = addr;
-      addr = (void**)addr[0];
-    } while (oldAddr != (void**)*it && addr != (void**)*it);
+  mvm::KnownFrame* currentKnownFrame = th->lastKnownFrame;
+  while (addr < th->baseSP && addr < addr[0]) {   
+    void* ip = FRAME_IP(addr);
+    bool isStub = ((unsigned char*)ip)[0] == 0xCE;
+    if (isStub) ip = addr[2];
+    mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
+    MI->scan(0, ip, addr);
     
-    // Set the iterator to the next native -> Java call.
-    --it;
-
-    // See if we're from JNI.
-    if (*it == 0) {
-      --it;
-      addr = (void**)*it;
-      --it;
-      if (*it == 0) {
-        void* ip = FRAME_IP(addr);
-        mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-        MI->scan(0, ip, addr);
+    if (currentKnownFrame && addr == currentKnownFrame->currentFP) {
+      currentKnownFrame = currentKnownFrame->previousFrame;
+      if  (currentKnownFrame) {
+        addr = (void**)currentKnownFrame->currentFP;
+        currentKnownFrame = currentKnownFrame->previousFrame;
+      } else {
         addr = (void**)addr[0];
-        continue;
       }
-    }
-
-    do {
-      void* ip = FRAME_IP(addr);
-      bool isStub = ((unsigned char*)ip)[0] == 0xCE;
-      if (isStub) ip = addr[2];
-      mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-      MI->scan(0, ip, addr);
-      
+    } else {
       addr = (void**)addr[0];
-      // 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 (addr < th->baseSP && addr < addr[0]) {
-    void* ip = FRAME_IP(addr);
-    mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
-    MI->scan(0, ip, addr);
-    addr = (void**)addr[0];
-  }
+    }
+  }  
 }
 
 





More information about the vmkit-commits mailing list