[vmkit-commits] [vmkit] r138857 - in /vmkit/trunk: include/j3/LLVMInfo.h include/mvm/Threads/ObjectLocks.h include/mvm/Threads/Thread.h lib/J3/Classpath/ClasspathVMRuntime.inc lib/J3/Compiler/JavaJIT.cpp lib/J3/Compiler/LLVMInfo.cpp lib/J3/VMCore/JavaRuntimeJIT.cpp lib/Mvm/CommonThread/ctthread.cpp tools/precompiler/trainer/Makefile

Nicolas Geoffray nicolas.geoffray at lip6.fr
Wed Aug 31 09:36:59 PDT 2011


Author: geoffray
Date: Wed Aug 31 11:36:59 2011
New Revision: 138857

URL: http://llvm.org/viewvc/llvm-project?rev=138857&view=rev
Log:
Few fixes to get vmkit compile and run (without GC) on x64.


Modified:
    vmkit/trunk/include/j3/LLVMInfo.h
    vmkit/trunk/include/mvm/Threads/ObjectLocks.h
    vmkit/trunk/include/mvm/Threads/Thread.h
    vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc
    vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
    vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
    vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
    vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
    vmkit/trunk/tools/precompiler/trainer/Makefile

Modified: vmkit/trunk/include/j3/LLVMInfo.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/LLVMInfo.h?rev=138857&r1=138856&r2=138857&view=diff
==============================================================================
--- vmkit/trunk/include/j3/LLVMInfo.h (original)
+++ vmkit/trunk/include/j3/LLVMInfo.h Wed Aug 31 11:36:59 2011
@@ -168,6 +168,7 @@
   llvm::FunctionType* getVirtualType();
   llvm::FunctionType* getStaticType();
   llvm::FunctionType* getNativeType();
+  llvm::FunctionType* getNativeStubType();
 
   llvm::FunctionType* getVirtualBufType();
   llvm::FunctionType* getStaticBufType();

Modified: vmkit/trunk/include/mvm/Threads/ObjectLocks.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/ObjectLocks.h?rev=138857&r1=138856&r2=138857&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Threads/ObjectLocks.h (original)
+++ vmkit/trunk/include/mvm/Threads/ObjectLocks.h Wed Aug 31 11:36:59 2011
@@ -161,7 +161,7 @@
   //    1           11                    12                  8
   // fat lock    thread id       thin lock count + hash     GC bits
 
-  static const uint64_t FatMask = 1 << ((sizeof(size_t) << 3) - 1);
+  static const uint64_t FatMask = 1 << 31;
 
   static const uint32_t NonLockBits = HashBits + GCBits;
   static const uint64_t NonLockBitsMask = ((1 << NonLockBits) - 1);

Modified: vmkit/trunk/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=138857&r1=138856&r2=138857&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Wed Aug 31 11:36:59 2011
@@ -253,7 +253,7 @@
 
   /// IDMask - Apply this mask to the stack pointer to get the Thread object.
   ///
-#if (__WORDSIZE == 64)
+#if 0//(__WORDSIZE == 64)
   static const uint64_t IDMask = 0xF7FF00000;
 #else
   static const uint64_t IDMask = 0x7FF00000;

Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc?rev=138857&r1=138856&r2=138857&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc (original)
+++ vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc Wed Aug 31 11:36:59 2011
@@ -81,6 +81,14 @@
 extern "C" void callOnLoad(void* res, JnjvmClassLoader* loader, Jnjvm* vm)
   __attribute__ ((noinline));
 
+extern "C" int doCall(onLoad_t func, void* res, Jnjvm* vm)
+  __attribute__ ((noinline));
+
+extern "C" int doCall(onLoad_t func, void* res, Jnjvm* vm) {
+  func(&vm->javavmEnv, res);
+  return 1;
+}
+
 // Calls the JNI_OnLoad function of a dynamic library.
 extern "C" void callOnLoad(void* res, JnjvmClassLoader* loader, Jnjvm* vm) {
 
@@ -92,7 +100,7 @@
     mvm::KnownFrame Frame;
     
     j3StartJNI(&num, &old, &Frame);
-    onLoad(&vm->javavmEnv, res);
+    doCall(onLoad, res, vm);
     j3EndJNI(&old);
   }
 }

Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=138857&r1=138856&r2=138857&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Wed Aug 31 11:36:59 2011
@@ -257,6 +257,36 @@
 	return GetElementPtrInst::Create(javaThreadPtr, GEP, "", currentBlock);
 }
 
+static llvm::Function* GetNativeCallee(JavaLLVMCompiler* TheCompiler,
+                                       JavaMethod* compilingMethod) {
+  LLVMSignatureInfo* LSI =
+    TheCompiler->getSignatureInfo(compilingMethod->getSignature());
+  FunctionType* FTy = LSI->getNativeStubType();
+  Function* callee = Function::Create(FTy,
+                                      GlobalValue::ExternalLinkage,
+                                      "",
+                                      TheCompiler->getLLVMModule());
+  std::vector<Value*> args;
+  Function::arg_iterator i = callee->arg_begin();
+  Value* nativeFunc = i;
+  i++;
+  for (Function::arg_iterator e = callee->arg_end(); i != e; i++) {
+    args.push_back(i);
+  }
+
+  LLVMContext& llvmContext = TheCompiler->getLLVMContext();
+  BasicBlock* BB = BasicBlock::Create(llvmContext, "", callee);
+  Value* res = CallInst::Create(nativeFunc, args, "", BB);
+  if (callee->getFunctionType()->getReturnType() != Type::getVoidTy(llvmContext)) {
+    ReturnInst::Create(llvmContext, res, BB);
+  } else {
+    ReturnInst::Create(llvmContext, BB);
+  }
+  callee->setGC("vmkit");
+
+  TheCompiler->GenerateStub(callee);
+  return callee;
+}
 
 llvm::Function* JavaJIT::nativeCompile(intptr_t natPtr) {
   
@@ -327,7 +357,6 @@
     return llvmFunction;
   }
 
-
   currentExceptionBlock = endExceptionBlock = 0;
   currentBlock = createBasicBlock("start");
   endBlock = createBasicBlock("end block");
@@ -350,6 +379,7 @@
   
   uint32 nargs = func->arg_size() + 1 + (stat ? 1 : 0); 
   std::vector<Value*> nativeArgs;
+  nativeArgs.push_back(NULL); // Will contain the callee
   
   
   Value* jniEnv = getJNIEnvPtr(getJavaThreadPtr(getMutatorThreadPtr()));
@@ -433,9 +463,7 @@
     }
   }
   
-  Value* nativeFunc = TheCompiler->getNativeFunction(compilingMethod,
-                                                     (void*)natPtr);
-
+  Value* nativeFunc = TheCompiler->getNativeFunction(compilingMethod, (void*)natPtr);
   if (TheCompiler->isStaticCompiling()) {
     Value* Arg = TheCompiler->getMethodInClass(compilingMethod); 
     
@@ -461,6 +489,7 @@
     currentBlock = endBlock;
     nativeFunc = node;
   }
+  nativeArgs[0] = nativeFunc;
 
   // Synchronize before saying we're entering native
   if (isSynchro(compilingMethod->access))
@@ -470,8 +499,8 @@
 
   CallInst::Create(intrinsics->StartJNIFunction, Args4, "", currentBlock);
   
-  Value* result = llvm::CallInst::Create(nativeFunc, nativeArgs, "",
-                                         currentBlock);
+  Function* callee = GetNativeCallee(TheCompiler, compilingMethod);
+  Value* result = llvm::CallInst::Create(callee, nativeArgs, "", currentBlock);
 
   if (returnType == intrinsics->JavaObjectType) {
     Type* Ty = PointerType::getUnqual(intrinsics->JavaObjectType);

Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=138857&r1=138856&r2=138857&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Wed Aug 31 11:36:59 2011
@@ -307,6 +307,41 @@
   return nativeType;
 }
 
+llvm::FunctionType* LLVMSignatureInfo::getNativeStubType() {
+  // Lock here because we are called by arbitrary code
+  mvm::MvmModule::protectIR();
+  std::vector<llvm::Type*> llvmArgs;
+  uint32 size = signature->nbArguments;
+  Typedef* const* arguments = signature->getArgumentsType();
+ 
+  llvm::Type* Ty =
+    PointerType::getUnqual(Compiler->getIntrinsics()->JavaObjectType);
+
+  llvmArgs.push_back(PointerType::getUnqual(getNativeType())); // method
+  llvmArgs.push_back(Compiler->getIntrinsics()->ptrType); // JNIEnv
+  llvmArgs.push_back(Ty); // Class
+
+  for (uint32 i = 0; i < size; ++i) {
+    Typedef* type = arguments[i];
+    LLVMAssessorInfo& LAI = Compiler->getTypedefInfo(type);
+    llvm::Type* Ty = LAI.llvmType;
+    if (Ty == Compiler->getIntrinsics()->JavaObjectType) {
+      llvmArgs.push_back(LAI.llvmTypePtr);
+    } else {
+      llvmArgs.push_back(LAI.llvmType);
+    }
+  }
+
+  LLVMAssessorInfo& LAI =
+    Compiler->getTypedefInfo(signature->getReturnType());
+  llvm::Type* RetType =
+    LAI.llvmType == Compiler->getIntrinsics()->JavaObjectType ?
+      LAI.llvmTypePtr : LAI.llvmType;
+  FunctionType* FTy = FunctionType::get(RetType, llvmArgs, false);
+  mvm::MvmModule::unprotectIR();
+  return FTy;
+}
+
 
 Function* LLVMSignatureInfo::createFunctionCallBuf(bool virt) {
   

Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=138857&r1=138856&r2=138857&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Wed Aug 31 11:36:59 2011
@@ -348,7 +348,7 @@
                             mvm::KnownFrame* Frame) 
   __attribute__((noinline));
 
-// Never throws. Does not call Java code. Can not yied a GC.
+// Never throws. Does not call Java code. Can not yield a GC. May join a GC.
 extern "C" void* j3StartJNI(uint32* localReferencesNumber,
                             uint32** oldLocalReferencesNumber,
                             mvm::KnownFrame* Frame) {

Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=138857&r1=138856&r2=138857&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Wed Aug 31 11:36:59 2011
@@ -134,16 +134,12 @@
 FrameInfo* StackWalker::get() {
   if (addr == thread->baseSP) return 0;
   ip = FRAME_IP(addr);
-  bool isStub = ((unsigned char*)ip)[0] == 0xCE;
-  if (isStub) ip = addr[2];
   return thread->MyVM->IPToFrameInfo(ip);
 }
 
 void* StackWalker::operator*() {
   if (addr == thread->baseSP) return 0;
   ip = FRAME_IP(addr);
-  bool isStub = ((unsigned char*)ip)[0] == 0xCE;
-  if (isStub) ip = addr[2];
   return ip;
 }
 
@@ -260,7 +256,7 @@
 #define STACK_SIZE 0x100000
 #define NR_THREADS 255
 
-#if (__WORDSIZE == 64)
+#if 0//(__WORDSIZE == 64)
 #define START_ADDR 0x110000000
 #define END_ADDR 0x170000000
 #else

Modified: vmkit/trunk/tools/precompiler/trainer/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=138857&r1=138856&r2=138857&view=diff
==============================================================================
--- vmkit/trunk/tools/precompiler/trainer/Makefile (original)
+++ vmkit/trunk/tools/precompiler/trainer/Makefile Wed Aug 31 11:36:59 2011
@@ -22,7 +22,7 @@
 
 HelloWorld.class: HelloWorld.java
 	$(Echo) "Compiling trainer"
-	$(Verb) javac HelloWorld.java
+	$(Verb) javac $<
 
 generated.bc: $(PRECOMPILER) HelloWorld.class
 	$(Echo) "Pre-compiling bootstrap code"





More information about the vmkit-commits mailing list