[vmkit-commits] [vmkit] r65555 - in /vmkit/trunk: include/jnjvm/ include/mvm/ include/mvm/Threads/ lib/JnJVM/Classpath/ lib/JnJVM/Compiler/ lib/JnJVM/VMCore/ lib/Mvm/Runtime/ lib/N3/Mono/ lib/N3/PNetLib/ lib/N3/VMCore/ tools/jnjvm/ tools/vmjc/ tools/vmkit/

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu Feb 26 10:44:00 PST 2009


Author: geoffray
Date: Thu Feb 26 12:44:00 2009
New Revision: 65555

URL: http://llvm.org/viewvc/llvm-project?rev=65555&view=rev
Log:
Completely rewrite the JnjvmModule abstraction in the JVM. We now have
two separate kinds of modules: AOT and JIT. The JVM lets the tool decide
which JIT it wants.

Because I had to use virtual functions, JnjvmModule could not extend
llvm::Module anymore. And since there was no real reason for it to
extend the llvm::Module class, I moved the llvm::Module object to
a field.

Also as a side-effect, I had to fix stack unwinding problems. Functions
that are involved in Java/native cross-calls and functions that get
the frame pointer now have a noinline attribute. This fixes the Debug
build on x86.


Added:
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleAOT.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleJIT.cpp
Modified:
    vmkit/trunk/include/jnjvm/JnjvmModule.h
    vmkit/trunk/include/mvm/JIT.h
    vmkit/trunk/include/mvm/Threads/Thread.h
    vmkit/trunk/include/mvm/VirtualMachine.h
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp
    vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h
    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/lib/N3/Mono/MonoString.cpp
    vmkit/trunk/lib/N3/PNetLib/PNetString.cpp
    vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
    vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp
    vmkit/trunk/lib/N3/VMCore/CLIRuntimeJIT.cpp
    vmkit/trunk/lib/N3/VMCore/N3.cpp
    vmkit/trunk/lib/N3/VMCore/VMThread.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=65555&r1=65554&r2=65555&view=diff

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Thu Feb 26 12:44:00 2009
@@ -184,97 +184,8 @@
 
 class JnjvmModule : public mvm::MvmModule {
   friend class LLVMClassInfo;
-private:
-  std::map<const CommonClass*, llvm::Constant*> nativeClasses;
-  std::map<const ClassArray*, llvm::GlobalVariable*> arrayClasses;
-  std::map<const CommonClass*, llvm::Constant*> javaClasses;
-  std::map<const CommonClass*, llvm::Constant*> virtualTables;
-  std::map<const Class*, llvm::Constant*> staticInstances;
-  std::map<const JavaConstantPool*, llvm::Constant*> constantPools;
-  std::map<const JavaString*, llvm::Constant*> strings;
-  std::map<const Enveloppe*, llvm::Constant*> enveloppes;
-  std::map<const JavaMethod*, llvm::Constant*> nativeFunctions;
-  std::map<const UTF8*, llvm::Constant*> utf8s;
-  std::map<const Class*, llvm::Constant*> virtualMethods;
-  std::map<const JavaObject*, llvm::Constant*> finalObjects;
-  
-  typedef std::map<const JavaObject*, llvm::Constant*>::iterator
-    final_object_iterator;
-  
-  typedef std::map<const Class*, llvm::Constant*>::iterator
-    method_iterator;
-  
-  typedef std::map<const CommonClass*, llvm::Constant*>::iterator
-    native_class_iterator; 
-  
-  typedef std::map<const ClassArray*, llvm::GlobalVariable*>::iterator
-    array_class_iterator;
-  
-  typedef std::map<const CommonClass*, llvm::Constant*>::iterator
-    java_class_iterator;
-  
-  typedef std::map<const CommonClass*, llvm::Constant*>::iterator
-    virtual_table_iterator;
-  
-  typedef std::map<const Class*, llvm::Constant*>::iterator
-    static_instance_iterator;
-  
-  typedef std::map<const JavaConstantPool*, llvm::Constant*>::iterator
-    constant_pool_iterator;
-  
-  typedef std::map<const JavaString*, llvm::Constant*>::iterator
-    string_iterator;
-  
-  typedef std::map<const Enveloppe*, llvm::Constant*>::iterator
-    enveloppe_iterator;
-  
-  typedef std::map<const JavaMethod*, llvm::Constant*>::iterator
-    native_function_iterator;
-  
-  typedef std::map<const UTF8*, llvm::Constant*>::iterator
-    utf8_iterator;
-  
-  
-  bool staticCompilation;
-  bool enabledException;
-
-#ifdef WITH_TRACER 
-  llvm::Function* makeTracer(Class* cl, bool stat);
-#endif
 
-  void makeVT(Class* cl);
-  void allocateVT(Class* cl);
-  
-  static llvm::Constant* PrimitiveArrayVT;
-  static llvm::Constant* ReferenceArrayVT;
-  
-  static llvm::Function* StaticInitializer;
-  static llvm::Function* ObjectPrinter;
-  
 public:
-  
-  static llvm::Function* NativeLoader;
-  
-  bool generateTracers;
-  bool generateStubs;
-  bool assumeCompiled;
-
-  bool isStaticCompiling() {
-    return staticCompilation;
-  }
-
-  bool hasExceptionsEnabled() {
-    return enabledException;
-  }
-  
-  void disableExceptions() {
-    enabledException = false;
-  }
-
-  void setIsStaticCompiling(bool sc) {
-    staticCompilation = sc;
-  }
-
   static llvm::ConstantInt* JavaArraySizeOffsetConstant;
   static llvm::ConstantInt* JavaArrayElementsOffsetConstant;
   static llvm::ConstantInt* JavaObjectLockOffsetConstant;
@@ -412,10 +323,59 @@
   llvm::Function* ClassCastExceptionFunction;
   llvm::Function* OutOfMemoryErrorFunction;
   llvm::Function* NegativeArraySizeExceptionFunction;
+  
+  static llvm::Function* NativeLoader;
+
+protected:
+#ifdef WITH_TRACER 
+  llvm::Function* internalMakeTracer(Class* cl, bool stat);
+  virtual llvm::Function* makeTracer(Class* cl, bool stat) {
+    return internalMakeTracer(cl, stat);
+  }
+#endif
+  
+  llvm::Constant* PrimitiveArrayVT;
+  llvm::Constant* ReferenceArrayVT;
+  
+  void internalMakeVT(Class* cl);
+
+private: 
+  
+  void initialise();
+  
+  bool enabledException;
+  
+  /// allocateVT - Allocate a VT for the class. The VT will be the VT of
+  /// instances of the class.
+  void allocateVT(Class* cl);
+
+
+  virtual void makeVT(Class* cl) = 0;
+  
+  
+  
+public:
+  
+  JnjvmModule(const std::string &ModuleID, JnjvmModule* Father = 0);
+  
+
+  virtual bool isStaticCompiling() = 0;
+
+  bool hasExceptionsEnabled() {
+    return enabledException;
+  }
+  
+  void disableExceptions() {
+    enabledException = false;
+  }
+  
+  virtual ~JnjvmModule() {}
+
+  llvm::Constant* getReferenceArrayVT();
+  llvm::Constant* getPrimitiveArrayVT();
 
   static void resolveVirtualClass(Class* cl);
   static void resolveStaticClass(Class* cl);
-  static void setMethod(JavaMethod* meth, void* ptr, const char* name);
   static llvm::Function* getMethod(JavaMethod* meth);
 
   static LLVMSignatureInfo* getSignatureInfo(Signdef* sign);
@@ -424,43 +384,99 @@
   static LLVMMethodInfo* getMethodInfo(JavaMethod* method);
   static LLVMAssessorInfo& getTypedefInfo(const Typedef* type);
   
-  explicit JnjvmModule(const std::string &ModuleID, bool sc = false);
-  void initialise();
-  void printStats();
 
-  llvm::Constant* getFinalObject(JavaObject* obj);
-  JavaObject* getFinalObject(llvm::Value* C);
-  llvm::Constant* getNativeClass(CommonClass* cl);
-  llvm::Constant* getJavaClass(CommonClass* cl);
-  llvm::Constant* getStaticInstance(Class* cl);
-  llvm::Constant* getVirtualTable(Class* cl);
-  llvm::Constant* getMethodInClass(JavaMethod* meth);
-  
-  llvm::Constant* getEnveloppe(Enveloppe* enveloppe);
-  llvm::Constant* getString(JavaString* str);
-  llvm::Constant* getConstantPool(JavaConstantPool* ctp);
-  llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr);
+  virtual llvm::Constant* getFinalObject(JavaObject* obj) = 0;
+  virtual JavaObject* getFinalObject(llvm::Value* C) = 0;
+  virtual llvm::Constant* getNativeClass(CommonClass* cl) = 0;
+  virtual llvm::Constant* getJavaClass(CommonClass* cl) = 0;
+  virtual llvm::Constant* getStaticInstance(Class* cl) = 0;
+  virtual llvm::Constant* getVirtualTable(Class* cl) = 0;
+  virtual llvm::Constant* getMethodInClass(JavaMethod* meth) = 0;
+  
+  virtual llvm::Constant* getEnveloppe(Enveloppe* enveloppe) = 0;
+  virtual llvm::Constant* getString(JavaString* str) = 0;
+  virtual llvm::Constant* getConstantPool(JavaConstantPool* ctp) = 0;
+  virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr) = 0;
+  
+  virtual void setMethod(JavaMethod* meth, void* ptr, const char* name) = 0;
   
-  llvm::Constant* getReferenceArrayVT();
-  llvm::Constant* getPrimitiveArrayVT();
 
 #ifdef SERVICE
-  std::map<const Jnjvm*, llvm::GlobalVariable*> isolates;
-  typedef std::map<const Jnjvm*, llvm::GlobalVariable*>::iterator
-    isolate_iterator;
+  virtual llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where) = 0;
+#endif
+
+};
+
+class JnjvmModuleJIT : public JnjvmModule {
+public:
+  JnjvmModuleJIT(const std::string &ModuleID, JnjvmModule* Father = 0);
+  
+  virtual bool isStaticCompiling() {
+    return false;
+  }
+  
+  virtual void makeVT(Class* cl);
+  
+  virtual llvm::Constant* getFinalObject(JavaObject* obj);
+  virtual JavaObject* getFinalObject(llvm::Value* C);
+  virtual llvm::Constant* getNativeClass(CommonClass* cl);
+  virtual llvm::Constant* getJavaClass(CommonClass* cl);
+  virtual llvm::Constant* getStaticInstance(Class* cl);
+  virtual llvm::Constant* getVirtualTable(Class* cl);
+  virtual llvm::Constant* getMethodInClass(JavaMethod* meth);
+  
+  virtual llvm::Constant* getEnveloppe(Enveloppe* enveloppe);
+  virtual llvm::Constant* getString(JavaString* str);
+  virtual llvm::Constant* getConstantPool(JavaConstantPool* ctp);
+  virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr);
   
-  llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where);
+  virtual void setMethod(JavaMethod* meth, void* ptr, const char* name);
+  
+
+#ifdef SERVICE
+  virtual llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where);
 #endif
   
+  virtual ~JnjvmModuleJIT() {}
 
-  bool isCompiling(const CommonClass* cl) const;
+};
+
+class JnjvmModuleAOT : public JnjvmModule {
+
+public:
+  JnjvmModuleAOT(const std::string &ModuleID, JnjvmModule* Father = 0);
   
-  void CreateStaticInitializer();
+  virtual bool isStaticCompiling() {
+    return true;
+  }
+  
+  virtual void makeVT(Class* cl);
+  
+  virtual llvm::Constant* getFinalObject(JavaObject* obj);
+  virtual JavaObject* getFinalObject(llvm::Value* C);
+  virtual llvm::Constant* getNativeClass(CommonClass* cl);
+  virtual llvm::Constant* getJavaClass(CommonClass* cl);
+  virtual llvm::Constant* getStaticInstance(Class* cl);
+  virtual llvm::Constant* getVirtualTable(Class* cl);
+  virtual llvm::Constant* getMethodInClass(JavaMethod* meth);
+  
+  virtual llvm::Constant* getEnveloppe(Enveloppe* enveloppe);
+  virtual llvm::Constant* getString(JavaString* str);
+  virtual llvm::Constant* getConstantPool(JavaConstantPool* ctp);
+  virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr);
+  
+  virtual void setMethod(JavaMethod* meth, void* ptr, const char* name);
   
-  static void setNoInline(Class* cl);
+
+#ifdef SERVICE
+  virtual llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where);
+#endif
+  
+  virtual ~JnjvmModuleAOT() {}
 
 private:
-  static llvm::Module* initialModule;
+  
+  virtual llvm::Function* makeTracer(Class* cl, bool stat);
   
   //--------------- Static compiler specific functions -----------------------//
   llvm::Constant* CreateConstantFromVT(Class* classDef);
@@ -483,6 +499,79 @@
   
   template<typename T>
   llvm::Constant* CreateConstantFromArray(T* val, const llvm::Type* Ty);
+  
+  std::map<const CommonClass*, llvm::Constant*> nativeClasses;
+  std::map<const ClassArray*, llvm::GlobalVariable*> arrayClasses;
+  std::map<const CommonClass*, llvm::Constant*> javaClasses;
+  std::map<const CommonClass*, llvm::Constant*> virtualTables;
+  std::map<const Class*, llvm::Constant*> staticInstances;
+  std::map<const JavaConstantPool*, llvm::Constant*> constantPools;
+  std::map<const JavaString*, llvm::Constant*> strings;
+  std::map<const Enveloppe*, llvm::Constant*> enveloppes;
+  std::map<const JavaMethod*, llvm::Constant*> nativeFunctions;
+  std::map<const UTF8*, llvm::Constant*> utf8s;
+  std::map<const Class*, llvm::Constant*> virtualMethods;
+  std::map<const JavaObject*, llvm::Constant*> finalObjects;
+  
+  typedef std::map<const JavaObject*, llvm::Constant*>::iterator
+    final_object_iterator;
+  
+  typedef std::map<const Class*, llvm::Constant*>::iterator
+    method_iterator;
+  
+  typedef std::map<const CommonClass*, llvm::Constant*>::iterator
+    native_class_iterator; 
+  
+  typedef std::map<const ClassArray*, llvm::GlobalVariable*>::iterator
+    array_class_iterator;
+  
+  typedef std::map<const CommonClass*, llvm::Constant*>::iterator
+    java_class_iterator;
+  
+  typedef std::map<const CommonClass*, llvm::Constant*>::iterator
+    virtual_table_iterator;
+  
+  typedef std::map<const Class*, llvm::Constant*>::iterator
+    static_instance_iterator;
+  
+  typedef std::map<const JavaConstantPool*, llvm::Constant*>::iterator
+    constant_pool_iterator;
+  
+  typedef std::map<const JavaString*, llvm::Constant*>::iterator
+    string_iterator;
+  
+  typedef std::map<const Enveloppe*, llvm::Constant*>::iterator
+    enveloppe_iterator;
+  
+  typedef std::map<const JavaMethod*, llvm::Constant*>::iterator
+    native_function_iterator;
+  
+  typedef std::map<const UTF8*, llvm::Constant*>::iterator
+    utf8_iterator;
+
+#ifdef SERVICE
+  virtual llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where);
+  std::map<const Jnjvm*, llvm::GlobalVariable*> isolates;
+  typedef std::map<const Jnjvm*, llvm::GlobalVariable*>::iterator
+    isolate_iterator; 
+#endif
+  
+  bool isCompiling(const CommonClass* cl) const;
+
+public:
+  llvm::Function* StaticInitializer;
+  llvm::Function* ObjectPrinter;
+  
+  bool generateTracers;
+  bool generateStubs;
+  bool assumeCompiled;
+  
+  
+  void CreateStaticInitializer();
+  
+  static void setNoInline(Class* cl);
+  
+  void printStats();
 
 
 };

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

==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Thu Feb 26 12:44:00 2009
@@ -12,8 +12,7 @@
 
 #include <cfloat>
 #include <cmath>
-
-#include "llvm/Module.h"
+#include <string>
 
 #include "types.h"
 
@@ -25,6 +24,7 @@
   class ExistingModuleProvider;
   class Function;
   class FunctionPassManager;
+  class Module;
   class PointerType;
   class TargetData;
   class TargetMachine;
@@ -55,10 +55,19 @@
 const float NaNFloat = NAN; //(float)(((float)0.0) / (float)0.0);
 const double NaNDouble = NAN; //0.0 / 0.0;
 
-class MvmModule : public llvm::Module {
+class MvmModule {
+protected:
+  llvm::Module* TheModule;
+
 public:
   
-  MvmModule(const std::string& ModuleID);
+  explicit MvmModule(const std::string& ModuleID);
+ 
+  virtual ~MvmModule() {}
+
+  llvm::Module* getLLVMModule() {
+    return TheModule;
+  }
   
   llvm::Function* exceptionEndCatch;
   llvm::Function* exceptionBeginCatch;

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

==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Thu Feb 26 12:44:00 2009
@@ -79,13 +79,22 @@
 };
 
 
+
 #if defined(__MACH__) && defined(__PPC__)
 #define FRAME_IP(fp) (fp[2])
 #else
 #define FRAME_IP(fp) (fp[1])
 #endif
 
+// Apparently gcc for i386 and family considers __builtin_frame_address(0) to
+// return the caller, not the current function.
+#if defined(__i386__) || defined(i386) || defined(_M_IX86) || \
+    defined(__x86_64__) || defined(_M_AMD64)
+#define FRAME_PTR() __builtin_frame_address(0)
+#else
 #define FRAME_PTR() (((void**)__builtin_frame_address(0))[0])
+#endif
+
 
 /// Thread - This class is the base of custom virtual machines' Thread classes.
 /// It provides static functions to manage threads. An instance of this class

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

==============================================================================
--- vmkit/trunk/include/mvm/VirtualMachine.h (original)
+++ vmkit/trunk/include/mvm/VirtualMachine.h Thu Feb 26 12:44:00 2009
@@ -54,7 +54,7 @@
   /// waitForExit - Wait until the virtual machine stops its execution.
   virtual void waitForExit() = 0;
 
-  static CompilationUnit* initialiseJVM(bool staticCompilation = false);
+  static CompilationUnit* initialiseJVM();
   static VirtualMachine* createJVM(CompilationUnit* C = 0);
   
   static CompilationUnit* initialiseCLIVM();

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp?rev=65555&r1=65554&r2=65555&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp Thu Feb 26 12:44:00 2009
@@ -65,15 +65,12 @@
   return res;
 }
 
-JNIEXPORT jobject JNICALL Java_java_lang_reflect_Constructor_constructNative(
-#ifdef NATIVE_JNI
-JNIEnv *env,
-#endif
-JavaObjectConstructor* cons, jobject _args, jclass Clazz, jint index) {
-
+static jobject proceed(JavaObjectConstructor* cons, jobject _args, jclass Clazz,
+                       jint index) __attribute__ ((noinline));
+ 
+static jobject proceed(JavaObjectConstructor* cons, jobject _args, jclass Clazz,
+                       jint index) {
   jobject res = 0;
-
-  
   Jnjvm* vm = JavaThread::get()->getJVM();
   JavaMethod* meth = cons->getInternalMethod();
   JavaArray* args = (JavaArray*)_args;
@@ -87,7 +84,6 @@
   void* startBuf = (void*)buf;
   
   // Do it after alloca
-  BEGIN_NATIVE_EXCEPTION(0)
 
   if (nbArgs == size) {
     UserCommonClass* _cl = 
@@ -128,6 +124,22 @@
   } else {
     vm->illegalArgumentExceptionForMethod(meth, 0, 0);
   }
+ 
+  return res;
+}
+
+JNIEXPORT jobject JNICALL Java_java_lang_reflect_Constructor_constructNative(
+#ifdef NATIVE_JNI
+JNIEnv *env,
+#endif
+JavaObjectConstructor* cons, jobject _args, jclass Clazz, jint index) {
+
+  jobject res = 0;
+  
+  BEGIN_NATIVE_EXCEPTION(0)
+
+  // Proceed in another function because we are using alloca.
+  res = proceed(cons, _args, Clazz, index);
   
   END_NATIVE_EXCEPTION
   

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp?rev=65555&r1=65554&r2=65555&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp Thu Feb 26 12:44:00 2009
@@ -85,15 +85,13 @@
   return res;
 }
 
-JNIEXPORT jobject JNICALL Java_java_lang_reflect_Method_invokeNative(
-#ifdef NATIVE_JNI
-JNIEnv *env, 
-#endif
-JavaObjectMethod* Meth, jobject _obj, jobject _args, jclass Cl, jint index) {
-  
-  JavaObject* res = 0;
+static jobject proceed(JavaObjectMethod* Meth, jobject _obj, jobject _args, 
+                       jclass Cl, jint index) __attribute__((noinline));
 
+static jobject proceed(JavaObjectMethod* Meth, jobject _obj, jobject _args, 
+                       jclass Cl, jint index) {
 
+  JavaObject* res = 0;
   Jnjvm* vm = JavaThread::get()->getJVM();
 
   JavaMethod* meth = Meth->getInternalMethod();
@@ -106,7 +104,6 @@
 
   uintptr_t buf = size ? (uintptr_t)alloca(size * sizeof(uint64)) : 0;
   
-  BEGIN_NATIVE_EXCEPTION(0)
 
   void* _buf = (void*)buf;
   if (nbArgs == size) {
@@ -219,13 +216,29 @@
     vm->illegalArgumentExceptionForMethod(meth, 0, 0); 
   }
 
+  return (jobject)res;
+}
+
+#undef RUN_METH
+
+JNIEXPORT jobject JNICALL Java_java_lang_reflect_Method_invokeNative(
+#ifdef NATIVE_JNI
+JNIEnv *env, 
+#endif
+JavaObjectMethod* Meth, jobject _obj, jobject _args, jclass Cl, jint index) {
+  
+  jobject res = 0;
+
+  BEGIN_NATIVE_EXCEPTION(0)
+
+  // Create a new function because we use alloca.
+  res = proceed(Meth, _obj, _args, Cl, index);
+  
   END_NATIVE_EXCEPTION
 
   return (jobject) res;
 }
 
-#undef RUN_METH
-
 JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_Method_getExceptionTypes(
 #ifdef NATIVE_JNI
 JNIEnv *env, 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Thu Feb 26 12:44:00 2009
@@ -957,8 +957,7 @@
     Value* res = getResolvedCommonClass(index, false, &cl);
 
 #ifndef ISOLATE
-    if (cl || (module->isStaticCompiling() && module->isCompiling(cl)))
-      res = module->getJavaClass(cl);
+    if (cl) res = module->getJavaClass(cl);
     else
 #endif
     

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Thu Feb 26 12:44:00 2009
@@ -10,50 +10,24 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
-#include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/Instructions.h"
-#include "llvm/Support/MutexGuard.h"
-#include "llvm/Target/TargetData.h"
-
 
 #include "mvm/JIT.h"
 
-#include "JavaCache.h"
-#include "JavaConstantPool.h"
-#include "JavaJIT.h"
-#include "JavaString.h"
-#include "JavaThread.h"
+#include "JavaArray.h"
+#include "JavaClass.h"
 #include "JavaTypes.h"
-#include "JavaUpcalls.h"
-#include "Jnjvm.h"
-#include "Reader.h"
 
 #include "jnjvm/JnjvmModule.h"
 #include "jnjvm/JnjvmModuleProvider.h"
 
-#include <cstdio>
-
 using namespace jnjvm;
 using namespace llvm;
 
-llvm::Constant* JnjvmModule::PrimitiveArrayVT;
-llvm::Constant* JnjvmModule::ReferenceArrayVT;
-llvm::Function* JnjvmModule::StaticInitializer;
-llvm::Function* JnjvmModule::ObjectPrinter;
-llvm::Function* JnjvmModule::NativeLoader;
 
-extern void* JavaArrayVT[];
-extern void* ArrayObjectVT[];
 extern void* JavaObjectVT[];
 
-extern ClassArray ArrayOfBool;
-extern ClassArray ArrayOfByte;
-extern ClassArray ArrayOfChar;
-extern ClassArray ArrayOfShort;
-extern ClassArray ArrayOfInt;
-extern ClassArray ArrayOfFloat;
-extern ClassArray ArrayOfDouble;
-extern ClassArray ArrayOfLong;
+llvm::Function* JnjvmModule::NativeLoader;
 
 #ifdef WITH_TRACER
 const llvm::FunctionType* JnjvmModule::MarkAndTraceType = 0;
@@ -105,1978 +79,160 @@
 const llvm::Type*   JnjvmModule::VTType;
 llvm::ConstantInt*  JnjvmModule::JavaArrayElementsOffsetConstant;
 llvm::ConstantInt*  JnjvmModule::JavaArraySizeOffsetConstant;
-llvm::ConstantInt*  JnjvmModule::JavaObjectLockOffsetConstant;
-llvm::ConstantInt*  JnjvmModule::JavaObjectClassOffsetConstant;
-
-
-bool JnjvmModule::isCompiling(const CommonClass* cl) const {
-  if (cl->isClass()) {
-    // A class is being static compiled if owner class is not null.
-    return (((Class*)cl)->getOwnerClass() != 0);
-  } else if (cl->isArray()) {
-    return isCompiling(((ClassArray*)cl)->baseClass());
-  } else {
-    return false;
-  }
-}
-
-Constant* JnjvmModule::getNativeClass(CommonClass* classDef) {
-
-  if (staticCompilation) {
-
-    if (classDef->isClass() || 
-        (classDef->isArray() && isCompiling(classDef)) ||
-        (assumeCompiled && !(classDef->isArray() && 
-          classDef->asArrayClass()->baseClass()->isPrimitive()))) {
-      native_class_iterator End = nativeClasses.end();
-      native_class_iterator I = nativeClasses.find(classDef);
-      if (I == End) {
-        const llvm::Type* Ty = 0;
-        
-        if (classDef->isArray()) {
-          Ty = JavaClassArrayType->getContainedType(0); 
-        } else {
-          Ty = JavaClassType->getContainedType(0); 
-        }
-      
-        GlobalVariable* varGV = 
-          new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage, 0,
-                             classDef->printString(), this);
-      
-        nativeClasses.insert(std::make_pair(classDef, varGV));
-
-        if (classDef->isClass() && isCompiling(classDef->asClass())) {
-          Constant* C = CreateConstantFromClass((Class*)classDef);
-          varGV->setInitializer(C);
-        } else if (classDef->isArray()) {
-          Constant* C = CreateConstantFromClassArray((ClassArray*)classDef);
-          varGV->setInitializer(C);
-        }
-
-        return varGV;
-
-      } else {
-        return I->second;
-      }
-    } else if (classDef->isArray()) {
-      array_class_iterator End = arrayClasses.end();
-      array_class_iterator I = arrayClasses.find((ClassArray*)classDef);
-      if (I == End) {
-        const llvm::Type* Ty = JavaClassArrayType; 
-      
-        GlobalVariable* varGV = 
-          new GlobalVariable(Ty, false, GlobalValue::InternalLinkage,
-                             Constant::getNullValue(Ty),
-                             classDef->printString(), this);
-      
-        arrayClasses.insert(std::make_pair((ClassArray*)classDef, varGV));
-        return varGV;
-      } else {
-        return I->second;
-      }
-    } else if (classDef->isPrimitive()) {
-      assert(0 && "implement me");
-    }
-    return 0;
-  } else {
-    const llvm::Type* Ty = classDef->isClass() ? JavaClassType : 
-                                                 JavaCommonClassType;
-    
-    ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64_t(classDef));
-    return ConstantExpr::getIntToPtr(CI, Ty);
-  }
-}
-
-Constant* JnjvmModule::getConstantPool(JavaConstantPool* ctp) {
-  if (staticCompilation) {
-    llvm::Constant* varGV = 0;
-    constant_pool_iterator End = constantPools.end();
-    constant_pool_iterator I = constantPools.find(ctp);
-    if (I == End) {
-      const Type* Ty = ConstantPoolType->getContainedType(0);
-      varGV = new GlobalVariable(Ty, false,
-                                 GlobalValue::InternalLinkage,
-                                 Constant::getNullValue(Ty), "", this);
-      constantPools.insert(std::make_pair(ctp, varGV));
-      return varGV;
-    } else {
-      return I->second;
-    }
-    
-  } else {
-    void* ptr = ctp->ctpRes;
-    assert(ptr && "No constant pool found");
-    ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64_t(ptr));
-    return ConstantExpr::getIntToPtr(CI, ConstantPoolType);
-  }
-}
-
-Constant* JnjvmModule::getMethodInClass(JavaMethod* meth) {
-  if (staticCompilation) {
-    Class* cl = meth->classDef;
-    Constant* MOffset = 0;
-    Constant* Array = 0;
-    method_iterator SI = virtualMethods.find(cl);
-    for (uint32 i = 0; i < cl->nbVirtualMethods + cl->nbStaticMethods; ++i) {
-      if (&cl->virtualMethods[i] == meth) {
-        MOffset = ConstantInt::get(Type::Int32Ty, i);
-        break;
-      }
-    }
-    Array = SI->second; 
-    Constant* GEPs[2] = { constantZero, MOffset };
-    return ConstantExpr::getGetElementPtr(Array, GEPs, 2);
-    
-  } else {
-    ConstantInt* CI = ConstantInt::get(Type::Int64Ty, (int64_t)meth);
-    return ConstantExpr::getIntToPtr(CI, JavaMethodType);
-  }
-}
-
-Constant* JnjvmModule::getString(JavaString* str) {
-  if (staticCompilation) {
-    string_iterator SI = strings.find(str);
-    if (SI != strings.end()) {
-      return SI->second;
-    } else {
-      assert(str && "No string given");
-      LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo((Class*)str->getClass());
-      const llvm::Type* Ty = LCI->getVirtualType();
-      GlobalVariable* varGV = 
-        new GlobalVariable(Ty->getContainedType(0), false,
-                           GlobalValue::InternalLinkage,
-                           0, "", this);
-      Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV,
-                                            JavaObjectType);
-      strings.insert(std::make_pair(str, res));
-      Constant* C = CreateConstantFromJavaString(str);
-      varGV->setInitializer(C);
-      return res;
-    }
-    
-  } else {
-    assert(str && "No string given");
-    ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64(str));
-    return ConstantExpr::getIntToPtr(CI, JavaObjectType);
-  }
-}
-
-Constant* JnjvmModule::getEnveloppe(Enveloppe* enveloppe) {
-  if (staticCompilation) {
-    enveloppe_iterator SI = enveloppes.find(enveloppe);
-    if (SI != enveloppes.end()) {
-      return SI->second;
-    } else {
-      GlobalVariable* varGV = 
-        new GlobalVariable(EnveloppeType->getContainedType(0), false,
-                           GlobalValue::InternalLinkage, 0, "", this);
-      enveloppes.insert(std::make_pair(enveloppe, varGV));
-      
-      Constant* C = CreateConstantFromEnveloppe(enveloppe);
-      varGV->setInitializer(C);
-      return varGV;
-    }
-  
-  } else {
-    assert(enveloppe && "No enveloppe given");
-    ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64(enveloppe));
-    return ConstantExpr::getIntToPtr(CI, EnveloppeType);
-  }
-}
-
-Constant* JnjvmModule::getJavaClass(CommonClass* cl) {
-  if (staticCompilation) {
-    java_class_iterator End = javaClasses.end();
-    java_class_iterator I = javaClasses.find(cl);
-    if (I == End) {
-      Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass;
-      LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(javaClass);
-      const llvm::Type* Ty = LCI->getVirtualType();
-      
-      GlobalVariable* varGV = 
-        new GlobalVariable(Ty->getContainedType(0), false,
-                           GlobalValue::InternalLinkage, 0, "", this);
-      
-      Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV,
-                                            JavaObjectType);
-    
-      javaClasses.insert(std::make_pair(cl, res));
-      varGV->setInitializer(CreateConstantFromJavaClass(cl));
-      return res;
-    } else {
-      return I->second;
-    }
-  
-  } else {
-    JavaObject* obj = cl->getClassDelegatee(JavaThread::get()->getJVM());
-    assert(obj && "Delegatee not created");
-    Constant* CI = ConstantInt::get(Type::Int64Ty, uint64(obj));
-    return ConstantExpr::getIntToPtr(CI, JavaObjectType);
-  }
-}
-
-JavaObject* JnjvmModule::getFinalObject(llvm::Value* obj) {
-  if (staticCompilation) {
-    // TODO
-  } else {
-    if (ConstantExpr* CE = dyn_cast<ConstantExpr>(obj)) {
-      if (ConstantInt* C = dyn_cast<ConstantInt>(CE->getOperand(0))) {
-        return (JavaObject*)C->getZExtValue();
-      }
-    }
-  }
-  return 0;
-}
-
-
-
-Constant* JnjvmModule::getFinalObject(JavaObject* obj) {
-  if (staticCompilation) {
-    final_object_iterator End = finalObjects.end();
-    final_object_iterator I = finalObjects.find(obj);
-    if (I == End) {
-      abort();
-      return 0;
-    } else {
-      return I->second;
-    }
-  
-  } else {
-    Constant* CI = ConstantInt::get(Type::Int64Ty, uint64(obj));
-    return ConstantExpr::getIntToPtr(CI, JavaObjectType);
-  }
-}
-
-Constant* JnjvmModule::CreateConstantFromStaticInstance(Class* cl) {
-  LLVMClassInfo* LCI = getClassInfo(cl);
-  const Type* Ty = LCI->getStaticType();
-  const StructType* STy = dyn_cast<StructType>(Ty->getContainedType(0));
-  
-  std::vector<Constant*> Elts;
-  
-  for (uint32 i = 0; i < cl->nbStaticFields; ++i) {
-    JavaField& field = cl->staticFields[i];
-    const Typedef* type = field.getSignature();
-    LLVMAssessorInfo& LAI = getTypedefInfo(type);
-    const Type* Ty = LAI.llvmType;
-
-    Attribut* attribut = field.lookupAttribut(Attribut::constantAttribut);
-
-    if (!attribut) {
-      Elts.push_back(Constant::getNullValue(Ty));
-    } else {
-      Reader reader(attribut, cl->bytes);
-      JavaConstantPool * ctpInfo = cl->ctpInfo;
-      uint16 idx = reader.readU2();
-      if (type->isPrimitive()) {
-        if (Ty == Type::Int64Ty) {
-          Elts.push_back(ConstantInt::get(Ty, (uint64)ctpInfo->LongAt(idx)));
-        } else if (Ty == Type::DoubleTy) {
-          Elts.push_back(ConstantFP::get(Ty, ctpInfo->DoubleAt(idx)));
-        } else if (Ty == Type::FloatTy) {
-          Elts.push_back(ConstantFP::get(Ty, ctpInfo->FloatAt(idx)));
-        } else {
-          Elts.push_back(ConstantInt::get(Ty, (uint64)ctpInfo->IntegerAt(idx)));
-        }
-      } else if (type->isReference()){
-        const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[idx]);
-        JavaString* obj = ctpInfo->resolveString(utf8, idx);
-        Constant* C = getString(obj);
-        C = ConstantExpr::getBitCast(C, JavaObjectType);
-        Elts.push_back(C);
-      } else {
-        fprintf(stderr, "Implement me");
-        abort();
-      }
-    }
-  }
-   
-  return ConstantStruct::get(STy, Elts);
-}
-
-Constant* JnjvmModule::getStaticInstance(Class* classDef) {
-#ifdef ISOLATE
-  assert(0 && "Should not be here");
-  abort();
-#endif
-  if (staticCompilation) {
-    static_instance_iterator End = staticInstances.end();
-    static_instance_iterator I = staticInstances.find(classDef);
-    if (I == End) {
-      
-      LLVMClassInfo* LCI = getClassInfo(classDef);
-      const Type* Ty = LCI->getStaticType();
-      Ty = Ty->getContainedType(0);
-      GlobalVariable* varGV = 
-        new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage,
-                           0, classDef->printString("<static>"), this);
-
-      Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV,
-                                            ptrType);
-      staticInstances.insert(std::make_pair(classDef, res));
-      
-      if (isCompiling(classDef)) { 
-        Constant* C = CreateConstantFromStaticInstance(classDef);
-        varGV->setInitializer(C);
-      }
-
-      return res;
-    } else {
-      return I->second;
-    }
-
-  } else {
-    void* obj = ((Class*)classDef)->getStaticInstance();
-    if (!obj) {
-      Class* cl = (Class*)classDef;
-      classDef->acquire();
-      obj = cl->getStaticInstance();
-      if (!obj) {
-        // Allocate now so that compiled code can reference it.
-        obj = cl->allocateStaticInstance(JavaThread::get()->getJVM());
-      }
-      classDef->release();
-    }
-    Constant* CI = ConstantInt::get(Type::Int64Ty, (uint64_t(obj)));
-    return ConstantExpr::getIntToPtr(CI, ptrType);
-  }
-}
-
-Constant* JnjvmModule::getVirtualTable(Class* classDef) {
-  LLVMClassInfo* LCI = getClassInfo((Class*)classDef);
-  LCI->getVirtualType();
-  if (staticCompilation) {
-    llvm::Constant* res = 0;
-    virtual_table_iterator End = virtualTables.end();
-    virtual_table_iterator I = virtualTables.find(classDef);
-    if (I == End) {
-      
-      const ArrayType* ATy = dyn_cast<ArrayType>(VTType->getContainedType(0));
-      const PointerType* PTy = dyn_cast<PointerType>(ATy->getContainedType(0));
-      ATy = ArrayType::get(PTy, classDef->virtualTableSize);
-      // Do not set a virtual table as a constant, because the runtime may
-      // modify it.
-      GlobalVariable* varGV = new GlobalVariable(ATy, false,
-                                                 GlobalValue::ExternalLinkage,
-                                                 0, 
-                                                 classDef->printString("<VT>"),
-                                                 this);
-    
-      res = ConstantExpr::getCast(Instruction::BitCast, varGV, VTType);
-      virtualTables.insert(std::make_pair(classDef, res));
-    
-      if (isCompiling(classDef)) {
-        Constant* C = CreateConstantFromVT(classDef);
-        varGV->setInitializer(C);
-      }
-      
-      return res;
-    } else {
-      return I->second;
-    } 
-
-  } else {
-    assert(classDef->virtualVT && "Virtual VT not created");
-    void* ptr = classDef->virtualVT;
-    ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64_t(ptr));
-    return ConstantExpr::getIntToPtr(CI, VTType);
-  }
-}
-
-Constant* JnjvmModule::getNativeFunction(JavaMethod* meth, void* ptr) {
-  if (staticCompilation) {
-    llvm::Constant* varGV = 0;
-    native_function_iterator End = nativeFunctions.end();
-    native_function_iterator I = nativeFunctions.find(meth);
-    if (I == End) {
-      
-      LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature());
-      const llvm::Type* valPtrType = LSI->getNativePtrType();
-      
-      varGV = new GlobalVariable(valPtrType, true,
-                                 GlobalValue::InternalLinkage,
-                                 Constant::getNullValue(valPtrType), "", this);
-    
-      nativeFunctions.insert(std::make_pair(meth, varGV));
-      return varGV;
-    } else {
-      return I->second;
-    }
-  
-  } else {
-    LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature());
-    const llvm::Type* valPtrType = LSI->getNativePtrType();
-    
-    assert(ptr && "No native function given");
-
-    Constant* CI = ConstantInt::get(Type::Int64Ty, uint64_t(ptr));
-    return ConstantExpr::getIntToPtr(CI, valPtrType);
-  }
-}
-
-#ifndef WITHOUT_VTABLE
-void JnjvmModule::allocateVT(Class* cl) {
-  for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
-    JavaMethod& meth = cl->virtualMethods[i];
-    if (meth.name->equals(cl->classLoader->bootstrapLoader->finalize)) {
-      meth.offset = 0;
-    } else {
-      JavaMethod* parent = cl->super? 
-        cl->super->lookupMethodDontThrow(meth.name, meth.type, false, true,
-                                         0) :
-        0;
-
-      uint64_t offset = 0;
-      if (!parent) {
-        offset = cl->virtualTableSize++;
-        meth.offset = offset;
-      } else {
-        offset = parent->offset;
-        meth.offset = parent->offset;
-      }
-    }
-  }
-
-  VirtualTable* VT = 0;
-  if (cl->super) {
-    uint64 size = cl->virtualTableSize;
-    mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
-    VT = (VirtualTable*)allocator.Allocate(size * sizeof(void*));
-    Class* super = (Class*)cl->super;
-    assert(cl->virtualTableSize >= cl->super->virtualTableSize &&
-      "Super VT bigger than own VT");
-    assert(super->virtualVT && "Super does not have a VT!");
-    memcpy(VT, super->virtualVT, cl->super->virtualTableSize * sizeof(void*));
-  } else {
-    VT = JavaObjectVT;
-  }
-
-  cl->virtualVT = VT;
-}
-#endif
-
-
-#ifdef WITH_TRACER
-llvm::Function* JnjvmModule::makeTracer(Class* cl, bool stat) {
-  
-  if (isStaticCompiling() && !generateTracers) {
-    return JavaObjectTracerFunction;
-  }
-
-  LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(cl);
-  const Type* type = stat ? LCI->getStaticType() : LCI->getVirtualType();
-  JavaField* fields = 0;
-  uint32 nbFields = 0;
-  if (stat) {
-    fields = cl->getStaticFields();
-    nbFields = cl->nbStaticFields;
-  } else {
-    fields = cl->getVirtualFields();
-    nbFields = cl->nbVirtualFields;
-  }
-  
-  Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
-                                    GlobalValue::InternalLinkage,
-                                    "",
-                                    this);
-
-  Constant* zero = mvm::MvmModule::constantZero;
-  Argument* arg = func->arg_begin();
-  BasicBlock* block = BasicBlock::Create("", func);
-  llvm::Value* realArg = new BitCastInst(arg, type, "", block);
-
-  std::vector<Value*> Args;
-  Args.push_back(arg);
-#ifdef MULTIPLE_GC
-  Value* GC = ++func->arg_begin();
-  Args.push_back(GC);
-#endif
-  if (!stat) {
-    if (cl->super == 0) {
-      CallInst::Create(JavaObjectTracerFunction, Args.begin(), Args.end(),
-                        "", block);
-
-    } else {
-      LLVMClassInfo* LCP = (LLVMClassInfo*)getClassInfo((Class*)(cl->super));
-      Function* F = LCP->virtualTracerFunction;
-      if (!F) {
-        if (isStaticCompiling()) {
-          F = makeTracer(cl->super, false);
-        } else {
-          F = LCP->getVirtualTracer();
-        }
-        assert(F && "Still no virtual tracer for super");
-      }
-      CallInst::Create(F, Args.begin(), Args.end(), "", block);
-    }
-  }
-  
-  for (uint32 i = 0; i < nbFields; ++i) {
-    JavaField& cur = fields[i];
-    if (cur.getSignature()->trace()) {
-      LLVMFieldInfo* LFI = getFieldInfo(&cur);
-      std::vector<Value*> args; //size = 2
-      args.push_back(zero);
-      args.push_back(LFI->getOffset());
-      Value* ptr = GetElementPtrInst::Create(realArg, args.begin(), args.end(), 
-                                             "",block);
-      Value* val = new LoadInst(ptr, "", block);
-      Value* valCast = new BitCastInst(val, JnjvmModule::JavaObjectType, "",
-                                       block);
-      std::vector<Value*> Args;
-      Args.push_back(valCast);
-#ifdef MULTIPLE_GC
-      Args.push_back(GC);
-#endif
-      CallInst::Create(JnjvmModule::MarkAndTraceFunction, Args.begin(),
-                       Args.end(), "", block);
-    }
-  }
-
-  ReturnInst::Create(block);
-  
-  if (!stat) {
-    LCI->virtualTracerFunction = func;
-  } else {
-    LCI->staticTracerFunction = func;
-  }
-
-  return func;
-}
-#endif
-
-Constant* JnjvmModule::CreateConstantForBaseObject(CommonClass* cl) {
-  const StructType* STy = 
-    dyn_cast<StructType>(JavaObjectType->getContainedType(0));
-  
-  std::vector<Constant*> Elmts;
-
-  // virtual table
-  if (cl->isClass()) {
-    Elmts.push_back(getVirtualTable(cl->asClass()));
-  } else {
-    ClassArray* clA = cl->asArrayClass();
-    if (clA->baseClass()->isPrimitive()) {
-      Elmts.push_back(PrimitiveArrayVT);
-    } else {
-      Elmts.push_back(ReferenceArrayVT);
-    }
-  }
-  
-  // classof
-  Constant* Cl = getNativeClass(cl);
-  Constant* ClGEPs[2] = { constantZero, constantZero };
-  Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2);
-    
-  Elmts.push_back(Cl);
-
-  // lock
-  Constant* L = ConstantInt::get(Type::Int64Ty,
-                                 JavaThread::get()->getThreadID());
-  Elmts.push_back(ConstantExpr::getIntToPtr(L, ptrType));
-
-  return ConstantStruct::get(STy, Elmts);
-}
-
-Constant* JnjvmModule::CreateConstantFromJavaClass(CommonClass* cl) {
-  Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass;
-  LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(javaClass);
-  const StructType* STy = 
-    dyn_cast<StructType>(LCI->getVirtualType()->getContainedType(0));
-
-  std::vector<Constant*> Elmts;
-
-  // JavaObject
-  Elmts.push_back(CreateConstantForBaseObject(javaClass));
-  
-  // signers
-  Elmts.push_back(Constant::getNullValue(JavaObjectType));
-  
-  // pd
-  Elmts.push_back(Constant::getNullValue(JavaObjectType));
-  
-  // vmdata
-  Constant* Cl = getNativeClass(cl);
-  Cl = ConstantExpr::getCast(Instruction::BitCast, Cl, JavaObjectType);
-  Elmts.push_back(Cl);
-
-  // constructor
-  Elmts.push_back(Constant::getNullValue(JavaObjectType));
-
-  return ConstantStruct::get(STy, Elmts);
-}
-
-Constant* JnjvmModule::CreateConstantFromJavaObject(JavaObject* obj) {
-  CommonClass* cl = obj->getClass();
-
-  if (cl->isArray()) {
-    Classpath* upcalls = cl->classLoader->bootstrapLoader->upcalls;
-    CommonClass* subClass = cl->asArrayClass()->baseClass();
-    if (subClass->isPrimitive()) {
-      if (subClass == upcalls->OfBool) {
-        return CreateConstantFromArray<ArrayUInt8>((ArrayUInt8*)obj,
-                                                   Type::Int8Ty);
-      } else if (subClass == upcalls->OfByte) {
-        return CreateConstantFromArray<ArraySInt8>((ArraySInt8*)obj,
-                                                   Type::Int8Ty);
-      } else if (subClass == upcalls->OfShort) {
-        return CreateConstantFromArray<ArraySInt16>((ArraySInt16*)obj,
-                                                    Type::Int16Ty);
-      } else if (subClass == upcalls->OfChar) {
-        return CreateConstantFromArray<ArrayUInt16>((ArrayUInt16*)obj,
-                                                    Type::Int16Ty);
-      } else if (subClass == upcalls->OfInt) {
-        return CreateConstantFromArray<ArraySInt32>((ArraySInt32*)obj,
-                                                    Type::Int32Ty);
-      } else if (subClass == upcalls->OfFloat) {
-        return CreateConstantFromArray<ArrayFloat>((ArrayFloat*)obj,
-                                                   Type::FloatTy);
-      } else if (subClass == upcalls->OfLong) {
-        return CreateConstantFromArray<ArrayLong>((ArrayLong*)obj,
-                                                  Type::Int64Ty);
-      } else if (subClass == upcalls->OfDouble) {
-        return CreateConstantFromArray<ArrayDouble>((ArrayDouble*)obj,
-                                                    Type::DoubleTy);
-      } else {
-        abort();
-      }
-    } else {
-      return CreateConstantFromArray<ArrayObject>((ArrayObject*)obj,
-                                                  JavaObjectType);
-    }
-  } else {
-    
-    std::vector<Constant*> Elmts;
-    
-    // JavaObject
-    Constant* CurConstant = CreateConstantForBaseObject(obj->getClass());
-
-    for (uint32 j = 0; j <= cl->depth; ++j) {
-      std::vector<Constant*> TempElts;
-      Elmts.push_back(CurConstant);
-      TempElts.push_back(CurConstant);
-      Class* curCl = cl->display[j]->asClass();
-      LLVMClassInfo* LCI = getClassInfo(curCl);
-      const StructType* STy = 
-        dyn_cast<StructType>(LCI->getVirtualType()->getContainedType(0));
-
-      for (uint32 i = 0; i < curCl->nbVirtualFields; ++i) {
-        JavaField& field = curCl->virtualFields[i];
-        const Typedef* type = field.getSignature();
-        if (type->isPrimitive()) {
-          const PrimitiveTypedef* prim = (PrimitiveTypedef*)type;
-          if (prim->isBool() || prim->isByte()) {
-            ConstantInt* CI = ConstantInt::get(Type::Int8Ty,
-                                               field.getInt8Field(obj));
-            TempElts.push_back(CI);
-          } else if (prim->isShort() || prim->isChar()) {
-            ConstantInt* CI = ConstantInt::get(Type::Int16Ty,
-                                               field.getInt16Field(obj));
-            TempElts.push_back(CI);
-          } else if (prim->isInt()) {
-            ConstantInt* CI = ConstantInt::get(Type::Int32Ty,
-                                               field.getInt32Field(obj));
-            TempElts.push_back(CI);
-          } else if (prim->isLong()) {
-            ConstantInt* CI = ConstantInt::get(Type::Int64Ty,
-                                               field.getLongField(obj));
-            TempElts.push_back(CI);
-          } else if (prim->isFloat()) {
-            ConstantInt* CI = ConstantInt::get(Type::FloatTy,
-                                               field.getFloatField(obj));
-            TempElts.push_back(CI);
-          } else if (prim->isDouble()) {
-            ConstantInt* CI = ConstantInt::get(Type::DoubleTy,
-                                               field.getDoubleField(obj));
-            TempElts.push_back(CI);
-          } else {
-            abort();
-          }
-        } else {
-          Constant* C = getFinalObject(field.getObjectField(obj));
-          TempElts.push_back(C);
-        }
-      }
-      CurConstant = ConstantStruct::get(STy, TempElts);
-    }
-
-    return CurConstant;
-  }
-}
-
-Constant* JnjvmModule::CreateConstantFromJavaString(JavaString* str) {
-  Class* cl = (Class*)str->getClass();
-  LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(cl);
-  const StructType* STy = 
-    dyn_cast<StructType>(LCI->getVirtualType()->getContainedType(0));
-
-  std::vector<Constant*> Elmts;
-
-  Elmts.push_back(CreateConstantForBaseObject(cl));
-
-  Constant* Array = getUTF8(str->value);
-  Constant* ObjGEPs[2] = { constantZero, constantZero };
-  Array = ConstantExpr::getGetElementPtr(Array, ObjGEPs, 2);
-  Elmts.push_back(Array);
-  
-  Elmts.push_back(ConstantInt::get(Type::Int32Ty, str->count));
-  Elmts.push_back(ConstantInt::get(Type::Int32Ty, str->cachedHashCode));
-  Elmts.push_back(ConstantInt::get(Type::Int32Ty, str->offset));
-  
-  return ConstantStruct::get(STy, Elmts);
-}
-
-
-Constant* JnjvmModule::CreateConstantFromCacheNode(CacheNode* CN) {
-  const StructType* STy = 
-    dyn_cast<StructType>(CacheNodeType->getContainedType(0));
-
-  std::vector<Constant*> Elmts;
-  Elmts.push_back(Constant::getNullValue(STy->getContainedType(0)));
-  Elmts.push_back(Constant::getNullValue(STy->getContainedType(1)));
-  Elmts.push_back(Constant::getNullValue(STy->getContainedType(2)));
-  Elmts.push_back(getEnveloppe(CN->enveloppe));
-  
-  return ConstantStruct::get(STy, Elmts);
-}
-
-Constant* JnjvmModule::CreateConstantFromEnveloppe(Enveloppe* val) {
-  
-  const StructType* STy = 
-    dyn_cast<StructType>(EnveloppeType->getContainedType(0));
-  const StructType* CNTy = 
-    dyn_cast<StructType>(CacheNodeType->getContainedType(0));
-  
-  std::vector<Constant*> Elmts;
-  
-  Constant* firstCache = CreateConstantFromCacheNode(val->firstCache);
-  Elmts.push_back(new GlobalVariable(CNTy, false,
-                                     GlobalValue::InternalLinkage,
-                                     firstCache, "", this));
-  Elmts.push_back(getUTF8(val->methodName));
-  Elmts.push_back(getUTF8(val->methodSign));
-
-  Elmts.push_back(Constant::getNullValue(Type::Int8Ty));
-  Elmts.push_back(getNativeClass(val->classDef));
-  Elmts.push_back(firstCache);
-
-  return ConstantStruct::get(STy, Elmts);
-  
-}
-
-Constant* JnjvmModule::CreateConstantFromAttribut(Attribut& attribut) {
-  const StructType* STy = 
-    dyn_cast<StructType>(AttributType->getContainedType(0));
-
-
-  std::vector<Constant*> Elmts;
-
-  // name
-  Elmts.push_back(getUTF8(attribut.name));
-
-  // start
-  Elmts.push_back(ConstantInt::get(Type::Int32Ty, attribut.start));
-
-  // nbb
-  Elmts.push_back(ConstantInt::get(Type::Int32Ty, attribut.nbb));
-  
-  return ConstantStruct::get(STy, Elmts);
-}
-
-Constant* JnjvmModule::CreateConstantFromCommonClass(CommonClass* cl) {
-  const StructType* STy = 
-    dyn_cast<StructType>(JavaCommonClassType->getContainedType(0));
-
-  const ArrayType* ATy = ArrayType::get(JavaCommonClassType, cl->depth + 1);
-  
-  std::vector<Constant*> CommonClassElts;
-  std::vector<Constant*> TempElmts;
-  Constant* ClGEPs[2] = { constantZero, constantZero };
-
-  // display
-  for (uint32 i = 0; i <= cl->depth; ++i) {
-    Constant* Cl = getNativeClass(cl->display[i]);
-    if (Cl->getType() != JavaCommonClassType)
-      Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2);
-    
-    TempElmts.push_back(Cl);
-  }
-
-  Constant* display = ConstantArray::get(ATy, TempElmts);
-  TempElmts.clear();
-  display = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
-                               display, "", this);
-  display = ConstantExpr::getCast(Instruction::BitCast, display,
-                                  PointerType::getUnqual(JavaCommonClassType));
-  CommonClassElts.push_back(display);
-
-  // depth
-  CommonClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->depth));
-  
-  // delegatee
-  ATy = dyn_cast<ArrayType>(STy->getContainedType(2));
-  assert(ATy && "Malformed type");
-
-  Constant* TCM[1] = { getJavaClass(cl) };
-  CommonClassElts.push_back(ConstantArray::get(ATy, TCM, 1));
-  
-  // access
-  CommonClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->access));
- 
-  // interfaces
-  if (cl->nbInterfaces) {
-    for (uint32 i = 0; i < cl->nbInterfaces; ++i) {
-      TempElmts.push_back(getNativeClass(cl->interfaces[i]));
-    }
-
-    ATy = ArrayType::get(JavaClassType, cl->nbInterfaces);
-    Constant* interfaces = ConstantArray::get(ATy, TempElmts);
-    interfaces = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
-                                    interfaces, "", this);
-    interfaces = ConstantExpr::getCast(Instruction::BitCast, interfaces,
-                                       PointerType::getUnqual(JavaClassType));
-
-    CommonClassElts.push_back(interfaces);
-  } else {
-    const Type* Ty = PointerType::getUnqual(JavaClassType);
-    CommonClassElts.push_back(Constant::getNullValue(Ty));
-  }
-
-  // nbInterfaces
-  CommonClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->nbInterfaces));
-
-  // name
-  CommonClassElts.push_back(getUTF8(cl->name));
-
-  // super
-  if (cl->super) {
-    CommonClassElts.push_back(getNativeClass(cl->super));
-  } else {
-    CommonClassElts.push_back(Constant::getNullValue(JavaClassType));
-  }
-
-  // classLoader: store the static initializer, it will be overriden once
-  // the class is loaded.
-  Constant* loader = ConstantExpr::getBitCast(StaticInitializer, ptrType);
-  CommonClassElts.push_back(loader);
- 
-  return ConstantStruct::get(STy, CommonClassElts);
-}
-
-Constant* JnjvmModule::CreateConstantFromJavaField(JavaField& field) {
-  const StructType* STy = 
-    dyn_cast<StructType>(JavaFieldType->getContainedType(0));
-  
-  std::vector<Constant*> FieldElts;
-  std::vector<Constant*> TempElts;
-  
-  // signature
-  FieldElts.push_back(Constant::getNullValue(ptrType));
-  
-  // access
-  FieldElts.push_back(ConstantInt::get(Type::Int16Ty, field.access));
-
-  // name
-  FieldElts.push_back(getUTF8(field.name));
-
-  // type
-  FieldElts.push_back(getUTF8(field.type));
-  
-  // attributs 
-  if (field.nbAttributs) {
-    const ArrayType* ATy = ArrayType::get(AttributType->getContainedType(0),
-                                          field.nbAttributs);
-    for (uint32 i = 0; i < field.nbAttributs; ++i) {
-      TempElts.push_back(CreateConstantFromAttribut(field.attributs[i]));
-    }
-
-    Constant* attributs = ConstantArray::get(ATy, TempElts);
-    TempElts.clear();
-    attributs = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
-                                   attributs, "", this);
-    attributs = ConstantExpr::getCast(Instruction::BitCast, attributs,
-                                      AttributType);
-  
-    FieldElts.push_back(attributs);
-  } else {
-    FieldElts.push_back(Constant::getNullValue(AttributType));
-  }
-  
-  // nbAttributs
-  FieldElts.push_back(ConstantInt::get(Type::Int16Ty, field.nbAttributs));
-
-  // classDef
-  FieldElts.push_back(getNativeClass(field.classDef));
-
-  // ptrOffset
-  FieldElts.push_back(ConstantInt::get(Type::Int32Ty, field.ptrOffset));
-
-  // num
-  FieldElts.push_back(ConstantInt::get(Type::Int16Ty, field.num));
-
-  //JInfo
-  FieldElts.push_back(Constant::getNullValue(ptrType));
-  
-  return ConstantStruct::get(STy, FieldElts); 
-}
-
-Constant* JnjvmModule::CreateConstantFromJavaMethod(JavaMethod& method) {
-  const StructType* STy = 
-    dyn_cast<StructType>(JavaMethodType->getContainedType(0));
-  
-  std::vector<Constant*> MethodElts;
-  std::vector<Constant*> TempElts;
-  
-  // signature
-  MethodElts.push_back(Constant::getNullValue(ptrType));
-  
-  // access
-  MethodElts.push_back(ConstantInt::get(Type::Int16Ty, method.access));
- 
-  // attributs
-  if (method.nbAttributs) {
-    const ArrayType* ATy = ArrayType::get(AttributType->getContainedType(0),
-                                          method.nbAttributs);
-    for (uint32 i = 0; i < method.nbAttributs; ++i) {
-      TempElts.push_back(CreateConstantFromAttribut(method.attributs[i]));
-    }
-
-    Constant* attributs = ConstantArray::get(ATy, TempElts);
-    TempElts.clear();
-    attributs = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
-                                   attributs, "", this);
-    attributs = ConstantExpr::getCast(Instruction::BitCast, attributs,
-                                      AttributType);
-
-    MethodElts.push_back(attributs);
-  } else {
-    MethodElts.push_back(Constant::getNullValue(AttributType));
-  }
-  
-  // nbAttributs
-  MethodElts.push_back(ConstantInt::get(Type::Int16Ty, method.nbAttributs));
-  
-  // enveloppes
-  // already allocated by the JIT, don't reallocate them.
-  MethodElts.push_back(Constant::getNullValue(EnveloppeType));
-  
-  // nbEnveloppes
-  // 0 because we're not allocating here.
-  MethodElts.push_back(ConstantInt::get(Type::Int16Ty, 0));
-  
-  // classDef
-  MethodElts.push_back(getNativeClass(method.classDef));
-  
-  // name
-  MethodElts.push_back(getUTF8(method.name));
-
-  // type
-  MethodElts.push_back(getUTF8(method.type));
-  
-  // canBeInlined
-  MethodElts.push_back(ConstantInt::get(Type::Int8Ty, method.canBeInlined));
-
-  // code
-  if (isAbstract(method.access)) {
-    MethodElts.push_back(Constant::getNullValue(ptrType));
-  } else {
-    LLVMMethodInfo* LMI = getMethodInfo(&method);
-    Function* func = LMI->getMethod();
-    MethodElts.push_back(ConstantExpr::getCast(Instruction::BitCast, func,
-                                               ptrType));
-  }
-
-  // offset
-  MethodElts.push_back(ConstantInt::get(Type::Int32Ty, method.offset));
-
-  //JInfo
-  MethodElts.push_back(Constant::getNullValue(ptrType));
-  
-  return ConstantStruct::get(STy, MethodElts); 
-}
-
-Constant* JnjvmModule::CreateConstantFromClassPrimitive(ClassPrimitive* cl) {
-  const StructType* STy = 
-    dyn_cast<StructType>(JavaClassPrimitiveType->getContainedType(0));
-  
-  std::vector<Constant*> ClassElts;
-  
-  // common class
-  ClassElts.push_back(CreateConstantFromCommonClass(cl));
-
-  // primSize
-  ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->primSize));
-
-  return ConstantStruct::get(STy, ClassElts);
-}
-
-Constant* JnjvmModule::CreateConstantFromClassArray(ClassArray* cl) {
-  const StructType* STy = 
-    dyn_cast<StructType>(JavaClassArrayType->getContainedType(0));
-  
-  std::vector<Constant*> ClassElts;
-  Constant* ClGEPs[2] = { constantZero, constantZero };
-  
-  // common class
-  ClassElts.push_back(CreateConstantFromCommonClass(cl));
-
-  // baseClass
-  Constant* Cl = getNativeClass(cl->baseClass());
-  if (Cl->getType() != JavaCommonClassType)
-    Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2);
-    
-  ClassElts.push_back(Cl);
-
-  return ConstantStruct::get(STy, ClassElts);
-}
-
-Constant* JnjvmModule::CreateConstantFromClass(Class* cl) {
-  const StructType* STy = 
-    dyn_cast<StructType>(JavaClassType->getContainedType(0));
-  
-  std::vector<Constant*> ClassElts;
-  std::vector<Constant*> TempElts;
-
-  // common class
-  ClassElts.push_back(CreateConstantFromCommonClass(cl));
-
-  // virtualSize
-  ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->virtualSize));
-
-  // virtualTable
-  ClassElts.push_back(getVirtualTable(cl));
-
-  // IsolateInfo
-  const ArrayType* ATy = dyn_cast<ArrayType>(STy->getContainedType(3));
-  assert(ATy && "Malformed type");
-  
-  const StructType* TCMTy = dyn_cast<StructType>(ATy->getContainedType(0));
-  assert(TCMTy && "Malformed type");
-
-  uint32 status = cl->needsInitialisationCheck() ? vmjc : ready;
-  TempElts.push_back(ConstantInt::get(Type::Int8Ty, status));
-  TempElts.push_back(ConstantInt::get(Type::Int1Ty, status == ready ? 1 : 0));
-  TempElts.push_back(getStaticInstance(cl));
-  Constant* CStr[1] = { ConstantStruct::get(TCMTy, TempElts) };
-  TempElts.clear();
-  ClassElts.push_back(ConstantArray::get(ATy, CStr, 1));
-
-  // thinlock
-  ClassElts.push_back(Constant::getNullValue(ptrType));
-
-  if (cl->nbVirtualFields + cl->nbStaticFields) {
-    ATy = ArrayType::get(JavaFieldType->getContainedType(0), 
-                         cl->nbVirtualFields + cl->nbStaticFields);
-  }
-
-  // virtualFields
-  if (cl->nbVirtualFields) {
-
-    for (uint32 i = 0; i < cl->nbVirtualFields; ++i) {
-      TempElts.push_back(CreateConstantFromJavaField(cl->virtualFields[i]));
-    }
-
-  } 
-  
-  // staticFields
-  if (cl->nbStaticFields) {
-
-    for (uint32 i = 0; i < cl->nbStaticFields; ++i) {
-      TempElts.push_back(CreateConstantFromJavaField(cl->staticFields[i]));
-    }
-
-  }
-
-  Constant* fields = 0;
-  if (cl->nbStaticFields + cl->nbVirtualFields) {
-  
-    fields = ConstantArray::get(ATy, TempElts);
-    TempElts.clear();
-    fields = new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
-                                fields, "", this);
-    fields = ConstantExpr::getCast(Instruction::BitCast, fields, JavaFieldType);
-  } else {
-    fields = Constant::getNullValue(JavaFieldType);
-  }
-
-  // virtualFields
-  ClassElts.push_back(fields);
-
-  ConstantInt* nbVirtualFields = 
-    ConstantInt::get(Type::Int16Ty, cl->nbVirtualFields);
-  // nbVirtualFields
-  ClassElts.push_back(nbVirtualFields);
-  
-  // staticFields
-  // Output null, this will be set in  the initializer. Otherwise, the
-  // assembly emitter of LLVM will try to align the data.
-  ClassElts.push_back(Constant::getNullValue(JavaFieldType));
-
-  // nbStaticFields
-  ClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->nbStaticFields));
-  
-  // virtualMethods
-  if (cl->nbVirtualMethods + cl->nbStaticMethods) {
-    ATy = ArrayType::get(JavaMethodType->getContainedType(0),
-                         cl->nbVirtualMethods + cl->nbStaticMethods);
-  }
-
-  if (cl->nbVirtualMethods) {
-    for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
-      TempElts.push_back(CreateConstantFromJavaMethod(cl->virtualMethods[i]));
-    }
-  }
-    
-  if (cl->nbStaticMethods) {
-    for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
-      TempElts.push_back(CreateConstantFromJavaMethod(cl->staticMethods[i]));
-    }
-  }
-
-  Constant* methods = 0;
-  if (cl->nbVirtualMethods + cl->nbStaticMethods) {
-    methods = ConstantArray::get(ATy, TempElts);
-    TempElts.clear();
-    GlobalVariable* GV = new GlobalVariable(ATy, false,
-                                            GlobalValue::InternalLinkage,
-                                            methods, "", this);
-    virtualMethods.insert(std::make_pair(cl, GV));
-    methods = ConstantExpr::getCast(Instruction::BitCast, GV,
-                                    JavaMethodType);
-  } else {
-    methods = Constant::getNullValue(JavaMethodType);
-  }
-
-  // virtualMethods
-  ClassElts.push_back(methods);
-
-  ConstantInt* nbVirtualMethods = 
-    ConstantInt::get(Type::Int16Ty, cl->nbVirtualMethods);
-  // nbVirtualMethods
-  ClassElts.push_back(nbVirtualMethods);
-  
-  // staticMethods
-  // Output null, this will be set in  the initializer.
-  ClassElts.push_back(Constant::getNullValue(JavaMethodType));
-
-  // nbStaticMethods
-  ClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->nbStaticMethods));
-
-  // ownerClass
-  ClassElts.push_back(Constant::getNullValue(ptrType));
-  
-  // bytes
-  ClassElts.push_back(Constant::getNullValue(JavaArrayUInt8Type));
-
-  // ctpInfo
-  ClassElts.push_back(Constant::getNullValue(ptrType));
-
-  // attributs
-  if (cl->nbAttributs) {
-    ATy = ArrayType::get(AttributType->getContainedType(0),
-                         cl->nbAttributs);
-
-    for (uint32 i = 0; i < cl->nbAttributs; ++i) {
-      TempElts.push_back(CreateConstantFromAttribut(cl->attributs[i]));
-    }
-
-    Constant* attributs = ConstantArray::get(ATy, TempElts);
-    TempElts.clear();
-    attributs = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
-                                   attributs, "", this);
-    attributs = ConstantExpr::getCast(Instruction::BitCast, attributs,
-                                      AttributType);
-    ClassElts.push_back(attributs);
-  } else {
-    ClassElts.push_back(Constant::getNullValue(AttributType));
-  }
-  
-  // nbAttributs
-  ClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->nbAttributs));
-  
-  // innerClasses
-  if (cl->nbInnerClasses) {
-    for (uint32 i = 0; i < cl->nbInnerClasses; ++i) {
-      TempElts.push_back(getNativeClass(cl->innerClasses[i]));
-    }
-
-    ATy = ArrayType::get(JavaClassType, cl->nbInnerClasses);
-    Constant* innerClasses = ConstantArray::get(ATy, TempElts);
-    innerClasses = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
-                                      innerClasses, "", this);
-    innerClasses = ConstantExpr::getCast(Instruction::BitCast, innerClasses,
-                                         PointerType::getUnqual(JavaClassType));
-
-    ClassElts.push_back(innerClasses);
-  } else {
-    const Type* Ty = PointerType::getUnqual(JavaClassType);
-    ClassElts.push_back(Constant::getNullValue(Ty));
-  }
-
-  // nbInnerClasses
-  ClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->nbInnerClasses));
-
-  // outerClass
-  if (cl->outerClass) {
-    ClassElts.push_back(getNativeClass(cl->outerClass));
-  } else {
-    ClassElts.push_back(Constant::getNullValue(JavaClassType));
-  }
-
-  // innerAccess
-  ClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->innerAccess));
-  
-  // innerOuterResolved
-  ClassElts.push_back(ConstantInt::get(Type::Int8Ty, cl->innerOuterResolved));
-  
-  // virtualTableSize
-  ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->virtualTableSize));
-  
-  // staticSize
-  ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->staticSize));
-
-  // JInfo
-  ClassElts.push_back(Constant::getNullValue(ptrType));
-
-  // staticTracer
-  const Type* FTy = STy->getContainedType(STy->getNumContainedTypes() - 1);
-#ifdef WITH_TRACER
-  Function* F = makeTracer(cl, true);
-  Constant* staticTracer = ConstantExpr::getCast(Instruction::BitCast, F, FTy);
-#else
-  Constant* staticTracer = ConstantExpr::getNullValue(FTy);
-#endif
-  ClassElts.push_back(staticTracer);
-
-
-  return ConstantStruct::get(STy, ClassElts);
-}
-
-template<typename T>
-Constant* JnjvmModule::CreateConstantFromArray(T* val, const llvm::Type* Ty) {
-  std::vector<const Type*> Elemts;
-  const ArrayType* ATy = ArrayType::get(Ty, val->size);
-  Elemts.push_back(JavaObjectType->getContainedType(0));
-  Elemts.push_back(pointerSizeType == Type::Int32Ty ? Type::Int32Ty : 
-                                                      Type::Int64Ty);
-
-  Elemts.push_back(ATy);
-
-  const StructType* STy = StructType::get(Elemts);
-  
-  std::vector<Constant*> Cts;
-  Cts.push_back(CreateConstantForBaseObject(val->getClass()));
-  Cts.push_back(ConstantInt::get(pointerSizeType, val->size));
-  
-  std::vector<Constant*> Vals;
-  for (sint32 i = 0; i < val->size; ++i) {
-    if (Ty->isInteger()) {
-      Vals.push_back(ConstantInt::get(Ty, (uint64)val->elements[i]));
-    } else if (Ty->isFloatingPoint()) {
-      Vals.push_back(ConstantFP::get(Ty, (double)(size_t)val->elements[i]));
-    } else {
-      Vals.push_back(getFinalObject((JavaObject*)(size_t)val->elements[i]));
-    }
-  }
-
-  Cts.push_back(ConstantArray::get(ATy, Vals));
-  
-  return ConstantStruct::get(STy, Cts);
-}
-
-Constant* JnjvmModule::CreateConstantFromUTF8(const UTF8* val) {
-  std::vector<const Type*> Elemts;
-  const ArrayType* ATy = ArrayType::get(Type::Int16Ty, val->size);
-  Elemts.push_back(JavaObjectType->getContainedType(0));
-  Elemts.push_back(pointerSizeType == Type::Int32Ty ? Type::Int32Ty : 
-                                                      Type::Int64Ty);
-
-  Elemts.push_back(ATy);
-
-  const StructType* STy = StructType::get(Elemts);
-  
-  std::vector<Constant*> Cts;
-  Cts.push_back(CreateConstantForBaseObject(&ArrayOfChar));
-  Cts.push_back(ConstantInt::get(pointerSizeType, val->size));
-  
-  std::vector<Constant*> Vals;
-  for (sint32 i = 0; i < val->size; ++i) {
-    Vals.push_back(ConstantInt::get(Type::Int16Ty, val->elements[i]));
-  }
-
-  Cts.push_back(ConstantArray::get(ATy, Vals));
-  
-  return ConstantStruct::get(STy, Cts);
-
-}
-
-Constant* JnjvmModule::getUTF8(const UTF8* val) {
-  utf8_iterator End = utf8s.end();
-  utf8_iterator I = utf8s.find(val);
-  if (I == End) {
-    Constant* C = CreateConstantFromUTF8(val);
-    GlobalVariable* varGV = new GlobalVariable(C->getType(), true,
-                                               GlobalValue::InternalLinkage,
-                                               C, "", this);
-    
-    Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV,
-                                          UTF8Type);
-    utf8s.insert(std::make_pair(val, res));
-
-    return res;
-  } else {
-    return I->second;
-  }
-}
-
-Constant* JnjvmModule::CreateConstantFromVT(Class* classDef) {
-  uint32 size = classDef->virtualTableSize;
-  VirtualTable* VT = classDef->virtualVT;
-  const ArrayType* ATy = dyn_cast<ArrayType>(VTType->getContainedType(0));
-  const PointerType* PTy = dyn_cast<PointerType>(ATy->getContainedType(0));
-  ATy = ArrayType::get(PTy, size);
-
-  ConstantPointerNull* N = ConstantPointerNull::get(PTy);
-  std::vector<Constant*> Elemts;
-   
-  // Destructor
-  JavaMethod* meth = ((JavaMethod**)VT)[0];
-  LLVMMethodInfo* LMI = getMethodInfo(meth);
-  Function* Finalizer = LMI->getMethod();
-  Elemts.push_back(Finalizer ? 
-      ConstantExpr::getCast(Instruction::BitCast, Finalizer, PTy) : N);
-  
-  // Delete
-  Elemts.push_back(N);
-  
-  // Tracer
-#ifdef WITH_TRACER
-  Function* Tracer = makeTracer(classDef, false);
-  Elemts.push_back(Tracer ? 
-      ConstantExpr::getCast(Instruction::BitCast, Tracer, PTy) : N);
-#else
-  Elemts.push_back(N);
-#endif
-
-  // Printer
-  Elemts.push_back(ConstantExpr::getBitCast(ObjectPrinter, PTy));
-  
-  // Hashcode
-  Elemts.push_back(N);  
-
-  for (uint32 i = VT_NB_FUNCS; i < size; ++i) {
-    JavaMethod* meth = ((JavaMethod**)VT)[i];
-    LLVMMethodInfo* LMI = getMethodInfo(meth);
-    Function* F = LMI->getMethod();
-    if (isAbstract(meth->access)) {
-      Elemts.push_back(Constant::getNullValue(PTy));
-    } else {
-      Elemts.push_back(ConstantExpr::getCast(Instruction::BitCast, F, PTy));
-    }
-  }
-
-  Constant* Array = ConstantArray::get(ATy, Elemts);
-  
-  return Array;
-}
-
-void JnjvmModule::makeVT(Class* cl) {
-  
-  VirtualTable* VT = 0;
-#ifdef WITHOUT_VTABLE
-  mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
-  VT = (VirtualTable*)allocator.Allocate(VT_SIZE);
-  memcpy(VT, JavaObjectVT, VT_SIZE);
-  cl->virtualVT = VT;
-#else
-  if (cl->super) {
-    if (isStaticCompiling() && !cl->super->virtualVT) {
-      makeVT(cl->super);
-    }
-
-    cl->virtualTableSize = cl->super->virtualTableSize;
-  } else {
-    cl->virtualTableSize = VT_NB_FUNCS;
-  }
-
-  // Allocate the virtual table.
-  allocateVT(cl);
-  VT = cl->virtualVT;
-
-  if (!staticCompilation) {
-    // Fill the virtual table with function pointers.
-    ExecutionEngine* EE = mvm::MvmModule::executionEngine;
-    for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
-      JavaMethod& meth = cl->virtualMethods[i];
-      LLVMMethodInfo* LMI = getMethodInfo(&meth);
-      Function* func = LMI->getMethod();
-
-      // Special handling for finalize method. Don't put a finalizer
-      // if there is none, or if it is empty.
-      if (meth.offset == 0) {
-#if defined(ISOLATE_SHARING) || defined(USE_GC_BOEHM)
-        ((void**)VT)[0] = 0;
-#else
-        JnjvmClassLoader* loader = cl->classLoader;
-        Function* func = loader->getModuleProvider()->parseFunction(&meth);
-        if (!cl->super) {
-          meth.canBeInlined = true;
-          ((void**)VT)[0] = 0;
-        } else {
-          Function::iterator BB = func->begin();
-          BasicBlock::iterator I = BB->begin();
-          if (isa<ReturnInst>(I)) {
-            ((void**)VT)[0] = 0;
-          } else {
-            // LLVM does not allow recursive compilation. Create the code now.
-            ((void**)VT)[0] = EE->getPointerToFunction(func);
-          }
-        }
-#endif
-      } else {
-        ((void**)VT)[meth.offset] = EE->getPointerToFunctionOrStub(func);
-      }
-    }
-
-#ifdef WITH_TRACER
-    Function* func = makeTracer(cl, false);
-  
-    void* codePtr = mvm::MvmModule::executionEngine->getPointerToFunction(func);
-    ((void**)VT)[VT_TRACER_OFFSET] = codePtr;
-    func->deleteBody();
-#endif
-    
-    // If there is no super, then it's the first VT that we allocate. Assign
-    // this VT to native types.
-    if (!(cl->super)) {
-      ClassArray::initialiseVT(cl);
-    }
-
-  } else {
-    for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
-      JavaMethod& meth = cl->virtualMethods[i];
-      ((void**)VT)[meth.offset] = &meth;
-    }
-  }
- 
-#endif
-  
-}
-
-
-const Type* LLVMClassInfo::getVirtualType() {
-  if (!virtualType) {
-    std::vector<const llvm::Type*> fields;
-    
-    if (classDef->super && classDef->super->super) {
-      LLVMClassInfo* CLI = 
-        JnjvmModule::getClassInfo((Class*)classDef->super);
-      fields.push_back(CLI->getVirtualType()->getContainedType(0));
-    } else {
-      fields.push_back(JnjvmModule::JavaObjectType->getContainedType(0));
-    }
-    
-    for (uint32 i = 0; i < classDef->nbVirtualFields; ++i) {
-      JavaField& field = classDef->virtualFields[i];
-      field.num = i + 1;
-      Typedef* type = field.getSignature();
-      LLVMAssessorInfo& LAI = JnjvmModule::getTypedefInfo(type);
-      fields.push_back(LAI.llvmType);
-    }
-    
-    
-    JnjvmModule* Mod = classDef->classLoader->getModule();
-    StructType* structType = StructType::get(fields, false);
-    virtualType = PointerType::getUnqual(structType);
-    const TargetData* targetData = Mod->TheTargetData;
-    const StructLayout* sl = targetData->getStructLayout(structType);
-    
-    for (uint32 i = 0; i < classDef->nbVirtualFields; ++i) {
-      JavaField& field = classDef->virtualFields[i];
-      field.ptrOffset = sl->getElementOffset(i + 1);
-    }
-    
-    uint64 size = Mod->getTypeSize(structType);
-    classDef->virtualSize = (uint32)size;
-    virtualSizeConstant = ConstantInt::get(Type::Int32Ty, size);
-    
-    if (!Mod->isStaticCompiling()) {
-      if (!classDef->virtualVT) {
-        Mod->makeVT((Class*)classDef);
-      } else {
-#ifdef WITH_TRACER
-        // So the class is vmjc'ed. Create the virtual tracer.
-        Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
-                                          GlobalValue::ExternalLinkage,
-                                          "markAndTraceObject", Mod);
-       
-        void* ptr = ((void**)classDef->virtualVT)[VT_TRACER_OFFSET];
-        Mod->executionEngine->addGlobalMapping(func, ptr);
-        virtualTracerFunction = func;
-#endif
-      }
-    } else {
-      Mod->makeVT(classDef);
-    }
-  
-  }
-
-  return virtualType;
-}
-
-const Type* LLVMClassInfo::getStaticType() {
-  
-  if (!staticType) {
-    Class* cl = (Class*)classDef;
-    std::vector<const llvm::Type*> fields;
-
-    for (uint32 i = 0; i < classDef->nbStaticFields; ++i) {
-      JavaField& field = classDef->staticFields[i];
-      field.num = i;
-      Typedef* type = field.getSignature();
-      LLVMAssessorInfo& LAI = JnjvmModule::getTypedefInfo(type);
-      fields.push_back(LAI.llvmType);
-    }
-  
-    JnjvmModule* Mod = cl->classLoader->getModule();
-    StructType* structType = StructType::get(fields, false);
-    staticType = PointerType::getUnqual(structType);
-    const TargetData* targetData = Mod->TheTargetData;
-    const StructLayout* sl = targetData->getStructLayout(structType);
-    
-    for (uint32 i = 0; i < classDef->nbStaticFields; ++i) {
-      JavaField& field = classDef->staticFields[i];
-      field.ptrOffset = sl->getElementOffset(i);
-    }
-    
-    uint64 size = Mod->getTypeSize(structType);
-    cl->staticSize = size;
-#ifdef WITH_TRACER
-    if (!Mod->isStaticCompiling()) {
-      Function* F = Mod->makeTracer(cl, true);
-      cl->staticTracer = (void (*)(void*)) (uintptr_t)
-        Mod->executionEngine->getPointerToFunction(F);
-      F->deleteBody();
-    }
-#endif
-  }
-  return staticType;
-}
-
-
-Value* LLVMClassInfo::getVirtualSize() {
-  if (!virtualSizeConstant) {
-    getVirtualType();
-    assert(classDef->virtualSize && "Zero size for a class?");
-    virtualSizeConstant = 
-      ConstantInt::get(Type::Int32Ty, classDef->virtualSize);
-  }
-  return virtualSizeConstant;
-}
-
-Function* LLVMClassInfo::getStaticTracer() {
-  if (!staticTracerFunction) {
-    getStaticType();
-  }
-  return staticTracerFunction;
-}
-
-Function* LLVMClassInfo::getVirtualTracer() {
-  if (!virtualTracerFunction) {
-    getVirtualType();
-  }
-  return virtualTracerFunction;
-}
-
-Function* LLVMMethodInfo::getMethod() {
-  if (!methodFunction) {
-    JnjvmClassLoader* JCL = methodDef->classDef->classLoader;
-    JnjvmModule* Mod = JCL->getModule();
-    if (Mod->isStaticCompiling()) {
-
-      const UTF8* jniConsClName = methodDef->classDef->name;
-      const UTF8* jniConsName = methodDef->name;
-      const UTF8* jniConsType = methodDef->type;
-      sint32 clen = jniConsClName->size;
-      sint32 mnlen = jniConsName->size;
-      sint32 mtlen = jniConsType->size;
-
-      char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN + 1 +
-                                ((mnlen + clen + mtlen) << 1));
-      
-      bool jnjvm = false;
-      if (isNative(methodDef->access)) {
-        // Verify if it's defined by JnJVM
-        JCL->nativeLookup(methodDef, jnjvm, buf);
-      }
-
-      if (!jnjvm) {
-        methodDef->jniConsFromMethOverloaded(buf + 1);
-        memcpy(buf, "JnJVM", 5);
-      }
-
-      methodFunction = Function::Create(getFunctionType(), 
-                                        GlobalValue::GhostLinkage, buf, Mod);
-
-    } else {
-
-      methodFunction = Function::Create(getFunctionType(), 
-                                        GlobalValue::GhostLinkage,
-                                        "", Mod);
-
-    }
-    methodFunction->addAnnotation(this);
-  }
-  return methodFunction;
-}
-
-const FunctionType* LLVMMethodInfo::getFunctionType() {
-  if (!functionType) {
-    Signdef* sign = methodDef->getSignature();
-    LLVMSignatureInfo* LSI = JnjvmModule::getSignatureInfo(sign);
-    assert(LSI);
-    if (isStatic(methodDef->access)) {
-      functionType = LSI->getStaticType();
-    } else {
-      functionType = LSI->getVirtualType();
-    }
-  }
-  return functionType;
-}
-
-ConstantInt* LLVMMethodInfo::getOffset() {
-  if (!offsetConstant) {
-    JnjvmModule::resolveVirtualClass(methodDef->classDef);
-    offsetConstant = ConstantInt::get(Type::Int32Ty, methodDef->offset);
-  }
-  return offsetConstant;
-}
-
-ConstantInt* LLVMFieldInfo::getOffset() {
-  if (!offsetConstant) {
-    if (isStatic(fieldDef->access)) {
-      JnjvmModule::resolveStaticClass(fieldDef->classDef); 
-    } else {
-      JnjvmModule::resolveVirtualClass(fieldDef->classDef); 
-    }
-    
-    offsetConstant = ConstantInt::get(Type::Int32Ty, fieldDef->num);
-  }
-  return offsetConstant;
-}
-
-const llvm::FunctionType* LLVMSignatureInfo::getVirtualType() {
- if (!virtualType) {
-    // Lock here because we are called by arbitrary code
-    mvm::MvmModule::protectIR();
-    std::vector<const llvm::Type*> llvmArgs;
-    uint32 size = signature->nbArguments;
-    Typedef* const* arguments = signature->getArgumentsType();
-
-    llvmArgs.push_back(JnjvmModule::JavaObjectType);
-
-    for (uint32 i = 0; i < size; ++i) {
-      Typedef* type = arguments[i];
-      LLVMAssessorInfo& LAI = JnjvmModule::getTypedefInfo(type);
-      llvmArgs.push_back(LAI.llvmType);
-    }
-
-#if defined(ISOLATE_SHARING)
-    llvmArgs.push_back(JnjvmModule::ConstantPoolType); // cached constant pool
-#endif
-
-    LLVMAssessorInfo& LAI = 
-      JnjvmModule::getTypedefInfo(signature->getReturnType());
-    virtualType = FunctionType::get(LAI.llvmType, llvmArgs, false);
-    mvm::MvmModule::unprotectIR();
-  }
-  return virtualType;
-}
-
-const llvm::FunctionType* LLVMSignatureInfo::getStaticType() {
- if (!staticType) {
-    // Lock here because we are called by arbitrary code
-    mvm::MvmModule::protectIR();
-    std::vector<const llvm::Type*> llvmArgs;
-    uint32 size = signature->nbArguments;
-    Typedef* const* arguments = signature->getArgumentsType();
-
-    for (uint32 i = 0; i < size; ++i) {
-      Typedef* type = arguments[i];
-      LLVMAssessorInfo& LAI = JnjvmModule::getTypedefInfo(type);
-      llvmArgs.push_back(LAI.llvmType);
-    }
+llvm::ConstantInt*  JnjvmModule::JavaObjectLockOffsetConstant;
+llvm::ConstantInt*  JnjvmModule::JavaObjectClassOffsetConstant;
 
-#if defined(ISOLATE_SHARING)
-    llvmArgs.push_back(JnjvmModule::ConstantPoolType); // cached constant pool
-#endif
 
-    LLVMAssessorInfo& LAI = 
-      JnjvmModule::getTypedefInfo(signature->getReturnType());
-    staticType = FunctionType::get(LAI.llvmType, llvmArgs, false);
-    mvm::MvmModule::unprotectIR();
-  }
-  return staticType;
-}
+#ifndef WITHOUT_VTABLE
+void JnjvmModule::allocateVT(Class* cl) {
+  for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
+    JavaMethod& meth = cl->virtualMethods[i];
+    if (meth.name->equals(cl->classLoader->bootstrapLoader->finalize)) {
+      meth.offset = 0;
+    } else {
+      JavaMethod* parent = cl->super? 
+        cl->super->lookupMethodDontThrow(meth.name, meth.type, false, true,
+                                         0) :
+        0;
 
-const llvm::FunctionType* LLVMSignatureInfo::getNativeType() {
-  if (!nativeType) {
-    // Lock here because we are called by arbitrary code
-    mvm::MvmModule::protectIR();
-    std::vector<const llvm::Type*> llvmArgs;
-    uint32 size = signature->nbArguments;
-    Typedef* const* arguments = signature->getArgumentsType();
-    
-    llvmArgs.push_back(mvm::MvmModule::ptrType); // JNIEnv
-    llvmArgs.push_back(JnjvmModule::JavaObjectType); // Class
-
-    for (uint32 i = 0; i < size; ++i) {
-      Typedef* type = arguments[i];
-      LLVMAssessorInfo& LAI = JnjvmModule::getTypedefInfo(type);
-      llvmArgs.push_back(LAI.llvmType);
+      uint64_t offset = 0;
+      if (!parent) {
+        offset = cl->virtualTableSize++;
+        meth.offset = offset;
+      } else {
+        offset = parent->offset;
+        meth.offset = parent->offset;
+      }
     }
-
-#if defined(ISOLATE_SHARING)
-    llvmArgs.push_back(JnjvmModule::ConstantPoolType); // cached constant pool
-#endif
-
-    LLVMAssessorInfo& LAI = 
-      JnjvmModule::getTypedefInfo(signature->getReturnType());
-    nativeType = FunctionType::get(LAI.llvmType, llvmArgs, false);
-    mvm::MvmModule::unprotectIR();
   }
-  return nativeType;
-}
-
-
-Function* LLVMSignatureInfo::createFunctionCallBuf(bool virt) {
-  
-  std::vector<Value*> Args;
 
-  JnjvmModule* Mod = signature->initialLoader->getModule();
-  const char* name = 0;
-  if (Mod->isStaticCompiling()) {
-    name = virt ? signature->printString("virtual_buf") :
-                  signature->printString("static_buf");
+  VirtualTable* VT = 0;
+  if (cl->super) {
+    uint64 size = cl->virtualTableSize;
+    mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
+    VT = (VirtualTable*)allocator.Allocate(size * sizeof(void*));
+    Class* super = (Class*)cl->super;
+    assert(cl->virtualTableSize >= cl->super->virtualTableSize &&
+      "Super VT bigger than own VT");
+    assert(super->virtualVT && "Super does not have a VT!");
+    memcpy(VT, super->virtualVT, cl->super->virtualTableSize * sizeof(void*));
   } else {
-    name = "";
-  }
-
-  Function* res = Function::Create(virt ? getVirtualBufType() : 
-                                          getStaticBufType(),
-                                   GlobalValue::InternalLinkage, name, Mod);
-  
-  BasicBlock* currentBlock = BasicBlock::Create("enter", res);
-  Function::arg_iterator i = res->arg_begin();
-  Value *obj, *ptr, *func;
-#if defined(ISOLATE_SHARING)
-  Value* ctp = i;
-#endif
-  ++i;
-  func = i;
-  ++i;
-  if (virt) {
-    obj = i;
-    ++i;
-    Args.push_back(obj);
-  }
-  ptr = i;
-  
-  Typedef* const* arguments = signature->getArgumentsType();
-  for (uint32 i = 0; i < signature->nbArguments; ++i) {
-  
-    LLVMAssessorInfo& LAI = JnjvmModule::getTypedefInfo(arguments[i]);
-    Value* val = new BitCastInst(ptr, LAI.llvmTypePtr, "", currentBlock);
-    Value* arg = new LoadInst(val, "", currentBlock);
-    Args.push_back(arg);
-    ptr = GetElementPtrInst::Create(ptr, JnjvmModule::constantEight, "",
-                                    currentBlock);
+    VT = JavaObjectVT;
   }
 
-#if defined(ISOLATE_SHARING)
-  Args.push_back(ctp);
+  cl->virtualVT = VT;
+}
 #endif
 
-  Value* val = CallInst::Create(func, Args.begin(), Args.end(), "",
-                                currentBlock);
-  if (res->getFunctionType()->getReturnType() != Type::VoidTy)
-    ReturnInst::Create(val, currentBlock);
-  else
-    ReturnInst::Create(currentBlock);
-  
-  return res;
-}
 
-Function* LLVMSignatureInfo::createFunctionCallAP(bool virt) {
-  
-  std::vector<Value*> Args;
+#ifdef WITH_TRACER
+llvm::Function* JnjvmModule::internalMakeTracer(Class* cl, bool stat) {
   
-  JnjvmModule* Mod = signature->initialLoader->getModule();
-  const char* name = 0;
-  if (Mod->isStaticCompiling()) {
-    name = virt ? signature->printString("virtual_ap") :
-                  signature->printString("static_ap");
+  LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(cl);
+  const Type* type = stat ? LCI->getStaticType() : LCI->getVirtualType();
+  JavaField* fields = 0;
+  uint32 nbFields = 0;
+  if (stat) {
+    fields = cl->getStaticFields();
+    nbFields = cl->nbStaticFields;
   } else {
-    name = "";
+    fields = cl->getVirtualFields();
+    nbFields = cl->nbVirtualFields;
   }
-
-  Function* res = Function::Create(virt ? getVirtualBufType() :
-                                          getStaticBufType(),
-                                   GlobalValue::InternalLinkage, name, Mod);
   
-  BasicBlock* currentBlock = BasicBlock::Create("enter", res);
-  Function::arg_iterator i = res->arg_begin();
-  Value *obj, *ap, *func;
-#if defined(ISOLATE_SHARING)
-  Value* ctp = i;
-#endif
-  ++i;
-  func = i;
-  ++i;
-  if (virt) {
-    obj = i;
-    Args.push_back(obj);
-    ++i;
-  }
-  ap = i;
+  Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
+                                    GlobalValue::InternalLinkage,
+                                    "", getLLVMModule());
 
-  Typedef* const* arguments = signature->getArgumentsType();
-  for (uint32 i = 0; i < signature->nbArguments; ++i) {
-    LLVMAssessorInfo& LAI = JnjvmModule::getTypedefInfo(arguments[i]);
-    Args.push_back(new VAArgInst(ap, LAI.llvmType, "", currentBlock));
-  }
+  Constant* zero = mvm::MvmModule::constantZero;
+  Argument* arg = func->arg_begin();
+  BasicBlock* block = BasicBlock::Create("", func);
+  llvm::Value* realArg = new BitCastInst(arg, type, "", block);
 
-#if defined(ISOLATE_SHARING)
-  Args.push_back(ctp);
+  std::vector<Value*> Args;
+  Args.push_back(arg);
+#ifdef MULTIPLE_GC
+  Value* GC = ++func->arg_begin();
+  Args.push_back(GC);
 #endif
+  if (!stat) {
+    if (cl->super == 0) {
+      CallInst::Create(JavaObjectTracerFunction, Args.begin(), Args.end(),
+                        "", block);
 
-  Value* val = CallInst::Create(func, Args.begin(), Args.end(), "",
-                                currentBlock);
-  if (res->getFunctionType()->getReturnType() != Type::VoidTy)
-    ReturnInst::Create(val, currentBlock);
-  else
-    ReturnInst::Create(currentBlock);
-  
-  return res;
-}
-
-const PointerType* LLVMSignatureInfo::getStaticPtrType() {
-  if (!staticPtrType) {
-    staticPtrType = PointerType::getUnqual(getStaticType());
-  }
-  return staticPtrType;
-}
-
-const PointerType* LLVMSignatureInfo::getVirtualPtrType() {
-  if (!virtualPtrType) {
-    virtualPtrType = PointerType::getUnqual(getVirtualType());
+    } else {
+      LLVMClassInfo* LCP = (LLVMClassInfo*)getClassInfo((Class*)(cl->super));
+      Function* F = LCP->virtualTracerFunction;
+      if (!F) {
+        if (isStaticCompiling()) {
+          F = internalMakeTracer(cl->super, false);
+        } else {
+          F = LCP->getVirtualTracer();
+        }
+        assert(F && "Still no virtual tracer for super");
+      }
+      CallInst::Create(F, Args.begin(), Args.end(), "", block);
+    }
   }
-  return virtualPtrType;
-}
-
-const PointerType* LLVMSignatureInfo::getNativePtrType() {
-  if (!nativePtrType) {
-    nativePtrType = PointerType::getUnqual(getNativeType());
+  
+  for (uint32 i = 0; i < nbFields; ++i) {
+    JavaField& cur = fields[i];
+    if (cur.getSignature()->trace()) {
+      LLVMFieldInfo* LFI = getFieldInfo(&cur);
+      std::vector<Value*> args; //size = 2
+      args.push_back(zero);
+      args.push_back(LFI->getOffset());
+      Value* ptr = GetElementPtrInst::Create(realArg, args.begin(), args.end(), 
+                                             "",block);
+      Value* val = new LoadInst(ptr, "", block);
+      Value* valCast = new BitCastInst(val, JnjvmModule::JavaObjectType, "",
+                                       block);
+      std::vector<Value*> Args;
+      Args.push_back(valCast);
+#ifdef MULTIPLE_GC
+      Args.push_back(GC);
+#endif
+      CallInst::Create(JnjvmModule::MarkAndTraceFunction, Args.begin(),
+                       Args.end(), "", block);
+    }
   }
-  return nativePtrType;
-}
-
 
-const FunctionType* LLVMSignatureInfo::getVirtualBufType() {
-  if (!virtualBufType) {
-    // Lock here because we are called by arbitrary code
-    mvm::MvmModule::protectIR();
-    std::vector<const llvm::Type*> Args2;
-    Args2.push_back(JnjvmModule::ConstantPoolType); // ctp
-    Args2.push_back(getVirtualPtrType());
-    Args2.push_back(JnjvmModule::JavaObjectType);
-    Args2.push_back(JnjvmModule::ptrType);
-    LLVMAssessorInfo& LAI = 
-      JnjvmModule::getTypedefInfo(signature->getReturnType());
-    virtualBufType = FunctionType::get(LAI.llvmType, Args2, false);
-    mvm::MvmModule::unprotectIR();
+  ReturnInst::Create(block);
+  
+  if (!stat) {
+    LCI->virtualTracerFunction = func;
+  } else {
+    LCI->staticTracerFunction = func;
   }
-  return virtualBufType;
-}
 
-const FunctionType* LLVMSignatureInfo::getStaticBufType() {
-  if (!staticBufType) {
-    // Lock here because we are called by arbitrary code
-    mvm::MvmModule::protectIR();
-    std::vector<const llvm::Type*> Args;
-    Args.push_back(JnjvmModule::ConstantPoolType); // ctp
-    Args.push_back(getStaticPtrType());
-    Args.push_back(JnjvmModule::ptrType);
-    LLVMAssessorInfo& LAI = 
-      JnjvmModule::getTypedefInfo(signature->getReturnType());
-    staticBufType = FunctionType::get(LAI.llvmType, Args, false);
-    mvm::MvmModule::unprotectIR();
-  }
-  return staticBufType;
+  return func;
 }
+#endif
 
-Function* LLVMSignatureInfo::getVirtualBuf() {
-  if (!virtualBufFunction) {
-    // Lock here because we are called by arbitrary code
-    mvm::MvmModule::protectIR();
-    virtualBufFunction = createFunctionCallBuf(true);
-    if (!signature->initialLoader->getModule()->isStaticCompiling()) {
-      signature->setVirtualCallBuf((intptr_t)
-        mvm::MvmModule::executionEngine->getPointerToGlobal(virtualBufFunction));
-      // Now that it's compiled, we don't need the IR anymore
-      virtualBufFunction->deleteBody();
-    }
-    mvm::MvmModule::unprotectIR();
-  }
-  return virtualBufFunction;
-}
 
-Function* LLVMSignatureInfo::getVirtualAP() {
-  if (!virtualAPFunction) {
-    // Lock here because we are called by arbitrary code
-    mvm::MvmModule::protectIR();
-    virtualAPFunction = createFunctionCallAP(true);
-    if (!signature->initialLoader->getModule()->isStaticCompiling()) {
-      signature->setVirtualCallAP((intptr_t)
-        mvm::MvmModule::executionEngine->getPointerToGlobal(virtualAPFunction));
-      // Now that it's compiled, we don't need the IR anymore
-      virtualAPFunction->deleteBody();
+void JnjvmModule::internalMakeVT(Class* cl) {
+  
+  VirtualTable* VT = 0;
+#ifdef WITHOUT_VTABLE
+  mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
+  VT = (VirtualTable*)allocator.Allocate(VT_SIZE);
+  memcpy(VT, JavaObjectVT, VT_SIZE);
+  cl->virtualVT = VT;
+#else
+  if (cl->super) {
+    if (isStaticCompiling() && !cl->super->virtualVT) {
+      makeVT(cl->super);
     }
-    mvm::MvmModule::unprotectIR();
-  }
-  return virtualAPFunction;
-}
 
-Function* LLVMSignatureInfo::getStaticBuf() {
-  if (!staticBufFunction) {
-    // Lock here because we are called by arbitrary code
-    mvm::MvmModule::protectIR();
-    staticBufFunction = createFunctionCallBuf(false);
-    if (!signature->initialLoader->getModule()->isStaticCompiling()) {
-      signature->setStaticCallBuf((intptr_t)
-        mvm::MvmModule::executionEngine->getPointerToGlobal(staticBufFunction));
-      // Now that it's compiled, we don't need the IR anymore
-      staticBufFunction->deleteBody();
-    }
-    mvm::MvmModule::unprotectIR();
+    cl->virtualTableSize = cl->super->virtualTableSize;
+  } else {
+    cl->virtualTableSize = VT_NB_FUNCS;
   }
-  return staticBufFunction;
-}
 
-Function* LLVMSignatureInfo::getStaticAP() {
-  if (!staticAPFunction) {
-    // Lock here because we are called by arbitrary code
-    mvm::MvmModule::protectIR();
-    staticAPFunction = createFunctionCallAP(false);
-    if (!signature->initialLoader->getModule()->isStaticCompiling()) {
-      signature->setStaticCallAP((intptr_t)
-        mvm::MvmModule::executionEngine->getPointerToGlobal(staticAPFunction));
-      // Now that it's compiled, we don't need the IR anymore
-      staticAPFunction->deleteBody();
-    }
-    mvm::MvmModule::unprotectIR();
-  }
-  return staticAPFunction;
+  // Allocate the virtual table.
+  allocateVT(cl);
+  VT = cl->virtualVT;
+#endif  
 }
 
 void JnjvmModule::resolveVirtualClass(Class* cl) {
@@ -2102,12 +258,9 @@
   }
 }
 
-Module* JnjvmModule::initialModule;
-
 void JnjvmModule::initialise() {
-  jnjvm::llvm_runtime::makeLLVMModuleContents(this);
-  Module* module = this;
-  initialModule = this;
+  jnjvm::llvm_runtime::makeLLVMModuleContents(getLLVMModule());
+  Module* module = getLLVMModule();
 
   VTType = PointerType::getUnqual(module->getTypeByName("VT"));
 
@@ -2201,68 +354,6 @@
   
   ClassReadyConstant = ConstantInt::get(Type::Int8Ty, ready);
  
-
-  if (staticCompilation) {
-    const Type* ATy = VTType->getContainedType(0);
-    PrimitiveArrayVT = new GlobalVariable(ATy, true,
-                                          GlobalValue::ExternalLinkage,
-                                          0, "JavaArrayVT", this);
-  
-    ReferenceArrayVT = new GlobalVariable(ATy, true, 
-                                          GlobalValue::ExternalLinkage,
-                                          0, "ArrayObjectVT", this);
-
-
-
-    ATy = JavaClassArrayType->getContainedType(0);
-    GlobalVariable* varGV = 0;
-    
-#define PRIMITIVE_ARRAY(name) \
-    varGV = new GlobalVariable(ATy, true, GlobalValue::ExternalLinkage, \
-                               0, #name, this); \
-    arrayClasses.insert(std::make_pair(&name, varGV));
-    
-    PRIMITIVE_ARRAY(ArrayOfBool)
-    PRIMITIVE_ARRAY(ArrayOfByte)
-    PRIMITIVE_ARRAY(ArrayOfChar)
-    PRIMITIVE_ARRAY(ArrayOfShort)
-    PRIMITIVE_ARRAY(ArrayOfInt)
-    PRIMITIVE_ARRAY(ArrayOfFloat)
-    PRIMITIVE_ARRAY(ArrayOfDouble)
-    PRIMITIVE_ARRAY(ArrayOfLong)
-
-#undef PRIMITIVE_ARRAY
-
-    std::vector<const llvm::Type*> llvmArgs;
-    llvmArgs.push_back(ptrType); // class loader.
-    const FunctionType* FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
-  
-    StaticInitializer = Function::Create(FTy, GlobalValue::InternalLinkage,
-                                         "Init", this);
-
-    llvmArgs.clear();
-    llvmArgs.push_back(JavaMethodType);
-    
-    FTy = FunctionType::get(ptrType, llvmArgs, false);
-  
-    NativeLoader = Function::Create(FTy, GlobalValue::ExternalLinkage,
-                                    "vmjcNativeLoader", this);
-    
-    llvmArgs.clear();
-    FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
-    ObjectPrinter = Function::Create(FTy, GlobalValue::ExternalLinkage,
-                                     "printJavaObject", this);
-
-  } else {
-    PrimitiveArrayVT = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty,
-                                                         uint64(JavaArrayVT)),
-                                                 VTType);
-  
-    ReferenceArrayVT = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty,
-                                                       uint64(ArrayObjectVT)),
-                                                 VTType);
-  }
-
   LLVMAssessorInfo::initialise();
 }
 
@@ -2274,59 +365,41 @@
   return PrimitiveArrayVT;
 }
 
-void JnjvmModule::setMethod(JavaMethod* meth, void* ptr, const char* name) {
-  Function* func = getMethodInfo(meth)->getMethod();
-  func->setName(name);
-  assert(ptr && "No value given");
-  if (executionEngine) executionEngine->addGlobalMapping(func, ptr);
-  func->setLinkage(GlobalValue::ExternalLinkage);
-}
-
-void JnjvmModule::printStats() {
-  fprintf(stderr, "----------------- Info from the module -----------------\n");
-  fprintf(stderr, "Number of native classes            : %llu\n", 
-          (unsigned long long int) nativeClasses.size());
-  fprintf(stderr, "Number of Java classes              : %llu\n",
-          (unsigned long long int) javaClasses.size());
-  fprintf(stderr, "Number of external array classes    : %llu\n",
-          (unsigned long long int) arrayClasses.size());
-  fprintf(stderr, "Number of virtual tables            : %llu\n", 
-          (unsigned long long int) virtualTables.size());
-  fprintf(stderr, "Number of static instances          : %llu\n", 
-          (unsigned long long int) staticInstances.size());
-  fprintf(stderr, "Number of constant pools            : %llu\n", 
-          (unsigned long long int) constantPools.size());
-  fprintf(stderr, "Number of strings                   : %llu\n", 
-          (unsigned long long int) strings.size());
-  fprintf(stderr, "Number of enveloppes                : %llu\n", 
-          (unsigned long long int) enveloppes.size());
-  fprintf(stderr, "Number of native functions          : %llu\n", 
-          (unsigned long long int) nativeFunctions.size());
-  fprintf(stderr, "----------------- Total size in .data ------------------\n");
-  uint64 size = 0;
-  for (Module::const_global_iterator i = global_begin(), e = global_end();
-       i != e; ++i) {
-    size += getTypeSize(i->getType());
-  }
-  fprintf(stderr, "%lluB\n", (unsigned long long int)size);
-}
-
-
 Function* JnjvmModule::getMethod(JavaMethod* meth) {
   return getMethodInfo(meth)->getMethod();
 }
 
-JnjvmModule::JnjvmModule(const std::string &ModuleID, bool sc) : 
+JnjvmModule::JnjvmModule(const std::string &ModuleID, JnjvmModule* Father) :
   MvmModule(ModuleID) {
   
-  staticCompilation = sc;
-  generateTracers = true;
-  generateStubs = true;
-  enabledException = true;
-  assumeCompiled = false;
-  if (!VTType) initialise();
-
-  Module* module = initialModule;
+  Module* module = 0;
+  if (!Father) {
+    assert(!VTType && "Attempting to create a new initial JnjvmModule");
+    enabledException = true;
+    initialise();
+    module = getLLVMModule();
+  } else {
+    enabledException = Father->enabledException;
+    module = getLLVMModule();
+    module->addTypeName("JavaObject", JavaObjectType);
+    module->addTypeName("JavaArray", JavaArrayType);
+    module->addTypeName("JavaCommonClass", JavaCommonClassType);
+    module->addTypeName("JavaClass", JavaClassType);
+    module->addTypeName("JavaClassPrimitive", JavaClassPrimitiveType);
+    module->addTypeName("JavaClassArray", JavaClassArrayType);
+    module->addTypeName("ArrayUInt8", JavaArrayUInt8Type);
+    module->addTypeName("ArraySInt8", JavaArraySInt8Type);
+    module->addTypeName("ArrayUInt16", JavaArrayUInt16Type);
+    module->addTypeName("ArraySInt16", JavaArraySInt16Type);
+    module->addTypeName("ArraySInt32", JavaArraySInt32Type);
+    module->addTypeName("ArrayLong", JavaArrayLongType);
+    module->addTypeName("ArrayFloat", JavaArrayFloatType);
+    module->addTypeName("ArrayDouble", JavaArrayDoubleType);
+    module->addTypeName("ArrayObject", JavaArrayObjectType);
+    module->addTypeName("CacheNode", CacheNodeType); 
+    module->addTypeName("Enveloppe", EnveloppeType);
+    module = Father->getLLVMModule();
+  }
    
   InterfaceLookupFunction = module->getFunction("jnjvmVirtualLookup");
   MultiCallNewFunction = module->getFunction("multiCallNew");
@@ -2424,256 +497,5 @@
 #endif
 
   GetLockFunction = module->getFunction("getLock");
-  
-  addTypeName("JavaObject", JavaObjectType);
-  addTypeName("JavaArray", JavaArrayType);
-  addTypeName("JavaCommonClass", JavaCommonClassType);
-  addTypeName("JavaClass", JavaClassType);
-  addTypeName("JavaClassPrimitive", JavaClassPrimitiveType);
-  addTypeName("JavaClassArray", JavaClassArrayType);
-  addTypeName("ArrayUInt8", JavaArrayUInt8Type);
-  addTypeName("ArraySInt8", JavaArraySInt8Type);
-  addTypeName("ArrayUInt16", JavaArrayUInt16Type);
-  addTypeName("ArraySInt16", JavaArraySInt16Type);
-  addTypeName("ArraySInt32", JavaArraySInt32Type);
-  addTypeName("ArrayLong", JavaArrayLongType);
-  addTypeName("ArrayFloat", JavaArrayFloatType);
-  addTypeName("ArrayDouble", JavaArrayDoubleType);
-  addTypeName("ArrayObject", JavaArrayObjectType);
-  addTypeName("CacheNode", CacheNodeType); 
-  addTypeName("Enveloppe", EnveloppeType); 
-}
-
-void LLVMAssessorInfo::initialise() {
-  AssessorInfo[I_VOID].llvmType = Type::VoidTy;
-  AssessorInfo[I_VOID].llvmTypePtr = 0;
-  AssessorInfo[I_VOID].llvmNullConstant = 0;
-  AssessorInfo[I_VOID].sizeInBytesConstant = 0;
-  
-  AssessorInfo[I_BOOL].llvmType = Type::Int8Ty;
-  AssessorInfo[I_BOOL].llvmTypePtr = PointerType::getUnqual(Type::Int8Ty);
-  AssessorInfo[I_BOOL].llvmNullConstant = 
-    Constant::getNullValue(Type::Int8Ty);
-  AssessorInfo[I_BOOL].sizeInBytesConstant = mvm::MvmModule::constantOne;
-  
-  AssessorInfo[I_BYTE].llvmType = Type::Int8Ty;
-  AssessorInfo[I_BYTE].llvmTypePtr = PointerType::getUnqual(Type::Int8Ty);
-  AssessorInfo[I_BYTE].llvmNullConstant = 
-    Constant::getNullValue(Type::Int8Ty);
-  AssessorInfo[I_BYTE].sizeInBytesConstant = mvm::MvmModule::constantOne;
-  
-  AssessorInfo[I_SHORT].llvmType = Type::Int16Ty;
-  AssessorInfo[I_SHORT].llvmTypePtr = PointerType::getUnqual(Type::Int16Ty);
-  AssessorInfo[I_SHORT].llvmNullConstant = 
-    Constant::getNullValue(Type::Int16Ty);
-  AssessorInfo[I_SHORT].sizeInBytesConstant = mvm::MvmModule::constantTwo;
-  
-  AssessorInfo[I_CHAR].llvmType = Type::Int16Ty;
-  AssessorInfo[I_CHAR].llvmTypePtr = PointerType::getUnqual(Type::Int16Ty);
-  AssessorInfo[I_CHAR].llvmNullConstant = 
-    Constant::getNullValue(Type::Int16Ty);
-  AssessorInfo[I_CHAR].sizeInBytesConstant = mvm::MvmModule::constantTwo;
-  
-  AssessorInfo[I_INT].llvmType = Type::Int32Ty;
-  AssessorInfo[I_INT].llvmTypePtr = PointerType::getUnqual(Type::Int32Ty);
-  AssessorInfo[I_INT].llvmNullConstant = 
-    Constant::getNullValue(Type::Int32Ty);
-  AssessorInfo[I_INT].sizeInBytesConstant = mvm::MvmModule::constantFour;
-  
-  AssessorInfo[I_FLOAT].llvmType = Type::FloatTy;
-  AssessorInfo[I_FLOAT].llvmTypePtr = PointerType::getUnqual(Type::FloatTy);
-  AssessorInfo[I_FLOAT].llvmNullConstant = 
-    Constant::getNullValue(Type::FloatTy);
-  AssessorInfo[I_FLOAT].sizeInBytesConstant = mvm::MvmModule::constantFour;
-  
-  AssessorInfo[I_LONG].llvmType = Type::Int64Ty;
-  AssessorInfo[I_LONG].llvmTypePtr = PointerType::getUnqual(Type::Int64Ty);
-  AssessorInfo[I_LONG].llvmNullConstant = 
-    Constant::getNullValue(Type::Int64Ty);
-  AssessorInfo[I_LONG].sizeInBytesConstant = mvm::MvmModule::constantEight;
-  
-  AssessorInfo[I_DOUBLE].llvmType = Type::DoubleTy;
-  AssessorInfo[I_DOUBLE].llvmTypePtr = PointerType::getUnqual(Type::DoubleTy);
-  AssessorInfo[I_DOUBLE].llvmNullConstant = 
-    Constant::getNullValue(Type::DoubleTy);
-  AssessorInfo[I_DOUBLE].sizeInBytesConstant = mvm::MvmModule::constantEight;
-  
-  AssessorInfo[I_TAB].llvmType = JnjvmModule::JavaObjectType;
-  AssessorInfo[I_TAB].llvmTypePtr =
-    PointerType::getUnqual(JnjvmModule::JavaObjectType);
-  AssessorInfo[I_TAB].llvmNullConstant =
-    JnjvmModule::JavaObjectNullConstant;
-  AssessorInfo[I_TAB].sizeInBytesConstant = mvm::MvmModule::constantPtrSize;
-  
-  AssessorInfo[I_REF].llvmType = JnjvmModule::JavaObjectType;
-  AssessorInfo[I_REF].llvmTypePtr =
-    PointerType::getUnqual(JnjvmModule::JavaObjectType);
-  AssessorInfo[I_REF].llvmNullConstant =
-    JnjvmModule::JavaObjectNullConstant;
-  AssessorInfo[I_REF].sizeInBytesConstant = mvm::MvmModule::constantPtrSize;
-}
-
-std::map<const char, LLVMAssessorInfo> LLVMAssessorInfo::AssessorInfo;
-
-LLVMAssessorInfo& JnjvmModule::getTypedefInfo(const Typedef* type) {
-  return LLVMAssessorInfo::AssessorInfo[type->getKey()->elements[0]];
-}
-
-static AnnotationID JavaMethod_ID(
-  AnnotationManager::getID("Java::JavaMethod"));
-
-
-LLVMMethodInfo::LLVMMethodInfo(JavaMethod* M) : 
-  llvm::Annotation(JavaMethod_ID), methodDef(M), methodFunction(0),
-  offsetConstant(0), functionType(0) {}
-
-JavaMethod* LLVMMethodInfo::get(const llvm::Function* F) {
-  LLVMMethodInfo *MI = (LLVMMethodInfo*)F->getAnnotation(JavaMethod_ID);
-  if (MI) return MI->methodDef;
-  return 0;
-}
-
-#ifdef SERVICE
-Value* JnjvmModule::getIsolate(Jnjvm* isolate, Value* Where) {
-  if (staticCompilation) {
-    llvm::Constant* varGV = 0;
-    isolate_iterator End = isolates.end();
-    isolate_iterator I = isolates.find(isolate);
-    if (I == End) {
-    
-      
-      Constant* cons = 
-        ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty,
-                                                   uint64_t(isolate)),
-                                  ptrType);
-
-      varGV = new GlobalVariable(ptrType, !staticCompilation,
-                                 GlobalValue::ExternalLinkage,
-                                 cons, "", this);
-    
-      isolates.insert(std::make_pair(isolate, varGV));
-    } else {
-      varGV = I->second;
-    }
-    if (BasicBlock* BB = dyn_cast<BasicBlock>(Where)) {
-      return new LoadInst(varGV, "", BB);
-    } else {
-      assert(dyn_cast<Instruction>(Where) && "Wrong use of module");
-      return new LoadInst(varGV, "", dyn_cast<Instruction>(Where));
-    }
-  } else {
-    ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64_t(isolate));
-    return ConstantExpr::getIntToPtr(CI, ptrType);
-  }
-}
-#endif
-
-void JnjvmModule::CreateStaticInitializer() {
-
-  std::vector<const llvm::Type*> llvmArgs;
-  llvmArgs.push_back(ptrType); // class loader
-  llvmArgs.push_back(JavaCommonClassType); // cl
-  const FunctionType* FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
-
-  Function* AddClass = Function::Create(FTy, GlobalValue::ExternalLinkage,
-                                        "vmjcAddPreCompiledClass", this);
  
-  llvmArgs.clear();
-  llvmArgs.push_back(ptrType); // class loader
-  llvmArgs.push_back(PointerType::getUnqual(JavaClassArrayType)); // array ptr
-  llvmArgs.push_back(UTF8Type); // name
-  FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
-  
-  Function* GetClassArray = Function::Create(FTy, GlobalValue::ExternalLinkage,
-                                             "vmjcGetClassArray", this);
-  
-  if (!StaticInitializer) {
-    std::vector<const llvm::Type*> llvmArgs;
-    llvmArgs.push_back(ptrType); // class loader.
-    const FunctionType* FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
-    
-    StaticInitializer = Function::Create(FTy, GlobalValue::InternalLinkage,
-                                         "Init", this);
-  }
-
-  BasicBlock* currentBlock = BasicBlock::Create("enter", StaticInitializer);
-  Function::arg_iterator loader = StaticInitializer->arg_begin();
-  
-  Value* Args[3];
-  // If we have defined some strings.
-  if (strings.begin() != strings.end()) {
-    llvmArgs.clear();
-    llvmArgs.push_back(ptrType); // class loader
-    llvmArgs.push_back(strings.begin()->second->getType()); // val
-    FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
-  
-    Function* AddString = Function::Create(FTy, GlobalValue::ExternalLinkage,
-                                           "vmjcAddString", this);
-  
-
-  
-    for (string_iterator i = strings.begin(), e = strings.end(); i != e; ++i) {
-      Args[0] = loader;
-      Args[1] = i->second;
-      CallInst::Create(AddString, Args, Args + 2, "", currentBlock);
-    }
-  }
-  
-  for (native_class_iterator i = nativeClasses.begin(), 
-       e = nativeClasses.end(); i != e; ++i) {
-    if (isCompiling(i->first)) {
-      Args[0] = loader;
-      Args[1] = ConstantExpr::getBitCast(i->second, JavaCommonClassType);
-      CallInst::Create(AddClass, Args, Args + 2, "", currentBlock);
-    }
-  }
-  
-  for (array_class_iterator i = arrayClasses.begin(), 
-       e = arrayClasses.end(); i != e; ++i) {
-    if (!(i->first->baseClass()->isPrimitive())) {
-      Args[0] = loader;
-      Args[1] = i->second;
-      Args[2] = getUTF8(i->first->name);
-      CallInst::Create(GetClassArray, Args, Args + 3, "", currentBlock);
-    }
-  }
-  
-
-  ReturnInst::Create(currentBlock);
-}
-
-void JnjvmModule::setNoInline(Class* cl) {
-  for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
-    JavaMethod& meth = cl->virtualMethods[i];
-    if (!isAbstract(meth.access)) {
-      LLVMMethodInfo* LMI = getMethodInfo(&meth);
-      Function* func = LMI->getMethod();
-      func->addFnAttr(Attribute::NoInline);
-    }
-  }
-  
-  for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
-    JavaMethod& meth = cl->staticMethods[i];
-    if (!isAbstract(meth.access)) {
-      LLVMMethodInfo* LMI = getMethodInfo(&meth);
-      Function* func = LMI->getMethod();
-      func->addFnAttr(Attribute::NoInline);
-    }
-  }
-}
-
-LLVMSignatureInfo* JnjvmModule::getSignatureInfo(Signdef* sign) {
-  return sign->getInfo<LLVMSignatureInfo>();
-}
-  
-LLVMClassInfo* JnjvmModule::getClassInfo(Class* cl) {
-  return cl->getInfo<LLVMClassInfo>();
-}
-
-LLVMFieldInfo* JnjvmModule::getFieldInfo(JavaField* field) {
-  return field->getInfo<LLVMFieldInfo>();
-}
-  
-LLVMMethodInfo* JnjvmModule::getMethodInfo(JavaMethod* method) {
-  return method->getInfo<LLVMMethodInfo>();
 }

Added: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleAOT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleAOT.cpp?rev=65555&view=auto

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleAOT.cpp (added)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleAOT.cpp Thu Feb 26 12:44:00 2009
@@ -0,0 +1,1417 @@
+//===--------- JnjvmModule.cpp - Definition of a Jnjvm module -------------===//
+//
+//                              JnJVM
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/BasicBlock.h"
+#include "llvm/Constants.h"
+#include "llvm/Instructions.h"
+
+#include "mvm/Threads/Thread.h"
+
+#include "jnjvm/JnjvmModule.h"
+
+#include "JavaCache.h"
+#include "JavaConstantPool.h"
+#include "JavaString.h"
+#include "JavaTypes.h"
+#include "JavaUpcalls.h"
+#include "Reader.h"
+
+#include <cstdio>
+
+using namespace jnjvm;
+using namespace llvm;
+
+extern void* JavaArrayVT[];
+extern void* ArrayObjectVT[];
+extern void* JavaObjectVT[];
+
+extern ClassArray ArrayOfBool;
+extern ClassArray ArrayOfByte;
+extern ClassArray ArrayOfChar;
+extern ClassArray ArrayOfShort;
+extern ClassArray ArrayOfInt;
+extern ClassArray ArrayOfFloat;
+extern ClassArray ArrayOfDouble;
+extern ClassArray ArrayOfLong;
+
+bool JnjvmModuleAOT::isCompiling(const CommonClass* cl) const {
+  if (cl->isClass()) {
+    // A class is being static compiled if owner class is not null.
+    return (((Class*)cl)->getOwnerClass() != 0);
+  } else if (cl->isArray()) {
+    return isCompiling(((ClassArray*)cl)->baseClass());
+  } else {
+    return false;
+  }
+}
+
+Constant* JnjvmModuleAOT::getNativeClass(CommonClass* classDef) {
+
+  if (classDef->isClass() || 
+      (classDef->isArray() && isCompiling(classDef)) ||
+      (assumeCompiled && !(classDef->isArray() && 
+        classDef->asArrayClass()->baseClass()->isPrimitive()))) {
+    native_class_iterator End = nativeClasses.end();
+    native_class_iterator I = nativeClasses.find(classDef);
+    if (I == End) {
+      const llvm::Type* Ty = 0;
+      
+      if (classDef->isArray()) {
+        Ty = JavaClassArrayType->getContainedType(0); 
+      } else {
+        Ty = JavaClassType->getContainedType(0); 
+      }
+    
+      GlobalVariable* varGV = 
+        new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage, 0,
+                           classDef->printString(), getLLVMModule());
+    
+      nativeClasses.insert(std::make_pair(classDef, varGV));
+
+      if (classDef->isClass() && isCompiling(classDef->asClass())) {
+        Constant* C = CreateConstantFromClass((Class*)classDef);
+        varGV->setInitializer(C);
+      } else if (classDef->isArray()) {
+        Constant* C = CreateConstantFromClassArray((ClassArray*)classDef);
+        varGV->setInitializer(C);
+      }
+
+      return varGV;
+
+    } else {
+      return I->second;
+    }
+  } else if (classDef->isArray()) {
+    array_class_iterator End = arrayClasses.end();
+    array_class_iterator I = arrayClasses.find((ClassArray*)classDef);
+    if (I == End) {
+      const llvm::Type* Ty = JavaClassArrayType; 
+    
+      GlobalVariable* varGV = 
+        new GlobalVariable(Ty, false, GlobalValue::InternalLinkage,
+                           Constant::getNullValue(Ty),
+                           classDef->printString(), getLLVMModule());
+    
+      arrayClasses.insert(std::make_pair((ClassArray*)classDef, varGV));
+      return varGV;
+    } else {
+      return I->second;
+    }
+  } else if (classDef->isPrimitive()) {
+    assert(0 && "implement me");
+  }
+  return 0;
+}
+
+Constant* JnjvmModuleAOT::getConstantPool(JavaConstantPool* ctp) {
+  llvm::Constant* varGV = 0;
+  constant_pool_iterator End = constantPools.end();
+  constant_pool_iterator I = constantPools.find(ctp);
+  if (I == End) {
+    const Type* Ty = ConstantPoolType->getContainedType(0);
+    varGV = new GlobalVariable(Ty, false,
+                               GlobalValue::InternalLinkage,
+                               Constant::getNullValue(Ty), "", getLLVMModule());
+    constantPools.insert(std::make_pair(ctp, varGV));
+    return varGV;
+  } else {
+    return I->second;
+  }
+}
+
+Constant* JnjvmModuleAOT::getMethodInClass(JavaMethod* meth) {
+  Class* cl = meth->classDef;
+  Constant* MOffset = 0;
+  Constant* Array = 0;
+  method_iterator SI = virtualMethods.find(cl);
+  for (uint32 i = 0; i < cl->nbVirtualMethods + cl->nbStaticMethods; ++i) {
+    if (&cl->virtualMethods[i] == meth) {
+      MOffset = ConstantInt::get(Type::Int32Ty, i);
+      break;
+    }
+  }
+  Array = SI->second; 
+  Constant* GEPs[2] = { constantZero, MOffset };
+  return ConstantExpr::getGetElementPtr(Array, GEPs, 2);
+}
+
+Constant* JnjvmModuleAOT::getString(JavaString* str) {
+  string_iterator SI = strings.find(str);
+  if (SI != strings.end()) {
+    return SI->second;
+  } else {
+    assert(str && "No string given");
+    LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo((Class*)str->getClass());
+    const llvm::Type* Ty = LCI->getVirtualType();
+    GlobalVariable* varGV = 
+      new GlobalVariable(Ty->getContainedType(0), false,
+                         GlobalValue::InternalLinkage,
+                         0, "", getLLVMModule());
+    Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV,
+                                          JavaObjectType);
+    strings.insert(std::make_pair(str, res));
+    Constant* C = CreateConstantFromJavaString(str);
+    varGV->setInitializer(C);
+    return res;
+  }
+}
+
+Constant* JnjvmModuleAOT::getEnveloppe(Enveloppe* enveloppe) {
+  enveloppe_iterator SI = enveloppes.find(enveloppe);
+  if (SI != enveloppes.end()) {
+    return SI->second;
+  } else {
+    GlobalVariable* varGV = 
+      new GlobalVariable(EnveloppeType->getContainedType(0), false,
+                         GlobalValue::InternalLinkage, 0, "", getLLVMModule());
+    enveloppes.insert(std::make_pair(enveloppe, varGV));
+    
+    Constant* C = CreateConstantFromEnveloppe(enveloppe);
+    varGV->setInitializer(C);
+    return varGV;
+  }
+}
+
+Constant* JnjvmModuleAOT::getJavaClass(CommonClass* cl) {
+  java_class_iterator End = javaClasses.end();
+  java_class_iterator I = javaClasses.find(cl);
+  if (I == End) {
+    Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass;
+    LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(javaClass);
+    const llvm::Type* Ty = LCI->getVirtualType();
+    
+    GlobalVariable* varGV = 
+      new GlobalVariable(Ty->getContainedType(0), false,
+                         GlobalValue::InternalLinkage, 0, "", getLLVMModule());
+    
+    Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV,
+                                          JavaObjectType);
+  
+    javaClasses.insert(std::make_pair(cl, res));
+    varGV->setInitializer(CreateConstantFromJavaClass(cl));
+    return res;
+  } else {
+    return I->second;
+    }
+}
+
+JavaObject* JnjvmModuleAOT::getFinalObject(llvm::Value* obj) {
+  return 0;
+}
+
+
+
+Constant* JnjvmModuleAOT::getFinalObject(JavaObject* obj) {
+  final_object_iterator End = finalObjects.end();
+  final_object_iterator I = finalObjects.find(obj);
+  if (I == End) {
+    abort();
+    return 0;
+  } else {
+    return I->second;
+  }
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromStaticInstance(Class* cl) {
+  LLVMClassInfo* LCI = getClassInfo(cl);
+  const Type* Ty = LCI->getStaticType();
+  const StructType* STy = dyn_cast<StructType>(Ty->getContainedType(0));
+  
+  std::vector<Constant*> Elts;
+  
+  for (uint32 i = 0; i < cl->nbStaticFields; ++i) {
+    JavaField& field = cl->staticFields[i];
+    const Typedef* type = field.getSignature();
+    LLVMAssessorInfo& LAI = getTypedefInfo(type);
+    const Type* Ty = LAI.llvmType;
+
+    Attribut* attribut = field.lookupAttribut(Attribut::constantAttribut);
+
+    if (!attribut) {
+      Elts.push_back(Constant::getNullValue(Ty));
+    } else {
+      Reader reader(attribut, cl->bytes);
+      JavaConstantPool * ctpInfo = cl->ctpInfo;
+      uint16 idx = reader.readU2();
+      if (type->isPrimitive()) {
+        if (Ty == Type::Int64Ty) {
+          Elts.push_back(ConstantInt::get(Ty, (uint64)ctpInfo->LongAt(idx)));
+        } else if (Ty == Type::DoubleTy) {
+          Elts.push_back(ConstantFP::get(Ty, ctpInfo->DoubleAt(idx)));
+        } else if (Ty == Type::FloatTy) {
+          Elts.push_back(ConstantFP::get(Ty, ctpInfo->FloatAt(idx)));
+        } else {
+          Elts.push_back(ConstantInt::get(Ty, (uint64)ctpInfo->IntegerAt(idx)));
+        }
+      } else if (type->isReference()){
+        const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[idx]);
+        JavaString* obj = ctpInfo->resolveString(utf8, idx);
+        Constant* C = getString(obj);
+        C = ConstantExpr::getBitCast(C, JavaObjectType);
+        Elts.push_back(C);
+      } else {
+        fprintf(stderr, "Implement me");
+        abort();
+      }
+    }
+  }
+   
+  return ConstantStruct::get(STy, Elts);
+}
+
+Constant* JnjvmModuleAOT::getStaticInstance(Class* classDef) {
+#ifdef ISOLATE
+  assert(0 && "Should not be here");
+  abort();
+#endif
+  static_instance_iterator End = staticInstances.end();
+  static_instance_iterator I = staticInstances.find(classDef);
+  if (I == End) {
+    
+    LLVMClassInfo* LCI = getClassInfo(classDef);
+    const Type* Ty = LCI->getStaticType();
+    Ty = Ty->getContainedType(0);
+    GlobalVariable* varGV = 
+      new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage,
+                         0, classDef->printString("<static>"), getLLVMModule());
+
+    Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV,
+                                          ptrType);
+    staticInstances.insert(std::make_pair(classDef, res));
+    
+    if (isCompiling(classDef)) { 
+      Constant* C = CreateConstantFromStaticInstance(classDef);
+      varGV->setInitializer(C);
+    }
+
+    return res;
+  } else {
+    return I->second;
+  }
+}
+
+Constant* JnjvmModuleAOT::getVirtualTable(Class* classDef) {
+  LLVMClassInfo* LCI = getClassInfo((Class*)classDef);
+  LCI->getVirtualType();
+  llvm::Constant* res = 0;
+  virtual_table_iterator End = virtualTables.end();
+  virtual_table_iterator I = virtualTables.find(classDef);
+  if (I == End) {
+    
+    const ArrayType* ATy = dyn_cast<ArrayType>(VTType->getContainedType(0));
+    const PointerType* PTy = dyn_cast<PointerType>(ATy->getContainedType(0));
+    ATy = ArrayType::get(PTy, classDef->virtualTableSize);
+    // Do not set a virtual table as a constant, because the runtime may
+    // modify it.
+    GlobalVariable* varGV = new GlobalVariable(ATy, false,
+                                               GlobalValue::ExternalLinkage,
+                                               0, 
+                                               classDef->printString("<VT>"),
+                                               getLLVMModule());
+  
+    res = ConstantExpr::getCast(Instruction::BitCast, varGV, VTType);
+    virtualTables.insert(std::make_pair(classDef, res));
+  
+    if (isCompiling(classDef)) {
+      Constant* C = CreateConstantFromVT(classDef);
+      varGV->setInitializer(C);
+    }
+    
+    return res;
+  } else {
+    return I->second;
+  } 
+}
+
+Constant* JnjvmModuleAOT::getNativeFunction(JavaMethod* meth, void* ptr) {
+  llvm::Constant* varGV = 0;
+  native_function_iterator End = nativeFunctions.end();
+  native_function_iterator I = nativeFunctions.find(meth);
+  if (I == End) {
+    
+    LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature());
+    const llvm::Type* valPtrType = LSI->getNativePtrType();
+    
+    varGV = new GlobalVariable(valPtrType, true,
+                               GlobalValue::InternalLinkage,
+                               Constant::getNullValue(valPtrType), "", getLLVMModule());
+  
+    nativeFunctions.insert(std::make_pair(meth, varGV));
+    return varGV;
+  } else {
+    return I->second;
+  }
+}
+
+Constant* JnjvmModuleAOT::CreateConstantForBaseObject(CommonClass* cl) {
+  const StructType* STy = 
+    dyn_cast<StructType>(JavaObjectType->getContainedType(0));
+  
+  std::vector<Constant*> Elmts;
+
+  // virtual table
+  if (cl->isClass()) {
+    Elmts.push_back(getVirtualTable(cl->asClass()));
+  } else {
+    ClassArray* clA = cl->asArrayClass();
+    if (clA->baseClass()->isPrimitive()) {
+      Elmts.push_back(PrimitiveArrayVT);
+    } else {
+      Elmts.push_back(ReferenceArrayVT);
+    }
+  }
+  
+  // classof
+  Constant* Cl = getNativeClass(cl);
+  Constant* ClGEPs[2] = { constantZero, constantZero };
+  Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2);
+    
+  Elmts.push_back(Cl);
+
+  // lock
+  Constant* L = ConstantInt::get(Type::Int64Ty,
+                                 mvm::Thread::get()->getThreadID());
+  Elmts.push_back(ConstantExpr::getIntToPtr(L, ptrType));
+
+  return ConstantStruct::get(STy, Elmts);
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromJavaClass(CommonClass* cl) {
+  Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass;
+  LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(javaClass);
+  const StructType* STy = 
+    dyn_cast<StructType>(LCI->getVirtualType()->getContainedType(0));
+
+  std::vector<Constant*> Elmts;
+
+  // JavaObject
+  Elmts.push_back(CreateConstantForBaseObject(javaClass));
+  
+  // signers
+  Elmts.push_back(Constant::getNullValue(JavaObjectType));
+  
+  // pd
+  Elmts.push_back(Constant::getNullValue(JavaObjectType));
+  
+  // vmdata
+  Constant* Cl = getNativeClass(cl);
+  Cl = ConstantExpr::getCast(Instruction::BitCast, Cl, JavaObjectType);
+  Elmts.push_back(Cl);
+
+  // constructor
+  Elmts.push_back(Constant::getNullValue(JavaObjectType));
+
+  return ConstantStruct::get(STy, Elmts);
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromJavaObject(JavaObject* obj) {
+  CommonClass* cl = obj->getClass();
+
+  if (cl->isArray()) {
+    Classpath* upcalls = cl->classLoader->bootstrapLoader->upcalls;
+    CommonClass* subClass = cl->asArrayClass()->baseClass();
+    if (subClass->isPrimitive()) {
+      if (subClass == upcalls->OfBool) {
+        return CreateConstantFromArray<ArrayUInt8>((ArrayUInt8*)obj,
+                                                   Type::Int8Ty);
+      } else if (subClass == upcalls->OfByte) {
+        return CreateConstantFromArray<ArraySInt8>((ArraySInt8*)obj,
+                                                   Type::Int8Ty);
+      } else if (subClass == upcalls->OfShort) {
+        return CreateConstantFromArray<ArraySInt16>((ArraySInt16*)obj,
+                                                    Type::Int16Ty);
+      } else if (subClass == upcalls->OfChar) {
+        return CreateConstantFromArray<ArrayUInt16>((ArrayUInt16*)obj,
+                                                    Type::Int16Ty);
+      } else if (subClass == upcalls->OfInt) {
+        return CreateConstantFromArray<ArraySInt32>((ArraySInt32*)obj,
+                                                    Type::Int32Ty);
+      } else if (subClass == upcalls->OfFloat) {
+        return CreateConstantFromArray<ArrayFloat>((ArrayFloat*)obj,
+                                                   Type::FloatTy);
+      } else if (subClass == upcalls->OfLong) {
+        return CreateConstantFromArray<ArrayLong>((ArrayLong*)obj,
+                                                  Type::Int64Ty);
+      } else if (subClass == upcalls->OfDouble) {
+        return CreateConstantFromArray<ArrayDouble>((ArrayDouble*)obj,
+                                                    Type::DoubleTy);
+      } else {
+        abort();
+      }
+    } else {
+      return CreateConstantFromArray<ArrayObject>((ArrayObject*)obj,
+                                                  JavaObjectType);
+    }
+  } else {
+    
+    std::vector<Constant*> Elmts;
+    
+    // JavaObject
+    Constant* CurConstant = CreateConstantForBaseObject(obj->getClass());
+
+    for (uint32 j = 0; j <= cl->depth; ++j) {
+      std::vector<Constant*> TempElts;
+      Elmts.push_back(CurConstant);
+      TempElts.push_back(CurConstant);
+      Class* curCl = cl->display[j]->asClass();
+      LLVMClassInfo* LCI = getClassInfo(curCl);
+      const StructType* STy = 
+        dyn_cast<StructType>(LCI->getVirtualType()->getContainedType(0));
+
+      for (uint32 i = 0; i < curCl->nbVirtualFields; ++i) {
+        JavaField& field = curCl->virtualFields[i];
+        const Typedef* type = field.getSignature();
+        if (type->isPrimitive()) {
+          const PrimitiveTypedef* prim = (PrimitiveTypedef*)type;
+          if (prim->isBool() || prim->isByte()) {
+            ConstantInt* CI = ConstantInt::get(Type::Int8Ty,
+                                               field.getInt8Field(obj));
+            TempElts.push_back(CI);
+          } else if (prim->isShort() || prim->isChar()) {
+            ConstantInt* CI = ConstantInt::get(Type::Int16Ty,
+                                               field.getInt16Field(obj));
+            TempElts.push_back(CI);
+          } else if (prim->isInt()) {
+            ConstantInt* CI = ConstantInt::get(Type::Int32Ty,
+                                               field.getInt32Field(obj));
+            TempElts.push_back(CI);
+          } else if (prim->isLong()) {
+            ConstantInt* CI = ConstantInt::get(Type::Int64Ty,
+                                               field.getLongField(obj));
+            TempElts.push_back(CI);
+          } else if (prim->isFloat()) {
+            ConstantFP* CF = ConstantFP::get(Type::FloatTy,
+                                             field.getFloatField(obj));
+            TempElts.push_back(CF);
+          } else if (prim->isDouble()) {
+            ConstantFP* CF = ConstantFP::get(Type::DoubleTy,
+                                             field.getDoubleField(obj));
+            TempElts.push_back(CF);
+          } else {
+            abort();
+          }
+        } else {
+          Constant* C = getFinalObject(field.getObjectField(obj));
+          TempElts.push_back(C);
+        }
+      }
+      CurConstant = ConstantStruct::get(STy, TempElts);
+    }
+
+    return CurConstant;
+  }
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromJavaString(JavaString* str) {
+  Class* cl = (Class*)str->getClass();
+  LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(cl);
+  const StructType* STy = 
+    dyn_cast<StructType>(LCI->getVirtualType()->getContainedType(0));
+
+  std::vector<Constant*> Elmts;
+
+  Elmts.push_back(CreateConstantForBaseObject(cl));
+
+  Constant* Array = getUTF8(str->value);
+  Constant* ObjGEPs[2] = { constantZero, constantZero };
+  Array = ConstantExpr::getGetElementPtr(Array, ObjGEPs, 2);
+  Elmts.push_back(Array);
+  
+  Elmts.push_back(ConstantInt::get(Type::Int32Ty, str->count));
+  Elmts.push_back(ConstantInt::get(Type::Int32Ty, str->cachedHashCode));
+  Elmts.push_back(ConstantInt::get(Type::Int32Ty, str->offset));
+  
+  return ConstantStruct::get(STy, Elmts);
+}
+
+
+Constant* JnjvmModuleAOT::CreateConstantFromCacheNode(CacheNode* CN) {
+  const StructType* STy = 
+    dyn_cast<StructType>(CacheNodeType->getContainedType(0));
+
+  std::vector<Constant*> Elmts;
+  Elmts.push_back(Constant::getNullValue(STy->getContainedType(0)));
+  Elmts.push_back(Constant::getNullValue(STy->getContainedType(1)));
+  Elmts.push_back(Constant::getNullValue(STy->getContainedType(2)));
+  Elmts.push_back(getEnveloppe(CN->enveloppe));
+  
+  return ConstantStruct::get(STy, Elmts);
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromEnveloppe(Enveloppe* val) {
+  
+  const StructType* STy = 
+    dyn_cast<StructType>(EnveloppeType->getContainedType(0));
+  const StructType* CNTy = 
+    dyn_cast<StructType>(CacheNodeType->getContainedType(0));
+  
+  std::vector<Constant*> Elmts;
+  
+  Constant* firstCache = CreateConstantFromCacheNode(val->firstCache);
+  Elmts.push_back(new GlobalVariable(CNTy, false,
+                                     GlobalValue::InternalLinkage,
+                                     firstCache, "", getLLVMModule()));
+  Elmts.push_back(getUTF8(val->methodName));
+  Elmts.push_back(getUTF8(val->methodSign));
+
+  Elmts.push_back(Constant::getNullValue(Type::Int8Ty));
+  Elmts.push_back(getNativeClass(val->classDef));
+  Elmts.push_back(firstCache);
+
+  return ConstantStruct::get(STy, Elmts);
+  
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromAttribut(Attribut& attribut) {
+  const StructType* STy = 
+    dyn_cast<StructType>(AttributType->getContainedType(0));
+
+
+  std::vector<Constant*> Elmts;
+
+  // name
+  Elmts.push_back(getUTF8(attribut.name));
+
+  // start
+  Elmts.push_back(ConstantInt::get(Type::Int32Ty, attribut.start));
+
+  // nbb
+  Elmts.push_back(ConstantInt::get(Type::Int32Ty, attribut.nbb));
+  
+  return ConstantStruct::get(STy, Elmts);
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromCommonClass(CommonClass* cl) {
+  const StructType* STy = 
+    dyn_cast<StructType>(JavaCommonClassType->getContainedType(0));
+
+  const ArrayType* ATy = ArrayType::get(JavaCommonClassType, cl->depth + 1);
+  
+  std::vector<Constant*> CommonClassElts;
+  std::vector<Constant*> TempElmts;
+  Constant* ClGEPs[2] = { constantZero, constantZero };
+
+  // display
+  for (uint32 i = 0; i <= cl->depth; ++i) {
+    Constant* Cl = getNativeClass(cl->display[i]);
+    if (Cl->getType() != JavaCommonClassType)
+      Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2);
+    
+    TempElmts.push_back(Cl);
+  }
+
+  Constant* display = ConstantArray::get(ATy, TempElmts);
+  TempElmts.clear();
+  display = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
+                               display, "", getLLVMModule());
+  display = ConstantExpr::getCast(Instruction::BitCast, display,
+                                  PointerType::getUnqual(JavaCommonClassType));
+  CommonClassElts.push_back(display);
+
+  // depth
+  CommonClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->depth));
+  
+  // delegatee
+  ATy = dyn_cast<ArrayType>(STy->getContainedType(2));
+  assert(ATy && "Malformed type");
+
+  Constant* TCM[1] = { getJavaClass(cl) };
+  CommonClassElts.push_back(ConstantArray::get(ATy, TCM, 1));
+  
+  // access
+  CommonClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->access));
+ 
+  // interfaces
+  if (cl->nbInterfaces) {
+    for (uint32 i = 0; i < cl->nbInterfaces; ++i) {
+      TempElmts.push_back(getNativeClass(cl->interfaces[i]));
+    }
+
+    ATy = ArrayType::get(JavaClassType, cl->nbInterfaces);
+    Constant* interfaces = ConstantArray::get(ATy, TempElmts);
+    interfaces = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
+                                    interfaces, "", getLLVMModule());
+    interfaces = ConstantExpr::getCast(Instruction::BitCast, interfaces,
+                                       PointerType::getUnqual(JavaClassType));
+
+    CommonClassElts.push_back(interfaces);
+  } else {
+    const Type* Ty = PointerType::getUnqual(JavaClassType);
+    CommonClassElts.push_back(Constant::getNullValue(Ty));
+  }
+
+  // nbInterfaces
+  CommonClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->nbInterfaces));
+
+  // name
+  CommonClassElts.push_back(getUTF8(cl->name));
+
+  // super
+  if (cl->super) {
+    CommonClassElts.push_back(getNativeClass(cl->super));
+  } else {
+    CommonClassElts.push_back(Constant::getNullValue(JavaClassType));
+  }
+
+  // classLoader: store the static initializer, it will be overriden once
+  // the class is loaded.
+  Constant* loader = ConstantExpr::getBitCast(StaticInitializer, ptrType);
+  CommonClassElts.push_back(loader);
+ 
+  return ConstantStruct::get(STy, CommonClassElts);
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromJavaField(JavaField& field) {
+  const StructType* STy = 
+    dyn_cast<StructType>(JavaFieldType->getContainedType(0));
+  
+  std::vector<Constant*> FieldElts;
+  std::vector<Constant*> TempElts;
+  
+  // signature
+  FieldElts.push_back(Constant::getNullValue(ptrType));
+  
+  // access
+  FieldElts.push_back(ConstantInt::get(Type::Int16Ty, field.access));
+
+  // name
+  FieldElts.push_back(getUTF8(field.name));
+
+  // type
+  FieldElts.push_back(getUTF8(field.type));
+  
+  // attributs 
+  if (field.nbAttributs) {
+    const ArrayType* ATy = ArrayType::get(AttributType->getContainedType(0),
+                                          field.nbAttributs);
+    for (uint32 i = 0; i < field.nbAttributs; ++i) {
+      TempElts.push_back(CreateConstantFromAttribut(field.attributs[i]));
+    }
+
+    Constant* attributs = ConstantArray::get(ATy, TempElts);
+    TempElts.clear();
+    attributs = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
+                                   attributs, "", getLLVMModule());
+    attributs = ConstantExpr::getCast(Instruction::BitCast, attributs,
+                                      AttributType);
+  
+    FieldElts.push_back(attributs);
+  } else {
+    FieldElts.push_back(Constant::getNullValue(AttributType));
+  }
+  
+  // nbAttributs
+  FieldElts.push_back(ConstantInt::get(Type::Int16Ty, field.nbAttributs));
+
+  // classDef
+  FieldElts.push_back(getNativeClass(field.classDef));
+
+  // ptrOffset
+  FieldElts.push_back(ConstantInt::get(Type::Int32Ty, field.ptrOffset));
+
+  // num
+  FieldElts.push_back(ConstantInt::get(Type::Int16Ty, field.num));
+
+  //JInfo
+  FieldElts.push_back(Constant::getNullValue(ptrType));
+  
+  return ConstantStruct::get(STy, FieldElts); 
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromJavaMethod(JavaMethod& method) {
+  const StructType* STy = 
+    dyn_cast<StructType>(JavaMethodType->getContainedType(0));
+  
+  std::vector<Constant*> MethodElts;
+  std::vector<Constant*> TempElts;
+  
+  // signature
+  MethodElts.push_back(Constant::getNullValue(ptrType));
+  
+  // access
+  MethodElts.push_back(ConstantInt::get(Type::Int16Ty, method.access));
+ 
+  // attributs
+  if (method.nbAttributs) {
+    const ArrayType* ATy = ArrayType::get(AttributType->getContainedType(0),
+                                          method.nbAttributs);
+    for (uint32 i = 0; i < method.nbAttributs; ++i) {
+      TempElts.push_back(CreateConstantFromAttribut(method.attributs[i]));
+    }
+
+    Constant* attributs = ConstantArray::get(ATy, TempElts);
+    TempElts.clear();
+    attributs = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
+                                   attributs, "", getLLVMModule());
+    attributs = ConstantExpr::getCast(Instruction::BitCast, attributs,
+                                      AttributType);
+
+    MethodElts.push_back(attributs);
+  } else {
+    MethodElts.push_back(Constant::getNullValue(AttributType));
+  }
+  
+  // nbAttributs
+  MethodElts.push_back(ConstantInt::get(Type::Int16Ty, method.nbAttributs));
+  
+  // enveloppes
+  // already allocated by the JIT, don't reallocate them.
+  MethodElts.push_back(Constant::getNullValue(EnveloppeType));
+  
+  // nbEnveloppes
+  // 0 because we're not allocating here.
+  MethodElts.push_back(ConstantInt::get(Type::Int16Ty, 0));
+  
+  // classDef
+  MethodElts.push_back(getNativeClass(method.classDef));
+  
+  // name
+  MethodElts.push_back(getUTF8(method.name));
+
+  // type
+  MethodElts.push_back(getUTF8(method.type));
+  
+  // canBeInlined
+  MethodElts.push_back(ConstantInt::get(Type::Int8Ty, method.canBeInlined));
+
+  // code
+  if (isAbstract(method.access)) {
+    MethodElts.push_back(Constant::getNullValue(ptrType));
+  } else {
+    LLVMMethodInfo* LMI = getMethodInfo(&method);
+    Function* func = LMI->getMethod();
+    MethodElts.push_back(ConstantExpr::getCast(Instruction::BitCast, func,
+                                               ptrType));
+  }
+
+  // offset
+  MethodElts.push_back(ConstantInt::get(Type::Int32Ty, method.offset));
+
+  //JInfo
+  MethodElts.push_back(Constant::getNullValue(ptrType));
+  
+  return ConstantStruct::get(STy, MethodElts); 
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromClassPrimitive(ClassPrimitive* cl) {
+  const StructType* STy = 
+    dyn_cast<StructType>(JavaClassPrimitiveType->getContainedType(0));
+  
+  std::vector<Constant*> ClassElts;
+  
+  // common class
+  ClassElts.push_back(CreateConstantFromCommonClass(cl));
+
+  // primSize
+  ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->primSize));
+
+  return ConstantStruct::get(STy, ClassElts);
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromClassArray(ClassArray* cl) {
+  const StructType* STy = 
+    dyn_cast<StructType>(JavaClassArrayType->getContainedType(0));
+  
+  std::vector<Constant*> ClassElts;
+  Constant* ClGEPs[2] = { constantZero, constantZero };
+  
+  // common class
+  ClassElts.push_back(CreateConstantFromCommonClass(cl));
+
+  // baseClass
+  Constant* Cl = getNativeClass(cl->baseClass());
+  if (Cl->getType() != JavaCommonClassType)
+    Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2);
+    
+  ClassElts.push_back(Cl);
+
+  return ConstantStruct::get(STy, ClassElts);
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromClass(Class* cl) {
+  const StructType* STy = 
+    dyn_cast<StructType>(JavaClassType->getContainedType(0));
+  
+  std::vector<Constant*> ClassElts;
+  std::vector<Constant*> TempElts;
+
+  // common class
+  ClassElts.push_back(CreateConstantFromCommonClass(cl));
+
+  // virtualSize
+  ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->virtualSize));
+
+  // virtualTable
+  ClassElts.push_back(getVirtualTable(cl));
+
+  // IsolateInfo
+  const ArrayType* ATy = dyn_cast<ArrayType>(STy->getContainedType(3));
+  assert(ATy && "Malformed type");
+  
+  const StructType* TCMTy = dyn_cast<StructType>(ATy->getContainedType(0));
+  assert(TCMTy && "Malformed type");
+
+  uint32 status = cl->needsInitialisationCheck() ? vmjc : ready;
+  TempElts.push_back(ConstantInt::get(Type::Int8Ty, status));
+  TempElts.push_back(ConstantInt::get(Type::Int1Ty, status == ready ? 1 : 0));
+  TempElts.push_back(getStaticInstance(cl));
+  Constant* CStr[1] = { ConstantStruct::get(TCMTy, TempElts) };
+  TempElts.clear();
+  ClassElts.push_back(ConstantArray::get(ATy, CStr, 1));
+
+  // thinlock
+  ClassElts.push_back(Constant::getNullValue(ptrType));
+
+  if (cl->nbVirtualFields + cl->nbStaticFields) {
+    ATy = ArrayType::get(JavaFieldType->getContainedType(0), 
+                         cl->nbVirtualFields + cl->nbStaticFields);
+  }
+
+  // virtualFields
+  if (cl->nbVirtualFields) {
+
+    for (uint32 i = 0; i < cl->nbVirtualFields; ++i) {
+      TempElts.push_back(CreateConstantFromJavaField(cl->virtualFields[i]));
+    }
+
+  } 
+  
+  // staticFields
+  if (cl->nbStaticFields) {
+
+    for (uint32 i = 0; i < cl->nbStaticFields; ++i) {
+      TempElts.push_back(CreateConstantFromJavaField(cl->staticFields[i]));
+    }
+
+  }
+
+  Constant* fields = 0;
+  if (cl->nbStaticFields + cl->nbVirtualFields) {
+  
+    fields = ConstantArray::get(ATy, TempElts);
+    TempElts.clear();
+    fields = new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
+                                fields, "", getLLVMModule());
+    fields = ConstantExpr::getCast(Instruction::BitCast, fields, JavaFieldType);
+  } else {
+    fields = Constant::getNullValue(JavaFieldType);
+  }
+
+  // virtualFields
+  ClassElts.push_back(fields);
+
+  ConstantInt* nbVirtualFields = 
+    ConstantInt::get(Type::Int16Ty, cl->nbVirtualFields);
+  // nbVirtualFields
+  ClassElts.push_back(nbVirtualFields);
+  
+  // staticFields
+  // Output null, getLLVMModule() will be set in  the initializer. Otherwise, the
+  // assembly emitter of LLVM will try to align the data.
+  ClassElts.push_back(Constant::getNullValue(JavaFieldType));
+
+  // nbStaticFields
+  ClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->nbStaticFields));
+  
+  // virtualMethods
+  if (cl->nbVirtualMethods + cl->nbStaticMethods) {
+    ATy = ArrayType::get(JavaMethodType->getContainedType(0),
+                         cl->nbVirtualMethods + cl->nbStaticMethods);
+  }
+
+  if (cl->nbVirtualMethods) {
+    for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
+      TempElts.push_back(CreateConstantFromJavaMethod(cl->virtualMethods[i]));
+    }
+  }
+    
+  if (cl->nbStaticMethods) {
+    for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
+      TempElts.push_back(CreateConstantFromJavaMethod(cl->staticMethods[i]));
+    }
+  }
+
+  Constant* methods = 0;
+  if (cl->nbVirtualMethods + cl->nbStaticMethods) {
+    methods = ConstantArray::get(ATy, TempElts);
+    TempElts.clear();
+    GlobalVariable* GV = new GlobalVariable(ATy, false,
+                                            GlobalValue::InternalLinkage,
+                                            methods, "", getLLVMModule());
+    virtualMethods.insert(std::make_pair(cl, GV));
+    methods = ConstantExpr::getCast(Instruction::BitCast, GV,
+                                    JavaMethodType);
+  } else {
+    methods = Constant::getNullValue(JavaMethodType);
+  }
+
+  // virtualMethods
+  ClassElts.push_back(methods);
+
+  ConstantInt* nbVirtualMethods = 
+    ConstantInt::get(Type::Int16Ty, cl->nbVirtualMethods);
+  // nbVirtualMethods
+  ClassElts.push_back(nbVirtualMethods);
+  
+  // staticMethods
+  // Output null, getLLVMModule() will be set in  the initializer.
+  ClassElts.push_back(Constant::getNullValue(JavaMethodType));
+
+  // nbStaticMethods
+  ClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->nbStaticMethods));
+
+  // ownerClass
+  ClassElts.push_back(Constant::getNullValue(ptrType));
+  
+  // bytes
+  ClassElts.push_back(Constant::getNullValue(JavaArrayUInt8Type));
+
+  // ctpInfo
+  ClassElts.push_back(Constant::getNullValue(ptrType));
+
+  // attributs
+  if (cl->nbAttributs) {
+    ATy = ArrayType::get(AttributType->getContainedType(0),
+                         cl->nbAttributs);
+
+    for (uint32 i = 0; i < cl->nbAttributs; ++i) {
+      TempElts.push_back(CreateConstantFromAttribut(cl->attributs[i]));
+    }
+
+    Constant* attributs = ConstantArray::get(ATy, TempElts);
+    TempElts.clear();
+    attributs = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
+                                   attributs, "", getLLVMModule());
+    attributs = ConstantExpr::getCast(Instruction::BitCast, attributs,
+                                      AttributType);
+    ClassElts.push_back(attributs);
+  } else {
+    ClassElts.push_back(Constant::getNullValue(AttributType));
+  }
+  
+  // nbAttributs
+  ClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->nbAttributs));
+  
+  // innerClasses
+  if (cl->nbInnerClasses) {
+    for (uint32 i = 0; i < cl->nbInnerClasses; ++i) {
+      TempElts.push_back(getNativeClass(cl->innerClasses[i]));
+    }
+
+    ATy = ArrayType::get(JavaClassType, cl->nbInnerClasses);
+    Constant* innerClasses = ConstantArray::get(ATy, TempElts);
+    innerClasses = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage,
+                                      innerClasses, "", getLLVMModule());
+    innerClasses = ConstantExpr::getCast(Instruction::BitCast, innerClasses,
+                                         PointerType::getUnqual(JavaClassType));
+
+    ClassElts.push_back(innerClasses);
+  } else {
+    const Type* Ty = PointerType::getUnqual(JavaClassType);
+    ClassElts.push_back(Constant::getNullValue(Ty));
+  }
+
+  // nbInnerClasses
+  ClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->nbInnerClasses));
+
+  // outerClass
+  if (cl->outerClass) {
+    ClassElts.push_back(getNativeClass(cl->outerClass));
+  } else {
+    ClassElts.push_back(Constant::getNullValue(JavaClassType));
+  }
+
+  // innerAccess
+  ClassElts.push_back(ConstantInt::get(Type::Int16Ty, cl->innerAccess));
+  
+  // innerOuterResolved
+  ClassElts.push_back(ConstantInt::get(Type::Int8Ty, cl->innerOuterResolved));
+  
+  // virtualTableSize
+  ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->virtualTableSize));
+  
+  // staticSize
+  ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->staticSize));
+
+  // JInfo
+  ClassElts.push_back(Constant::getNullValue(ptrType));
+
+  // staticTracer
+  const Type* FTy = STy->getContainedType(STy->getNumContainedTypes() - 1);
+#ifdef WITH_TRACER
+  Function* F = makeTracer(cl, true);
+  Constant* staticTracer = ConstantExpr::getCast(Instruction::BitCast, F, FTy);
+#else
+  Constant* staticTracer = ConstantExpr::getNullValue(FTy);
+#endif
+  ClassElts.push_back(staticTracer);
+
+
+  return ConstantStruct::get(STy, ClassElts);
+}
+
+template<typename T>
+Constant* JnjvmModuleAOT::CreateConstantFromArray(T* val, const Type* Ty) {
+  std::vector<const Type*> Elemts;
+  const ArrayType* ATy = ArrayType::get(Ty, val->size);
+  Elemts.push_back(JavaObjectType->getContainedType(0));
+  Elemts.push_back(pointerSizeType == Type::Int32Ty ? Type::Int32Ty : 
+                                                      Type::Int64Ty);
+
+  Elemts.push_back(ATy);
+
+  const StructType* STy = StructType::get(Elemts);
+  
+  std::vector<Constant*> Cts;
+  Cts.push_back(CreateConstantForBaseObject(val->getClass()));
+  Cts.push_back(ConstantInt::get(pointerSizeType, val->size));
+  
+  std::vector<Constant*> Vals;
+  for (sint32 i = 0; i < val->size; ++i) {
+    if (Ty->isInteger()) {
+      Vals.push_back(ConstantInt::get(Ty, (uint64)val->elements[i]));
+    } else if (Ty->isFloatingPoint()) {
+      Vals.push_back(ConstantFP::get(Ty, (double)(size_t)val->elements[i]));
+    } else {
+      Vals.push_back(getFinalObject((JavaObject*)(size_t)val->elements[i]));
+    }
+  }
+
+  Cts.push_back(ConstantArray::get(ATy, Vals));
+  
+  return ConstantStruct::get(STy, Cts);
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromUTF8(const UTF8* val) {
+  std::vector<const Type*> Elemts;
+  const ArrayType* ATy = ArrayType::get(Type::Int16Ty, val->size);
+  Elemts.push_back(JavaObjectType->getContainedType(0));
+  Elemts.push_back(pointerSizeType == Type::Int32Ty ? Type::Int32Ty : 
+                                                      Type::Int64Ty);
+
+  Elemts.push_back(ATy);
+
+  const StructType* STy = StructType::get(Elemts);
+  
+  std::vector<Constant*> Cts;
+  Cts.push_back(CreateConstantForBaseObject(&ArrayOfChar));
+  Cts.push_back(ConstantInt::get(pointerSizeType, val->size));
+  
+  std::vector<Constant*> Vals;
+  for (sint32 i = 0; i < val->size; ++i) {
+    Vals.push_back(ConstantInt::get(Type::Int16Ty, val->elements[i]));
+  }
+
+  Cts.push_back(ConstantArray::get(ATy, Vals));
+  
+  return ConstantStruct::get(STy, Cts);
+
+}
+
+Constant* JnjvmModuleAOT::getUTF8(const UTF8* val) {
+  utf8_iterator End = utf8s.end();
+  utf8_iterator I = utf8s.find(val);
+  if (I == End) {
+    Constant* C = CreateConstantFromUTF8(val);
+    GlobalVariable* varGV = new GlobalVariable(C->getType(), true,
+                                               GlobalValue::InternalLinkage,
+                                               C, "", getLLVMModule());
+    
+    Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV,
+                                          UTF8Type);
+    utf8s.insert(std::make_pair(val, res));
+
+    return res;
+  } else {
+    return I->second;
+  }
+}
+
+Constant* JnjvmModuleAOT::CreateConstantFromVT(Class* classDef) {
+  uint32 size = classDef->virtualTableSize;
+  VirtualTable* VT = classDef->virtualVT;
+  const ArrayType* ATy = dyn_cast<ArrayType>(VTType->getContainedType(0));
+  const PointerType* PTy = dyn_cast<PointerType>(ATy->getContainedType(0));
+  ATy = ArrayType::get(PTy, size);
+
+  ConstantPointerNull* N = ConstantPointerNull::get(PTy);
+  std::vector<Constant*> Elemts;
+   
+  // Destructor
+  JavaMethod* meth = ((JavaMethod**)VT)[0];
+  LLVMMethodInfo* LMI = getMethodInfo(meth);
+  Function* Finalizer = LMI->getMethod();
+  Elemts.push_back(Finalizer ? 
+      ConstantExpr::getCast(Instruction::BitCast, Finalizer, PTy) : N);
+  
+  // Delete
+  Elemts.push_back(N);
+  
+  // Tracer
+#ifdef WITH_TRACER
+  Function* Tracer = makeTracer(classDef, false);
+  Elemts.push_back(Tracer ? 
+      ConstantExpr::getCast(Instruction::BitCast, Tracer, PTy) : N);
+#else
+  Elemts.push_back(N);
+#endif
+
+  // Printer
+  Elemts.push_back(ConstantExpr::getBitCast(ObjectPrinter, PTy));
+  
+  // Hashcode
+  Elemts.push_back(N);  
+
+  for (uint32 i = VT_NB_FUNCS; i < size; ++i) {
+    JavaMethod* meth = ((JavaMethod**)VT)[i];
+    LLVMMethodInfo* LMI = getMethodInfo(meth);
+    Function* F = LMI->getMethod();
+    if (isAbstract(meth->access)) {
+      Elemts.push_back(Constant::getNullValue(PTy));
+    } else {
+      Elemts.push_back(ConstantExpr::getCast(Instruction::BitCast, F, PTy));
+    }
+  }
+
+  Constant* Array = ConstantArray::get(ATy, Elemts);
+  
+  return Array;
+}
+
+#ifdef WITH_TRACER
+llvm::Function* JnjvmModuleAOT::makeTracer(Class* cl, bool stat) {
+  if (!generateTracers) {
+    return JavaObjectTracerFunction;
+  } else {
+    return internalMakeTracer(cl, stat);
+  }
+}
+#endif
+
+JnjvmModuleAOT::JnjvmModuleAOT(const std::string& ModuleID,
+                               JnjvmModule* Father) :
+  JnjvmModule(ModuleID, Father) {
+ 
+  generateTracers = true;
+  generateStubs = true;
+  assumeCompiled = false;
+
+  const Type* ATy = VTType->getContainedType(0);
+  PrimitiveArrayVT = new GlobalVariable(ATy, true,
+                                        GlobalValue::ExternalLinkage,
+                                        0, "JavaArrayVT", getLLVMModule());
+
+  ReferenceArrayVT = new GlobalVariable(ATy, true, 
+                                        GlobalValue::ExternalLinkage,
+                                        0, "ArrayObjectVT", getLLVMModule());
+
+
+
+  ATy = JavaClassArrayType->getContainedType(0);
+  GlobalVariable* varGV = 0;
+  
+#define PRIMITIVE_ARRAY(name) \
+  varGV = new GlobalVariable(ATy, true, GlobalValue::ExternalLinkage, \
+                             0, #name, getLLVMModule()); \
+  arrayClasses.insert(std::make_pair(&name, varGV));
+  
+  PRIMITIVE_ARRAY(ArrayOfBool)
+  PRIMITIVE_ARRAY(ArrayOfByte)
+  PRIMITIVE_ARRAY(ArrayOfChar)
+  PRIMITIVE_ARRAY(ArrayOfShort)
+  PRIMITIVE_ARRAY(ArrayOfInt)
+  PRIMITIVE_ARRAY(ArrayOfFloat)
+  PRIMITIVE_ARRAY(ArrayOfDouble)
+  PRIMITIVE_ARRAY(ArrayOfLong)
+
+#undef PRIMITIVE_ARRAY
+
+  std::vector<const llvm::Type*> llvmArgs;
+  llvmArgs.push_back(ptrType); // class loader.
+  const FunctionType* FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
+
+  StaticInitializer = Function::Create(FTy, GlobalValue::InternalLinkage,
+                                       "Init", getLLVMModule());
+
+  llvmArgs.clear();
+  llvmArgs.push_back(JavaMethodType);
+  
+  FTy = FunctionType::get(ptrType, llvmArgs, false);
+
+  NativeLoader = Function::Create(FTy, GlobalValue::ExternalLinkage,
+                                  "vmjcNativeLoader", getLLVMModule());
+  
+  llvmArgs.clear();
+  FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
+  ObjectPrinter = Function::Create(FTy, GlobalValue::ExternalLinkage,
+                                   "printJavaObject", getLLVMModule());
+}
+
+void JnjvmModuleAOT::printStats() {
+  fprintf(stderr, "----------------- Info from the module -----------------\n");
+  fprintf(stderr, "Number of native classes            : %llu\n", 
+          (unsigned long long int) nativeClasses.size());
+  fprintf(stderr, "Number of Java classes              : %llu\n",
+          (unsigned long long int) javaClasses.size());
+  fprintf(stderr, "Number of external array classes    : %llu\n",
+          (unsigned long long int) arrayClasses.size());
+  fprintf(stderr, "Number of virtual tables            : %llu\n", 
+          (unsigned long long int) virtualTables.size());
+  fprintf(stderr, "Number of static instances          : %llu\n", 
+          (unsigned long long int) staticInstances.size());
+  fprintf(stderr, "Number of constant pools            : %llu\n", 
+          (unsigned long long int) constantPools.size());
+  fprintf(stderr, "Number of strings                   : %llu\n", 
+          (unsigned long long int) strings.size());
+  fprintf(stderr, "Number of enveloppes                : %llu\n", 
+          (unsigned long long int) enveloppes.size());
+  fprintf(stderr, "Number of native functions          : %llu\n", 
+          (unsigned long long int) nativeFunctions.size());
+  fprintf(stderr, "----------------- Total size in .data ------------------\n");
+  uint64 size = 0;
+  Module* Mod = getLLVMModule();
+  for (Module::const_global_iterator i = Mod->global_begin(),
+       e = Mod->global_end(); i != e; ++i) {
+    size += getTypeSize(i->getType());
+  }
+  fprintf(stderr, "%lluB\n", (unsigned long long int)size);
+}
+
+
+#ifdef SERVICE
+Value* JnjvmModuleAOT::getIsolate(Jnjvm* isolate, Value* Where) {
+  llvm::Constant* varGV = 0;
+  isolate_iterator End = isolates.end();
+  isolate_iterator I = isolates.find(isolate);
+  if (I == End) {
+  
+    
+    Constant* cons = 
+      ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty,
+                                                 uint64_t(isolate)),
+                                ptrType);
+
+    varGV = new GlobalVariable(ptrType, !staticCompilation,
+                               GlobalValue::ExternalLinkage,
+                               cons, "", getLLVMModule());
+  
+    isolates.insert(std::make_pair(isolate, varGV));
+  } else {
+    varGV = I->second;
+  }
+  if (BasicBlock* BB = dyn_cast<BasicBlock>(Where)) {
+    return new LoadInst(varGV, "", BB);
+  } else {
+    assert(dyn_cast<Instruction>(Where) && "Wrong use of module");
+    return new LoadInst(varGV, "", dyn_cast<Instruction>(Where));
+  }
+}
+#endif
+
+void JnjvmModuleAOT::CreateStaticInitializer() {
+
+  std::vector<const llvm::Type*> llvmArgs;
+  llvmArgs.push_back(ptrType); // class loader
+  llvmArgs.push_back(JavaCommonClassType); // cl
+  const FunctionType* FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
+
+  Function* AddClass = Function::Create(FTy, GlobalValue::ExternalLinkage,
+                                        "vmjcAddPreCompiledClass", getLLVMModule());
+ 
+  llvmArgs.clear();
+  llvmArgs.push_back(ptrType); // class loader
+  llvmArgs.push_back(PointerType::getUnqual(JavaClassArrayType)); // array ptr
+  llvmArgs.push_back(UTF8Type); // name
+  FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
+  
+  Function* GetClassArray = Function::Create(FTy, GlobalValue::ExternalLinkage,
+                                             "vmjcGetClassArray", getLLVMModule());
+  
+  BasicBlock* currentBlock = BasicBlock::Create("enter", StaticInitializer);
+  Function::arg_iterator loader = StaticInitializer->arg_begin();
+  
+  Value* Args[3];
+  // If we have defined some strings.
+  if (strings.begin() != strings.end()) {
+    llvmArgs.clear();
+    llvmArgs.push_back(ptrType); // class loader
+    llvmArgs.push_back(strings.begin()->second->getType()); // val
+    FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
+  
+    Function* AddString = Function::Create(FTy, GlobalValue::ExternalLinkage,
+                                           "vmjcAddString", getLLVMModule());
+  
+
+  
+    for (string_iterator i = strings.begin(), e = strings.end(); i != e; ++i) {
+      Args[0] = loader;
+      Args[1] = i->second;
+      CallInst::Create(AddString, Args, Args + 2, "", currentBlock);
+    }
+  }
+  
+  for (native_class_iterator i = nativeClasses.begin(), 
+       e = nativeClasses.end(); i != e; ++i) {
+    if (isCompiling(i->first)) {
+      Args[0] = loader;
+      Args[1] = ConstantExpr::getBitCast(i->second, JavaCommonClassType);
+      CallInst::Create(AddClass, Args, Args + 2, "", currentBlock);
+    }
+  }
+  
+  for (array_class_iterator i = arrayClasses.begin(), 
+       e = arrayClasses.end(); i != e; ++i) {
+    if (!(i->first->baseClass()->isPrimitive())) {
+      Args[0] = loader;
+      Args[1] = i->second;
+      Args[2] = getUTF8(i->first->name);
+      CallInst::Create(GetClassArray, Args, Args + 3, "", currentBlock);
+    }
+  }
+  
+
+  ReturnInst::Create(currentBlock);
+}
+
+void JnjvmModuleAOT::setNoInline(Class* cl) {
+  for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
+    JavaMethod& meth = cl->virtualMethods[i];
+    if (!isAbstract(meth.access)) {
+      LLVMMethodInfo* LMI = getMethodInfo(&meth);
+      Function* func = LMI->getMethod();
+      func->addFnAttr(Attribute::NoInline);
+    }
+  }
+  
+  for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
+    JavaMethod& meth = cl->staticMethods[i];
+    if (!isAbstract(meth.access)) {
+      LLVMMethodInfo* LMI = getMethodInfo(&meth);
+      Function* func = LMI->getMethod();
+      func->addFnAttr(Attribute::NoInline);
+    }
+  }
+}
+
+void JnjvmModuleAOT::makeVT(Class* cl) {
+  internalMakeVT(cl);
+#ifndef WITHOUT_VTABLE
+  VirtualTable* VT = cl->virtualVT;
+  for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
+    JavaMethod& meth = cl->virtualMethods[i];
+    ((void**)VT)[meth.offset] = &meth;
+  }
+#endif 
+}
+
+void JnjvmModuleAOT::setMethod(JavaMethod* meth, void* ptr, const char* name) {
+  Function* func = getMethodInfo(meth)->getMethod();
+  func->setName(name);
+  func->setLinkage(GlobalValue::ExternalLinkage);
+}

Added: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleJIT.cpp?rev=65555&view=auto

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleJIT.cpp (added)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleJIT.cpp Thu Feb 26 12:44:00 2009
@@ -0,0 +1,201 @@
+//===--------- JnjvmModule.cpp - Definition of a Jnjvm module -------------===//
+//
+//                              JnJVM
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/Instructions.h"
+#include "llvm/ExecutionEngine/ExecutionEngine.h"
+
+#include "JavaConstantPool.h"
+#include "JavaThread.h"
+#include "Jnjvm.h"
+
+#include "jnjvm/JnjvmModule.h"
+#include "jnjvm/JnjvmModuleProvider.h"
+
+using namespace jnjvm;
+using namespace llvm;
+
+extern void* JavaArrayVT[];
+extern void* ArrayObjectVT[];
+
+Constant* JnjvmModuleJIT::getNativeClass(CommonClass* classDef) {
+  const llvm::Type* Ty = classDef->isClass() ? JavaClassType : 
+                                               JavaCommonClassType;
+  
+  ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64_t(classDef));
+  return ConstantExpr::getIntToPtr(CI, Ty);
+}
+
+Constant* JnjvmModuleJIT::getConstantPool(JavaConstantPool* ctp) {
+  void* ptr = ctp->ctpRes;
+  assert(ptr && "No constant pool found");
+  ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64_t(ptr));
+  return ConstantExpr::getIntToPtr(CI, ConstantPoolType);
+}
+
+Constant* JnjvmModuleJIT::getMethodInClass(JavaMethod* meth) {
+  ConstantInt* CI = ConstantInt::get(Type::Int64Ty, (int64_t)meth);
+  return ConstantExpr::getIntToPtr(CI, JavaMethodType);
+}
+
+Constant* JnjvmModuleJIT::getString(JavaString* str) {
+  assert(str && "No string given");
+  ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64(str));
+  return ConstantExpr::getIntToPtr(CI, JavaObjectType);
+}
+
+Constant* JnjvmModuleJIT::getEnveloppe(Enveloppe* enveloppe) {
+  assert(enveloppe && "No enveloppe given");
+  ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64(enveloppe));
+  return ConstantExpr::getIntToPtr(CI, EnveloppeType);
+}
+
+Constant* JnjvmModuleJIT::getJavaClass(CommonClass* cl) {
+  JavaObject* obj = cl->getClassDelegatee(JavaThread::get()->getJVM());
+  assert(obj && "Delegatee not created");
+  Constant* CI = ConstantInt::get(Type::Int64Ty, uint64(obj));
+  return ConstantExpr::getIntToPtr(CI, JavaObjectType);
+}
+
+JavaObject* JnjvmModuleJIT::getFinalObject(llvm::Value* obj) {
+  if (ConstantExpr* CE = dyn_cast<ConstantExpr>(obj)) {
+    if (ConstantInt* C = dyn_cast<ConstantInt>(CE->getOperand(0))) {
+      return (JavaObject*)C->getZExtValue();
+    }
+  }
+  return 0;
+}
+
+Constant* JnjvmModuleJIT::getFinalObject(JavaObject* obj) {
+  Constant* CI = ConstantInt::get(Type::Int64Ty, uint64(obj));
+  return ConstantExpr::getIntToPtr(CI, JavaObjectType);
+}
+
+Constant* JnjvmModuleJIT::getStaticInstance(Class* classDef) {
+#ifdef ISOLATE
+  assert(0 && "Should not be here");
+  abort();
+#endif
+  void* obj = ((Class*)classDef)->getStaticInstance();
+  if (!obj) {
+    Class* cl = (Class*)classDef;
+    classDef->acquire();
+    obj = cl->getStaticInstance();
+    if (!obj) {
+      // Allocate now so that compiled code can reference it.
+      obj = cl->allocateStaticInstance(JavaThread::get()->getJVM());
+    }
+    classDef->release();
+  }
+  Constant* CI = ConstantInt::get(Type::Int64Ty, (uint64_t(obj)));
+  return ConstantExpr::getIntToPtr(CI, ptrType);
+}
+
+Constant* JnjvmModuleJIT::getVirtualTable(Class* classDef) {
+  LLVMClassInfo* LCI = getClassInfo((Class*)classDef);
+  LCI->getVirtualType();
+  
+  assert(classDef->virtualVT && "Virtual VT not created");
+  void* ptr = classDef->virtualVT;
+  ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64_t(ptr));
+  return ConstantExpr::getIntToPtr(CI, VTType);
+}
+
+Constant* JnjvmModuleJIT::getNativeFunction(JavaMethod* meth, void* ptr) {
+  LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature());
+  const llvm::Type* valPtrType = LSI->getNativePtrType();
+  
+  assert(ptr && "No native function given");
+
+  Constant* CI = ConstantInt::get(Type::Int64Ty, uint64_t(ptr));
+  return ConstantExpr::getIntToPtr(CI, valPtrType);
+}
+
+JnjvmModuleJIT::JnjvmModuleJIT(const std::string &ModuleID,
+                               JnjvmModule* Father) :
+  JnjvmModule(ModuleID, Father) {
+   
+  ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64(JavaArrayVT));
+  PrimitiveArrayVT = ConstantExpr::getIntToPtr(CI, VTType);
+ 
+  CI = ConstantInt::get(Type::Int64Ty, uint64(ArrayObjectVT));
+  ReferenceArrayVT = ConstantExpr::getIntToPtr(CI, VTType);
+}
+
+#ifdef SERVICE
+Value* JnjvmModuleJIT::getIsolate(Jnjvm* isolate, Value* Where) {
+  ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64_t(isolate));
+  return ConstantExpr::getIntToPtr(CI, ptrType);
+}
+#endif
+
+void JnjvmModuleJIT::makeVT(Class* cl) { 
+  internalMakeVT(cl);
+
+#ifndef WITHOUT_VTABLE
+  VirtualTable* VT = cl->virtualVT;
+  
+  // Fill the virtual table with function pointers.
+  ExecutionEngine* EE = mvm::MvmModule::executionEngine;
+  for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
+    JavaMethod& meth = cl->virtualMethods[i];
+    LLVMMethodInfo* LMI = getMethodInfo(&meth);
+    Function* func = LMI->getMethod();
+
+    // Special handling for finalize method. Don't put a finalizer
+    // if there is none, or if it is empty.
+    if (meth.offset == 0) {
+#if defined(ISOLATE_SHARING) || defined(USE_GC_BOEHM)
+      ((void**)VT)[0] = 0;
+#else
+      JnjvmClassLoader* loader = cl->classLoader;
+      Function* func = loader->getModuleProvider()->parseFunction(&meth);
+      if (!cl->super) {
+        meth.canBeInlined = true;
+        ((void**)VT)[0] = 0;
+      } else {
+        Function::iterator BB = func->begin();
+        BasicBlock::iterator I = BB->begin();
+        if (isa<ReturnInst>(I)) {
+          ((void**)VT)[0] = 0;
+        } else {
+          // LLVM does not allow recursive compilation. Create the code now.
+          ((void**)VT)[0] = EE->getPointerToFunction(func);
+        }
+      }
+#endif
+    } else {
+      ((void**)VT)[meth.offset] = EE->getPointerToFunctionOrStub(func);
+    }
+  }
+
+#ifdef WITH_TRACER
+  Function* func = makeTracer(cl, false);
+  
+  void* codePtr = mvm::MvmModule::executionEngine->getPointerToFunction(func);
+  ((void**)VT)[VT_TRACER_OFFSET] = codePtr;
+  func->deleteBody();
+#endif
+    
+  // If there is no super, then it's the first VT that we allocate. Assign
+  // this VT to native types.
+  if (!(cl->super)) {
+    ClassArray::initialiseVT(cl);
+  }
+#endif 
+}
+
+void JnjvmModuleJIT::setMethod(JavaMethod* meth, void* ptr, const char* name) {
+  Function* func = getMethodInfo(meth)->getMethod();
+  func->setName(name);
+  assert(ptr && "No value given");
+  executionEngine->addGlobalMapping(func, ptr);
+  func->setLinkage(GlobalValue::ExternalLinkage);
+}

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp Thu Feb 26 12:44:00 2009
@@ -147,7 +147,7 @@
   LLVMSignatureInfo* LSI = M->getSignatureInfo(sign);
   if (!stat) {
     const char* name = cl->printString();
-    char* key = (char*)alloca(strlen(name) + 2);
+    char* key = (char*)alloca(strlen(name) + 16);
     sprintf(key, "%s%d", name, index);
     Function* F = TheModule->getFunction(key);
     if (F) return F;
@@ -182,7 +182,7 @@
 }
 
 JnjvmModuleProvider::JnjvmModuleProvider(JnjvmModule *m) {
-  TheModule = (Module*)m;
+  TheModule = m->getLLVMModule();
   if (m->executionEngine) {
     m->protectEngine.lock();
     m->executionEngine->addModuleProvider(this);
@@ -190,13 +190,13 @@
   }
     
   JavaNativeFunctionPasses = new llvm::FunctionPassManager(this);
-  JavaNativeFunctionPasses->add(new llvm::TargetData(m));
+  JavaNativeFunctionPasses->add(new llvm::TargetData(TheModule));
   // Lower constant calls to lower things like getClass used
   // on synchronized methods.
   JavaNativeFunctionPasses->add(createLowerConstantCallsPass());
   
   JavaFunctionPasses = new llvm::FunctionPassManager(this);
-  JavaFunctionPasses->add(new llvm::TargetData(m));
+  JavaFunctionPasses->add(new llvm::TargetData(TheModule));
   Function* func = m->JavaObjectAllocateFunction;
   JavaFunctionPasses->add(mvm::createEscapeAnalysisPass(func));
   JavaFunctionPasses->add(createLowerConstantCallsPass());

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Thu Feb 26 12:44:00 2009
@@ -114,8 +114,8 @@
 #endif
 
 bool LowerConstantCalls::runOnFunction(Function& F) {
-  JnjvmModule* module = (JnjvmModule*)F.getParent();
   JavaMethod* meth = LLVMMethodInfo::get(&F);
+  JnjvmModule* module = meth->classDef->classLoader->getModule();
   bool Changed = false;
   for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) { 
     BasicBlock *Cur = BI; 
@@ -433,7 +433,7 @@
             GlobalVariable* GV = 
               new GlobalVariable(module->JavaCommonClassType, false,
                                  GlobalValue::ExternalLinkage,
-                                 init, "", module);
+                                 init, "", module->getLLVMModule());
 
             Value* LoadedGV = new LoadInst(GV, "", CI);
             Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, LoadedGV, init,

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Thu Feb 26 12:44:00 2009
@@ -1080,62 +1080,109 @@
 //===----------------------------------------------------------------------===//
   
   /// This class of methods takes a variable argument list.
-  uint32 invokeIntSpecialAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap);
-  float invokeFloatSpecialAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap);
-  double invokeDoubleSpecialAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap);
-  sint64 invokeLongSpecialAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap);
-  JavaObject* invokeJavaObjectSpecialAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap);
-  
-  uint32 invokeIntVirtualAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap);
-  float invokeFloatVirtualAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap);
-  double invokeDoubleVirtualAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap);
-  sint64 invokeLongVirtualAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap);
-  JavaObject* invokeJavaObjectVirtualAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap);
-  
-  uint32 invokeIntStaticAP(Jnjvm* vm, UserClass*, va_list ap);
-  float invokeFloatStaticAP(Jnjvm* vm, UserClass*, va_list ap);
-  double invokeDoubleStaticAP(Jnjvm* vm, UserClass*, va_list ap);
-  sint64 invokeLongStaticAP(Jnjvm* vm, UserClass*, va_list ap);
-  JavaObject* invokeJavaObjectStaticAP(Jnjvm* vm, UserClass*, va_list ap);
+  uint32 invokeIntSpecialAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap)
+    __attribute__ ((noinline));
+  float invokeFloatSpecialAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap)
+    __attribute__ ((noinline));
+  double invokeDoubleSpecialAP(Jnjvm* vm, UserClass*, JavaObject* obj,
+                               va_list ap)
+    __attribute__ ((noinline));
+  sint64 invokeLongSpecialAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap)
+    __attribute__ ((noinline));
+  JavaObject* invokeJavaObjectSpecialAP(Jnjvm* vm, UserClass*, JavaObject* obj,
+                                        va_list ap)
+    __attribute__ ((noinline));
+  
+  uint32 invokeIntVirtualAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap)
+    __attribute__ ((noinline));
+  float invokeFloatVirtualAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap)
+    __attribute__ ((noinline));
+  double invokeDoubleVirtualAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap)
+    __attribute__ ((noinline));
+  sint64 invokeLongVirtualAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap)
+    __attribute__ ((noinline));
+  JavaObject* invokeJavaObjectVirtualAP(Jnjvm* vm, UserClass*, JavaObject* obj, va_list ap)
+    __attribute__ ((noinline));
+  
+  uint32 invokeIntStaticAP(Jnjvm* vm, UserClass*, va_list ap)
+    __attribute__ ((noinline));
+  float invokeFloatStaticAP(Jnjvm* vm, UserClass*, va_list ap)
+    __attribute__ ((noinline));
+  double invokeDoubleStaticAP(Jnjvm* vm, UserClass*, va_list ap)
+    __attribute__ ((noinline));
+  sint64 invokeLongStaticAP(Jnjvm* vm, UserClass*, va_list ap)
+    __attribute__ ((noinline));
+  JavaObject* invokeJavaObjectStaticAP(Jnjvm* vm, UserClass*, va_list ap)
+    __attribute__ ((noinline));
 
   /// This class of methods takes a buffer which contain the arguments of the
   /// call.
-  uint32 invokeIntSpecialBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf);
-  float invokeFloatSpecialBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf);
-  double invokeDoubleSpecialBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf);
-  sint64 invokeLongSpecialBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf);
-  JavaObject* invokeJavaObjectSpecialBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf);
-  
-  uint32 invokeIntVirtualBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf);
-  float invokeFloatVirtualBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf);
-  double invokeDoubleVirtualBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf);
-  sint64 invokeLongVirtualBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf);
-  JavaObject* invokeJavaObjectVirtualBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf);
-  
-  uint32 invokeIntStaticBuf(Jnjvm* vm, UserClass*, void* buf);
-  float invokeFloatStaticBuf(Jnjvm* vm, UserClass*, void* buf);
-  double invokeDoubleStaticBuf(Jnjvm* vm, UserClass*, void* buf);
-  sint64 invokeLongStaticBuf(Jnjvm* vm, UserClass*, void* buf);
-  JavaObject* invokeJavaObjectStaticBuf(Jnjvm* vm, UserClass*, void* buf);
+  uint32 invokeIntSpecialBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf)
+    __attribute__ ((noinline));
+  float invokeFloatSpecialBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf)
+    __attribute__ ((noinline));
+  double invokeDoubleSpecialBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf)
+    __attribute__ ((noinline));
+  sint64 invokeLongSpecialBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf)
+    __attribute__ ((noinline));
+  JavaObject* invokeJavaObjectSpecialBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf)
+    __attribute__ ((noinline));
+  
+  uint32 invokeIntVirtualBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf)
+    __attribute__ ((noinline));
+  float invokeFloatVirtualBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf)
+    __attribute__ ((noinline));
+  double invokeDoubleVirtualBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf)
+    __attribute__ ((noinline));
+  sint64 invokeLongVirtualBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf)
+    __attribute__ ((noinline));
+  JavaObject* invokeJavaObjectVirtualBuf(Jnjvm* vm, UserClass*, JavaObject* obj, void* buf)
+    __attribute__ ((noinline));
+  
+  uint32 invokeIntStaticBuf(Jnjvm* vm, UserClass*, void* buf)
+    __attribute__ ((noinline));
+  float invokeFloatStaticBuf(Jnjvm* vm, UserClass*, void* buf)
+    __attribute__ ((noinline));
+  double invokeDoubleStaticBuf(Jnjvm* vm, UserClass*, void* buf)
+    __attribute__ ((noinline));
+  sint64 invokeLongStaticBuf(Jnjvm* vm, UserClass*, void* buf)
+    __attribute__ ((noinline));
+  JavaObject* invokeJavaObjectStaticBuf(Jnjvm* vm, UserClass*, void* buf)
+    __attribute__ ((noinline));
 
   /// This class of methods is variadic.
-  uint32 invokeIntSpecial(Jnjvm* vm, UserClass*, JavaObject* obj, ...);
-  float invokeFloatSpecial(Jnjvm* vm, UserClass*, JavaObject* obj, ...);
-  double invokeDoubleSpecial(Jnjvm* vm, UserClass*, JavaObject* obj, ...);
-  sint64 invokeLongSpecial(Jnjvm* vm, UserClass*, JavaObject* obj, ...);
-  JavaObject* invokeJavaObjectSpecial(Jnjvm* vm, UserClass*, JavaObject* obj, ...);
-  
-  uint32 invokeIntVirtual(Jnjvm* vm, UserClass*, JavaObject* obj, ...);
-  float invokeFloatVirtual(Jnjvm* vm, UserClass*, JavaObject* obj, ...);
-  double invokeDoubleVirtual(Jnjvm* vm, UserClass*, JavaObject* obj, ...);
-  sint64 invokeLongVirtual(Jnjvm* vm, UserClass*, JavaObject* obj, ...);
-  JavaObject* invokeJavaObjectVirtual(Jnjvm* vm, UserClass*, JavaObject* obj, ...);
-  
-  uint32 invokeIntStatic(Jnjvm* vm, UserClass*, ...);
-  float invokeFloatStatic(Jnjvm* vm, UserClass*, ...);
-  double invokeDoubleStatic(Jnjvm* vm, UserClass*, ...);
-  sint64 invokeLongStatic(Jnjvm* vm, UserClass*, ...);
-  JavaObject* invokeJavaObjectStatic(Jnjvm* vm, UserClass*, ...);
+  uint32 invokeIntSpecial(Jnjvm* vm, UserClass*, JavaObject* obj, ...)
+    __attribute__ ((noinline));
+  float invokeFloatSpecial(Jnjvm* vm, UserClass*, JavaObject* obj, ...)
+    __attribute__ ((noinline));
+  double invokeDoubleSpecial(Jnjvm* vm, UserClass*, JavaObject* obj, ...)
+    __attribute__ ((noinline));
+  sint64 invokeLongSpecial(Jnjvm* vm, UserClass*, JavaObject* obj, ...)
+    __attribute__ ((noinline));
+  JavaObject* invokeJavaObjectSpecial(Jnjvm* vm, UserClass*, JavaObject* obj, ...)
+    __attribute__ ((noinline));
+  
+  uint32 invokeIntVirtual(Jnjvm* vm, UserClass*, JavaObject* obj, ...)
+    __attribute__ ((noinline));
+  float invokeFloatVirtual(Jnjvm* vm, UserClass*, JavaObject* obj, ...)
+    __attribute__ ((noinline));
+  double invokeDoubleVirtual(Jnjvm* vm, UserClass*, JavaObject* obj, ...)
+    __attribute__ ((noinline));
+  sint64 invokeLongVirtual(Jnjvm* vm, UserClass*, JavaObject* obj, ...)
+    __attribute__ ((noinline));
+  JavaObject* invokeJavaObjectVirtual(Jnjvm* vm, UserClass*, JavaObject* obj, ...)
+    __attribute__ ((noinline));
+  
+  uint32 invokeIntStatic(Jnjvm* vm, UserClass*, ...)
+    __attribute__ ((noinline));
+  float invokeFloatStatic(Jnjvm* vm, UserClass*, ...)
+    __attribute__ ((noinline));
+  double invokeDoubleStatic(Jnjvm* vm, UserClass*, ...)
+    __attribute__ ((noinline));
+  sint64 invokeLongStatic(Jnjvm* vm, UserClass*, ...)
+    __attribute__ ((noinline));
+  JavaObject* invokeJavaObjectStatic(Jnjvm* vm, UserClass*, ...)
+    __attribute__ ((noinline));
   
   mvm::JITInfo* JInfo;
   template<typename Ty> 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Thu Feb 26 12:44:00 2009
@@ -66,16 +66,16 @@
 }
 
 mvm::VirtualMachine* mvm::VirtualMachine::createJVM(mvm::CompilationUnit* C) {
-  JnjvmBootstraLoader* bootstrapLoader = gc_new(JnjvmBootstrapLoader)(false);
+  JnjvmBootstraLoader* bootstrapLoader = gc_new(JnjvmBootstrapLoader)(0, 0);
   Jnjvm* vm = gc_new(Jnjvm)(bootstrapLoader);
   return vm;
 }
 #else
   
 mvm::CompilationUnit* 
-mvm::VirtualMachine::initialiseJVM(bool staticCompilation) {
+mvm::VirtualMachine::initialiseJVM() {
   initialiseVT();
-  return gc_new(JnjvmBootstrapLoader)(staticCompilation);
+  return gc_new(JnjvmBootstrapLoader)(0, 0);
 }
 
 mvm::VirtualMachine* mvm::VirtualMachine::createJVM(mvm::CompilationUnit* C) {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Thu Feb 26 12:44:00 2009
@@ -356,7 +356,7 @@
 
   // Start native because the next instruction after setjmp is a call to a
   // native function.
-  th->startNative(1);
+  th->startNative(2);
 
   // Finally, return the buffer that the Java code will use to do the setjmp.
   return (void*)buf;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp Thu Feb 26 12:44:00 2009
@@ -89,6 +89,7 @@
 void JavaThread::startJava() {
   // Caller of this function.
   void** cur = (void**)FRAME_PTR();
+  cur = (void**)cur[0];
   
   addresses.push_back(cur);
 }
@@ -130,7 +131,7 @@
       // We end walking the stack when we cross a native -> Java call. Here
       // the iterator points to a native -> Java call. We dereference addr twice
       // because a native -> Java call always contains the signature function.
-    } while (((void***)addr)[0] != *it);
+    } while (((void***)addr)[0][0] != *it);
   }
 }
 
@@ -158,7 +159,7 @@
       // We end walking the stack when we cross a native -> Java call. Here
       // the iterator points to a native -> Java call. We dereference addr twice
       // because a native -> Java call always contains the signature function.
-    } while (((void***)addr)[0] != *it);
+    } while (((void***)addr)[0][0] != *it);
   }
   return 0;
 }
@@ -185,7 +186,7 @@
       // We end walking the stack when we cross a native -> Java call. Here
       // the iterator points to a native -> Java call. We dereference addr twice
       // because a native -> Java call always contains the signature function.
-    } while (((void***)addr)[0] != *it);
+    } while (((void***)addr)[0][0] != *it);
   }
 
   return 0;
@@ -246,7 +247,7 @@
       // End walking the stack when we cross a native -> Java call. Here
       // the iterator points to a native -> Java call. We dereference addr twice
       // because a native -> Java call always contains the signature function.
-    } while (((void***)addr)[0] != *it);
+    } while (((void***)addr)[0][0] != *it);
   }
 
   while (addr < baseSP && addr < addr[0]) {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h Thu Feb 26 12:44:00 2009
@@ -194,11 +194,11 @@
 
   /// startNative - Record that we are entering native code.
   ///
-  void startNative(int level);
+  void startNative(int level) __attribute__ ((noinline));
 
   /// startJava - Record that we are entering Java code.
   ///
-  void startJava();
+  void startJava() __attribute__ ((noinline));
   
   /// endNative - Record that we are leaving native code.
   ///
@@ -206,7 +206,7 @@
     addresses.pop_back();
   }
 
-  /// endNative - Record that we are leaving Java code.
+  /// endJava - Record that we are leaving Java code.
   ///
   void endJava() {
     addresses.pop_back();
@@ -229,7 +229,7 @@
     
   /// printBacktrace - Prints the backtrace of this thread.
   ///
-  void printBacktrace();
+  void printBacktrace() __attribute__ ((noinline));
   
   /// printJavaBacktrace - Prints the backtrace of this thread. Only prints
   /// the Java methods on the stack.

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Thu Feb 26 12:44:00 2009
@@ -1102,7 +1102,7 @@
 
 
 static void compileClass(Class* cl) {
-  JnjvmModule* Mod = cl->classLoader->getModule();
+  JnjvmModuleAOT* Mod = (JnjvmModuleAOT*)cl->classLoader->getModule();
   
   // Make sure the class is emitted.
   Mod->getNativeClass(cl);
@@ -1127,14 +1127,14 @@
 void Jnjvm::mainCompilerStart(JavaThread* th) {
   
   Jnjvm* vm = th->getJVM();
+  JnjvmBootstrapLoader* bootstrapLoader = vm->bootstrapLoader;
+  JnjvmModuleAOT* M = (JnjvmModuleAOT*)bootstrapLoader->getModule();
   try {
-    JnjvmBootstrapLoader* bootstrapLoader = vm->bootstrapLoader;
 
     bootstrapLoader->analyseClasspathEnv(vm->classpath);
     bootstrapLoader->upcalls->initialiseClasspath(bootstrapLoader);
   
     uint32 size = strlen(name);
-    JnjvmModule* M = bootstrapLoader->getModule();
     
     if (size > 4 && 
        (!strcmp(&name[size - 4], ".jar") || !strcmp(&name[size - 4], ".zip"))) {
@@ -1215,7 +1215,7 @@
 #define SET_INLINE(NAME) { \
   const UTF8* name = vm->asciizToUTF8(NAME); \
   Class* cl = (Class*)vm->bootstrapLoader->lookupClass(name); \
-  if (cl) vm->bootstrapLoader->getModule()->setNoInline(cl); }
+  if (cl) M->setNoInline(cl); }
 
   SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater")
   SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater"

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Thu Feb 26 12:44:00 2009
@@ -63,11 +63,9 @@
 
 typedef void (*static_init_t)(JnjvmClassLoader*);
 
-JnjvmBootstrapLoader::JnjvmBootstrapLoader(bool staticCompilation) {
+JnjvmBootstrapLoader::JnjvmBootstrapLoader(JnjvmModule* Mod,
+                                           JnjvmModuleProvider* MP) {
   
-  TheModule = new JnjvmModule("Bootstrap JnJVM", staticCompilation);
-  TheModuleProvider = new JnjvmModuleProvider(getModule());
-
   hashUTF8 = new(allocator) UTF8Map(allocator, 0);
   classes = new(allocator) ClassMap();
   javaTypes = new(allocator) TypeMap(); 
@@ -269,11 +267,14 @@
 
 #undef DEF_UTF8
   
+  TheModule = Mod;
+  TheModuleProvider = MP;
+  
 }
 
 JnjvmClassLoader::JnjvmClassLoader(JnjvmClassLoader& JCL, JavaObject* loader,
                                    Jnjvm* I) {
-  TheModule = new JnjvmModule("Applicative loader");
+  TheModule = new JnjvmModuleJIT("Applicative loader", JCL.getModule());
   TheModuleProvider = new JnjvmModuleProvider(getModule());
   bootstrapLoader = JCL.bootstrapLoader;
   

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Thu Feb 26 12:44:00 2009
@@ -116,14 +116,14 @@
   /// TheModule - JIT module for compiling methods.
   ///
   JnjvmModule* getModule() {
-    return (JnjvmModule*)TheModule;
+    return reinterpret_cast<JnjvmModule*>(TheModule);
   }
 
   /// TheModuleProvider - JIT module provider for dynamic class loading and
   /// lazy compilation.
   ///
   JnjvmModuleProvider* getModuleProvider() {
-    return (JnjvmModuleProvider*)TheModuleProvider;
+    return reinterpret_cast<JnjvmModuleProvider*>(TheModuleProvider);
   }
 
   /// tracer - Traces a JnjvmClassLoader for GC.
@@ -342,7 +342,7 @@
   /// createBootstrapLoader - Creates the bootstrap loader, first thing
   /// to do before any execution of a JVM.
   ///
-  JnjvmBootstrapLoader(bool staticCompilation);
+  JnjvmBootstrapLoader(JnjvmModule* Mod, JnjvmModuleProvider* MP);
   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=65555&r1=65554&r2=65555&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/JIT.cpp Thu Feb 26 12:44:00 2009
@@ -12,6 +12,7 @@
 #include <llvm/DerivedTypes.h>
 #include <llvm/Instructions.h>
 #include <llvm/LinkAllPasses.h>
+#include <llvm/Module.h>
 #include <llvm/ModuleProvider.h>
 #include <llvm/PassManager.h>
 #include <llvm/Type.h>
@@ -68,15 +69,11 @@
   globalFunctionPasses = new FunctionPassManager(globalModuleProvider);
 
   
-  Module module("unused");
-  module.setDataLayout(globalModule->getDataLayout());
-  mvm::llvm_runtime::makeLLVMModuleContents(&module);
-  
   // Type declaration
   ptrType = PointerType::getUnqual(Type::Int8Ty);
   ptr32Type = PointerType::getUnqual(Type::Int32Ty);
   ptrPtrType = PointerType::getUnqual(ptrType);
-  pointerSizeType = module.getPointerSize() == llvm::Module::Pointer32 ?
+  pointerSizeType = globalModule->getPointerSize() == Module::Pointer32 ?
     Type::Int32Ty : Type::Int64Ty;
   
   // Constant declaration
@@ -129,10 +126,12 @@
 }
 
 
-MvmModule::MvmModule(const std::string& ModuleID) : llvm::Module(ModuleID) {
-  Module* module = this;
-  module->setDataLayout(globalModule->getDataLayout());
-  module->setTargetTriple(globalModule->getTargetTriple());
+MvmModule::MvmModule(const std::string& ModuleID) {
+  TheModule = new Module(ModuleID);
+  Module* module = TheModule;
+
+  TheModule->setDataLayout(globalModule->getDataLayout());
+  TheModule->setTargetTriple(globalModule->getTargetTriple());
   
   mvm::llvm_runtime::makeLLVMModuleContents(module);
   
@@ -145,7 +144,7 @@
   unwindResume = module->getFunction("_Unwind_Resume_or_Rethrow");
   
   llvmGetException = module->getFunction("llvm.eh.exception");
-  exceptionSelector = (getPointerSize() == llvm::Module::Pointer32 ?
+  exceptionSelector = (module->getPointerSize() == Module::Pointer32 ?
                 module->getFunction("llvm.eh.selector.i32") : 
                 module->getFunction("llvm.eh.selector.i64"));
   

Modified: vmkit/trunk/lib/N3/Mono/MonoString.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/Mono/MonoString.cpp?rev=65555&r1=65554&r2=65555&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/Mono/MonoString.cpp (original)
+++ vmkit/trunk/lib/N3/Mono/MonoString.cpp Thu Feb 26 12:44:00 2009
@@ -56,7 +56,7 @@
       str->_llvmVar = new GlobalVariable(pty, true,
                                     GlobalValue::ExternalLinkage,
                                     cons, "",
-                                    vm->module);
+                                    vm->module->getLLVMModule());
     }
   }
   return str->_llvmVar;

Modified: vmkit/trunk/lib/N3/PNetLib/PNetString.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetString.cpp?rev=65555&r1=65554&r2=65555&view=diff

==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/PNetString.cpp (original)
+++ vmkit/trunk/lib/N3/PNetLib/PNetString.cpp Thu Feb 26 12:44:00 2009
@@ -57,7 +57,7 @@
       str->_llvmVar = new GlobalVariable(pty, true,
                                     GlobalValue::ExternalLinkage,
                                     cons, "",
-                                    vm->module);
+                                    vm->module->getLLVMModule());
     }
   }
   return str->_llvmVar;

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

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Thu Feb 26 12:44:00 2009
@@ -151,7 +151,7 @@
   Function* func = Function::Create(markAndTraceLLVMType,
                                 GlobalValue::ExternalLinkage,
                                 "markAndTraceObject",
-                                cl->vm->module);
+                                cl->vm->module->getLLVMModule());
   Argument* arg = func->arg_begin();
 #ifdef MULTIPLE_GC 
   Argument* GC = ++(func->arg_begin());
@@ -253,7 +253,7 @@
   Function* func = Function::Create(markAndTraceLLVMType,
                                 GlobalValue::ExternalLinkage,
                                 "markAndTraceObject",
-                                cl->vm->module);
+                                cl->vm->module->getLLVMModule());
 
   Argument* arg = func->arg_begin();
 #ifdef MULTIPLE_GC 
@@ -1484,7 +1484,7 @@
     classDef->aquire();
     if (methPtr == 0) {
       methPtr = Function::Create(getSignature(genMethod), GlobalValue::GhostLinkage,
-                                   printString(), classDef->vm->module);
+                                 printString(), classDef->vm->module->getLLVMModule());
       classDef->vm->functions->hash(methPtr, this);
       N3Annotation* A = new N3Annotation(this);
       methPtr->addAnnotation(A);
@@ -1533,10 +1533,11 @@
 
 
 void CLIJit::initialiseBootstrapVM(N3* vm) {
-  mvm::MvmModule* module = vm->module;
-  module->protectEngine.lock();
-  module->executionEngine->addModuleProvider(vm->TheModuleProvider);
-  module->protectEngine.unlock();
+  mvm::MvmModule* M = vm->module;
+  Module* module = M->getLLVMModule();
+  M->protectEngine.lock();
+  M->executionEngine->addModuleProvider(vm->TheModuleProvider);
+  M->protectEngine.unlock();
     
   n3::llvm_runtime::makeLLVMModuleContents(module);
 

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

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIJitMeta.cpp Thu Feb 26 12:44:00 2009
@@ -372,7 +372,7 @@
       _llvmVar = new GlobalVariable(pty, true,
                                     GlobalValue::ExternalLinkage,
                                     cons, "",
-                                    vm->module);
+                                    vm->module->getLLVMModule());
     
     }
     release();
@@ -392,7 +392,7 @@
       _llvmVar = new GlobalVariable(pty, true,
                                     GlobalValue::ExternalLinkage,
                                     cons, "",
-                                    classDef->vm->module);
+                                    classDef->vm->module->getLLVMModule());
     }
     classDef->release();
   }
@@ -411,7 +411,7 @@
       _llvmVar = new GlobalVariable(pty, true,
                                     GlobalValue::ExternalLinkage,
                                     cons, "",
-                                    classDef->vm->module);
+                                    classDef->vm->module->getLLVMModule());
     
     }
     classDef->release();

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

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIRuntimeJIT.cpp Thu Feb 26 12:44:00 2009
@@ -28,6 +28,8 @@
 #include "VMObject.h"
 #include "VMThread.h"
 
+#include <cstdarg>
+
 using namespace n3;
 using namespace llvm;
 

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

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3.cpp Thu Feb 26 12:44:00 2009
@@ -64,10 +64,10 @@
     mvm::MvmModule::executionEngine->getTargetData()->getStringRepresentation();
 
   vm->module = new mvm::MvmModule("Bootstrap N3");
-  vm->module->setDataLayout(str);
+  vm->module->getLLVMModule()->setDataLayout(str);
   vm->protectModule = new mvm::LockNormal();
   vm->functions = FunctionMap::allocate();
-  vm->TheModuleProvider = new N3ModuleProvider(vm->module, vm->functions);
+  vm->TheModuleProvider = new N3ModuleProvider(vm->module->getLLVMModule(), vm->functions);
   CLIJit::initialiseBootstrapVM(vm);
   
   vm->name = "bootstrapN3";
@@ -86,10 +86,10 @@
   std::string str = 
     mvm::MvmModule::executionEngine->getTargetData()->getStringRepresentation();
   vm->module = new mvm::MvmModule("App Domain");
-  vm->module->setDataLayout(str);
+  vm->module->getLLVMModule()->setDataLayout(str);
   vm->protectModule = new mvm::LockNormal();
   vm->functions = FunctionMap::allocate();
-  vm->TheModuleProvider = new N3ModuleProvider(vm->module, vm->functions);
+  vm->TheModuleProvider = new N3ModuleProvider(vm->module->getLLVMModule(), vm->functions);
   CLIJit::initialiseAppDomain(vm);
 
   

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

==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VMThread.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VMThread.cpp Thu Feb 26 12:44:00 2009
@@ -53,7 +53,7 @@
   key->state = StateRunning;
   key->pendingException = 0;
   key->perFunctionPasses = new llvm::FunctionPassManager(vm->TheModuleProvider);
-  key->perFunctionPasses->add(new llvm::TargetData(vm->module));
+  key->perFunctionPasses->add(new llvm::TargetData(vm->module->getLLVMModule()));
   AddStandardCompilePasses(key->perFunctionPasses);
   return key;
 }

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

==============================================================================
--- vmkit/trunk/tools/jnjvm/Main.cpp (original)
+++ vmkit/trunk/tools/jnjvm/Main.cpp Thu Feb 26 12:44:00 2009
@@ -13,9 +13,13 @@
 #include "mvm/VirtualMachine.h"
 #include "mvm/Threads/Thread.h"
 
+#include "jnjvm/JnjvmModule.h"
+#include "jnjvm/JnjvmModuleProvider.h"
+
 #include "llvm/Support/ManagedStatic.h"
 
 
+using namespace jnjvm;
 using namespace llvm;
 using namespace mvm;
 
@@ -27,6 +31,8 @@
   Collector::initialise(0);
  
   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=65555&r1=65554&r2=65555&view=diff

==============================================================================
--- vmkit/trunk/tools/vmjc/vmjc.cpp (original)
+++ vmkit/trunk/tools/vmjc/vmjc.cpp Thu Feb 26 12:44:00 2009
@@ -16,14 +16,17 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Module.h"
+#include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
 #include "llvm/Assembly/PrintModulePass.h"
 #include "llvm/Config/config.h"
 #include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/PassNameParser.h"
+#include "llvm/Support/PluginLoader.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/SystemUtils.h"
 #include "llvm/Support/raw_ostream.h"
@@ -38,11 +41,15 @@
 #include "mvm/VirtualMachine.h"
 #include "mvm/Threads/Thread.h"
 
+#include "jnjvm/JnjvmModule.h"
+#include "jnjvm/JnjvmModuleProvider.h"
+
 #include <iostream>
 #include <fstream>
 #include <memory>
 #include <string>
 
+using namespace jnjvm;
 using namespace llvm;
 
 static cl::opt<std::string>
@@ -77,6 +84,23 @@
 static cl::opt<std::string>
 TargetTriple("mtriple", cl::desc("Override target triple for module"));
 
+static cl::opt<bool>
+DisableExceptions("disable-exceptions",
+              cl::desc("Disable Java exceptions"));
+
+static cl::opt<bool>
+DisableTracers("disable-tracers",
+              cl::desc("Disable Java tracers"));
+
+static cl::opt<bool>
+DisableStubs("disable-stubs",
+              cl::desc("Disable Java stubs"));
+
+static cl::opt<bool>
+AssumeCompiled("assume-compiled",
+              cl::desc("Assume external Java classes are compiled"));
+
+
 
 inline void addPass(FunctionPassManager *PM, Pass *P) {
   // Add the pass to the pass manager...
@@ -166,8 +190,16 @@
     Collector::initialise(0);
     Collector::enable(0);
 
-    mvm::CompilationUnit* CU = mvm::VirtualMachine::initialiseJVM(true);
-    addCommandLinePass(CU, argv); 
+    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;
     mvm::VirtualMachine* vm = mvm::VirtualMachine::createJVM(CU);
     vm->compile(InputFilename.c_str());
     vm->waitForExit();
@@ -218,7 +250,7 @@
     }
     
     if (Force || !CheckBitcodeOutputToConsole(Out,true))
-      WriteBitcodeToFile(CU->TheModule, *Out);
+      WriteBitcodeToFile(CU->TheModule->getLLVMModule(), *Out);
 
     if (Out != &std::cout) {
       ((std::ofstream*)Out)->close();

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

==============================================================================
--- vmkit/trunk/tools/vmkit/Launcher.cpp (original)
+++ vmkit/trunk/tools/vmkit/Launcher.cpp Thu Feb 26 12:44:00 2009
@@ -24,8 +24,12 @@
 #include "mvm/VirtualMachine.h"
 #include "mvm/Threads/Thread.h"
 
+#include "jnjvm/JnjvmModule.h"
+#include "jnjvm/JnjvmModuleProvider.h"
+
 #include "CommandLine.h"
 
+using namespace jnjvm;
 using namespace llvm;
 
 enum VMType {
@@ -135,6 +139,8 @@
   if (VMToRun == RunJava) {
 #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);
@@ -152,6 +158,9 @@
 #if WITH_JNJVM
     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