You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2006/09/01 13:57:54 UTC

svn commit: r439279 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/services/loader/GeneratedByteCode.java iapi/sql/conn/LanguageConnectionContext.java impl/sql/conn/GenericLanguageConnectionContext.java impl/sql/execute/BaseActivation.java

Author: kahatlen
Date: Fri Sep  1 04:57:54 2006
New Revision: 439279

URL: http://svn.apache.org/viewvc?rev=439279&view=rev
Log:
DERBY-418: outofmemory error when running large query in autocommit=false mode
DERBY-1142: Metadata calls leak memory

Notify GenericLanguageConnectionContext when activations are marked as
unused, and clean up unused activations when a new one is added.

Patch contributed by Mayuresh Nirhali.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/GeneratedByteCode.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/GeneratedByteCode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/GeneratedByteCode.java?rev=439279&r1=439278&r2=439279&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/GeneratedByteCode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/loader/GeneratedByteCode.java Fri Sep  1 04:57:54 2006
@@ -35,7 +35,8 @@
 		Called by the class manager just after
 		creating the instance of the new class.
 	*/
-	public void initFromContext(Context context);
+	public void initFromContext(Context context)
+		throws StandardException;
 
 	/**
 		Set the Generated Class. Call by the class manager just after

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java?rev=439279&r1=439278&r2=439279&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java Fri Sep  1 04:57:54 2006
@@ -143,7 +143,13 @@
 	 * Add the activation to those known about by this connection.
 	 *
 	 */
-	void addActivation(Activation a);
+	void addActivation(Activation a)
+		throws StandardException;
+
+	/**
+	 * Make a note that some activations are marked unused
+	 */
+	void notifyUnusedActivation();
 
 	/**
 	 * Remove the activation from those known about by this connection.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java?rev=439279&r1=439278&r2=439279&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java Fri Sep  1 04:57:54 2006
@@ -116,6 +116,7 @@
 	 */
 
 	private final Vector acts;
+	private volatile boolean unusedActs=false;
 	protected int bindCount;
 	private boolean ddWriteMode;
 	private boolean runTimeStatisticsSetting ;
@@ -429,9 +430,32 @@
 	/**
 	 * Add the activation to those known about by this connection.
 	 */
-	public void addActivation(Activation a) {
+	public void addActivation(Activation a) 
+		throws StandardException {
 		acts.addElement(a);
 
+		// DERBY-418. Activations which are marked unused,
+		// are closed here. Activations Vector is iterated 
+		// to identify and close unused activations, only if 
+		// unusedActs flag is set to true and if the total 
+		// size exceeds 20.
+		if( (unusedActs) && (acts.size() > 20) ) {
+			unusedActs = false;
+			for (int i = acts.size() - 1; i >= 0; i--) {
+
+				// it maybe the case that a Activation's reset() ends up
+				// closing one or more activation leaving our index beyond
+				// the end of the array
+				if (i >= acts.size())
+					continue;
+
+				Activation a1 = (Activation) acts.elementAt(i);
+				if (!a1.isInUse()) {
+					a1.close();
+				}
+			}
+		}
+
 		if (SanityManager.DEBUG) {
 
 			if (SanityManager.DEBUG_ON("memoryLeakTrace")) {
@@ -440,6 +464,13 @@
 					System.out.println("memoryLeakTrace:GenericLanguageContext:activations " + acts.size());
 			}
 		}
+	}
+
+	/**
+	 * Make a note that some activations are marked unused
+	 */
+	public void notifyUnusedActivation() {
+	    unusedActs = true;
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java?rev=439279&r1=439278&r2=439279&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java Fri Sep  1 04:57:54 2006
@@ -125,7 +125,10 @@
 	protected int numSubqueries;
 
 	private boolean singleExecution;
-	private boolean inUse;
+
+	// This flag is declared volatile to ensure it is 
+	// visible when it has been modified by the finalizer thread.
+	private volatile boolean inUse;
 
 	private java.sql.ResultSet targetVTI;
 	private SQLWarning warnings;
@@ -192,7 +195,8 @@
 		super();
 	}
 
-	public final void initFromContext(Context context) {
+	public final void initFromContext(Context context) 
+		throws StandardException {
 
 		if (SanityManager.DEBUG)
 		{
@@ -786,7 +790,10 @@
 	 */
 	public final void markUnused()
 	{
-		inUse = false;
+		if(isInUse()) {
+			inUse = false;
+			lcc.notifyUnusedActivation();
+		}
 	}
 
 	/**