You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by da...@apache.org on 2004/03/16 01:04:37 UTC
cvs commit: xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store CursorData.java Cursor.java Root.java
daveremy 2004/03/15 16:04:37
Modified: v1/src/typeimpl/org/apache/xmlbeans/impl/schema
SchemaTypeLoaderImpl.java
v1/src/xmlstore/org/apache/xmlbeans/impl/store Cursor.java
Root.java
Added: v1/src/xmlstore/org/apache/xmlbeans/impl/store
CursorData.java
Log:
XmlCursor perf: thread local cache of CursorData
DRTs: pass
Revision Changes Path
1.5 +3 -2 xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
Index: SchemaTypeLoaderImpl.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SchemaTypeLoaderImpl.java 3 Mar 2004 22:56:38 -0000 1.4
+++ SchemaTypeLoaderImpl.java 16 Mar 2004 00:04:36 -0000 1.5
@@ -30,6 +30,7 @@
import java.io.InputStream;
import java.util.Map;
import java.util.HashMap;
+import java.util.WeakHashMap;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
@@ -60,12 +61,12 @@
private static ThreadLocal _threadTypeSystems =
new ThreadLocal()
{
- protected Object initialValue() { return new HashMap(); }
+ protected Object initialValue() { return new WeakHashMap(); }
};
public static SchemaTypeLoaderImpl getContextTypeLoader()
{
- HashMap candidates = (HashMap) _threadTypeSystems.get();
+ WeakHashMap candidates = (WeakHashMap) _threadTypeSystems.get();
ClassLoader threadContextClassLoader = Thread.currentThread().getContextClassLoader();
SchemaTypeLoaderImpl candidate = (SchemaTypeLoaderImpl) candidates.get( threadContextClassLoader );
1.7 +51 -74 xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Cursor.java
Index: Cursor.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Cursor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Cursor.java 12 Feb 2004 20:06:04 -0000 1.6
+++ Cursor.java 16 Mar 2004 00:04:36 -0000 1.7
@@ -53,18 +53,8 @@
public final class Cursor implements XmlCursor, ChangeListener
{
- Cursor ( Root r, Splay s ) { assert s != null; _goober = new CursorGoober( r ); set( s ); }
- Cursor ( Root r, Splay s, int p ) { assert s != null; _goober = new CursorGoober( r ); set( s, p ); }
-
- protected void finalize ( )
- {
- Splay s = getSplay();
-
- if (s != null)
- {
- dispose();
- }
- }
+ Cursor ( Root r, Splay s ) { assert s != null; _data = CursorData.getOne( r ); set( s ); }
+ Cursor ( Root r, Splay s, int p ) { assert s != null; _data = CursorData.getOne( r ); set( s, p ); }
//
//
@@ -75,15 +65,15 @@
return getRoot();
}
- Root getRoot ( ) { return _goober.getRoot(); }
+ Root getRoot ( ) { return _data._goober.getRoot(); }
- Splay getSplay ( ) { return _goober.getSplay(); }
- int getPos ( ) { return _goober.getPos(); }
+ Splay getSplay ( ) { return _data._goober.getSplay(); }
+ int getPos ( ) { return _data._goober.getPos(); }
- void set ( Splay s, int p ) { _goober.set( s, p ); }
- void set ( Splay s ) { _goober.set( s, 0 ); }
- void set ( int p ) { _goober.set( p ); }
- void set ( Goober g ) { _goober.set( g ); }
+ void set ( Splay s, int p ) { _data._goober.set( s, p ); }
+ void set ( Splay s ) { _data._goober.set( s, 0 ); }
+ void set ( int p ) { _data._goober.set( p ); }
+ void set ( Goober g ) { _data._goober.set( g ); }
int getPostCch ( )
{
@@ -128,7 +118,7 @@
boolean isDisposed ( )
{
- return getSplay() == null;
+ return _data == null;
}
//
@@ -141,12 +131,8 @@
{
if (!isDisposed())
{
- clearSelections();
-
- if (_stack != null)
- _stack.dispose();
-
- set( (Splay) null );
+ _data.release();
+ _data = null;
}
}
}
@@ -238,7 +224,7 @@
if (c == null)
return false;
- set( c._goober );
+ set( c._data._goober );
return true;
}
@@ -1111,7 +1097,7 @@
if (a._key == null)
throw new IllegalArgumentException( "Annotation key is null" );
- a.set( _goober );
+ a.set( _data._goober );
annotation._currentMark = a;
}
}
@@ -2759,10 +2745,10 @@
{
checkDisposed();
- if (_stack == null)
- _stack = new Selections();
+ if (_data._stack == null)
+ _data._stack = new Selections();
- _stack.add( getRoot(), getSplay(), getPos() );
+ _data._stack.add( getRoot(), getSplay(), getPos() );
getRoot().registerForChange( this );
}
@@ -2774,12 +2760,12 @@
{
checkDisposed();
- if (_stack == null || _stack.size() == 0)
+ if (_data._stack == null || _data._stack.size() == 0)
return false;
- _stack.setCursor( this, _stack.size() - 1 );
+ _data._stack.setCursor( this, _data._stack.size() - 1 );
- _stack.pop();
+ _data._stack.pop();
return true;
}
@@ -2791,7 +2777,7 @@
{
checkDisposed();
- return _selections == null ? 0 : _selections.size();
+ return _data._selections == null ? 0 : _data._selections.size();
}
}
@@ -2801,9 +2787,9 @@
{
checkDisposed();
- if (_selections != null && i >= 0 && _selections.setCursor( this, i ))
+ if (_data._selections != null && i >= 0 && _data._selections.setCursor( this, i ))
{
- _currentSelection = i;
+ _data._currentSelection = i;
return true;
}
@@ -2816,7 +2802,7 @@
synchronized ( monitor() )
{
push();
- int currentSelection = _currentSelection;
+ int currentSelection = _data._currentSelection;
try
{
@@ -2825,7 +2811,7 @@
finally
{
pop();
- _currentSelection = currentSelection;
+ _data._currentSelection = currentSelection;
}
}
}
@@ -2836,18 +2822,18 @@
{
checkDisposed();
- if (_selections == null || _currentSelection < -1)
+ if (_data._selections == null || _data._currentSelection < -1)
return false;
- int nextSelection = _currentSelection + 1;
+ int nextSelection = _data._currentSelection + 1;
- if (!_selections.setCursor( this, nextSelection ))
+ if (!_data._selections.setCursor( this, nextSelection ))
{
- _currentSelection = -2;
+ _data._currentSelection = -2;
return false;
}
- _currentSelection = nextSelection;
+ _data._currentSelection = nextSelection;
return true;
}
@@ -2858,11 +2844,7 @@
synchronized ( monitor() )
{
checkDisposed();
-
- if (_selections != null)
- _selections.dispose();
-
- _currentSelection = -2;
+ _data.clearSelections();
}
}
@@ -2872,13 +2854,13 @@
{
checkDisposed();
- if (_selections == null)
- _selections = Path.newSelections();
+ if (_data._selections == null)
+ _data._selections = Path.newSelections();
// Force any selection engine to search all...
- _selections.size();
+ _data._selections.size();
- _selections.add( getRoot(), getSplay(), getPos() );
+ _data._selections.add( getRoot(), getSplay(), getPos() );
getRoot().registerForChange( this );
}
@@ -2886,14 +2868,14 @@
public void changeNotification ( )
{
- if (_selections != null)
+ if (_data._selections != null)
{
- _selections.size(); // Force a full selection
- _selections.cursify( getRoot() );
+ _data._selections.size(); // Force a full selection
+ _data._selections.cursify( getRoot() );
}
- if (_stack != null)
- _stack.cursify( getRoot() );
+ if (_data._stack != null)
+ _data._stack.cursify( getRoot() );
}
public void selectPath ( String path, XmlOptions options )
@@ -2902,23 +2884,23 @@
{
checkDisposed();
- if (_selections == null)
- _selections = Path.newSelections();
+ if (_data._selections == null)
+ _data._selections = Path.newSelections();
else
- _selections.dispose();
+ _data._selections.dispose();
- _selections.init(
+ _data._selections.init(
Path.select( getRoot(), getSplay(), getPos(), path, options ) );
push();
- if (_selections.setCursor( this, 0 ))
+ if (_data._selections.setCursor( this, 0 ))
{
getRoot().registerForChange( this );
- _currentSelection = -1;
+ _data._currentSelection = -1;
}
else
- _currentSelection = -2;
+ _data._currentSelection = -2;
pop();
}
@@ -3147,12 +3129,12 @@
private boolean validate ( )
{
- assert _goober.getRoot().validate();
+ assert _data._goober.getRoot().validate();
return true;
}
- public void dump ( ) { _goober.getRoot().dump(); }
- public void dump ( boolean verbose ) { _goober.getRoot().dump( verbose ); }
+ public void dump ( ) { _data._goober.getRoot().dump(); }
+ public void dump ( boolean verbose ) { _data._goober.getRoot().dump( verbose ); }
interface PathEngine
{
@@ -3320,10 +3302,5 @@
//
//
- final CursorGoober _goober;
-
- private Selections _stack;
-
- private Selections _selections;
- private int _currentSelection;
+ CursorData _data;
}
1.11 +1 -1 xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Root.java
Index: Root.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Root.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Root.java 27 Feb 2004 23:55:15 -0000 1.10
+++ Root.java 16 Mar 2004 00:04:36 -0000 1.11
@@ -2259,7 +2259,7 @@
if (src instanceof Cursor)
{
ps.println(
- " from cursor " + ((CursorGoober)((Cursor) src)._goober).getDebugId() );
+ " from cursor " + ((CursorGoober)((Cursor) src)._data._goober).getDebugId() );
}
else if (src instanceof Splay)
ps.println( " from splay " + ((Splay) src).getDebugId() );
1.1 xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/CursorData.java
Index: CursorData.java
===================================================================
/* 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.store;
import org.apache.xmlbeans.impl.store.Splay.CursorGoober;
import java.util.ArrayList;
public final class CursorData
{
public static CursorData getOne ( Root r )
{
ArrayList dataCache = (ArrayList) tl_CachedCursorData.get();
CursorData cd;
if (dataCache.size() == 0)
cd = new CursorData( r );
else
{
cd = (CursorData) dataCache.remove( dataCache.size() - 1 );
cd._goober.set( r );
}
return cd;
}
private CursorData ( Root r )
{
_goober = new CursorGoober( r );
}
private static ThreadLocal tl_CachedCursorData =
new ThreadLocal() { protected Object initialValue() { return new ArrayList(); } };
protected void release ( )
{
if (_goober.getSplay() != null)
{
clearSelections();
if (_stack != null)
_stack.dispose();
_goober.set( null, 0 );
ArrayList dataCache = (ArrayList) tl_CachedCursorData.get();
if (dataCache.size() < 128)
dataCache.add( this );
}
}
protected void finalize ( )
{
Splay s = _goober.getSplay();
if (s != null)
{
synchronized ( _goober.getRoot() )
{
release();
}
}
}
protected void clearSelections ( )
{
if (_selections != null)
_selections.dispose();
_currentSelection = -2;
}
public final CursorGoober _goober;
protected Cursor.Selections _stack;
protected Cursor.Selections _selections;
protected int _currentSelection;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org