You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2011/08/09 16:54:56 UTC
svn commit: r1155388 -
/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/SoftReferenceSymbolTable.java
Author: mrglavas
Date: Tue Aug 9 14:54:56 2011
New Revision: 1155388
URL: http://svn.apache.org/viewvc?rev=1155388&view=rev
Log:
JIRA Issue #1521: http://issues.apache.org/jira/browse/XERCESJ-1521. Compact the SoftReferenceSymbolTable if after cleaning out cleared SoftReferences the number of symbols drops below 25% of the table's load factor threshold.
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/SoftReferenceSymbolTable.java
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/SoftReferenceSymbolTable.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/SoftReferenceSymbolTable.java?rev=1155388&r1=1155387&r2=1155388&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/SoftReferenceSymbolTable.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/SoftReferenceSymbolTable.java Tue Aug 9 14:54:56 2011
@@ -203,12 +203,26 @@ public class SoftReferenceSymbolTable ex
* and load factor.
*/
protected void rehash() {
-
- int oldCapacity = fBuckets.length;
- SREntry[] oldTable = fBuckets;
-
- int newCapacity = oldCapacity * 2 + 1;
- SREntry[] newTable = new SREntry[newCapacity];
+ rehashCommon(fBuckets.length * 2 + 1);
+ }
+
+ /**
+ * Reduces the capacity of and internally reorganizes this
+ * SymbolTable, in order to accommodate and access its entries in
+ * a more memory efficient way. This method is called automatically when
+ * the number of keys in the SymbolTable drops below 25% of this
+ * hashtable's load factor (as a result of SoftReferences which have
+ * been cleared).
+ */
+ protected void compact() {
+ rehashCommon(((int) (fCount / fLoadFactor)) * 2 + 1);
+ }
+
+ private void rehashCommon(final int newCapacity) {
+
+ final int oldCapacity = fBuckets.length;
+ final SREntry[] oldTable = fBuckets;
+ final SREntry[] newTable = new SREntry[newCapacity];
fThreshold = (int)(newCapacity * fLoadFactor);
fBuckets = newTable;
@@ -321,9 +335,17 @@ public class SoftReferenceSymbolTable ex
*/
private void clean() {
SREntry entry = (SREntry)fReferenceQueue.poll();
- while (entry != null) {
- removeEntry(entry);
- entry = (SREntry)fReferenceQueue.poll();
+ if (entry != null) {
+ do {
+ removeEntry(entry);
+ entry = (SREntry)fReferenceQueue.poll();
+ }
+ while (entry != null);
+ // Reduce the number of buckets if the number of items
+ // in the table has dropped below 25% of the threshold.
+ if (fCount < (fThreshold >> 2)) {
+ compact();
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org