[jboss-svn-commits] JBL Code SVN: r29844 - in labs/jbosstm/trunk/ArjunaCore: txoj/classes/com/arjuna/ats/txoj and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Oct 28 05:53:45 EDT 2009


Author: jhalliday
Date: 2009-10-28 05:53:45 -0400 (Wed, 28 Oct 2009)
New Revision: 29844

Modified:
   labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java
   labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/Lock.java
Log:
Further fixes and improvements for Uid immutability and performance. JBTM-623


Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java	2009-10-28 09:20:29 UTC (rev 29843)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/Uid.java	2009-10-28 09:53:45 UTC (rev 29844)
@@ -43,6 +43,7 @@
 import java.lang.StringIndexOutOfBoundsException;
 import java.lang.NumberFormatException;
 import java.lang.CloneNotSupportedException;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import com.arjuna.ats.arjuna.logging.tsLogger;
 
@@ -376,7 +377,7 @@
 	 * Copy the specified Uid over this instance.
 	 */
 
-	public void copy (Uid toCopy)
+	private void copy (Uid toCopy)
 	{
 		if (toCopy == this)
 			return;
@@ -601,15 +602,20 @@
 		}
 	}
 
-	private static final synchronized int getValue ()
+    private static final int MAX_SEQ_VALUE = 0x40000000; // 2^30, which is a bit conservative.
+
+	private static int getValue ()
 	{
-		if ((Uid.uidsCreated & 0xf0000000) > 0)
-		{
-			Uid.uidsCreated = 0;
-			Uid.initTime = (int) (System.currentTimeMillis() / 1000);
-		}
+        int value = 0;
+        do {
+            value = uidsCreated.getAndIncrement();
+            if(value == MAX_SEQ_VALUE) {
+                uidsCreated.set(0);
+                initTime = (int) (System.currentTimeMillis() / 1000);
+            }
+        } while(value >= MAX_SEQ_VALUE);
 
-		return Uid.uidsCreated++;
+        return value;
 	}
 
 	/*
@@ -675,30 +681,30 @@
 			return Uid.breakChar;
 	}
 
-	protected long[] hostAddr;  // representation of ipv6 address (and ipv4)
-	protected int process;
-	protected int sec;
-	protected int other;
+	protected volatile long[] hostAddr;  // representation of ipv6 address (and ipv4)
+	protected volatile int process;
+	protected volatile int sec;
+	protected volatile int other;
 
-	private int _hashValue;
+	private volatile int _hashValue;
 
-	private boolean _valid;
+	private volatile boolean _valid;
 	
-	private String _stringForm;
+	private volatile String _stringForm;
 
-	private static int uidsCreated ;
+	private static final AtomicInteger uidsCreated = new AtomicInteger();
 
-	private static int initTime ;
+	private static volatile int initTime ;
 
-	private static char breakChar = ':';
+	private static final char breakChar = ':';
 
-	private static char fileBreakChar = '_';
+	private static final char fileBreakChar = '_';
 
-	private static Uid NIL_UID = new Uid("0:0:0:0:0") ;
+	private static final Uid NIL_UID = new Uid("0:0:0:0:0") ;
 
-	private static Uid LAST_RESOURCE_UID = new Uid("0:0:0:0:1") ;
+	private static final Uid LAST_RESOURCE_UID = new Uid("0:0:0:0:1") ;
 
-	private static Uid MAX_UID = new Uid("7fffffff:7fffffff:7fffffff:7fffffff:7fffffff") ;
+	private static final Uid MAX_UID = new Uid("7fffffff:7fffffff:7fffffff:7fffffff:7fffffff") ;
 
-	private static Uid MIN_UID = new Uid("-80000000:-80000000:-80000000:-80000000:-80000000") ;
+	private static final Uid MIN_UID = new Uid("-80000000:-80000000:-80000000:-80000000:-80000000") ;
 }

Modified: labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/Lock.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/Lock.java	2009-10-28 09:20:29 UTC (rev 29843)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/classes/com/arjuna/ats/txoj/Lock.java	2009-10-28 09:53:45 UTC (rev 29844)
@@ -111,15 +111,13 @@
 	    
 	    if (applicPid != currentPid)
 	    {
-		Uid temp = new Uid();
-	    
 		/*
 		 * Process id change probably due to a fork(). Get new pid 
 		 * and generate a new Applic_Uid
 		 */
 
 		applicPid = currentPid;
-		applicUid.copy(temp);
+		applicUid = new Uid();
 	    }
 
 	    ah.add(applicUid);



More information about the jboss-svn-commits mailing list