xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r233375 - in /xmlbeans/trunk: ./ src/common/org/apache/xmlbeans/impl/common/ src/store/org/apache/xmlbeans/impl/store/ src/typeimpl/org/apache/xmlbeans/impl/schema/ test/perf/bin/
Date Thu, 18 Aug 2005 20:49:41 GMT
Author: radup
Date: Thu Aug 18 13:49:36 2005
New Revision: 233375

URL: http://svn.apache.org/viewcvs?rev=233375&view=rev
Log:
Added a new interface to the XmlBeans caches, so that it is possible to implement different
caching strategies for example in multi-threaded environments that are more efficient than
the default mechanisms.


Added:
    xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/SystemCache.java
Modified:
    xmlbeans/trunk/build.xml
    xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscChecker.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
    xmlbeans/trunk/test/perf/bin/run_v2.sh

Modified: xmlbeans/trunk/build.xml
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/build.xml?rev=233375&r1=233374&r2=233375&view=diff
==============================================================================
--- xmlbeans/trunk/build.xml (original)
+++ xmlbeans/trunk/build.xml Thu Aug 18 13:49:36 2005
@@ -480,7 +480,6 @@
         <javac srcdir="src/xmlpublic" destdir="build/classes/xmlpublic" source="${javac.source}"
target="${javac.target}" debug="on">
             <classpath>
                 <pathelement location="build/classes/xmlinputstream"/>
-                <pathelement location="build/classes/common"/>
                 <pathelement location="build/lib/jsr173_api.jar"/>
             </classpath>
         </javac>

Added: xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/SystemCache.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/SystemCache.java?rev=233375&view=auto
==============================================================================
--- xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/SystemCache.java (added)
+++ xmlbeans/trunk/src/common/org/apache/xmlbeans/impl/common/SystemCache.java Thu Aug 18
13:49:36 2005
@@ -0,0 +1,102 @@
+/*   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.xmlbeans.impl.common;
+
+import java.lang.ref.SoftReference;
+import java.util.ArrayList;
+
+import org.apache.xmlbeans.SchemaTypeLoader;
+import org.apache.xmlbeans.SystemProperties;
+
+public class SystemCache
+{
+    private static SystemCache INSTANCE = new SystemCache();
+
+    static
+    {
+        String cacheClass = SystemProperties.getProperty("xmlbean.systemcacheimpl");
+        Object impl = null;
+        if (cacheClass != null)
+        {
+            try
+            {
+                impl = Class.forName(cacheClass).newInstance();
+                if (!(impl instanceof SystemCache))
+                throw new ClassCastException("Value for system property " +
+                    "\"xmlbean.systemcacheimpl\" points to a class (" + cacheClass +
+                    ") which does not derive from SystemCache");
+            }
+            catch (ClassNotFoundException cnfe)
+            {
+                throw new RuntimeException("Cache class " + cacheClass +
+                    " specified by \"xmlbean.systemcacheimpl\" was not found.",
+                    cnfe);
+            }
+            catch (InstantiationException ie)
+            {
+                throw new RuntimeException("Could not instantiate class " +
+                    cacheClass + " as specified by \"xmlbean.systemcacheimpl\"." +
+                    " An empty constructor may be missing.", ie);
+            }
+            catch (IllegalAccessException iae)
+            {
+                throw new RuntimeException("Could not instantiate class " +
+                    cacheClass + " as specified by \"xmlbean.systemcacheimpl\"." +
+                    " A public empty constructor may be missing.", iae);
+            }
+        }
+        if (impl != null)
+            INSTANCE = (SystemCache) impl;
+    }
+
+    public static synchronized final void set(SystemCache instance)
+    {
+        if (INSTANCE.getClass() != SystemCache.class)
+            throw new RuntimeException("Cache instance is already set to class " +
+                INSTANCE.getClass().getName());
+        INSTANCE = instance;
+    }
+
+    public static final SystemCache get()
+    {
+        return INSTANCE;
+    }
+
+    public SchemaTypeLoader getFromTypeLoaderCache(ClassLoader cl)
+    {
+        return null;
+    }
+
+    public void addToTypeLoaderCache(SchemaTypeLoader stl, ClassLoader cl)
+    {
+        return;
+    }
+
+    private static ThreadLocal tl_saxLoaders = new ThreadLocal();
+
+    public Object getSaxLoader()
+    {
+        SoftReference s = (SoftReference) tl_saxLoaders.get();
+        if (s == null)
+            return null;
+        else
+            return s.get();
+    }
+
+    public void setSaxLoader(Object saxLoader)
+    {
+        tl_saxLoaders.set(new SoftReference(saxLoader));
+    }
+}

Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java?rev=233375&r1=233374&r2=233375&view=diff
==============================================================================
--- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java (original)
+++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java Thu Aug 18 13:49:36
2005
@@ -71,6 +71,7 @@
 import org.apache.xmlbeans.impl.common.QNameHelper;
 import org.apache.xmlbeans.impl.common.XmlLocale;
 import org.apache.xmlbeans.impl.common.ResolverUtil;
+import org.apache.xmlbeans.impl.common.SystemCache;
 
 import org.apache.xmlbeans.impl.store.Saaj.SaajCallback;
 
@@ -3000,23 +3001,13 @@
         }
     }
 
-    private static ThreadLocal tl_piccoloLoaders =
-        new ThreadLocal()
-        {
-            protected Object initialValue()
-            {
-                return new SoftReference(PiccoloSaxLoader.newInstance());
-            }
-        };
-
     private static SaxLoader getPiccoloSaxLoader()
     {
-        SoftReference softRef = (SoftReference) tl_piccoloLoaders.get();
-        SaxLoader piccoloLoader = (SaxLoader) (softRef).get();
+        SaxLoader piccoloLoader = (SaxLoader) SystemCache.get().getSaxLoader();
         if (piccoloLoader == null)
         {
             piccoloLoader = PiccoloSaxLoader.newInstance();
-            tl_piccoloLoaders.set(new SoftReference(piccoloLoader));
+            SystemCache.get().setSaxLoader(piccoloLoader);
         }
         return piccoloLoader;
     }

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java?rev=233375&r1=233374&r2=233375&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
(original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
Thu Aug 18 13:49:36 2005
@@ -24,6 +24,7 @@
 import org.apache.xmlbeans.SchemaTypeSystem;
 import org.apache.xmlbeans.SchemaIdentityConstraint;
 import org.apache.xmlbeans.ResourceLoader;
+import org.apache.xmlbeans.impl.common.SystemCache;
 import org.apache.xmlbeans.impl.common.QNameHelper;
 import org.apache.xmlbeans.impl.common.XBeanDebug;
 import javax.xml.namespace.QName;
@@ -58,59 +59,85 @@
 
     public static String METADATA_PACKAGE_LOAD = SchemaTypeSystemImpl.METADATA_PACKAGE_GEN;
     private static final Object CACHED_NOT_FOUND = new Object();
-        
-    // The following maintains a cache of SchemaTypeLoaders per ClassLoader per Thread.
-    // I use soft references to allow the garbage collector to reclain the type loaders
-    // and/pr class loaders at will.
-
-    private static ThreadLocal _cachedTypeSystems =
-        new ThreadLocal() { protected Object initialValue() { return new ArrayList(); } };
 
-    public static SchemaTypeLoaderImpl getContextTypeLoader ( )
+    private static class SchemaTypeLoaderCache extends SystemCache
     {
-        ClassLoader cl = Thread.currentThread().getContextClassLoader();
-        ArrayList a = (ArrayList) _cachedTypeSystems.get();
+        // The following maintains a cache of SchemaTypeLoaders per ClassLoader per Thread.
+        // I use soft references to allow the garbage collector to reclain the type loaders
+        // and/pr class loaders at will.
 
-        int candidate = -1;
-        SchemaTypeLoaderImpl result = null;
+        private static ThreadLocal _cachedTypeSystems =
+            new ThreadLocal() { protected Object initialValue() { return new ArrayList();
} };
 
-        for ( int i = 0 ; i < a.size() ; i++ )
+        public SchemaTypeLoader getFromTypeLoaderCache(ClassLoader cl)
         {
-            SchemaTypeLoaderImpl tl = (SchemaTypeLoaderImpl) ((SoftReference) a.get( i )).get();
+            ArrayList a = (ArrayList) _cachedTypeSystems.get();
+
+            int candidate = -1;
+            SchemaTypeLoaderImpl result = null;
 
-            if (tl == null)
+            for ( int i = 0 ; i < a.size() ; i++ )
             {
-                assert i > candidate;
-                a.remove( i-- );
+                SchemaTypeLoaderImpl tl = (SchemaTypeLoaderImpl) ((SoftReference) a.get(
i )).get();
+
+                if (tl == null)
+                {
+                    assert i > candidate;
+                    a.remove( i-- );
+                }
+                else if (tl._classLoader == cl)
+                {
+                    assert candidate == -1 && result == null;
+
+                    candidate = i;
+                    result = tl;
+
+                    break;
+                }
             }
-            else if (tl._classLoader == cl)
-            {
-                assert candidate == -1 && result == null;
-                
-                candidate = i;
-                result = tl;
 
-                break;
+            // Make sure the most recently accessed entry is at the beginning of the array
+
+            if (candidate > 0)
+            {
+                Object t = a.get( 0 );
+                a.set( 0, a.get( candidate ) );
+                a.set( candidate, t );
             }
+
+            return result;
         }
 
-        if (candidate < 0)
+        public void addToTypeLoaderCache(SchemaTypeLoader stl, ClassLoader cl)
         {
-            result =
-                new SchemaTypeLoaderImpl(
-                    new SchemaTypeLoader[] { BuiltinSchemaTypeSystem.get() }, null, cl );
-            
-            candidate = a.size();
-            a.add( new SoftReference( result ) );
+            assert (stl instanceof SchemaTypeLoaderImpl) &&
+                ((SchemaTypeLoaderImpl) stl)._classLoader == cl;
+
+            ArrayList a = (ArrayList) _cachedTypeSystems.get();
+            // Make sure this entry is at the top of the stack
+            if (a.size() > 0)
+            {
+                Object t = a.get( 0 );
+                a.set( 0, new SoftReference( stl ) );
+                a.add( t );
+            }
+            else
+                a.add( new SoftReference( stl ) );
         }
+    }
 
-        // Make sure the most recently accessed entry is at the beginning of the array
+    public static SchemaTypeLoaderImpl getContextTypeLoader ( )
+    {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        SchemaTypeLoaderImpl result = (SchemaTypeLoaderImpl)
+            SystemCache.get().getFromTypeLoaderCache(cl);
 
-        if (candidate > 0)
+        if (result == null)
         {
-            Object t = a.get( 0 );
-            a.set( 0, a.get( candidate ) );
-            a.set( candidate, t );
+            result =
+                new SchemaTypeLoaderImpl(
+                    new SchemaTypeLoader[] { BuiltinSchemaTypeSystem.get() }, null, cl );
+            SystemCache.get().addToTypeLoaderCache(result, cl);
         }
 
         return result;
@@ -579,4 +606,9 @@
     }
 
     private static final SchemaTypeLoader[] EMPTY_SCHEMATYPELOADER_ARRAY = new SchemaTypeLoader[0];
+
+    static
+    {
+        SystemCache.set(new SchemaTypeLoaderCache());
+    }
 }

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscChecker.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscChecker.java?rev=233375&r1=233374&r2=233375&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscChecker.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscChecker.java Thu Aug 18
13:49:36 2005
@@ -619,10 +619,10 @@
             errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_DERIVATION_MAP_AND_SUM$SUM_MIN_OCCURS_GTE_MIN_OCCURS,
                 new Object[] { derivedRangeMin.toString(), baseModel.getMinOccurs().toString()
},
                 context));
-        } else if (baseModel.getMaxOccurs() == UNBOUNDED || derivedRangeMax != UNBOUNDED
&& derivedRangeMax.compareTo(baseModel.getMaxOccurs()) > 0) {
+        } else if (baseModel.getMaxOccurs() != UNBOUNDED && (derivedRangeMax == UNBOUNDED
|| derivedRangeMax.compareTo(baseModel.getMaxOccurs()) > 0)) {
             mapAndSumValid = false;
             errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_DERIVATION_MAP_AND_SUM$SUM_MAX_OCCURS_LTE_MAX_OCCURS,
-                new Object[] { derivedRangeMax.toString(), baseModel.getMaxOccurs().toString()
},
+                    new Object[] { derivedRangeMax == UNBOUNDED ? "unbounded" : derivedRangeMax.toString(),
baseModel.getMaxOccurs().toString() },
                 context));
         }
 

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java?rev=233375&r1=233374&r2=233375&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java Thu Aug 18
13:49:36 2005
@@ -41,7 +41,6 @@
 import java.net.URI;
 import java.net.URL;
 import java.io.File;
-import java.lang.ref.SoftReference;
 
 
 import javax.xml.namespace.QName;

Modified: xmlbeans/trunk/test/perf/bin/run_v2.sh
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/bin/run_v2.sh?rev=233375&r1=233374&r2=233375&view=diff
==============================================================================
--- xmlbeans/trunk/test/perf/bin/run_v2.sh (original)
+++ xmlbeans/trunk/test/perf/bin/run_v2.sh Thu Aug 18 13:49:36 2005
@@ -45,32 +45,32 @@
 sh ./v2.sh POValidateXmlObjV2
 sh ./v2.sh PrimTopDownV2
 sh ./v2.sh NPrimTopDownV2
-sh ./v2.sh CursorWalkV2 deep-attributes
-sh ./v2.sh CursorWalkV2 deep-elements
-sh ./v2.sh CursorWalkV2 wide-attributes
-sh ./v2.sh CursorWalkV2 wide-elements
-sh ./v2.sh CursorWalkV2 wide-text
-sh ./v2.sh CursorGetAttributeV2 deep-attributes
-sh ./v2.sh CursorGetAttributeV2 wide-attributes
-sh ./v2.sh CursorGetSetGetAttributeV2 deep-attributes
-sh ./v2.sh CursorGetSetGetAttributeV2 wide-attributes
+sh ./v2.sh CursorWalkV2 flavor deep-attributes
+sh ./v2.sh CursorWalkV2 flavor deep-elements
+sh ./v2.sh CursorWalkV2 flavor wide-attributes
+sh ./v2.sh CursorWalkV2 flavor wide-elements
+sh ./v2.sh CursorWalkV2 flavor wide-text
+sh ./v2.sh CursorGetAttributeV2 flavor deep-attributes
+sh ./v2.sh CursorGetAttributeV2 flavor wide-attributes
+sh ./v2.sh CursorGetSetGetAttributeV2 flavor deep-attributes
+sh ./v2.sh CursorGetSetGetAttributeV2 flavor wide-attributes
 sh ./v2.sh CursorGetElementV2
 sh ./v2.sh CursorGetSetGetElementV2
-sh ./v2.sh BisLoadV2 deep-attributes
-sh ./v2.sh BisLoadV2 deep-elements
-sh ./v2.sh BisLoadV2 wide-attributes
-sh ./v2.sh BisLoadV2 wide-elements
-sh ./v2.sh BisLoadV2 wide-text
-sh ./v2.sh DomWalkV2 deep-attributes
-sh ./v2.sh DomWalkV2 deep-elements
-sh ./v2.sh DomWalkV2 wide-attributes
-sh ./v2.sh DomWalkV2 wide-elements 
-sh ./v2.sh DomWalkV2 wide-text
-sh ./v2.sh DomWalkNLV2 deep-attributes
-sh ./v2.sh DomWalkNLV2 deep-elements
-sh ./v2.sh DomWalkNLV2 wide-attributes
-sh ./v2.sh DomWalkNLV2 wide-elements 
-sh ./v2.sh DomWalkNLV2 wide-text
+sh ./v2.sh BisLoadV2 flavor deep-attributes
+sh ./v2.sh BisLoadV2 flavor deep-elements
+sh ./v2.sh BisLoadV2 flavor wide-attributes
+sh ./v2.sh BisLoadV2 flavor wide-elements
+sh ./v2.sh BisLoadV2 flavor wide-text
+sh ./v2.sh DomWalkV2 flavor deep-attributes
+sh ./v2.sh DomWalkV2 flavor deep-elements
+sh ./v2.sh DomWalkV2 flavor wide-attributes
+sh ./v2.sh DomWalkV2 flavor wide-elements 
+sh ./v2.sh DomWalkV2 flavor wide-text
+sh ./v2.sh DomWalkNLV2 flavor deep-attributes
+sh ./v2.sh DomWalkNLV2 flavor deep-elements
+sh ./v2.sh DomWalkNLV2 flavor wide-attributes
+sh ./v2.sh DomWalkNLV2 flavor wide-elements 
+sh ./v2.sh DomWalkNLV2 flavor wide-text
 sh v2.sh MaxMemUntypedBisLoadV2 memory 64 flavor deep-attributes
 sh v2.sh MaxMemUntypedBisLoadV2 memory 128 flavor deep-attributes
 sh v2.sh MaxMemUntypedBisLoadV2 memory 256 flavor deep-attributes



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org


Mime
View raw message