[vmkit-commits] [vmkit] r198219 - ensure that llvmFunction and llvmFunctionType are only called while the compiler lock is held

Gael Thomas gael.thomas at lip6.fr
Mon Dec 30 09:02:13 PST 2013


Author: gthomas
Date: Mon Dec 30 11:02:13 2013
New Revision: 198219

URL: http://llvm.org/viewvc/llvm-project?rev=198219&view=rev
Log:
ensure that llvmFunction and llvmFunctionType are only called while the compiler lock is held

Modified:
    vmkit/branches/mcjit/include/j3/j3method.h
    vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
    vmkit/branches/mcjit/lib/j3/vm/j3method.cc

Modified: vmkit/branches/mcjit/include/j3/j3method.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=198219&r1=198218&r2=198219&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3method.h (original)
+++ vmkit/branches/mcjit/include/j3/j3method.h Mon Dec 30 11:02:13 2013
@@ -28,7 +28,7 @@ namespace j3 {
 	class J3ObjectHandle;
 
 	class J3MethodType : public vmkit::PermanentObject {
-		llvm::FunctionType* volatile _llvmType;
+		llvm::FunctionType* volatile _llvmFunctionType;
 		J3Type*                      _out;
 		uint32_t                     _nbIns;
 		J3Type*                      _ins[1];
@@ -36,7 +36,7 @@ namespace j3 {
 	public:
 		J3MethodType(J3Type** args, size_t nbArgs);
 
-		llvm::FunctionType* llvmType();
+		llvm::FunctionType* llvmFunctionType(); /* only call this function from j3codegen */
 		uint32_t            nbIns() { return _nbIns; }
 		J3Type*             out() { return _out; }
 		J3Type*             ins(uint32_t idx) { return _ins[idx]; }
@@ -96,7 +96,7 @@ namespace j3 {
 
 		llvm::Function*     nativeLLVMFunction(llvm::Module* module);
 		llvm::GlobalValue*  llvmDescriptor(llvm::Module* module);
-		llvm::Function*     llvmFunction(bool isStub, llvm::Module* module, J3Class* from=0);
+		llvm::Function*     llvmFunction(bool isStub, llvm::Module* module, J3Class* from=0); /* only call from J3CodeGen */
 
 		uint32_t            index();
 		uint32_t*           indexPtr() { return &_index; }

Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198219&r1=198218&r2=198219&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 11:02:13 2013
@@ -107,9 +107,7 @@ void J3CodeGen::operator delete(void* pt
 
 void J3CodeGen::translate(J3Method* method, llvm::Function* llvmFunction) {
 	vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create();
-	method->cl()->loader()->vm()->lockCompiler();
 	delete new(allocator) J3CodeGen(allocator, method, llvmFunction);
-	method->cl()->loader()->vm()->unlockCompiler();
 	vmkit::BumpAllocator::destroy(allocator);
 }
 
@@ -367,7 +365,7 @@ void J3CodeGen::invokeInterface(uint32_t
 															builder->getInt32(J3VirtualTable::gepInterfaceMethods),
 															builder->getInt32(index % J3VirtualTable::nbInterfaceMethodTable) };
 	llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)), 
-																						 type->llvmType()->getPointerTo());
+																						 type->llvmFunctionType()->getPointerTo());
 
 	invoke(target, func);
 }
@@ -387,7 +385,7 @@ void J3CodeGen::invokeVirtual(uint32_t i
 															builder->getInt32(J3VirtualTable::gepVirtualMethods),
 															funcEntry };
 	llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)), 
-																						 type->llvmType()->getPointerTo());
+																						 type->llvmFunctionType()->getPointerTo());
 
 	invoke(target, func);
 }

Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198219&r1=198218&r2=198219&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 30 11:02:13 2013
@@ -28,14 +28,14 @@ J3MethodType::J3MethodType(J3Type** args
 			
 }
 
-llvm::FunctionType* J3MethodType::llvmType() {
-	if(!_llvmType) {
+llvm::FunctionType* J3MethodType::llvmFunctionType() {
+	if(!_llvmFunctionType) {
 		std::vector<llvm::Type*> in;
 		for(uint32_t i=0; i<nbIns(); i++)
 			in.push_back(ins(i)->llvmType());
-		_llvmType = llvm::FunctionType::get(out()->llvmType(), in, 0);
+		_llvmFunctionType = llvm::FunctionType::get(out()->llvmType(), in, 0);
 	}
-	return _llvmType;
+	return _llvmFunctionType;
 }
 
 J3Method::J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign) :
@@ -67,6 +67,7 @@ void* J3Method::fnPtr() {
 				J3::noSuchMethodError(L"unable to find method", cl(), name(), sign());
 		}
 
+		cl()->loader()->vm()->lockCompiler();
 		llvm::Module* module = new llvm::Module(llvmFunctionName(), cl()->loader()->vm()->llvmContext());
 		_llvmFunction = llvmFunction(0, module);
 
@@ -75,6 +76,7 @@ void* J3Method::fnPtr() {
 		cl()->loader()->compileModule(module);
 
 		_fnPtr = (void*)cl()->loader()->ee()->getFunctionAddress(_llvmFunction->getName().data());
+		cl()->loader()->vm()->unlockCompiler();
  	}
 
 	return _fnPtr;
@@ -337,7 +339,7 @@ llvm::GlobalValue* J3Method::llvmDescrip
 
 llvm::Function* J3Method::llvmFunction(bool isStub, llvm::Module* module, J3Class* from) {
 	const char* id = (isStub && !_fnPtr) ? llvmStubName(from) : llvmFunctionName(from);
-	return (llvm::Function*)module->getOrInsertFunction(id, methodType(from ? from : cl())->llvmType());
+	return (llvm::Function*)module->getOrInsertFunction(id, methodType(from ? from : cl())->llvmFunctionType());
 }
 
 void J3Method::dump() {





More information about the vmkit-commits mailing list