Author: adelmelle
Date: Mon Dec 8 10:54:16 2008
New Revision: 724444
URL: http://svn.apache.org/viewvc?rev=724444&view=rev
Log:
Bugzilla 46319:
Fixed a memory-leak in Marker.MarkerAttribute, where an instance was used as
both key and value
in a WeakHashMap, effectively neutralizing the benefit of using WeakReferences.
Solved by extending PropertyCache to work for MarkerAttributes as well.
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Marker.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyCache.java
xmlgraphics/fop/trunk/status.xml
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Marker.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Marker.java?rev=724444&r1=724443&r2=724444&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Marker.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Marker.java Mon Dec
8 10:54:16 2008
@@ -34,6 +34,7 @@
import org.apache.fop.fo.PropertyListMaker;
import org.apache.fop.fo.ValidationException;
import org.apache.fop.fo.properties.Property;
+import org.apache.fop.fo.properties.PropertyCache;
/**
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_marker">
@@ -334,10 +335,10 @@
}
/** Convenience inner class */
- private static final class MarkerAttribute {
+ public static final class MarkerAttribute {
- private static Map attributeCache =
- Collections.synchronizedMap(new java.util.WeakHashMap());
+ private static PropertyCache attributeCache =
+ new PropertyCache(MarkerAttribute.class);
protected String namespace;
protected String qname;
@@ -373,18 +374,26 @@
private static MarkerAttribute getInstance(
String namespace, String qname,
String name, String value) {
- MarkerAttribute newInstance =
- new MarkerAttribute(namespace, qname, name, value);
- if (attributeCache.containsKey(newInstance)) {
- return (MarkerAttribute) attributeCache.get(newInstance);
- } else {
- attributeCache.put(newInstance, newInstance);
- return newInstance;
- }
+ return attributeCache.fetch(
+ new MarkerAttribute(namespace, qname, name, value));
+ }
+
+ /** [EMAIL PROTECTED] */
+ public int hashCode() {
+ int hash = 17;
+ hash = (37 * hash) + (this.namespace == null ? 0 :
this.namespace.hashCode());
+ hash = (37 * hash) + (this.qname == null ? 0 :
this.qname.hashCode());
+ hash = (37 * hash) + (this.name == null ? 0 :
this.name.hashCode());
+ hash = (37 * hash) + (this.value == null ? 0 :
this.value.hashCode());
+ return hash;
}
/** [EMAIL PROTECTED] */
public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
if (o instanceof MarkerAttribute) {
MarkerAttribute attr = (MarkerAttribute) o;
return ((attr.namespace == this.namespace)
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyCache.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyCache.java?rev=724444&r1=724443&r2=724444&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyCache.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyCache.java
Mon Dec 8 10:54:16 2008
@@ -19,6 +19,8 @@
package org.apache.fop.fo.properties;
+import org.apache.fop.fo.flow.Marker;
+
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
@@ -53,7 +55,7 @@
private Class runtimeType;
- private boolean[] votesForRehash = new boolean[SEGMENT_COUNT];
+ private final boolean[] votesForRehash = new boolean[SEGMENT_COUNT];
/* same hash function as used by java.util.HashMap */
private static int hash(Object x) {
@@ -381,6 +383,19 @@
return (CommonBorderPaddingBackground.BorderInfo) fetch((Object) bi);
}
+ /**
+ * Checks if the given [EMAIL PROTECTED] Marker.MarkerAttribute} is
present
+ * in the cache - if so, returns a reference to the cached instance.
+ * Otherwise the given object is added to the cache and returned.
+ *
+ * @param ma the MarkerAttribute instance to check for
+ * @return the cached instance
+ */
+ public Marker.MarkerAttribute fetch(
+ Marker.MarkerAttribute ma) {
+ return (Marker.MarkerAttribute) fetch((Object) ma);
+ }
+
/** [EMAIL PROTECTED] */
public String toString() {
return super.toString() + "[runtimeType=" + this.runtimeType + "]";
Modified: xmlgraphics/fop/trunk/status.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=724444&r1=724443&r2=724444&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Mon Dec 8 10:54:16 2008
@@ -53,6 +53,11 @@
<changes>
<release version="FOP Trunk" date="TBD">
+ <action context="Code" dev="AD" type="fix" fixes-bug="46319">
+ Fixed a memory-leak in Marker.MarkerAttribute, where an instance was
used both as key and value in
+ a WeakHashMap, effectively neutralizing the benefit of using
WeakReferences. Solved by extending
+ PropertyCache to work for MarkerAttributes as well.
+ </action>
<action context="Renderers" dev="JM" type="fix" fixed-bug="46360">
Fixed a multi-threading issue when rendering SVG.
</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]