[vmkit-commits] [vmkit] r86373 - in /vmkit/trunk: include/jnjvm/ include/mvm/ include/mvm/GC/ lib/JnJVM/Classpath/ lib/JnJVM/Compiler/ lib/JnJVM/VMCore/ lib/Mvm/Compiler/ lib/Mvm/Runtime/

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sat Nov 7 04:30:45 PST 2009


Author: geoffray
Date: Sat Nov  7 06:30:44 2009
New Revision: 86373

URL: http://llvm.org/viewvc/llvm-project?rev=86373&view=rev
Log:
Add a MethodInfo class. Instances of this class are stored
in maps that match instruction pointer addresses.


Added:
    vmkit/trunk/include/mvm/MethodInfo.h
    vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp
Modified:
    vmkit/trunk/include/jnjvm/JnjvmModule.h
    vmkit/trunk/include/mvm/GC/GC.h
    vmkit/trunk/include/mvm/JIT.h
    vmkit/trunk/include/mvm/VirtualMachine.h
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.inc
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.inc
    vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.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=86373&r1=86372&r2=86373&view=diff

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Sat Nov  7 06:30:44 2009
@@ -505,6 +505,23 @@
                                                    void* ip);
 };
 
+class JavaJITMethodInfo : public mvm::JITMethodInfo {
+protected:
+  JavaMethod* meth;
+public:
+  virtual void print(void* ip, void* addr);
+  
+  JavaJITMethodInfo(llvm::GCFunctionInfo* GFI, JavaMethod* m) : 
+    mvm::JITMethodInfo(GFI) {
+    meth = m;
+  }
+  
+  virtual void* getMetaInfo() {
+    return meth;
+  }
+
+};
+
 class JavaJITCompiler : public JavaLLVMCompiler {
 public:
 

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

==============================================================================
--- vmkit/trunk/include/mvm/GC/GC.h (original)
+++ vmkit/trunk/include/mvm/GC/GC.h Sat Nov  7 06:30:44 2009
@@ -61,20 +61,21 @@
   }
 };
 
-typedef struct {
+class CamlFrame {
+public:
   void* ReturnAddress;
   uint16_t FrameSize;
   uint16_t NumLiveOffsets;
   int16_t LiveOffsets[1];
-} camlframe;
+};
 
 class StaticGCMap {
 public:
   std::map<void*, void*> GCInfos;
 
   StaticGCMap() {
-    camlframe* currentFrame =
-      (camlframe*)dlsym(SELF_HANDLE, "camlVmkitoptimized__frametable");
+    CamlFrame* currentFrame =
+      (CamlFrame*)dlsym(SELF_HANDLE, "camlVmkitoptimized__frametable");
     
     if (currentFrame) {
       while (true) {
@@ -83,7 +84,7 @@
         GCInfos.insert(std::make_pair(currentFrame->ReturnAddress,
                                     currentFrame));
     
-        currentFrame = (camlframe*) ((char*)currentFrame + 
+        currentFrame = (CamlFrame*) ((char*)currentFrame + 
           (currentFrame->NumLiveOffsets % 2) * sizeof(uint16_t) +
           currentFrame->NumLiveOffsets * sizeof(uint16_t) +
           sizeof(void*) + sizeof(uint16_t) + sizeof(uint16_t));

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

==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Sat Nov  7 06:30:44 2009
@@ -18,6 +18,7 @@
 
 #include "llvm/Target/TargetMachine.h"
 
+#include "mvm/MethodInfo.h"
 #include "mvm/GC/GC.h"
 
 namespace llvm {
@@ -180,7 +181,8 @@
    static llvm::ExistingModuleProvider *globalModuleProvider;
    static llvm::FunctionPassManager* globalFunctionPasses;
    static const llvm::TargetData* TheTargetData;
-  
+   static mvm::BumpPtrAllocator Allocator;
+
    static uint64 getTypeSize(const llvm::Type* type);
    static void runPasses(llvm::Function* func, llvm::FunctionPassManager*);
    static void initialise(llvm::CodeGenOpt::Level = llvm::CodeGenOpt::Default,
@@ -207,6 +209,23 @@
                                                    void* ip) = 0;
 };
 
+class JITMethodInfo : public MethodInfo {
+  llvm::GCFunctionInfo* GCInfo;
+public:
+  virtual void scan(void* TL, void* ip, void* addr);
+  JITMethodInfo(llvm::GCFunctionInfo* GFI) : GCInfo(GFI) {}
+};
+
+class MvmJITMethodInfo : public JITMethodInfo {
+  const llvm::Function* Func;
+public:
+  virtual void print(void* ip, void* addr);
+  MvmJITMethodInfo(llvm::GCFunctionInfo* GFI, const llvm::Function* F) :
+    JITMethodInfo(GFI) {
+      Func = F;
+  }
+};
+
 
 } // end namespace mvm
 

Added: vmkit/trunk/include/mvm/MethodInfo.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/MethodInfo.h?rev=86373&view=auto

==============================================================================
--- vmkit/trunk/include/mvm/MethodInfo.h (added)
+++ vmkit/trunk/include/mvm/MethodInfo.h Sat Nov  7 06:30:44 2009
@@ -0,0 +1,60 @@
+//===---------- MethodInfo.h - Meta information for methods ---------------===//
+//
+//                            The VMKit project
+//
+// This file is distributed under the University of Pierre et Marie Curie 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MVM_METHODINFO_H
+#define MVM_METHODINFO_H
+
+#include "mvm/Allocator.h"
+#include "mvm/GC/GC.h"
+
+namespace mvm {
+
+class MethodInfo : public PermanentObject {
+public:
+  virtual void print(void* ip, void* addr) = 0;
+  virtual void scan(void* TL, void* ip, void* addr) = 0;
+
+  static void* isStub(void* ip, void* addr) {
+    bool isStub = ((unsigned char*)ip)[0] == 0xCE;
+    if (isStub) ip = ((void**)addr)[2];
+    return ip;
+  }
+  
+  virtual void* getMetaInfo() {
+    abort();
+    return NULL;
+  }
+};
+
+class CamlMethodInfo : public MethodInfo {
+  CamlFrame* CF;
+public:
+  virtual void scan(void* TL, void* ip, void* addr);
+  CamlMethodInfo(CamlFrame* C) : CF(C) {}
+};
+
+class StaticCamlMethodInfo : public CamlMethodInfo {
+  const char* name;
+public:
+  virtual void print(void* ip, void* addr);
+  StaticCamlMethodInfo(CamlFrame* CF, const char* n) : CamlMethodInfo(CF) {
+    name = n;
+  }
+};
+
+class DefaultMethodInfo : public MethodInfo {
+public:
+  virtual void print(void* ip, void* addr);
+  virtual void scan(void* TL, void* ip, void* addr);
+  static DefaultMethodInfo DM;
+};
+
+
+} // end namespace mvm
+#endif // MVM_METHODINFO_H

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

==============================================================================
--- vmkit/trunk/include/mvm/VirtualMachine.h (original)
+++ vmkit/trunk/include/mvm/VirtualMachine.h Sat Nov  7 06:30:44 2009
@@ -16,6 +16,7 @@
 #define MVM_VIRTUALMACHINE_H
 
 #include "mvm/Allocator.h"
+#include "mvm/MethodInfo.h"
 #include "mvm/Threads/CollectionRV.h"
 #include "mvm/Threads/Cond.h"
 #include "mvm/Threads/Locks.h"
@@ -33,6 +34,67 @@
 
 namespace mvm {
 
+class FunctionMap {
+public:
+  /// Functions - Map of applicative methods to function pointers. This map is
+  /// used when walking the stack so that VMKit knows which applicative method
+  /// is executing on the stack.
+  ///
+  std::map<void*, MethodInfo*> Functions;
+
+  /// FunctionMapLock - Spin lock to protect the Functions map.
+  ///
+  mvm::SpinLock FunctionMapLock;
+};
+
+/// StartEndFunctionMap - This map is for functions for which we have
+/// a start and end address.
+///
+class StartEndFunctionMap : public FunctionMap {
+public:
+  /// addMethodInFunctionMap - A new method pointer in the function map.
+  ///
+  void addMethodInfo(MethodInfo* meth, void* start, void* end) {
+    FunctionMapLock.acquire();
+    Functions.insert(std::make_pair(start, meth));
+    Functions.insert(std::make_pair(end, meth));
+    FunctionMapLock.release();
+  }
+  
+  /// IPToMethodInfo - Map an instruction pointer to the MethodInfo.
+  ///
+  MethodInfo* IPToMethodInfo(void* ip) {
+    FunctionMapLock.acquire();
+    std::map<void*, MethodInfo*>::iterator I = Functions.upper_bound(ip);
+    MethodInfo* res = 0;
+    if (I != Functions.end() && I != Functions.begin()) {
+      res = I->second;
+      if ((--I)->second != res) res = 0;
+    }
+    FunctionMapLock.release();
+    return res;
+  }
+};
+
+/// StartFunctionMap - This map is for static functions where getting an end
+/// address is cumbersome.
+///
+class StartFunctionMap : public FunctionMap {
+public: 
+  /// addMethodInFunctionMap - A new method pointer in the function map.
+  ///
+  void addMethodInfo(MethodInfo* meth, void* addr) {
+    FunctionMapLock.acquire();
+    Functions.insert(std::make_pair((void*)addr, meth));
+    FunctionMapLock.release();
+  }
+  
+  /// IPToMethodInfo - Map an instruction pointer to the MethodInfo.
+  ///
+  MethodInfo* IPToMethodInfo(void* ip);
+ 
+};
+
 
 // Same values than JikesRVM
 #define INITIAL_QUEUE_SIZE 256
@@ -401,94 +463,26 @@
   virtual bool enqueueReference(gc*) { return false; }
 
 
-protected:
-
-  /// Functions - Map of applicative methods to function pointers. This map is
-  /// used when walking the stack so that VMKit knows which applicative method
-  /// is executing on the stack.
-  ///
-  std::map<void*, void*> Functions;
-
-  /// FunctionMapLock - Spin lock to protect the Functions map.
-  ///
-  mvm::SpinLock FunctionMapLock;
+public:
 
   /// scanner - Scanner of threads' stacks.
   ///
   mvm::StackScanner* scanner;
 
-public:
-  /// addMethodInFunctionMap - A new method pointer in the function map.
-  ///
-  template <typename T>
-  void addMethodInFunctionMap(T* meth, void* addr) {
-    FunctionMapLock.acquire();
-    Functions.insert(std::make_pair((void*)addr, meth));
-    FunctionMapLock.release();
-  }
-  
-  /// IPToJavaMethod - Map an instruction pointer to the Java method.
-  ///
-  template <typename T> T* IPToMethod(void* ip) {
-    FunctionMapLock.acquire();
-    std::map<void*, void*>::iterator I = Functions.upper_bound(ip);
-    assert(I != Functions.begin() && "Wrong value in function map");
-
-    // Decrement because we had the "greater than" value.
-    I--;
-    
-    T* res = (T*)I->second;
-    FunctionMapLock.release();
-    return res;
-  }
-
-  void setScanner(mvm::StackScanner* s) {
-    scanner = s;
-  }
-
   mvm::StackScanner* getScanner() {
     return scanner;
   }
 
-protected:
-
-  /// InternalFunctions - Map of internal methods to function pointers. This
-  /// map is used when walking the stack so that VMKit knows which
-  /// JIT-generated internal method is executing on the stack.
+  /// rendezvous - The rendezvous implementation for garbage collection.
   ///
-  std::map<void*, const char*> InternalFunctions;
+  CollectionRV rendezvous;
 
-  /// FunctionMapLock - Spin lock to protect the Functions map.
-  ///
-  mvm::SpinLock InternalFunctionMapLock;
 
-public:
-  /// addMethodInFunctionMap - A new method pointer in the function map.
-  ///
-  void addInternalMethodInFunctionMap(const char* meth, void* start, void* end) {
-    InternalFunctionMapLock.acquire();
-    InternalFunctions.insert(std::make_pair(start, meth));
-    InternalFunctions.insert(std::make_pair(end, meth));
-    InternalFunctionMapLock.release();
-  }
-  
-  /// IPToJavaMethod - Map an instruction pointer to the Java method.
-  ///
-  const char* IPToInternalMethod(void* ip) {
-    InternalFunctionMapLock.acquire();
-    std::map<void*, const char*>::iterator I = InternalFunctions.upper_bound(ip);
-    const char* res = 0;
-    if (I != InternalFunctions.end() && I != InternalFunctions.begin()) {
-      res = I->second;
-      if ((--I)->second != res) res = 0;
-    }
-    InternalFunctionMapLock.release();
-    return res;
-  }
+  StartEndFunctionMap RuntimeFunctions;
+  static StartEndFunctionMap SharedRuntimeFunctions;
+  StartFunctionMap StaticFunctions;
 
-  /// rendezvous - The rendezvous implementation for garbage collection.
-  ///
-  CollectionRV rendezvous;
+  MethodInfo* IPToMethodInfo(void* ip);
 
 #ifdef ISOLATE
   size_t IsolateID;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.inc (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.inc Sat Nov  7 06:30:44 2009
@@ -48,7 +48,8 @@
   uint32 index = 0;
  
   for (; i != e; ++i) {
-    JavaMethod* meth = vm->IPToMethod<JavaMethod>(*i);
+    mvm::MethodInfo* MI = vm->IPToMethodInfo(*i);
+    JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
     assert(meth && "Wrong stack trace");
     result->elements[index++] = meth->classDef->getClassDelegatee(vm);
   }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.inc (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.inc Sat Nov  7 06:30:44 2009
@@ -136,7 +136,8 @@
   // remove the VMThrowable.fillInStackTrace method
   sint32 index = 1;;
   while (index != stack->size) {
-    JavaMethod* meth = vm->IPToMethod<JavaMethod>(stack->elements[index]);
+    mvm::MethodInfo* MI = vm->IPToMethodInfo(stack->elements[index]);
+    JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
     assert(meth && "Wrong stack trace");
     if (meth->classDef->isAssignableFrom(vm->upcalls->newThrowable)) {
       ++index;
@@ -147,7 +148,8 @@
     vm->upcalls->stackTraceArray->doNew(stack->size - index, vm);
   
   for (sint32 i = 0; i < result->size; ++i) {
-    JavaMethod* meth = vm->IPToMethod<JavaMethod>(stack->elements[i + index]);
+    mvm::MethodInfo* MI = vm->IPToMethodInfo(stack->elements[i + index]);
+    JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
     assert(meth && "Wrong stack trace");
     result->elements[i] = consStackElement(meth, stack->elements[i + index]);
   }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Sat Nov  7 06:30:44 2009
@@ -43,10 +43,22 @@
     if (currentCompiledMethod &&
         JavaLLVMCompiler::getMethod(currentCompiledMethod) == &F) {
       Jnjvm* vm = JavaThread::get()->getJVM();
-      vm->addMethodInFunctionMap(currentCompiledMethod, Code);
-    } else {
-      Jnjvm* vm = JavaThread::get()->getJVM();
-      vm->addInternalMethodInFunctionMap(F.getName().data(), Code,
+      mvm::BumpPtrAllocator& Alloc = 
+        currentCompiledMethod->classDef->classLoader->allocator;
+      llvm::GCFunctionInfo* GFI = 0;
+      // We know the last GC info is for this method.
+      if (F.hasGC()) {
+        GCStrategy::iterator I = mvm::MvmModule::GC->end();
+        I--;
+        DEBUG(errs() << (*I)->getFunction().getName() << '\n');
+        DEBUG(errs() << F.getName() << '\n');
+        assert(&(*I)->getFunction() == &F &&
+           "GC Info and method do not correspond");
+        GFI = *I;
+      }
+      JavaJITMethodInfo* MI = new(Alloc, "JavaJITMethodInfo")
+        JavaJITMethodInfo(GFI, currentCompiledMethod);
+      vm->RuntimeFunctions.addMethodInfo(MI, Code,
                                          (void*)((uintptr_t)Code + Size));
     }
   }
@@ -286,7 +298,8 @@
 
 llvm::GCFunctionInfo*
 JavaJITStackScanner::IPToGCFunctionInfo(mvm::VirtualMachine* vm, void* ip) {
-  JavaMethod* method = vm->IPToMethod<JavaMethod>(ip);
+  mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
+  JavaMethod* method = (JavaMethod*)MI->getMetaInfo();
   return method->getInfo<LLVMMethodInfo>()->GCInfo;
 }
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Sat Nov  7 06:30:44 2009
@@ -405,3 +405,12 @@
   //JavaFunctionPasses->add(mvm::createEscapeAnalysisPass());
   JavaFunctionPasses->add(createLowerConstantCallsPass(getIntrinsics()));
 }
+
+void JavaJITMethodInfo::print(void* ip, void* addr) {
+  void* new_ip = isStub(ip, addr);
+  fprintf(stderr, "; %p in %s.%s", new_ip,
+          UTF8Buffer(meth->classDef->name).cString(),
+          UTF8Buffer(meth->name).cString());
+  if (ip != new_ip) fprintf(stderr, " (from stub)");
+  fprintf(stderr, "\n");
+}

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sat Nov  7 06:30:44 2009
@@ -319,12 +319,24 @@
   return code;
 }
 
+void JavaStaticMethodInfo::print(void* ip, void* addr) {
+  void* new_ip = mvm::MethodInfo::isStub(ip, addr);
+  fprintf(stderr, "; %p in %s.%s", new_ip,
+          UTF8Buffer(meth->classDef->name).cString(),
+          UTF8Buffer(meth->name).cString());
+  if (ip != new_ip) fprintf(stderr, " (from stub)");
+  fprintf(stderr, "\n");
+}
+
 void JavaMethod::setCompiledPtr(void* ptr, const char* name) {
   classDef->acquire();
   if (code == 0) {
     code = ptr;
     Jnjvm* vm = JavaThread::get()->getJVM();
-    vm->addMethodInFunctionMap(this, code);
+    JavaStaticMethodInfo* MI =
+      new (classDef->classLoader->allocator, "JavaStaticMethodInfo")
+        JavaStaticMethodInfo(0, this);
+    vm->StaticFunctions.addMethodInfo(MI, code);
     classDef->classLoader->getCompiler()->setMethod(this, ptr, name);
   }
   access |= ACC_NATIVE;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sat Nov  7 06:30:44 2009
@@ -14,6 +14,7 @@
 #include "types.h"
 
 #include "mvm/Allocator.h"
+#include "mvm/MethodInfo.h"
 #include "mvm/Object.h"
 #include "mvm/Threads/Cond.h"
 #include "mvm/Threads/Locks.h"
@@ -951,6 +952,22 @@
   
 };
 
+class JavaStaticMethodInfo : public mvm::CamlMethodInfo {
+protected:
+  JavaMethod* meth;
+public:
+  virtual void print(void* ip, void* addr);
+  
+  JavaStaticMethodInfo(CamlFrame* CF, JavaMethod* M) :
+    mvm::CamlMethodInfo(CF) {
+    meth = M;
+  }
+
+  virtual void* getMetaInfo() {
+    return meth;
+  }
+};
+
 /// JavaMethod - This class represents Java methods.
 ///
 class JavaMethod : public mvm::PermanentObject {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp Sat Nov  7 06:30:44 2009
@@ -116,9 +116,9 @@
   // Get the IP of the caller.
   void* ip = FRAME_IP(addr);
 
-  JavaMethod* meth = getJVM()->IPToMethod<JavaMethod>(ip);
+  mvm::MethodInfo* meth = getJVM()->IPToMethodInfo(ip);
 
-  return meth;
+  return (JavaMethod*)meth->getMetaInfo();
 }
 
 UserClass* JavaThread::getCallingClass(uint32 level) {
@@ -134,7 +134,8 @@
     addr = (void**)addr[0];
   void* ip = FRAME_IP(addr);
 
-  JavaMethod* meth = getJVM()->IPToMethod<JavaMethod>(ip);
+  mvm::MethodInfo* MI = getJVM()->IPToMethodInfo(ip);
+  JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
 
   return meth->classDef;
 }
@@ -165,7 +166,8 @@
     void* ip = FRAME_IP(addr);
     bool isStub = ((unsigned char*)ip)[0] == 0xCE;
     if (isStub) ip = addr[2];
-    JavaMethod* meth = getJVM()->IPToMethod<JavaMethod>(ip);
+    mvm::MethodInfo* MI = getJVM()->IPToMethodInfo(ip);
+    JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
     return meth->classDef;
   }
   return 0;
@@ -236,7 +238,8 @@
       bool isStub = ((unsigned char*)ip)[0] == 0xCE;
       if (isStub) ip = addr[2];
       if (index == level) {
-        JavaMethod* meth = getJVM()->IPToMethod<JavaMethod>(ip);
+        mvm::MethodInfo* MI = getJVM()->IPToMethodInfo(ip);
+        JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
         return meth->classDef;
       }
       addr = (void**)addr[0];
@@ -280,7 +283,8 @@
       void* ip = FRAME_IP(addr);
       bool isStub = ((unsigned char*)ip)[0] == 0xCE;
       if (isStub) ip = addr[2];
-      JavaMethod* meth = getJVM()->IPToMethod<JavaMethod>(ip);
+      mvm::MethodInfo* MI = getJVM()->IPToMethodInfo(ip);
+      JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
       JnjvmClassLoader* loader = meth->classDef->classLoader;
       obj = loader->getJavaClassLoader();
       if (obj) return obj;
@@ -301,7 +305,8 @@
   getJavaFrameContext(vals);
   for (std::vector<void*>::iterator i = vals.begin(), e = vals.end(); 
        i != e; ++i) {
-    JavaMethod* meth = vm->IPToMethod<JavaMethod>(*i);
+    mvm::MethodInfo* MI = vm->IPToMethodInfo(*i);
+    JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
     assert(meth && "Wrong stack");
     fprintf(stderr, "; %p in %s.%s\n",  *i,
             UTF8Buffer(meth->classDef->name).cString(),
@@ -318,12 +323,7 @@
   if (res != 0) {
     fprintf(stderr, "; %p in %s\n",  ip, info.dli_sname);
   } else {
-    const char* name = vm->IPToInternalMethod(ip);
-    if (name) {
-      fprintf(stderr, "; %p in %s LLVM method\n", ip, name);
-    } else {
-      fprintf(stderr, "; %p in Unknown method\n", ip);
-    }
+    fprintf(stderr, "; %p in Unknown method\n", ip);
   }
 }
 
@@ -372,7 +372,8 @@
       void* ip = FRAME_IP(addr);
       bool isStub = ((unsigned char*)ip)[0] == 0xCE;
       if (isStub) ip = addr[2];
-      JavaMethod* meth = vm->IPToMethod<JavaMethod>(ip);
+      mvm::MethodInfo* MI = getJVM()->IPToMethodInfo(ip);
+      JavaMethod* meth = (JavaMethod*)MI->getMetaInfo();
       assert(meth && "Wrong stack");
       fprintf(stderr, "; %p in %s.%s",  ip,
               UTF8Buffer(meth->classDef->name).cString(),

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sat Nov  7 06:30:44 2009
@@ -1391,22 +1391,28 @@
   return tmp;
 }
 
-void Jnjvm::removeMethodsInFunctionMap(JnjvmClassLoader* loader) {
+void Jnjvm::internalRemoveMethods(JnjvmClassLoader* loader, mvm::FunctionMap& Map) {
   // Loop over all methods in the map to find which ones belong
   // to this class loader.
-  FunctionMapLock.acquire();
-  std::map<void*, void*>::iterator temp;
-  for (std::map<void*, void*>::iterator i = Functions.begin(), 
-       e = Functions.end(); i != e;) {
-    if (((JavaMethod*)i->second)->classDef->classLoader == loader) {
+  Map.FunctionMapLock.acquire();
+  std::map<void*, mvm::MethodInfo*>::iterator temp;
+  for (std::map<void*, mvm::MethodInfo*>::iterator i = Map.Functions.begin(), 
+       e = Map.Functions.end(); i != e;) {
+    JavaMethod* meth = (JavaMethod*)i->second->getMetaInfo();
+    if (meth->classDef->classLoader == loader) {
       temp = i;
       ++i;
-      Functions.erase(temp);
+      Map.Functions.erase(temp);
     } else {
       ++i;
     }
   }
-  FunctionMapLock.release();
+  Map.FunctionMapLock.release();
+}
+
+void Jnjvm::removeMethodsInFunctionMaps(JnjvmClassLoader* loader) {
+  internalRemoveMethods(loader, RuntimeFunctions);
+  internalRemoveMethods(loader, StaticFunctions);
 }
 
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Sat Nov  7 06:30:44 2009
@@ -337,11 +337,18 @@
   /// waitForExit - Waits that there are no more non-daemon threads in this JVM.
   ///
   virtual void waitForExit();
-  
-  /// removeMethodsInFunctionMap - Removes all methods compiled by this
+
+private:
+  /// internalRemoveMethodsInFunctionMap - Removes all methods compiled by this
   /// class loader from the function map.
   ///
-  void removeMethodsInFunctionMap(JnjvmClassLoader* loader);
+  void internalRemoveMethods(JnjvmClassLoader* loader, mvm::FunctionMap& Map);
+
+public:
+  /// removeMethodsInFunctionMaps - Removes all methods compiled by this
+  /// class loader from the function maps.
+  ///
+  void removeMethodsInFunctionMaps(JnjvmClassLoader* loader);
   
   /// loadBootstrap - Bootstraps the JVM, getting the class loader, initializing
   /// bootstrap classes (e.g. java/lang/Class, java/lang/*Exception) and

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Sat Nov  7 06:30:44 2009
@@ -900,7 +900,7 @@
 JnjvmClassLoader::~JnjvmClassLoader() {
 
   if (isolate)
-    isolate->removeMethodsInFunctionMap(this);
+    isolate->removeMethodsInFunctionMaps(this);
 
   if (classes) {
     classes->~ClassMap();
@@ -1077,7 +1077,9 @@
       for (uint32 i = 0; i < C->nbVirtualMethods; ++i) {
         JavaMethod& meth = C->virtualMethods[i];
         if (!isAbstract(meth.access) && meth.code) {
-          vm->addMethodInFunctionMap(&meth, meth.code);
+          JavaStaticMethodInfo* MI = new (allocator, "JavaStaticMethodInfo")
+            JavaStaticMethodInfo(0, &meth);
+          vm->StaticFunctions.addMethodInfo(MI, meth.code);
           M->setMethod(&meth, meth.code, "");
         }
       }
@@ -1085,7 +1087,9 @@
       for (uint32 i = 0; i < C->nbStaticMethods; ++i) {
         JavaMethod& meth = C->staticMethods[i];
         if (!isAbstract(meth.access) && meth.code) {
-          vm->addMethodInFunctionMap(&meth, meth.code);
+          JavaStaticMethodInfo* MI = new (allocator, "JavaStaticMethodInfo")
+            JavaStaticMethodInfo(0, &meth);
+          vm->StaticFunctions.addMethodInfo(MI, meth.code);
           M->setMethod(&meth, meth.code, "");
         }
       }

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Sat Nov  7 06:30:44 2009
@@ -24,6 +24,7 @@
 #include <llvm/CodeGen/GCStrategy.h>
 #include <llvm/Config/config.h>
 #include <llvm/ExecutionEngine/ExecutionEngine.h>
+#include "llvm/ExecutionEngine/JITEventListener.h"
 #include "llvm/Support/CommandLine.h"
 #include <llvm/Support/Debug.h>
 #include <llvm/Support/IRReader.h>
@@ -61,6 +62,34 @@
   return LLVM_HOSTTRIPLE;
 }
 
+class MvmJITListener : public llvm::JITEventListener {
+public:
+  virtual void NotifyFunctionEmitted(const Function &F,
+                                     void *Code, size_t Size,
+                                     const EmittedFunctionDetails &Details) {
+    
+    if (F.getParent() == MvmModule::globalModule) {
+      llvm::GCFunctionInfo* GFI = 0;
+      // We know the last GC info is for this method.
+      if (F.hasGC()) {
+        GCStrategy::iterator I = mvm::MvmModule::GC->end();
+        I--;
+        DEBUG(errs() << (*I)->getFunction().getName() << '\n');
+        DEBUG(errs() << F.getName() << '\n');
+        assert(&(*I)->getFunction() == &F &&
+           "GC Info and method do not correspond");
+        GFI = *I;
+      }
+      MethodInfo* MI =
+        new(MvmModule::Allocator, "MvmJITMethodInfo") MvmJITMethodInfo(GFI, &F);
+      VirtualMachine::SharedRuntimeFunctions.addMethodInfo(MI, Code,
+                                              (void*)((uintptr_t)Code + Size));
+    }
+  }
+};
+
+static MvmJITListener JITListener;
+
 void MvmModule::loadBytecodeFile(const std::string& str) {
   SMDiagnostic Err;
   Module* M = ParseIRFile(str, Err, getGlobalContext());
@@ -97,7 +126,8 @@
 
     executionEngine = ExecutionEngine::createJIT(globalModuleProvider, 0,
                                                  0, level, false);
- 
+
+    executionEngine->RegisterJITEventListener(&JITListener);    
     executionEngine->DisableLazyCompilation(false); 
     std::string str = 
       executionEngine->getTargetData()->getStringRepresentation();
@@ -411,7 +441,7 @@
 llvm::FunctionPassManager* MvmModule::globalFunctionPasses;
 llvm::ExecutionEngine* MvmModule::executionEngine;
 mvm::LockRecursive MvmModule::protectEngine;
-
+mvm::BumpPtrAllocator MvmModule::Allocator;
 
 uint64 MvmModule::getTypeSize(const llvm::Type* type) {
   return TheTargetData->getTypeAllocSize(type);
@@ -531,7 +561,7 @@
     // Until we hit the last Java frame.
     do {
       void* ip = FRAME_IP(addr);
-      camlframe* CF = (camlframe*)VirtualMachine::GCMap.GCInfos[ip];
+      CamlFrame* CF = (CamlFrame*)VirtualMachine::GCMap.GCInfos[ip];
       if (CF) { 
         //char* spaddr = (char*)addr + CF->FrameSize + sizeof(void*);
         uintptr_t spaddr = (uintptr_t)addr[0];
@@ -554,7 +584,7 @@
       --it;
       if (*it == 0) {
         void* ip = FRAME_IP(addr);
-        camlframe* CF = (camlframe*)VirtualMachine::GCMap.GCInfos[ip];
+        CamlFrame* CF = (CamlFrame*)VirtualMachine::GCMap.GCInfos[ip];
         if (CF) { 
           //char* spaddr = (char*)addr + CF->FrameSize + sizeof(void*);
           uintptr_t spaddr = (uintptr_t)addr[0];
@@ -571,7 +601,7 @@
       void* ip = FRAME_IP(addr);
       bool isStub = ((unsigned char*)ip)[0] == 0xCE;
       if (isStub) ip = addr[2];
-      camlframe* CF = (camlframe*)VirtualMachine::GCMap.GCInfos[ip];
+      CamlFrame* CF = (CamlFrame*)VirtualMachine::GCMap.GCInfos[ip];
       if (CF) {
         //uintptr_t spaddr = (uintptr_t)addr + CF->FrameSize + sizeof(void*);
         uintptr_t spaddr = (uintptr_t)addr[0];
@@ -605,7 +635,7 @@
 
   while (addr < th->baseSP && addr < addr[0]) {
     void* ip = FRAME_IP(addr);
-    camlframe* CF = (camlframe*)VirtualMachine::GCMap.GCInfos[ip];
+    CamlFrame* CF = (CamlFrame*)VirtualMachine::GCMap.GCInfos[ip];
     if (CF) { 
       //uintptr_t spaddr = (uintptr_t)addr + CF->FrameSize + sizeof(void*);
       uintptr_t spaddr = (uintptr_t)addr[0];
@@ -617,3 +647,23 @@
   }
 
 }
+
+void JITMethodInfo::scan(void* TL, void* ip, void* addr) {
+  if (GCInfo) {
+    DEBUG(llvm::errs() << GCInfo->getFunction().getName() << '\n');
+    // All safe points have the same informations currently in LLVM.
+    llvm::GCFunctionInfo::iterator J = GCInfo->begin();
+    //uintptr_t spaddr = (uintptr_t)addr + GFI->getFrameSize() + sizeof(void*);
+    uintptr_t spaddr = ((uintptr_t*)addr)[0];
+    for (llvm::GCFunctionInfo::live_iterator K = GCInfo->live_begin(J),
+         KE = GCInfo->live_end(J); K != KE; ++K) {
+      intptr_t obj = *(intptr_t*)(spaddr + K->StackOffset);
+      // Verify that obj does not come from a JSR bytecode.
+      if (!(obj & 1)) Collector::scanObject((void**)(spaddr + K->StackOffset));
+    }
+  }
+}
+
+void MvmJITMethodInfo::print(void* ip, void* addr) {
+  fprintf(stderr, "; %p in %s LLVM method\n", ip, Func->getName().data());
+}

Added: vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp?rev=86373&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp (added)
+++ vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Sat Nov  7 06:30:44 2009
@@ -0,0 +1,83 @@
+//===------- MethodInfo.cpp - Runtime information for methods -------------===//
+//
+//                        The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mvm/Allocator.h"
+#include "mvm/MethodInfo.h"
+#include "MvmGC.h"
+
+#include <dlfcn.h>
+
+using namespace mvm;
+
+void CamlMethodInfo::scan(void* TL, void* ip, void* addr) {
+  //uintptr_t spaddr = (uintptr_t)addr + CF->FrameSize + sizeof(void*);
+  uintptr_t spaddr = ((uintptr_t*)addr)[0];
+  for (uint16 i = 0; i < CF->NumLiveOffsets; ++i) {
+    Collector::scanObject((void**)(spaddr + CF->LiveOffsets[i]));
+  }
+}
+
+void StaticCamlMethodInfo::print(void* ip, void* addr) {
+  fprintf(stderr, "; %p in %s static method\n", ip, name);
+}
+
+void DefaultMethodInfo::print(void* ip, void* addr) {
+  Dl_info info;
+  int res = dladdr(ip, &info);
+  if (res != 0) {
+    fprintf(stderr, "; %p in %s\n",  ip, info.dli_sname);
+  } else {
+    fprintf(stderr, "; %p in Unknown method\n",  ip);
+  }
+}
+
+DefaultMethodInfo DefaultMethodInfo::DM;
+
+void DefaultMethodInfo::scan(void* TL, void* ip, void* addr) {
+}
+
+
+MethodInfo* StartFunctionMap::IPToMethodInfo(void* ip) {
+  FunctionMapLock.acquire();
+  std::map<void*, MethodInfo*>::iterator E = Functions.end();
+  std::map<void*, MethodInfo*>::iterator I = Functions.find(ip);
+  MethodInfo* MI = 0;
+  if (I == E) {
+    Dl_info info;
+    int res = dladdr(ip, &info);
+    if (res != 0) {
+      I = Functions.find(info.dli_saddr);
+      if (I == E) {
+        // The method is static, and we have no information for it.
+        // Just return the Default MethodInfo object.
+        MI = &DefaultMethodInfo::DM;
+      } else {
+        MI = I->second;
+        // Add it to the map, so that we don't need to call dladdr again
+        // on something that belongs to our code.
+        Functions.insert(std::make_pair(ip, MI));
+      }
+    }
+  } else {
+    MI = I->second;
+  }
+  FunctionMapLock.release();
+  return MI;
+}
+
+MethodInfo* VirtualMachine::IPToMethodInfo(void* ip) {
+  MethodInfo* MI = RuntimeFunctions.IPToMethodInfo(ip);
+  if (MI) return MI;
+  
+  MI = SharedRuntimeFunctions.IPToMethodInfo(ip);
+  if (MI) return MI;
+
+  MI = StaticFunctions.IPToMethodInfo(ip);
+  return MI;
+}

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sat Nov  7 06:30:44 2009
@@ -277,7 +277,7 @@
     // Until we hit the last Java frame.
     do {
       void* ip = FRAME_IP(addr);
-      camlframe* CF = (camlframe*)VirtualMachine::GCMap.GCInfos[ip];
+      CamlFrame* CF = (CamlFrame*)VirtualMachine::GCMap.GCInfos[ip];
       if (CF) { 
         //char* spaddr = (char*)addr + CF->FrameSize + sizeof(void*);
         uintptr_t spaddr = (uintptr_t)addr[0];
@@ -299,7 +299,7 @@
       --it;
       if (*it == 0) {
         void* ip = FRAME_IP(addr);
-        camlframe* CF = (camlframe*)VirtualMachine::GCMap.GCInfos[ip];
+        CamlFrame* CF = (CamlFrame*)VirtualMachine::GCMap.GCInfos[ip];
         if (CF) { 
           //char* spaddr = (char*)addr + CF->FrameSize + sizeof(void*);
           uintptr_t spaddr = (uintptr_t)addr[0];
@@ -316,7 +316,7 @@
       void* ip = FRAME_IP(addr);
       bool isStub = ((unsigned char*)ip)[0] == 0xCE;
       if (isStub) ip = addr[2];
-      camlframe* CF = (camlframe*)VirtualMachine::GCMap.GCInfos[ip];
+      CamlFrame* CF = (CamlFrame*)VirtualMachine::GCMap.GCInfos[ip];
       if (CF) {
         //uintptr_t spaddr = (uintptr_t)addr + CF->FrameSize + sizeof(void*);
         uintptr_t spaddr = (uintptr_t)addr[0];
@@ -334,7 +334,7 @@
 
   while (addr < th->baseSP && addr < addr[0]) {
     void* ip = FRAME_IP(addr);
-    camlframe* CF = (camlframe*)VirtualMachine::GCMap.GCInfos[ip];
+    CamlFrame* CF = (CamlFrame*)VirtualMachine::GCMap.GCInfos[ip];
     if (CF) { 
       //uintptr_t spaddr = (uintptr_t)addr + CF->FrameSize + sizeof(void*);
       uintptr_t spaddr = (uintptr_t)addr[0];
@@ -360,3 +360,4 @@
   }
 }
 
+StartEndFunctionMap VirtualMachine::SharedRuntimeFunctions;





More information about the vmkit-commits mailing list