[vmkit-commits] [vmkit] r94367 - in /vmkit/trunk: include/mvm/Threads/Locks.h lib/J3/Classpath/ClasspathVMSystem.inc lib/J3/VMCore/JavaLocks.cpp lib/J3/VMCore/JavaLocks.h lib/J3/VMCore/JavaObject.cpp lib/J3/VMCore/JavaObject.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sun Jan 24 10:28:40 PST 2010


Author: geoffray
Date: Sun Jan 24 12:28:39 2010
New Revision: 94367

URL: http://llvm.org/viewvc/llvm-project?rev=94367&view=rev
Log:
Use a 10-bit hashcode placed in the header instead of using the address.


Modified:
    vmkit/trunk/include/mvm/Threads/Locks.h
    vmkit/trunk/lib/J3/Classpath/ClasspathVMSystem.inc
    vmkit/trunk/lib/J3/VMCore/JavaLocks.cpp
    vmkit/trunk/lib/J3/VMCore/JavaLocks.h
    vmkit/trunk/lib/J3/VMCore/JavaObject.cpp
    vmkit/trunk/lib/J3/VMCore/JavaObject.h

Modified: vmkit/trunk/include/mvm/Threads/Locks.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Locks.h?rev=94367&r1=94366&r2=94367&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/Threads/Locks.h (original)
+++ vmkit/trunk/include/mvm/Threads/Locks.h Sun Jan 24 12:28:39 2010
@@ -187,6 +187,7 @@
   static const uint64_t ThinCountShift = 12;
   static const uint64_t ThinCountAdd = 0x1000;
   static const uint64_t GCMask = 0xFFF;
+  static const uint64_t HashMask = 0xFFC;
 
 
 

Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMSystem.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMSystem.inc?rev=94367&r1=94366&r2=94367&view=diff

==============================================================================
--- vmkit/trunk/lib/J3/Classpath/ClasspathVMSystem.inc (original)
+++ vmkit/trunk/lib/J3/Classpath/ClasspathVMSystem.inc Sun Jan 24 12:28:39 2010
@@ -109,7 +109,7 @@
 JavaObject* obj) {
 
   llvm_gcroot(obj, 0);
-  return (jint)(intptr_t)obj;
+  return obj->hashCode();
 }
 
 }

Modified: vmkit/trunk/lib/J3/VMCore/JavaLocks.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaLocks.cpp?rev=94367&r1=94366&r2=94367&view=diff

==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaLocks.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaLocks.cpp Sun Jan 24 12:28:39 2010
@@ -73,13 +73,13 @@
 }
 
 uintptr_t JavaLock::getID() {
-  return (index << LockSystem::BitGC) | mvm::FatMask;
+  return (index << LockSystem::BitGCHash) | mvm::FatMask;
 }
 
 JavaLock* JavaLock::getFromID(uintptr_t ID) {
   Jnjvm* vm = JavaThread::get()->getJVM();
   if (ID & mvm::FatMask) {
-    uint32_t index = (ID & ~mvm::FatMask) >> LockSystem::BitGC;
+    uint32_t index = (ID & ~mvm::FatMask) >> LockSystem::BitGCHash;
     JavaLock* res = vm->lockSystem.getLock(index);
     return res;
   } else {

Modified: vmkit/trunk/lib/J3/VMCore/JavaLocks.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaLocks.h?rev=94367&r1=94366&r2=94367&view=diff

==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaLocks.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaLocks.h Sun Jan 24 12:28:39 2010
@@ -125,7 +125,9 @@
   static const uint32_t IndexSize = 1 << BitIndex;
   static const uint32_t BitMask = IndexSize - 1;
   static const uint32_t MaxLocks = GlobalSize * IndexSize;
-  static const uint32_t BitGC = 12;
+  static const uint32_t BitGC = 2;
+  static const uint32_t BitHash = 10;
+  static const uint32_t BitGCHash = BitGC + BitHash;
 
   /// LockTable - The global table that will hold the locks. The table is
   /// a two-dimensional array, and only one entry is created, so that

Modified: vmkit/trunk/lib/J3/VMCore/JavaObject.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaObject.cpp?rev=94367&r1=94366&r2=94367&view=diff

==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaObject.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaObject.cpp Sun Jan 24 12:28:39 2010
@@ -20,6 +20,8 @@
 
 using namespace j3;
 
+uint16_t JavaObject::hashCodeGenerator = 1;
+
 void JavaObject::waitIntern(struct timeval* info, bool timed) {
   JavaLock* l = 0;
   JavaObject* self = this;

Modified: vmkit/trunk/lib/J3/VMCore/JavaObject.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaObject.h?rev=94367&r1=94366&r2=94367&view=diff

==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaObject.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaObject.h Sun Jan 24 12:28:39 2010
@@ -284,6 +284,28 @@
   ///
   void decapsulePrimitive(Jnjvm* vm, jvalue* buf, const Typedef* signature);
 
+  static uint16_t hashCodeGenerator;
+
+  /// hashCode - Return the hash code of this object.
+  uint32_t hashCode() {
+    JavaObject* self = this;
+    llvm_gcroot(self, 0);
+    uintptr_t oldLock = self->lock.lock;
+    uintptr_t val = (oldLock & mvm::HashMask) >> LockSystem::BitGC;
+    if (val) return val;
+    else {
+      if (hashCodeGenerator >= (mvm::HashMask >> LockSystem::BitGC))
+        val = hashCodeGenerator = 1;
+      else val = ++hashCodeGenerator;
+    }
+
+    do {
+      uintptr_t oldLock = self->lock.lock;
+      uintptr_t newLock = (val << LockSystem::BitGC) | oldLock;
+      __sync_val_compare_and_swap(&(self->lock.lock), oldLock, newLock);
+    } while ((self->lock.lock & mvm::HashMask)  == 0);
+    return (self->lock.lock & mvm::HashMask) >> LockSystem::BitGC;
+  }
 };
 
 





More information about the vmkit-commits mailing list