Browse files

further optimisations

  • Loading branch information...
1 parent 237fe4d commit efc90afcf02f7d8ce34fc8e9904d73001f18b7ff @nmcl nmcl committed Nov 8, 2012
View
84 ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/StateManager.java
@@ -224,6 +224,8 @@ public synchronized boolean activate (String rootName)
synchronized (mutex)
{
+ createLists();
+
if (usingActions.get(action.get_uid()) == null)
{
/*
@@ -773,25 +775,7 @@ protected StateManager(Uid objUid, int ot)
protected StateManager (Uid objUid, int ot, int om)
{
objectModel = om;
-
- if (ot == ObjectType.NEITHER)
- {
- modifyingActions = null;
- usingActions = null;
- }
- else
- {
- modifyingActions = new Hashtable();
- usingActions = new Hashtable();
- }
-
- activated = false;
- currentlyActivated = false;
- currentStatus = ObjectStatus.PASSIVE;
- initialStatus = ObjectStatus.PASSIVE;
myType = ot;
- participantStore = null;
- storeRoot = null;
objectUid = objUid;
@@ -813,26 +797,10 @@ protected StateManager(int ot)
protected StateManager (int ot, int om)
{
objectModel = om;
-
- if (ot == ObjectType.NEITHER)
- {
- modifyingActions = null;
- usingActions = null;
- }
- else
- {
- modifyingActions = new Hashtable();
- usingActions = new Hashtable();
- }
-
- activated = false;
- currentlyActivated = false;
currentStatus = (((objectModel == ObjectModel.SINGLE) && (ot == ObjectType.RECOVERABLE)) ? ObjectStatus.ACTIVE
: ObjectStatus.PASSIVE_NEW);
initialStatus = currentStatus;
myType = ot;
- participantStore = null;
- storeRoot = null;
objectUid = new Uid();
@@ -890,6 +858,8 @@ protected synchronized boolean modified ()
* BasicList insert returns FALSE if the entry is already present.
*/
+ createLists();
+
synchronized (modifyingActions)
{
if ((modifyingActions.size() > 0)
@@ -1231,6 +1201,8 @@ protected final synchronized boolean forgetAction (BasicAction action,
+ objectUid);
}
+ createLists();
+
synchronized (modifyingActions)
{
modifyingActions.remove(action.get_uid());
@@ -1367,7 +1339,23 @@ protected final boolean tryLockMutex ()
{
return mutex.tryLock();
}
-
+
+ /*
+ * Delay creating these lists until we really need them. Some transactions may start
+ * and end without adding any participants or being involved with multiple threads.
+ * Some classes (e.g., AbstractRecords) that inherit from StateManager may never need
+ * these lists either.
+ */
+
+ protected synchronized void createLists ()
+ {
+ if (modifyingActions == null)
+ {
+ modifyingActions = new Hashtable();
+ usingActions = new Hashtable();
+ }
+ }
+
/*
* Package scope.
*/
@@ -1382,28 +1370,18 @@ synchronized final void destroyed ()
currentStatus = ObjectStatus.DESTROYED;
}
- protected Hashtable modifyingActions;
-
- protected Hashtable usingActions;
-
+ protected Hashtable modifyingActions = null;
+ protected Hashtable usingActions = null;
protected final Uid objectUid;
-
protected int objectModel = ObjectModel.SINGLE;
- private boolean activated;
-
- private boolean currentlyActivated;
-
- private int currentStatus;
-
- private int initialStatus;
-
+ private boolean activated = false;
+ private boolean currentlyActivated = false;
+ private int currentStatus = ObjectStatus.PASSIVE;
+ private int initialStatus = ObjectStatus.PASSIVE;
private int myType;
-
- private ParticipantStore participantStore;
-
- private String storeRoot;
-
+ private ParticipantStore participantStore = null;
+ private String storeRoot = null;
private ReentrantLock mutex = new ReentrantLock();
private static final String marker = "#ARJUNA#";
View
16 ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/ActionHierarchy.java
@@ -69,12 +69,7 @@ public ActionHierarchy (int depth)
currentDepth = 0;
if (maxHierarchyDepth > 0)
- {
hierarchy = new ActionInfo[maxHierarchyDepth];
-
- for (int i = 0; i < maxHierarchyDepth; i++)
- hierarchy[i] = null;
- }
}
/**
@@ -88,13 +83,8 @@ public ActionHierarchy (ActionHierarchy theCopy)
currentDepth = theCopy.currentDepth;
if (maxHierarchyDepth > 0)
- {
hierarchy = new ActionInfo[maxHierarchyDepth];
- for (int i = 0; i < maxHierarchyDepth; i++)
- hierarchy[i] = null;
- }
-
for (int i = 0; i < currentDepth; i++)
{
hierarchy[i] = new ActionInfo(theCopy.hierarchy[i]);
@@ -427,7 +417,11 @@ public synchronized final ActionInfo getActionInfo (int typeIndex)
return hierarchy[typeIndex];
}
- public static final int DEFAULT_HIERARCHY_DEPTH = 5;
+ /*
+ * Most transactions are top-level so optimise data structure for that case.
+ */
+
+ public static final int DEFAULT_HIERARCHY_DEPTH = 1;
private ActionInfo[] hierarchy;
private int maxHierarchyDepth;
View
2 ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/LogWriteStateManager.java
@@ -128,6 +128,8 @@ protected synchronized boolean modified ()
* present.
*/
+ createLists();
+
synchronized (modifyingActions)
{
if ((modifyingActions.size() > 0) &&

0 comments on commit efc90af

Please sign in to comment.