You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2016/07/25 13:44:31 UTC

svn commit: r1753995 - in /uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src: main/java/org/apache/uima/jcas/impl/ test/java/org/apache/uima/jcas/impl/

Author: schor
Date: Mon Jul 25 13:44:31 2016
New Revision: 1753995

URL: http://svn.apache.org/viewvc?rev=1753995&view=rev
Log:
[UIMA-5030] add impl and tests of JCasHashMap for UV3 to use with Pears

Added:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java
      - copied, changed from r1712073, uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMapSubMap.java
      - copied, changed from r1712073, uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMapSubMap.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java   (contents, props changed)
      - copied, changed from r1712624, uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java   (contents, props changed)
      - copied, changed from r1712624, uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java

Copied: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java (from r1712073, uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java)
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java?p2=uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java&p1=uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java&r1=1712073&r2=1753995&rev=1753995&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java Mon Jul 25 13:44:31 2016
@@ -19,8 +19,8 @@
 
 package org.apache.uima.jcas.impl;
 
-import org.apache.uima.cas.impl.FeatureStructureImpl;
-import org.apache.uima.internal.util.Utilities;
+import org.apache.uima.internal.util.Misc;
+import org.apache.uima.jcas.cas.TOP;
 
 /**
  * Version 2 (2014) of map between CAS addr and JCasCover Objects
@@ -132,11 +132,11 @@ public class JCasHashMap {
         // max is 16 (the number of l1 slots is 256 in some high performance cpus (2015) so going higer than this 
         //  probably has too much cache loading
         // 
-        1 + (int)(Utilities.numberOfCores * 
-                   ((Utilities.numberOfCores > 64) ? .08 : 
-                    (Utilities.numberOfCores > 32) ? .1  :
-                    (Utilities.numberOfCores > 16) ? .2  :
-                    (Utilities.numberOfCores > 8)  ? .3  : .4));
+        1 + (int)(Misc.numberOfCores * 
+                   ((Misc.numberOfCores > 64) ? .08 : 
+                    (Misc.numberOfCores > 32) ? .1  :
+                    (Misc.numberOfCores > 16) ? .2  :
+                    (Misc.numberOfCores > 8)  ? .3  : .4));
   }
 
   static int getDEFAULT_CONCURRENCY_LEVEL() {
@@ -145,7 +145,7 @@ public class JCasHashMap {
   
   // used in test cases
   static void setDEFAULT_CONCURRENCY_LEVEL(int dEFAULT_CONCURRENCY_LEVEL) {
-    DEFAULT_CONCURRENCY_LEVEL = Utilities.nextHigherPowerOf2(dEFAULT_CONCURRENCY_LEVEL);
+    DEFAULT_CONCURRENCY_LEVEL = Misc.nextHigherPowerOf2(dEFAULT_CONCURRENCY_LEVEL);
   }
   
 //  // size set to ~1 cache line 
@@ -157,8 +157,6 @@ public class JCasHashMap {
   private final float loadFactor = (float)0.60;
     
   private final int initialCapacity; 
-
-  private final boolean useCache;
   
   private final int concurrencyLevel;
   
@@ -174,7 +172,7 @@ public class JCasHashMap {
   private final JCasHashMapSubMap oneSubmap;
   
 //  // cache to improve locality of reference for lookup
-//  private final FeatureStructureImpl[] cacheFS = new FeatureStructureImpl[CACHE_SIZE];  // one cache line is 32 words, save some for length and java object overhead
+//  private final TOP[] cacheFS = new TOP[CACHE_SIZE];  // one cache line is 32 words, save some for length and java object overhead
 //  private final int[] cacheInt = new int[CACHE_SIZE];
 //  private int cacheNewIndex = 0;
   
@@ -183,25 +181,24 @@ public class JCasHashMap {
     //   that is, minimum sub-table capacity is 32 entries
     // if capacity/concurrency < 32,
     //   concurrency = capacity / 32
-    this(capacity, doUseCache,
+    this(capacity,
         ((capacity / DEFAULT_CONCURRENCY_LEVEL) < 32) ?
-            Utilities.nextHigherPowerOf2(
+            Misc.nextHigherPowerOf2(
                 Math.max(1, capacity / 32)) :
             DEFAULT_CONCURRENCY_LEVEL);
     if (check && (capacity / DEFAULT_CONCURRENCY_LEVEL) < 32) {
       System.out.println(String.format("JCasHashMap concurrency reduced, capacity: %,d DefaultConcur: %d, concur: %d%n",
           capacity, DEFAULT_CONCURRENCY_LEVEL, 
-          Utilities.nextHigherPowerOf2(Math.max(1, capacity / 32))));
+          Misc.nextHigherPowerOf2(Math.max(1, capacity / 32))));
     }
   }
   
-  JCasHashMap(int capacity, boolean doUseCache, int aConcurrencyLevel) {
-    this.useCache = doUseCache;
+  JCasHashMap(int capacity, int aConcurrencyLevel) {
 
     if (aConcurrencyLevel < 1|| capacity < 1) {
       throw new RuntimeException(String.format("capacity %d and concurrencyLevel %d must be > 0", capacity, aConcurrencyLevel));
     }
-    concurrencyLevel = Utilities.nextHigherPowerOf2(aConcurrencyLevel);
+    concurrencyLevel = Misc.nextHigherPowerOf2(aConcurrencyLevel);
     concurrencyBitmask = concurrencyLevel - 1;
     // for clvl=1, lvlbits = 0,  
     // for clvl=2  lvlbits = 1;
@@ -209,7 +206,7 @@ public class JCasHashMap {
     concurrencyLevelBits = Integer.numberOfTrailingZeros(concurrencyLevel); 
     
     // capacity is the greater of the passed in capacity, rounded up to a power of 2, or 32.
-    capacity = Math.max(32, Utilities.nextHigherPowerOf2(capacity));
+    capacity = Math.max(32, Misc.nextHigherPowerOf2(capacity));
     // if capacity / concurrencyLevel <32, increase capacity
     if ((capacity / concurrencyLevel) < 32) {
       capacity = 32 * concurrencyLevel;
@@ -244,7 +241,7 @@ public class JCasHashMap {
     int submapSize = curMapSize / DEFAULT_CONCURRENCY_LEVEL;
     
     int newConcurrencyLevel = (submapSize < 32) ?
-        Utilities.nextHigherPowerOf2(
+        Misc.nextHigherPowerOf2(
             Math.max(1, curMapSize / 32)) :
               DEFAULT_CONCURRENCY_LEVEL;
         
@@ -255,7 +252,7 @@ public class JCasHashMap {
     int submapSize = curMapSize / DEFAULT_CONCURRENCY_LEVEL;
     
     int newConcurrencyLevel = (submapSize < 32) ?
-        Utilities.nextHigherPowerOf2(
+        Misc.nextHigherPowerOf2(
             Math.max(1, curMapSize / 32)) :
               DEFAULT_CONCURRENCY_LEVEL;
     return Math.max(32 * newConcurrencyLevel,   curMapSize / 2);  
@@ -266,9 +263,6 @@ public class JCasHashMap {
   //   shrink if current number of entries
   //      wouldn't trigger an expansion if the size was reduced by 1/2 
   public synchronized void clear() {
-    if (!this.useCache) {
-      return;
-    }
     for (JCasHashMapSubMap m : subMaps) {
       m.clear();
     }
@@ -280,10 +274,7 @@ public class JCasHashMap {
     return (null != oneSubmap) ? oneSubmap : subMaps[hash & concurrencyBitmask];
   }
   
-  public FeatureStructureImpl getReserve(int key) {
-    if (!this.useCache) {
-      return null;
-    }
+  public TOP getReserve(int key) {
 //    for (int i = 0; i < cacheInt.length; i++) {
 //      final int vi = cacheInt[i];
 //      if (vi == 0) {
@@ -294,7 +285,7 @@ public class JCasHashMap {
 //        if (MEASURE_CACHE) {
 //          cacheHits.incrementAndGet();
 //        }
-//        FeatureStructureImpl fsi = cacheFS[i];
+//        TOP fsi = cacheFS[i];
 //        if (fsi.getAddress() != key) { // recheck to avoid sync 
 //          break; // entry was overwritten
 //        }
@@ -315,7 +306,7 @@ public class JCasHashMap {
 //      cacheMisses.incrementAndGet();  // includes creates
 //    }
     final int hash = hashInt(key);
-    final FeatureStructureImpl r = getSubMap(hash).getReserve(key, hash >>> concurrencyLevelBits);
+    final TOP r = getSubMap(hash).getReserve(key, hash >>> concurrencyLevelBits);
     
 //    if (r != null) {
 //      updateCache(key, r);
@@ -323,17 +314,14 @@ public class JCasHashMap {
     return r;
   }
 
-//  private void updateCache(int key, FeatureStructureImpl value) {
+//  private void updateCache(int key, TOP value) {
 //    final int newIdx = cacheNewIndex;
 //    cacheNewIndex = (cacheNewIndex == (CACHE_SIZE - 1)) ? 0 : cacheNewIndex + 1;
 //    cacheFS[cacheNewIndex] = value;  // update this first to avoid putting in the same value multiple times
 //    cacheInt[cacheNewIndex] = key;
 //  }
   
-  public FeatureStructureImpl put(FeatureStructureImpl value) {
-    if (!this.useCache) {
-      return null;
-    }
+  public TOP put(TOP value) {
     final int key = value.getAddress();
 //    updateCache(key, value);
     final int hash = hashInt(key);

Copied: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMapSubMap.java (from r1712073, uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMapSubMap.java)
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMapSubMap.java?p2=uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMapSubMap.java&p1=uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMapSubMap.java&r1=1712073&r2=1753995&rev=1753995&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMapSubMap.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMapSubMap.java Mon Jul 25 13:44:31 2016
@@ -19,13 +19,12 @@
 
 package org.apache.uima.jcas.impl;
 
+
 import java.util.Arrays;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
 
-import org.apache.uima.cas.impl.FeatureStructureImpl;
 import org.apache.uima.jcas.cas.TOP;
-import org.apache.uima.jcas.cas.TOP_Type;
 
 class JCasHashMapSubMap {
   
@@ -37,16 +36,6 @@ class JCasHashMapSubMap {
   private static final int PROBE_ADDR_INDEX = 0;
   private static final int PROBE_DELTA_INDEX = 1;
 
-
-  private static class ReserveTopType extends TOP_Type {
-    public ReserveTopType() {
-      super();
-    }
-  }
-
-  // package private for test case use
-  static final TOP_Type RESERVE_TOP_TYPE_INSTANCE = new ReserveTopType(); 
-
   static final ThreadLocal<int[]> probeInfoGet = new ThreadLocal<int[]>() {
     protected int[] initialValue() { return new int[2]; } };
       
@@ -67,7 +56,7 @@ class JCasHashMapSubMap {
   
   private int sizeWhichTriggersExpansion;
   int size; // number of elements in the table  
-  volatile FeatureStructureImpl [] table;
+  volatile TOP [] table;
   private boolean secondTimeShrinkable = false;
   
   private final float loadFactor;
@@ -91,9 +80,9 @@ class JCasHashMapSubMap {
     return this;
   }
   
-  private FeatureStructureImpl[] newTableKeepSize(int capacity) {
+  private TOP[] newTableKeepSize(int capacity) {
     assert(Integer.bitCount(capacity) == 1);
-    FeatureStructureImpl[] t = new FeatureStructureImpl[capacity];
+    TOP[] t = new TOP[capacity];
     sizeWhichTriggersExpansion = (int)(capacity * loadFactor);
     return t;
   }
@@ -152,11 +141,11 @@ class JCasHashMapSubMap {
    *    1: (in/out) probeDelta (starts at 1)
    * @return the probeAddr in original table (which might have been resized)
    */
-  private FeatureStructureImpl find(final FeatureStructureImpl[] localTable, final int key, final int hash, final int[] probeInfo) {
+  private TOP find(final TOP[] localTable, final int key, final int hash, final int[] probeInfo) {
     final int bitMask = localTable.length - 1;
     final int startProbe = probeInfo[PROBE_ADDR_INDEX];      
     final int probeAddr = (startProbe < 0) ? (hash & bitMask) : startProbe; 
-    final FeatureStructureImpl m = localTable[probeAddr];
+    final TOP m = localTable[probeAddr];
     // fast paths 
     if (m == null) {
       // not in table
@@ -175,14 +164,14 @@ class JCasHashMapSubMap {
     return find2(localTable, key, probeInfo, probeAddr);
   }
 
-  private FeatureStructureImpl find2(final FeatureStructureImpl[] localTable, final int key, final int[] probeInfo, int probeAddr) {
+  private TOP find2(final TOP[] localTable, final int key, final int[] probeInfo, int probeAddr) {
     final boolean isContinue = TUNE && (probeInfo[PROBE_ADDR_INDEX] != -1); 
     final int bitMask = localTable.length - 1;
 //    assert((startProbe < 0) ? probeInfo[PROBE_DELTA_INDEX] == 1 : true);
     int probeDelta = probeInfo[PROBE_DELTA_INDEX];
     int nbrProbes = 2;  
     probeAddr = bitMask & (probeAddr + (probeDelta++));
-    FeatureStructureImpl m = localTable[probeAddr];
+    TOP m = localTable[probeAddr];
 
     while (null != m) {  // loop to traverse bucket chain
       if (m.getAddress() == key) {
@@ -232,7 +221,7 @@ class JCasHashMapSubMap {
   
   /**
    * Gets a value, but if the value isn't there, it reserves the slot where it will go
-   * with a new instance where the key matches, but the type is a unique value.
+   * with a new instance where the key matches, but the _casView is null.
    * 
    * Threading: not synchronized for main path where get is finding an element.
    *   Since elements are never updated, there is no race if an element is found.
@@ -245,7 +234,7 @@ class JCasHashMapSubMap {
    * @param hash - the hash that was already computed from the key
    * @return - the found fs, or null
    */
-  FeatureStructureImpl getReserve(final int key, final int hash) {
+  TOP getReserve(final int key, final int hash) {
 
     boolean isLocked = false;
     final int[] probeInfo = probeInfoGet.get();
@@ -254,8 +243,8 @@ class JCasHashMapSubMap {
    retry:
       while (true) { // loop back point after locking against updates, to re-traverse the bucket chain from the beginning
         resetProbeInfo(probeInfo);
-        final FeatureStructureImpl m;
-        final FeatureStructureImpl[] localTable = table;
+        final TOP m;
+        final TOP[] localTable = table;
         
         if (isReal(m = find(localTable, key, hash, probeInfo))) {
           return m;  // fast path for found item       
@@ -271,7 +260,7 @@ class JCasHashMapSubMap {
         /*****************
          *    LOCKED     *
          *****************/
-        final FeatureStructureImpl[] localTable3;
+        final TOP[] localTable3;
         if (localTable != table) {
           // redo search from top, because table resized
           resetProbeInfo(probeInfo);
@@ -280,20 +269,20 @@ class JCasHashMapSubMap {
           localTable3 = localTable;
         }
 //        // re acquire the FeatureStructure m, because another thread could change it before the lock got acquired
-//        final FeatureStructureImpl m2 = localTable[probeInfo[PROBE_ADDR_INDEX]];
+//        final TOP m2 = localTable[probeInfo[PROBE_ADDR_INDEX]];
 //        if (isReal(m2)) {
 //          return m2;  // another thread snuck in before the lock and switched this
 //        }
         
         // note: localTable not used from this point, unless reset
         // note: this "find" either finds from the top (if size changed) or finds from current spot.
-        final FeatureStructureImpl m2 = find(localTable3, key, hash, probeInfo);
+        final TOP m2 = find(localTable3, key, hash, probeInfo);
         if (isReal(m2)) {
           return m2;  // fast path for found item       
         }
         
         while (isReserve(m2)) {
-          final FeatureStructureImpl[] localTable2 = table;  // to see if table gets resized
+          final TOP[] localTable2 = table;  // to see if table gets resized
           // can't wait on reserved item because would need to do lock.unlock() followed by wait, but
           //   inbetween these, another thread could already do the notify.
           try {
@@ -308,7 +297,7 @@ class JCasHashMapSubMap {
           if (localTable2 != table) { // table was resized
              continue retry;
           }
-          final FeatureStructureImpl m3 = localTable2[probeInfo[PROBE_ADDR_INDEX]];
+          final TOP m3 = localTable2[probeInfo[PROBE_ADDR_INDEX]];
           if (isReserve(m3)) {
             continue;  // case = interruptedexception && no resize && not changed to real, retry
           }
@@ -321,7 +310,7 @@ class JCasHashMapSubMap {
         // is null. Reserve this slot to prevent other "getReserved" calls for this same instance from succeeding,
         // causing them to wait until this slot gets filled in with a FS value
         // Use table, not localTable, because resize may have occurred
-        table[probeInfo[PROBE_ADDR_INDEX]] = new TOP(key, RESERVE_TOP_TYPE_INSTANCE);
+        table[probeInfo[PROBE_ADDR_INDEX]] = TOP._createJCasHashMapReserve(key); 
         incrementSize();          
         return null;
       }
@@ -333,14 +322,14 @@ class JCasHashMapSubMap {
   }
     
       
-  FeatureStructureImpl put(int key, FeatureStructureImpl value, int hash) {
+  TOP put(int key, TOP value, int hash) {
 
     lock.lock();
     try {
       final int[] probeInfo = probeInfoPut.get();
       resetProbeInfo(probeInfo);
-      final FeatureStructureImpl[] localTable = table;
-      final FeatureStructureImpl prevValue = find(localTable, key, hash, probeInfo);
+      final TOP[] localTable = table;
+      final TOP prevValue = find(localTable, key, hash, probeInfo);
       localTable[probeInfo[PROBE_ADDR_INDEX]] = value;
       if (isReserve(prevValue)) {
         lockCondition.signalAll();
@@ -364,13 +353,13 @@ class JCasHashMapSubMap {
   * @param hash -
   */
   
-  private void putInner(int key, FeatureStructureImpl value, int hash) {
+  private void putInner(int key, TOP value, int hash) {
     assert(lock.getHoldCount() > 0);
     final int[] probeInfo = probeInfoPutInner.get();
     resetProbeInfo(probeInfo);
-    final FeatureStructureImpl[] localTable = table;
+    final TOP[] localTable = table;
 
-    final FeatureStructureImpl m = find(localTable, key, hash, probeInfo);
+    final TOP m = find(localTable, key, hash, probeInfo);
     assert(m == null);  // no dups in original table imply no hits in new one
     localTable[probeInfo[PROBE_ADDR_INDEX]] = value;
   }
@@ -378,7 +367,7 @@ class JCasHashMapSubMap {
 
   // called under lock
   private void increaseTableCapacity() {
-    final FeatureStructureImpl [] oldTable = table; 
+    final TOP [] oldTable = table; 
     final int oldCapacity = oldTable.length;
     int newCapacity = 2 * oldCapacity;
     
@@ -387,7 +376,7 @@ class JCasHashMapSubMap {
     }
     table = newTableKeepSize(newCapacity);
     for (int i = 0; i < oldCapacity; i++) {
-      FeatureStructureImpl fs = oldTable[i];
+      TOP fs = oldTable[i];
       if (fs != null) {
         final int key = fs.getAddress();
         final int hash = JCasHashMap.hashInt(key);
@@ -396,11 +385,12 @@ class JCasHashMapSubMap {
     }
   }
   
-  private static boolean isReserve(FeatureStructureImpl m) {
-    return m != null && ((TOP)m).jcasType == RESERVE_TOP_TYPE_INSTANCE;
+  private static boolean isReserve(TOP m) {
+    return m != null && m._isJCasHashMapReserve();
   }
-  private static boolean isReal(FeatureStructureImpl m) {
-    return m != null && ((TOP)m).jcasType != RESERVE_TOP_TYPE_INSTANCE;
+  
+  private static boolean isReal(TOP m) {
+    return m != null && !m._isJCasHashMapReserve();
   }
   
   private static void resetProbeInfo(int[] probeInfo) {

Copied: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java (from r1712624, uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java)
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java?p2=uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java&p1=uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java&r1=1712624&r2=1753995&rev=1753995&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java Mon Jul 25 13:44:31 2016
@@ -24,13 +24,11 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
-import junit.framework.TestCase;
-
-import org.apache.uima.cas.impl.FeatureStructureImpl;
 import org.apache.uima.internal.util.MultiThreadUtils;
 import org.apache.uima.internal.util.Utilities;
 import org.apache.uima.jcas.cas.TOP;
-import org.apache.uima.jcas.cas.TOP_Type;
+
+import junit.framework.TestCase;
 
 /**
  * Run this as a single test with yourkit, and look at the retained storage for both maps.
@@ -40,20 +38,13 @@ import org.apache.uima.jcas.cas.TOP_Type
  *
  */
 public class JCasHashMapCompareTest extends TestCase {
-  
-  private static class FakeTopType extends TOP_Type {
-    public FakeTopType() {
-      super();
-    }
-  }
-  
+    
   private static final long rm =  0x5deece66dL;
 
   private static int sizeOfTest = 1024 * 8;  
 //  private static final int SIZEm1 = SIZE - 1;
-  private static final TOP_Type FAKE_TOP_TYPE_INSTANCE = new FakeTopType(); 
 //  private JCasHashMap jhm;
-  private ConcurrentMap<Integer, FeatureStructureImpl> concurrentMap;
+  private ConcurrentMap<Integer, TOP> concurrentMap;
 
   
   public void testComp() throws Exception {
@@ -70,7 +61,7 @@ public class JCasHashMapCompareTest exte
 //    stats("custom", runCustom(numberOfThreads));  // not accurate, use yourkit retained size instead
 //    stats("concur", runConCur(numberOfThreads));
     Set<Integer> ints = new HashSet<Integer>();
-    for (Entry<Integer, FeatureStructureImpl> e : concurrentMap.entrySet()) {
+    for (Entry<Integer, TOP> e : concurrentMap.entrySet()) {
       assertFalse(ints.contains(Integer.valueOf(e.getKey())));
       assertEquals(e.getValue().getAddress(), (int)(e.getKey()));
       ints.add(e.getKey());
@@ -83,8 +74,8 @@ public class JCasHashMapCompareTest exte
   }
   
   private int runConCur(int numberOfThreads) throws Exception {
-    final ConcurrentMap<Integer, FeatureStructureImpl> m = 
-        new ConcurrentHashMap<Integer, FeatureStructureImpl>(200, 0.75F, numberOfThreads);
+    final ConcurrentMap<Integer, TOP> m = 
+        new ConcurrentHashMap<Integer, TOP>(200, 0.75F, numberOfThreads);
     concurrentMap = m;
     
     final int numberOfWaiters = numberOfThreads*2;
@@ -99,14 +90,14 @@ public class JCasHashMapCompareTest exte
         for (int i = 0; i < sizeOfTest*threadNumber; i++) {
           final int key = hash(i, threadNumber) / 2;
           final Object waiter = waiters[key & (numberOfWaiters - 1)];
-          FeatureStructureImpl fs = m.putIfAbsent(key, new TOP(key, JCasHashMapSubMap.RESERVE_TOP_TYPE_INSTANCE));
-          while (fs != null && ((TOP)fs).jcasType == JCasHashMapSubMap.RESERVE_TOP_TYPE_INSTANCE) {
+          TOP fs = m.putIfAbsent(key, TOP._createJCasHashMapReserve(key));
+          while (fs != null && fs._isJCasHashMapReserve()) {
             // someone else reserved this
 
             // wait for notify
             synchronized (waiter) {
               fs = m.get(key);
-              if (((TOP)fs).jcasType == JCasHashMapSubMap.RESERVE_TOP_TYPE_INSTANCE) {
+              if (fs._isJCasHashMapReserve()) {
                 try {
                   waiter.wait();
                 } catch (InterruptedException e) {
@@ -115,11 +106,11 @@ public class JCasHashMapCompareTest exte
             }
           }
             
-//          FeatureStructureImpl fs = m.get(key);
+//          TOP fs = m.get(key);
           if (null == fs) {
 //            puts ++;
-            FeatureStructureImpl prev = m.put(key,  new TOP(key, FAKE_TOP_TYPE_INSTANCE));
-            if (((TOP)prev).jcasType == JCasHashMapSubMap.RESERVE_TOP_TYPE_INSTANCE) {
+            TOP prev = m.put(key,  TOP._createSearchKey(key));
+            if (prev._isJCasHashMapReserve()) {
               synchronized (waiter) {
                 waiter.notifyAll();
               }
@@ -154,11 +145,11 @@ public class JCasHashMapCompareTest exte
               ) / 2;
 //          if (key == 456551)
 //            System.out.println("debug");
-          FeatureStructureImpl fs = m.getReserve(key);
+          TOP fs = m.getReserve(key);
 
           if (null == fs) {
 //            puts++;
-            m.put(new TOP(key, FAKE_TOP_TYPE_INSTANCE));
+            m.put(TOP._createSearchKey(key));
           } else {
 //            founds ++;
           }

Propchange: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Jul 25 13:44:31 2016
@@ -0,0 +1,7 @@
+/incubator/uima/uimaj/branches/mavenAlign/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java:932400-933272
+/uima/uimaj/branches/2.6.0-json/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java:1616936-1617592
+/uima/uimaj/branches/depend-on-july-9-build-tools/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java:963167-964468
+/uima/uimaj/branches/depend-on-parent-pom-4/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java:961329-961745
+/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java:1436573-1462257
+/uima/uimaj/branches/mavenAlign/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java:933273-944396
+/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapCompareTest.java:1690273-1693269

Copied: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java (from r1712624, uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java)
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java?p2=uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java&p1=uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java&r1=1712624&r2=1753995&rev=1753995&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java Mon Jul 25 13:44:31 2016
@@ -24,22 +24,14 @@ import java.util.Random;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
-import junit.framework.TestCase;
-
-import org.apache.uima.cas.impl.FeatureStructureImpl;
+import org.apache.uima.internal.util.Misc;
 import org.apache.uima.internal.util.MultiThreadUtils;
-import org.apache.uima.internal.util.Utilities;
 import org.apache.uima.jcas.cas.TOP;
-import org.apache.uima.jcas.cas.TOP_Type;
+
+import junit.framework.TestCase;
 
 public class JCasHashMapTest extends TestCase {
-  static private class FakeTopType extends TOP_Type {
-    public FakeTopType() {
-      super();
-    }    
-  }
   
-  static final TOP_Type FAKE_TOP_TYPE_INSTANCE = new FakeTopType(); 
   static final int SIZE = 20000;  // set > 2 million for cache avoidance timing tests
   static final long SEED = 12345;
   static Random r = new Random(SEED);
@@ -72,11 +64,11 @@ public class JCasHashMapTest extends Tes
       assertEquals(Math.max(1, i / 2), m.getConcurrencyLevel());
       
       //test capacity adjusted up
-      m = new JCasHashMap(32 * i, true, i);
+      m = new JCasHashMap(32 * i, i);
       assertEquals( 32 * i, m.getCapacity());
-      m = new JCasHashMap(31 * i, true, i);
+      m = new JCasHashMap(31 * i, i);
       assertEquals( 32 * i, m.getCapacity());
-      m = new JCasHashMap(16 * i, true, i);
+      m = new JCasHashMap(16 * i, i);
       assertEquals( 32 * i, m.getCapacity());
     }
   }
@@ -97,7 +89,7 @@ public class JCasHashMapTest extends Tes
   
   public void testMultiThread() throws Exception {
     final Random random = new Random();
-    int numberOfThreads = Utilities.numberOfCores;    
+    int numberOfThreads = Misc.numberOfCores;    
     System.out.format("test JCasHashMap with up to %d threads%n", numberOfThreads);
 
     
@@ -110,9 +102,9 @@ public class JCasHashMapTest extends Tes
           for (int k = 0; k < 4; k++) {
             for (int i = 0; i < SIZE / 4; i++) {
               final int key = addrs[random.nextInt(SIZE / 16)];
-              FeatureStructureImpl fs = m.getReserve(key);
+              TOP fs = m.getReserve(key);
               if (null == fs) {
-                m.put(new TOP(key, FAKE_TOP_TYPE_INSTANCE));
+                m.put(TOP._createSearchKey(key));
               }
             }
             try {
@@ -135,11 +127,11 @@ public class JCasHashMapTest extends Tes
 
   public void testMultiThreadCompare() throws Exception {
     final Random random = new Random();
-    int numberOfThreads = Utilities.numberOfCores;    
+    int numberOfThreads = Misc.numberOfCores;    
     System.out.format("test JCasHashMap with compare with up to %d threads%n", numberOfThreads);
 
-    final ConcurrentMap<Integer, FeatureStructureImpl> check = 
-        new ConcurrentHashMap<Integer, FeatureStructureImpl>(SIZE, .5F, numberOfThreads * 2);
+    final ConcurrentMap<Integer, TOP> check = 
+        new ConcurrentHashMap<Integer, TOP>(SIZE, .5F, numberOfThreads * 2);
     
     for (int th = 2; th <= numberOfThreads; th *= 2) {
       JCasHashMap.setDEFAULT_CONCURRENCY_LEVEL(th);
@@ -151,13 +143,13 @@ public class JCasHashMapTest extends Tes
           for (int k = 0; k < 4; k++) {
             for (int i = 0; i < SIZE / 4; i++) {
               final int key = addrs[random.nextInt(SIZE / 16)];
-              FeatureStructureImpl fs = m.getReserve(key);
+              TOP fs = m.getReserve(key);
               if (null == fs) {
-                fs = new TOP(key, FAKE_TOP_TYPE_INSTANCE);
+                fs = TOP._createSearchKey(key);
                 check.put(key, fs);  
                 m.put(fs);
               } else {
-                FeatureStructureImpl fscheck = check.get(key);
+                TOP fscheck = check.get(key);
                 if (fscheck == null || fscheck != fs) {
                   String msg = String.format("JCasHashMapTest miscompare, repeat=%,d, count=%,d key=%,d"
                       + ", checkKey=%s JCasHashMapKey=%,d",
@@ -197,7 +189,7 @@ public class JCasHashMapTest extends Tes
    * @throws Exception
    */
   public void testMultiThreadCollide() throws Exception {
-    int numberOfThreads = Utilities.numberOfCores;
+    int numberOfThreads = Misc.numberOfCores;
     if (numberOfThreads < 2) {
       return;
     }
@@ -210,8 +202,8 @@ public class JCasHashMapTest extends Tes
     final JCasHashMap m = new JCasHashMap(200, true); // true = do use cache 
     final Random r = new Random();  // used to sleep from 0 to 4 milliseconds
     final int hashKey = 15;
-    final TOP fs = new TOP(hashKey, FAKE_TOP_TYPE_INSTANCE);
-    final FeatureStructureImpl[] found = new FeatureStructureImpl[numberOfThreads];
+    final TOP fs = TOP._createSearchKey(hashKey);
+    final TOP[] found = new TOP[numberOfThreads];
     
     for (int i = 0; i < numberOfThreads; i++) {
       final int finalI = i;
@@ -282,7 +274,7 @@ public class JCasHashMapTest extends Tes
         
 //        assertEquals(0, numberWaiting);  // if not 0 by now, something is likely wrong, or machine stalled more than 30 seconds
   //      System.out.format("JCasHashMapTest collide,  found = %s%n", intList(found));
-        for (FeatureStructureImpl f : found) {
+        for (TOP f : found) {
           if (f != fs) {
             System.err.format("JCasHashMapTest miscompare fs = %s,  f = %s%n", fs, (f == null) ? "null" : f);
           }
@@ -306,7 +298,7 @@ public class JCasHashMapTest extends Tes
 //    long start = System.currentTimeMillis();
 //    for (int i = 0; i < n; i++) {
 //      TOP fs = new TOP(7 * i, NULL_TOP_TYPE_INSTANCE);
-//      FeatureStructureImpl v = m.get(fs.getAddress());
+//      TOP v = m.get(fs.getAddress());
 //      if (null == v) {
 //        m.putAtLastProbeAddr(fs);
 //      }
@@ -324,8 +316,8 @@ public class JCasHashMapTest extends Tes
     long start = System.currentTimeMillis();
     for (int i = 0; i < n; i++) {
       final int key = addrs[i];
-      TOP fs = new TOP(key, FAKE_TOP_TYPE_INSTANCE);
-//      FeatureStructureImpl v = m.get(fs.getAddress());
+      TOP fs = TOP._createSearchKey(key);
+//      TOP v = m.get(fs.getAddress());
 //      if (null == v) {
 //        m.get(7 * i);
         m.put(fs);
@@ -345,8 +337,8 @@ public class JCasHashMapTest extends Tes
     
     for (int i = 0; i < n; i++) {
       final int key = addrs[i];
-      TOP fs = new TOP(key, FAKE_TOP_TYPE_INSTANCE);
-//      FeatureStructureImpl v = m.get(fs.getAddress());
+      TOP fs = TOP._createSearchKey(key);
+//      TOP v = m.get(fs.getAddress());
 //      if (null == v) {
 //        m.get(7 * i);
 //        m.findEmptySlot(key);
@@ -382,7 +374,8 @@ public class JCasHashMapTest extends Tes
       System.out.print("JCasHashMapTest: after fill to switch point: ");
       assertTrue(checkSubsCapacity(m, sub_capacity));
       System.out.print("JCasHashMapTest: after 1 past switch point:  ");
-      m.put(new TOP(addrs[switchpoint + 1], null));
+      int key = addrs[switchpoint + 1];
+      m.put(TOP._createSearchKey(key));
       assertTrue(checkSubsCapacity(m, sub_capacity));
       
       m.clear();
@@ -393,7 +386,8 @@ public class JCasHashMapTest extends Tes
       fill(switchpoint, m);
       System.out.print("JCasHashMapTest: after fill to switch point: ");
       assertTrue(checkSubsCapacity(m, sub_capacity));
-      m.put(new TOP(addrs[switchpoint + 1], null));
+      key = addrs[switchpoint + 1];
+      m.put(TOP._createSearchKey(key));
       System.out.print("JCasHashMapTest: after 1 past switch point:  ");
       assertTrue(checkSubsCapacity(m, sub_capacity));
   
@@ -449,9 +443,9 @@ public class JCasHashMapTest extends Tes
     return sb.toString();
   }
   
-  private String intList(FeatureStructureImpl[] a) {
+  private String intList(TOP[] a) {
     StringBuilder sb = new StringBuilder();
-    for (FeatureStructureImpl i : a) {
+    for (TOP i : a) {
       sb.append(i == null ? "null" : i.getAddress()).append(", ");
     }
     return sb.toString();
@@ -460,7 +454,7 @@ public class JCasHashMapTest extends Tes
   private void fill (int n, JCasHashMap m) {
     for (int i = 0; i < n; i++) {
       final int key = addrs[i];
-      TOP fs = new TOP(key, FAKE_TOP_TYPE_INSTANCE);
+      TOP fs = TOP._createSearchKey(key);
       m.put(fs);
 //      System.out.format("JCasHashMapTest fill %s%n",  intList(m.getCapacities()));
     }

Propchange: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Jul 25 13:44:31 2016
@@ -0,0 +1,7 @@
+/incubator/uima/uimaj/branches/mavenAlign/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java:932400-933272
+/uima/uimaj/branches/2.6.0-json/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java:1616936-1617592
+/uima/uimaj/branches/depend-on-july-9-build-tools/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java:963167-964468
+/uima/uimaj/branches/depend-on-parent-pom-4/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java:961329-961745
+/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java:1436573-1462257
+/uima/uimaj/branches/mavenAlign/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java:933273-944396
+/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/impl/JCasHashMapTest.java:1690273-1693269