[vmkit-commits] [vmkit] r66348 - in /vmkit/trunk: include/jnjvm/ include/mvm/ lib/JnJVM/Compiler/ lib/JnJVM/VMCore/ lib/Mvm/Runtime/ tools/jnjvm/ tools/vmjc/ tools/vmkit/

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sat Mar 7 13:25:47 PST 2009


Author: geoffray
Date: Sat Mar  7 15:25:46 2009
New Revision: 66348

URL: http://llvm.org/viewvc/llvm-project?rev=66348&view=rev
Log:
Make the VM unaware of a module provider.


Modified:
    vmkit/trunk/include/jnjvm/JnjvmModule.h
    vmkit/trunk/include/jnjvm/JnjvmModuleProvider.h
    vmkit/trunk/include/mvm/CompilationUnit.h
    vmkit/trunk/include/mvm/JIT.h
    vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleAOT.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleJIT.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h
    vmkit/trunk/lib/Mvm/Runtime/JIT.cpp
    vmkit/trunk/tools/jnjvm/Main.cpp
    vmkit/trunk/tools/vmjc/vmjc.cpp
    vmkit/trunk/tools/vmkit/Launcher.cpp

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

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Sat Mar  7 15:25:46 2009
@@ -342,6 +342,8 @@
   
   void internalMakeVT(Class* cl);
 
+  void addJavaPasses();
+
 private: 
   
   static void initialise();
@@ -415,6 +417,9 @@
    
   llvm::FunctionPassManager* JavaFunctionPasses;
   llvm::FunctionPassManager* JavaNativeFunctionPasses;
+  
+  virtual llvm::Function* addCallback(Class* cl, uint16 index, Signdef* sign,
+                                      bool stat) = 0;
 
 
 };
@@ -456,6 +461,9 @@
 #endif
   
   virtual ~JnjvmModuleJIT() {}
+  
+  virtual llvm::Function* addCallback(Class* cl, uint16 index, Signdef* sign,
+                                      bool stat);
 
 };
 
@@ -477,6 +485,9 @@
     abort();
   }
   
+  virtual llvm::Function* addCallback(Class* cl, uint16 index, Signdef* sign,
+                                      bool stat);
+  
   virtual void makeVT(Class* cl);
   
   virtual llvm::Constant* getFinalObject(JavaObject* obj);

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

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModuleProvider.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModuleProvider.h Sat Mar  7 15:25:46 2009
@@ -12,35 +12,21 @@
 
 #include <llvm/ModuleProvider.h>
 
-using namespace llvm;
-
-namespace llvm {
-class FunctionPassManager;
-}
-
 namespace jnjvm {
 
-class JnjvmModule;
-
-class JnjvmModuleProvider : public ModuleProvider {
-private:
-  JavaMethod* staticLookup(Class* caller, uint32 index);
-  
-  uint32 nbCallbacks;
+class JnjvmModuleJIT;
 
+class JnjvmModuleProvider : public llvm::ModuleProvider {
 public:
-  
-  JnjvmModuleProvider(JnjvmModule *m);
+   
+  JnjvmModuleProvider(JnjvmModuleJIT *m);
   ~JnjvmModuleProvider();
-  
-  llvm::Function* addCallback(Class* cl, uint32 index, Signdef* sign,
-                              bool stat);
-
-  bool materializeFunction(Function *F, std::string *ErrInfo = 0);
 
-  Module* materializeModule(std::string *ErrInfo = 0) { return TheModule; }
+  bool materializeFunction(llvm::Function *F, std::string *ErrInfo = 0);
 
-  void printStats();
+  llvm::Module* materializeModule(std::string *ErrInfo = 0) { 
+    return TheModule;
+  }
 };
 
 } // End jnjvm namespace

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

==============================================================================
--- vmkit/trunk/include/mvm/CompilationUnit.h (original)
+++ vmkit/trunk/include/mvm/CompilationUnit.h Sat Mar  7 15:25:46 2009
@@ -17,12 +17,6 @@
 
 #include "mvm/Object.h"
 
-namespace llvm {
-  class FunctionPassManager;
-  class Module;
-  class ModuleProvider;
-}
-
 namespace mvm {
 
 class MvmModule;
@@ -30,7 +24,6 @@
 class CompilationUnit : public mvm::Object {
 public:
   MvmModule* TheModule;
-  llvm::ModuleProvider* TheModuleProvider;
 
   void AddStandardCompilePasses();
 };

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

==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Sat Mar  7 15:25:46 2009
@@ -25,6 +25,7 @@
   class Function;
   class FunctionPassManager;
   class Module;
+  class ModuleProvider;
   class PointerType;
   class TargetData;
   class TargetMachine;
@@ -58,12 +59,13 @@
 class MvmModule {
 protected:
   llvm::Module* TheModule;
+  llvm::ModuleProvider* TheModuleProvider;
 
 public:
   
   explicit MvmModule(const std::string& ModuleID);
  
-  virtual ~MvmModule() {}
+  virtual ~MvmModule();
 
   llvm::Module* getLLVMModule() {
     return TheModule;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Sat Mar  7 15:25:46 2009
@@ -39,6 +39,7 @@
 #include "Reader.h"
 
 #include "jnjvm/JnjvmModule.h"
+#include "jnjvm/JnjvmModuleProvider.h"
 
 using namespace jnjvm;
 using namespace llvm;
@@ -1233,6 +1234,7 @@
 
 void JavaJIT::invokeSpecial(uint16 index, CommonClass* finalCl) {
   JavaConstantPool* ctpInfo = compilingClass->ctpInfo;
+  JnjvmClassLoader* JCL = compilingClass->classLoader;
   JavaMethod* meth = 0;
   Signdef* signature = 0;
   const UTF8* name = 0;
@@ -1253,16 +1255,10 @@
 
     meth = lookup->lookupMethodDontThrow(name, signature->keyName, false, true,
                                          0);
-    if (meth) {
-      // don't throw if no meth, the exception will be thrown just in time
-      JnjvmModule* M = compilingClass->classLoader->getModule();
-      func = M->getMethod(meth);
-    }
   }
   
-  if (!func) {
-    func = (Function*)ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL,
-                                                           signature, meth);
+  if (!meth) {
+    meth = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL, signature);
   }
   
   if (meth == compilingClass->classLoader->bootstrapLoader->upcalls->InitObject)
@@ -1304,6 +1300,10 @@
     if (!cl) {
       CallInst::Create(module->ForceLoadedCheckFunction, Cl, "", currentBlock);
     }
+    func =  JCL->getModule()->addCallback(compilingClass, index,
+                                          signature, false);
+  } else {
+    func = JCL->getModule()->getMethod(meth);
   }
 
   if (meth && canBeInlined(meth)) {
@@ -1324,7 +1324,7 @@
 
 void JavaJIT::invokeStatic(uint16 index) {
   JavaConstantPool* ctpInfo = compilingClass->ctpInfo;
-  JavaMethod* meth = 0;
+  JnjvmClassLoader* JCL = compilingClass->classLoader;
   Signdef* signature = 0;
   const UTF8* name = 0;
   const UTF8* cl = 0;
@@ -1348,10 +1348,17 @@
   }
 
   if (!val) {
-    Function* func = (Function*)
-      ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_STATIC,
-                                           signature, meth);
+    JavaMethod* meth = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_STATIC,
+                                                            signature);
     
+    Function* func = 0;
+    if (meth) {
+      func = JCL->getModule()->getMethod(meth);
+    } else {
+      func = JCL->getModule()->addCallback(compilingClass, index,
+                                           signature, true);
+    }
+
 #if defined(ISOLATE_SHARING)
     Value* newCtpCache = getConstantPoolAt(index,
                                            module->StaticCtpLookupFunction,

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Sat Mar  7 15:25:46 2009
@@ -13,6 +13,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
+#include "llvm/Target/TargetData.h"
 
 #include "mvm/JIT.h"
 
@@ -523,3 +524,25 @@
   delete JavaFunctionPasses;
   delete JavaNativeFunctionPasses;
 }
+
+namespace mvm {
+  llvm::FunctionPass* createEscapeAnalysisPass(llvm::Function*);
+}
+
+namespace jnjvm {
+  llvm::FunctionPass* createLowerConstantCallsPass();
+}
+
+void JnjvmModule::addJavaPasses() {
+  JavaNativeFunctionPasses = new FunctionPassManager(TheModuleProvider);
+  JavaNativeFunctionPasses->add(new TargetData(TheModule));
+  // Lower constant calls to lower things like getClass used
+  // on synchronized methods.
+  JavaNativeFunctionPasses->add(createLowerConstantCallsPass());
+  
+  JavaFunctionPasses = new FunctionPassManager(TheModuleProvider);
+  JavaFunctionPasses->add(new TargetData(TheModule));
+  Function* func = JavaObjectAllocateFunction;
+  JavaFunctionPasses->add(mvm::createEscapeAnalysisPass(func));
+  JavaFunctionPasses->add(createLowerConstantCallsPass());
+}

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleAOT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleAOT.cpp Sat Mar  7 15:25:46 2009
@@ -1,4 +1,4 @@
-//===--------- JnjvmModule.cpp - Definition of a Jnjvm module -------------===//
+//===----- JnjvmModuleAOT.cpp - Support for Ahead of Time Compiler --------===//
 //
 //                              JnJVM
 //
@@ -11,6 +11,8 @@
 #include "llvm/Constants.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
+#include "llvm/ModuleProvider.h"
+#include "llvm/PassManager.h"
 
 #include "mvm/Threads/Thread.h"
 
@@ -1195,6 +1197,14 @@
 }
 #endif
 
+namespace mvm {
+  llvm::FunctionPass* createEscapeAnalysisPass(llvm::Function*);
+}
+
+namespace jnjvm {
+  llvm::FunctionPass* createLowerConstantCallsPass();
+}
+
 JnjvmModuleAOT::JnjvmModuleAOT(const std::string& ModuleID) :
   JnjvmModule(ModuleID) {
  
@@ -1251,6 +1261,10 @@
   FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
   ObjectPrinter = Function::Create(FTy, GlobalValue::ExternalLinkage,
                                    "printJavaObject", getLLVMModule());
+
+  TheModuleProvider = new ExistingModuleProvider(TheModule);
+  addJavaPasses();
+      
 }
 
 void JnjvmModuleAOT::printStats() {
@@ -1415,3 +1429,20 @@
   func->setName(name);
   func->setLinkage(GlobalValue::ExternalLinkage);
 }
+
+Function* JnjvmModuleAOT::addCallback(Class* cl, uint16 index,
+                                      Signdef* sign, bool stat) {
+ 
+  fprintf(stderr, "Warning: emitting a callback from %s (%d)\n",
+          cl->printString(), index);
+  Function* func = 0;
+  LLVMSignatureInfo* LSI = getSignatureInfo(sign);
+  
+  const FunctionType* type = stat ? LSI->getStaticType() : 
+                                    LSI->getVirtualType();
+  
+  func = Function::Create(type, GlobalValue::ExternalLinkage, "staticCallback",
+                          TheModule);
+  
+  return func;
+}

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleJIT.cpp Sat Mar  7 15:25:46 2009
@@ -1,4 +1,4 @@
-//===--------- JnjvmModule.cpp - Definition of a Jnjvm module -------------===//
+//===--------- JnjvmModuleJIT.cpp - Support for JIT compiling -------------===//
 //
 //                              JnJVM
 //
@@ -11,11 +11,11 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 #include "llvm/Instructions.h"
+#include "llvm/Module.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 
 #include "JavaConstantPool.h"
 #include "JavaThread.h"
-#include "Jnjvm.h"
 
 #include "jnjvm/JnjvmModule.h"
 #include "jnjvm/JnjvmModuleProvider.h"
@@ -127,6 +127,9 @@
  
   CI = ConstantInt::get(Type::Int64Ty, uint64(ArrayObjectVT));
   ReferenceArrayVT = ConstantExpr::getIntToPtr(CI, VTType);
+
+  TheModuleProvider = new JnjvmModuleProvider(this);
+  addJavaPasses();
 }
 
 #ifdef SERVICE

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp Sat Mar  7 15:25:46 2009
@@ -7,19 +7,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/LinkAllPasses.h"
-#include "llvm/PassManager.h"
+#include "llvm/Constants.h"
 #include "llvm/Module.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
-#include "llvm/Support/MutexGuard.h"
-#include "llvm/Target/TargetData.h"
 
 #include "mvm/JIT.h"
 
 #include "JavaAccess.h"
 #include "JavaClass.h"
 #include "JavaConstantPool.h"
-#include "JavaJIT.h"
 #include "JavaThread.h"
 #include "JavaTypes.h"
 #include "Jnjvm.h"
@@ -34,21 +30,23 @@
 static AnnotationID JavaCallback_ID(
   AnnotationManager::getID("Java::Callback"));
 
-
 class CallbackInfo: public Annotation {
 public:
   Class* cl;
-  uint32 index;
+  uint16 index;
+  bool stat;
 
-  CallbackInfo(Class* c, uint32 i) : Annotation(JavaCallback_ID), 
-    cl(c), index(i) {}
+  CallbackInfo(Class* c, uint32 i, bool s) : Annotation(JavaCallback_ID), 
+    cl(c), index(i), stat(s) {}
 };
 
-JavaMethod* JnjvmModuleProvider::staticLookup(Class* caller, uint32 index) {
+static JavaMethod* staticLookup(Function* F) {
+  CallbackInfo* CI = (CallbackInfo*)F->getAnnotation(JavaCallback_ID);
+  assert(CI && "No callback where there should be one");
+  Class* caller = CI->cl;
+  uint16 index = CI->index; 
+  bool isStatic = CI->stat;
   JavaConstantPool* ctpInfo = caller->getConstantPool();
-  
-
-  bool isStatic = ctpInfo->isAStaticCall(index);
 
   CommonClass* cl = 0;
   const UTF8* utf8 = 0;
@@ -60,18 +58,42 @@
                                           0);
 
   assert(lookup->isInitializing() && "Class not ready");
+ 
+  return meth;
+}
+
+
 
+Function* JnjvmModuleJIT::addCallback(Class* cl, uint16 index,
+                                      Signdef* sign, bool stat) {
   
-  return meth;
+  Function* func = 0;
+  LLVMSignatureInfo* LSI = getSignatureInfo(sign);
+  
+  const char* name = cl->printString();
+  char* key = (char*)alloca(strlen(name) + 16);
+  sprintf(key, "%s%d", name, index);
+  Function* F = TheModule->getFunction(key);
+  if (F) return F;
+  
+  const FunctionType* type = stat ? LSI->getStaticType() : 
+                                    LSI->getVirtualType();
+  
+  func = Function::Create(type, GlobalValue::GhostLinkage, key, TheModule);
+  
+  CallbackInfo* A = new CallbackInfo(cl, index, stat);
+  func->addAnnotation(A);
+  
+  return func;
 }
 
+
 bool JnjvmModuleProvider::materializeFunction(Function *F, 
                                               std::string *ErrInfo) {
   
   if (!(F->hasNotBeenReadFromBitcode())) 
     return false;
  
-  assert(mvm::MvmModule::executionEngine && "No execution engine");
   if (mvm::MvmModule::executionEngine->getPointerToGlobalIfAvailable(F))
     return false;
 
@@ -79,9 +101,7 @@
   
   if (!meth) {
     // It's a callback
-    CallbackInfo* CI = (CallbackInfo*)F->getAnnotation(JavaCallback_ID);
-    assert(CI && "No callback where there should be one");
-    meth = staticLookup(CI->cl, CI->index); 
+    meth = staticLookup(F);
   }
   
   void* val = meth->compiledPtr();
@@ -110,80 +130,15 @@
   return false;
 }
 
-llvm::Function* JnjvmModuleProvider::addCallback(Class* cl, uint32 index,
-                                                 Signdef* sign, bool stat) {
-  
-  JnjvmModule* M = cl->classLoader->getModule();
-  Function* func = 0;
-  LLVMSignatureInfo* LSI = M->getSignatureInfo(sign);
-  if (!stat) {
-    const char* name = cl->printString();
-    char* key = (char*)alloca(strlen(name) + 16);
-    sprintf(key, "%s%d", name, index);
-    Function* F = TheModule->getFunction(key);
-    if (F) return F;
-  
-    const FunctionType* type = LSI->getVirtualType();
-  
-    func = Function::Create(type, GlobalValue::GhostLinkage, key, TheModule);
-  } else {
-    const llvm::FunctionType* type = LSI->getStaticType();
-    if (M->isStaticCompiling()) {
-      func = Function::Create(type, GlobalValue::ExternalLinkage, "staticCallback",
-                              TheModule);
-    } else {
-      func = Function::Create(type, GlobalValue::GhostLinkage, "staticCallback",
-                              TheModule);
-    }
-  }
-  
-  ++nbCallbacks;
-  CallbackInfo* A = new CallbackInfo(cl, index);
-  func->addAnnotation(A);
-  
-  return func;
-}
-
-namespace mvm {
-  llvm::FunctionPass* createEscapeAnalysisPass(llvm::Function*);
-}
-
-namespace jnjvm {
-  llvm::FunctionPass* createLowerConstantCallsPass();
-}
-
-JnjvmModuleProvider::JnjvmModuleProvider(JnjvmModule *m) {
+JnjvmModuleProvider::JnjvmModuleProvider(JnjvmModuleJIT *m) {
   TheModule = m->getLLVMModule();
-  if (m->executionEngine) {
-    m->protectEngine.lock();
-    m->executionEngine->addModuleProvider(this);
-    m->protectEngine.unlock();
-  }
-    
-  m->JavaNativeFunctionPasses = new llvm::FunctionPassManager(this);
-  m->JavaNativeFunctionPasses->add(new llvm::TargetData(TheModule));
-  // Lower constant calls to lower things like getClass used
-  // on synchronized methods.
-  m->JavaNativeFunctionPasses->add(createLowerConstantCallsPass());
-  
-  m->JavaFunctionPasses = new llvm::FunctionPassManager(this);
-  m->JavaFunctionPasses->add(new llvm::TargetData(TheModule));
-  Function* func = m->JavaObjectAllocateFunction;
-  m->JavaFunctionPasses->add(mvm::createEscapeAnalysisPass(func));
-  m->JavaFunctionPasses->add(createLowerConstantCallsPass());
-  nbCallbacks = 0;
+  m->protectEngine.lock();
+  m->executionEngine->addModuleProvider(this);
+  m->protectEngine.unlock();
 }
 
 JnjvmModuleProvider::~JnjvmModuleProvider() {
-  if (mvm::MvmModule::executionEngine) {
-    mvm::MvmModule::protectEngine.lock();
-    mvm::MvmModule::executionEngine->removeModuleProvider(this);
-    mvm::MvmModule::protectEngine.unlock();
-  }
-  delete TheModule;
-}
-
-void JnjvmModuleProvider::printStats() {
-  fprintf(stderr, "------------ Info from the module provider -------------\n");
-  fprintf(stderr, "Number of callbacks        : %d\n", nbCallbacks);
+  mvm::MvmModule::protectEngine.lock();
+  mvm::MvmModule::executionEngine->removeModuleProvider(this);
+  mvm::MvmModule::protectEngine.unlock();
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sat Mar  7 15:25:46 2009
@@ -23,7 +23,6 @@
 #include "JavaUpcalls.h"
 #include "Jnjvm.h"
 #include "JnjvmModule.h"
-#include "JnjvmModuleProvider.h"
 #include "LockedMap.h"
 #include "Reader.h"
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp Sat Mar  7 15:25:46 2009
@@ -21,7 +21,6 @@
 #include "JavaConstantPool.h"
 #include "Jnjvm.h"
 #include "JnjvmModule.h"
-#include "JnjvmModuleProvider.h"
 #include "JavaThread.h"
 #include "JavaTypes.h"
 #include "LockedMap.h"
@@ -405,49 +404,29 @@
   cl = resolveClassName(entry >> 16);
 }
 
-void* JavaConstantPool::infoOfStaticOrSpecialMethod(uint32 index, 
-                                                    uint32 access,
-                                                    Signdef*& sign,
-                                                    JavaMethod*& meth) {
+JavaMethod* JavaConstantPool::infoOfStaticOrSpecialMethod(uint32 index, 
+                                                          uint32 access,
+                                                          Signdef* sign) {
   uint8 id = typeAt(index);
   if (id != ConstantMethodref && id != ConstantInterfaceMethodref)
     JavaThread::get()->getJVM()->classFormatError(
               "bad constant pool number for method at entry %d", index);
   
-  sign = resolveNameAndSign(ctpDef[index] & 0xFFFF);
   sint32 entry = ctpDef[index];
   sint32 ntIndex = entry & 0xFFFF;
   const UTF8* utf8 = UTF8At(ctpDef[ntIndex] >> 16);
   CommonClass* cl = getMethodClassIfLoaded(entry >> 16);
+  JavaMethod* meth = 0;
   if (cl) {
     Class* lookup = cl->isArray() ? cl->super : cl->asClass();
     if (lookup->isResolved()) {
       // lookup the method
       meth = lookup->lookupMethodDontThrow(utf8, sign->keyName,
                                            isStatic(access), true, 0);
-      if (meth) { 
-        // don't throw if no meth, the exception will be thrown just in time
-        JnjvmModule* M = classDef->classLoader->getModule();
-        void* F = M->getMethod(meth);
-        return F;
-      }
     }
   }
- 
-  // If it's static we're not using ctpRes for anything. We can store
-  // the callback. If it's special, the ctpRes contains the offset in
-  // the virtual table, so we can't put the callback and must rely on
-  // the module provider to hash callbacks.
-  if (isStatic(access) && ctpRes[index]) return ctpRes[index];
-
-  void* val =
-    classDef->classLoader->getModuleProvider()->addCallback(classDef, index,
-                                                            sign,
-                                                            isStatic(access));
-        
-  if (isStatic(access)) ctpRes[index] = val;
   
-  return val;
+  return meth;
 }
 
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h Sat Mar  7 15:25:46 2009
@@ -188,14 +188,12 @@
   /// referenced at the given entry.
   Signdef* infoOfInterfaceOrVirtualMethod(uint32 index, const UTF8*& name);
 
-  /// infoOfStaticOrSpecialMethod - Get the JIT representation of a
-  /// non-virtual method. Also returns its signature and the Jnjvm
-  /// representation.
-  ///
-  void* infoOfStaticOrSpecialMethod(uint32 index,
-                                    uint32 access,
-                                    Signdef*& sign,
-                                    JavaMethod*& meth);
+  /// infoOfStaticOrSpecialMethod - Get the JavaMethod of a non-virtual
+  /// method. Return null if not loaded yet.
+  ///
+  JavaMethod* infoOfStaticOrSpecialMethod(uint32 index, uint32 access,
+                                          Signdef* sign);
+  
   
   /// nameOfStaticOrSpecialMethod - Get the name and the signature
   /// of a non-virtual method.

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Sat Mar  7 15:25:46 2009
@@ -75,7 +75,7 @@
 mvm::CompilationUnit* 
 mvm::VirtualMachine::initialiseJVM() {
   initialiseVT();
-  return gc_new(JnjvmBootstrapLoader)(0, 0);
+  return gc_new(JnjvmBootstrapLoader)(0);
 }
 
 mvm::VirtualMachine* mvm::VirtualMachine::createJVM(mvm::CompilationUnit* C) {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sat Mar  7 15:25:46 2009
@@ -29,7 +29,6 @@
 #include "JavaUpcalls.h"
 #include "Jnjvm.h"
 #include "JnjvmModule.h"
-#include "JnjvmModuleProvider.h"
 #include "LockedMap.h"
 #include "Reader.h"
 #include "Zip.h"
@@ -1206,7 +1205,6 @@
 
     // Print stats before quitting.
     M->printStats();
-    bootstrapLoader->getModuleProvider()->printStats();
 
   } catch(std::string str) {
     fprintf(stderr, "Error : %s\n", str.c_str());

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Sat Mar  7 15:25:46 2009
@@ -45,7 +45,6 @@
 #include "Jnjvm.h"
 #include "JnjvmClassLoader.h"
 #include "JnjvmModule.h"
-#include "JnjvmModuleProvider.h"
 #include "LockedMap.h"
 #include "Reader.h"
 #include "Zip.h"
@@ -63,8 +62,7 @@
 
 typedef void (*static_init_t)(JnjvmClassLoader*);
 
-JnjvmBootstrapLoader::JnjvmBootstrapLoader(JnjvmModule* Mod,
-                                           JnjvmModuleProvider* MP) {
+JnjvmBootstrapLoader::JnjvmBootstrapLoader(JnjvmModule* Mod) {
   
   hashUTF8 = new(allocator) UTF8Map(allocator, 0);
   classes = new(allocator) ClassMap();
@@ -268,7 +266,6 @@
 #undef DEF_UTF8
   
   TheModule = Mod;
-  TheModuleProvider = MP;
   
 }
 
@@ -276,7 +273,6 @@
                                    Jnjvm* I) {
   bootstrapLoader = JCL.bootstrapLoader;
   TheModule = bootstrapLoader->getModule()->Create("Applicative loader");
-  TheModuleProvider = new JnjvmModuleProvider(getModule());
   
   hashUTF8 = new(allocator) UTF8Map(allocator,
                                     bootstrapLoader->upcalls->ArrayOfChar);
@@ -819,7 +815,7 @@
     allocator.Deallocate(javaSignatures);
   }
 
-  delete TheModuleProvider;
+  delete TheModule;
 }
 
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Sat Mar  7 15:25:46 2009
@@ -37,7 +37,6 @@
 class Jnjvm;
 class JnjvmBootstrapLoader;
 class JnjvmModule;
-class JnjvmModuleProvider;
 class Signdef;
 class SignMap;
 class Typedef;
@@ -119,13 +118,6 @@
     return reinterpret_cast<JnjvmModule*>(TheModule);
   }
 
-  /// TheModuleProvider - JIT module provider for dynamic class loading and
-  /// lazy compilation.
-  ///
-  JnjvmModuleProvider* getModuleProvider() {
-    return reinterpret_cast<JnjvmModuleProvider*>(TheModuleProvider);
-  }
-
   /// tracer - Traces a JnjvmClassLoader for GC.
   ///
   virtual void TRACER;
@@ -221,7 +213,6 @@
     javaTypes = 0;
     javaSignatures = 0;
     TheModule = 0;
-    TheModuleProvider = 0;
     isolate = 0;
     classes = 0;
   }
@@ -342,7 +333,7 @@
   /// createBootstrapLoader - Creates the bootstrap loader, first thing
   /// to do before any execution of a JVM.
   ///
-  JnjvmBootstrapLoader(JnjvmModule* Mod, JnjvmModuleProvider* MP);
+  JnjvmBootstrapLoader(JnjvmModule* Mod);
   JnjvmBootstrapLoader() {}
   
   virtual JavaString* UTF8ToStr(const UTF8* utf8);

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/JIT.cpp Sat Mar  7 15:25:46 2009
@@ -337,3 +337,7 @@
                      SF->getName(), Dst);
   }
 }
+
+MvmModule::~MvmModule() {
+  delete TheModuleProvider;
+}

Modified: vmkit/trunk/tools/jnjvm/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/jnjvm/Main.cpp?rev=66348&r1=66347&r2=66348&view=diff

==============================================================================
--- vmkit/trunk/tools/jnjvm/Main.cpp (original)
+++ vmkit/trunk/tools/jnjvm/Main.cpp Sat Mar  7 15:25:46 2009
@@ -32,7 +32,6 @@
  
   CompilationUnit* CU = VirtualMachine::initialiseJVM();
   CU->TheModule = new JnjvmModuleJIT("JITModule");
-  CU->TheModuleProvider = new JnjvmModuleProvider((JnjvmModule*)CU->TheModule);
   CU->AddStandardCompilePasses();
   VirtualMachine* vm = VirtualMachine::createJVM(CU);
   vm->runApplication(argc, argv);

Modified: vmkit/trunk/tools/vmjc/vmjc.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=66348&r1=66347&r2=66348&view=diff

==============================================================================
--- vmkit/trunk/tools/vmjc/vmjc.cpp (original)
+++ vmkit/trunk/tools/vmjc/vmjc.cpp Sat Mar  7 15:25:46 2009
@@ -100,6 +100,9 @@
 AssumeCompiled("assume-compiled",
               cl::desc("Assume external Java classes are compiled"));
 
+static cl::opt<std::string>
+WithClinit("with-clinit", cl::desc("Clinit the given file"));
+
 
 
 inline void addPass(FunctionPassManager *PM, Pass *P) {
@@ -160,46 +163,59 @@
       cl::PrintHelpMessage();
       return 0;
     }
+   
+    JnjvmModule* Mod = 0;
+    if (WithClinit.empty()) {
+      Module* TheModule = new Module("bootstrap module");
+      if (!TargetTriple.empty())
+        TheModule->setTargetTriple(TargetTriple);
+      else
+        TheModule->setTargetTriple(LLVM_HOSTTRIPLE);
     
-    Module* TheModule = new Module("bootstrap module");
-    if (!TargetTriple.empty())
-      TheModule->setTargetTriple(TargetTriple);
-    else
-      TheModule->setTargetTriple(LLVM_HOSTTRIPLE);
-    
-    // Create the TargetMachine we will be generating code with.
-    std::string Err; 
-    const TargetMachineRegistry::entry *TME = 
-      TargetMachineRegistry::getClosestStaticTargetForModule(*TheModule, Err);
-    if (!TME) {
-      cerr << "Did not get a target machine!\n";
-      exit(1);
-    }
+      // Create the TargetMachine we will be generating code with.
+      std::string Err; 
+      const TargetMachineRegistry::entry *TME = 
+        TargetMachineRegistry::getClosestStaticTargetForModule(*TheModule, Err);
+      if (!TME) {
+        cerr << "Did not get a target machine!\n";
+        exit(1);
+      }
 
-    std::string FeatureStr;
-    TargetMachine* TheTarget = TME->CtorFn(*TheModule, FeatureStr);
+      std::string FeatureStr;
+      TargetMachine* TheTarget = TME->CtorFn(*TheModule, FeatureStr);
 
-    // Install information about target datalayout stuff into the module for
-    // optimizer use.
-    TheModule->setDataLayout(TheTarget->getTargetData()->
-                             getStringRepresentation());
+      // Install information about target datalayout stuff into the module for
+      // optimizer use.
+      TheModule->setDataLayout(TheTarget->getTargetData()->
+                               getStringRepresentation());
 
 
-    mvm::MvmModule::initialise(false, TheModule, TheTarget);
+      mvm::MvmModule::initialise(false, TheModule, TheTarget);
+      Mod = new JnjvmModuleAOT("AOT");
+    } else {
+      mvm::MvmModule::initialise(true);
+      Mod = new JnjvmModuleJIT("JIT");
+    }
+
     mvm::Object::initialise();
     Collector::initialise(0);
     Collector::enable(0);
 
     mvm::CompilationUnit* CU = mvm::VirtualMachine::initialiseJVM();
     addCommandLinePass(CU, argv);
-    JnjvmModuleAOT* Mod = new JnjvmModuleAOT("AOT");
-    JnjvmModuleProvider* MP = new JnjvmModuleProvider(Mod);
     CU->TheModule = Mod;
-    CU->TheModuleProvider = MP;
-    if (DisableExceptions) Mod->disableExceptions();
-    if (DisableTracers) Mod->generateTracers = false;
-    if (DisableStubs) Mod->generateStubs = false;
-    if (AssumeCompiled) Mod->assumeCompiled = true;
+
+    if (!WithClinit.empty()) {
+      // TODO
+      Mod = new JnjvmModuleAOT("AOT");
+      CU->TheModule = Mod;
+    }
+    
+    JnjvmModuleAOT* MAOT = (JnjvmModuleAOT*)Mod;
+    if (DisableExceptions) MAOT->disableExceptions();
+    if (DisableTracers) MAOT->generateTracers = false;
+    if (DisableStubs) MAOT->generateStubs = false;
+    if (AssumeCompiled) MAOT->assumeCompiled = true;
     mvm::VirtualMachine* vm = mvm::VirtualMachine::createJVM(CU);
     vm->compile(InputFilename.c_str());
     vm->waitForExit();

Modified: vmkit/trunk/tools/vmkit/Launcher.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmkit/Launcher.cpp?rev=66348&r1=66347&r2=66348&view=diff

==============================================================================
--- vmkit/trunk/tools/vmkit/Launcher.cpp (original)
+++ vmkit/trunk/tools/vmkit/Launcher.cpp Sat Mar  7 15:25:46 2009
@@ -140,7 +140,6 @@
 #if WITH_JNJVM
     mvm::CompilationUnit* CU = mvm::VirtualMachine::initialiseJVM();
     CU->TheModule = new JnjvmModuleJIT("JITModule");
-    CU->TheModuleProvider = new JnjvmModuleProvider((JnjvmModule*)CU->TheModule);
     addCommandLinePass(CU, argv);
     mvm::VirtualMachine* vm = mvm::VirtualMachine::createJVM(CU);
     vm->runApplication(argc, argv);
@@ -159,8 +158,6 @@
     mvm::CompilationUnit* JVMCompiler = 
       mvm::VirtualMachine::initialiseJVM();
     JVMCompiler->TheModule = new JnjvmModuleJIT("JITModule");
-    JVMCompiler->TheModuleProvider = 
-      new JnjvmModuleProvider((JnjvmModule*)JVMCompiler->TheModule);
     addCommandLinePass(JVMCompiler, argv);
     MyCl.vmlets["java"] = (mvm::VirtualMachine::createJVM);
     MyCl.compilers["java"] = JVMCompiler;





More information about the vmkit-commits mailing list