[vmkit-commits] [vmkit] r65329 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaJIT.cpp JavaJIT.h JnjvmModule.cpp JnjvmModule.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Feb 23 09:55:58 PST 2009


Author: geoffray
Date: Mon Feb 23 11:55:58 2009
New Revision: 65329

URL: http://llvm.org/viewvc/llvm-project?rev=65329&view=rev
Log:
Devirtualize virtual calls to final fields.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Mon Feb 23 11:55:58 2009
@@ -77,18 +77,25 @@
   ctpInfo->infoOfMethod(index, ACC_VIRTUAL, cl, meth);
  
   if ((cl && isFinal(cl->access)) || 
-      (meth && (isFinal(meth->access) || isPrivate(meth->access))))
+      (meth && (isFinal(meth->access) || isPrivate(meth->access)))) {
     return invokeSpecial(index);
+  }
 
   // If the method is in fact a method defined in an interface,
   // call invokeInterface instead.
   if (meth && isInterface(meth->classDef->access)) {
     return invokeInterface(index, true);
   }
-
-#if !defined(WITHOUT_VTABLE)
+  
   const UTF8* name = 0;
   Signdef* signature = ctpInfo->infoOfInterfaceOrVirtualMethod(index, name);
+  Value* obj = stack[signature->nbArguments].first;
+  JavaObject* source = module->getFinalObject(obj);
+  if (source) {
+    return invokeSpecial(index, source->getClass());
+  }
+ 
+#if !defined(WITHOUT_VTABLE)
   Typedef* retTypedef = signature->getReturnType();
   std::vector<Value*> args; // size = [signature->nbIn + 3];
   LLVMSignatureInfo* LSI = module->getSignatureInfo(signature);
@@ -96,8 +103,9 @@
   FunctionType::param_iterator it  = virtualType->param_end();
   makeArgs(it, index, args, signature->nbArguments + 1);
   const llvm::Type* retType = virtualType->getReturnType();
-  
-  JITVerifyNull(args[0]); 
+   
+  JITVerifyNull(args[0]);
+
   BasicBlock* endBlock = 0;
   PHINode* node = 0;
 #if 0
@@ -1218,7 +1226,7 @@
   return ret;
 }
 
-void JavaJIT::invokeSpecial(uint16 index) {
+void JavaJIT::invokeSpecial(uint16 index, CommonClass* finalCl) {
   JavaConstantPool* ctpInfo = compilingClass->ctpInfo;
   JavaMethod* meth = 0;
   Signdef* signature = 0;
@@ -1230,13 +1238,27 @@
   const llvm::FunctionType* virtualType = LSI->getVirtualType();
   llvm::Instruction* val = 0;
   
-  std::vector<Value*> args; 
+  std::vector<Value*> args;
   FunctionType::param_iterator it  = virtualType->param_end();
   makeArgs(it, index, args, signature->nbArguments + 1);
+  Function* func = 0;
+
+  if (finalCl) {
+    Class* lookup = finalCl->isArray() ? finalCl->super : finalCl->asClass();
+
+    meth = lookup->lookupMethodDontThrow(name, signature->keyName, false, true,
+                                         0);
+    if (meth) {
+      // don't throw if no meth, the exception will be thrown just in time
+      JnjvmModule* M = compilingClass->classLoader->getModule();
+      func = M->getMethod(meth);
+    }
+  }
   
-  Function* func =   
-    (Function*)ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL,
-                                                      signature, meth);
+  if (!func) {
+    func = (Function*)ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL,
+                                                           signature, meth);
+  }
   
   if (meth == compilingClass->classLoader->bootstrapLoader->upcalls->InitObject)
     return;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h Mon Feb 23 11:55:58 2009
@@ -365,7 +365,7 @@
   void invokeInterface(uint16 index, bool buggyVirtual = false);
 
   /// invokeSpecial - Invoke an instance Java method directly.
-  void invokeSpecial(uint16 index);
+  void invokeSpecial(uint16 index, CommonClass* finalCl = 0);
 
   /// invokeStatic - Invoke a static Java method.
   void invokeStatic(uint16 index);

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Mon Feb 23 11:55:58 2009
@@ -310,6 +310,21 @@
   }
 }
 
+JavaObject* JnjvmModule::getFinalObject(llvm::Value* obj) {
+  if (staticCompilation) {
+    abort();
+  } else {
+    if (ConstantExpr* CE = dyn_cast<ConstantExpr>(obj)) {
+      if (ConstantInt* C = dyn_cast<ConstantInt>(CE->getOperand(0))) {
+        return (JavaObject*)C->getZExtValue();
+      }
+    }
+  }
+  return 0;
+}
+
+
+
 Constant* JnjvmModule::getFinalObject(JavaObject* obj) {
   if (staticCompilation) {
     final_object_iterator End = finalObjects.end();

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h Mon Feb 23 11:55:58 2009
@@ -424,6 +424,7 @@
   void printStats();
 
   llvm::Constant* getFinalObject(JavaObject* obj);
+  JavaObject* getFinalObject(llvm::Value* C);
   llvm::Constant* getNativeClass(CommonClass* cl);
   llvm::Constant* getJavaClass(CommonClass* cl);
   llvm::Constant* getStaticInstance(Class* cl);





More information about the vmkit-commits mailing list