[vmkit-commits] [vmkit] r59297 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaJIT.cpp JnjvmClassLoader.cpp JnjvmModuleProvider.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Fri Nov 14 02:15:45 PST 2008


Author: geoffray
Date: Fri Nov 14 04:15:44 2008
New Revision: 59297

URL: http://llvm.org/viewvc/llvm-project?rev=59297&view=rev
Log:
Correctly handle class initialization when doing an invokestatic.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Fri Nov 14 04:15:44 2008
@@ -1511,47 +1511,39 @@
   makeArgs(it, index, args, signature->args.size() + 1);
   JITVerifyNull(args[0]); 
 
-  if (cl->equals(compilingClass->classLoader->bootstrapLoader->mathName)) {
-    val = lowerMathOps(name, args);
-  }
-
-
-  if (!val) {
 #if defined(ISOLATE_SHARING)
-    const Type* Ty = module->ConstantPoolType;
-    Constant* Nil = Constant::getNullValue(Ty);
-    GlobalVariable* GV = new GlobalVariable(Ty, false,
-                                            GlobalValue::ExternalLinkage, Nil,
-                                            "", module);
-    Value* res = new LoadInst(GV, "", false, currentBlock);
-    Value* test = new ICmpInst(ICmpInst::ICMP_EQ, res, Nil, "", currentBlock);
+  const Type* Ty = module->ConstantPoolType;
+  Constant* Nil = Constant::getNullValue(Ty);
+  GlobalVariable* GV = new GlobalVariable(Ty, false,
+                                          GlobalValue::ExternalLinkage, Nil,
+                                          "", module);
+  Value* res = new LoadInst(GV, "", false, currentBlock);
+  Value* test = new ICmpInst(ICmpInst::ICMP_EQ, res, Nil, "", currentBlock);
  
-    BasicBlock* trueCl = createBasicBlock("UserCtp OK");
-    BasicBlock* falseCl = createBasicBlock("UserCtp Not OK");
-    PHINode* node = llvm::PHINode::Create(Ty, "", trueCl);
-    node->addIncoming(res, currentBlock);
-    BranchInst::Create(falseCl, trueCl, test, currentBlock);
-    std::vector<Value*> Args;
-    Args.push_back(ctpCache);
-    Args.push_back(ConstantInt::get(Type::Int32Ty, index));
-    Args.push_back(GV);
-    res = CallInst::Create(module->SpecialCtpLookupFunction, Args.begin(),
-                           Args.end(), "", falseCl);
-    node->addIncoming(res, falseCl);
-    BranchInst::Create(trueCl, falseCl);
-    currentBlock = trueCl;
-    args.push_back(node);
+  BasicBlock* trueCl = createBasicBlock("UserCtp OK");
+  BasicBlock* falseCl = createBasicBlock("UserCtp Not OK");
+  PHINode* node = llvm::PHINode::Create(Ty, "", trueCl);
+  node->addIncoming(res, currentBlock);
+  BranchInst::Create(falseCl, trueCl, test, currentBlock);
+  std::vector<Value*> Args;
+  Args.push_back(ctpCache);
+  Args.push_back(ConstantInt::get(Type::Int32Ty, index));
+  Args.push_back(GV);
+  res = CallInst::Create(module->SpecialCtpLookupFunction, Args.begin(),
+                         Args.end(), "", falseCl);
+  node->addIncoming(res, falseCl);
+  BranchInst::Create(trueCl, falseCl);
+  currentBlock = trueCl;
+  args.push_back(node);
 #endif
-    Function* func = 
-      (Function*)ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL,
+  Function* func =   
+    (Function*)ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL,
                                                       signature, meth);
 
-    if (meth && canBeInlined(meth)) {
-      val = invokeInline(meth, args);
-    } else {
-      val = invoke(func, args, "", currentBlock);
-    }
-
+  if (meth && canBeInlined(meth)) {
+    val = invokeInline(meth, args);
+  } else {
+    val = invoke(func, args, "", currentBlock);
   }
   
   const llvm::Type* retType = virtualType->getReturnType();
@@ -1585,7 +1577,7 @@
     val = lowerMathOps(name, args);
   }
 
-  if (cl->equals(loader->stackWalkerName)) {
+  else if (cl->equals(loader->stackWalkerName)) {
     callsStackWalker = true;
   }
 
@@ -1601,6 +1593,21 @@
                                            false);
     args.push_back(newCtpCache);
 #endif
+    
+    // If we're not static compiling or we're not in an isolate environment,
+    // the callback will do the initialization
+#ifndef ISOLATE
+    if (module->isStaticCompiling()) {
+#endif
+      uint32 clIndex = ctpInfo->getClassIndexFromMethod(index);
+      Value* Cl = getResolvedClass(clIndex, true); 
+      if (!(meth && compilingClass->subclassOf(meth->classDef))) {
+        CallInst::Create(module->ForceInitialisationCheckFunction, Cl, "",
+                         currentBlock);
+      }
+#ifndef ISOLATE
+    }
+#endif
 
     if (meth && canBeInlined(meth)) {
       val = invokeInline(meth, args);

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Fri Nov 14 04:15:44 2008
@@ -43,8 +43,8 @@
 JnjvmBootstrapLoader::JnjvmBootstrapLoader(bool staticCompilation) {
   
   TheModule = new JnjvmModule("Bootstrap JnJVM");
-  TheModuleProvider = new JnjvmModuleProvider(getModule());
   getModule()->setIsStaticCompiling(staticCompilation);
+  TheModuleProvider = new JnjvmModuleProvider(getModule());
   
   hashUTF8 = new(allocator) UTF8Map(allocator, 0);
   classes = new(allocator) ClassMap();

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp Fri Nov 14 04:15:44 2008
@@ -230,6 +230,11 @@
   addPass(PM, createDeadStoreEliminationPass()); // Delete dead stores
   addPass(PM, createAggressiveDCEPass());        // Delete dead instructions
   addPass(PM, createCFGSimplificationPass());    // Merge & remove BBs
+
+#ifndef ISOLATE
+  if (mod->isStaticCompiling())
+#endif
+    addPass(PM, mvm::createLowerForcedCallsPass());    // Remove forced initialization
   
 }
 





More information about the vmkit-commits mailing list