[vmkit-commits] [vmkit] r135863 - in /vmkit/trunk: ./ lib/J3/Classpath/ lib/J3/Compiler/ lib/J3/Compiler/AOT/ lib/J3/VMCore/ lib/Mvm/StaticGCPass/ mmtk/mmtk-alloc/ mmtk/mmtk-j3/ tools/ tools/j3/ tools/precompiler/ tools/precompiler/trainer/

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sat Jul 23 14:54:55 PDT 2011


Author: geoffray
Date: Sat Jul 23 16:54:55 2011
New Revision: 135863

URL: http://llvm.org/viewvc/llvm-project?rev=135863&view=rev
Log:
Include precompiled Java code in final j3 executable.


Added:
    vmkit/trunk/lib/J3/Compiler/AOT/
    vmkit/trunk/lib/J3/Compiler/AOT/Makefile
    vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp
Modified:
    vmkit/trunk/Makefile
    vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h
    vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
    vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
    vmkit/trunk/lib/J3/Compiler/Makefile
    vmkit/trunk/lib/J3/VMCore/JavaClass.h
    vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp
    vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h
    vmkit/trunk/lib/J3/VMCore/Precompiled.cpp
    vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp
    vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp
    vmkit/trunk/mmtk/mmtk-j3/Memory.cpp
    vmkit/trunk/tools/Makefile
    vmkit/trunk/tools/j3/Makefile
    vmkit/trunk/tools/precompiler/Makefile
    vmkit/trunk/tools/precompiler/trainer/Makefile

Modified: vmkit/trunk/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/Makefile (original)
+++ vmkit/trunk/Makefile Sat Jul 23 16:54:55 2011
@@ -13,7 +13,7 @@
 
 # Top-Level vmkit Build Stages:
 #
-DIRS := lib/Mvm/StaticGCPass lib tools/vmjc mmtk tools
+DIRS := lib/Mvm/StaticGCPass lib tools/vmjc mmtk tools/precompiler tools
 
 EXTRA_DIST=include
 

Modified: vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h (original)
+++ vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h Sat Jul 23 16:54:55 2011
@@ -56,8 +56,11 @@
 class Jnjvm;
 class JavaField;
 class JavaMethod;
+class JavaObject;
+class JavaThread;
 class Class;
 class ClassArray;
+class JnjvmClassLoader;
 
 class Classpath : public mvm::PermanentObject {
 public: 

Added: vmkit/trunk/lib/J3/Compiler/AOT/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/AOT/Makefile?rev=135863&view=auto
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/AOT/Makefile (added)
+++ vmkit/trunk/lib/J3/Compiler/AOT/Makefile Sat Jul 23 16:54:55 2011
@@ -0,0 +1,15 @@
+##===- lib/J3/Compiler/AOT/Makefile ------------------------*- Makefile -*-===##
+#
+#                            The VMKit project
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../../..
+LIBRARYNAME = StaticJ3GC
+LOADABLE_MODULE = 1
+
+include $(LEVEL)/Makefile.common
+

Added: vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp?rev=135863&view=auto
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp (added)
+++ vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp Sat Jul 23 16:54:55 2011
@@ -0,0 +1,155 @@
+//===----- StaticJ3GC.cpp - Support for Ahead of Time Compiler GC -------===//
+//
+//                            The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/GCs.h"
+#include "llvm/CodeGen/GCStrategy.h"
+#include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/CodeGen/GCMetadataPrinter.h"
+#include "llvm/Module.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/Target/Mangler.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormattedStream.h"
+#include <cctype>
+
+using namespace llvm;
+
+namespace {
+  class StaticJ3GC : public GCStrategy {
+  public:
+    StaticJ3GC();
+  };
+}
+
+static GCRegistry::Add<StaticJ3GC>
+X("java_aot", "Java GC for AOT-generated functions");
+
+StaticJ3GC::StaticJ3GC() {
+  NeededSafePoints = 1 << GC::PostCall;
+  UsesMetadata = true;
+}
+
+namespace {
+
+  class StaticJ3GCMetadataPrinter : public GCMetadataPrinter {
+  public:
+    void beginAssembly(AsmPrinter &AP);
+    void finishAssembly(AsmPrinter &AP);
+  };
+
+}
+
+static GCMetadataPrinterRegistry::Add<StaticJ3GCMetadataPrinter>
+Y("java_aot", "Java GC for AOT-generated functions");
+
+void StaticJ3GCMetadataPrinter::beginAssembly(AsmPrinter &AP) {
+}
+
+/// emitAssembly - Print the frametable. The ocaml frametable format is thus:
+///
+///   extern "C" struct align(sizeof(intptr_t)) {
+///     void *FunctionAddress;
+///     uint16_t NumDescriptors;
+///     struct align(sizeof(intptr_t)) {
+///       void *ReturnAddress;
+///       uint16_t BytecodeIndex; 
+///       uint16_t FrameSize;
+///       uint16_t NumLiveOffsets;
+///       uint16_t LiveOffsets[NumLiveOffsets];
+///     } Descriptors[NumDescriptors];
+///   } ${method}__frame;
+///
+/// Note that this precludes programs from stack frames larger than 64K
+/// (FrameSize and LiveOffsets would overflow). FrameTablePrinter will abort if
+/// either condition is detected in a function which uses the GC.
+///
+void StaticJ3GCMetadataPrinter::finishAssembly(AsmPrinter &AP) {
+  unsigned IntPtrSize = AP.TM.getTargetData()->getPointerSize();
+
+  AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection());
+
+
+  for (iterator I = begin(), IE = end(); I != IE; ++I) {
+    GCFunctionInfo &FI = **I;
+
+    // Emit the frame symbol
+    MCSymbol *Sym = AP.OutContext.GetOrCreateSymbol(FI.getFunction().getName() + "_frame");
+    AP.OutStreamer.EmitSymbolAttribute(Sym, MCSA_Global);
+    AP.OutStreamer.EmitLabel(Sym);
+
+    // Emit the method symbol
+    MCSymbol *FunctionSym = AP.Mang->getSymbol(&FI.getFunction());
+    AP.OutStreamer.EmitSymbolValue(FunctionSym, IntPtrSize, 0);
+  
+    int NumDescriptors = 0;
+    for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) {
+        NumDescriptors++;
+    }
+    if (NumDescriptors >= 1<<16) {
+      // Very rude!
+      report_fatal_error(" Too much descriptor for J3 AOT GC");
+    }
+    AP.EmitInt16(NumDescriptors);
+    AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
+
+    uint64_t FrameSize = FI.getFrameSize();
+    if (FrameSize >= 1<<16) {
+      // Very rude!
+      report_fatal_error("Function '" + FI.getFunction().getName() +
+                         "' is too large for the J3 AOT GC! "
+                         "Frame size " + Twine(FrameSize) + ">= 65536.\n"
+                         "(" + Twine(uintptr_t(&FI)) + ")");
+    }
+
+    AP.OutStreamer.AddComment("live roots for " +
+                              Twine(FI.getFunction().getName()));
+    AP.OutStreamer.AddBlankLine();
+
+    for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) {
+      size_t LiveCount = FI.live_size(J);
+      if (LiveCount >= 1<<16) {
+        // Very rude!
+        report_fatal_error("Function '" + FI.getFunction().getName() +
+                           "' is too large for the ocaml GC! "
+                           "Live root count "+Twine(LiveCount)+" >= 65536.");
+      }
+
+      DebugLoc DL = J->Loc;
+      uint32_t bytecodeIndex = DL.getLine();
+      uint32_t second = DL.getCol();
+      assert(second == 0 && "Wrong column number");
+
+      AP.OutStreamer.EmitSymbolValue(J->Label, IntPtrSize, 0);
+      AP.EmitInt16(bytecodeIndex);
+      AP.EmitInt16(FrameSize);
+      AP.EmitInt16(LiveCount);
+
+      for (GCFunctionInfo::live_iterator K = FI.live_begin(J),
+                                         KE = FI.live_end(J); K != KE; ++K) {
+        if (K->StackOffset >= 1<<16) {
+          // Very rude!
+          report_fatal_error(
+                 "GC root stack offset is outside of fixed stack frame and out "
+                 "of range for ocaml GC!");
+        }
+        AP.EmitInt16(K->StackOffset);
+      }
+
+      AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
+    }
+  }
+}

Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sat Jul 23 16:54:55 2011
@@ -1022,8 +1022,7 @@
   MethodElts.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), method.canBeInlined));
 
   // code
-  if (isAbstract(method.access)
-      || (precompile && getMethodInfo(&method)->getMethod()->hasExternalWeakLinkage())) {
+  if (method.code == NULL) {
     MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType));
   } else {
     Function* func = getMethod(&method);
@@ -1032,7 +1031,15 @@
   }
   
   // codeInfo
-  MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.CodeLineInfoType));
+  if (useCooperativeGC() && method.code != NULL) {
+    Twine name = getMethodInfo(&method)->getMethod()->getName() + "_frame";
+    GlobalVariable* frame = new GlobalVariable(
+        Mod, JavaIntrinsics.CodeLineInfoType->getContainedType(0), false,
+        GlobalValue::ExternalLinkage, NULL, name);
+    MethodElts.push_back(frame);
+  } else {
+    MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.CodeLineInfoType));
+  }
   
   // codeInfoLength
   MethodElts.push_back(ConstantInt::get(Type::getInt16Ty(getLLVMContext()), 0));
@@ -1106,11 +1113,10 @@
   StructType* TCMTy = dyn_cast<StructType>(ATy->getContainedType(0));
   assert(TCMTy && "Malformed type");
 
-  uint32 status = cl->needsInitialisationCheck() ? vmjc : ready;
   TempElts.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()),
-                                      status));
+                                      cl->getInitializationState()));
   TempElts.push_back(ConstantInt::get(Type::getInt1Ty(getLLVMContext()),
-                                      status == ready ? 1 : 0));
+                                      cl->isReady() ? 1 : 0));
   TempElts.push_back(getStaticInstance(cl));
   Constant* CStr[1] = { ConstantStruct::get(TCMTy, TempElts) };
   TempElts.clear();
@@ -2190,6 +2196,25 @@
   precompile = true;
   addJavaPasses();
 
+  // Make sure that the native classes are emitted.
+  getNativeClass(loader->upcalls->OfVoid);
+  getNativeClass(loader->upcalls->OfBool);
+  getNativeClass(loader->upcalls->OfByte);
+  getNativeClass(loader->upcalls->OfChar);
+  getNativeClass(loader->upcalls->OfShort);
+  getNativeClass(loader->upcalls->OfInt);
+  getNativeClass(loader->upcalls->OfFloat);
+  getNativeClass(loader->upcalls->OfLong);
+  getNativeClass(loader->upcalls->OfDouble);
+
+  // First set classes that have been more than resolved to resolved.
+  for (ClassMap::iterator i = loader->getClasses()->map.begin(),
+       e = loader->getClasses()->map.end(); i!= e; ++i) {
+    if (i->second->isClass() && i->second->asClass()->isResolved()) {
+      i->second->asClass()->setResolved();
+    }
+  }
+
   for (ClassMap::iterator i = loader->getClasses()->map.begin(),
        e = loader->getClasses()->map.end(); i!= e; ++i) {
     getNativeClass(i->second);
@@ -2197,12 +2222,20 @@
       Class* cl = i->second->asClass();
       for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
         JavaMethod& meth = cl->virtualMethods[i];
-        if (meth.code != NULL) parseFunction(&meth);
+        if (meth.code != NULL) {
+          Function* Func = parseFunction(&meth);
+          Func->clearGC();
+          Func->setGC("java_aot");
+        }
       }
   
       for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
         JavaMethod& meth = cl->staticMethods[i];
-        if (meth.code != NULL) parseFunction(&meth);
+        if (meth.code != NULL) {
+          Function* Func = parseFunction(&meth);
+          Func->clearGC();
+          Func->setGC("java_aot");
+        }
       }
     }
   }
@@ -2211,7 +2244,11 @@
     JavaMethod* meth = toCompile.back();
     toCompile.pop_back();
     getNativeClass(meth->classDef);
-    parseFunction(meth);
+    Function* Func = parseFunction(meth);
+    Func->clearGC();
+    Func->setGC("java_aot");
+    // Also update code to notify that this function has been emitted.
+    meth->code = Func;
   }
 
   bool changed = false;

Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Sat Jul 23 16:54:55 2011
@@ -172,7 +172,7 @@
     methodFunction->setGC("vmkit");
     
     Compiler->functions.insert(std::make_pair(methodFunction, methodDef));
-    if (Compiler != JCL->getCompiler() && methodDef->code) {
+    if (!Compiler->isStaticCompiling() && methodDef->code) {
       Compiler->setMethod(methodFunction, methodDef->code, methodFunction->getName().data());
     }
   }

Modified: vmkit/trunk/lib/J3/Compiler/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/Makefile?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/Makefile (original)
+++ vmkit/trunk/lib/J3/Compiler/Makefile Sat Jul 23 16:54:55 2011
@@ -10,6 +10,7 @@
 
 include $(LEVEL)/Makefile.config
 
+DIRS = AOT
 MODULE_WITH_GC = J3Compiler
 
 include $(LEVEL)/Makefile.common

Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Sat Jul 23 16:54:55 2011
@@ -713,6 +713,7 @@
   /// setStaticInstance - Set the memory that holds static variables.
   ///
   void setStaticInstance(void* val) {
+    assert(getCurrentTaskClassMirror().staticInstance == NULL);
     getCurrentTaskClassMirror().staticInstance = val;
   }
   

Modified: vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp Sat Jul 23 16:54:55 2011
@@ -270,7 +270,14 @@
             UTF8Buffer(classDef->name).cString());
     abort();
   }
-  return (CommonClass*)ctpRes[entry];
+
+  CommonClass* res = (CommonClass*)ctpRes[entry];
+  if (res == NULL) {
+    JnjvmClassLoader* loader = classDef->classLoader;
+    const UTF8* name = UTF8At(ctpDef[entry]);
+    res = loader->lookupClassOrArray(name);
+  }
+  return res;
 }
 
 const UTF8* JavaConstantPool::resolveClassName(uint32 index) {
@@ -298,12 +305,6 @@
 
 CommonClass* JavaConstantPool::getMethodClassIfLoaded(uint32 index) {
   CommonClass* temp = isClassLoaded(index);
-  if (!temp) {
-    JnjvmClassLoader* loader = classDef->classLoader;
-    assert(loader && "Class has no loader?");
-    const UTF8* name = UTF8At(ctpDef[index]);
-    temp = loader->lookupClassOrArray(name);
-  }
 
   if (classDef->classLoader->getCompiler()->isStaticCompiling()) {
     if (temp == NULL) {

Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Sat Jul 23 16:54:55 2011
@@ -115,7 +115,6 @@
     //    now in progress by the current thread and release the lock on the
     //    Class object.
     setOwnerClass(self);
-    bool vmjced = (getInitializationState() == vmjc);
     setInitializationState(inClinit);
     UserClass* cl = (UserClass*)this;
     
@@ -162,17 +161,11 @@
     PRINT_DEBUG(JNJVM_LOAD, 0, LIGHT_GREEN, "clinit ", 0);
     PRINT_DEBUG(JNJVM_LOAD, 0, COLOR_NORMAL, "%s\n", mvm::PrintString(this).cString());
 
-
-
-    if (!vmjced) {
-      JavaField* fields = cl->getStaticFields();
-      for (uint32 i = 0; i < cl->nbStaticFields; ++i) {
-        fields[i].InitStaticField(vm);
-      }
+    JavaField* fields = cl->getStaticFields();
+    for (uint32 i = 0; i < cl->nbStaticFields; ++i) {
+      fields[i].InitStaticField(vm);
     }
   
-      
-      
     JavaMethod* meth = lookupMethodDontThrow(vm->bootstrapLoader->clinitName,
                                              vm->bootstrapLoader->clinitType,
                                              true, false, 0);
@@ -1325,25 +1318,17 @@
   VirtualMachine(Alloc, frames), lockSystem(Alloc) {
 
   classpath = getenv("CLASSPATH");
-  if (!classpath) classpath = ".";
+  if (classpath == NULL) classpath = ".";
   
-  appClassLoader = 0;
+  appClassLoader = NULL;
   jniEnv = &JNI_JNIEnvTable;
   javavmEnv = &JNI_JavaVMTable;
   
   bootstrapLoader = loader;
   upcalls = bootstrapLoader->upcalls;
-
   throwable = upcalls->newThrowable;
 
-  StringList* end = loader->strings;
-  while (end) {
-    for (uint32 i = 0; i < end->length; ++i) {
-      JavaString* obj = end->strings[i];
-      hashStr.insert(obj);
-    }
-    end = end->prev;
-  }
+  Precompiled::ReadFrames(this, this->bootstrapLoader);
 }
 
 Jnjvm::~Jnjvm() {

Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Sat Jul 23 16:54:55 2011
@@ -424,6 +424,7 @@
 class Precompiled {
  public:
   static bool Init(JnjvmBootstrapLoader* loader);
+  static void ReadFrames(Jnjvm* vm, JnjvmClassLoader* loader);
 };
 
 /// VMClassLoader - The vmdata object that will be placed in and will only

Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sat Jul 23 16:54:55 2011
@@ -44,6 +44,8 @@
   if (javaLangObject == NULL) {
     return false;
   }
+
+  ClassArray::SuperArray = javaLangObject;
     
   // Get the native classes.
   Classpath* upcalls = loader->upcalls;
@@ -75,59 +77,12 @@
   return true;
 }
 
-class JavaStaticMethodInfo : public mvm::CamlMethodInfo {
-public:
-  virtual void print(void* ip, void* addr);
-  virtual bool isHighLevelMethod() {
-    return true;
-  }
-  
-  JavaStaticMethodInfo(mvm::CamlMethodInfo* super, void* ip, JavaMethod* M) :
-    mvm::CamlMethodInfo(super->CF) {
-    MetaInfo = M;
-    Owner = M->classDef->classLoader->getCompiler();
-  }
-};
-
-void JavaStaticMethodInfo::print(void* ip, void* addr) {
-  void* new_ip = NULL;
-  if (ip) new_ip = mvm::MethodInfo::isStub(ip, addr);
-  JavaMethod* meth = (JavaMethod*)MetaInfo;
-  fprintf(stderr, "; %p in %s.%s", new_ip,
-          UTF8Buffer(meth->classDef->name).cString(),
-          UTF8Buffer(meth->name).cString());
-  if (ip != new_ip) fprintf(stderr, " (from stub)");
-  fprintf(stderr, "\n");
-}
 
 void JnjvmClassLoader::insertAllMethodsInVM(Jnjvm* vm) {
-  for (ClassMap::iterator i = classes->map.begin(), e = classes->map.end();
-       i != e; ++i) {
-    CommonClass* cl = i->second;
-    if (cl->isClass()) {
-      Class* C = cl->asClass();
-      
-      for (uint32 i = 0; i < C->nbVirtualMethods; ++i) {
-        JavaMethod& meth = C->virtualMethods[i];
-        if (!isAbstract(meth.access) && meth.code) {
-          JavaStaticMethodInfo* MI = new (allocator, "JavaStaticMethodInfo")
-            JavaStaticMethodInfo(0, meth.code, &meth);
-          vm->FunctionsCache.addMethodInfo(MI, meth.code);
-        }
-      }
-      
-      for (uint32 i = 0; i < C->nbStaticMethods; ++i) {
-        JavaMethod& meth = C->staticMethods[i];
-        if (!isAbstract(meth.access) && meth.code) {
-          JavaStaticMethodInfo* MI = new (allocator, "JavaStaticMethodInfo")
-            JavaStaticMethodInfo(0, meth.code, &meth);
-          vm->FunctionsCache.addMethodInfo(MI, meth.code);
-        }
-      }
-    }
-  }
+  UNIMPLEMENTED();
 }
 
+
 void JnjvmClassLoader::loadLibFromJar(Jnjvm* vm, const char* name,
                                       const char* file) {
 
@@ -148,6 +103,7 @@
   }
 }
 
+
 void JnjvmClassLoader::loadLibFromFile(Jnjvm* vm, const char* name) {
   mvm::ThreadAllocator threadAllocator;
   assert(classes->map.size() == 0);
@@ -165,6 +121,7 @@
   }
 }
 
+
 Class* JnjvmClassLoader::loadClassFromSelf(Jnjvm* vm, const char* name) {
   assert(classes->map.size() == 0);
   Class* cl = (Class*)dlsym(SELF_HANDLE, name);
@@ -222,6 +179,7 @@
   }
 }
 
+
 extern "C" void vmjcGetClassArray(JnjvmClassLoader* JCL, ClassArray** ptr,
                                   const UTF8* name) {
   JCL->hashUTF8->insert(name);
@@ -258,4 +216,159 @@
   abort();
 }
 
+
+class StaticJ3Frame {
+public:
+  void* ReturnAddress;
+  uint16_t BytecodeIndex;
+  uint16_t FrameSize;
+  uint16_t NumLiveOffsets;
+  int16_t LiveOffsets[1];
+};
+
+class StaticJ3Frames {
+public:
+  void* FunctionAddress;
+  uint16_t NumDescriptors;
+  StaticJ3Frame* frames() const; 
+};
+
+class StaticJ3FrameDecoder {
+public:
+  StaticJ3Frames* frames ;
+  uint32 currentDescriptor;
+  StaticJ3Frame* currentFrame;
+
+  StaticJ3FrameDecoder(StaticJ3Frames* frames) {
+    this->frames = frames;
+    currentDescriptor = 0;
+    currentFrame = frames->frames();
+  }
+
+  bool hasNext() {
+    return currentDescriptor < frames->NumDescriptors;
+  }
+
+  void advance() {
+    ++currentDescriptor;
+    if (!hasNext()) return;
+    intptr_t ptr = 
+    ptr = reinterpret_cast<intptr_t>(currentFrame)
+      + currentFrame->NumLiveOffsets * sizeof(uint16_t)
+      + sizeof(void*)       // ReturnAddress
+      + sizeof(uint16_t)    // BytecodeIndex
+      + sizeof(uint16_t)    // FrameSize
+      + sizeof(uint16_t);   // NumLiveOffsets
+    if (ptr & 2) {
+      ptr += sizeof(uint16_t);
+    }
+    currentFrame = reinterpret_cast<StaticJ3Frame*>(ptr);
+  }
+
+  StaticJ3Frame* next() {
+    assert(hasNext());
+    StaticJ3Frame* result = currentFrame;
+    advance();
+    return result;
+  }
+};
+
+StaticJ3Frame* StaticJ3Frames::frames() const {
+  intptr_t ptr = reinterpret_cast<intptr_t>(this) + sizeof(void*) + sizeof(uint16_t);
+  // If the frames structure was not 4-aligned, manually do it here.
+  if (ptr & 2) {
+    ptr += sizeof(uint16_t);
+  }
+  return reinterpret_cast<StaticJ3Frame*>(ptr);
+}
+
+class JavaStaticMethodInfo : public mvm::MethodInfo {
+private:
+  StaticJ3Frame* frame;
+public:
+  virtual void print(void* ip, void* addr);
+  virtual bool isHighLevelMethod() {
+    return true;
+  }
+
+  virtual void scan(uintptr_t closure, void* ip, void* addr) {
+    assert(frame != NULL);
+    //uintptr_t spaddr = (uintptr_t)addr + CF->FrameSize + sizeof(void*);
+    uintptr_t spaddr = ((uintptr_t*)addr)[0];
+    for (uint16 i = 0; i < frame->NumLiveOffsets; ++i) {
+      mvm::Collector::scanObject((void**)(spaddr + frame->LiveOffsets[i]), closure);
+    }
+  }
+
+  JavaStaticMethodInfo(StaticJ3Frame* F, JavaMethod* M) {
+    frame = F;
+    MetaInfo = M;
+    Owner = M->classDef->classLoader->getCompiler();
+  }
+};
+
+
+void JavaStaticMethodInfo::print(void* ip, void* addr) {
+  JavaMethod* meth = (JavaMethod*)MetaInfo;
+  CodeLineInfo* info = meth->lookupCodeLineInfo((uintptr_t)ip);
+  if (info != NULL) {
+    fprintf(stderr, "; %p (%p) in %s.%s (AOT line %d, bytecode %d, code start %p)", ip, addr,
+            UTF8Buffer(meth->classDef->name).cString(),
+            UTF8Buffer(meth->name).cString(),
+            meth->lookupLineNumber((uintptr_t)ip),
+            info->bytecodeIndex, meth->code);
+  } else {
+    fprintf(stderr, "; %p (%p) in %s.%s (native method, code start %p)", ip, addr,
+            UTF8Buffer(meth->classDef->name).cString(),
+            UTF8Buffer(meth->name).cString(), meth->code);
+  }
+  fprintf(stderr, "\n");
+}
+
+
+static void ReadFrame(Jnjvm* vm, JnjvmClassLoader* loader, JavaMethod* meth) {
+  StaticJ3Frames* frames = reinterpret_cast<StaticJ3Frames*>(meth->codeInfo);
+  StaticJ3FrameDecoder decoder(frames);
+  mvm::BumpPtrAllocator& allocator = loader->allocator;
+  meth->codeInfoLength = frames->NumDescriptors;
+  if (frames->NumDescriptors > 0) {
+    meth->codeInfo = new(allocator, "CodeLineInfo") CodeLineInfo[frames->NumDescriptors];
+  } else {
+    meth->codeInfo = NULL;
+  }
+
+  int codeInfoIndex = 0;
+  while (decoder.hasNext()) {
+    StaticJ3Frame* frame = decoder.next();
+    mvm::MethodInfo* MI = new(allocator, "JavaStaticMethodInfo") JavaStaticMethodInfo(frame, meth);
+    vm->FunctionsCache.addMethodInfo(MI, frame->ReturnAddress);
+    meth->codeInfo[codeInfoIndex].address = reinterpret_cast<uintptr_t>(frame->ReturnAddress);
+    meth->codeInfo[codeInfoIndex++].bytecodeIndex = frame->BytecodeIndex;
+  }
+}
+
+
+void Precompiled::ReadFrames(Jnjvm* vm, JnjvmClassLoader* loader) {
+  for (ClassMap::iterator i = loader->getClasses()->map.begin(),
+       e = loader->getClasses()->map.end(); i != e; ++i) {
+    CommonClass* cl = i->second;
+    if (cl->isClass()) {
+      Class* C = cl->asClass(); 
+      for (uint32 i = 0; i < C->nbVirtualMethods; ++i) {
+        JavaMethod& meth = C->virtualMethods[i];
+        if (meth.code != NULL) {
+          ReadFrame(vm, loader, &meth);
+        }
+      }
+      
+      for (uint32 i = 0; i < C->nbStaticMethods; ++i) {
+        JavaMethod& meth = C->staticMethods[i];
+        if (meth.code != NULL) {
+          ReadFrame(vm, loader, &meth);
+        }
+      }
+    }
+  }
+}
+
 }

Modified: vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp (original)
+++ vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp Sat Jul 23 16:54:55 2011
@@ -39,6 +39,10 @@
   RegisterPass<StaticGCPass> X("StaticGCPass",
                       "Add GC information in files compiled with llvm-gcc");
 
+static bool HasVmkitGC(Function* F) {
+  return !strcmp(F->getGC(), "vmkit");
+}
+
 bool StaticGCPass::runOnModule(Module& M) {
 
   Function* F = M.getFunction("__llvm_gcroot");
@@ -54,8 +58,13 @@
        E = gcrootFun->use_end(); I != E; ++I) {
     if (Instruction* II = dyn_cast<Instruction>(*I)) {
       Function* F = II->getParent()->getParent();
-      if (F->hasGC()) F->clearGC();
-      F->setGC("ocaml");
+      if (!F->hasGC()) {
+        F->setGC("ocaml");
+      } else if (HasVmkitGC(F)) {
+        F->clearGC();
+        F->setGC("ocaml");
+      }
+      assert(F->hasGC());
     }
   }
 
@@ -66,7 +75,7 @@
                       "Functions using gc_root should not have static linkage.\n",
                       I->getName().data());
     }
-    if (I->hasGC() && !strcmp(I->getGC(), "vmkit")) I->setGC("ocaml");
+    if (I->hasGC() && HasVmkitGC(I)) I->setGC("ocaml");
   }
 
   if (error) abort();

Modified: vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp (original)
+++ vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp Sat Jul 23 16:54:55 2011
@@ -164,7 +164,7 @@
 #else
   uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED;
 #endif
-  void* baseAddr = mmap((void*)0x60000000, 0x40000000, PROT_READ | PROT_WRITE,
+  void* baseAddr = mmap((void*)0x60000000, 0x30000000, PROT_READ | PROT_WRITE,
                         flags, -1, 0);
   if (baseAddr == MAP_FAILED) {
     perror("mmap");

Modified: vmkit/trunk/mmtk/mmtk-j3/Memory.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Memory.cpp?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/mmtk/mmtk-j3/Memory.cpp (original)
+++ vmkit/trunk/mmtk/mmtk-j3/Memory.cpp Sat Jul 23 16:54:55 2011
@@ -20,7 +20,7 @@
 }
 
 extern "C" uintptr_t Java_org_j3_mmtk_Memory_getHeapEndConstant__ (MMTkObject* M) {
-  return (uintptr_t)0xa0000000;
+  return (uintptr_t)0x90000000;
 }
 
 extern "C" uintptr_t Java_org_j3_mmtk_Memory_getAvailableStartConstant__ (MMTkObject* M) {
@@ -28,7 +28,7 @@
 }
 
 extern "C" uintptr_t Java_org_j3_mmtk_Memory_getAvailableEndConstant__ (MMTkObject* M) {
-  return (uintptr_t)0xa0000000;
+  return (uintptr_t)0x90000000;
 }
 
 extern "C" sint32

Modified: vmkit/trunk/tools/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/Makefile?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/tools/Makefile (original)
+++ vmkit/trunk/tools/Makefile Sat Jul 23 16:54:55 2011
@@ -10,7 +10,7 @@
 
 include $(LEVEL)/Makefile.config
 
-PARALLEL_DIRS = j3 vmjc llcj precompiler
+PARALLEL_DIRS = j3 vmjc llcj
 
 include $(LEVEL)/Makefile.common
 

Modified: vmkit/trunk/tools/j3/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/j3/Makefile?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/tools/j3/Makefile (original)
+++ vmkit/trunk/tools/j3/Makefile Sat Jul 23 16:54:55 2011
@@ -11,8 +11,8 @@
 include $(LEVEL)/Makefile.config
 
 TOOLNAME = j3
-USEDLIBS = Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a CommonThread.a FinalMMTk.a InlineMMTk.a
+USEDLIBS = Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a CommonThread.a FinalMMTk.a InlineMMTk.a Precompiled.a
 BUILD_FRAMETABLE = 1
-LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo asmparser linker
+LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo
 
 include $(LEVEL)/Makefile.common

Modified: vmkit/trunk/tools/precompiler/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Makefile?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/tools/precompiler/Makefile (original)
+++ vmkit/trunk/tools/precompiler/Makefile Sat Jul 23 16:54:55 2011
@@ -10,6 +10,7 @@
 
 include $(LEVEL)/Makefile.config
 
+DIRS = trainer
 TOOLNAME = precompiler
 USEDLIBS = Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a CommonThread.a FinalMMTk.a InlineMMTk.a
 BUILD_FRAMETABLE = 1

Modified: vmkit/trunk/tools/precompiler/trainer/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=135863&r1=135862&r2=135863&view=diff
==============================================================================
--- vmkit/trunk/tools/precompiler/trainer/Makefile (original)
+++ vmkit/trunk/tools/precompiler/trainer/Makefile Sat Jul 23 16:54:55 2011
@@ -18,7 +18,16 @@
 
 PRECOMPILER := $(ToolDir)/precompiler$(EXEEXT)
 
-generated.bc: $(PRECOMPILER) HelloWorld.java
+generated.bc: $(PRECOMPILER) HelloWorld.java $(LibDir)/StaticJ3GC$(SHLIBEXT) $(LibDir)/StaticGCPass$(SHLIBEXT)
 	$(Echo) "Building precompiled bootstrap code"
 	$(Verb) javac HelloWorld.java
 	$(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld
+	$(Verb) $(MKDIR) $(ObjDir)
+	$(Verb) $(LOPT) generated.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -StaticGCPass -o $(LibDir)/Precompiled.bc
+	$(Verb) $(LLC) -O0 -fast-isel=false -load=$(LibDir)/StaticJ3GC$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s
+	$(Verb) $(Compile.C) $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o
+	$(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o
+	$(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a
+
+clean-local::
+	$(Verb) $(RM) -f HelloWorld.class generated.bc





More information about the vmkit-commits mailing list