[vmkit-commits] [vmkit] r198026 - implement arraycopy

Gael Thomas gael.thomas at lip6.fr
Wed Dec 25 13:49:34 PST 2013


Author: gthomas
Date: Wed Dec 25 15:49:33 2013
New Revision: 198026

URL: http://llvm.org/viewvc/llvm-project?rev=198026&view=rev
Log:
implement arraycopy

Modified:
    vmkit/branches/mcjit/include/j3/j3.h
    vmkit/branches/mcjit/include/j3/j3object.h
    vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
    vmkit/branches/mcjit/lib/j3/vm/j3.cc
    vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
    vmkit/branches/mcjit/lib/j3/vm/j3object.cc
    vmkit/branches/mcjit/lib/j3/vm/j3options.cc

Modified: vmkit/branches/mcjit/include/j3/j3.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198026&r1=198025&r2=198026&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3.h (original)
+++ vmkit/branches/mcjit/include/j3/j3.h Wed Dec 25 15:49:33 2013
@@ -111,7 +111,8 @@ namespace j3 {
 		static void    nullPointerException() __attribute__((noreturn));
 		static void    classCastException() __attribute__((noreturn));
 
-		static void    arrayBoundCheckException() __attribute__((noreturn));
+		static void    arrayStoreException() __attribute__((noreturn));
+		static void    arrayIndexOutOfBoundsException() __attribute__((noreturn));
 
 		static void    printStackTrace();
 	};

Modified: vmkit/branches/mcjit/include/j3/j3object.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=198026&r1=198025&r2=198026&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3object.h (original)
+++ vmkit/branches/mcjit/include/j3/j3object.h Wed Dec 25 15:49:33 2013
@@ -129,6 +129,7 @@ namespace j3 {
 	private:
 		J3Object* volatile _obj;
 
+	public:
 		J3Object*           obj()   { return _obj; }
 		J3ArrayObject*      array() { return (J3ArrayObject*)_obj; }
 	public:
@@ -139,10 +140,14 @@ namespace j3 {
 		static J3ObjectHandle* doNewObject(J3Class* cl);
 		static J3ObjectHandle* doNewArray(J3ArrayClass* cl, uint32_t length);
 
+		bool            isSame(J3ObjectHandle* handle) { return obj() == handle->obj(); }
+
 		void            harakiri() { _obj = 0; }
 
 		uint32_t        hashCode();
 
+		void            rawArrayCopyTo(uint32_t fromOffset, J3ObjectHandle* to, uint32_t toOffset, uint32_t nbb); 
+
 		void            rawSetObject(uint32_t offset, J3ObjectHandle* v);
 		J3ObjectHandle* rawGetObject(uint32_t offset);
 		void            setObject(J3Field* f, J3ObjectHandle* v);

Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198026&r1=198025&r2=198026&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Wed Dec 25 15:49:33 2013
@@ -51,14 +51,22 @@ jlong JNICALL JVM_NanoTime(JNIEnv* env,
 void JNICALL JVM_ArrayCopy(JNIEnv* env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length) { 
 	enterJVM(); 
 
-	printf("to array copy: %p and %p\n", src->vt(), dst->vt());
+	J3Type* srcType0 = src->vt()->type();
+	J3Type* dstType0 = dst->vt()->type();
 
-	J3Type* srcType = src->vt()->type();
-	J3Type* dstType = dst->vt()->type();
+	if(!srcType0->isArrayClass() || !dstType0->isArrayClass() || !srcType0->isAssignableTo(dstType0))
+		J3::arrayStoreException();
 
-	fprintf(stderr, "%ls to %ls\n", srcType->name()->cStr(), dstType->name()->cStr());
+	if(src_pos >= src->arrayLength() || 
+		 dst_pos >= dst->arrayLength() ||
+		 (src_pos + length) > src->arrayLength() ||
+		 (dst_pos + length) > dst->arrayLength())
+		J3::arrayIndexOutOfBoundsException();
+
+	uint32_t scale = srcType0->asArrayClass()->component()->getLogSize();
+
+	src->rawArrayCopyTo(src_pos << scale, dst, dst_pos << scale, length << scale);
 
-	NYI();
 	leaveJVM(); 
 }
 
@@ -133,7 +141,13 @@ void JNICALL JVM_StopThread(JNIEnv* env,
 jboolean JNICALL JVM_IsThreadAlive(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); }
 void JNICALL JVM_SuspendThread(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); }
 void JNICALL JVM_ResumeThread(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); }
-void JNICALL JVM_SetThreadPriority(JNIEnv* env, jobject thread, jint prio) { enterJVM(); NYI(); leaveJVM(); }
+
+void JNICALL JVM_SetThreadPriority(JNIEnv* env, jobject thread, jint prio) { 
+	enterJVM(); 
+	// not yet implemented
+	leaveJVM(); 
+}
+
 void JNICALL JVM_Yield(JNIEnv* env, jclass threadClass) { enterJVM(); NYI(); leaveJVM(); }
 void JNICALL JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis) { enterJVM(); NYI(); leaveJVM(); }
 
@@ -415,7 +429,12 @@ jobject JNICALL JVM_DoPrivileged(JNIEnv*
 }
 
 jobject JNICALL JVM_GetInheritedAccessControlContext(JNIEnv* env, jclass cls) { enterJVM(); NYI(); leaveJVM(); }
-jobject JNICALL JVM_GetStackAccessControlContext(JNIEnv* env, jclass cls) { enterJVM(); NYI(); leaveJVM(); }
+jobject JNICALL JVM_GetStackAccessControlContext(JNIEnv* env, jclass cls) { 
+	enterJVM(); 
+  // not yet implemented
+	leaveJVM(); 
+	return 0;
+}
 
 /*
  * Signal support, used to implement the shutdown sequence.  Every VM must

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=198026&r1=198025&r2=198026&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Wed Dec 25 15:49:33 2013
@@ -177,6 +177,14 @@ void J3::linkageError(J3Method* method)
 	internalError(L"unable to find native method '%ls::%ls%ls'", method->cl()->name()->cStr(), method->name()->cStr(), method->sign()->cStr());
 }
 
+void J3::arrayStoreException() {
+	internalError(L"array store exception");
+}
+
+void J3::arrayIndexOutOfBoundsException() {
+	internalError(L"array bound check exception");
+}
+
 void J3::vinternalError(const wchar_t* msg, va_list va) {
 	wchar_t buf[65536];
 	vswprintf(buf, 65536, msg, va);

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=198026&r1=198025&r2=198026&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Wed Dec 25 15:49:33 2013
@@ -848,7 +848,7 @@ void J3CodeGen::translate() {
 			case J3Cst::BC_lload:                         /* 0x16 wide */
 			case J3Cst::BC_fload:                         /* 0x17 wide */
 			case J3Cst::BC_dload:                         /* 0x18 wide */
-			case J3Cst::BC_aload:                         /* 0x19 wide */
+			case J3Cst::BC_aload:                         /* 0x19 wide */				
 				stack.push(locals.at(wideReadU1()));
 				break;
 

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=198026&r1=198025&r2=198026&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Wed Dec 25 15:49:33 2013
@@ -278,7 +278,7 @@ J3Object* J3Object::allocate(J3VirtualTa
 }
 
 J3Object* J3Object::doNewNoInit(J3Class* cl) {
-	return allocate(cl->vt(), cl->size());
+	return allocate(cl->vtAndResolve(), cl->size());
 }
 
 J3Object* J3Object::doNew(J3Class* cl) {
@@ -292,7 +292,7 @@ J3Object* J3Object::doNew(J3Class* cl) {
 J3Object* J3ArrayObject::doNew(J3ArrayClass* cl, uint32_t length) {
 	llvm::DataLayout* layout = cl->loader()->vm()->dataLayout();
 	J3ArrayObject* res = 
-		(J3ArrayObject*)allocate(cl->vt(),
+		(J3ArrayObject*)allocate(cl->vtAndResolve(),
 														 layout->getTypeAllocSize(cl->llvmType()->getContainedType(0))
 														 + layout->getTypeAllocSize(cl->component()->llvmType()) * length);
 
@@ -367,7 +367,7 @@ J3ObjectHandle* J3ObjectHandle::doNewArr
 																																				\
 	void  J3ObjectHandle::setRegion##name(uint32_t selfIdx, const ctype* buf, uint32_t bufIdx, uint32_t len) { \
 		if(selfIdx + len > arrayLength())																		\
-			J3::arrayBoundCheckException();																		\
+			J3::arrayIndexOutOfBoundsException();															\
 		memcpy((uint8_t*)array() + sizeof(J3ArrayObject) + selfIdx*sizeof(ctype), \
 					 (uint8_t*)buf + bufIdx*sizeof(ctype),												\
 					 len*sizeof(ctype));																					\
@@ -375,7 +375,7 @@ J3ObjectHandle* J3ObjectHandle::doNewArr
 																																				\
 	void  J3ObjectHandle::getRegion##name(uint32_t selfIdx, const ctype* buf, uint32_t bufIdx, uint32_t len) { \
 		if(selfIdx + len > arrayLength())																		\
-			J3::arrayBoundCheckException();																		\
+			J3::arrayIndexOutOfBoundsException();															\
 		memcpy((uint8_t*)buf + bufIdx*sizeof(ctype),												\
 					 (uint8_t*)array() + sizeof(J3ArrayObject) + selfIdx*sizeof(ctype), \
 					 len*sizeof(ctype));																					\
@@ -385,6 +385,13 @@ onJavaPrimitives(defAccessor)
 
 #undef defAccessor
 
+void J3ObjectHandle::rawArrayCopyTo(uint32_t fromOffset, J3ObjectHandle* to, uint32_t toOffset, uint32_t nbb) {
+	if(isSame(to))
+		memmove((uint8_t*)(to->array()+1) + toOffset, (uint8_t*)(array()+1) + fromOffset, nbb); 
+	else
+		memcpy((uint8_t*)(to->array()+1) + toOffset, (uint8_t*)(array()+1) + fromOffset, nbb); 
+}
+
 void J3ObjectHandle::rawSetObject(uint32_t offset, J3ObjectHandle* value) {
 	*((J3Object**)((uintptr_t)obj() + offset)) = value->obj();
 }

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=198026&r1=198025&r2=198026&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Wed Dec 25 15:49:33 2013
@@ -15,11 +15,11 @@ J3Options::J3Options() {
 
 	debugEnterIndent = 1;
 
-	debugExecute = 2;
+	debugExecute = 0;
 	debugLoad = 0;
 	debugResolve = 0;
 	debugIniting = 0;
-	debugTranslate = 3;
+	debugTranslate = 0;
 	debugLinking = 0;
 
 	genDebugExecute = debugExecute ? 1 : 0;





More information about the vmkit-commits mailing list