You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2008/06/06 19:26:53 UTC
svn commit: r664046 - in
/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima:
UIMAFramework.java cas/admin/CASFactory.java cas/impl/CASImpl.java
jcas/impl/JCasHashMap.java jcas/impl/JCasImpl.java util/CasCreationUtils.java
Author: twgoetz
Date: Fri Jun 6 10:26:52 2008
New Revision: 664046
URL: http://svn.apache.org/viewvc?rev=664046&view=rev
Log:
Jira UIMA-1068: initial implementation done, test cases pass. Still need
to add comments, documentation and test case.
https://issues.apache.org/jira/browse/UIMA-1068
Modified:
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/admin/CASFactory.java
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasImpl.java
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCreationUtils.java
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java?rev=664046&r1=664045&r2=664046&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java Fri Jun 6 10:26:52 2008
@@ -82,6 +82,15 @@
public static final Object SOCKET_KEEPALIVE_ENABLED = "socket_keepalive_enabled";
/**
+ * Key to be used in the Properties object returned by
+ * {@link #getDefaultPerformanceTuningProperties()}. The value of this key indicates whether the
+ * JCas object cache should be used (significant memory overhead, but may have performance
+ * benefits). The default is true. A value of "false" (case insensitive) for this property
+ * disables the cache; any other value leaves the default setting of true.
+ */
+ public static final String JCAS_CACHE_ENABLED = "jcas_cache_enabled";
+
+ /**
* To be implemented by subclasses; this should return a Properties object representing the
* default performance tuning settings for the framework. It must return a new Properties object
* each time it is called.
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/admin/CASFactory.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/admin/CASFactory.java?rev=664046&r1=664045&r2=664046&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/admin/CASFactory.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/admin/CASFactory.java Fri Jun 6 10:26:52 2008
@@ -36,6 +36,8 @@
*
*/
public abstract class CASFactory {
+
+ public static final boolean USE_JCAS_CACHE_DEFAULT = true;
/**
* Create a new CASMgr object.
@@ -56,7 +58,11 @@
* @return A new CASMgr object.
*/
public static CASMgr createCAS(int initialHeapSize) {
- return new CASImpl(initialHeapSize);
+ return createCAS(initialHeapSize, USE_JCAS_CACHE_DEFAULT);
+ }
+
+ public static CASMgr createCAS(int initialHeapSize, boolean useJcasCache) {
+ return new CASImpl(initialHeapSize, useJcasCache);
}
/**
@@ -71,10 +77,14 @@
* @return A new CASMgr object.
*/
public static CASMgr createCAS(int initialHeapSize, TypeSystem ts) {
+ return createCAS(initialHeapSize, ts, USE_JCAS_CACHE_DEFAULT);
+ }
+
+ public static CASMgr createCAS(int initialHeapSize, TypeSystem ts, boolean useJcasCache) {
if (ts == null) {
throw new NullPointerException("TypeSystem");
}
- return new CASImpl((TypeSystemImpl) ts, initialHeapSize);
+ return new CASImpl((TypeSystemImpl) ts, initialHeapSize, useJcasCache);
}
/**
@@ -85,10 +95,15 @@
* @return A new CASMgr object.
*/
public static CASMgr createCAS(TypeSystem ts) {
+ return createCAS(ts, USE_JCAS_CACHE_DEFAULT);
+ }
+
+
+ public static CASMgr createCAS(TypeSystem ts, boolean useJcasCache) {
if (ts == null) {
throw new NullPointerException("TypeSystem");
}
- return new CASImpl((TypeSystemImpl) ts, CASImpl.DEFAULT_INITIAL_HEAP_SIZE);
+ return new CASImpl((TypeSystemImpl) ts, CASImpl.DEFAULT_INITIAL_HEAP_SIZE, useJcasCache);
}
/**
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java?rev=664046&r1=664045&r2=664046&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java Fri Jun 6 10:26:52 2008
@@ -69,6 +69,7 @@
import org.apache.uima.cas.Type;
import org.apache.uima.cas.TypeSystem;
import org.apache.uima.cas.admin.CASAdminException;
+import org.apache.uima.cas.admin.CASFactory;
import org.apache.uima.cas.admin.CASMgr;
import org.apache.uima.cas.admin.FSIndexComparator;
import org.apache.uima.cas.admin.FSIndexRepositoryMgr;
@@ -226,6 +227,8 @@
private int mySofaRef = 0;
private JCas jcas = null;
+
+ private final boolean isUsedJcasCache;
private final ArrayList<String> getStringList() {
ArrayList<String> stringList = new ArrayList<String>();
@@ -267,8 +270,8 @@
// initTypeVariables();
// }
- public CASImpl(TypeSystemImpl typeSystem, int initialHeapSize) {
- this(typeSystem, initialHeapSize, DEFAULT_USE_FS_CACHE);
+ public CASImpl(TypeSystemImpl typeSystem, int initialHeapSize, boolean useJcasCache) {
+ this(typeSystem, initialHeapSize, DEFAULT_USE_FS_CACHE, useJcasCache);
}
/*
@@ -279,8 +282,9 @@
* by calling
*/
- CASImpl(TypeSystemImpl typeSystem, int initialHeapSize, boolean useFSCache) {
+ CASImpl(TypeSystemImpl typeSystem, int initialHeapSize, boolean useFSCache, boolean useJcasCache) {
super();
+ this.isUsedJcasCache = useJcasCache;
TypeSystemImpl ts;
final boolean externalTypeSystem = (typeSystem != null);
@@ -318,18 +322,18 @@
* Constructor. Use only if you want to use the low-level APIs.
*/
public CASImpl() {
- this(DEFAULT_INITIAL_HEAP_SIZE);
+ this(DEFAULT_INITIAL_HEAP_SIZE, CASFactory.USE_JCAS_CACHE_DEFAULT);
}
- public CASImpl(int initialHeapSize) {
- this((TypeSystemImpl) null, initialHeapSize);
+ public CASImpl(int initialHeapSize, boolean useJcasCache) {
+ this((TypeSystemImpl) null, initialHeapSize, useJcasCache);
}
// In May 2007, appears to have 1 caller, createCASMgr in Serialization class,
// could have
// out-side the framework callers because it is public.
public CASImpl(CASMgrSerializer ser) {
- this(ser.getTypeSystem(), DEFAULT_INITIAL_HEAP_SIZE);
+ this(ser.getTypeSystem(), DEFAULT_INITIAL_HEAP_SIZE, CASFactory.USE_JCAS_CACHE_DEFAULT);
checkInternalCodes(ser);
// assert(ts != null);
// assert(getTypeSystem() != null);
@@ -337,7 +341,9 @@
}
// Use this when creating a CAS view
- CASImpl(CASImpl cas, SofaFS aSofa) {
+ CASImpl(CASImpl cas, SofaFS aSofa, boolean useJcasCache) {
+ this.isUsedJcasCache = useJcasCache;
+
// these next fields are final and must be set in the constructor
this.svd = cas.svd;
@@ -2254,7 +2260,7 @@
return couldBeThis;
}
// create the initial view, without a Sofa
- CAS aView = new CASImpl(this.svd.baseCAS, null);
+ CAS aView = new CASImpl(this.svd.baseCAS, null, this.isUsedJcasCache);
this.svd.sofaNbr2ViewMap.put(Integer.valueOf(1), aView);
assert (this.svd.viewCount <= 1);
this.svd.viewCount = 1;
@@ -2340,7 +2346,7 @@
// which is now creating the associated view
// create a new CAS view
- aView = new CASImpl(this.svd.baseCAS, aSofa);
+ aView = new CASImpl(this.svd.baseCAS, aSofa, this.isUsedJcasCache);
this.svd.sofaNbr2ViewMap.put(sofaNbrInteger, aView);
verifySofaNameUniqueIfDeserializedViewAdded(sofaNbr, aSofa);
return aView;
@@ -3858,5 +3864,9 @@
}
return viewList.iterator();
}
+
+ public final boolean doUseJcasCache() {
+ return this.isUsedJcasCache;
+ }
}
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java?rev=664046&r1=664045&r2=664046&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasHashMap.java Fri Jun 6 10:26:52 2008
@@ -69,7 +69,10 @@
private int bitsMask; // 1's to "and" with result to keep in range
private int casAddr;
- JCasHashMap(int initialSize) {
+ private final boolean useCache;
+
+ JCasHashMap(int initialSize, boolean doUseCache) {
+ this.useCache = true;
// round initialSize to a power of 2
int n = initialSize;
int i = 0;
@@ -100,11 +103,17 @@
}
public void clear() {
+ if (!this.useCache) {
+ return;
+ }
Arrays.fill(table, null);
size = 0;
}
public FeatureStructureImpl get(int key) {
+ if (!this.useCache) {
+ return null;
+ }
FeatureStructureImpl maybe = table[probe(key)];
while ((null != maybe) && (maybe.getAddress() != key)) {
maybe = table[nextProbe()];
@@ -117,6 +126,9 @@
}
public void put(FeatureStructureImpl value) {
+ if (!this.useCache) {
+ return;
+ }
final int key = value.getAddress();
int probeAddr = probe(key);
if (TUNE) {
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasImpl.java?rev=664046&r1=664045&r2=664046&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/impl/JCasImpl.java Fri Jun 6 10:26:52 2008
@@ -261,7 +261,7 @@
*/
private int prevCaddr2JfsSize = INITIAL_HASHMAP_SIZE;
- private JCasHashMap cAddr2Jfs = new JCasHashMap(INITIAL_HASHMAP_SIZE);
+ private JCasHashMap cAddr2Jfs;
private final Map cAddr2JfsByClassLoader = new HashMap();
@@ -281,10 +281,12 @@
public ClassLoader currentClassLoader = null;
- private JCasSharedView(CASImpl aCAS) {
+ private JCasSharedView(CASImpl aCAS, boolean useJcasCache) {
+ this.cAddr2Jfs = new JCasHashMap(INITIAL_HASHMAP_SIZE, useJcasCache);
cAddr2JfsByClassLoader.put(aCAS.getJCasClassLoader(), cAddr2Jfs);
currentClassLoader = aCAS.getJCasClassLoader();
}
+
}
// *******************
@@ -301,6 +303,8 @@
private final LowLevelIndexRepository ll_IndexRepository;
private final JFSIndexRepository jfsIndexRepository;
+
+ private final boolean isUsedCache;
/*
* typeArray is one per CAS because holds pointers to instances of _Type objects, per CAS Not in
@@ -445,6 +449,7 @@
sharedView = null;
casImpl = null;
ll_IndexRepository = null;
+ isUsedCache = false;
throw new RuntimeException("JCas constructor with no args called, should never be called.");
}
@@ -467,11 +472,12 @@
// * that will be loaded.
this.casImpl = cas;
+ this.isUsedCache = cas.doUseJcasCache();
if (casImpl != casImpl.getBaseCAS()) {
sharedView = ((JCasImpl) casImpl.getBaseCAS().getJCas()).sharedView;
sharedView.errorSet.clear();
} else {
- sharedView = new JCasSharedView(cas);
+ sharedView = new JCasSharedView(cas, this.isUsedCache);
}
this.ll_IndexRepository = casImpl.ll_getIndexRepository();
@@ -505,7 +511,7 @@
final JCasSharedView sv = this.sharedView;
sv.cAddr2Jfs = (JCasHashMap) sv.cAddr2JfsByClassLoader.get(cl);
if (null == sv.cAddr2Jfs) {
- sv.cAddr2Jfs = new JCasHashMap(INITIAL_HASHMAP_SIZE);
+ sv.cAddr2Jfs = new JCasHashMap(INITIAL_HASHMAP_SIZE, this.isUsedCache);
sv.cAddr2JfsByClassLoader.put(cl, sv.cAddr2Jfs);
}
sv.currentClassLoader = cl;
@@ -1019,7 +1025,7 @@
// System.out.println("JCas Shrinking Hashtable from " +
// jcas.prevCaddr2JfsSize);
sv.prevCaddr2JfsSize = hashSize;
- sv.cAddr2Jfs = new JCasHashMap(hashSize);
+ sv.cAddr2Jfs = new JCasHashMap(hashSize, jcas.isUsedCache);
sv.cAddr2JfsByClassLoader.put(e.getKey(), sv.cAddr2Jfs);
} else {
sv.prevCaddr2JfsSize = Math.max(hashSize, sv.prevCaddr2JfsSize);
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCreationUtils.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCreationUtils.java?rev=664046&r1=664045&r2=664046&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCreationUtils.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCreationUtils.java Fri Jun 6 10:26:52 2008
@@ -560,19 +560,29 @@
initialHeapSizeStr = aPerformanceTuningSettings
.getProperty(UIMAFramework.CAS_INITIAL_HEAP_SIZE);
}
+
+ // Check Jcas cache performance setting. Defaults to true.
+ boolean useJcasCache = false;
+ if (aPerformanceTuningSettings != null) {
+ String useJcasCacheString = aPerformanceTuningSettings.getProperty(
+ UIMAFramework.JCAS_CACHE_ENABLED, "true");
+ if ("false".equalsIgnoreCase(useJcasCacheString)) {
+ useJcasCache = false;
+ }
+ }
// create CAS using either aTypeSystem or aTypeSystemDesc
CASMgr casMgr;
if (aTypeSystem != null) {
if (initialHeapSizeStr != null) {
- casMgr = CASFactory.createCAS(Integer.parseInt(initialHeapSizeStr), aTypeSystem);
+ casMgr = CASFactory.createCAS(Integer.parseInt(initialHeapSizeStr), aTypeSystem, useJcasCache);
} else {
- casMgr = CASFactory.createCAS(aTypeSystem);
+ casMgr = CASFactory.createCAS(aTypeSystem, useJcasCache);
}
} else // no TypeSystem to reuse - create a new one
{
if (initialHeapSizeStr != null) {
- casMgr = CASFactory.createCAS(Integer.parseInt(initialHeapSizeStr));
+ casMgr = CASFactory.createCAS(Integer.parseInt(initialHeapSizeStr), useJcasCache);
} else {
casMgr = CASFactory.createCAS();
}