[vmkit-commits] [vmkit] r197917 - use finer locks and define a map to record all the interface types

Gael Thomas gael.thomas at lip6.fr
Mon Dec 23 12:04:41 PST 2013


Author: gthomas
Date: Mon Dec 23 14:04:40 2013
New Revision: 197917

URL: http://llvm.org/viewvc/llvm-project?rev=197917&view=rev
Log:
use finer locks and define a map to record all the interface types

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

Modified: vmkit/branches/mcjit/include/j3/j3class.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197917&r1=197916&r2=197917&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3class.h (original)
+++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 23 14:04:40 2013
@@ -220,6 +220,8 @@ namespace j3 {
 		void          load();
 		void          doResolve(J3Field* hiddenFields, size_t nbHiddenFields);
 		void          doInitialise();
+
+		J3Method*     interfaceOrMethodAt(uint16_t idx, uint16_t access);
 	public:
 		J3Class(J3ClassLoader* loader, const vmkit::Name* name);
 
@@ -244,6 +246,7 @@ namespace j3 {
 		uint64_t            longAt(uint16_t idx);
 		J3ObjectHandle*     stringAt(uint16_t idx);
 		J3ObjectType*       classAt(uint16_t idx);
+		J3Method*           interfaceMethodAt(uint16_t idx, uint16_t access);
 		J3Method*           methodAt(uint16_t idx, uint16_t access);
 		J3Field*            fieldAt(uint16_t idx, uint16_t access);
 

Modified: vmkit/branches/mcjit/include/j3/j3classloader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=197917&r1=197916&r2=197917&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3classloader.h (original)
+++ vmkit/branches/mcjit/include/j3/j3classloader.h Mon Dec 23 14:04:40 2013
@@ -39,10 +39,20 @@ namespace j3 {
 
 		J3ObjectHandle*                      _javaClassLoader;
 		J3GlobalReferences                   _globalReferences;
-		pthread_mutex_t                      _mutex;       /* a lock */
+
+		pthread_mutex_t                      _mutexClasses;
 		vmkit::NameMap<J3Class*>::map        classes;      /* classes managed by this class loader */
+
+		pthread_mutex_t                      _mutexTypes;
 		vmkit::NameMap<J3Type*>::map         types;        /* shortcut to find types */
+
+		pthread_mutex_t                      _mutexMethodTypes;
 		vmkit::NameMap<J3MethodType*>::map   methodTypes;  /* shortcut to find method types - REMOVE */
+
+		pthread_mutex_t                      _mutexInterfaceSignatures;
+		vmkit::NameMap<uint32_t>::map        interfaceSignatures; 
+
+		pthread_mutex_t                      _mutexMethods;
 		MethodRefMap                         methods;      /* all te known method */
 
 		llvm::ExecutionEngine*               _ee;
@@ -57,13 +67,12 @@ namespace j3 {
 	public:
 		J3ClassLoader(J3* vm, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator);
 
+		uint32_t                      interfaceIndex(const vmkit::Name* sign);
+
 		J3GlobalReferences*           globalReferences() { return &_globalReferences; }
 		
 		J3ObjectHandle*               javaClassLoader() { return _javaClassLoader; }
 
-		void                          lock() { pthread_mutex_lock(&_mutex); }
-		void                          unlock() { pthread_mutex_unlock(&_mutex); }
-
 		J3*                           vm() const { return (J3*)vmkit::CompilationUnit::vm(); };
 
 		J3Method*                     method(uint16_t access, J3Class* cl, 

Modified: vmkit/branches/mcjit/include/j3/j3codegen.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=197917&r1=197916&r2=197917&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3codegen.h (original)
+++ vmkit/branches/mcjit/include/j3/j3codegen.h Mon Dec 23 14:04:40 2013
@@ -138,6 +138,7 @@ namespace j3 {
 		void               invokeVirtual(uint32_t idx);
 		void               invokeStatic(uint32_t idx);
 		void               invokeSpecial(uint32_t idx);
+		void               invokeInterface(uint32_t idx);
 
 		llvm::Value*       arrayContent(J3Type* cType, llvm::Value* array, llvm::Value* idx);
 

Modified: vmkit/branches/mcjit/include/j3/j3method.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=197917&r1=197916&r2=197917&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3method.h (original)
+++ vmkit/branches/mcjit/include/j3/j3method.h Mon Dec 23 14:04:40 2013
@@ -80,6 +80,8 @@ namespace j3 {
 	public:
 		J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign);
 
+		uint32_t            interfaceIndex();
+
 		void*               getSymbolAddress();
 
 		char*               llvmFunctionName(J3Class* from=0);

Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197917&r1=197916&r2=197917&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 23 14:04:40 2013
@@ -637,13 +637,12 @@ uint64_t J3Class::longAt(uint16_t idx) {
 	return ((uint64_t)ctpValues[idx] << 32) + (uint64_t)ctpValues[idx+1];
 }
 
-J3Method* J3Class::methodAt(uint16_t idx, uint16_t access) {
-	check(idx, J3Cst::CONSTANT_Methodref);
+J3Method* J3Class::interfaceOrMethodAt(uint16_t idx, uint16_t access) {
 	J3Method* res = (J3Method*)ctpResolved[idx];
 	
 	if(res) {
 		if((res->access() & J3Cst::ACC_STATIC) != (access & J3Cst::ACC_STATIC))
-			J3::classFormatError(this, L"inconstitent use of virtual and static methods"); 
+			J3::classFormatError(this, L"inconsistent use of virtual and static methods"); 
 		return res;
 	}
 
@@ -659,6 +658,16 @@ J3Method* J3Class::methodAt(uint16_t idx
 	return res;
 }
 
+J3Method* J3Class::methodAt(uint16_t idx, uint16_t access) {
+	check(idx, J3Cst::CONSTANT_Methodref);
+	return interfaceOrMethodAt(idx, access);
+}
+
+J3Method* J3Class::interfaceMethodAt(uint16_t idx, uint16_t access) {
+	check(idx, J3Cst::CONSTANT_InterfaceMethodref);
+	return interfaceOrMethodAt(idx, access);
+}
+
 J3Field* J3Class::fieldAt(uint16_t idx, uint16_t access) {
 	check(idx, J3Cst::CONSTANT_Fieldref);
 	J3Field* res = (J3Field*)ctpResolved[idx];

Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=197917&r1=197916&r2=197917&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Mon Dec 23 14:04:40 2013
@@ -26,14 +26,33 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob
 		classes(vmkit::Name::less, allocator),
 		types(vmkit::Name::less, allocator),
 		methodTypes(vmkit::Name::less, allocator), 
+		interfaceSignatures(vmkit::Name::less, allocator),
 		methods(j3MethodLess, allocator),
 		nativeLibraries(allocator) {
 	_javaClassLoader = javaClassLoader;
 
-	//	pthread_mutexattr_t attr;
-	//	pthread_mutexattr_init(&attr);
-	//	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-	pthread_mutex_init(&_mutex, 0);//&attr);
+	pthread_mutex_init(&_mutexClasses, 0);
+	pthread_mutex_init(&_mutexTypes, 0);
+	pthread_mutex_init(&_mutexMethodTypes, 0);
+	pthread_mutex_init(&_mutexInterfaceSignatures, 0);
+	pthread_mutex_init(&_mutexMethods, 0);
+}
+
+uint32_t J3ClassLoader::interfaceIndex(const vmkit::Name* sign) {
+	pthread_mutex_lock(&_mutexInterfaceSignatures);
+	std::map<const vmkit::Name*, uint32_t>::iterator it = interfaceSignatures.find(sign);
+	uint32_t res;
+
+	if(it == interfaceSignatures.end()) {
+		res = interfaceSignatures.size();
+		interfaceSignatures[sign] = res;
+	} else {
+		res = it->second;
+	}
+
+	pthread_mutex_unlock(&_mutexInterfaceSignatures);
+
+	return res;
 }
 
 void* J3ClassLoader::lookupNativeFunctionPointer(J3Method* method, const char* symbol) {
@@ -47,11 +66,11 @@ void* J3ClassLoader::lookupNativeFunctio
 }
 
 J3Class* J3ClassLoader::getClass(const vmkit::Name* name) {
-	lock();
+	pthread_mutex_lock(&_mutexClasses);
 	J3Class* res = classes[name];
 	if(!res)
 		classes[name] = res = new(allocator()) J3Class(this, name);
-	unlock();
+	pthread_mutex_unlock(&_mutexClasses);
 	return res;
 }
 
@@ -119,9 +138,9 @@ J3Type* J3ClassLoader::getTypeInternal(J
 }
 
 J3Type* J3ClassLoader::getType(J3Class* from, const vmkit::Name* type) {
-	lock();
+	pthread_mutex_lock(&_mutexTypes);
 	J3Type* res = types[type];
-	unlock();
+	pthread_mutex_unlock(&_mutexTypes);
 
 	if(!res) {
 		uint32_t end;
@@ -132,18 +151,18 @@ J3Type* J3ClassLoader::getType(J3Class*
 
 		//printf("Analyse %ls => %ls\n", type->cStr(), res->name()->cStr());
 		
-		lock();
+		pthread_mutex_lock(&_mutexTypes);
 		types[type] = res;
-		unlock();
+		pthread_mutex_unlock(&_mutexTypes);
 	}
 
 	return res;
 }
 
 J3MethodType* J3ClassLoader::getMethodType(J3Class* from, const vmkit::Name* sign) {
-	lock();
+	pthread_mutex_lock(&_mutexMethodTypes);
 	J3MethodType* res = methodTypes[sign];
-	unlock();
+	pthread_mutex_unlock(&_mutexMethodTypes);
 
 	if(!res) {
 		J3Type*  args[sign->length()];
@@ -160,13 +179,13 @@ J3MethodType* J3ClassLoader::getMethodTy
 		if(cur != sign->length())
 			wrongType(from, sign);
 
-		lock();
+		pthread_mutex_lock(&_mutexMethodTypes);
 		J3MethodType* tmp = methodTypes[sign];
 		if(tmp)
 			res = tmp;
 		else
 			res = new(allocator(), nbArgs - 1) J3MethodType(args, nbArgs);
-		unlock();
+		pthread_mutex_unlock(&_mutexMethodTypes);
 	}
 
 	return res;
@@ -175,7 +194,7 @@ J3MethodType* J3ClassLoader::getMethodTy
 J3Method* J3ClassLoader::method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign) {
 	J3Method method(access, cl, name, sign), *res;
 
-	lock();
+	pthread_mutex_lock(&_mutexMethods);
 	std::map<J3Method*, J3Method*>::iterator it = methods.find(&method);
 
 	if(it == methods.end()) {
@@ -184,7 +203,7 @@ J3Method* J3ClassLoader::method(uint16_t
 	} else {
 		res = it->second;
 	}
-	unlock();
+	pthread_mutex_unlock(&_mutexMethods);
 
 	return res;
 }

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=197917&r1=197916&r2=197917&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 23 14:04:40 2013
@@ -262,6 +262,12 @@ void J3CodeGen::invoke(J3Method* target,
 	}
 }
 
+void J3CodeGen::invokeInterface(uint32_t idx) {
+	J3Method*     target = cl->interfaceMethodAt(idx, 0);
+	fprintf(stderr, "---> %d\n", target->interfaceIndex());
+	J3::internalError(L"implement me: invokeInterface");
+}
+
 void J3CodeGen::invokeVirtual(uint32_t idx) {
 	J3Method*     target = cl->methodAt(idx, 0);
 	J3MethodType* type = target->methodType(cl);
@@ -1250,7 +1256,11 @@ void J3CodeGen::translate() {
 				invokeStatic(codeReader->readU2());
 				break;
 
-			case J3Cst::BC_invokeinterface: nyi();        /* 0xb9 */
+			case J3Cst::BC_invokeinterface:               /* 0xb9 */
+				invokeInterface(codeReader->readU2());
+				codeReader->readU2();
+				break;
+
 			case J3Cst::BC_new:                           /* 0xbb */
 				newObject(cl->classAt(codeReader->readU2())->asClass());
 				break;

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=197917&r1=197916&r2=197917&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 23 14:04:40 2013
@@ -41,6 +41,10 @@ J3Method::J3Method(uint16_t access, J3Cl
 	_index = -1;
 }
 
+uint32_t J3Method::interfaceIndex() {
+	return cl()->loader()->interfaceIndex(name());
+}
+
 uint32_t J3Method::index()  { 
 	return _index; 
 }





More information about the vmkit-commits mailing list