[vmkit-commits] [vmkit] r198329 - Correct dispatch of array functions.

Gael Thomas gael.thomas at lip6.fr
Thu Jan 2 10:29:19 PST 2014


Author: gthomas
Date: Thu Jan  2 12:29:19 2014
New Revision: 198329

URL: http://llvm.org/viewvc/llvm-project?rev=198329&view=rev
Log:
Correct dispatch of array functions.

Modified:
    vmkit/branches/mcjit/include/j3/j3class.h
    vmkit/branches/mcjit/include/j3/j3classloader.h
    vmkit/branches/mcjit/include/j3/j3mangler.h
    vmkit/branches/mcjit/include/j3/j3method.h
    vmkit/branches/mcjit/lib/j3/vm/j3.cc
    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/j3mangler.cc
    vmkit/branches/mcjit/lib/j3/vm/j3method.cc
    vmkit/branches/mcjit/lib/j3/vm/j3object.cc
    vmkit/branches/mcjit/lib/j3/vm/j3options.cc

Modified: vmkit/branches/mcjit/include/j3/j3class.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3class.h (original)
+++ vmkit/branches/mcjit/include/j3/j3class.h Thu Jan  2 12:29:19 2014
@@ -270,6 +270,9 @@ namespace j3 {
 
 		J3Type*             component() { return _component; }
 		bool                isArrayClass() { return 1; }
+
+		J3Method*           findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error=1);
+		J3Method*           findStaticMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error=1);
 	};
 
 	class J3Primitive : public J3Type {

Modified: vmkit/branches/mcjit/include/j3/j3classloader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3classloader.h (original)
+++ vmkit/branches/mcjit/include/j3/j3classloader.h Thu Jan  2 12:29:19 2014
@@ -63,8 +63,8 @@ namespace j3 {
 	public:
 		J3ClassLoader(J3* vm, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator);
 
-		J3Type*                       getTypeInternal(J3ObjectType* from, const vmkit::Name* type, uint32_t start, uint32_t* end);
-		void                          wrongType(J3ObjectType* from, const vmkit::Name* type);
+		J3Type*                       getTypeInternal(J3Class* from, const vmkit::Name* type, uint32_t start, uint32_t* end);
+		void                          wrongType(J3Class* from, const vmkit::Name* type);
 
 		uint32_t                      interfaceIndex(J3Method* sign);
 

Modified: vmkit/branches/mcjit/include/j3/j3mangler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3mangler.h?rev=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3mangler.h (original)
+++ vmkit/branches/mcjit/include/j3/j3mangler.h Thu Jan  2 12:29:19 2014
@@ -8,24 +8,24 @@ namespace vmkit {
 }
 
 namespace j3 {
-	class J3ObjectType;
+	class J3Class;
 	class J3Method;
 
 	class J3Mangler {
 		static const uint32_t max = 65536;
 
-		J3ObjectType* from;
-		char          buf[max];
-		char*         cur;
-		char*         next;
+		J3Class* from;
+		char     buf[max];
+		char*    cur;
+		char*    next;
 
-		void          check(uint32_t n);
+		void     check(uint32_t n);
 
 	public:
 		static const char*    j3Id;
 		static const char*    javaId;
 
-		J3Mangler(J3ObjectType* from);
+		J3Mangler(J3Class* from);
 
 		char*    cStr() { return buf; }
 		uint32_t length() { return cur - buf; }

Modified: vmkit/branches/mcjit/include/j3/j3method.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3method.h (original)
+++ vmkit/branches/mcjit/include/j3/j3method.h Thu Jan  2 12:29:19 2014
@@ -58,7 +58,7 @@ namespace j3 {
 	public:
 		J3MethodCode                 _selfCode;
 		uint16_t                     _access;
-		J3ObjectType*                _cl;
+		J3Class*                     _cl;
 		const vmkit::Name*           _name;
 		const vmkit::Name*           _sign;
 		J3MethodType*                _methodType;
@@ -76,9 +76,9 @@ namespace j3 {
 		J3Value            internalInvoke(bool statically, J3ObjectHandle* handle, va_list va);
 		J3Value            internalInvoke(bool statically, J3ObjectHandle* handle, J3Value* args);
 		J3Value            internalInvoke(bool statically, J3Value* args);
-		void               buildLLVMNames(J3ObjectType* from);
+		void               buildLLVMNames(J3Class* from);
 	public:
-		J3Method(uint16_t access, J3ObjectType* cl, const vmkit::Name* name, const vmkit::Name* sign);
+		J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign);
 
 		uint32_t            slot() { return _slot; }
 
@@ -108,10 +108,10 @@ namespace j3 {
 
 		J3Attributes*       attributes() const { return _attributes; }
 		uint16_t            access() const { return _access; }
-		J3ObjectType*       cl()     const { return _cl; }
+		J3Class*            cl()     const { return _cl; }
 		const vmkit::Name*  name()   const { return _name; }
 		const vmkit::Name*  sign()   const { return _sign; }
-		J3MethodType*       methodType(J3ObjectType* from=0);
+		J3MethodType*       methodType(J3Class* from=0);
 
 		void                registerNative(void* ptr);
 

Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Thu Jan  2 12:29:19 2014
@@ -110,6 +110,7 @@ void J3::run() {
 
 	charArrayClass           = typeChar->getArray();
 	objectClass              = z_class("java/lang/Object");
+	objectClass->resolve();
 	
 	stringClass              = z_class("java/lang/String");
 	stringClassInit          = z_method(0, stringClass, initName, names()->get("([CZ)V"));
@@ -242,8 +243,8 @@ void J3::vinternalError(const char* msg,
 	vsnprintf(buf, 65536, msg, va);
 	fprintf(stderr, "Internal error: %s\n", buf);
 	printStackTrace();
-	//exit(1);
-	abort();
+	exit(1);
+	//abort();
 }
 
 void J3::printStackTrace() {

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=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Thu Jan  2 12:29:19 2014
@@ -860,12 +860,18 @@ J3ArrayClass::J3ArrayClass(J3ClassLoader
 	}
 }
 
+J3Method* J3ArrayClass::findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error) {
+	return loader()->vm()->objectClass->findVirtualMethod(name, sign, error);
+}
+
+J3Method* J3ArrayClass::findStaticMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error) {
+	return loader()->vm()->objectClass->findStaticMethod(name, sign, error);
+}
+
 void J3ArrayClass::doResolve(J3Field* hiddenFields, size_t nbHiddenFields) {
 	lock();
 	if(status < RESOLVED) {
 		status = RESOLVED;
-		J3Class* objectClass = loader()->vm()->objectClass;
-		objectClass->resolve();
 		_vt = J3VirtualTable::create(this);
 		prepareInterfaceTable();
 	}

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=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Thu Jan  2 12:29:19 2014
@@ -85,11 +85,11 @@ J3Class* J3ClassLoader::loadClass(const
 	J3::internalError("implement me: loadClass from a Java class loader");
 }
 
-void J3ClassLoader::wrongType(J3ObjectType* from, const vmkit::Name* type) {
+void J3ClassLoader::wrongType(J3Class* from, const vmkit::Name* type) {
 	J3::classFormatError(from, "wrong type: %s", type->cStr());
 }
 
-J3Type* J3ClassLoader::getTypeInternal(J3ObjectType* from, const vmkit::Name* typeName, uint32_t start, uint32_t* pend) {
+J3Type* J3ClassLoader::getTypeInternal(J3Class* from, const vmkit::Name* typeName, uint32_t start, uint32_t* pend) {
 	J3Type*        res  = 0;
 	const char*    type = typeName->cStr();
 	uint32_t       len  = typeName->length();
@@ -166,21 +166,26 @@ J3Type* J3ClassLoader::getType(J3Class*
 	return res;
 }
 
-J3Method* J3ClassLoader::method(uint16_t access, J3ObjectType* cl, const vmkit::Name* name, const vmkit::Name* sign) {
-	J3Method method(access, cl, name, sign), *res;
-
-	pthread_mutex_lock(&_mutexMethods);
-	std::map<J3Method*, J3Method*>::iterator it = methods.find(&method);
+J3Method* J3ClassLoader::method(uint16_t access, J3ObjectType* type, const vmkit::Name* name, const vmkit::Name* sign) {
+	if(type->isArrayClass())
+		return method(access, vm()->objectClass, name, sign);
+	else {
+		J3Class* cl = type->asClass();
+		J3Method method(access, cl, name, sign), *res;
+
+		pthread_mutex_lock(&_mutexMethods);
+		std::map<J3Method*, J3Method*>::iterator it = methods.find(&method);
+
+		if(it == methods.end()) {
+			res = new(allocator()) J3Method(access, cl, name, sign);
+			methods[res] = res;
+		} else {
+			res = it->second;
+		}
+		pthread_mutex_unlock(&_mutexMethods);
 
-	if(it == methods.end()) {
-		res = new(allocator()) J3Method(access, cl, name, sign);
-		methods[res] = res;
-	} else {
-		res = it->second;
+		return res;
 	}
-	pthread_mutex_unlock(&_mutexMethods);
-
-	return res;
 }
 
 bool J3ClassLoader::J3InterfaceMethodLess::operator()(j3::J3Method const* lhs, j3::J3Method const* rhs) const {

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=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Thu Jan  2 12:29:19 2014
@@ -442,6 +442,14 @@ void J3CodeGen::invokeVirtual(uint32_t i
 	llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)), 
 																						 llvmFunctionType(type)->getPointerTo());
 
+
+	builder->CreateCall5(funcEchoDebugExecute,
+											 builder->getInt32(2),
+											 buildString("Invoking %p::%d %p\n"),
+											 vt(obj),
+											 funcEntry,
+											 func);
+
 	invoke(target, func);
 }
 

Modified: vmkit/branches/mcjit/lib/j3/vm/j3mangler.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3mangler.cc?rev=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3mangler.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3mangler.cc Thu Jan  2 12:29:19 2014
@@ -11,7 +11,7 @@ const char*    J3Mangler::j3Id = "j3_";
 const char*    J3Mangler::javaId = "Java_";
 
 
-J3Mangler::J3Mangler(J3ObjectType* _from) {
+J3Mangler::J3Mangler(J3Class* _from) {
 	from = _from;
 	cur  = buf;
 }

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=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Thu Jan  2 12:29:19 2014
@@ -29,7 +29,7 @@ J3MethodType::J3MethodType(J3Type** args
 			
 }
 
-J3Method::J3Method(uint16_t access, J3ObjectType* cl, const vmkit::Name* name, const vmkit::Name* sign) :
+J3Method::J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign) :
 	_selfCode(this) {
 	_access = access;
 	_cl = cl;
@@ -225,7 +225,7 @@ J3Value J3Method::invokeVirtual(J3Object
 	return res;
 }
 
-J3MethodType* J3Method::methodType(J3ObjectType* from) {
+J3MethodType* J3Method::methodType(J3Class* from) {
 	if(!_methodType) {
 		J3ClassLoader*     loader = cl()->loader();
 		J3Type*            args[1+sign()->length()];
@@ -251,7 +251,7 @@ J3MethodType* J3Method::methodType(J3Obj
 	return _methodType;
 }
 
-void J3Method::buildLLVMNames(J3ObjectType* from) {
+void J3Method::buildLLVMNames(J3Class* from) {
 	const char* prefix = "stub_";
 	uint32_t plen = 5;
 	J3Mangler mangler(from);

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=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Thu Jan  2 12:29:19 2014
@@ -156,6 +156,7 @@ J3VirtualTable* J3VirtualTable::create(J
 		J3VirtualTable(cl, super, secondaries, nbSecondaries, isSecondary);
 
 	memcpy(res->_virtualMethods, objClass->vt()->_virtualMethods, sizeof(void*)*objClass->vt()->_nbVirtualMethods);
+	memcpy(res->_interfaceMethodTable, objClass->vt()->_interfaceMethodTable, sizeof(void*)*nbInterfaceMethodTable);
 
 	return res;
 }

Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=198329&r1=198328&r2=198329&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Thu Jan  2 12:29:19 2014
@@ -15,7 +15,7 @@ J3Options::J3Options() {
 
 	debugEnterIndent = 1;
 
-	debugExecute = 2;
+	debugExecute = 0;
 	debugLoad = 0;
 	debugResolve = 0;
 	debugIniting = 0;





More information about the vmkit-commits mailing list