[vmkit-commits] [vmkit] r198062 - Able to start a Java thread, that's cool, but I have a bug in invokeVirtual that leads to the execution of Thread::run instead of the run() method of the thread object.

Gael Thomas gael.thomas at lip6.fr
Thu Dec 26 15:23:12 PST 2013


Author: gthomas
Date: Thu Dec 26 17:23:12 2013
New Revision: 198062

URL: http://llvm.org/viewvc/llvm-project?rev=198062&view=rev
Log:
Able to start a Java thread, that's cool, but I have a bug in invokeVirtual that leads to the execution of Thread::run instead of the run() method of the thread object.

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

Modified: vmkit/branches/mcjit/include/j3/j3.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198062&r1=198061&r2=198062&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3.h (original)
+++ vmkit/branches/mcjit/include/j3/j3.h Thu Dec 26 17:23:12 2013
@@ -66,6 +66,7 @@ namespace j3 {
 		J3Field*         classVMData;
 
 		J3Field*         threadVMData;
+		J3Method*        threadRun;
 
 		const vmkit::Name* codeAttr;
 		const vmkit::Name* constantValueAttr;

Modified: vmkit/branches/mcjit/include/j3/j3thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198062&r1=198061&r2=198062&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3thread.h (original)
+++ vmkit/branches/mcjit/include/j3/j3thread.h Thu Dec 26 17:23:12 2013
@@ -25,6 +25,8 @@ namespace j3 {
 		J3ObjectHandle*            _pendingException;
 		J3ObjectHandle*            _javaThread;
 
+		static void doRun();
+
 		J3Thread(J3* vm, vmkit::BumpAllocator* allocator);
 	public:
 		static J3Thread*  create(J3* j3);
@@ -52,6 +54,8 @@ namespace j3 {
 		JNIEnv* jniEnv() { return &_jniEnv; }
 
 		static J3Thread* get();
+
+		static void start(J3ObjectHandle* handle);
 	};
 }
 

Modified: vmkit/branches/mcjit/include/vmkit/thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=198062&r1=198061&r2=198062&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/vmkit/thread.h (original)
+++ vmkit/branches/mcjit/include/vmkit/thread.h Thu Dec 26 17:23:12 2013
@@ -7,9 +7,14 @@ namespace vmkit {
 	class VMKit;
 
 	class Thread : protected PermanentObject {
+		typedef void (*entryPoint_t)();
+
 		BumpAllocator*       _allocator;
 		VMKit*               _vm;
 		void*                _baseFramePointer;
+		entryPoint_t         _entryPoint;
+
+		static void* doRun(void* thread);
 
 	protected:
 		Thread(VMKit* vm, BumpAllocator* allocator);
@@ -27,6 +32,8 @@ namespace vmkit {
 
 		static Thread* get()          { return _thread; }
 		static void set(Thread* thread) { _thread = thread; }
+
+		static void start(entryPoint_t entryPoint, Thread* thread);
 	};
 
 	class StackWalker {

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=198062&r1=198061&r2=198062&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Thu Dec 26 17:23:12 2013
@@ -136,7 +136,12 @@ void JNICALL JVM_DisableCompiler(JNIEnv*
 /*
  * java.lang.Thread
  */
-void JNICALL JVM_StartThread(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); }
+void JNICALL JVM_StartThread(JNIEnv* env, jobject thread) { 
+	enterJVM(); 
+	J3Thread::start(thread);
+	leaveJVM(); 
+}
+
 void JNICALL JVM_StopThread(JNIEnv* env, jobject thread, jobject exception) { enterJVM(); NYI(); leaveJVM(); }
 jboolean JNICALL JVM_IsThreadAlive(JNIEnv* env, jobject thread) { 
 	jboolean res;

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=198062&r1=198061&r2=198062&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Thu Dec 26 17:23:12 2013
@@ -104,6 +104,7 @@ void J3::start(int argc, char** argv) {
 
 	threadVMData             = initialClassLoader->getClass(names()->get("java/lang/Thread"))
 		->findVirtualField(names()->get(L"eetop"), typeLong);
+	threadRun                = initialClassLoader->method(0, L"java/lang/Thread", L"run", L"()V");
 
 	J3Lib::bootstrap(this);
 }

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=198062&r1=198061&r2=198062&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Thu Dec 26 17:23:12 2013
@@ -19,8 +19,8 @@ J3Options::J3Options() {
 	debugLoad = 0;
 	debugResolve = 0;
 	debugIniting = 0;
-	debugTranslate = 2;
-	debugLinking = 0;
+	debugTranslate = 1;
+	debugLinking = 1;
 
 	genDebugExecute = debugExecute ? 1 : 0;
 }

Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198062&r1=198061&r2=198062&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Thu Dec 26 17:23:12 2013
@@ -19,6 +19,18 @@ J3Thread* J3Thread::create(J3* j3) {
 	return new(allocator) J3Thread(j3, allocator);
 }
 
+void J3Thread::doRun() {
+	J3ObjectHandle* handle = get()->javaThread();
+	get()->vm()->threadRun->invokeVirtual(handle);
+}
+
+void J3Thread::start(J3ObjectHandle* handle) {
+	J3Thread* thread = create(J3Thread::get()->vm());
+	thread->assocJavaThread(handle);
+	Thread::start(doRun, thread);
+	while(1);
+}
+
 J3Method* J3Thread::getJavaCaller(uint32_t level) {
 	vmkit::Safepoint* sf = 0;
 	vmkit::StackWalker walker;

Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=198062&r1=198061&r2=198062&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/thread.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/thread.cc Thu Dec 26 17:23:12 2013
@@ -15,6 +15,19 @@ void Thread::destroy(Thread* thread) {
 	BumpAllocator::destroy(thread->allocator());
 }
 
+void* Thread::doRun(void* _thread) {
+	Thread* thread = (Thread*)_thread;
+	set(thread);
+	thread->_entryPoint();
+	return 0;
+}
+
+void Thread::start(entryPoint_t entryPoint, Thread* thread) {
+	thread->_entryPoint = entryPoint;
+	pthread_t tid;
+	pthread_create(&tid, 0, doRun, thread);
+}
+
 StackWalker::StackWalker(uint32_t initialPop) {
 	framePointer = System::current_fp();
 	next(initialPop+1);





More information about the vmkit-commits mailing list