[vmkit-commits] [vmkit] r86474 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h include/mvm/JIT.h include/mvm/MethodInfo.h lib/JnJVM/VMCore/JavaClass.h lib/JnJVM/VMCore/JavaThread.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sun Nov 8 08:17:32 PST 2009


Author: geoffray
Date: Sun Nov  8 10:17:32 2009
New Revision: 86474

URL: http://llvm.org/viewvc/llvm-project?rev=86474&view=rev
Log:
Use a magic value to differentiate Java MethodInfo from ohters.
TODO: make that cleaner.
And use the stack walker in some areas of JavaThread.


Modified:
    vmkit/trunk/include/jnjvm/JnjvmModule.h
    vmkit/trunk/include/mvm/JIT.h
    vmkit/trunk/include/mvm/MethodInfo.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp

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

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Sun Nov  8 10:17:32 2009
@@ -508,6 +508,7 @@
   JavaJITMethodInfo(llvm::GCFunctionInfo* GFI, JavaMethod* m) : 
     mvm::JITMethodInfo(GFI) {
     meth = m;
+    MethodType = 1;
   }
   
   virtual void* getMetaInfo() {

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

==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Sun Nov  8 10:17:32 2009
@@ -216,6 +216,7 @@
   MvmJITMethodInfo(llvm::GCFunctionInfo* GFI, const llvm::Function* F) :
     JITMethodInfo(GFI) {
       Func = F;
+      MethodType = 0;
   }
 };
 

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

==============================================================================
--- vmkit/trunk/include/mvm/MethodInfo.h (original)
+++ vmkit/trunk/include/mvm/MethodInfo.h Sun Nov  8 10:17:32 2009
@@ -30,6 +30,9 @@
     abort();
     return NULL;
   }
+
+  unsigned MethodType;
+
 };
 
 class CamlFrame {
@@ -54,6 +57,7 @@
   StaticCamlMethodInfo(CamlFrame* CF, void* ip, const char* n) :
     CamlMethodInfo(CF, ip) {
     name = n;
+    MethodType = 0;
   }
 };
 
@@ -62,6 +66,10 @@
   virtual void print(void* ip, void* addr);
   virtual void scan(void* TL, void* ip, void* addr);
   static DefaultMethodInfo DM;
+    
+  DefaultMethodInfo() {
+    MethodType = -1;
+  }
 };
 
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sun Nov  8 10:17:32 2009
@@ -961,6 +961,7 @@
   JavaStaticMethodInfo(mvm::CamlFrame* CF, void* ip, JavaMethod* M) :
     mvm::CamlMethodInfo(CF, ip) {
     meth = M;
+    MethodType = 1;
   }
 
   virtual void* getMetaInfo() {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp Sun Nov  8 10:17:32 2009
@@ -110,18 +110,6 @@
   addresses.push_back(cur);
 }
 
-JavaMethod* JavaThread::getCallingMethod() {
-  // I'm a native function, so try to look at the last Java method.
-  // First take the last caller.
-  void** addr = (void**)addresses.back();
-  
-  // Get the IP of the caller.
-  void* ip = FRAME_IP(addr);
-
-  mvm::MethodInfo* meth = getJVM()->IPToMethodInfo(ip);
-
-  return (JavaMethod*)meth->getMetaInfo();
-}
 
 UserClass* JavaThread::getCallingClass(uint32 level) {
   // I'm a native function, so try to look at the last Java method.
@@ -141,39 +129,25 @@
 
   return meth->classDef;
 }
-  
-UserClass* JavaThread::getCallingClassFromJNI() {
-  std::vector<void*>::iterator it = addresses.end();
 
-  // Loop until we cross the first Java frame.
-  while (it != addresses.begin()) {
-    
-    // Get the last Java frame.
-    void** 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) {
-        addr = (void**)addr[0];
-        continue;
-      }
-    }
+JavaMethod* JavaThread::getCallingMethod() {
+  mvm::StackWalker Walker(this);
 
-    void* ip = FRAME_IP(addr);
-    bool isStub = ((unsigned char*)ip)[0] == 0xCE;
-    if (isStub) ip = addr[2];
-    mvm::MethodInfo* MI = getJVM()->IPToMethodInfo(ip);
-    JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
-    return meth->classDef;
+  while (mvm::MethodInfo* MI = Walker.get()) {
+    if (MI->MethodType == 1) {
+      JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
+      return meth;
+    }
+    ++Walker;
   }
   return 0;
 }
+  
+UserClass* JavaThread::getCallingClassFromJNI() {
+  JavaMethod* meth = getCallingMethod();
+  if (meth) return meth->classDef;
+  return 0;
+}
 
 void JavaThread::getJavaFrameContext(std::vector<void*>& context) {
   std::vector<void*>::iterator it = addresses.end();
@@ -212,44 +186,18 @@
 }
 
 UserClass* JavaThread::getCallingClassLevel(uint32 level) {
-  std::vector<void*>::iterator it = addresses.end();
+  mvm::StackWalker Walker(this);
   uint32 index = 0;
 
-  // Loop until we cross the first Java frame.
-  while (it != addresses.begin()) {
-    
-    // Get the last Java frame.
-    void** 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) {
-        addr = (void**)addr[0];
-        continue;
-      }
-    }
-
-    do {
-      void* ip = FRAME_IP(addr);
-      bool isStub = ((unsigned char*)ip)[0] == 0xCE;
-      if (isStub) ip = addr[2];
+  while (mvm::MethodInfo* MI = Walker.get()) {
+    if (MI->MethodType == 1) {
       if (index == level) {
-        mvm::MethodInfo* MI = getJVM()->IPToMethodInfo(ip);
         JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
         return meth->classDef;
       }
-      addr = (void**)addr[0];
       ++index;
-      // 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);
+    }
+    ++Walker;
   }
   return 0;
 }
@@ -258,57 +206,29 @@
   
   JavaObject* obj = 0;
   llvm_gcroot(obj, 0);
+  
+  mvm::StackWalker Walker(this);
 
-  std::vector<void*>::iterator it = addresses.end();
-
-  // Loop until we cross the first Java frame.
-  while (it != addresses.begin()) {
-    
-    // Get the last Java frame.
-    void** 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) {
-        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 = getJVM()->IPToMethodInfo(ip);
+  while (mvm::MethodInfo* MI = Walker.get()) {
+    if (MI->MethodType == 1) {
       JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
       JnjvmClassLoader* loader = meth->classDef->classLoader;
       obj = loader->getJavaClassLoader();
       if (obj) return obj;
-      addr = (void**)addr[0];
-      // 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);
+    }
+    ++Walker;
   }
-
   return 0;
 }
 
 
 void JavaThread::printJavaBacktrace() {
-  Jnjvm* vm = getJVM();
-  std::vector<void*> vals;
-  getJavaFrameContext(vals);
-  for (std::vector<void*>::iterator i = vals.begin(), e = vals.end(); 
-       i != e; ++i) {
-    mvm::MethodInfo* MI = vm->IPToMethodInfo(*i);
-    MI->print(*i, 0);
+  mvm::StackWalker Walker(this);
+
+  while (mvm::MethodInfo* MI = Walker.get()) {
+    if (MI->MethodType == 1)
+      MI->print(Walker.ip, Walker.addr);
+    ++Walker;
   }
 }
 





More information about the vmkit-commits mailing list