[llvm-commits] [vmkit] r51710 - in /vmkit/trunk: include/mvm/ lib/JnJVM/VMCore/ lib/Mvm/ lib/N3/VMCore/

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu May 29 15:26:00 PDT 2008


Author: geoffray
Date: Thu May 29 17:26:00 2008
New Revision: 51710

URL: http://llvm.org/viewvc/llvm-project?rev=51710&view=rev
Log:
Use internaly LLVM's memory manager to allocate native code.


Modified:
    vmkit/trunk/include/mvm/JIT.h
    vmkit/trunk/include/mvm/Method.h
    vmkit/trunk/include/mvm/MvmMemoryManager.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaBacktrace.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp
    vmkit/trunk/lib/Mvm/JIT.cpp
    vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp
    vmkit/trunk/lib/Mvm/Object.cpp
    vmkit/trunk/lib/N3/VMCore/BackTrace.cpp
    vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
    vmkit/trunk/lib/N3/VMCore/CLIJit.h
    vmkit/trunk/lib/N3/VMCore/N3.cpp
    vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp
    vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp
    vmkit/trunk/lib/N3/VMCore/Opcodes.cpp
    vmkit/trunk/lib/N3/VMCore/VMClass.h
    vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp

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

==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Thu May 29 17:26:00 2008
@@ -20,13 +20,13 @@
 #include "llvm/PassManager.h"
 #include "llvm/Type.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
-#include "llvm/ExecutionEngine/GenericValue.h"
 #include "llvm/Target/TargetData.h"
 
 #include "types.h"
 
-#include "mvm/Threads/Locks.h"
+#include "mvm/Method.h"
 #include "mvm/MvmMemoryManager.h"
+#include "mvm/Threads/Locks.h"
 
 namespace mvm {
 
@@ -154,6 +154,9 @@
 
 extern int disassemble(unsigned int* addr);
 
+extern int getBacktrace(void** stack, int size);
+extern Code* getCodeFromPointer(void* addr);
+extern void addMethodInfo(void* end, Code* c);
 
 } // end namespace jit
 

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

==============================================================================
--- vmkit/trunk/include/mvm/Method.h (original)
+++ vmkit/trunk/include/mvm/Method.h Thu May 29 17:26:00 2008
@@ -10,88 +10,38 @@
 #ifndef MVM_METHOD_H
 #define MVM_METHOD_H
 
-#include "mvm/Object.h"
-#include "mvm/Threads/Thread.h"
-
-namespace llvm {
-  class Function;
-}
+extern "C" void __deregister_frame(void*);
 
 namespace mvm {
 
-class Code;
-class ExceptionTable;
-
-class Method : public Object {
+class Code {
 public:
-  inline Method() {}
-  static VirtualTable* VT;
-  GC_defass(Object, name);
-  GC_defass(Code, code);
-  GC_defass(Object, definition);
-  GC_defass(Object, literals);
-  GC_defass(ExceptionTable, exceptionTable);
-  const llvm::Function* llvmFunction;
-  size_t  codeSize;
-
-  /* use this constructor to map a function which is compiled by llvm  */
-  inline Method(Code *c, size_t sz) {
-    code(c);
-    codeSize = sz;
-  }
-
-  virtual void print(PrintBuffer *buf) const;
-  virtual void TRACER;
-};
-
 
-class Code : public Object {
-public:
-  inline Code() {}
-  static VirtualTable* VT;
-  Method* meth;
+  Code() {
+    stubSize = 0;
+    FunctionStart = 0;
+    FunctionEnd = 0;
+    stub = 0;
+    frameRegister = 0;
+    exceptionTable = 0;
+    metaInfo = 0;
+  }
+
+  unsigned stubSize;
+  unsigned char* FunctionStart;
+  unsigned char* FunctionEnd;
+  unsigned char* stub;
+  unsigned char* frameRegister;
+  unsigned char* exceptionTable;
 
-  inline Method *method(Method *m, size_t nbb) {
-    return (meth = m);
-  }
+  void* metaInfo;
 
-  inline Method *method(size_t nbb) {
-    return meth;
-  }
-    
-  inline Method *method(Method *m) { return meth = m; }
-  inline Method *method() { return meth; }
-
-  virtual void print(PrintBuffer *buf) const;
-  virtual void TRACER;
-
-  static Code* getCodeFromPointer(void* ptr) {
-#ifdef MULTIPLE_GC
-    return (mvm::Code*)mvm::Thread::get()->GC->begOf(ptr);
-#else
-    return (mvm::Code*)Collector::begOf(ptr);
-#endif
-  }
-};
-
-class ExceptionTable : public Object {
-public:
-  inline ExceptionTable() {}
-  static VirtualTable* VT;
-  void* framePtr;
-
-  inline void *frameRegister(void *m, size_t nbb) {
-    return (framePtr = m);
-  }
+  void* getMetaInfo() { return metaInfo; }
+  void  setMetaInfo(void* m) { metaInfo = m; }
 
-  inline void *frameRegister(size_t nbb) {
-    return framePtr;
+  inline void unregisterFrame() {
+    __deregister_frame((unsigned char*)frameRegister);
   }
-    
-  inline void *frameRegister(void *m) { return (framePtr = m); }
-  inline void *frameRegister() { return framePtr; }
-  
-  virtual void destroyer(size_t sz);
 };
 
 } // end namespace mvm

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

==============================================================================
--- vmkit/trunk/include/mvm/MvmMemoryManager.h (original)
+++ vmkit/trunk/include/mvm/MvmMemoryManager.h Thu May 29 17:26:00 2008
@@ -22,24 +22,24 @@
 
 namespace mvm {
 
-class Method;
-class Object;
+class Code;
 
 class MvmMemoryManager : public JITMemoryManager {
-  Method* currentMethod;       // Current method being compiled
+  Code* currentMethod;       // Current method being compiled
   unsigned char *GOTBase;      // Target Specific reserved memory
 #ifdef MULTIPLE_GC
   std::map<const Module*, Collector*> GCMap;
   mvm::Lock* lock;
 #endif
+  JITMemoryManager* realMemoryManager;
 public:
   
   MvmMemoryManager() : JITMemoryManager() { 
       GOTBase = 0; 
-      SizeRequired = true;
 #ifdef MULTIPLE_GC
       lock = mvm::Lock::allocNormal();
 #endif
+      realMemoryManager= JITMemoryManager::CreateDefaultMemManager();
   }
    ~MvmMemoryManager() { 
       delete[] GOTBase;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaBacktrace.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaBacktrace.cpp Thu May 29 17:26:00 2008
@@ -10,9 +10,6 @@
 #include <stdio.h>
 #include <dlfcn.h>
 
-#include "llvm/Function.h"
-#include "llvm/ExecutionEngine/ExecutionEngine.h"
-
 #include "mvm/JIT.h"
 #include "mvm/Method.h"
 #include "mvm/Object.h"
@@ -26,50 +23,28 @@
 using namespace jnjvm;
 
 JavaMethod* JavaJIT::IPToJavaMethod(void* begIp) {
-  mvm::Code* val = mvm::Code::getCodeFromPointer(begIp);
-  if (val) {
-    mvm::Method* m = val->method();
-    mvm::Object* meth = m->definition();
+  mvm::Code* code = mvm::jit::getCodeFromPointer(begIp);
+  if (code) {
+    JavaMethod* meth = (JavaMethod*)code->getMetaInfo();
     if (meth) {
-      return (JavaMethod*)meth;
+      return meth;
     }
   }
   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;
-  void* baseSP = JavaThread::get()->baseSP;
-  while (blah && cpt < size && blah < baseSP) {
-    stack[cpt++] = (void**)FRAME_IP(blah);
-    blah = (void**)blah[0];
-  }
-  return cpt;
-}
-
 void JavaJIT::printBacktrace() {
   int* ips[100];
-  int real_size = getBacktrace((void**)(void*)ips, 100);
+  int real_size = mvm::jit::getBacktrace((void**)(void*)ips, 100);
   int n = 0;
   while (n < real_size) {
-    mvm::Code* code = mvm::Code::getCodeFromPointer(ips[n++]);
+    mvm::Code* code = mvm::jit::getCodeFromPointer(ips[n++]);
     if (code) {
-      mvm::Method* m = code->method();
-      mvm::Object* meth = m->definition();
+      JavaMethod* meth = (JavaMethod*)code->getMetaInfo();
       if (meth) {
         printf("; %p in %s\n",  ips[n - 1], meth->printString());
-      } else if (m->llvmFunction) {
-        printf("; %p in %s\n",  ips[n - 1],
-                   m->llvmFunction->getNameStr().c_str());
       } else {
-        printf("; %p in %s\n",  ips[n - 1], "stub (probably)");
+        printf("; %p in %s\n",  ips[n - 1], "unknown");
       }
     } else {
       Dl_info info;
@@ -88,17 +63,16 @@
 
 Class* JavaJIT::getCallingClass() {
   int* ips[10];
-  int real_size = getBacktrace((void**)(void*)ips, 10);
+  int real_size = mvm::jit::getBacktrace((void**)(void*)ips, 10);
   int n = 0;
   int i = 0;
   while (n < real_size) {
-    mvm::Code* code = mvm::Code::getCodeFromPointer(ips[n++]);
+    mvm::Code* code = mvm::jit::getCodeFromPointer(ips[n++]);
     if (code) {
-      mvm::Method* m = code->method();
-      mvm::Object* meth = m->definition();
+      JavaMethod* meth = (JavaMethod*)code->getMetaInfo();
       if (meth) {
         if (i == 1) {
-          return ((JavaMethod*)meth)->classDef;
+          return meth->classDef;
         } else {
           ++i;
         }
@@ -110,17 +84,16 @@
 
 Class* JavaJIT::getCallingClassWalker() {
   int* ips[10];
-  int real_size = getBacktrace((void**)(void*)ips, 10);
+  int real_size = mvm::jit::getBacktrace((void**)(void*)ips, 10);
   int n = 0;
   int i = 0;
   while (n < real_size) {
-    mvm::Code* code = mvm::Code::getCodeFromPointer(ips[n++]);
+    mvm::Code* code = mvm::jit::getCodeFromPointer(ips[n++]);
     if (code) {
-      mvm::Method* m = code->method();
-      mvm::Object* meth = m->definition();
+      JavaMethod* meth = (JavaMethod*)code->getMetaInfo();
       if (meth) {
         if (i == 1) {
-          return ((JavaMethod*)meth)->classDef;
+          return meth->classDef;
         } else {
           ++i;
         }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Thu May 29 17:26:00 2008
@@ -253,21 +253,10 @@
   else {
     classDef->aquire();
     if (code == 0) {
-      void* val = 
+      code = 
         classDef->isolate->TheModuleProvider->materializeFunction(this);
-#ifndef MULTIPLE_GC
-      mvm::Code* temp = (mvm::Code*)(Collector::begOf(val));
-#else
-      mvm::Code* temp = (mvm::Code*)(classDef->isolate->GC->begOf(val));
-#endif
-      if (temp) {
-        temp->method()->definition((mvm::Object*)this);
-      }
-      code = (mvm::Code*)val;
-      classDef->release();
-    } else {
-      classDef->release();
     }
+    classDef->release();
     return code;
   }
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Thu May 29 17:26:00 2008
@@ -363,7 +363,7 @@
   const UTF8* name;
   const UTF8* type;
   bool canBeInlined;
-  mvm::Code* code;
+  void* code;
   
   /// offset - The index of the method in the virtual table.
   ///

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp Thu May 29 17:26:00 2008
@@ -119,7 +119,10 @@
     }
   }
   
-  return mvm::jit::executionEngine->getPointerToGlobal(func);
+  void* res = mvm::jit::executionEngine->getPointerToGlobal(func);
+  mvm::Code* m = mvm::jit::getCodeFromPointer(res);
+  if (m) m->setMetaInfo(meth);
+  return res;
 }
 
 llvm::Function* JnjvmModuleProvider::addCallback(Class* cl, uint32 index,
@@ -158,7 +161,7 @@
 }
 
 static void AddStandardCompilePasses(FunctionPassManager *PM) {
-  llvm::MutexGuard locked(mvm::jit::executionEngine->lock);
+    llvm::MutexGuard locked(mvm::jit::executionEngine->lock);
   // LLVM does not allow calling functions from other modules in verifier
   //PM->add(llvm::createVerifierPass());                  // Verify that input is correct
   
@@ -179,13 +182,14 @@
   addPass(PM, createTailCallEliminationPass());  // Eliminate tail calls
   addPass(PM, createCFGSimplificationPass());    // Merge & remove BBs
   addPass(PM, createReassociatePass());          // Reassociate expressions
-  addPass(PM, createLoopRotatePass());
+  //addPass(PM, createLoopRotatePass());
   addPass(PM, createLICMPass());                 // Hoist loop invariants
+  /*
   addPass(PM, createLoopUnswitchPass());         // Unswitch loops.
   addPass(PM, createLoopIndexSplitPass());       // Index split loops.
   addPass(PM, createIndVarSimplifyPass());       // Canonicalize indvars
   addPass(PM, createLoopDeletionPass());         // Delete dead loops
-  addPass(PM, createLoopUnrollPass());           // Unroll small loops
+  addPass(PM, createLoopUnrollPass());           // Unroll small loops*/
   addPass(PM, createInstructionCombiningPass()); // Clean up after the unroller
   addPass(PM, createGVNPass());                  // Remove redundancies
   addPass(PM, createMemCpyOptPass());            // Remove memcpy / form memset
@@ -199,8 +203,9 @@
   addPass(PM, createCondPropagationPass());      // Propagate conditionals
 
   addPass(PM, createDeadStoreEliminationPass()); // Delete dead stores
-  addPass(PM, createAggressiveDCEPass());        // SSA based 'Aggressive DCE'
+  addPass(PM, createAggressiveDCEPass());        // Delete dead instructions
   addPass(PM, createCFGSimplificationPass());    // Merge & remove BBs
+  
 }
 
 JnjvmModuleProvider::JnjvmModuleProvider(JnjvmModule *m) {

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

==============================================================================
--- vmkit/trunk/lib/Mvm/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/JIT.cpp Thu May 29 17:26:00 2008
@@ -18,6 +18,8 @@
 #include "mvm/JIT.h"
 #include "mvm/Method.h"
 #include "mvm/MvmMemoryManager.h"
+#include "mvm/Object.h"
+#include "mvm/Threads/Thread.h"
 
 using namespace mvm;
 using namespace mvm::jit;
@@ -659,12 +661,46 @@
   return executionEngine->getTargetData()->getABITypeSize(type);
 }
 
-extern "C" void __deregister_frame(void*);
+void mvm::jit::runPasses(llvm::Function* func,  llvm::FunctionPassManager* pm) {
+  pm->run(*func);
+}
 
-void ExceptionTable::destroyer(size_t sz) {
-  __deregister_frame(this->frameRegister());
+#if defined(__MACH__) && !defined(__i386__)
+#define FRAME_IP(fp) (fp[2])
+#else
+#define FRAME_IP(fp) (fp[1])
+#endif
+
+int mvm::jit::getBacktrace(void** stack, int size) {
+  void** blah = (void**)__builtin_frame_address(1);
+  int cpt = 0;
+  void* baseSP = mvm::Thread::get()->baseSP;
+  while (blah && cpt < size && blah < baseSP) {
+    stack[cpt++] = (void**)FRAME_IP(blah);
+    blah = (void**)blah[0];
+  }
+  return cpt;
 }
 
-void mvm::jit::runPasses(llvm::Function* func,  llvm::FunctionPassManager* pm) {
-  pm->run(*func);
+LockNormal lock;
+std::map<void*, Code*> pointerMap;
+
+Code* mvm::jit::getCodeFromPointer(void* Addr) {
+  lock.lock();
+  std::map<void*, Code*>::iterator I =
+    pointerMap.lower_bound(Addr);
+  
+  lock.unlock();
+  if (I != pointerMap.end()) {
+    Code* m = I->second;
+    if (Addr >= m->FunctionStart) return m;
+  }
+
+  return 0;
+}
+
+void mvm::jit::addMethodInfo(void* Addr, Code* C) {
+  lock.lock();
+  pointerMap.insert(std::make_pair(Addr, C));
+  lock.unlock();
 }

Modified: vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp?rev=51710&r1=51709&r2=51710&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp (original)
+++ vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp Thu May 29 17:26:00 2008
@@ -9,6 +9,7 @@
 
 #include <assert.h>
 
+#include "mvm/JIT.h"
 #include "mvm/Method.h"
 #include "mvm/Object.h"
 
@@ -19,54 +20,37 @@
 
 unsigned char* MvmMemoryManager::startFunctionBody(const Function* F, 
                                                    uintptr_t &ActualSize) {
-  size_t nbb = ((ActualSize - 1) & -4) + 4 + sizeof(Method *);
-#ifdef MULTIPLE_GC
-  Collector* GC = GCMap[F->getParent()];
-  assert(GC && "GC not available in a multi-GC environment");
-  Code *res = (Code *)gc::operator new(nbb, Code::VT, GC);
-  Method* meth = collector_new(Method, GC)(res, ActualSize);
-#else
-  Code *res = (Code *)gc::operator new(nbb, Code::VT);
-  Method* meth = gc_new(Method)(res, ActualSize);
-#endif
-  meth->llvmFunction = F;
-  res->method(meth);
+  Code* meth = new Code(); 
   currentMethod = meth;
-  Object::pushRoot(meth);
-  return (unsigned char*)((unsigned int*)res + 2);
+  return realMemoryManager->startFunctionBody(F, ActualSize); 
 }
 
 unsigned char *MvmMemoryManager::allocateStub(const GlobalValue* GV,
                                               unsigned StubSize, 
                                               unsigned Alignment) {
-  size_t nbb = ((StubSize - 1) & -4) + 4 + sizeof(Method *);
-#ifdef MULTIPLE_GC
-  Code *res = 0;
-  Method* meth = 0;
-  if (GV) { 
-    Collector* GC = GCMap[GV->getParent()];
-    res = (Code *)gc::operator new(nbb, Code::VT, GC); 
-    meth = collector_new(Method, GC)(res, StubSize);
-  } else {
-    res = (Code *)gc::operator new(nbb, Code::VT); 
-    meth = gc_new(Method)(res, StubSize);
-  }
-#else
-  Code *res = (Code *)gc::operator new(nbb, Code::VT); 
-  Method* meth = gc_new(Method)(res, StubSize);
-#endif
-  res->method(meth);
-  Object::pushRoot(meth);
-  return (unsigned char*)((unsigned int*)res + 2);
+  unsigned char* res = realMemoryManager->allocateStub(GV, StubSize, Alignment); 
+  Code* meth = new Code();
+  mvm::jit::addMethodInfo((void*)(res + StubSize), meth);
+  currentMethod = meth;
+  meth->FunctionStart = res;
+  meth->FunctionEnd = res + StubSize;
+  currentMethod = meth;
+
+  return res;
 }
 
 void MvmMemoryManager::endFunctionBody(const Function *F, 
                                        unsigned char *FunctionStart,
                                        unsigned char *FunctionEnd) {
+  mvm::jit::addMethodInfo((void*)FunctionEnd, currentMethod);
+  currentMethod->FunctionStart = FunctionStart;
+  currentMethod->FunctionEnd = FunctionEnd;
+  realMemoryManager->endFunctionBody(F, FunctionStart, FunctionEnd);
 }
 
 
 void MvmMemoryManager::deallocateMemForFunction(const Function *F) {
+  realMemoryManager->deallocateMemForFunction(F);
 }
 
 void MvmMemoryManager::AllocateGOT() {
@@ -81,25 +65,16 @@
 
 unsigned char *MvmMemoryManager::startExceptionTable(const Function* F, 
                                                      uintptr_t &ActualSize) {
-#ifdef MULTIPLE_GC
-  Collector* GC = GCMap[F->getParent()];
-  assert(GC && "GC not available in a multi-GC environment");
-  ExceptionTable *res = (ExceptionTable*)gc::operator new(ActualSize + 4, 
-                                                          ExceptionTable::VT,
-                                                          GC);
-#else
-  ExceptionTable *res = (ExceptionTable*)gc::operator new(ActualSize + 4, 
-                                                          ExceptionTable::VT);
-#endif
-  currentMethod->exceptionTable(res);
-  return (unsigned char*)((unsigned int*)res + 2);
+  unsigned char* res = realMemoryManager->startExceptionTable(F, ActualSize);
+  
+  currentMethod->exceptionTable = res;
+  return (unsigned char*)res;
 }                                                     
 
 void MvmMemoryManager::endExceptionTable(const Function *F, 
                                          unsigned char *TableStart,
                                          unsigned char *TableEnd,
                                          unsigned char* FrameRegister) {
-  ExceptionTable* table = currentMethod->exceptionTable();
-  table->frameRegister(FrameRegister);
+  realMemoryManager->endExceptionTable(F, TableStart, TableEnd, FrameRegister);
+  currentMethod->frameRegister = FrameRegister;
 }
-

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Object.cpp Thu May 29 17:26:00 2008
@@ -20,9 +20,6 @@
 
 
 VirtualTable *Object::VT = 0;
-VirtualTable *Method::VT = 0;
-VirtualTable *Code::VT = 0;
-VirtualTable *ExceptionTable::VT = 0;
 VirtualTable *NativeString::VT = 0;
 VirtualTable *PrintBuffer::VT = 0;
 
@@ -62,28 +59,12 @@
   X::VT = ((void**)(void*)(&fake))[0]; }
   
   INIT(Object);
-  INIT(Method);
-  INIT(Code);
   INIT(NativeString);
   INIT(PrintBuffer);
-  INIT(ExceptionTable);
   
 #undef INIT
 }
 
-void Code::TRACER {
-  this->method()->MARK_AND_TRACE;
-}
-
-void Method::TRACER {
-  Method *const self= (Method *)this;
-  self->definition()->MARK_AND_TRACE;
-  self->literals()->MARK_AND_TRACE;
-  self->name()->MARK_AND_TRACE;
-  self->code()->MARK_AND_TRACE;
-  self->exceptionTable()->MARK_AND_TRACE;
-}
-
 void PrintBuffer::TRACER {
   ((PrintBuffer *)this)->contents()->MARK_AND_TRACE;
 }
@@ -142,22 +123,6 @@
   buf->write(">");
 }
 
-void Code::print(PrintBuffer *buf) const {
-  buf->write("Code<");
-  buf->write(">");
-}
-
-void Method::print(PrintBuffer *buf) const {
-  Method *const self= (Method *)this;
-  buf->write("Method<");
-  if (self->name()) {
-    self->name()->print(buf);
-  } else {
-    buf->write("lambda");
-  }
-  buf->write(">");
-}
-
 void NativeString::print(PrintBuffer *buf) const {
   NativeString *const self= (NativeString *)this;
   buf->write("\"");

Modified: vmkit/trunk/lib/N3/VMCore/BackTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/BackTrace.cpp?rev=51710&r1=51709&r2=51710&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/BackTrace.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/BackTrace.cpp Thu May 29 17:26:00 2008
@@ -32,20 +32,16 @@
 
 void CLIJit::printBacktrace() {
   int* ips[100];
-  int real_size = backtrace((void**)(void*)ips, 100);
+  int real_size = mvm::jit::getBacktrace((void**)(void*)ips, 100);
   int n = 0;
   while (n < real_size) {
-    mvm::Code* code = mvm::Code::getCodeFromPointer(ips[n++]);
+    mvm::Code* code = mvm::jit::getCodeFromPointer(ips[n++]);
     if (code) {
-      mvm::Method* m = code->method();
-      mvm::Object* meth = m->definition();
-      if (meth && meth->getVirtualTable() == VMMethod::VT) {
+      VMMethod* meth = (VMMethod*)code->getMetaInfo();
+      if (meth) {
         printf("; %p in %s\n",  ips[n - 1], meth->printString());
-      } else if (m->llvmFunction) {
-        printf("; %p in %s\n",  ips[n - 1],
-                   m->llvmFunction->getNameStr().c_str());
       } else {
-        printf("; %p in %s\n",  ips[n - 1], "stub (probably)");
+        printf("; %p in %s\n",  ips[n - 1], "unknown");
       }
     } else {
       Dl_info info;
@@ -63,15 +59,14 @@
 
 Assembly* Assembly::getExecutingAssembly() {
   int* ips[10];
-  int real_size = backtrace((void**)(void*)ips, 10);
+  int real_size = mvm::jit::getBacktrace((void**)(void*)ips, 10);
   int n = 0;
   while (n < real_size) {
-    mvm::Code* code = mvm::Code::getCodeFromPointer(ips[n++]);
+    mvm::Code* code = mvm::jit::getCodeFromPointer(ips[n++]);
     if (code) {
-      mvm::Method* m = code->method();
-      mvm::Object* meth = m->definition();
-      if (meth && meth->getVirtualTable() == VMMethod::VT) {
-        return ((VMMethod*)meth)->classDef->assembly;
+      VMMethod* meth = (VMMethod*)code->getMetaInfo();
+      if (meth) {
+        return meth->classDef->assembly;
       }
     }
   }
@@ -80,16 +75,15 @@
 
 Assembly* Assembly::getCallingAssembly() {
   int* ips[10];
-  int real_size = backtrace((void**)(void*)ips, 10);
+  int real_size = mvm::jit::getBacktrace((void**)(void*)ips, 10);
   int n = 0;
   int i = 0;
   while (n < real_size) {
-    mvm::Code* code = mvm::Code::getCodeFromPointer(ips[n++]);
+    mvm::Code* code = mvm::jit::getCodeFromPointer(ips[n++]);
     if (code) {
-      mvm::Method* m = code->method();
-      mvm::Object* meth = m->definition();
-      if (meth && i >= 1 && meth->getVirtualTable() == VMMethod::VT) {
-        return ((VMMethod*)meth)->classDef->assembly;
+      VMMethod* meth = (VMMethod*)code->getMetaInfo();
+      if (meth && i >= 1) {
+        return meth->classDef->assembly;
       } else {
         ++i;
       }

Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=51710&r1=51709&r2=51710&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Thu May 29 17:26:00 2008
@@ -240,7 +240,6 @@
   void* tracer = mvm::jit::executionEngine->getPointerToGlobal(func);
   ((void**)res)[VT_TRACER_OFFSET] = tracer;
   cl->virtualTracer = func;
-  cl->codeVirtualTracer = mvm::Code::getCodeFromPointer(tracer);
 #endif
 
   return res;
@@ -291,10 +290,8 @@
   
   if (!stat) {
     cl->virtualTracer = func;
-    cl->codeVirtualTracer = mvm::Code::getCodeFromPointer(tracer);
   } else {
     cl->staticTracer = func;
-    cl->codeStaticTracer = mvm::Code::getCodeFromPointer(tracer);
   }
 #endif
   return res;
@@ -1473,15 +1470,6 @@
 }
 
 
-extern "C" bool isInCode(void* value) {
-  mvm::Object *obj = mvm::Code::getCodeFromPointer(value);
-  if (obj && obj->getVirtualTable() == mvm::Code::VT) {
-    return true;
-  } else {
-    return false;
-  }
-}
-
 extern "C" VMObject* newString(const UTF8* utf8) {
   CLIString * str = 
     (CLIString*)(((N3*)VMThread::get()->vm)->UTF8ToStr(utf8));
@@ -1880,16 +1868,6 @@
                      module);
   }
   
-  // Create isInCodeLLVM
-  {
-  std::vector<const Type*> args;
-  args.push_back(VMObject::llvmType);
-  const FunctionType* type = FunctionType::get(Type::Int1Ty, args, false);
-
-  isInCodeLLVM = Function::Create(type, GlobalValue::ExternalLinkage, "isInCode",
-                              module);
-  }
-  
   // Create arrayMultiConsLLVM
   {
   std::vector<const Type*> args;

Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.h?rev=51710&r1=51709&r2=51710&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIJit.h (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIJit.h Thu May 29 17:26:00 2008
@@ -152,7 +152,6 @@
   static llvm::Function* clearExceptionLLVM;
   static llvm::Function* compareExceptionLLVM;
   static llvm::Function* classCastExceptionLLVM;
-  static llvm::Function* isInCodeLLVM;
   static llvm::Function* newStringLLVM;
   static llvm::Function* arrayLengthLLVM;
 

Modified: vmkit/trunk/lib/N3/VMCore/N3.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3.cpp?rev=51710&r1=51709&r2=51710&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3.cpp Thu May 29 17:26:00 2008
@@ -74,6 +74,7 @@
   CLIJit::initialiseBootstrapVM(vm);
   
   vm->bootstrapThread = VMThread::allocate(0, vm);
+  vm->bootstrapThread->baseSP = mvm::Thread::get()->baseSP;
 #ifdef MULTIPLE_GC
   vm->bootstrapThread->GC = GC;
   mvm::jit::memoryManager->addGCForModule(vm->module, GC);
@@ -107,6 +108,7 @@
   CLIJit::initialiseAppDomain(vm);
 
   vm->bootstrapThread = VMThread::allocate(0, vm);
+  vm->bootstrapThread->baseSP = mvm::Thread::get()->baseSP;
 #ifdef MULTIPLE_GC
   vm->bootstrapThread->GC = GC;
   mvm::jit::memoryManager->addGCForModule(vm->module, GC);

Modified: vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp?rev=51710&r1=51709&r2=51710&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp Thu May 29 17:26:00 2008
@@ -141,7 +141,6 @@
 llvm::Function* CLIJit::objInitLLVM;
 llvm::Function* CLIJit::throwExceptionLLVM;
 llvm::Function* CLIJit::instanceOfLLVM;
-llvm::Function* CLIJit::isInCodeLLVM;
 llvm::Function* CLIJit::getCLIExceptionLLVM;
 llvm::Function* CLIJit::getCppExceptionLLVM;
 llvm::Function* CLIJit::newStringLLVM;

Modified: vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp?rev=51710&r1=51709&r2=51710&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp Thu May 29 17:26:00 2008
@@ -40,8 +40,9 @@
       if (res == 0) {
         CLIJit::compile(meth->classDef, meth);
         void* res = mvm::jit::executionEngine->getPointerToGlobal(meth->methPtr);
-        meth->code = mvm::Code::getCodeFromPointer(res);
-        meth->code->method()->definition(meth);
+        meth->code = res;
+        mvm::Code* code = mvm::jit::getCodeFromPointer(res);
+        code->setMetaInfo(meth);
       }
       meth->classDef->release();
       meth->classDef->resolveStatic(true);

Modified: vmkit/trunk/lib/N3/VMCore/Opcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Opcodes.cpp?rev=51710&r1=51709&r2=51710&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Opcodes.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Opcodes.cpp Thu May 29 17:26:00 2008
@@ -687,11 +687,6 @@
 
       case ENDFINALLY : {
         Value* val = new LoadInst(supplLocal, "", currentBlock);
-        /*Value* call = CallInst::Create(isInCodeLLVM, val, "", currentBlock);
-        BasicBlock* bb1 = createBasicBlock("end finally");
-        BasicBlock* bb2 = createBasicBlock("no end finally");
-        BranchInst::Create(bb1, bb2, call, currentBlock);
-        currentBlock = bb1;*/
         val = new PtrToIntInst(val, Type::Int32Ty, "", currentBlock);
         SwitchInst* inst = SwitchInst::Create(val, leaves[0], 
                                           leaves.size(), currentBlock);

Modified: vmkit/trunk/lib/N3/VMCore/VMClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.h?rev=51710&r1=51709&r2=51710&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMClass.h (original)
+++ vmkit/trunk/lib/N3/VMCore/VMClass.h Thu May 29 17:26:00 2008
@@ -66,8 +66,6 @@
   
   llvm::Function* virtualTracer;
   llvm::Function* staticTracer;
-  mvm::Code* codeVirtualTracer;
-  mvm::Code* codeStaticTracer;
 
   uint32 superToken;
   uint32 token;
@@ -208,7 +206,7 @@
   bool virt;
   bool canBeInlined;
 
-  mvm::Code* code;
+  void* code;
   
   llvm::GenericValue operator()(...);
   llvm::GenericValue operator()(va_list ap);

Modified: vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp?rev=51710&r1=51709&r2=51710&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp Thu May 29 17:26:00 2008
@@ -159,8 +159,6 @@
   assembly->MARK_AND_TRACE;
   //funcs->MARK_AND_TRACE;
   TRACE_VECTOR(Property*, properties, gc_allocator);
-  codeVirtualTracer->MARK_AND_TRACE;
-  codeStaticTracer->MARK_AND_TRACE;
 }
 
 void VMClass::TRACER {
@@ -189,7 +187,6 @@
   TRACE_VECTOR(Param*, params, gc_allocator);
   TRACE_VECTOR(Enveloppe*, caches, gc_allocator);
   name->MARK_AND_TRACE;
-  code->MARK_AND_TRACE;
 }
 
 void VMField::TRACER {





More information about the llvm-commits mailing list