[llvm-commits] [vmkit] r50348 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaClass.cpp JavaClass.h JavaIsolate.cpp JavaJIT.cpp JavaJIT.h JavaJITInitialise.cpp JavaMetaJIT.cpp JavaRuntimeJIT.cpp Jnjvm.cpp LockedMap.h ServiceDomain.cpp VirtualTables.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Apr 28 02:21:34 PDT 2008


Author: geoffray
Date: Mon Apr 28 04:21:34 2008
New Revision: 50348

URL: http://llvm.org/viewvc/llvm-project?rev=50348&view=rev
Log:
Multi-vm improvements:
- Correct initialization of classes (JavaState and vm argument)
- Static instances of classes loaded by app class loaders are not
  unique anymore (make room for code sharing between class loaders)
- getstatic and putstatic: when the class is not resolved, the runtime
  callback does not update the global variable and index, just the
  constant pool.

Service-vm improvements:
- Check if a call is a service call in the called function, not in 
  the caller (TODO: optimize static calls since we know at compilation
  time if it's a service call or not).



Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h
    vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp
    vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Mon Apr 28 04:21:34 2008
@@ -608,15 +608,10 @@
 
 #ifdef MULTIPLE_VM
 JavaObject* Class::staticInstance() {
-  if (isolate == Jnjvm::bootstrapVM) {
-    Class* cl = this;
-    std::pair<uint8, JavaObject*>* val = 
-      JavaThread::get()->isolate->statics->lookup(cl);
-    assert(val);
-    return val->second;
-  } else {
-    return _staticInstance;
-  }
+  std::pair<JavaState, JavaObject*>* val = 
+    JavaThread::get()->isolate->statics->lookup(this);
+  assert(val);
+  return val->second;
 }
 
 void Class::createStaticInstance() {
@@ -629,35 +624,28 @@
     
     (*i)->initField(val);
   }
-  if (isolate == Jnjvm::bootstrapVM) {
-    std::pair<uint8, JavaObject*>* v = 
-      new std::pair<uint8, JavaObject*>(0, val);
-    JavaThread::get()->isolate->statics->hash(this, v);
-  } else {
-    _staticInstance = val;
-  }
+  
+  Jnjvm* vm = JavaThread::get()->isolate;
+  std::pair<JavaState, JavaObject*>* p = vm->statics->lookup(this);
+  assert(p);
+  assert(!p->second);
+  p->second = val;
 }
 
-bool CommonClass::isReady() {
-  if (isolate == Jnjvm::bootstrapVM && !this->isArray && 
+JavaState* CommonClass::getStatus() {
+  if (!this->isArray && 
       !AssessorDesc::bogusClassToPrimitive(this)) {
     Class* cl = (Class*)this;
-    std::pair<uint8, JavaObject*>* val = 
-      JavaThread::get()->isolate->statics->lookup(cl);
-    return val && val->first;
-  } else {
-    return status == ready;
-  }
-}
-
-void CommonClass::setReady() {
-  if (isolate == Jnjvm::bootstrapVM && !this->isArray &&
-      !AssessorDesc::bogusClassToPrimitive(this)) {
-    std::pair<uint8, JavaObject*>* val = 
-      JavaThread::get()->isolate->statics->lookup((Class*)this);
-    val->first = 1;
+    Jnjvm* vm = JavaThread::get()->isolate;
+    std::pair<JavaState, JavaObject*>* val = vm->statics->lookup(cl);
+    if (!val) {
+      val = new std::pair<JavaState, JavaObject*>(status, 0);
+      JavaThread::get()->isolate->statics->hash(cl, val);
+    }
+    if (val->first < status) val->first = status;
+    return (JavaState*)&(val->first);
   } else {
-    status = ready;
+    return &status;
   }
 }
 #endif

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Mon Apr 28 04:21:34 2008
@@ -35,6 +35,7 @@
 class Class;
 class JavaCtpInfo;
 class JavaField;
+class JavaJIT;
 class JavaMethod;
 class JavaObject;
 class Jnjvm;
@@ -73,6 +74,8 @@
 };
 
 class CommonClass : public mvm::Object {
+public:
+  JavaObject* classLoader;
 private:
   llvm::GlobalVariable* _llvmVar;
 #ifndef MULTIPLE_VM
@@ -93,7 +96,6 @@
   std::vector<JavaMethod*> staticMethods;
   std::vector<JavaField*>  virtualFields;
   std::vector<JavaField*>  staticFields;
-  JavaObject* classLoader;
 #ifndef MULTIPLE_VM
   JavaObject* delegatee;
 #endif
@@ -147,15 +149,17 @@
   void resolveClass(bool doClinit);
 
 #ifndef MULTIPLE_VM
+  JavaState* getStatus() {
+    return &status;
+  }
   bool isReady() {
     return status == ready;
   }
-  void setReady() {
-    status = ready;
-  }
 #else
-  bool isReady();
-  void setReady();
+  JavaState* getStatus();
+  bool isReady() {
+    return *getStatus() == ready;
+  }
 #endif
   bool isResolved() {
     return status >= resolved;
@@ -171,7 +175,6 @@
   unsigned int minor;
   unsigned int major;
   ArrayUInt8* bytes;
-  JavaObject* _staticInstance;
   JavaObject* virtualInstance;
   llvm::Function* virtualTracer;
   llvm::Function* staticTracer;
@@ -185,7 +188,7 @@
   bool innerOuterResolved;
   
   void resolveFields();
-  llvm::Value* staticVar(llvm::Module* compilingModule, llvm::BasicBlock* BB);
+  llvm::Value* staticVar(JavaJIT* jit);
   
   uint64 virtualSize;
   VirtualTable* virtualVT;
@@ -200,6 +203,7 @@
   JavaObject* operator()(Jnjvm* vm);
 
 #ifndef MULTIPLE_VM
+  JavaObject* _staticInstance;
   JavaObject* staticInstance() {
     return _staticInstance;
   }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp Mon Apr 28 04:21:34 2008
@@ -29,6 +29,10 @@
 #include "LockedMap.h"
 #include "Zip.h"
 
+#ifdef SERVICE_VM
+#include "ServiceDomain.h"
+#endif
+
 #define PATH_MANIFEST "META-INF/MANIFEST.MF"
 #define MAIN_CLASS "Main-Class: "
 #define PREMAIN_CLASS "Premain-Class: "
@@ -382,6 +386,9 @@
     argc = argc - pos + 1;
     
     loadBootstrap();
+#ifdef SERVICE_VM
+    (*Classpath::vmdataClassLoader)(appClassLoader, (JavaObject*)this);
+#endif
     
     if (info.agents.size()) {
       assert(0 && "implement me");
@@ -397,7 +404,7 @@
     for (int i = 2; i < argc; ++i) {
       args->setAt(i - 2, (JavaObject*)asciizToStr(argv[i]));
     }
-  
+
     executeClass(info.className, args);
     waitForExit();
   }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Mon Apr 28 04:21:34 2008
@@ -98,7 +98,7 @@
 uint32 JavaJIT::stackSize() {
   return stack.size();
 }
-
+  
 void JavaJIT::invokeVirtual(uint16 index) {
   
   JavaCtpInfo* ctpInfo = compilingClass->ctpInfo;
@@ -109,7 +109,8 @@
   if ((cl && isFinal(cl->access)) || 
       (meth && (isFinal(meth->access) || isPrivate(meth->access))))
     return invokeSpecial(index);
-  
+ 
+
 #ifndef WITHOUT_VTABLE
   Constant* zero = mvm::jit::constantZero;
   Signdef* signature = ctpInfo->infoOfInterfaceOrVirtualMethod(index);
@@ -119,7 +120,7 @@
   makeArgs(it, index, args, signature->nbIn + 1);
   
   JITVerifyNull(args[0]); 
-    
+
   std::vector<Value*> indexes; //[3];
   indexes.push_back(zero);
   indexes.push_back(zero);
@@ -174,7 +175,9 @@
     
   Value* Func = new LoadInst(FuncPtr, "", currentBlock);
   Func = new BitCastInst(Func, signature->virtualTypePtr, "", currentBlock);
+
   Value* val = invoke(Func, args, "", currentBlock);
+  
   const llvm::Type* retType = signature->virtualType->getReturnType();
   if (retType != Type::VoidTy) {
     push(val, signature->ret->funcs);
@@ -182,6 +185,7 @@
       push(mvm::jit::constantZero, AssessorDesc::dInt);
     }
   }
+    
 #else
   return invokeInterfaceOrVirtual(index);
 #endif
@@ -299,8 +303,7 @@
   if (isVirtual(compilingMethod->access)) {
     argsSync.push_back(llvmFunction->arg_begin());
   } else {
-    Module* M = compilingClass->isolate->module;
-    Value* arg = compilingClass->staticVar(M, currentBlock);
+    Value* arg = compilingClass->staticVar(this);
     argsSync.push_back(arg);
   }
   llvm::CallInst::Create(aquireObjectLLVM, argsSync.begin(), argsSync.end(),
@@ -312,8 +315,7 @@
   if (isVirtual(compilingMethod->access)) {
     argsSync.push_back(llvmFunction->arg_begin());
   } else {
-    Module* M = compilingClass->isolate->module;
-    Value* arg = compilingClass->staticVar(M, currentBlock);
+    Value* arg = compilingClass->staticVar(this);
     argsSync.push_back(arg);
   }
   llvm::CallInst::Create(releaseObjectLLVM, argsSync.begin(), argsSync.end(), "",
@@ -349,6 +351,7 @@
   
   const FunctionType *funcType = compilingMethod->llvmType;
   returnType = funcType->getReturnType();
+  endBlock = createBasicBlock("end");
 
   llvmFunction = parentFunction;
   currentBlock = curBB;
@@ -409,13 +412,25 @@
     JavaObject* loader = compilingClass->classLoader;
     ServiceDomain* vm = ServiceDomain::getDomainFromLoader(loader);
     isolateLocal = new LoadInst(vm->llvmDelegatee(), "", currentBlock);
+    Value* cmp = new ICmpInst(ICmpInst::ICMP_NE, args[args.size() - 1], 
+                              isolateLocal, "", currentBlock);
+    BasicBlock* ifTrue = createBasicBlock("true service call");
+    BasicBlock* endBlock = createBasicBlock("end check service call");
+    BranchInst::Create(ifTrue, endBlock, cmp, currentBlock);
+    currentBlock = ifTrue;
+    std::vector<Value*> Args;
+    Args.push_back(args[args.size()-  1]);
+    Args.push_back(isolateLocal);
+    CallInst::Create(ServiceDomain::serviceCallStartLLVM, Args.begin(),
+                     Args.end(), "", currentBlock);
+    BranchInst::Create(endBlock, currentBlock);
+    currentBlock = endBlock;
   }
 #endif
 #endif
   
   exploreOpcodes(&compilingClass->bytes->elements[start], codeLen);
   
-  endBlock = createBasicBlock("end");
 
   if (returnType != Type::VoidTy) {
     endNode = llvm::PHINode::Create(returnType, "", endBlock);
@@ -425,6 +440,25 @@
   
   PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "--> end inline compiling %s\n",
               compilingMethod->printString());
+
+#if defined(SERVICE_VM)
+  if (compilingClass->isolate != Jnjvm::bootstrapVM) {
+    Value* cmp = new ICmpInst(ICmpInst::ICMP_NE, args[args.size() - 1], 
+                              isolateLocal, "", currentBlock);
+    BasicBlock* ifTrue = createBasicBlock("true service call");
+    BasicBlock* newEndBlock = createBasicBlock("end check service call");
+    BranchInst::Create(ifTrue, newEndBlock, cmp, currentBlock);
+    currentBlock = ifTrue;
+    std::vector<Value*> Args;
+    Args.push_back(args[args.size() - 1]);
+    Args.push_back(isolateLocal);
+    CallInst::Create(ServiceDomain::serviceCallStopLLVM, Args.begin(),
+                     Args.end(), "", currentBlock);
+    BranchInst::Create(newEndBlock, currentBlock);
+    currentBlock = newEndBlock;
+    endBlock = currentBlock;
+  }
+#endif
   
   curBB = endBlock;
   return endNode;
@@ -460,7 +494,7 @@
   
   Function* func = llvmFunction = compilingMethod->llvmFunction;
 
-  BasicBlock* startBlock = currentBlock = createBasicBlock("start");
+  currentBlock = createBasicBlock("start");
   endExceptionBlock = createBasicBlock("endExceptionBlock");
   unifiedUnreachable = createBasicBlock("unifiedUnreachable"); 
 
@@ -481,9 +515,7 @@
     }
 #endif
 
-  unsigned nbe = readExceptionTable(reader);
   
-  currentBlock = startBlock;
 
   for (int i = 0; i < maxLocals; i++) {
     intLocals.push_back(new AllocaInst(Type::Int32Ty, "", currentBlock));
@@ -534,10 +566,25 @@
     JavaObject* loader = compilingClass->classLoader;
     ServiceDomain* vm = ServiceDomain::getDomainFromLoader(loader);
     isolateLocal = new LoadInst(vm->llvmDelegatee(), "", currentBlock);
+    Value* cmp = new ICmpInst(ICmpInst::ICMP_NE, i, isolateLocal, "",
+                              currentBlock);
+    BasicBlock* ifTrue = createBasicBlock("true service call");
+    BasicBlock* endBlock = createBasicBlock("end check service call");
+    BranchInst::Create(ifTrue, endBlock, cmp, currentBlock);
+    currentBlock = ifTrue;
+    std::vector<Value*> Args;
+    Args.push_back(i);
+    Args.push_back(isolateLocal);
+    CallInst::Create(ServiceDomain::serviceCallStartLLVM, Args.begin(),
+                     Args.end(), "", currentBlock);
+    BranchInst::Create(endBlock, currentBlock);
+    currentBlock = endBlock;
   }
 #endif
 #endif
   
+  unsigned nbe = readExceptionTable(reader);
+  
   exploreOpcodes(&compilingClass->bytes->elements[start], codeLen);
   
 
@@ -567,11 +614,29 @@
                            currentBlock);
     }
 #endif
+  
+#if defined(SERVICE_VM)
+  if (compilingClass->isolate != Jnjvm::bootstrapVM) {
+    Value* cmp = new ICmpInst(ICmpInst::ICMP_NE, i, isolateLocal, "",
+                              currentBlock);
+    BasicBlock* ifTrue = createBasicBlock("true service call");
+    BasicBlock* newEndBlock = createBasicBlock("end check service call");
+    BranchInst::Create(ifTrue, newEndBlock, cmp, currentBlock);
+    currentBlock = ifTrue;
+    std::vector<Value*> Args;
+    Args.push_back(i);
+    Args.push_back(isolateLocal);
+    CallInst::Create(ServiceDomain::serviceCallStopLLVM, Args.begin(),
+                     Args.end(), "", currentBlock);
+    BranchInst::Create(newEndBlock, currentBlock);
+    currentBlock = newEndBlock;
+  }
+#endif
 
   if (returnType != Type::VoidTy)
-    llvm::ReturnInst::Create(endNode, endBlock);
+    llvm::ReturnInst::Create(endNode, currentBlock);
   else
-    llvm::ReturnInst::Create(endBlock);
+    llvm::ReturnInst::Create(currentBlock);
 
   pred_iterator PI = pred_begin(endExceptionBlock);
   pred_iterator PE = pred_end(endExceptionBlock);
@@ -623,6 +688,7 @@
 
 
 unsigned JavaJIT::readExceptionTable(Reader* reader) {
+  BasicBlock* temp = currentBlock;
   uint16 nbe = reader->readU2();
   std::vector<Exception*> exceptions;  
   unsigned sync = isSynchro(compilingMethod->access) ? 1 : 0;
@@ -634,6 +700,7 @@
   }
   
   BasicBlock* realEndExceptionBlock = endExceptionBlock;
+  currentExceptionBlock = endExceptionBlock;
   if (sync) {
     BasicBlock* synchronizeExceptionBlock = 
           createBasicBlock("synchronizeExceptionBlock");
@@ -644,8 +711,7 @@
     if (isVirtual(compilingMethod->access)) {
       argsSync.push_back(llvmFunction->arg_begin());
     } else {
-      Value* arg = compilingClass->staticVar(compilingClass->isolate->module,
-                                             currentBlock);
+      Value* arg = compilingClass->staticVar(this);
       argsSync.push_back(arg);
     }
     llvm::CallInst::Create(releaseObjectLLVM, argsSync.begin(), argsSync.end(),
@@ -817,7 +883,8 @@
     e = exceptions.end(); i!= e; ++i) {
     delete *i;
   }
-
+  
+  currentBlock = temp;
   return nbe;
 
 }
@@ -850,9 +917,7 @@
         const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[index]);
         void* val = 0;
         GlobalVariable* gv = 0;
-#ifdef MULTIPLE_VM
-        if (compilingClass->isolate != Jnjvm::bootstrapVM) {
-#endif
+#ifndef MULTIPLE_VM
         val = compilingClass->isolate->UTF8ToStr(utf8);
         compilingClass->isolate->protectModule->lock();
         gv =
@@ -861,8 +926,7 @@
                              constantJavaObjectNull, "",
                              compilingClass->isolate->module);
         compilingClass->isolate->protectModule->unlock();
-#ifdef MULTIPLE_VM
-        } else {
+#else
           val = (void*)utf8;
           compilingClass->isolate->protectModule->lock();
           gv =
@@ -871,7 +935,6 @@
                                constantUTF8Null, "",
                                compilingClass->isolate->module);
           compilingClass->isolate->protectModule->unlock();
-        }
 #endif
         
         // TODO: put an initialiser in here
@@ -893,13 +956,12 @@
                             currentBlock);
     }
 #ifdef MULTIPLE_VM
-    if (compilingClass->isolate == Jnjvm::bootstrapVM) {
-      CallInst* C = llvm::CallInst::Create(runtimeUTF8ToStrLLVM, toPush, "",
-                                           currentBlock);
-      push(C, AssessorDesc::dRef);
-    } else 
-#endif
+    CallInst* C = llvm::CallInst::Create(runtimeUTF8ToStrLLVM, toPush, "",
+                                         currentBlock);
+    push(C, AssessorDesc::dRef);
+#else
     push(toPush, AssessorDesc::dRef);
+#endif
   } else if (type == JavaCtpInfo::ConstantLong) {
     mvm::jit::protectConstants();//->lock();
     push(ConstantInt::get(Type::Int64Ty, ctpInfo->LongAt(index)),
@@ -1285,7 +1347,7 @@
   if (!val) {
     Function* func = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL,
                                                           signature, meth);
-#ifdef SERVICE_VM
+#if 0//def SERVICE_VM
     bool serviceCall = false;
     if (meth && meth->classDef->classLoader != compilingClass->classLoader &&
         meth->classDef->isolate != Jnjvm::bootstrapVM){
@@ -1294,7 +1356,7 @@
       serviceCall = true;
       std::vector<Value*> Args;
       Args.push_back(isolateLocal);
-      Args.push_back(calling->llvmDelegatee());
+      Args.push_back(new LoadInst(calling->llvmDelegatee(), "", currentBlock));
       CallInst::Create(ServiceDomain::serviceCallStartLLVM, Args.begin(),
                        Args.end(), "", currentBlock);
     }
@@ -1307,14 +1369,14 @@
       val = invoke(func, args, "", currentBlock);
     }
 
-#ifdef SERVICE_VM
+#if 0//def SERVICE_VM
     if (serviceCall) {  
       JavaObject* loader = meth->classDef->classLoader;
       ServiceDomain* calling = ServiceDomain::getDomainFromLoader(loader);
       serviceCall = true;
       std::vector<Value*> Args;
       Args.push_back(isolateLocal);
-      Args.push_back(calling->llvmDelegatee());
+      Args.push_back(new LoadInst(calling->llvmDelegatee(), "", currentBlock));
       CallInst::Create(ServiceDomain::serviceCallStopLLVM, Args.begin(),
                        Args.end(), "", currentBlock);
     }
@@ -1353,7 +1415,7 @@
     Function* func = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_STATIC,
                                                           signature, meth);
     
-#ifdef SERVICE_VM
+#if 0//def SERVICE_VM
     bool serviceCall = false;
     if (meth && meth->classDef->classLoader != compilingClass->classLoader &&
         meth->classDef->isolate != Jnjvm::bootstrapVM){
@@ -1362,7 +1424,7 @@
       serviceCall = true;
       std::vector<Value*> Args;
       Args.push_back(isolateLocal);
-      Args.push_back(calling->llvmDelegatee());
+      Args.push_back(new LoadInst(calling->llvmDelegatee(), "", currentBlock));
       CallInst::Create(ServiceDomain::serviceCallStartLLVM, Args.begin(),
                        Args.end(), "", currentBlock);
     }
@@ -1375,13 +1437,13 @@
       val = invoke(func, args, "", currentBlock);
     }
 
-#ifdef SERVICE_VM
+#if 0//def SERVICE_VM
     if (serviceCall) {  
       JavaObject* loader = meth->classDef->classLoader;
       ServiceDomain* calling = ServiceDomain::getDomainFromLoader(loader);
       std::vector<Value*> Args;
       Args.push_back(isolateLocal);
-      Args.push_back(calling->llvmDelegatee());
+      Args.push_back(new LoadInst(calling->llvmDelegatee(), "", currentBlock));
       CallInst::Create(ServiceDomain::serviceCallStopLLVM, Args.begin(), Args.end(), "",
                        currentBlock);
     }
@@ -1476,11 +1538,9 @@
     Value* load = new LoadInst(cl->llvmVar(compilingClass->isolate->module),
                                "", currentBlock);
 #ifdef MULTIPLE_VM
-    if (cl->isolate == Jnjvm::bootstrapVM) {
-      Module* M = compilingClass->isolate->module;
-      Value* arg = new LoadInst(cl->llvmVar(M), "", currentBlock);
-      invoke(initialisationCheckLLVM, arg, "", currentBlock);
-    }
+    Module* M = compilingClass->isolate->module;
+    Value* arg = new LoadInst(cl->llvmVar(M), "", currentBlock);
+    invoke(initialisationCheckLLVM, arg, "", currentBlock);
     val = invoke(doNewLLVM, load, isolateLocal, "", currentBlock);
 #else
     val = invoke(doNewLLVM, load, "", currentBlock);
@@ -1531,16 +1591,9 @@
       && field->classDef->isReady()
 #endif
      ) {
-    Module* M = compilingClass->isolate->module;
-    if (stat) object = field->classDef->staticVar(M, currentBlock);
+    if (stat) object = field->classDef->staticVar(this);
     const Type* type = stat ? field->classDef->staticType :
                               field->classDef->virtualType;
-#ifdef MULTIPLE_VM
-    if (stat && field->classDef->isolate == Jnjvm::bootstrapVM) {
-      Value* arg = new LoadInst(field->classDef->llvmVar(M), "", currentBlock);
-      invoke(initialisationCheckLLVM, arg, "", currentBlock); 
-    }
-#endif
     return fieldGetter(this, type, object, field->offset);
   } else {
     const Type* Pty = mvm::jit::arrayPtrType;
@@ -1607,15 +1660,6 @@
     llvm::BranchInst::Create(endBlock, currentBlock);
     
     currentBlock = endBlock;;
-#ifdef MULTIPLE_VM
-    if (stat) {
-      std::vector<Value*> args;
-      Value* val = new LoadInst(compilingClass->llvmVar(M), "", currentBlock);
-      args.push_back(val);
-      args.push_back(CI);
-      invoke(initialisationCheckCtpLLVM, args, "", currentBlock); 
-    }
-#endif
     return new BitCastInst(node, fieldTypePtr, "", currentBlock);
   }
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h Mon Apr 28 04:21:34 2008
@@ -252,7 +252,6 @@
   static llvm::Function* doNewUnknownLLVM;
 #ifdef MULTIPLE_VM
   static llvm::Function* initialisationCheckLLVM;
-  static llvm::Function* initialisationCheckCtpLLVM;
 #endif
   static llvm::Function* initialiseObjectLLVM;
   static llvm::Function* newLookupLLVM;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp Mon Apr 28 04:21:34 2008
@@ -232,20 +232,7 @@
   initialisationCheckLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
                      "initialisationCheck",
                      module);
-  }
-  
-  // Create initialisationCheckCtpLLVM
-  {
-  std::vector<const Type*> args;
-  args.push_back(mvm::jit::ptrType);
-  args.push_back(Type::Int32Ty);
-  const FunctionType* type = FunctionType::get(Type::VoidTy, args,
-                                               false);
-
-  initialisationCheckCtpLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
-                     "initialisationCheckCtp",
-                     module);
-  }
+  } 
 #endif
   
   
@@ -518,7 +505,8 @@
   // Create getStaticInstanceLLVM
   {
   std::vector<const Type*> args;
-  args.push_back(mvm::jit::ptrType);
+  args.push_back(mvm::jit::ptrType); // cl
+  args.push_back(mvm::jit::ptrType); // vm
   const FunctionType* type = FunctionType::get(JavaObject::llvmType, args, false);
 
   getStaticInstanceLLVM = Function::Create(type, GlobalValue::ExternalLinkage,

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Mon Apr 28 04:21:34 2008
@@ -32,16 +32,12 @@
 using namespace jnjvm;
 using namespace llvm;
 
-Value* Class::staticVar(Module* compilingModule,  BasicBlock* currentBlock) {
+Value* Class::staticVar(JavaJIT* jit) {
 
+#ifndef MULTIPLE_VM
   if (!_staticVar) {
     aquire();
     if (!_staticVar) {
-#ifdef MULTIPLE_VM
-      if (isolate == Jnjvm::bootstrapVM) {
-        _staticVar = llvmVar(compilingModule);
-      } else {
-#endif
         JavaObject* obj = staticInstance();
         mvm::jit::protectConstants();//->lock();
         Constant* cons = 
@@ -55,23 +51,18 @@
                                       cons, "",
                                       isolate->module);
         isolate->protectModule->unlock();
-      }
-#ifdef MULTIPLE_VM
     }
-#endif
     release();
   }
 
-#ifdef MULTIPLE_VM
-  if (isolate == Jnjvm::bootstrapVM) {
-    Value* ld = new LoadInst(_staticVar, "", currentBlock);
-    return llvm::CallInst::Create(JavaJIT::getStaticInstanceLLVM, ld, "",
-                                  currentBlock);
-  } else {
-#endif
-    return new LoadInst(_staticVar, "", currentBlock);
-#ifdef MULTIPLE_VM
-  }
+  return new LoadInst(_staticVar, "", jit->currentBlock);
+
+#else
+  Value* var = llvmVar(jit->compilingClass->isolate->module);
+  Value* ld = new LoadInst(var, "", jit->currentBlock);
+  jit->invoke(JavaJIT::initialisationCheckLLVM, ld, "", jit->currentBlock);
+  return jit->invoke(JavaJIT::getStaticInstanceLLVM, ld, jit->isolateLocal, 
+                     "", jit->currentBlock);
 #endif
 }
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Mon Apr 28 04:21:34 2008
@@ -60,7 +60,6 @@
 llvm::Function* JavaJIT::doNewUnknownLLVM = 0;
 #ifdef MULTIPLE_VM
 llvm::Function* JavaJIT::initialisationCheckLLVM = 0;
-llvm::Function* JavaJIT::initialisationCheckCtpLLVM = 0;
 #endif
 llvm::Function* JavaJIT::initialiseObjectLLVM = 0;
 llvm::Function* JavaJIT::newLookupLLVM = 0;
@@ -139,8 +138,10 @@
     field->classDef->initialiseClass();
     if (stat) obj = field->classDef->staticInstance();
     void* ptr = (void*)(field->ptrOffset + (uint64)obj);
+#ifndef MULTIPLE_VM
     if (stat) *ifStatic = ptr;
     *offset = (uint32)field->ptrOffset;
+#endif
     return ptr;
   }
   
@@ -157,9 +158,10 @@
   void* ptr = (void*)((uint64)obj + field->ptrOffset);
   
   ctpInfo->ctpRes[index] = field;
-
+#ifndef MULTIPLE_VM
   if (stat) *ifStatic = ptr;
   *offset = (uint32)field->ptrOffset;
+#endif
 
   return ptr;
 }
@@ -210,18 +212,17 @@
 }
 
 #ifdef MULTIPLE_VM
-extern "C" JavaObject* getStaticInstance(Class* cl) {
-  if (cl->isolate == Jnjvm::bootstrapVM) {
-    Jnjvm* vm = JavaThread::get()->isolate;
-    std::pair<uint8, JavaObject*>* val = vm->statics->lookup(cl);
-    if (!val) {
-      cl->initialiseClass();
-      val = vm->statics->lookup(cl);
-    }
-    return val->second;
-  } else {
-    return cl->_staticInstance;
+extern "C" JavaObject* getStaticInstance(Class* cl, Jnjvm* vm) {
+  std::pair<JavaState, JavaObject*>* val = vm->statics->lookup(cl);
+  if (!val || !(val->second)) {
+    cl->initialiseClass();
+    val = vm->statics->lookup(cl);
   }
+  return val->second;
+}
+
+extern "C" void initialisationCheck(CommonClass* cl) {
+  cl->isolate->initialiseClass(cl);
 }
 #endif
 
@@ -270,15 +271,3 @@
 }
 #endif
 
-#ifdef MULTIPLE_VM
-extern "C" void initialisationCheck(CommonClass* cl) {
-  cl->isolate->initialiseClass(cl);
-}
-
-extern "C" void initialisationCheckCtp(Class* caller, uint16 index) {
-  JavaCtpInfo* ctpInfo = caller->ctpInfo;
-  JavaField* field = (JavaField*)(ctpInfo->ctpRes[index]);
-  assert(field && "checking without resolving?");  
-  field->classDef->isolate->initialiseClass(field->classDef);
-}
-#endif

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Mon Apr 28 04:21:34 2008
@@ -304,22 +304,23 @@
 typedef void (*clinit_t)(Jnjvm* vm);
 
 void Jnjvm::initialiseClass(CommonClass* cl) {
+  JavaState* status = cl->getStatus();
   if (cl->isArray || AssessorDesc::bogusClassToPrimitive(cl)) {
-    cl->status = ready;
-  } else if (!(cl->isReady())) {
+    *status = ready;
+  } else if (!(*status == ready)) {
     cl->aquire();
-    int status = cl->status;
-    if (cl->isReady()) {
+    JavaState* status = cl->getStatus();
+    if (*status == ready) {
       cl->release();
-    } else if (status >= resolved && status != clinitParent &&
-               status != inClinit) {
-      cl->status = clinitParent;
+    } else if (*status >= resolved && *status != clinitParent &&
+               *status != inClinit) {
+      *status = clinitParent;
       cl->release();
       if (cl->super) {
         cl->super->initialiseClass();
       }
       
-      cl->status = inClinit;
+      *status = inClinit;
       JavaMethod* meth = cl->lookupMethodDontThrow(clinitName, clinitType, true,
                                                    false);
       
@@ -334,7 +335,7 @@
         JavaObject* exc = 0;
         try{
           clinit_t pred = (clinit_t)meth->compiledPtr();
-          pred(this);
+          pred(JavaThread::get()->isolate);
         } catch(...) {
           exc = JavaThread::getJavaException();
           assert(exc && "no exception?");
@@ -349,14 +350,14 @@
         }
       }
       
-      cl->setReady();
+      *status = ready;
       cl->broadcastClass();
-    } else if (status < resolved) {
+    } else if (*status < resolved) {
       cl->release();
       unknownError("try to clinit a not-readed class...");
     } else {
       if (!cl->ownerClass()) {
-        while (status < ready) cl->waitClass();
+        while (*status < ready) cl->waitClass();
         cl->release();
         initialiseClass(cl);
       } 
@@ -713,7 +714,9 @@
   cl->name = name;
   cl->classLoader = 0;
   cl->bytes = 0;
+#ifndef MULTIPLE_VM
   cl->_staticInstance = 0;
+#endif
   cl->virtualInstance = 0;
   cl->super = 0;
   cl->ctpInfo = 0;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h Mon Apr 28 04:21:34 2008
@@ -264,7 +264,7 @@
 };
 
 class StaticInstanceMap :
-    public LockedMap<Class*, std::pair<uint8, JavaObject*>*, std::less<Class*> > {
+    public LockedMap<Class*, std::pair<JavaState, JavaObject*>*, std::less<Class*> > {
 public:
   static VirtualTable* VT;
   

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp Mon Apr 28 04:21:34 2008
@@ -69,14 +69,18 @@
 #ifdef MULTIPLE_GC
   service->GC = Collector::allocate();
 #endif
-
+  
+  service->classpath = callingVM->classpath;
+  service->bootClasspathEnv = callingVM->bootClasspathEnv;
+  service->libClasspathEnv = callingVM->libClasspathEnv;
+  service->bootClasspath = callingVM->bootClasspath;
   service->functions = vm_new(service, FunctionMap)();
   service->functionDefs = vm_new(service, FunctionDefMap)();
   service->module = new llvm::Module("Service Domain");
   service->protectModule = mvm::Lock::allocNormal();
-  service->TheModuleProvider = new JnjvmModuleProvider(service->module, 
+  service->TheModuleProvider = new JnjvmModuleProvider(service->module,
                                                        service->functions,
-                                                       service->functionDefs);  
+                                                       service->functionDefs); 
 
 #ifdef MULTIPLE_GC
   mvm::jit::memoryManager->addGCForModule(service->module, service->GC);
@@ -86,7 +90,8 @@
   service->name = "service";
   service->jniEnv = &JNI_JNIEnvTable;
   service->javavmEnv = &JNI_JavaVMTable;
-  
+  service->appClassLoader = callingVM->appClassLoader;
+
   // We copy so that bootstrap utf8 such as "<init>" are unique  
   service->hashUTF8 = vm_new(service, UTF8Map)();
   callingVM->hashUTF8->copy(service->hashUTF8);
@@ -118,8 +123,8 @@
 void ServiceDomain::loadBootstrap() {
   // load and initialise math since it is responsible for dlopen'ing 
   // libjavalang.so and we are optimizing some math operations
-  loadName(asciizConstructUTF8("java/lang/Math"), 
-           CommonClass::jnjvmClassLoader, true, true, true);
+  //loadName(asciizConstructUTF8("java/lang/Math"), 
+  //         CommonClass::jnjvmClassLoader, true, true, true);
 }
 
 void ServiceDomain::serviceError(const char* str) {
@@ -133,29 +138,38 @@
   return vm;
 }
 
-#ifdef SERVICE_VM
-extern "C" void ServiceDomainStart(ServiceDomain* caller,
-                                   ServiceDomain* callee) {
+extern "C" void serviceCallStart(ServiceDomain* caller,
+                                 ServiceDomain* callee) {
+  assert(caller && "No caller in service stop?");
+  assert(callee && "No callee in service stop?");
+  assert(caller->getVirtualTable() == ServiceDomain::VT && "Caller not a service domain?");
+  assert(callee->getVirtualTable() == ServiceDomain::VT && "Callee not a service domain?");
   JavaThread* th = JavaThread::get();
   th->isolate = callee;
+#ifdef SERVICE_VM
   time_t t = time(NULL);
   caller->lock->lock();
   caller->executionTime += t - th->executionTime;
   caller->interactions[callee]++;
   caller->lock->unlock();
   th->executionTime = t;
-
+#endif
 }
 
-extern "C" void ServiceDomainStop(ServiceDomain* caller,
-                                  ServiceDomain* callee) {
+extern "C" void serviceCallStop(ServiceDomain* caller,
+                                ServiceDomain* callee) {
+  assert(caller && "No caller in service stop?");
+  assert(callee && "No callee in service stop?");
+  assert(caller->getVirtualTable() == ServiceDomain::VT && "Caller not a service domain?");
+  assert(callee->getVirtualTable() == ServiceDomain::VT && "Callee not a service domain?");
   JavaThread* th = JavaThread::get();
   th->isolate = caller;
+#ifdef SERVICE_VM
   time_t t = time(NULL);
   callee->lock->lock();
   callee->executionTime += t - th->executionTime;
   callee->lock->unlock();
   th->executionTime = t;
+#endif
 }
 
-#endif

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Mon Apr 28 04:21:34 2008
@@ -144,7 +144,9 @@
 void Class::TRACER {
   CommonClass::PARENT_TRACER;
   bytes->MARK_AND_TRACE;
+#ifndef MULTIPLE_VM
   _staticInstance->MARK_AND_TRACE;
+#endif
   virtualInstance->MARK_AND_TRACE;
   ctpInfo->MARK_AND_TRACE;
   TRACE_VECTOR(Attribut*, gc_allocator, attributs);





More information about the llvm-commits mailing list