Author: schor
Date: Sat Dec 23 19:15:04 2017
New Revision: 1819177

URL: http://svn.apache.org/viewvc?rev=1819177&view=rev
Log:
[UIMA-5662] change impl to match docs, fix bug - not resetting lastFsId on reset

Modified:
    
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
    
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelCAS.java

Modified: 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java?rev=1819177&r1=1819176&r2=1819177&view=diff
==============================================================================
--- 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
 (original)
+++ 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
 Sat Dec 23 19:15:04 2017
@@ -223,7 +223,7 @@ public class CASImpl extends AbstractCas
       !IS_REPORT_FS_UPDATE_CORRUPTS_INDEX &&
       !IS_THROW_EXCEPTION_CORRUPT_INDEX;
  
-  public static final String ALWAYS_HOLD_ONTO_FSS = 
"uima.enable_id_to_feature_structure_map_for_all_fss";
+  public static final String ALWAYS_HOLD_ONTO_FSS = 
"uima.default_v2_id_references";
   static final boolean IS_ALWAYS_HOLD_ONTO_FSS =    // debug and users of 
low-level cas apis with deserialization
       Misc.getNoValueSystemProperty(ALWAYS_HOLD_ONTO_FSS);
 //  private static final int REF_DATA_FOR_ALLOC_SIZE = 1024;
@@ -238,7 +238,14 @@ public class CASImpl extends AbstractCas
     new DebugNameValuePair(null, null);
     new DebugFSLogicalStructure();
   }
-
+  
+  private final static ThreadLocal<Boolean> defaultV2IdRefs = 
+      InheritableThreadLocal.withInitial(() -> null);
+  
+  public static ThreadLocal<Boolean> getDefaultV2IdRefs() {
+    return defaultV2IdRefs;
+  }
+  
   // Static classes representing shared instance data
   // - shared data is computed once for all views
   
@@ -543,8 +550,8 @@ public class CASImpl extends AbstractCas
      *      or the V2 "address" imputed from that)
      *    modify serializers to include reachables only found via id2fs table
      */
-    private boolean isId2Fs = IS_ALWAYS_HOLD_ONTO_FSS;  // default (usually 
false unless this global is set
-        
+    private boolean isId2Fs;
+                
     private SharedViewData(CASImpl baseCAS, int initialHeapSize, 
TypeSystemImpl tsi) {
       this.baseCAS = baseCAS;
       this.tsi = tsi;
@@ -552,11 +559,17 @@ public class CASImpl extends AbstractCas
       bcsd = new BinaryCasSerDes(baseCAS);
       id2fs = new Id2FS(initialHeapSize);
       if (traceFSs) id2addr.add(0);
+      
+      Boolean v = getDefaultV2IdRefs().get();
+      isId2Fs = (v == null) 
+                  ? IS_ALWAYS_HOLD_ONTO_FSS
+                  : v;
     }
     
     void clearCasReset() {
       // fss
       fsIdGenerator = 0;
+      lastFsV2Size = 1;
       id2fs.clear();
       
       // pear caches
@@ -783,13 +796,13 @@ public class CASImpl extends AbstractCas
   //    assert(l.size() == (2 + fsIdGenerator));
       final int p = fsIdGenerator;
       
-      final int r = fsIdGenerator += (IS_ALWAYS_HOLD_ONTO_FSS || isId2Fs) 
+      final int r = fsIdGenerator += isId2Fs 
                                        ? lastFsV2Size
                                        : 1;
       if (r < p) { 
         throw new RuntimeException("UIMA Cas Internal id value overflowed 
maximum int value");
       }
-      if (IS_ALWAYS_HOLD_ONTO_FSS || isId2Fs) {
+      if (isId2Fs) {
         // this computation is partial - misses length of arrays stored on heap
         // because that info not yet available  
         // It is added later via call to adjustLastFsV2size(int)
@@ -4698,7 +4711,7 @@ public class CASImpl extends AbstractCas
   }
   
   private void setId2FsMaybeUnconditionally(TOP fs) {
-    if (IS_ALWAYS_HOLD_ONTO_FSS || svd.isId2Fs) {
+    if (svd.isId2Fs) {
       svd.id2fs.putUnconditionally(fs);
     } else {
       set_id2fs(fs);
@@ -5546,7 +5559,7 @@ public class CASImpl extends AbstractCas
   }
   
   void maybeHoldOntoFS(FeatureStructureImplC fs) {
-    if (IS_ALWAYS_HOLD_ONTO_FSS || svd.isId2Fs) {
+    if (svd.isId2Fs) {
       svd.id2fs.putUnconditionally((TOP)fs);
     }
   }
@@ -5610,11 +5623,11 @@ public class CASImpl extends AbstractCas
     };
   }
   
-  public boolean is_ll_enable_id_to_fs_map() {
+  public boolean is_ll_enableV2IdRefs() {
     return svd.isId2Fs;
   }
   
-  public AutoCloseableNoException ll_enable_id_to_fs_map(boolean enable) {
+  public AutoCloseableNoException ll_enableV2IdRefs(boolean enable) {
     final boolean restoreState = svd.isId2Fs;
     AutoCloseableNoException r = () -> svd.isId2Fs = restoreState; 
     svd.isId2Fs = enable;

Modified: 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelCAS.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelCAS.java?rev=1819177&r1=1819176&r2=1819177&view=diff
==============================================================================
--- 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelCAS.java
 (original)
+++ 
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelCAS.java
 Sat Dec 23 19:15:04 2017
@@ -76,6 +76,7 @@ import org.apache.uima.util.AutoCloseabl
  * 
  */
 public interface LowLevelCAS {
+  
   /**
    * Not a valid type. Type class constant returned by
    * {@link #ll_getTypeClass(int) ll_getTypeClass()}.
@@ -832,14 +833,14 @@ public interface LowLevelCAS {
   CASImpl ll_getSofaCasView(int addr);
   
   int ll_getSofa();
-  
+    
   /**
    * Enables the id_to_fs_map mode. 
    * @return an AutoClosable whose close method doesn't throw an exception
    *   that will reset the mode to what it was when it was changed
    */
-  default AutoCloseableNoException ll_enable_id_to_fs_map() {
-    return ll_enable_id_to_fs_map(true);
+  default AutoCloseableNoException ll_enableV2IdRefs() {
+    return ll_enableV2IdRefs(true);
   }
   
   /**
@@ -847,12 +848,32 @@ public interface LowLevelCAS {
    * @return an AutoClosable whose close method doesn't throw an exception
    *   that will reset the mode to what it was when it was changed
    */
-  AutoCloseableNoException ll_enable_id_to_fs_map(boolean enable);
+  AutoCloseableNoException ll_enableV2IdRefs(boolean enable);
   
   /**
    * @return true if the id_to_fs_map mode is enabled
    */
-  boolean is_ll_enable_id_to_fs_map();
+  boolean is_ll_enableV2IdRefs();
+  
+  /**
+   * Defaults new CASs to have the id_to_fs_map enabled
+   * @return an AutoCloseable which restores the previous setting
+   */
+  static AutoCloseableNoException ll_defaultV2IdRefs() {
+    return ll_defaultV2IdRefs(true);
+  }
   
+  /**
+   * Sets the defaults for new CASs to have the id_to_fs_map enabled.
+   * @return an AutoCloseable which restores the previous setting
+   */
+  static AutoCloseableNoException ll_defaultV2IdRefs(boolean enable) {
+    final ThreadLocal<Boolean> tl = CASImpl.getDefaultV2IdRefs(); 
+    final Boolean prev = tl.get();  // could be null, true or false
+    AutoCloseableNoException r = () -> tl.set(prev);     
+    tl.set(enable);
+    return r;
+  }
+
 }
 


Reply via email to