[vmkit-commits] [vmkit] r54633 - in /vmkit/trunk/lib/Mvm: CommandLine.cpp CommandLine.h Disassembler.cpp EscapeAnalysis.cpp JIT.cpp LLVMRuntime/ LLVMRuntime/LLVMRuntime.ll LLVMRuntime/Makefile Makefile MvmMemoryManager.cpp Object.cpp Runtime/ Runtime/CommandLine.cpp Runtime/CommandLine.h Runtime/Disassembler.cpp Runtime/EscapeAnalysis.cpp Runtime/JIT.cpp Runtime/Makefile Runtime/MvmMemoryManager.cpp Runtime/Object.cpp Runtime/Sigsegv.cpp Sigsegv.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Aug 11 00:20:01 PDT 2008


Author: geoffray
Date: Mon Aug 11 02:20:00 2008
New Revision: 54633

URL: http://llvm.org/viewvc/llvm-project?rev=54633&view=rev
Log:
Create a LLVM runtime file, and move all MVM runtime
files into the Runtime directory.


Added:
    vmkit/trunk/lib/Mvm/LLVMRuntime/
    vmkit/trunk/lib/Mvm/LLVMRuntime/LLVMRuntime.ll
    vmkit/trunk/lib/Mvm/LLVMRuntime/Makefile
    vmkit/trunk/lib/Mvm/Runtime/
    vmkit/trunk/lib/Mvm/Runtime/CommandLine.cpp
    vmkit/trunk/lib/Mvm/Runtime/CommandLine.h
    vmkit/trunk/lib/Mvm/Runtime/Disassembler.cpp
    vmkit/trunk/lib/Mvm/Runtime/EscapeAnalysis.cpp
    vmkit/trunk/lib/Mvm/Runtime/JIT.cpp
    vmkit/trunk/lib/Mvm/Runtime/Makefile
    vmkit/trunk/lib/Mvm/Runtime/MvmMemoryManager.cpp
    vmkit/trunk/lib/Mvm/Runtime/Object.cpp
    vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp
Removed:
    vmkit/trunk/lib/Mvm/CommandLine.cpp
    vmkit/trunk/lib/Mvm/CommandLine.h
    vmkit/trunk/lib/Mvm/Disassembler.cpp
    vmkit/trunk/lib/Mvm/EscapeAnalysis.cpp
    vmkit/trunk/lib/Mvm/JIT.cpp
    vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp
    vmkit/trunk/lib/Mvm/Object.cpp
    vmkit/trunk/lib/Mvm/Sigsegv.cpp
Modified:
    vmkit/trunk/lib/Mvm/Makefile

Removed: vmkit/trunk/lib/Mvm/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommandLine.cpp?rev=54632&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/CommandLine.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommandLine.cpp (removed)
@@ -1,165 +0,0 @@
-//===------- CommandLine.cpp - Parses the command line --------------------===//
-//
-//                     The Micro Virtual Machine
-//
-// This file is distributed under the University of Illinois Open Source 
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-
-#include <assert.h>
-#include <dlfcn.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "CommandLine.h"
-#include "MvmGC.h"
-#include "mvm/Threads/Thread.h"
-
-using namespace mvm;
-
-typedef struct thread_arg_t {
-  int argc;
-  char** argv;
-  vmlet_main_t func;
-} thread_arg_t;
-
-typedef int (*boot_t)();
-
-
-CommandLine::CommandLine() {
-  resetString();
-  resetArgv();
-}
-
-void CommandLine::appendChar(char c) {
-  assert(_yytext);
-  _yytext[_yylen++]= c;
-  if (_yylen == _yylenMax) {
-    _yylenMax *= 2;
-    _yytext= (char *)realloc(_yytext, _yylenMax);
-  }
-}
-
-void CommandLine::appendString(char* str) {
-  assert(argv);
-  appendChar(0);
-  argv[argc++] = str;
-  if (argc == argcMax) {
-    argcMax *= 2;
-    argv = (char **)realloc(argv, argcMax * sizeof(char*));
-  }
-}
-
-void CommandLine::resetString() {
-  _yytext = (char *)malloc(_yylenMax= 32);
-  _yylen = 0;
-}
-
-void CommandLine::resetArgv() {
-  argv = (char **)malloc(sizeof(char*) * (argcMax= 10));
-  argc = 0;
-}
-
-
-void CommandLine::start() {
-  printf("> ");
-  _yyChar = getc(stdin);
-  
-  while (true) {
-    switch(_yyChar) {
-      case ' ' : 
-        do { _yyChar = getc(stdin); } while (_yyChar == ' ');
-        if (_yylen != 0) {
-          appendString(_yytext);
-          resetString();
-        }
-        break;
-      
-      case '\n' :
-        if (_yylen != 0) {
-          appendString(_yytext);
-          resetString();
-        }
-        if (argc > 1) {
-          executeInstr();
-          resetArgv();
-          printf("> ");
-        }
-        _yyChar = getc(stdin);
-        break;
-
-      case EOF :
-        printf("\n");
-        return;
-
-      default :
-        appendChar(_yyChar);
-        _yyChar = getc(stdin);
-    }
-  } 
-}
-
-extern "C" int startApp(thread_arg_t* arg) {
-  int argc = arg->argc;
-  char** argv = arg->argv;
-  vmlet_main_t func = arg->func;
-  free(arg);
-#ifndef MULTIPLE_GC
-  Collector::inject_my_thread(&argc);
-  func(argc, argv);
-  Collector::remove_my_thread();
-  Collector::collect();
-#else
-  Collector* GC = Collector::allocate();
-  GC->inject_my_thread(&argc);
-  func(argc, argv);
-  GC->remove_my_thread();
-  GC->collect();
-#endif
-  return 0;
-}
-
-void CommandLine::executeInstr() {
-  if (!strcmp(argv[0], "load")) {
-    char* buf = (char*)alloca(sizeof(argv[1]) + 7);
-    sprintf(buf, "lib%s.so", argv[1]);
-    void* handle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
-    if (handle == 0) {
-      fprintf(stderr, "\t Unable to load %s\n", argv[1]);
-      printf("\t error = %s\n", dlerror());
-      return;
-    }
-    
-    boot_t func = (boot_t)(intptr_t)dlsym(handle, "boot");
-    
-    if (func == 0) {
-      fprintf(stderr, "\t Unable to find %s boot method\n", argv[1]);
-      dlclose(handle);
-      return;
-    }
-    func();
-    
-    vmlet_main_t vmlet = (vmlet_main_t)(intptr_t)dlsym(handle, "start_app");
-
-    vmlets[argv[1]] = vmlet;
-
-  } else {
-    vmlet_main_t func = vmlets[argv[0]];
-    if (!func) {
-      fprintf(stderr, "\t Unknown vmlet %s\n", argv[0]);
-    } else {
-#if 0
-      thread_arg_t* thread_arg = (thread_arg_t*)malloc(sizeof (thread_arg_t));
-      thread_arg->argc = argc;
-      thread_arg->argv = argv;
-      thread_arg->func = func;
-      int tid = 0;
-      Thread::start(&tid, (int (*)(void *))startApp, thread_arg);
-#else
-      func(argc, argv);
-#endif
-    }
-  }
-}

Removed: vmkit/trunk/lib/Mvm/CommandLine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommandLine.h?rev=54632&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/CommandLine.h (original)
+++ vmkit/trunk/lib/Mvm/CommandLine.h (removed)
@@ -1,57 +0,0 @@
-//===--------- CommandLine.h - Parses the command line --------------------===//
-//
-//                     The Micro Virtual Machine
-//
-// This file is distributed under the University of Illinois Open Source 
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef COMMAND_LINE_H
-#define COMMAND_LINE_H
-
-#include <map>
-
-#include <string.h>
-
-namespace mvm {
-
-typedef int (*vmlet_main_t)(int argc, char** argv);
-
-struct ltstr
-{
-  bool operator()(const char* s1, const char* s2) const
-  {
-    return strcmp(s1, s2) < 0;
-  }
-};
-
-class CommandLine {
-public:
-  char** argv;
-  unsigned argc;
-  unsigned argcMax;
-
-  char* _yytext;
-  unsigned _yylen;
-  unsigned _yylenMax;
-  char _yyChar;
-  
-  std::map<const char*, vmlet_main_t, ltstr> vmlets;
-
-  CommandLine();
-  
-  void appendChar(char c);
-  void appendString(char* str);
-
-  void start();
-  void executeInstr();
-
-  void resetArgv();
-  void resetString();
-
-};
-
-} // end namespace mvm
-
-#endif // COMMAND_LINE_H

Removed: vmkit/trunk/lib/Mvm/Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Disassembler.cpp?rev=54632&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/Disassembler.cpp (original)
+++ vmkit/trunk/lib/Mvm/Disassembler.cpp (removed)
@@ -1,91 +0,0 @@
-//===--------- Disassembler.cc - Intefarce to disassembler ----------------===//
-//
-//                      Micro Virtual Machine
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "mvm/JIT.h"
-
-#ifdef HAVE_DISASSEMBLER
-
-#if defined(__PPC__)
-extern "C"
-{
-# include <dis-asm.h>
-# include <bfd.h>
-}
-
-
-
-static struct disassemble_info  info;
-static int      initialised= 0;  
-
-// this is the only function exported from this file
-
-int mvm::jit::disassemble(unsigned int *addr)
-{
-  
-  if (!initialised)
-    {   
-      INIT_DISASSEMBLE_INFO(info, stdout, fprintf);
-      info.flavour=   bfd_target_elf_flavour;
-      info.arch=    bfd_arch_powerpc;
-      info.mach=    bfd_mach_ppc_750; // generic(ish) == PPC G3
-      info.endian=    BFD_ENDIAN_BIG;
-      info.buffer_length= 65536;
-    }   
-  info.buffer=     (bfd_byte *)addr;
-  info.buffer_vma= (bfd_vma)(long)addr;
-  return print_insn_big_powerpc((bfd_vma)(long)addr, &info);
-  
-}
-
-#elif defined(__i386__)
-extern "C"
-{
-# include <bfd.h>	// bfd types
-# include <dis-asm.h>	// disassemble_info
-  int print_insn_i386_att(bfd_vma, disassemble_info *);
-}
-
-
-static struct disassemble_info	info;
-static int			initialised= 0;
-
-
-int mvm::jit::disassemble(unsigned int *addr)
-{
-  if (!initialised)
-    {
-      INIT_DISASSEMBLE_INFO(info, stdout, fprintf);
-      info.flavour=	  bfd_target_elf_flavour;
-      info.arch=	  bfd_arch_i386;
-      info.mach=	  bfd_mach_i386_i386;
-      info.endian=	  BFD_ENDIAN_LITTLE;
-      info.buffer_length= 65536;
-    }
-  info.buffer=	   (bfd_byte *)addr;
-  info.buffer_vma= (bfd_vma)(long)addr;
-  return print_insn_i386_att((bfd_vma)(long)addr, &info);
-}
-
-#else
-
-int mvm::jit::disassemble(unsigned int* addr) {
-  return 0;
-}
-
-#endif
-
-#else
-
-int mvm::jit::disassemble(unsigned int* addr) {
-  return 0;
-}
-
-#endif
-
-

Removed: vmkit/trunk/lib/Mvm/EscapeAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/EscapeAnalysis.cpp?rev=54632&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/EscapeAnalysis.cpp (original)
+++ vmkit/trunk/lib/Mvm/EscapeAnalysis.cpp (removed)
@@ -1,137 +0,0 @@
-//===------EscapeAnalysis.cpp - Simple LLVM escape analysis ---------------===//
-//
-//                     The Micro Virtual Machine
-//
-// This file is distributed under the University of Illinois Open Source 
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-
-#include "llvm/Constants.h"
-#include "llvm/Pass.h"
-#include "llvm/Function.h"
-#include "llvm/Instructions.h"
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/Debug.h"
-
-#include <map>
-
-#include "mvm/GC/GC.h"
-
-using namespace llvm;
-
-namespace {
-
-  class VISIBILITY_HIDDEN EscapeAnalysis : public FunctionPass {
-  public:
-    static char ID;
-    EscapeAnalysis(Function* alloc = 0) : 
-      FunctionPass((intptr_t)&ID) {
-      Allocator = alloc;
-    }
-
-    virtual bool runOnFunction(Function &F);
-  private:
-    Function* Allocator;
-    bool processMalloc(Instruction* I, Value* Size, Value* VT);
-  };
-  char EscapeAnalysis::ID = 0;
-  RegisterPass<EscapeAnalysis> X("EscapeAnalysis", "Escape Analysis Pass");
-
-bool EscapeAnalysis::runOnFunction(Function& F) {
-  bool Changed = false;
-  for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) { 
-    BasicBlock *Cur = BI; 
-
-    for (BasicBlock::iterator II = Cur->begin(), IE = Cur->end(); II != IE;) {
-      Instruction *I = II;
-      II++;
-      if (CallInst *CI = dyn_cast<CallInst>(I)) {
-        if (CI->getOperand(0) == Allocator) {
-          Changed |= processMalloc(CI, CI->getOperand(1), CI->getOperand(2));
-        }
-      } else if (InvokeInst *CI = dyn_cast<InvokeInst>(I)) {
-        if (CI->getOperand(0) == Allocator) {
-          Changed |= processMalloc(CI, CI->getOperand(3), CI->getOperand(4));
-        }
-      }
-    }
-  }
-  return Changed;
-}
-
-
-
-
-static bool escapes(Instruction* Ins, std::map<Instruction*, bool>& visited) {
-  for (Value::use_iterator I = Ins->use_begin(), E = Ins->use_end(); 
-       I != E; ++I) {
-    if (Instruction* II = dyn_cast<Instruction>(I)) {
-      if (dyn_cast<CallInst>(II)) return true;
-      else if (dyn_cast<InvokeInst>(II)) return true;
-      else if (dyn_cast<BitCastInst>(II)) {
-        if (escapes(II, visited)) return true;
-      }
-      else if (StoreInst* SI = dyn_cast<StoreInst>(II)) {
-        if (AllocaInst * AI = dyn_cast<AllocaInst>(SI->getOperand(1))) {
-          if (!visited[AI]) {
-            visited[AI] = true;
-            if (escapes(AI, visited)) return true;
-          }
-        } else if (SI->getOperand(0) == Ins) {
-          return true;
-        }
-      }
-      else if (dyn_cast<LoadInst>(II)) {
-        if (isa<PointerType>(II->getType())) {
-          if (escapes(II, visited)) return true; // allocas
-        }
-      }
-      else if (dyn_cast<GetElementPtrInst>(II)) {
-        if (escapes(II, visited)) return true;
-      }
-      else if (dyn_cast<ReturnInst>(II)) return true;
-      else if (dyn_cast<PHINode>(II)) {
-        if (!visited[II]) {
-          visited[II] = true;
-          if (escapes(II, visited)) return true;
-        }
-      }
-    } else {
-      return true;
-    }
-  }
-  return false;
-}
-
-bool EscapeAnalysis::processMalloc(Instruction* I, Value* Size, Value* VT) {
-  Instruction* Alloc = I;
-  
-  ConstantExpr* CE = dyn_cast<ConstantExpr>(VT);
-  if (CE) {
-    ConstantInt* C = (ConstantInt*)CE->getOperand(0);
-    VirtualTable* Table = (VirtualTable*)C->getZExtValue();
-    // If the class has a finalize method, do not stack allocate the object
-    if (!((void**)Table)[0]) {
-      std::map<Instruction*, bool> visited;
-      if (!(escapes(Alloc, visited))) {
-        AllocaInst* AI = new AllocaInst(Type::Int8Ty, Size, "", Alloc);
-        BitCastInst* BI = new BitCastInst(AI, Alloc->getType(), "", Alloc);
-        DOUT << "escape" << Alloc->getParent()->getParent()->getName() << "\n";
-        Alloc->replaceAllUsesWith(BI);
-        Alloc->eraseFromParent();
-        return true;
-      }
-    }
-  }
-  return false;
-}
-}
-
-namespace mvm {
-FunctionPass* createEscapeAnalysisPass(llvm::Function* alloc) {
-
-  return new EscapeAnalysis(alloc);
-}
-}

Removed: vmkit/trunk/lib/Mvm/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/JIT.cpp?rev=54632&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/JIT.cpp (removed)
@@ -1,612 +0,0 @@
-//===---------------- JIT.cc - Initialize the JIT -------------------------===//
-//
-//                     The Micro Virtual Machine
-//
-// This file is distributed under the University of Illinois Open Source 
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include <llvm/Constants.h>
-
-#include <llvm/Intrinsics.h>
-#include <llvm/Type.h>
-#include <llvm/DerivedTypes.h>
-#include "llvm/Support/MutexGuard.h"
-#include "llvm/Target/TargetOptions.h"
-
-#include <stdio.h>
-
-#include "mvm/JIT.h"
-#include "mvm/Method.h"
-#include "mvm/MvmMemoryManager.h"
-#include "mvm/Object.h"
-#include "mvm/Threads/Thread.h"
-
-using namespace mvm;
-using namespace mvm::jit;
-using namespace llvm;
-
-
-extern "C" void printFloat(float f) {
-  printf("%f\n", f);
-}
-
-extern "C" void printDouble(double d) {
-  printf("%f\n", d);
-}
-
-extern "C" void printLong(sint64 l) {
-  printf("%lld\n", l);
-}
-
-extern "C" void printInt(sint32 i) {
-  printf("%d\n", i);
-}
-
-extern "C" void printObject(mvm::Object* obj) {
-  printf("%s\n", obj->printString());
-}
-
-static void initialiseTypes(llvm::Module* mod) {
-  {
-  // llvm::Type Definitions
-  std::vector<const llvm::Type*>StructTy_struct_NativeString_fields;
-  StructTy_struct_NativeString_fields.push_back(IntegerType::get(8));
-  StructType* StructTy_struct_NativeString =
-    StructType::get(StructTy_struct_NativeString_fields, /*isPacked=*/true);
-  mod->addTypeName("struct.mvm::NativeString", StructTy_struct_NativeString);
-  
-  mod->addTypeName("struct.mvm::Object", StructTy_struct_NativeString);
-  mod->addTypeName("struct.mvm::Thread", StructTy_struct_NativeString);
-  
-  std::vector<const llvm::Type*>StructTy_struct_PrintBuffer_fields;
-  StructTy_struct_PrintBuffer_fields.push_back(IntegerType::get(32));
-  StructTy_struct_PrintBuffer_fields.push_back(IntegerType::get(32));
-  PointerType* PointerTy_0 = PointerType::getUnqual(StructTy_struct_NativeString);
-  
-  StructTy_struct_PrintBuffer_fields.push_back(PointerTy_0);
-  StructType* StructTy_struct_PrintBuffer =
-    StructType::get(StructTy_struct_PrintBuffer_fields, /*isPacked=*/false);
-  mod->addTypeName("struct.mvm::PrintBuffer", StructTy_struct_PrintBuffer);
-  
-  std::vector<const llvm::Type*>StructTy_struct_VirtualTable_fields;
-  std::vector<const llvm::Type*>StructTy_struct_gc_vt_fields;
-  std::vector<const llvm::Type*>FuncTy_2_args;
-  FuncTy_2_args.push_back(PointerTy_0);
-  FuncTy_2_args.push_back(IntegerType::get(32));
-  FunctionType* FuncTy_2 = FunctionType::get(
-    /*Result=*/llvm::Type::VoidTy,
-    /*Params=*/FuncTy_2_args,
-    /*isVarArg=*/false);
-  
-  PointerType* PointerTy_1 = PointerType::getUnqual(FuncTy_2);
-  
-  StructTy_struct_gc_vt_fields.push_back(PointerTy_1);
-  StructTy_struct_gc_vt_fields.push_back(PointerTy_1);
-  StructType* StructTy_struct_gc_vt =
-    StructType::get(StructTy_struct_gc_vt_fields, /*isPacked=*/false);
-  mod->addTypeName("struct.mvm::gc_vt", StructTy_struct_gc_vt);
-  
-  StructTy_struct_VirtualTable_fields.push_back(PointerTy_1);
-  StructTy_struct_VirtualTable_fields.push_back(PointerTy_1);
-  std::vector<const llvm::Type*>FuncTy_4_args;
-  FuncTy_4_args.push_back(PointerTy_0);
-  PointerType* PointerTy_5 = PointerType::getUnqual(StructTy_struct_PrintBuffer);
-  
-  FuncTy_4_args.push_back(PointerTy_5);
-  FunctionType* FuncTy_4 = FunctionType::get(
-    /*Result=*/llvm::Type::VoidTy,
-    /*Params=*/FuncTy_4_args,
-    /*isVarArg=*/false);
-  
-  PointerType* PointerTy_3 = PointerType::getUnqual(FuncTy_4);
-  
-  StructTy_struct_VirtualTable_fields.push_back(PointerTy_3);
-  std::vector<const llvm::Type*>FuncTy_7_args;
-  FuncTy_7_args.push_back(PointerTy_0);
-  FunctionType* FuncTy_7 = FunctionType::get(
-    /*Result=*/IntegerType::get(32),
-    /*Params=*/FuncTy_7_args,
-    /*isVarArg=*/false);
-  
-  PointerType* PointerTy_6 = PointerType::getUnqual(FuncTy_7);
-  
-  StructTy_struct_VirtualTable_fields.push_back(PointerTy_6);
-  StructTy_struct_VirtualTable_fields.push_back(IntegerType::get(32));
-  OpaqueType* OpaqueTy_struct_llvm__Type = OpaqueType::get();
-  mod->addTypeName("struct.llvm::Type", OpaqueTy_struct_llvm__Type);
-  
-  PointerType* PointerTy_8 = PointerType::getUnqual(OpaqueTy_struct_llvm__Type);
-  
-  StructTy_struct_VirtualTable_fields.push_back(PointerTy_8);
-  StructType* StructTy_struct_VirtualTable = 
-    StructType::get(StructTy_struct_VirtualTable_fields, /*isPacked=*/false);
-  mod->addTypeName("struct.mvm::VirtualTable", StructTy_struct_VirtualTable);
-  
-  mod->addTypeName("struct.mvm::gc_vt", StructTy_struct_gc_vt);
-  mod->addTypeName("struct.llvm::Type", OpaqueTy_struct_llvm__Type);
-  }
-
-
-
-  {
-  // Lock llvm::Type Definitions
-  std::vector<const llvm::Type*>StructTy_struct_mvm__Lock_fields;
-  std::vector<const llvm::Type*>StructTy_struct_mvm__SpinLock_fields;
-  StructTy_struct_mvm__SpinLock_fields.push_back(IntegerType::get(32));
-  StructType* StructTy_struct_mvm__SpinLock =
-    StructType::get(StructTy_struct_mvm__SpinLock_fields, /*isPacked=*/false);
-  mod->addTypeName("struct.mvm::SpinLock", StructTy_struct_mvm__SpinLock);
-  
-  StructTy_struct_mvm__Lock_fields.push_back(StructTy_struct_mvm__SpinLock);
-  std::vector<const llvm::Type*>FuncTy_1_args;
-  PATypeHolder StructTy_struct_mvm__Lock_fwd = OpaqueType::get();
-  PointerType* PointerTy_2 = PointerType::getUnqual(StructTy_struct_mvm__Lock_fwd);
-  
-  FuncTy_1_args.push_back(PointerTy_2);
-  FunctionType* FuncTy_1 = FunctionType::get(
-    /*Result=*/llvm::Type::VoidTy,
-    /*Params=*/FuncTy_1_args,
-    /*isVarArg=*/false);
-  
-  PointerType* PointerTy_0 = PointerType::getUnqual(FuncTy_1);
-  
-  StructTy_struct_mvm__Lock_fields.push_back(PointerTy_0);
-  StructTy_struct_mvm__Lock_fields.push_back(PointerTy_0);
-  std::vector<const llvm::Type*>FuncTy_4_args;
-  FuncTy_4_args.push_back(PointerTy_2);
-  FunctionType* FuncTy_4 = FunctionType::get(
-    /*Result=*/IntegerType::get(32),
-    /*Params=*/FuncTy_4_args,
-    /*isVarArg=*/false);
-  
-  PointerType* PointerTy_3 = PointerType::getUnqual(FuncTy_4);
-  
-  StructTy_struct_mvm__Lock_fields.push_back(PointerTy_3);
-  StructTy_struct_mvm__Lock_fields.push_back(IntegerType::get(32));
-  StructType* StructTy_struct_mvm__Lock =
-    StructType::get(StructTy_struct_mvm__Lock_fields, /*isPacked=*/false);
-  mod->addTypeName("struct.mvm::Lock", StructTy_struct_mvm__Lock);
-  mod->addTypeName("struct.mvm::LockNormal", StructTy_struct_mvm__Lock);
-  cast<OpaqueType>(StructTy_struct_mvm__Lock_fwd.get())->
-    refineAbstractTypeTo(StructTy_struct_mvm__Lock);
-  StructTy_struct_mvm__Lock =
-    cast<StructType>(StructTy_struct_mvm__Lock_fwd.get());
-  
-  
-  std::vector<const llvm::Type*>StructTy_struct_mvm__LockRecursive_fields;
-  StructTy_struct_mvm__LockRecursive_fields.push_back(StructTy_struct_mvm__Lock);
-  StructTy_struct_mvm__LockRecursive_fields.push_back(IntegerType::get(32));
-  StructType* StructTy_struct_mvm__LockRecursive =
-    StructType::get(StructTy_struct_mvm__LockRecursive_fields,
-                    /*isPacked=*/false);
-  mod->addTypeName("struct.mvm::LockRecursive",
-                   StructTy_struct_mvm__LockRecursive);
-  
-  std::vector<const llvm::Type*>StructTy_struct_mvm__Object_fields;
-  StructTy_struct_mvm__Object_fields.push_back(IntegerType::get(8));
-  StructType* StructTy_struct_mvm__Object =
-    StructType::get(StructTy_struct_mvm__Object_fields, /*isPacked=*/true);
-  mod->addTypeName("struct.mvm::Object", StructTy_struct_mvm__Object);
-  
-  mod->addTypeName("struct.mvm::SpinLock", StructTy_struct_mvm__SpinLock);
-  
-
-  // llvm::Type definition of Cond and CollectableArea
-  std::vector<const llvm::Type*>StructTy_struct_collectablearea_fields;
-  StructTy_struct_collectablearea_fields.push_back(IntegerType::get(32));
-  StructTy_struct_collectablearea_fields.push_back(IntegerType::get(32));
-  StructTy_struct_collectablearea_fields.push_back(IntegerType::get(32));
-  StructType* StructTy_struct_collectablearea =
-  StructType::get(StructTy_struct_collectablearea_fields, /*isPacked=*/false);
-  mod->addTypeName("struct.mvm::Cond", StructTy_struct_collectablearea);
-  mod->addTypeName("struct.mvm::CollectableArea", StructTy_struct_collectablearea);
-  }
-
-  // llvm::Type Definitions of Key
-  std::vector<const llvm::Type*>StructTy_struct_Key_fields;
-  PointerType* PointerTy_0 = PointerType::getUnqual(IntegerType::get(8));
-  
-  StructTy_struct_Key_fields.push_back(PointerTy_0);
-  StructType* StructTy_struct_Key =
-    StructType::get(StructTy_struct_Key_fields, /*isPacked=*/false);
-  mod->addTypeName("struct.mvm::ThreadKey", StructTy_struct_Key);
-
-  // TODO
-  mod->addTypeName("struct.mvm::Method", StructTy_struct_Key);
-  mod->addTypeName("struct.mvm::Code", StructTy_struct_Key);
-  
-}
-
-extern "C" void __register_frame(void*);
-
-void mvm::jit::initialise() {
-  llvm::NoFramePointerElim = true;
-  llvm::ExceptionHandling = true;
-  llvm::Module *module = jit::globalModule = new llvm::Module ("microvm");
-  jit::globalModuleProvider = new llvm::ExistingModuleProvider (jit::globalModule);
-  jit::memoryManager = new MvmMemoryManager();
-  
-  initialiseTypes(globalModule);
-
-  executionEngine = llvm::ExecutionEngine::createJIT(jit::globalModuleProvider, 0, jit::memoryManager);
-  executionEngine->InstallExceptionTableRegister(__register_frame);
-  module->setDataLayout(mvm::jit::executionEngine->getTargetData()->getStringRepresentation());
-
-  ptrType = PointerType::getUnqual(Type::Int8Ty);
-  ptr32Type = PointerType::getUnqual(Type::Int32Ty);
-  ptrPtrType = PointerType::getUnqual(ptrType);
-  
-  Intrinsic::getDeclaration(module, Intrinsic::vastart);
-  Intrinsic::getDeclaration(module, Intrinsic::frameaddress);
-
-  std::vector<const llvm::Type*> args;
-
-  const llvm::Type *BPTy = ptrType;
-  // Prototype malloc as "char* malloc(...)", because we don't know in
-  // doInitialization whether size_t is int or long.
-  FunctionType *FT = FunctionType::get(BPTy, args, true);
-  llvm::Function::Create(FT, llvm::GlobalValue::ExternalLinkage,
-                         "_ZN2gcnwEjP5gc_vt", module); 
-
-  // Create printFloatLLVM
-  args.push_back(Type::FloatTy);
-  const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
-  printFloatLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
-                                    "printFloat", module);
-  args.clear();
-  
-  // Create printDoubleLLVM
-  args.push_back(Type::DoubleTy);
-  type = FunctionType::get(Type::VoidTy, args, false);
-  printDoubleLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
-                                     "printDouble", module);
-  args.clear();
-  
-  // Create printLongLLVM
-  args.push_back(Type::Int64Ty);
-  type = FunctionType::get(Type::VoidTy, args, false);
-  printLongLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
-                                   "printLong", module);
-  args.clear();
-  
-  // Create printIntLLVM
-  args.push_back(Type::Int32Ty);
-  type = FunctionType::get(Type::VoidTy, args, false);
-  printIntLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
-                                  "printInt", module);
-  args.clear();
-  
-  // Create printObjectLLVM
-  args.push_back(ptrType);
-  type = FunctionType::get(Type::VoidTy, args, false);
-  printObjectLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
-                                     "printObject", module);
-  args.clear();
-
-  args.push_back(ptrType);
-  type = FunctionType::get(
-    /*Result=*/Type::VoidTy,
-    /*Params=*/args,
-    /*isVarArg=*/false);
-  unwindResume = Function::Create(
-    /*Type=*/type,
-    /*Linkage=*/GlobalValue::ExternalLinkage,
-    /*Name=*/"_Unwind_Resume_or_Rethrow", module); // (external, no body)
-  args.clear();
-
-  llvmGetException = Intrinsic::getDeclaration(module, Intrinsic::eh_exception);
-  exceptionSelector = sizeof(void*) == 4 ?
-                Intrinsic::getDeclaration(module, Intrinsic::eh_selector_i32) :
-                Intrinsic::getDeclaration(module, Intrinsic::eh_selector_i64);
-  
-  type = FunctionType::get(
-    /*Result=*/Type::VoidTy,
-    /*Params=*/args,
-    /*isVarArg=*/false);
-  personality = Function::Create(
-    /*Type=*/type,
-    /*Linkage=*/GlobalValue::ExternalLinkage,
-    /*Name=*/"__gxx_personality_v0", module); // (external, no body)
-  exceptionEndCatch = Function::Create(
-    /*Type=*/type,
-    /*Linkage=*/GlobalValue::ExternalLinkage,
-    /*Name=*/"__cxa_end_catch", module); // (external, no body)
-    
-  args.push_back(ptrType);
-  type = FunctionType::get(
-    /*Result=*/ptrType,
-    /*Params=*/args,
-    /*isVarArg=*/false);
-  exceptionBeginCatch = Function::Create(
-    /*Type=*/type,
-    /*Linkage=*/GlobalValue::ExternalLinkage,
-    /*Name=*/"__cxa_begin_catch", module); // (external, no body)
-  args.clear();
-
-  // Math function
-  args.push_back(Type::DoubleTy);
-  type = FunctionType::get(
-    /*Result=*/Type::DoubleTy,
-    /*Params=*/args,
-    /*isVarArg=*/false);
-  args.clear();
-    
-  func_llvm_sqrt_f64 = Intrinsic::getDeclaration(module, Intrinsic::sqrt, 
-                                                 &Type::DoubleTy, 1);
-  func_llvm_sin_f64 = Intrinsic::getDeclaration(module, Intrinsic::sin,
-                                                &Type::DoubleTy, 1);
-  func_llvm_cos_f64 = Intrinsic::getDeclaration(module, Intrinsic::cos,
-                                                &Type::DoubleTy, 1);
-  
-  func_llvm_tan_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                       "tan", module);
-  func_llvm_asin_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "asin", module);
-  func_llvm_acos_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "acos", module);
-  func_llvm_atan_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "atan", module);
-  func_llvm_exp_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                       "exp", module);
-  func_llvm_log_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                       "log", module);
-  func_llvm_ceil_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "ceil", module);
-  func_llvm_floor_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                         "floor", module);
-  func_llvm_cbrt_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "cbrt", module);
-  func_llvm_cosh_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "cosh", module);
-  func_llvm_expm1_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                         "expm1", module);
-  func_llvm_log10_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                         "log10", module);
-  func_llvm_log1p_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                         "log1p", module);
-  func_llvm_sinh_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "sinh", module);
-  func_llvm_tanh_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "tanh", module);
-  func_llvm_fabs_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "fabs", module);
-  func_llvm_rint_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "rint", module);
-    
-  args.push_back(Type::DoubleTy);
-  args.push_back(Type::DoubleTy);
-  type = FunctionType::get(
-    /*Result=*/Type::DoubleTy,
-    /*Params=*/args,
-    /*isVarArg=*/false);
-  args.clear();
-  
-  func_llvm_hypot_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                         "hypot", module);
-  //func_llvm_pow_f64 = Function::Create(FuncTy2, GlobalValue::ExternalLinkage, "llvm.pow.f64", module);
-  func_llvm_pow_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                       "pow", module);
-  func_llvm_atan2_f64 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                         "atan2", module);
-    
-  args.push_back(Type::FloatTy);
-  type = FunctionType::get(
-    /*Result=*/Type::FloatTy,
-    /*Params=*/args,
-    /*isVarArg=*/false);
-  args.clear();
-    
-  func_llvm_fabs_f32 = Function::Create(type, GlobalValue::ExternalLinkage,
-                                        "fabsf", module);
-
-  // Create setjmp
-  args.push_back(ptrType);
-  type = FunctionType::get(Type::Int32Ty, args, false);
-  setjmpLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
-                                "setjmp", module);
-  
-  /* Create memcpy */
-  llvm_memcpy_i32 = Intrinsic::getDeclaration(module, Intrinsic::memcpy_i32);
-
-  /* Create memset */
-  llvm_memset_i32 = Intrinsic::getDeclaration(module, Intrinsic::memset_i32);
-    
-  /* Create atomic cas i32 */
-  const Type* i32 = Type::Int32Ty;
-  llvm_atomic_lcs_i32 = Intrinsic::getDeclaration(module, 
-                                                  Intrinsic::atomic_cmp_swap,
-                                                  &i32, 1);
-  
-    // Constant declaration
-  constantLongMinusOne = ConstantInt::get(Type::Int64Ty, (uint64_t)-1);
-  constantLongZero = ConstantInt::get(Type::Int64Ty, 0);
-  constantLongOne = ConstantInt::get(Type::Int64Ty, 1);
-  constantZero = ConstantInt::get(Type::Int32Ty, 0);
-  constantInt8Zero = ConstantInt::get(Type::Int8Ty, 0);
-  constantOne = ConstantInt::get(Type::Int32Ty, 1);
-  constantTwo = ConstantInt::get(Type::Int32Ty, 2);
-  constantThree = ConstantInt::get(Type::Int32Ty, 3);
-  constantFour = ConstantInt::get(Type::Int32Ty, 4);
-  constantFive = ConstantInt::get(Type::Int32Ty, 5);
-  constantSix = ConstantInt::get(Type::Int32Ty, 6);
-  constantSeven = ConstantInt::get(Type::Int32Ty, 7);
-  constantEight = ConstantInt::get(Type::Int32Ty, 8);
-  constantMinusOne = ConstantInt::get(Type::Int32Ty, (uint64_t)-1);
-  constantMinInt = ConstantInt::get(Type::Int32Ty, MinInt);
-  constantMaxInt = ConstantInt::get(Type::Int32Ty, MaxInt);
-  constantMinLong = ConstantInt::get(Type::Int64Ty, MinLong);
-  constantMaxLong = ConstantInt::get(Type::Int64Ty, MaxLong);
-  constantFloatZero = ConstantFP::get(Type::FloatTy, 0.0f);
-  constantFloatOne = ConstantFP::get(Type::FloatTy, 1.0f);
-  constantFloatTwo = ConstantFP::get(Type::FloatTy, 2.0f);
-  constantDoubleZero = ConstantFP::get(Type::DoubleTy, 0.0);
-  constantDoubleOne = ConstantFP::get(Type::DoubleTy, 1.0);
-  constantMaxIntFloat = ConstantFP::get(Type::FloatTy, MaxIntFloat);
-  constantMinIntFloat = ConstantFP::get(Type::FloatTy, MinIntFloat);
-  constantMinLongFloat = ConstantFP::get(Type::FloatTy, MinLongFloat);
-  constantMinLongDouble = ConstantFP::get(Type::DoubleTy, MinLongDouble);
-  constantMaxLongFloat = ConstantFP::get(Type::FloatTy, MaxLongFloat);
-  constantMaxIntDouble = ConstantFP::get(Type::DoubleTy, MaxIntDouble);
-  constantMinIntDouble = ConstantFP::get(Type::DoubleTy, MinIntDouble);
-  constantMaxLongDouble = ConstantFP::get(Type::DoubleTy, MaxLongDouble);
-  constantMaxLongDouble = ConstantFP::get(Type::DoubleTy, MaxLongDouble);
-  constantFloatInfinity = ConstantFP::get(Type::FloatTy, MaxFloat);
-  constantFloatMinusInfinity = ConstantFP::get(Type::FloatTy, MinFloat);
-  constantDoubleInfinity = ConstantFP::get(Type::DoubleTy, MaxDouble);
-  constantDoubleMinusInfinity = ConstantFP::get(Type::DoubleTy, MinDouble);
-  constantDoubleMinusZero = ConstantFP::get(Type::DoubleTy, -0.0);
-  constantFloatMinusZero = ConstantFP::get(Type::FloatTy, -0.0f);
-
-  constantPtrNull = Constant::getNullValue(ptrType); 
-  constantPtrSize = ConstantInt::get(Type::Int32Ty, sizeof(void*));
-  arrayPtrType = PointerType::getUnqual(ArrayType::get(Type::Int8Ty, 0));
-
-  mvm::jit::protectEngine = mvm::Lock::allocNormal();
-}
-
-llvm::Function* mvm::jit::llvm_memcpy_i32;
-llvm::Function* mvm::jit::llvm_memset_i32;
-
-llvm::Function* mvm::jit::llvm_atomic_lcs_i32;
-
-llvm::Function* mvm::jit::exceptionEndCatch;
-llvm::Function* mvm::jit::exceptionBeginCatch;
-llvm::Function* mvm::jit::unwindResume;
-llvm::Function* mvm::jit::exceptionSelector;
-llvm::Function* mvm::jit::personality;
-llvm::Function* mvm::jit::llvmGetException;
-
-llvm::Function* mvm::jit::printFloatLLVM;
-llvm::Function* mvm::jit::printDoubleLLVM;
-llvm::Function* mvm::jit::printLongLLVM;
-llvm::Function* mvm::jit::printIntLLVM;
-llvm::Function* mvm::jit::printObjectLLVM;
-
-llvm::Function* mvm::jit::setjmpLLVM;
-
-llvm::Function* mvm::jit::func_llvm_fabs_f32;
-llvm::Function* mvm::jit::func_llvm_fabs_f64;
-llvm::Function* mvm::jit::func_llvm_sqrt_f64;
-llvm::Function* mvm::jit::func_llvm_sin_f64;
-llvm::Function* mvm::jit::func_llvm_cos_f64;
-llvm::Function* mvm::jit::func_llvm_tan_f64;
-llvm::Function* mvm::jit::func_llvm_asin_f64;
-llvm::Function* mvm::jit::func_llvm_acos_f64;
-llvm::Function* mvm::jit::func_llvm_atan_f64;
-llvm::Function* mvm::jit::func_llvm_atan2_f64;
-llvm::Function* mvm::jit::func_llvm_exp_f64;
-llvm::Function* mvm::jit::func_llvm_log_f64;
-llvm::Function* mvm::jit::func_llvm_pow_f64;
-llvm::Function* mvm::jit::func_llvm_ceil_f64;
-llvm::Function* mvm::jit::func_llvm_floor_f64;
-llvm::Function* mvm::jit::func_llvm_rint_f64;
-llvm::Function* mvm::jit::func_llvm_cbrt_f64;
-llvm::Function* mvm::jit::func_llvm_cosh_f64;
-llvm::Function* mvm::jit::func_llvm_expm1_f64;
-llvm::Function* mvm::jit::func_llvm_hypot_f64;
-llvm::Function* mvm::jit::func_llvm_log10_f64;
-llvm::Function* mvm::jit::func_llvm_log1p_f64;
-llvm::Function* mvm::jit::func_llvm_sinh_f64;
-llvm::Function* mvm::jit::func_llvm_tanh_f64;
-
-llvm::ExecutionEngine* mvm::jit::executionEngine;
-
-mvm::Lock* mvm::jit::protectEngine;
-llvm::ConstantInt* mvm::jit::constantInt8Zero;
-llvm::ConstantInt* mvm::jit::constantZero;
-llvm::ConstantInt* mvm::jit::constantOne;
-llvm::ConstantInt* mvm::jit::constantTwo;
-llvm::ConstantInt* mvm::jit::constantThree;
-llvm::ConstantInt* mvm::jit::constantFour;
-llvm::ConstantInt* mvm::jit::constantFive;
-llvm::ConstantInt* mvm::jit::constantSix;
-llvm::ConstantInt* mvm::jit::constantSeven;
-llvm::ConstantInt* mvm::jit::constantEight;
-llvm::ConstantInt* mvm::jit::constantMinusOne;
-llvm::ConstantInt* mvm::jit::constantLongMinusOne;
-llvm::ConstantInt* mvm::jit::constantLongZero;
-llvm::ConstantInt* mvm::jit::constantLongOne;
-llvm::ConstantInt* mvm::jit::constantMinInt;
-llvm::ConstantInt* mvm::jit::constantMaxInt;
-llvm::ConstantInt* mvm::jit::constantMinLong;
-llvm::ConstantInt* mvm::jit::constantMaxLong;
-llvm::ConstantFP*  mvm::jit::constantFloatZero;
-llvm::ConstantFP*  mvm::jit::constantFloatOne;
-llvm::ConstantFP*  mvm::jit::constantFloatTwo;
-llvm::ConstantFP*  mvm::jit::constantDoubleZero;
-llvm::ConstantFP*  mvm::jit::constantDoubleOne;
-llvm::ConstantFP*  mvm::jit::constantMaxIntFloat;
-llvm::ConstantFP*  mvm::jit::constantMinIntFloat;
-llvm::ConstantFP*  mvm::jit::constantMinLongFloat;
-llvm::ConstantFP*  mvm::jit::constantMinLongDouble;
-llvm::ConstantFP*  mvm::jit::constantMaxLongFloat;
-llvm::ConstantFP*  mvm::jit::constantMaxIntDouble;
-llvm::ConstantFP*  mvm::jit::constantMinIntDouble;
-llvm::ConstantFP*  mvm::jit::constantMaxLongDouble;
-llvm::ConstantFP*  mvm::jit::constantDoubleInfinity;
-llvm::ConstantFP*  mvm::jit::constantDoubleMinusInfinity;
-llvm::ConstantFP*  mvm::jit::constantFloatInfinity;
-llvm::ConstantFP*  mvm::jit::constantFloatMinusInfinity;
-llvm::ConstantFP*  mvm::jit::constantFloatMinusZero;
-llvm::ConstantFP*  mvm::jit::constantDoubleMinusZero;
-llvm::Constant*    mvm::jit::constantPtrNull;
-llvm::ConstantInt* mvm::jit::constantPtrSize;
-const llvm::PointerType* mvm::jit::ptrType;
-const llvm::PointerType* mvm::jit::ptr32Type;
-const llvm::PointerType* mvm::jit::ptrPtrType;
-const llvm::Type* mvm::jit::arrayPtrType;
-
-llvm::Module *mvm::jit::globalModule;
-llvm::ExistingModuleProvider *mvm::jit::globalModuleProvider;
-mvm::MvmMemoryManager *mvm::jit::memoryManager;
-
-
-uint64 mvm::jit::getTypeSize(const llvm::Type* type) {
-  return executionEngine->getTargetData()->getABITypeSize(type);
-}
-
-void mvm::jit::runPasses(llvm::Function* func,  llvm::FunctionPassManager* pm) {
-  pm->run(*func);
-}
-
-#if defined(__MACH__) && !defined(__i386__)
-#define FRAME_IP(fp) (fp[2])
-#else
-#define FRAME_IP(fp) (fp[1])
-#endif
-
-int mvm::jit::getBacktrace(void** stack, int size) {
-  void** blah = (void**)__builtin_frame_address(1);
-  int cpt = 0;
-  void* baseSP = mvm::Thread::get()->baseSP;
-  while (blah && cpt < size && blah < baseSP) {
-    stack[cpt++] = (void**)FRAME_IP(blah);
-    blah = (void**)blah[0];
-  }
-  return cpt;
-}
-
-LockNormal lock;
-std::map<void*, Code*> pointerMap;
-
-Code* mvm::jit::getCodeFromPointer(void* Addr) {
-  lock.lock();
-  std::map<void*, Code*>::iterator I =
-    pointerMap.lower_bound(Addr);
-  
-  lock.unlock();
-  if (I != pointerMap.end()) {
-    Code* m = I->second;
-    if (Addr >= m->FunctionStart) return m;
-  }
-
-  return 0;
-}
-
-void mvm::jit::addMethodInfo(void* Addr, Code* C) {
-  lock.lock();
-  pointerMap.insert(std::make_pair(Addr, C));
-  lock.unlock();
-}

Added: vmkit/trunk/lib/Mvm/LLVMRuntime/LLVMRuntime.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/LLVMRuntime/LLVMRuntime.ll?rev=54633&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/LLVMRuntime/LLVMRuntime.ll (added)
+++ vmkit/trunk/lib/Mvm/LLVMRuntime/LLVMRuntime.ll Mon Aug 11 02:20:00 2008
@@ -0,0 +1,95 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Printing functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+declare void @printFloat(float)
+declare void @printDouble(double)
+declare void @printLong(i64)
+declare void @printInt(i32)
+declare void @printObject(i8*)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Exceptions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+declare void @_Unwind_Resume_or_Rethrow(i8*)
+declare i8* @llvm.eh.exception()
+declare i32 @llvm.eh.selector.i32(i8*, i8*, i8*, ...)
+declare i64 @llvm.eh.selector.i64(i8*, i8*, i8*, ...)
+declare void @__gxx_personality_v0()
+declare i8* @__cxa_begin_catch(i8*)
+declare void @__cxa_end_catch()
+declare i32 @setjmp(i8*)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Math ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+declare double @llvm.sqrt.f64(double)
+declare double @llvm.sin.f64(double)
+declare double @llvm.cos.f64(double)
+declare double @tan(double)
+declare double @asin(double)
+declare double @acos(double)
+declare double @atan(double)
+declare double @exp(double)
+declare double @log(double)
+declare double @ceil(double)
+declare double @floor(double)
+declare double @cbrt(double)
+declare double @cosh(double)
+declare double @expm1(double)
+declare double @log10(double)
+declare double @log1p(double)
+declare double @sinh(double)
+declare double @tanh(double)
+declare double @fabs(double)
+declare double @rint(double)
+declare double @hypot(double, double)
+declare double @pow(double, double)
+declare double @atan2(double, double)
+declare float @fabsf(float)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Memory ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+declare void @llvm.memcpy.i32(i8 *, i8 *, i32, i32)
+declare void @llvm.memset.i32(i8 *, i8 *, i32, i32)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Atomic ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+declare i8 @llvm.atomic.cmp.swap.i8.p0i8(i8*, i8, i8)
+declare i16 @llvm.atomic.cmp.swap.i16.p0i16(i16*, i16, i16)
+declare i32 @llvm.atomic.cmp.swap.i32.p0i32(i32*, i32, i32)
+declare i64 @llvm.atomic.cmp.swap.i64.p0i64(i64*, i64, i64)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;Helper functions for gcc < 4.2 ;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+define i8 @runtime.llvm.atomic.cmp.swap.i8(i8* %ptr, i8 %cmp, i8 %swap) 
+nounwind {
+  %A = call i8 @llvm.atomic.cmp.swap.i8.p0i8( i8* %ptr, i8 %cmp, i8 %swap)
+  ret i8 %A
+}
+
+define i16 @runtime.llvm.atomic.cmp.swap.i16(i16* %ptr, i16 %cmp, i16 %swap)
+nounwind {
+  %A = call i16 @llvm.atomic.cmp.swap.i16.p0i16( i16* %ptr, i16 %cmp, i16 %swap)
+  ret i16 %A
+}
+
+define i32 @runtime.llvm.atomic.cmp.swap.i32(i32* %ptr, i32 %cmp, i32 %swap)
+nounwind {
+  %A = call i32 @llvm.atomic.cmp.swap.i32.p0i32(i32* %ptr, i32 %cmp, i32 %swap)
+  ret i32 %A
+}
+
+define i64 @runtime.llvm.atomic.cmp.swap.i64(i64* %ptr, i64 %cmp, i64 %swap)
+nounwind {
+  %A = call i64 @llvm.atomic.cmp.swap.i64.p0i64( i64* %ptr, i64 %cmp, i64 %swap)
+  ret i64 %A
+}

Added: vmkit/trunk/lib/Mvm/LLVMRuntime/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/LLVMRuntime/Makefile?rev=54633&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/LLVMRuntime/Makefile (added)
+++ vmkit/trunk/lib/Mvm/LLVMRuntime/Makefile Mon Aug 11 02:20:00 2008
@@ -0,0 +1,26 @@
+##===- lib/Mvm/LLVMRuntime/Makefile ------------------------*- Makefile -*-===##
+# 
+#                     The vmkit project
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+# 
+##===----------------------------------------------------------------------===##
+LEVEL = ../../..
+
+include $(LEVEL)/Makefile.common
+
+all = llvmruntime.cpp
+
+llvmruntimebc	: llvmruntimell
+	$(Echo) "Building LLVM runtime with llvm-as"
+	$(Verb) $(LLVMAS) -f LLVMRuntime.ll
+
+all :: llvmruntimebc
+	$(Echo) "Building LLVM runtime with llc"
+	$(Verb) $(LLC) -march=cpp -cppgen=contents -f LLVMRuntime.bc
+
+llvmruntimell: LLVMRuntime.ll
+
+clean::
+	rm -f LLVMRuntime.bc LLVMRuntime.cpp

Modified: vmkit/trunk/lib/Mvm/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Makefile?rev=54633&r1=54632&r2=54633&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/Makefile (original)
+++ vmkit/trunk/lib/Mvm/Makefile Mon Aug 11 02:20:00 2008
@@ -10,8 +10,6 @@
 
 include $(LEVEL)/Makefile.config
 
-PARALLEL_DIRS = Allocator CommonThread $(GCLIB)
+DIRS = Allocator CommonThread $(GCLIB) LLVMRuntime Runtime
 
-LIBRARYNAME = Mvm
 include $(LEVEL)/Makefile.common
-

Removed: vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp?rev=54632&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp (original)
+++ vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp (removed)
@@ -1,78 +0,0 @@
-//===----- MvmMemoryManager.cpp - LLVM Memory manager for Mvm -------------===//
-//
-//                              Mvm
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include <assert.h>
-
-#include "mvm/JIT.h"
-#include "mvm/Method.h"
-#include "mvm/Object.h"
-
-#include "mvm/MvmMemoryManager.h"
-
-using namespace mvm;
-using namespace llvm;
-
-unsigned char* MvmMemoryManager::startFunctionBody(const Function* F, 
-                                                   uintptr_t &ActualSize) {
-  Code* meth = new Code(); 
-  currentMethod = meth;
-  return realMemoryManager->startFunctionBody(F, ActualSize); 
-}
-
-unsigned char *MvmMemoryManager::allocateStub(const GlobalValue* GV,
-                                              unsigned StubSize, 
-                                              unsigned Alignment) {
-  unsigned char* res = realMemoryManager->allocateStub(GV, StubSize, Alignment); 
-  Code* meth = new Code();
-  mvm::jit::addMethodInfo((void*)(res + StubSize), meth);
-  currentMethod = meth;
-  meth->FunctionStart = res;
-  meth->FunctionEnd = res + StubSize;
-  currentMethod = meth;
-
-  return res;
-}
-
-void MvmMemoryManager::endFunctionBody(const Function *F, 
-                                       unsigned char *FunctionStart,
-                                       unsigned char *FunctionEnd) {
-  mvm::jit::addMethodInfo((void*)FunctionEnd, currentMethod);
-  currentMethod->FunctionStart = FunctionStart;
-  currentMethod->FunctionEnd = FunctionEnd;
-  realMemoryManager->endFunctionBody(F, FunctionStart, FunctionEnd);
-}
-
-
-void MvmMemoryManager::deallocateMemForFunction(const Function *F) {
-  realMemoryManager->deallocateMemForFunction(F);
-}
-
-void MvmMemoryManager::AllocateGOT() {
-  realMemoryManager->AllocateGOT();
-}
-
-unsigned char *MvmMemoryManager::getGOTBase() const {
-  return realMemoryManager->getGOTBase();
-}
-
-unsigned char *MvmMemoryManager::startExceptionTable(const Function* F, 
-                                                     uintptr_t &ActualSize) {
-  unsigned char* res = realMemoryManager->startExceptionTable(F, ActualSize);
-  
-  currentMethod->exceptionTable = res;
-  return (unsigned char*)res;
-}                                                     
-
-void MvmMemoryManager::endExceptionTable(const Function *F, 
-                                         unsigned char *TableStart,
-                                         unsigned char *TableEnd,
-                                         unsigned char* FrameRegister) {
-  realMemoryManager->endExceptionTable(F, TableStart, TableEnd, FrameRegister);
-  currentMethod->frameRegister = FrameRegister;
-}

Removed: vmkit/trunk/lib/Mvm/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Object.cpp?rev=54632&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Object.cpp (removed)
@@ -1,116 +0,0 @@
-//===--------- Object.cc - Common objects for vmlets ----------------------===//
-//
-//                     The Micro Virtual Machine
-//
-// This file is distributed under the University of Illinois Open Source 
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include <stdlib.h>
-
-#include "MvmGC.h"
-#include "mvm/Method.h"
-#include "mvm/Object.h"
-#include "mvm/PrintBuffer.h"
-#include "mvm/Threads/Key.h"
-#include "mvm/Threads/Thread.h"
-
-using namespace mvm;
-
-
-VirtualTable *NativeString::VT = 0;
-VirtualTable *PrintBuffer::VT = 0;
-
-mvm::Key<mvm::Thread>* mvm::Thread::threadKey = 0;
-
-
-void Object::initialise() {
-# define INIT(X) { \
-  X fake; \
-  X::VT = ((void**)(void*)(&fake))[0]; }
-  
-  INIT(NativeString);
-  INIT(PrintBuffer);
-  
-#undef INIT
-}
-
-void PrintBuffer::TRACER {
-  ((PrintBuffer *)this)->contents()->MARK_AND_TRACE;
-}
-
-
-PrintBuffer *PrintBuffer::writeObj(const Object *obj) {
-#ifdef MULTIPLE_GC
-  Object *beg = (Object*)mvm::Thread::get()->GC->begOf(obj);
-#else
-  Object *beg = (Object*)Collector::begOf(obj);
-#endif
-  
-  if(beg) {
-    if(beg == obj) {
-      obj->print((mvm::PrintBuffer*)this);
-    } else {
-      write("<In Object [");
-      beg->print(this);
-      write("] -- offset ");
-      writeS4((intptr_t)obj - (intptr_t)beg);
-      write(">");
-    }
-  } else {
-    write("<DirectValue: ");
-    writeS4((intptr_t)obj);
-    write(">");
-  }
-  return this;
-}
-
-extern "C" void write_ptr(PrintBuffer* buf, void* obj) {
-  buf->writePtr(obj);
-}
-
-extern "C" void write_int(PrintBuffer* buf, int a) {
-  buf->writeS4(a);
-}
-
-extern "C" void write_str(PrintBuffer* buf, char* a) {
-  buf->write(a);
-}
-
-char *Object::printString(void) const {
-  PrintBuffer *buf= PrintBuffer::alloc();
-  buf->writeObj(this);
-  return buf->contents()->cString();
-}
-
-void Object::print(PrintBuffer *buf) const {
-  buf->write("<Object@");
-  buf->writePtr((void*)this);
-  buf->write(">");
-}
-
-void NativeString::print(PrintBuffer *buf) const {
-  NativeString *const self= (NativeString *)this;
-  buf->write("\"");
-  for (size_t i= 0; i < strlen(self->cString()); ++i) {
-    int c= self->cString()[i];
-    switch (c) {
-      case '\b': buf->write("\\b"); break;
-      case '\f': buf->write("\\f"); break;
-      case '\n': buf->write("\\n"); break;
-      case '\r': buf->write("\\r"); break;
-      case '\t': buf->write("\\t"); break;
-      case '"':  buf->write("\\\""); break;
-      default: {
-        char esc[32];
-        if (c < 32)
-          sprintf(esc, "\\x%02x", c);
-        else
-          sprintf(esc, "%c", c);
-        buf->write(esc);
-      }
-    }
-  }
-  buf->write("\"");
-}

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/CommandLine.cpp (added)
+++ vmkit/trunk/lib/Mvm/Runtime/CommandLine.cpp Mon Aug 11 02:20:00 2008
@@ -0,0 +1,165 @@
+//===------- CommandLine.cpp - Parses the command line --------------------===//
+//
+//                     The Micro Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include <assert.h>
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "CommandLine.h"
+#include "MvmGC.h"
+#include "mvm/Threads/Thread.h"
+
+using namespace mvm;
+
+typedef struct thread_arg_t {
+  int argc;
+  char** argv;
+  vmlet_main_t func;
+} thread_arg_t;
+
+typedef int (*boot_t)();
+
+
+CommandLine::CommandLine() {
+  resetString();
+  resetArgv();
+}
+
+void CommandLine::appendChar(char c) {
+  assert(_yytext);
+  _yytext[_yylen++]= c;
+  if (_yylen == _yylenMax) {
+    _yylenMax *= 2;
+    _yytext= (char *)realloc(_yytext, _yylenMax);
+  }
+}
+
+void CommandLine::appendString(char* str) {
+  assert(argv);
+  appendChar(0);
+  argv[argc++] = str;
+  if (argc == argcMax) {
+    argcMax *= 2;
+    argv = (char **)realloc(argv, argcMax * sizeof(char*));
+  }
+}
+
+void CommandLine::resetString() {
+  _yytext = (char *)malloc(_yylenMax= 32);
+  _yylen = 0;
+}
+
+void CommandLine::resetArgv() {
+  argv = (char **)malloc(sizeof(char*) * (argcMax= 10));
+  argc = 0;
+}
+
+
+void CommandLine::start() {
+  printf("> ");
+  _yyChar = getc(stdin);
+  
+  while (true) {
+    switch(_yyChar) {
+      case ' ' : 
+        do { _yyChar = getc(stdin); } while (_yyChar == ' ');
+        if (_yylen != 0) {
+          appendString(_yytext);
+          resetString();
+        }
+        break;
+      
+      case '\n' :
+        if (_yylen != 0) {
+          appendString(_yytext);
+          resetString();
+        }
+        if (argc > 1) {
+          executeInstr();
+          resetArgv();
+          printf("> ");
+        }
+        _yyChar = getc(stdin);
+        break;
+
+      case EOF :
+        printf("\n");
+        return;
+
+      default :
+        appendChar(_yyChar);
+        _yyChar = getc(stdin);
+    }
+  } 
+}
+
+extern "C" int startApp(thread_arg_t* arg) {
+  int argc = arg->argc;
+  char** argv = arg->argv;
+  vmlet_main_t func = arg->func;
+  free(arg);
+#ifndef MULTIPLE_GC
+  Collector::inject_my_thread(&argc);
+  func(argc, argv);
+  Collector::remove_my_thread();
+  Collector::collect();
+#else
+  Collector* GC = Collector::allocate();
+  GC->inject_my_thread(&argc);
+  func(argc, argv);
+  GC->remove_my_thread();
+  GC->collect();
+#endif
+  return 0;
+}
+
+void CommandLine::executeInstr() {
+  if (!strcmp(argv[0], "load")) {
+    char* buf = (char*)alloca(sizeof(argv[1]) + 7);
+    sprintf(buf, "lib%s.so", argv[1]);
+    void* handle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
+    if (handle == 0) {
+      fprintf(stderr, "\t Unable to load %s\n", argv[1]);
+      printf("\t error = %s\n", dlerror());
+      return;
+    }
+    
+    boot_t func = (boot_t)(intptr_t)dlsym(handle, "boot");
+    
+    if (func == 0) {
+      fprintf(stderr, "\t Unable to find %s boot method\n", argv[1]);
+      dlclose(handle);
+      return;
+    }
+    func();
+    
+    vmlet_main_t vmlet = (vmlet_main_t)(intptr_t)dlsym(handle, "start_app");
+
+    vmlets[argv[1]] = vmlet;
+
+  } else {
+    vmlet_main_t func = vmlets[argv[0]];
+    if (!func) {
+      fprintf(stderr, "\t Unknown vmlet %s\n", argv[0]);
+    } else {
+#if 0
+      thread_arg_t* thread_arg = (thread_arg_t*)malloc(sizeof (thread_arg_t));
+      thread_arg->argc = argc;
+      thread_arg->argv = argv;
+      thread_arg->func = func;
+      int tid = 0;
+      Thread::start(&tid, (int (*)(void *))startApp, thread_arg);
+#else
+      func(argc, argv);
+#endif
+    }
+  }
+}

Added: vmkit/trunk/lib/Mvm/Runtime/CommandLine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/CommandLine.h?rev=54633&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/CommandLine.h (added)
+++ vmkit/trunk/lib/Mvm/Runtime/CommandLine.h Mon Aug 11 02:20:00 2008
@@ -0,0 +1,57 @@
+//===--------- CommandLine.h - Parses the command line --------------------===//
+//
+//                     The Micro Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef COMMAND_LINE_H
+#define COMMAND_LINE_H
+
+#include <map>
+
+#include <string.h>
+
+namespace mvm {
+
+typedef int (*vmlet_main_t)(int argc, char** argv);
+
+struct ltstr
+{
+  bool operator()(const char* s1, const char* s2) const
+  {
+    return strcmp(s1, s2) < 0;
+  }
+};
+
+class CommandLine {
+public:
+  char** argv;
+  unsigned argc;
+  unsigned argcMax;
+
+  char* _yytext;
+  unsigned _yylen;
+  unsigned _yylenMax;
+  char _yyChar;
+  
+  std::map<const char*, vmlet_main_t, ltstr> vmlets;
+
+  CommandLine();
+  
+  void appendChar(char c);
+  void appendString(char* str);
+
+  void start();
+  void executeInstr();
+
+  void resetArgv();
+  void resetString();
+
+};
+
+} // end namespace mvm
+
+#endif // COMMAND_LINE_H

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Disassembler.cpp (added)
+++ vmkit/trunk/lib/Mvm/Runtime/Disassembler.cpp Mon Aug 11 02:20:00 2008
@@ -0,0 +1,91 @@
+//===--------- Disassembler.cc - Intefarce to disassembler ----------------===//
+//
+//                      Micro Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mvm/JIT.h"
+
+#ifdef HAVE_DISASSEMBLER
+
+#if defined(__PPC__)
+extern "C"
+{
+# include <dis-asm.h>
+# include <bfd.h>
+}
+
+
+
+static struct disassemble_info  info;
+static int      initialised= 0;  
+
+// this is the only function exported from this file
+
+int mvm::jit::disassemble(unsigned int *addr)
+{
+  
+  if (!initialised)
+    {   
+      INIT_DISASSEMBLE_INFO(info, stdout, fprintf);
+      info.flavour=   bfd_target_elf_flavour;
+      info.arch=    bfd_arch_powerpc;
+      info.mach=    bfd_mach_ppc_750; // generic(ish) == PPC G3
+      info.endian=    BFD_ENDIAN_BIG;
+      info.buffer_length= 65536;
+    }   
+  info.buffer=     (bfd_byte *)addr;
+  info.buffer_vma= (bfd_vma)(long)addr;
+  return print_insn_big_powerpc((bfd_vma)(long)addr, &info);
+  
+}
+
+#elif defined(__i386__)
+extern "C"
+{
+# include <bfd.h>	// bfd types
+# include <dis-asm.h>	// disassemble_info
+  int print_insn_i386_att(bfd_vma, disassemble_info *);
+}
+
+
+static struct disassemble_info	info;
+static int			initialised= 0;
+
+
+int mvm::jit::disassemble(unsigned int *addr)
+{
+  if (!initialised)
+    {
+      INIT_DISASSEMBLE_INFO(info, stdout, fprintf);
+      info.flavour=	  bfd_target_elf_flavour;
+      info.arch=	  bfd_arch_i386;
+      info.mach=	  bfd_mach_i386_i386;
+      info.endian=	  BFD_ENDIAN_LITTLE;
+      info.buffer_length= 65536;
+    }
+  info.buffer=	   (bfd_byte *)addr;
+  info.buffer_vma= (bfd_vma)(long)addr;
+  return print_insn_i386_att((bfd_vma)(long)addr, &info);
+}
+
+#else
+
+int mvm::jit::disassemble(unsigned int* addr) {
+  return 0;
+}
+
+#endif
+
+#else
+
+int mvm::jit::disassemble(unsigned int* addr) {
+  return 0;
+}
+
+#endif
+
+

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/EscapeAnalysis.cpp (added)
+++ vmkit/trunk/lib/Mvm/Runtime/EscapeAnalysis.cpp Mon Aug 11 02:20:00 2008
@@ -0,0 +1,137 @@
+//===------EscapeAnalysis.cpp - Simple LLVM escape analysis ---------------===//
+//
+//                     The Micro Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "llvm/Constants.h"
+#include "llvm/Pass.h"
+#include "llvm/Function.h"
+#include "llvm/Instructions.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Debug.h"
+
+#include <map>
+
+#include "mvm/GC/GC.h"
+
+using namespace llvm;
+
+namespace {
+
+  class VISIBILITY_HIDDEN EscapeAnalysis : public FunctionPass {
+  public:
+    static char ID;
+    EscapeAnalysis(Function* alloc = 0) : 
+      FunctionPass((intptr_t)&ID) {
+      Allocator = alloc;
+    }
+
+    virtual bool runOnFunction(Function &F);
+  private:
+    Function* Allocator;
+    bool processMalloc(Instruction* I, Value* Size, Value* VT);
+  };
+  char EscapeAnalysis::ID = 0;
+  RegisterPass<EscapeAnalysis> X("EscapeAnalysis", "Escape Analysis Pass");
+
+bool EscapeAnalysis::runOnFunction(Function& F) {
+  bool Changed = false;
+  for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) { 
+    BasicBlock *Cur = BI; 
+
+    for (BasicBlock::iterator II = Cur->begin(), IE = Cur->end(); II != IE;) {
+      Instruction *I = II;
+      II++;
+      if (CallInst *CI = dyn_cast<CallInst>(I)) {
+        if (CI->getOperand(0) == Allocator) {
+          Changed |= processMalloc(CI, CI->getOperand(1), CI->getOperand(2));
+        }
+      } else if (InvokeInst *CI = dyn_cast<InvokeInst>(I)) {
+        if (CI->getOperand(0) == Allocator) {
+          Changed |= processMalloc(CI, CI->getOperand(3), CI->getOperand(4));
+        }
+      }
+    }
+  }
+  return Changed;
+}
+
+
+
+
+static bool escapes(Instruction* Ins, std::map<Instruction*, bool>& visited) {
+  for (Value::use_iterator I = Ins->use_begin(), E = Ins->use_end(); 
+       I != E; ++I) {
+    if (Instruction* II = dyn_cast<Instruction>(I)) {
+      if (dyn_cast<CallInst>(II)) return true;
+      else if (dyn_cast<InvokeInst>(II)) return true;
+      else if (dyn_cast<BitCastInst>(II)) {
+        if (escapes(II, visited)) return true;
+      }
+      else if (StoreInst* SI = dyn_cast<StoreInst>(II)) {
+        if (AllocaInst * AI = dyn_cast<AllocaInst>(SI->getOperand(1))) {
+          if (!visited[AI]) {
+            visited[AI] = true;
+            if (escapes(AI, visited)) return true;
+          }
+        } else if (SI->getOperand(0) == Ins) {
+          return true;
+        }
+      }
+      else if (dyn_cast<LoadInst>(II)) {
+        if (isa<PointerType>(II->getType())) {
+          if (escapes(II, visited)) return true; // allocas
+        }
+      }
+      else if (dyn_cast<GetElementPtrInst>(II)) {
+        if (escapes(II, visited)) return true;
+      }
+      else if (dyn_cast<ReturnInst>(II)) return true;
+      else if (dyn_cast<PHINode>(II)) {
+        if (!visited[II]) {
+          visited[II] = true;
+          if (escapes(II, visited)) return true;
+        }
+      }
+    } else {
+      return true;
+    }
+  }
+  return false;
+}
+
+bool EscapeAnalysis::processMalloc(Instruction* I, Value* Size, Value* VT) {
+  Instruction* Alloc = I;
+  
+  ConstantExpr* CE = dyn_cast<ConstantExpr>(VT);
+  if (CE) {
+    ConstantInt* C = (ConstantInt*)CE->getOperand(0);
+    VirtualTable* Table = (VirtualTable*)C->getZExtValue();
+    // If the class has a finalize method, do not stack allocate the object
+    if (!((void**)Table)[0]) {
+      std::map<Instruction*, bool> visited;
+      if (!(escapes(Alloc, visited))) {
+        AllocaInst* AI = new AllocaInst(Type::Int8Ty, Size, "", Alloc);
+        BitCastInst* BI = new BitCastInst(AI, Alloc->getType(), "", Alloc);
+        DOUT << "escape" << Alloc->getParent()->getParent()->getName() << "\n";
+        Alloc->replaceAllUsesWith(BI);
+        Alloc->eraseFromParent();
+        return true;
+      }
+    }
+  }
+  return false;
+}
+}
+
+namespace mvm {
+FunctionPass* createEscapeAnalysisPass(llvm::Function* alloc) {
+
+  return new EscapeAnalysis(alloc);
+}
+}

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/JIT.cpp (added)
+++ vmkit/trunk/lib/Mvm/Runtime/JIT.cpp Mon Aug 11 02:20:00 2008
@@ -0,0 +1,348 @@
+//===---------------- JIT.cc - Initialize the JIT -------------------------===//
+//
+//                     The Micro Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CallingConv.h"
+#include <llvm/Constants.h>
+#include <llvm/DerivedTypes.h>
+#include <llvm/Instructions.h>
+#include <llvm/Type.h>
+#include "llvm/Support/MutexGuard.h"
+#include "llvm/Target/TargetOptions.h"
+
+#include <stdio.h>
+
+#include "mvm/JIT.h"
+#include "mvm/Method.h"
+#include "mvm/MvmMemoryManager.h"
+#include "mvm/Object.h"
+#include "mvm/Threads/Thread.h"
+
+using namespace mvm;
+using namespace mvm::jit;
+using namespace llvm;
+
+
+extern "C" void printFloat(float f) {
+  printf("%f\n", f);
+}
+
+extern "C" void printDouble(double d) {
+  printf("%f\n", d);
+}
+
+extern "C" void printLong(sint64 l) {
+  printf("%lld\n", l);
+}
+
+extern "C" void printInt(sint32 i) {
+  printf("%d\n", i);
+}
+
+extern "C" void printObject(mvm::Object* obj) {
+  printf("%s\n", obj->printString());
+}
+
+extern "C" void __register_frame(void*);
+
+#include "LLVMRuntime.cpp"
+
+void mvm::jit::initialise() {
+  llvm::NoFramePointerElim = true;
+  llvm::ExceptionHandling = true;
+  llvm::Module *module = globalModule = new Module("microvm");
+  jit::globalModuleProvider = new ExistingModuleProvider (globalModule);
+  jit::memoryManager = new MvmMemoryManager();
+  
+  executionEngine = ExecutionEngine::createJIT(globalModuleProvider, 0,
+                                               memoryManager);
+  executionEngine->InstallExceptionTableRegister(__register_frame);
+  std::string str = executionEngine->getTargetData()->getStringRepresentation();
+  module->setDataLayout(str);
+  
+  makeLLVMModuleContents(module);
+  
+  printFloatLLVM = module->getFunction("printFloat");
+  printDoubleLLVM = module->getFunction("printDouble");
+  printLongLLVM = module->getFunction("printLong");
+  printIntLLVM = module->getFunction("printInt");
+  printObjectLLVM = module->getFunction("printObject");
+
+  unwindResume = module->getFunction("_Unwind_Resume_or_Rethrow");
+  
+  llvmGetException = module->getFunction("llvm.eh.exception");
+  exceptionSelector = sizeof(void*) == 4 ?
+                module->getFunction("llvm.eh.selector.i32") : 
+                module->getFunction("llvm.eh.selector.i64");
+  
+  personality = module->getFunction("__gxx_personality_v0");
+  exceptionEndCatch = module->getFunction("__cxa_end_catch");
+  exceptionBeginCatch = module->getFunction("__cxa_begin_catch");
+
+  func_llvm_sqrt_f64 = module->getFunction("llvm.sqrt.f64");
+  func_llvm_sin_f64 = module->getFunction("llvm.sin.f64");
+  func_llvm_cos_f64 = module->getFunction("llvm.cos.f64");
+  
+  func_llvm_tan_f64 = module->getFunction("tan");
+  func_llvm_asin_f64 = module->getFunction("asin");
+  func_llvm_acos_f64 = module->getFunction("acos");
+  func_llvm_atan_f64 = module->getFunction("atan");
+  func_llvm_exp_f64 = module->getFunction("exp");
+  func_llvm_log_f64 = module->getFunction("log");
+  func_llvm_ceil_f64 = module->getFunction("ceil");
+  func_llvm_floor_f64 = module->getFunction("floor");
+  func_llvm_cbrt_f64 = module->getFunction("cbrt");
+  func_llvm_cosh_f64 = module->getFunction("cosh");
+  func_llvm_expm1_f64 = module->getFunction("expm1");
+  func_llvm_log10_f64 = module->getFunction("log10");
+  func_llvm_log1p_f64 = module->getFunction("log1p");
+  func_llvm_sinh_f64 = module->getFunction("sinh");
+  func_llvm_tanh_f64 = module->getFunction("tanh");
+  func_llvm_fabs_f64 = module->getFunction("fabs");
+  func_llvm_rint_f64 = module->getFunction("rint");
+    
+  func_llvm_hypot_f64 = module->getFunction("hypot");
+  func_llvm_pow_f64 = module->getFunction("pow");
+  func_llvm_atan2_f64 = module->getFunction("atan2");
+    
+  func_llvm_fabs_f32 = module->getFunction("fabsf");
+
+  setjmpLLVM = module->getFunction("setjmp");
+  
+  llvm_memcpy_i32 = module->getFunction("llvm.memcpy.i32");
+  llvm_memset_i32 = module->getFunction("llvm.memset.i32");
+    
+  llvm_atomic_lcs_i8 = module->getFunction("llvm.atomic.cmp.swap.i8.p0i8");
+  llvm_atomic_lcs_i16 = module->getFunction("llvm.atomic.cmp.swap.i16.p0i16");
+  llvm_atomic_lcs_i32 = module->getFunction("llvm.atomic.cmp.swap.i32.p0i32");
+  llvm_atomic_lcs_i64 = module->getFunction("llvm.atomic.cmp.swap.i64.p0i64");
+  
+  llvm_atomic_cmp_swap_i8 = (uint8 (*)(uint8*, uint8, uint8))
+    (uintptr_t)executionEngine->getPointerToFunction(
+      module->getFunction("runtime.llvm.atomic.cmp.swap.i8"));
+  llvm_atomic_cmp_swap_i16 = (uint16 (*)(uint16*, uint16, uint16))
+    (uintptr_t)executionEngine->getPointerToFunction(
+      module->getFunction("runtime.llvm.atomic.cmp.swap.i16"));
+  llvm_atomic_cmp_swap_i32 = (uint32 (*)(uint32*, uint32, uint32))
+    (uintptr_t)executionEngine->getPointerToFunction(
+      module->getFunction("runtime.llvm.atomic.cmp.swap.i32"));
+  llvm_atomic_cmp_swap_i64 = (uint64 (*)(uint64*, uint64, uint64))
+    (uintptr_t)executionEngine->getPointerToFunction(
+      module->getFunction("runtime.llvm.atomic.cmp.swap.i64"));
+
+  // Type declaration
+  ptrType = PointerType::getUnqual(Type::Int8Ty);
+  ptr32Type = PointerType::getUnqual(Type::Int32Ty);
+  ptrPtrType = PointerType::getUnqual(ptrType);
+  
+  // Constant declaration
+  constantLongMinusOne = ConstantInt::get(Type::Int64Ty, (uint64_t)-1);
+  constantLongZero = ConstantInt::get(Type::Int64Ty, 0);
+  constantLongOne = ConstantInt::get(Type::Int64Ty, 1);
+  constantZero = ConstantInt::get(Type::Int32Ty, 0);
+  constantInt8Zero = ConstantInt::get(Type::Int8Ty, 0);
+  constantOne = ConstantInt::get(Type::Int32Ty, 1);
+  constantTwo = ConstantInt::get(Type::Int32Ty, 2);
+  constantThree = ConstantInt::get(Type::Int32Ty, 3);
+  constantFour = ConstantInt::get(Type::Int32Ty, 4);
+  constantFive = ConstantInt::get(Type::Int32Ty, 5);
+  constantSix = ConstantInt::get(Type::Int32Ty, 6);
+  constantSeven = ConstantInt::get(Type::Int32Ty, 7);
+  constantEight = ConstantInt::get(Type::Int32Ty, 8);
+  constantMinusOne = ConstantInt::get(Type::Int32Ty, (uint64_t)-1);
+  constantMinInt = ConstantInt::get(Type::Int32Ty, MinInt);
+  constantMaxInt = ConstantInt::get(Type::Int32Ty, MaxInt);
+  constantMinLong = ConstantInt::get(Type::Int64Ty, MinLong);
+  constantMaxLong = ConstantInt::get(Type::Int64Ty, MaxLong);
+  constantFloatZero = ConstantFP::get(Type::FloatTy, 0.0f);
+  constantFloatOne = ConstantFP::get(Type::FloatTy, 1.0f);
+  constantFloatTwo = ConstantFP::get(Type::FloatTy, 2.0f);
+  constantDoubleZero = ConstantFP::get(Type::DoubleTy, 0.0);
+  constantDoubleOne = ConstantFP::get(Type::DoubleTy, 1.0);
+  constantMaxIntFloat = ConstantFP::get(Type::FloatTy, MaxIntFloat);
+  constantMinIntFloat = ConstantFP::get(Type::FloatTy, MinIntFloat);
+  constantMinLongFloat = ConstantFP::get(Type::FloatTy, MinLongFloat);
+  constantMinLongDouble = ConstantFP::get(Type::DoubleTy, MinLongDouble);
+  constantMaxLongFloat = ConstantFP::get(Type::FloatTy, MaxLongFloat);
+  constantMaxIntDouble = ConstantFP::get(Type::DoubleTy, MaxIntDouble);
+  constantMinIntDouble = ConstantFP::get(Type::DoubleTy, MinIntDouble);
+  constantMaxLongDouble = ConstantFP::get(Type::DoubleTy, MaxLongDouble);
+  constantMaxLongDouble = ConstantFP::get(Type::DoubleTy, MaxLongDouble);
+  constantFloatInfinity = ConstantFP::get(Type::FloatTy, MaxFloat);
+  constantFloatMinusInfinity = ConstantFP::get(Type::FloatTy, MinFloat);
+  constantDoubleInfinity = ConstantFP::get(Type::DoubleTy, MaxDouble);
+  constantDoubleMinusInfinity = ConstantFP::get(Type::DoubleTy, MinDouble);
+  constantDoubleMinusZero = ConstantFP::get(Type::DoubleTy, -0.0);
+  constantFloatMinusZero = ConstantFP::get(Type::FloatTy, -0.0f);
+
+  constantPtrNull = Constant::getNullValue(ptrType); 
+  constantPtrSize = ConstantInt::get(Type::Int32Ty, sizeof(void*));
+  arrayPtrType = PointerType::getUnqual(ArrayType::get(Type::Int8Ty, 0));
+
+  mvm::jit::protectEngine = mvm::Lock::allocNormal();
+
+}
+
+llvm::Function* mvm::jit::llvm_memcpy_i32;
+llvm::Function* mvm::jit::llvm_memset_i32;
+
+llvm::Function* mvm::jit::llvm_atomic_lcs_i8;
+llvm::Function* mvm::jit::llvm_atomic_lcs_i16;
+llvm::Function* mvm::jit::llvm_atomic_lcs_i32;
+llvm::Function* mvm::jit::llvm_atomic_lcs_i64;
+
+
+llvm::Function* mvm::jit::exceptionEndCatch;
+llvm::Function* mvm::jit::exceptionBeginCatch;
+llvm::Function* mvm::jit::unwindResume;
+llvm::Function* mvm::jit::exceptionSelector;
+llvm::Function* mvm::jit::personality;
+llvm::Function* mvm::jit::llvmGetException;
+
+llvm::Function* mvm::jit::printFloatLLVM;
+llvm::Function* mvm::jit::printDoubleLLVM;
+llvm::Function* mvm::jit::printLongLLVM;
+llvm::Function* mvm::jit::printIntLLVM;
+llvm::Function* mvm::jit::printObjectLLVM;
+
+llvm::Function* mvm::jit::setjmpLLVM;
+
+llvm::Function* mvm::jit::func_llvm_fabs_f32;
+llvm::Function* mvm::jit::func_llvm_fabs_f64;
+llvm::Function* mvm::jit::func_llvm_sqrt_f64;
+llvm::Function* mvm::jit::func_llvm_sin_f64;
+llvm::Function* mvm::jit::func_llvm_cos_f64;
+llvm::Function* mvm::jit::func_llvm_tan_f64;
+llvm::Function* mvm::jit::func_llvm_asin_f64;
+llvm::Function* mvm::jit::func_llvm_acos_f64;
+llvm::Function* mvm::jit::func_llvm_atan_f64;
+llvm::Function* mvm::jit::func_llvm_atan2_f64;
+llvm::Function* mvm::jit::func_llvm_exp_f64;
+llvm::Function* mvm::jit::func_llvm_log_f64;
+llvm::Function* mvm::jit::func_llvm_pow_f64;
+llvm::Function* mvm::jit::func_llvm_ceil_f64;
+llvm::Function* mvm::jit::func_llvm_floor_f64;
+llvm::Function* mvm::jit::func_llvm_rint_f64;
+llvm::Function* mvm::jit::func_llvm_cbrt_f64;
+llvm::Function* mvm::jit::func_llvm_cosh_f64;
+llvm::Function* mvm::jit::func_llvm_expm1_f64;
+llvm::Function* mvm::jit::func_llvm_hypot_f64;
+llvm::Function* mvm::jit::func_llvm_log10_f64;
+llvm::Function* mvm::jit::func_llvm_log1p_f64;
+llvm::Function* mvm::jit::func_llvm_sinh_f64;
+llvm::Function* mvm::jit::func_llvm_tanh_f64;
+
+llvm::ExecutionEngine* mvm::jit::executionEngine;
+
+mvm::Lock* mvm::jit::protectEngine;
+llvm::ConstantInt* mvm::jit::constantInt8Zero;
+llvm::ConstantInt* mvm::jit::constantZero;
+llvm::ConstantInt* mvm::jit::constantOne;
+llvm::ConstantInt* mvm::jit::constantTwo;
+llvm::ConstantInt* mvm::jit::constantThree;
+llvm::ConstantInt* mvm::jit::constantFour;
+llvm::ConstantInt* mvm::jit::constantFive;
+llvm::ConstantInt* mvm::jit::constantSix;
+llvm::ConstantInt* mvm::jit::constantSeven;
+llvm::ConstantInt* mvm::jit::constantEight;
+llvm::ConstantInt* mvm::jit::constantMinusOne;
+llvm::ConstantInt* mvm::jit::constantLongMinusOne;
+llvm::ConstantInt* mvm::jit::constantLongZero;
+llvm::ConstantInt* mvm::jit::constantLongOne;
+llvm::ConstantInt* mvm::jit::constantMinInt;
+llvm::ConstantInt* mvm::jit::constantMaxInt;
+llvm::ConstantInt* mvm::jit::constantMinLong;
+llvm::ConstantInt* mvm::jit::constantMaxLong;
+llvm::ConstantFP*  mvm::jit::constantFloatZero;
+llvm::ConstantFP*  mvm::jit::constantFloatOne;
+llvm::ConstantFP*  mvm::jit::constantFloatTwo;
+llvm::ConstantFP*  mvm::jit::constantDoubleZero;
+llvm::ConstantFP*  mvm::jit::constantDoubleOne;
+llvm::ConstantFP*  mvm::jit::constantMaxIntFloat;
+llvm::ConstantFP*  mvm::jit::constantMinIntFloat;
+llvm::ConstantFP*  mvm::jit::constantMinLongFloat;
+llvm::ConstantFP*  mvm::jit::constantMinLongDouble;
+llvm::ConstantFP*  mvm::jit::constantMaxLongFloat;
+llvm::ConstantFP*  mvm::jit::constantMaxIntDouble;
+llvm::ConstantFP*  mvm::jit::constantMinIntDouble;
+llvm::ConstantFP*  mvm::jit::constantMaxLongDouble;
+llvm::ConstantFP*  mvm::jit::constantDoubleInfinity;
+llvm::ConstantFP*  mvm::jit::constantDoubleMinusInfinity;
+llvm::ConstantFP*  mvm::jit::constantFloatInfinity;
+llvm::ConstantFP*  mvm::jit::constantFloatMinusInfinity;
+llvm::ConstantFP*  mvm::jit::constantFloatMinusZero;
+llvm::ConstantFP*  mvm::jit::constantDoubleMinusZero;
+llvm::Constant*    mvm::jit::constantPtrNull;
+llvm::ConstantInt* mvm::jit::constantPtrSize;
+const llvm::PointerType* mvm::jit::ptrType;
+const llvm::PointerType* mvm::jit::ptr32Type;
+const llvm::PointerType* mvm::jit::ptrPtrType;
+const llvm::Type* mvm::jit::arrayPtrType;
+
+llvm::Module *mvm::jit::globalModule;
+llvm::ExistingModuleProvider *mvm::jit::globalModuleProvider;
+mvm::MvmMemoryManager *mvm::jit::memoryManager;
+
+
+uint8  (*mvm::jit::llvm_atomic_cmp_swap_i8)  (uint8* ptr, uint8 cmp,
+                                              uint8 val);
+uint16 (*mvm::jit::llvm_atomic_cmp_swap_i16) (uint16* ptr, uint16 cmp,
+                                              uint16 val);
+uint32 (*mvm::jit::llvm_atomic_cmp_swap_i32) (uint32* ptr, uint32 cmp,
+                                              uint32 val);
+uint64 (*mvm::jit::llvm_atomic_cmp_swap_i64) (uint64* ptr, uint64 cmp,
+                                              uint64 val);
+
+
+uint64 mvm::jit::getTypeSize(const llvm::Type* type) {
+  return executionEngine->getTargetData()->getABITypeSize(type);
+}
+
+void mvm::jit::runPasses(llvm::Function* func,  llvm::FunctionPassManager* pm) {
+  pm->run(*func);
+}
+
+#if defined(__MACH__) && !defined(__i386__)
+#define FRAME_IP(fp) (fp[2])
+#else
+#define FRAME_IP(fp) (fp[1])
+#endif
+
+int mvm::jit::getBacktrace(void** stack, int size) {
+  void** blah = (void**)__builtin_frame_address(1);
+  int cpt = 0;
+  void* baseSP = mvm::Thread::get()->baseSP;
+  while (blah && cpt < size && blah < baseSP) {
+    stack[cpt++] = (void**)FRAME_IP(blah);
+    blah = (void**)blah[0];
+  }
+  return cpt;
+}
+
+LockNormal lock;
+std::map<void*, Code*> pointerMap;
+
+Code* mvm::jit::getCodeFromPointer(void* Addr) {
+  lock.lock();
+  std::map<void*, Code*>::iterator I =
+    pointerMap.lower_bound(Addr);
+  
+  lock.unlock();
+  if (I != pointerMap.end()) {
+    Code* m = I->second;
+    if (Addr >= m->FunctionStart) return m;
+  }
+
+  return 0;
+}
+
+void mvm::jit::addMethodInfo(void* Addr, Code* C) {
+  lock.lock();
+  pointerMap.insert(std::make_pair(Addr, C));
+  lock.unlock();
+}

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Makefile (added)
+++ vmkit/trunk/lib/Mvm/Runtime/Makefile Mon Aug 11 02:20:00 2008
@@ -0,0 +1,16 @@
+##===- lib/Mvm/Runtime/Makefile ----------------------------*- Makefile -*-===##
+# 
+#                     The vmkit project
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+# 
+##===----------------------------------------------------------------------===##
+LEVEL = ../../..
+
+include $(LEVEL)/Makefile.config
+
+LIBRARYNAME = Mvm
+include $(LEVEL)/Makefile.common
+
+CXX.Flags += -I../LLVMRuntime

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/MvmMemoryManager.cpp (added)
+++ vmkit/trunk/lib/Mvm/Runtime/MvmMemoryManager.cpp Mon Aug 11 02:20:00 2008
@@ -0,0 +1,78 @@
+//===----- MvmMemoryManager.cpp - LLVM Memory manager for Mvm -------------===//
+//
+//                              Mvm
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <assert.h>
+
+#include "mvm/JIT.h"
+#include "mvm/Method.h"
+#include "mvm/Object.h"
+
+#include "mvm/MvmMemoryManager.h"
+
+using namespace mvm;
+using namespace llvm;
+
+unsigned char* MvmMemoryManager::startFunctionBody(const Function* F, 
+                                                   uintptr_t &ActualSize) {
+  Code* meth = new Code(); 
+  currentMethod = meth;
+  return realMemoryManager->startFunctionBody(F, ActualSize); 
+}
+
+unsigned char *MvmMemoryManager::allocateStub(const GlobalValue* GV,
+                                              unsigned StubSize, 
+                                              unsigned Alignment) {
+  unsigned char* res = realMemoryManager->allocateStub(GV, StubSize, Alignment); 
+  Code* meth = new Code();
+  mvm::jit::addMethodInfo((void*)(res + StubSize), meth);
+  currentMethod = meth;
+  meth->FunctionStart = res;
+  meth->FunctionEnd = res + StubSize;
+  currentMethod = meth;
+
+  return res;
+}
+
+void MvmMemoryManager::endFunctionBody(const Function *F, 
+                                       unsigned char *FunctionStart,
+                                       unsigned char *FunctionEnd) {
+  mvm::jit::addMethodInfo((void*)FunctionEnd, currentMethod);
+  currentMethod->FunctionStart = FunctionStart;
+  currentMethod->FunctionEnd = FunctionEnd;
+  realMemoryManager->endFunctionBody(F, FunctionStart, FunctionEnd);
+}
+
+
+void MvmMemoryManager::deallocateMemForFunction(const Function *F) {
+  realMemoryManager->deallocateMemForFunction(F);
+}
+
+void MvmMemoryManager::AllocateGOT() {
+  realMemoryManager->AllocateGOT();
+}
+
+unsigned char *MvmMemoryManager::getGOTBase() const {
+  return realMemoryManager->getGOTBase();
+}
+
+unsigned char *MvmMemoryManager::startExceptionTable(const Function* F, 
+                                                     uintptr_t &ActualSize) {
+  unsigned char* res = realMemoryManager->startExceptionTable(F, ActualSize);
+  
+  currentMethod->exceptionTable = res;
+  return (unsigned char*)res;
+}                                                     
+
+void MvmMemoryManager::endExceptionTable(const Function *F, 
+                                         unsigned char *TableStart,
+                                         unsigned char *TableEnd,
+                                         unsigned char* FrameRegister) {
+  realMemoryManager->endExceptionTable(F, TableStart, TableEnd, FrameRegister);
+  currentMethod->frameRegister = FrameRegister;
+}

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (added)
+++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Mon Aug 11 02:20:00 2008
@@ -0,0 +1,116 @@
+//===--------- Object.cc - Common objects for vmlets ----------------------===//
+//
+//                     The Micro Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdlib.h>
+
+#include "MvmGC.h"
+#include "mvm/Method.h"
+#include "mvm/Object.h"
+#include "mvm/PrintBuffer.h"
+#include "mvm/Threads/Key.h"
+#include "mvm/Threads/Thread.h"
+
+using namespace mvm;
+
+
+VirtualTable *NativeString::VT = 0;
+VirtualTable *PrintBuffer::VT = 0;
+
+mvm::Key<mvm::Thread>* mvm::Thread::threadKey = 0;
+
+
+void Object::initialise() {
+# define INIT(X) { \
+  X fake; \
+  X::VT = ((void**)(void*)(&fake))[0]; }
+  
+  INIT(NativeString);
+  INIT(PrintBuffer);
+  
+#undef INIT
+}
+
+void PrintBuffer::TRACER {
+  ((PrintBuffer *)this)->contents()->MARK_AND_TRACE;
+}
+
+
+PrintBuffer *PrintBuffer::writeObj(const Object *obj) {
+#ifdef MULTIPLE_GC
+  Object *beg = (Object*)mvm::Thread::get()->GC->begOf(obj);
+#else
+  Object *beg = (Object*)Collector::begOf(obj);
+#endif
+  
+  if(beg) {
+    if(beg == obj) {
+      obj->print((mvm::PrintBuffer*)this);
+    } else {
+      write("<In Object [");
+      beg->print(this);
+      write("] -- offset ");
+      writeS4((intptr_t)obj - (intptr_t)beg);
+      write(">");
+    }
+  } else {
+    write("<DirectValue: ");
+    writeS4((intptr_t)obj);
+    write(">");
+  }
+  return this;
+}
+
+extern "C" void write_ptr(PrintBuffer* buf, void* obj) {
+  buf->writePtr(obj);
+}
+
+extern "C" void write_int(PrintBuffer* buf, int a) {
+  buf->writeS4(a);
+}
+
+extern "C" void write_str(PrintBuffer* buf, char* a) {
+  buf->write(a);
+}
+
+char *Object::printString(void) const {
+  PrintBuffer *buf= PrintBuffer::alloc();
+  buf->writeObj(this);
+  return buf->contents()->cString();
+}
+
+void Object::print(PrintBuffer *buf) const {
+  buf->write("<Object@");
+  buf->writePtr((void*)this);
+  buf->write(">");
+}
+
+void NativeString::print(PrintBuffer *buf) const {
+  NativeString *const self= (NativeString *)this;
+  buf->write("\"");
+  for (size_t i= 0; i < strlen(self->cString()); ++i) {
+    int c= self->cString()[i];
+    switch (c) {
+      case '\b': buf->write("\\b"); break;
+      case '\f': buf->write("\\f"); break;
+      case '\n': buf->write("\\n"); break;
+      case '\r': buf->write("\\r"); break;
+      case '\t': buf->write("\\t"); break;
+      case '"':  buf->write("\\\""); break;
+      default: {
+        char esc[32];
+        if (c < 32)
+          sprintf(esc, "\\x%02x", c);
+        else
+          sprintf(esc, "%c", c);
+        buf->write(esc);
+      }
+    }
+  }
+  buf->write("\"");
+}

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

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp (added)
+++ vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp Mon Aug 11 02:20:00 2008
@@ -0,0 +1,68 @@
+//===----------- Sigsegv.cc - Sigsegv default handling --------------------===//
+//
+//                     The Micro Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "MvmGC.h"
+#include "mvm/Sigsegv.h"
+#include "mvm/Threads/Thread.h"
+
+#include <signal.h>
+#include <stdio.h>
+
+using namespace mvm;
+
+void (*client_sigsegv_handler)(int, void *) = 0;
+
+#if defined(__MACH__) && defined(__i386__)
+#include "ucontext.h"
+#endif
+
+void sigsegv_handler(int n, siginfo_t *_info, void *context) {
+  void *addr = _info->si_addr;
+#if defined(__i386__)
+  struct frame {
+    struct frame *caller;
+    void         *ip;
+  };
+  
+  /* my frame */
+  struct frame *fp;
+  /* get it */
+  asm ("mov %%ebp, %0" : "=&r"(fp));
+  /* my caller */
+  struct frame *caller = fp->caller; 
+  /* preserve my caller if I return from the handler */
+  void *caller_ip = caller->ip; 
+
+#if defined(__MACH__)
+  //.gregs[REG_EIP]; /* just like it's on the stack.. */
+  caller->ip = (void *)((ucontext_t*)context)->uc_mcontext->__ss.__eip;
+#else
+  /* just like it's on the stack... */
+  caller->ip = (void *)((ucontext_t*)context)->uc_mcontext.gregs[REG_EIP]; 
+#endif
+#endif
+	
+  /* Free the GC if it sisgegv'd. No other collection is possible */
+#ifndef MULTIPLE_GC
+  Collector::die_if_sigsegv_occured_during_collection(addr);
+#else
+  mvm::Thread::get()->GC->die_if_sigsegv_occured_during_collection(addr);
+#endif
+	
+  //	sys_exit(0);
+  if(client_sigsegv_handler)
+    client_sigsegv_handler(n, addr);
+  else
+    signal(SIGSEGV, SIG_DFL);
+	
+#if defined(__i386__)
+  caller->ip = caller_ip; /* restore the caller ip */
+#endif
+}

Removed: vmkit/trunk/lib/Mvm/Sigsegv.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Sigsegv.cpp?rev=54632&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/Sigsegv.cpp (original)
+++ vmkit/trunk/lib/Mvm/Sigsegv.cpp (removed)
@@ -1,68 +0,0 @@
-//===----------- Sigsegv.cc - Sigsegv default handling --------------------===//
-//
-//                     The Micro Virtual Machine
-//
-// This file is distributed under the University of Illinois Open Source 
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-
-#include "MvmGC.h"
-#include "mvm/Sigsegv.h"
-#include "mvm/Threads/Thread.h"
-
-#include <signal.h>
-#include <stdio.h>
-
-using namespace mvm;
-
-void (*client_sigsegv_handler)(int, void *) = 0;
-
-#if defined(__MACH__) && defined(__i386__)
-#include "ucontext.h"
-#endif
-
-void sigsegv_handler(int n, siginfo_t *_info, void *context) {
-  void *addr = _info->si_addr;
-#if defined(__i386__)
-  struct frame {
-    struct frame *caller;
-    void         *ip;
-  };
-  
-  /* my frame */
-  struct frame *fp;
-  /* get it */
-  asm ("mov %%ebp, %0" : "=&r"(fp));
-  /* my caller */
-  struct frame *caller = fp->caller; 
-  /* preserve my caller if I return from the handler */
-  void *caller_ip = caller->ip; 
-
-#if defined(__MACH__)
-  //.gregs[REG_EIP]; /* just like it's on the stack.. */
-  caller->ip = (void *)((ucontext_t*)context)->uc_mcontext->__ss.__eip;
-#else
-  /* just like it's on the stack... */
-  caller->ip = (void *)((ucontext_t*)context)->uc_mcontext.gregs[REG_EIP]; 
-#endif
-#endif
-	
-  /* Free the GC if it sisgegv'd. No other collection is possible */
-#ifndef MULTIPLE_GC
-  Collector::die_if_sigsegv_occured_during_collection(addr);
-#else
-  mvm::Thread::get()->GC->die_if_sigsegv_occured_during_collection(addr);
-#endif
-	
-  //	sys_exit(0);
-  if(client_sigsegv_handler)
-    client_sigsegv_handler(n, addr);
-  else
-    signal(SIGSEGV, SIG_DFL);
-	
-#if defined(__i386__)
-  caller->ip = caller_ip; /* restore the caller ip */
-#endif
-}





More information about the vmkit-commits mailing list