Author: karthick
Date: Tue Apr 14 21:37:26 2009
New Revision: 764966
URL: http://svn.apache.org/viewvc?rev=764966&view=rev
Log:
ODE-573 Use interning mechanism to reduce process size.
Added:
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/InternPool.java
Modified:
ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/o/DebugInfo.java
ode/branches/APACHE_ODE_1.X/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/NSContext.java
Modified:
ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/o/DebugInfo.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/o/DebugInfo.java?rev=764966&r1=764965&r2=764966&view=diff
==============================================================================
---
ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/o/DebugInfo.java
(original)
+++
ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/o/DebugInfo.java
Tue Apr 14 21:37:26 2009
@@ -18,11 +18,15 @@
*/
package org.apache.ode.bpel.o;
-import javax.xml.namespace.QName;
+import java.io.IOException;
+import java.io.ObjectInputStream;
import java.io.Serializable;
+import java.io.ObjectInputStream.GetField;
import java.util.HashMap;
import java.util.Map;
+import javax.xml.namespace.QName;
+
/**
* Information about the source that was used to create a compiled object.
*/
@@ -30,13 +34,13 @@
static final long serialVersionUID = -1L ;
/** Source file / resource name. */
- public final String sourceURI;
+ public String sourceURI;
/** Source line number (start). */
- public final int startLine;
+ public int startLine;
/** Source line number (end). */
- public final int endLine;
+ public int endLine;
public String description;
@@ -55,4 +59,19 @@
this(sourceURI, line, line, extElmt);
}
+ /**
+ * Do not load the description and extensibilityElements fields,
+ * as they may be big and are not really required at run-time.
+ *
+ * @param ois
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ private void readObject(ObjectInputStream ois) throws IOException,
ClassNotFoundException {
+ GetField getField = ois.readFields();
+ sourceURI = (String) getField.get("sourceURI", null);
+ startLine = (Integer) getField.get("startLine", 0);
+ endLine = (Integer) getField.get("endLine", 0);
+ }
+
}
Modified:
ode/branches/APACHE_ODE_1.X/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java?rev=764966&r1=764965&r2=764966&view=diff
==============================================================================
---
ode/branches/APACHE_ODE_1.X/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java
(original)
+++
ode/branches/APACHE_ODE_1.X/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java
Tue Apr 14 21:37:26 2009
@@ -18,6 +18,24 @@
*/
package org.apache.ode.store;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ode.bpel.compiler.BpelC;
@@ -31,29 +49,12 @@
import org.apache.ode.bpel.dd.TDeployment.Process;
import org.apache.ode.bpel.iapi.ContextException;
import org.apache.ode.bpel.o.Serializer;
+import org.apache.ode.utils.InternPool;
+import org.apache.ode.utils.InternPool.InternableBlock;
import org.apache.ode.utils.fs.FileUtils;
import org.apache.xmlbeans.XmlOptions;
import org.w3c.dom.Node;
-import javax.wsdl.Definition;
-import javax.wsdl.WSDLException;
-import javax.wsdl.xml.WSDLReader;
-import javax.xml.namespace.QName;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
/**
* Container providing various functions on the deployment directory.
*
@@ -158,8 +159,8 @@
return !_duDirectory.exists();
}
- private void compile(File bpelFile) {
- BpelC bpelc = BpelC.newBpelCompiler();
+ private void compile(final File bpelFile) {
+ final BpelC bpelc = BpelC.newBpelCompiler();
// BPEL 1.1 does not suport the <import> element, so "global" WSDL
needs to be configured explicitly.
File bpel11wsdl = findBpel11Wsdl(bpelFile);
@@ -168,11 +169,16 @@
bpelc.setCompileProperties(prepareCompileProperties(bpelFile));
bpelc.setBaseDirectory(_duDirectory);
- try {
- bpelc.compile(bpelFile);
- } catch (IOException e) {
- __log.error("Compile error in " + bpelFile, e);
- }
+ // Create process such that immutable objects are intern'ed.
+ InternPool.runBlock(new InternableBlock() {
+ public void run() {
+ try {
+ bpelc.compile(bpelFile);
+ } catch (IOException e) {
+ __log.error("Compile error in " + bpelFile, e);
+ }
+ }
+ });
}
/**
Modified:
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java?rev=764966&r1=764965&r2=764966&view=diff
==============================================================================
---
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java
(original)
+++
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java
Tue Apr 14 21:37:26 2009
@@ -24,13 +24,13 @@
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -63,14 +63,12 @@
import org.w3c.dom.CharacterData;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
-import org.w3c.dom.TypeInfo;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -1070,7 +1068,7 @@
if (nl instanceof List) return (List<Node>) nl;
NodeList cnl = (NodeList) nl;
- LinkedList<Node> ll = new LinkedList<Node>();
+ List<Node> ll = new ArrayList<Node>();
for (int m = 0; m < cnl.getLength(); m++) ll.add(cnl.item(m));
return ll;
}
Added:
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/InternPool.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/InternPool.java?rev=764966&view=auto
==============================================================================
---
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/InternPool.java
(added)
+++
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/InternPool.java
Tue Apr 14 21:37:26 2009
@@ -0,0 +1,104 @@
+package org.apache.ode.utils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.collections.map.LRUMap;
+import org.apache.commons.collections.map.MultiKeyMap;
+
+
+/**
+ * A key value based cache that internalizes immutable values
+ * so that they can be shared across various BPEL objects.
+ *
+ */
+public class InternPool {
+ private static MultiKeyMap cachedValues = MultiKeyMap.decorate(new
LRUMap());
+ private static Set<String> cachedBlocks = Collections.synchronizedSet(new
HashSet<String>());
+
+ /**
+ * Creates a new KeyValueCache object.
+ */
+ protected InternPool() {
+ }
+
+ /**
+ * Runs the given block in the context of a cache.
+ * If you do not run your block this way, the caching
+ * mechanism will be disabled.
+ *
+ * @param block block
+ */
+ public static void runBlock(InternableBlock block) {
+ String processId = getProcessId();
+ cachedBlocks.add(processId);
+ block.run();
+ cachedBlocks.remove(processId);
+ clearAll(processId);
+ }
+
+ /**
+ * Returns an internalized value if it already exists in the cache
+ *
+ * @param value value
+ *
+ * @return the internalized value
+ */
+ public static Object intern(Object key, Object value) {
+ String processId = getProcessId();
+
+ if (!cachedBlocks.contains(processId)) {
+ return value;
+ }
+
+ synchronized (cachedValues) {
+ List values = (List) cachedValues.get(processId, key);
+ if (values == null) {
+ cachedValues.put(processId, key, (values = new ArrayList()));
+ }
+
+ Object intern;
+ if (values.contains(value)) {
+ intern = values.get(values.indexOf(value));
+ } else {
+ values.add(intern = value);
+ }
+
+ return intern;
+ }
+ }
+
+ /**
+ * Clears all the values corresponding to the given process
+ *
+ * @param processId processId
+ */
+ protected static void clearAll(String processId) {
+ synchronized (cachedValues) {
+ cachedValues.remove(processId);
+ }
+ }
+
+ /**
+ * Returns the current thread id as the process id.
+ *
+ * @return the "process id"
+ */
+ private static String getProcessId() {
+ return String.valueOf(Thread.currentThread().getId());
+ }
+
+ /**
+ * An interface that clients should implement to run their
+ * blocks of code in the context of this caching mechanism.
+ */
+ public interface InternableBlock {
+ /**
+ * The block to run
+ */
+ public void run();
+ }
+}
Modified:
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/NSContext.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/NSContext.java?rev=764966&r1=764965&r2=764966&view=diff
==============================================================================
---
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/NSContext.java
(original)
+++
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/NSContext.java
Tue Apr 14 21:37:26 2009
@@ -23,15 +23,24 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
-import org.apache.ode.utils.stl.*;
+import org.apache.ode.utils.stl.CollectionsX;
+import org.apache.ode.utils.stl.CompositeUnaryFunction;
+import org.apache.ode.utils.stl.EqualsUnaryFunction;
+import org.apache.ode.utils.stl.FilterIterator;
+import org.apache.ode.utils.stl.TransformIterator;
/**
* A simple in-memory implementation of the {...@link NamespaceContext}
interface
@@ -48,8 +57,15 @@
private static final Log __log = LogFactory.getLog(NSContext.class);
/** Prefix-to-URI map. */
- private HashMap<String, String> _prefixToUriMap = new HashMap<String,
String>();
-
+ private HashMap<String, String> _prefixToUriMap = new HashMap<String,
String>() {
+ @Override
+ public String put(String prefix, String uri) {
+ prefix = (String) InternPool.intern("namespace.prefixes", prefix);
+ uri = (String) InternPool.intern("namespace.uris", uri);
+ return super.put(prefix, uri);
+ }
+ };
+
public NSContext() {
}
@@ -123,7 +139,7 @@
__log.trace("readExternal: contents=" + _prefixToUriMap);
}
}
-
+
/**
* Add a prefix to URI mapping to this context.
*