[vmkit-commits] [vmkit] r81645 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h lib/JnJVM/Compiler/GCInfoPass.cpp lib/JnJVM/Compiler/JITInfo.cpp lib/JnJVM/Compiler/JnjvmModule.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sat Sep 12 15:45:25 PDT 2009


Author: geoffray
Date: Sat Sep 12 17:45:24 2009
New Revision: 81645

URL: http://llvm.org/viewvc/llvm-project?rev=81645&view=rev
Log:
Set the GC for JIT-generated functions and get back the frame layout
from LLVM during a compilation pass.


Added:
    vmkit/trunk/lib/JnJVM/Compiler/GCInfoPass.cpp
Modified:
    vmkit/trunk/include/jnjvm/JnjvmModule.h
    vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp

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

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Sat Sep 12 17:45:24 2009
@@ -26,6 +26,7 @@
   class FunctionPassManager;
   class FunctionType;
   class GlobalVariable;
+  class GCFunctionInfo;
   class Module;
   class Type;
   class Value;
@@ -110,15 +111,17 @@
   
   
 public:
+  llvm::GCFunctionInfo* GCInfo;
   llvm::Function* getMethod();
   llvm::Constant* getOffset();
   const llvm::FunctionType* getFunctionType();
     
   LLVMMethodInfo(JavaMethod* M) :  methodDef(M), methodFunction(0),
-    offsetConstant(0), functionType(0) {}
+    offsetConstant(0), functionType(0), GCInfo(0) {}
  
 
   virtual void clear() {
+    GCInfo = 0;
     methodFunction = 0;
     offsetConstant = 0;
     functionType = 0;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/GCInfoPass.cpp (added)
+++ vmkit/trunk/lib/JnJVM/Compiler/GCInfoPass.cpp Sat Sep 12 17:45:24 2009
@@ -0,0 +1,57 @@
+//===---- GCInfoPass.cpp - Get GC info for JIT-generated functions --------===//
+//
+//                     The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "llvm/Function.h"
+#include "llvm/Pass.h"
+#include "llvm/CodeGen/GCMetadata.h"
+#include "llvm/Support/Compiler.h"
+
+#include "jnjvm/JnjvmModule.h"
+
+using namespace jnjvm;
+using namespace llvm;
+
+namespace {
+  class VISIBILITY_HIDDEN GCInfoPass : public FunctionPass {
+  public:
+    static char ID;
+    JavaLLVMCompiler* Comp;
+    GCInfoPass(JavaLLVMCompiler* C) : FunctionPass(&ID) {
+      Comp = C;
+    }
+
+    void getAnalysisUsage(AnalysisUsage &AU) const {
+      FunctionPass::getAnalysisUsage(AU);      
+      AU.setPreservesAll();
+      AU.addRequired<GCModuleInfo>();
+    }
+
+    bool runOnFunction(Function &F) {
+      // Quick exit for functions that do not use GC.
+      assert(F.hasGC() && "Function without GC");
+      GCFunctionInfo &FI = getAnalysis<GCModuleInfo>().getFunctionInfo(F);
+      JavaMethod* meth = Comp->getJavaMethod(&F);
+      assert(meth && "Function without a Java method");
+      
+      LLVMMethodInfo* LMI = Comp->getMethodInfo(meth);
+      LMI->GCInfo = &FI;
+      return false;
+    }
+  };
+}
+
+char GCInfoPass::ID = 0;
+
+namespace jnjvm {
+  FunctionPass* createGCInfo(JavaLLVMCompiler* C) {
+    return new GCInfoPass(C);
+  }
+}
+

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Sat Sep 12 17:45:24 2009
@@ -169,6 +169,11 @@
                                         "", Mod->getLLVMModule());
 
     }
+    
+    if (Mod->useCooperativeGC()) {
+      methodFunction->setGC("vmkit");
+    }
+    
     Mod->functions.insert(std::make_pair(methodFunction, methodDef));
   }
   return methodFunction;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Sat Sep 12 17:45:24 2009
@@ -67,7 +67,7 @@
   JavaIntrinsics(TheModule) {
 
   enabledException = true;
-  cooperativeGC = false;
+  cooperativeGC = true;
 }
   
 void JavaLLVMCompiler::resolveVirtualClass(Class* cl) {
@@ -377,6 +377,7 @@
 
 namespace jnjvm {
   llvm::FunctionPass* createLowerConstantCallsPass(JnjvmModule* M);
+  llvm::FunctionPass* createGCInfo(JavaLLVMCompiler* Comp);
 }
 
 void JavaLLVMCompiler::addJavaPasses() {
@@ -385,12 +386,16 @@
   // Lower constant calls to lower things like getClass used
   // on synchronized methods.
   JavaNativeFunctionPasses->add(createLowerConstantCallsPass(getIntrinsics()));
+  JavaNativeFunctionPasses->add(createGCInfo(this));
   
   JavaFunctionPasses = new FunctionPassManager(TheModuleProvider);
   JavaFunctionPasses->add(new TargetData(TheModule));
   if (cooperativeGC)
     JavaFunctionPasses->add(mvm::createLoopSafePointsPass());
 
-  JavaFunctionPasses->add(mvm::createEscapeAnalysisPass());
+  // Re-enable this when the pointers in stack-allocated objects can
+  // be given to the GC.
+  //JavaFunctionPasses->add(mvm::createEscapeAnalysisPass());
   JavaFunctionPasses->add(createLowerConstantCallsPass(getIntrinsics()));
+  JavaFunctionPasses->add(createGCInfo(this));
 }





More information about the vmkit-commits mailing list