[vmkit-commits] [vmkit] r197919 - hash interface methods with their name and signature, add an interface method dispatch table in the virtual table

Gael Thomas gael.thomas at lip6.fr
Mon Dec 23 12:21:02 PST 2013


Author: gthomas
Date: Mon Dec 23 14:21:01 2013
New Revision: 197919

URL: http://llvm.org/viewvc/llvm-project?rev=197919&view=rev
Log:
hash interface methods with their name and signature, add an interface method dispatch table in the virtual table

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

Modified: vmkit/branches/mcjit/include/j3/j3classloader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=197919&r1=197918&r2=197919&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3classloader.h (original)
+++ vmkit/branches/mcjit/include/j3/j3classloader.h Mon Dec 23 14:21:01 2013
@@ -32,10 +32,18 @@ namespace j3 {
 			bool operator()(const J3Method* lhs, const J3Method* rhs) const;
 		};
 
+		struct J3InterfaceMethodLess : public std::binary_function<wchar_t*,wchar_t*,bool> {
+			bool operator()(const J3Method* lhs, const J3Method* rhs) const;
+		};
+
 		typedef std::map<J3Method*, J3Method*, J3MethodLess,
 										 vmkit::StdAllocator<std::pair<J3Method*, J3Method*> > > MethodRefMap;
 
-		static J3MethodLess  j3MethodLess;
+		typedef std::map<J3Method*, uint32_t, J3InterfaceMethodLess,
+										 vmkit::StdAllocator<std::pair<J3Method*, J3Method*> > > InterfaceMethodRefMap;
+
+		static J3MethodLess           j3MethodLess;
+		static J3InterfaceMethodLess  j3InterfaceMethodLess;
 
 		J3ObjectHandle*                      _javaClassLoader;
 		J3GlobalReferences                   _globalReferences;
@@ -49,8 +57,8 @@ namespace j3 {
 		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                      _mutexInterfaces;
+		InterfaceMethodRefMap                interfaces; 
 
 		pthread_mutex_t                      _mutexMethods;
 		MethodRefMap                         methods;      /* all te known method */
@@ -67,7 +75,7 @@ namespace j3 {
 	public:
 		J3ClassLoader(J3* vm, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator);
 
-		uint32_t                      interfaceIndex(const vmkit::Name* sign);
+		uint32_t                      interfaceIndex(J3Method* sign);
 
 		J3GlobalReferences*           globalReferences() { return &_globalReferences; }
 		

Modified: vmkit/branches/mcjit/include/j3/j3object.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197919&r1=197918&r2=197919&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3object.h (original)
+++ vmkit/branches/mcjit/include/j3/j3object.h Mon Dec 23 14:21:01 2013
@@ -40,12 +40,14 @@ namespace j3 {
 
 	class J3VirtualTable {
 	public:
+		static const uint32_t nbInterfaceMethodTable = 23;
 		static const uint32_t gepObjectClass = 0;
-		static const uint32_t gepVirtualMethods = 3;
+		static const uint32_t gepVirtualMethods = 4;
 
 	private:
 		J3Type*               _type;
 		J3TypeChecker         checker;
+		void*                 _interfaceMethodTable[nbInterfaceMethodTable];
 		size_t                _nbVirtualMethods;
 		void*                 _virtualMethods[1];
 

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=197919&r1=197918&r2=197919&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Mon Dec 23 14:21:01 2013
@@ -18,7 +18,8 @@
 
 using namespace j3;
 
-J3ClassLoader::J3MethodLess J3ClassLoader::j3MethodLess;
+J3ClassLoader::J3MethodLess          J3ClassLoader::j3MethodLess;
+J3ClassLoader::J3InterfaceMethodLess J3ClassLoader::j3InterfaceMethodLess;
 
 J3ClassLoader::J3ClassLoader(J3* v, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator) 
 	: CompilationUnit(allocator, v, "class-loader"),
@@ -26,7 +27,7 @@ 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),
+		interfaces(j3InterfaceMethodLess, allocator),
 		methods(j3MethodLess, allocator),
 		nativeLibraries(allocator) {
 	_javaClassLoader = javaClassLoader;
@@ -34,23 +35,23 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob
 	pthread_mutex_init(&_mutexClasses, 0);
 	pthread_mutex_init(&_mutexTypes, 0);
 	pthread_mutex_init(&_mutexMethodTypes, 0);
-	pthread_mutex_init(&_mutexInterfaceSignatures, 0);
+	pthread_mutex_init(&_mutexInterfaces, 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 J3ClassLoader::interfaceIndex(J3Method* method) {
+	pthread_mutex_lock(&_mutexInterfaces);
+	InterfaceMethodRefMap::iterator it = interfaces.find(method);
 	uint32_t res;
 
-	if(it == interfaceSignatures.end()) {
-		res = interfaceSignatures.size();
-		interfaceSignatures[sign] = res;
+	if(it == interfaces.end()) {
+		res = interfaces.size();
+		interfaces[method] = res;
 	} else {
 		res = it->second;
 	}
 
-	pthread_mutex_unlock(&_mutexInterfaceSignatures);
+	pthread_mutex_unlock(&_mutexInterfaces);
 
 	return res;
 }
@@ -217,6 +218,12 @@ J3Method* J3ClassLoader::method(uint16_t
 	return method(access, names->get(clName), names->get(name), names->get(sign));
 }
 
+bool J3ClassLoader::J3InterfaceMethodLess::operator()(j3::J3Method const* lhs, j3::J3Method const* rhs) const {
+	return lhs->name() < rhs->name()
+		|| (lhs->name() == rhs->name()
+				&& (lhs->sign() < rhs->sign()));
+}
+
 bool J3ClassLoader::J3MethodLess::operator()(j3::J3Method const* lhs, j3::J3Method const* rhs) const {
 	return lhs->name() < rhs->name()
 		|| (lhs->name() == rhs->name()
@@ -267,11 +274,6 @@ J3ClassBytes* J3InitialClassLoader::look
 	return 0;
 }
 
-bool char_ptr_less::operator()(const char* lhs, const char* rhs) const {
-	//printf("Compare: %ls - %ls - %d\n", lhs, rhs, wcscmp(lhs, rhs));
-	return strcmp(lhs, rhs) < 0;
-}
-
 void J3InitialClassLoader::registerCMangling(const char* mangled, const char* demangled) {
 	_cmangled[demangled] = mangled;
 }

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=197919&r1=197918&r2=197919&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 23 14:21:01 2013
@@ -42,7 +42,7 @@ J3Method::J3Method(uint16_t access, J3Cl
 }
 
 uint32_t J3Method::interfaceIndex() {
-	return cl()->loader()->interfaceIndex(name());
+	return cl()->loader()->interfaceIndex(this);
 }
 
 uint32_t J3Method::index()  { 

Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197919&r1=197918&r2=197919&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Dec 23 14:21:01 2013
@@ -71,6 +71,9 @@ J3VirtualTable* J3VirtualTable::create(J
 	if(super != cl)  /* super->vt() is not yet allocated for Object */
 		memcpy(res->_virtualMethods, super->vt()->_virtualMethods, sizeof(void*)*super->vt()->nbVirtualMethods());
 
+	//	for(uint32_t i=0; i<nbInterfaceMethodTable; i++)
+	//		res->_interfaceMethodTable[i] = 
+
 	for(uint32_t i=0; i<cl->nbMethods(); i++) 
 		res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline();
 





More information about the vmkit-commits mailing list