[vmkit-commits] [vmkit] r197971 - better method lookup + create the vt of an object array

Gael Thomas gael.thomas at lip6.fr
Tue Dec 24 01:34:45 PST 2013


Author: gthomas
Date: Tue Dec 24 03:34:44 2013
New Revision: 197971

URL: http://llvm.org/viewvc/llvm-project?rev=197971&view=rev
Log:
better method lookup + create the vt of an object array

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

Modified: vmkit/branches/mcjit/include/j3/j3class.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197971&r1=197970&r2=197971&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3class.h (original)
+++ vmkit/branches/mcjit/include/j3/j3class.h Tue Dec 24 03:34:44 2013
@@ -153,6 +153,8 @@ namespace j3 {
 	public:
 		J3ObjectType(J3ClassLoader* loader, const vmkit::Name* name);
 
+		void prepareInterfaceTable();
+
 		virtual J3Method* findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error=1);
 		virtual J3Method* findStaticMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error=1);
 

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=197971&r1=197970&r2=197971&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 24 03:34:44 2013
@@ -156,6 +156,32 @@ J3ObjectHandle* J3ObjectType::javaClass(
 	return _javaClass;
 }
 
+void J3ObjectType::prepareInterfaceTable() {
+#if 0
+	struct {
+		uint32_t   nbSlots;
+		J3Method** slots;
+	} slots[nbInterfaceMethodTable];
+	
+	for(uint32_t i=0; i<nbInterfaceMethodTable; i++)
+		slots[i].nbSlots = 0;
+
+	for(uint32_t i=0; i<res->checker.nbSecondaryTypes; i++) {
+		J3Class* ifce = res->checker.secondaryTypes[i]->type()->asClass();
+		fprintf(stderr, "processing: %ls from %ls\n", ifce->name()->cStr(), cl->name()->cStr());
+		if(J3Cst::isInterface(ifce->access())) {
+			for(uint32_t j=0; j<ifce->nbMethods(); j++) {
+				J3Method* base = ifce->methods()[j];
+				fprintf(stderr, "  %s lookup %ls %ls::%ls in %ls\n", 
+								J3Cst::isAbstract(base->access()) ? "abstract" : "concrete",
+								base->sign()->cStr(), base->cl()->name()->cStr(), base->name()->cStr(), cl->name()->cStr());
+				J3Method* method = cl->findVirtualMethod(base->name(), base->sign(), 1);
+			}
+		}
+	}
+#endif
+}
+
 /*  
  *  ------------ J3Layout ------------
  */
@@ -208,29 +234,44 @@ J3Method* J3Class::findVirtualMethod(con
 	//loader()->vm()->log(L"Lookup: %ls %ls in %ls (%d)", methName->cStr(), methSign->cStr(), name()->cStr(), nbVirtualMethods);
 	resolve();
 
-	J3Method* res = findMethod(name, sign);
+	J3Class* cur = this;
+	J3Method* res;
+	while(1) {
+		res = cur->findMethod(name, sign);
 
-	if(!res) {
-		if(super() == this) {
+		if(res)
+			return res;
+
+		if(cur == cur->super()) {
 			if(error)
 				J3::noSuchMethodError(L"no such method", this, name, sign);
 			else
 				return 0;
 		}
-		res = super()->findVirtualMethod(name, sign, error);
+		cur = cur->super();
 	}
-
-	return res;
 }
 
 J3Method* J3Class::findStaticMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error) {
 	//loader()->vm()->log(L"Lookup: %ls %ls in %ls", methName->cStr(), methSign->cStr(), name()->cStr());
 	resolve();
 
-	J3Method* res = staticLayout.findMethod(name, sign);
+	J3Class* cur = this;
+	J3Method* res;
+	while(1) {
+		res = cur->staticLayout.findMethod(name, sign);
 
-	if(!res)
-		J3::internalError(L"implement me");
+		if(res)
+			return res;
+
+		if(cur == cur->super()) {
+			if(error)
+				J3::noSuchMethodError(L"no such method", this, name, sign);
+			else
+				return 0;
+		}
+		cur = cur->super();
+	}
 
 	return res;
 }
@@ -372,6 +413,8 @@ void J3Class::doResolve(J3Field* hiddenF
 
 		_vt = J3VirtualTable::create(this);
 
+		prepareInterfaceTable();
+
 		//fprintf(stderr, "virtual part of %ls: ", name()->cStr());
 		//llvmType()->getContainedType(0)->dump();
 		//fprintf(stderr, "\n");
@@ -379,17 +422,6 @@ void J3Class::doResolve(J3Field* hiddenF
 	unlock();
 }
 
-#if 0
-void J3Class::addHiddenField(J3Field* f, uint32_t num) {
-	if(this == loader()->vm()->classClass) {
-		f->_access     = J3Cst::ACC_PRIVATE;
-		f->_name       = loader()->vm()->names()->get(L"vmData");
-		f->_type       = (sizeof(uintptr_t) == 8) ? loader()->vm()->typeLong : loader()->vm()->typeInteger;
-		f->_attributes = new (loader()->allocator(), 0) J3Attributes(0);
-	}
-}
-#endif
-
 void J3Class::readClassBytes(std::vector<llvm::Type*>* virtualBody, J3Field* hiddenFields, uint32_t nbHiddenFields) {
 	J3Reader reader(_bytes);
 
@@ -833,6 +865,7 @@ void J3ArrayClass::doResolve(J3Field* hi
 		J3Class* objectClass = loader()->vm()->objectClass;
 		objectClass->resolve();
 		_vt = J3VirtualTable::create(this);
+		prepareInterfaceTable();
 	}
 	unlock();
 }

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=197971&r1=197970&r2=197971&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Tue Dec 24 03:34:44 2013
@@ -62,38 +62,26 @@ J3VirtualTable* J3VirtualTable::create(J
 		}
 	}
 
+	/* virtual table */
+	uint32_t isConcrete = !J3Cst::isInterface(cl->access()) && ! J3Cst::isAbstract(cl->access());
+
+	n = isConcrete ? n : 0;
+
 	J3VirtualTable* res = new(cl->loader()->allocator(), n) 
 		J3VirtualTable(cl, cl->super(), (J3Type**)cl->interfaces(), cl->nbInterfaces(), J3Cst::isInterface(cl->access()) ? 1 : 0);
-
-	/* virtual table */
 	res->_nbVirtualMethods = n;
-	if(super != cl)  /* super->vt() is not yet allocated for Object */
-		memcpy(res->_virtualMethods, super->vt()->_virtualMethods, sizeof(void*)*super->vt()->nbVirtualMethods());
 
-	struct {
-		uint32_t   nbSlots;
-		J3Method** slots;
-	} slots[nbInterfaceMethodTable];
-	
-	for(uint32_t i=0; i<nbInterfaceMethodTable; i++)
-		slots[i].nbSlots = 0;
-
-	for(uint32_t i=0; i<res->checker.nbSecondaryTypes; i++) {
-		J3Class* cl = res->checker.secondaryTypes[i]->type()->asClass();
-		if(J3Cst::isInterface(cl->access())) {
-			for(uint32_t j=0; j<cl->nbMethods(); j++) {
-				J3Method* m = cl->methods()[j];
-				fprintf(stderr, "[%d] method: %ls::%ls\n", i, cl->name()->cStr(), m->name()->cStr());
-			}
-		}
-	}
-
-	void* interfaceTrampoline = cl->loader()->vm()->interfaceTrampoline;
-	for(uint32_t i=0; i<nbInterfaceMethodTable; i++)
-		res->_interfaceMethodTable[i] = interfaceTrampoline;
+	if(isConcrete) {
+		if(super != cl)  /* super->vt() is not yet allocated for Object */
+			memcpy(res->_virtualMethods, super->vt()->_virtualMethods, sizeof(void*)*super->vt()->nbVirtualMethods());
+
+		void* interfaceTrampoline = cl->loader()->vm()->interfaceTrampoline;
+		for(uint32_t i=0; i<nbInterfaceMethodTable; i++)
+			res->_interfaceMethodTable[i] = interfaceTrampoline;
 
-	for(uint32_t i=0; i<cl->nbMethods(); i++) 
-		res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline();
+		for(uint32_t i=0; i<cl->nbMethods(); i++) 
+			res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline();
+	}
 
 	return res;
 }
@@ -159,8 +147,10 @@ J3VirtualTable* J3VirtualTable::create(J
 
 	super->resolve();
 
-	J3VirtualTable* res = new(cl->loader()->allocator(), 0) J3VirtualTable(cl, super, secondaries, nbSecondaries, isSecondary);
-	//memcpy(_virtualMethods, objClass->vt()->virtualMethods(), sizeof(void*)*objClass->nbVt());
+	J3VirtualTable* res = new(cl->loader()->allocator(), objClass->vt()->_nbVirtualMethods) 
+		J3VirtualTable(cl, super, secondaries, nbSecondaries, isSecondary);
+
+	memcpy(res->_virtualMethods, objClass->vt()->_virtualMethods, sizeof(void*)*objClass->vt()->_nbVirtualMethods);
 
 	return res;
 }





More information about the vmkit-commits mailing list