[vmkit-commits] [vmkit] r199099 - Implements JVM_HoldsLock and fix a bug in GetPrimitiveArrayCritical when isCopy is not null.

Gael Thomas gael.thomas at lip6.fr
Mon Jan 13 03:39:49 PST 2014


Author: gthomas
Date: Mon Jan 13 05:39:49 2014
New Revision: 199099

URL: http://llvm.org/viewvc/llvm-project?rev=199099&view=rev
Log:
Implements JVM_HoldsLock and fix a bug in GetPrimitiveArrayCritical when isCopy is not null.

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

Modified: vmkit/branches/mcjit/include/j3/j3monitor.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3monitor.h?rev=199099&r1=199098&r2=199099&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3monitor.h (original)
+++ vmkit/branches/mcjit/include/j3/j3monitor.h Mon Jan 13 05:39:49 2014
@@ -43,6 +43,7 @@ namespace j3 {
 		J3Monitor* prepare(J3Object* _object, uintptr_t header, J3LockRecord* _record);
 		J3Monitor* prepare();
 
+		bool isOwner(J3Thread* thread);
 		void lock();
 		void unlock();
 

Modified: vmkit/branches/mcjit/include/j3/j3object.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=199099&r1=199098&r2=199099&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3object.h (original)
+++ vmkit/branches/mcjit/include/j3/j3object.h Mon Jan 13 05:39:49 2014
@@ -43,7 +43,7 @@ namespace j3 {
 		friend class J3Trampoline;
 
 	public:
-		static const uint32_t nbInterfaceMethodTable = 41;
+		static const uint32_t nbInterfaceMethodTable = 43;
 		static const uint32_t gepObjectClass = 0;
 		static const uint32_t gepInterfaceMethods = 2;
 		static const uint32_t gepVirtualMethods = 4;
@@ -102,6 +102,7 @@ namespace j3 {
 
 		J3Object(); /* never directly allocate an object */
 
+		bool       isLockOwner();
 		J3Monitor* monitor();
 		uint32_t   hashCode();
 
@@ -157,6 +158,7 @@ namespace j3 {
 		static J3ObjectHandle* doNewObject(J3Class* cl);
 		static J3ObjectHandle* doNewArray(J3ArrayClass* cl, uint32_t length);
 
+		bool            isLockOwner();
 		void            wait();
 
 		bool            isSame(J3ObjectHandle* handle) { return obj() == handle->obj(); }

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=199099&r1=199098&r2=199099&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Mon Jan 13 05:39:49 2014
@@ -400,7 +400,15 @@ jobject JNICALL JVM_CurrentThread(JNIEnv
 jint JNICALL JVM_CountStackFrames(JNIEnv* env, jobject thread) { enterJVM(); leaveJVM(); NYI(); }
 void JNICALL JVM_Interrupt(JNIEnv* env, jobject thread) { enterJVM(); leaveJVM(); NYI(); }
 jboolean JNICALL JVM_IsInterrupted(JNIEnv* env, jobject thread, jboolean clearInterrupted) { enterJVM(); leaveJVM(); NYI(); }
-jboolean JNICALL JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj) { enterJVM(); leaveJVM(); NYI(); }
+
+jboolean JNICALL JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj) { 
+	jboolean res;
+	enterJVM(); 
+	res = obj->isLockOwner();
+	leaveJVM(); 
+	return res;
+}
+
 void JNICALL JVM_DumpAllStacks(JNIEnv* env, jclass unused) { enterJVM(); leaveJVM(); NYI(); }
 jobjectArray JNICALL JVM_GetAllThreads(JNIEnv* env, jclass dummy) { enterJVM(); leaveJVM(); NYI(); }
 void JNICALL JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name) { enterJVM(); leaveJVM(); NYI(); }

Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=199099&r1=199098&r2=199099&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Mon Jan 13 05:39:49 2014
@@ -462,7 +462,7 @@ const char* JNICALL GetStringUTFChars(JN
 	J3Utf16Decoder::decode(content, res);
 
 	if(isCopy)
-		*isCopy = 1;
+		*isCopy = JNI_TRUE;
 
 	leaveJVM(); 
 
@@ -573,7 +573,7 @@ void JNICALL GetStringUTFRegion(JNIEnv*
 void* JNICALL GetPrimitiveArrayCritical(JNIEnv* env, jarray array, jboolean* isCopy) { 
 	//GC::disable(); ?
 	if(isCopy)
-		isCopy = 0;
+		*isCopy = JNI_FALSE;
 	return array ? array->array()->content() : 0;
 }
 

Modified: vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc?rev=199099&r1=199098&r2=199099&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc Mon Jan 13 05:39:49 2014
@@ -35,6 +35,10 @@ void J3Monitor::checkRecord() {
 	}
 }
 
+bool J3Monitor::isOwner(J3Thread* thread) {
+	return owner == thread;
+}
+
 void J3Monitor::lock() {
 	J3Thread* self = J3Thread::get();
 

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=199099&r1=199098&r2=199099&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Jan 13 05:39:49 2014
@@ -333,6 +333,16 @@ uint32_t J3Object::hashCode() {
 	}
 }
 
+bool J3Object::isLockOwner() {
+	J3Thread* self = J3Thread::get();
+	uintptr_t header = _header;
+
+	if((header & 0x3) == 2) /* inflated */
+		return ((J3Monitor*)(header & -2))->isOwner(self);
+	else
+		return !(header & 3) && (J3Thread*)(header & J3Thread::getThreadMask()) == self;
+}
+
 J3Monitor* J3Object::monitor() {
 	uintptr_t header = _header;
 
@@ -384,6 +394,10 @@ void J3ObjectHandle::wait() {
 	obj()->monitor()->wait();
 }
 
+bool J3ObjectHandle::isLockOwner() {
+	return obj()->isLockOwner();
+}
+
 uint32_t J3ObjectHandle::hashCode() {
 	return obj()->hashCode();
 }





More information about the vmkit-commits mailing list