[vmkit-commits] [vmkit] r83304 - in /vmkit/trunk: include/mvm/VirtualMachine.h lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/VMCore/JavaClass.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Oct 5 06:47:45 PDT 2009


Author: geoffray
Date: Mon Oct  5 08:47:44 2009
New Revision: 83304

URL: http://llvm.org/viewvc/llvm-project?rev=83304&view=rev
Log:
Use a JITEventListener to register a code pointer. This is necessary
for multithreaded applications, where a code pointer may be registered
after a thread calls it.


Modified:
    vmkit/trunk/include/mvm/VirtualMachine.h
    vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp

Modified: vmkit/trunk/include/mvm/VirtualMachine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=83304&r1=83303&r2=83304&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/VirtualMachine.h (original)
+++ vmkit/trunk/include/mvm/VirtualMachine.h Mon Oct  5 08:47:44 2009
@@ -382,8 +382,9 @@
     // Decrement because we had the "greater than" value.
     I--;
     
+    T* res = (T*)I->second;
     FunctionMapLock.release();
-    return (T*)I->second;
+    return res;
   }
 
   void setScanner(mvm::StackScanner* s) {

Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=83304&r1=83303&r2=83304&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Mon Oct  5 08:47:44 2009
@@ -14,6 +14,7 @@
 #include "llvm/Module.h"
 #include "llvm/CodeGen/GCStrategy.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/ExecutionEngine/JITEventListener.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -24,6 +25,7 @@
 #include "JavaClass.h"
 #include "JavaConstantPool.h"
 #include "JavaThread.h"
+#include "Jnjvm.h"
 
 #include "jnjvm/JnjvmModule.h"
 #include "jnjvm/JnjvmModuleProvider.h"
@@ -31,6 +33,27 @@
 using namespace jnjvm;
 using namespace llvm;
 
+class JavaJITListener : public llvm::JITEventListener {
+  JavaMethod* currentCompiledMethod;
+public:
+  virtual void NotifyFunctionEmitted(const Function &F,
+                                     void *Code, size_t Size,
+                                     const EmittedFunctionDetails &Details) {
+    if (currentCompiledMethod) {
+      assert(JavaLLVMCompiler::getMethod(currentCompiledMethod) == &F &&
+             "Method mismatch");
+      Jnjvm* vm = JavaThread::get()->getJVM();
+      vm->addMethodInFunctionMap(currentCompiledMethod, Code);
+    }
+  }
+
+  void setCurrentCompiledMethod(JavaMethod* meth) {
+    currentCompiledMethod = meth;
+  }
+};
+
+static JavaJITListener* JITListener = 0;
+
 Constant* JavaJITCompiler::getNativeClass(CommonClass* classDef) {
   const llvm::Type* Ty = classDef->isClass() ? JnjvmModule::JavaClassType :
                                                JnjvmModule::JavaCommonClassType;
@@ -161,6 +184,11 @@
 #endif
   TheModuleProvider = new JnjvmModuleProvider(TheModule, this);
   addJavaPasses();
+
+  if (!JITListener) {
+    JITListener = new JavaJITListener();
+    mvm::MvmModule::executionEngine->RegisterJITEventListener(JITListener);
+  }
 }
 
 #ifdef SERVICE
@@ -225,7 +253,9 @@
 void* JavaJITCompiler::materializeFunction(JavaMethod* meth) {
   mvm::MvmModule::protectIR();
   Function* func = parseFunction(meth);
+  JITListener->setCurrentCompiledMethod(meth);
   void* res = mvm::MvmModule::executionEngine->getPointerToGlobal(func);
+  JITListener->setCurrentCompiledMethod(0);
   func->deleteBody();
 
   // Update the GC info.

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Mon Oct  5 08:47:44 2009
@@ -314,8 +314,6 @@
     }
 #endif
     code = classDef->classLoader->getCompiler()->materializeFunction(this);
-    Jnjvm* vm = JavaThread::get()->getJVM();
-    vm->addMethodInFunctionMap(this, code);
   }
   
   return code;





More information about the vmkit-commits mailing list