db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r160932 - incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile
Date Mon, 11 Apr 2005 18:36:23 GMT
Author: djd
Date: Mon Apr 11 11:36:20 2005
New Revision: 160932

URL: http://svn.apache.org/viewcvs?view=rev&rev=160932
Log:
Derby-176 (partial)
Reduce the number of code instructions generated for a putField() followed by an endStatement()
by providing a setField() method that sets a field with the top value of the stack but does
not
leave the field's contents on the stack. The use of putField() mimicing the Java language
field=value;
lead to many cases where the value on the stack was not required and immediately popped using
endStatement().
This lead to two extra instructions per field assignment (dup and pop), providing a setField()
removes the
need for the endStatement() as it never performs the dup.


Modified:
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/MethodBuilder.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ExpressionClassBuilder.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SQLToJavaValueNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/MethodBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/MethodBuilder.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/MethodBuilder.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/services/compiler/MethodBuilder.java
Mon Apr 11 11:36:20 2005
@@ -182,6 +182,18 @@
 	public void getStaticField(String declaringClass, String fieldName, String fieldType);
 
 	/**
+	Pop the top stack value and store it in the local field. 
+	This call pushes the this instance required to access the field itself.
+	This call does not leave any value on the stack.
+
+	<PRE>
+	Stack ...,value  =>
+	      ...
+	</PRE>
+	*/
+	public void setField(LocalField field);
+
+	/**
 		Pop the top stack value and store it in the local field. 
 		This call pushes the this instance required to access the field itself.
 		Like the Java language 'field = value', this leaves the value on the stack.

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
Mon Apr 11 11:36:20 2005
@@ -202,7 +202,7 @@
 	public void complete() {
 		// write exceptions attribute info
 		writeExceptions();
-
+		
 		// get the code attribute to put itself into the class
 		// provide the final header information needed
 		myCode.complete(modClass, myEntry, maxStack, currentVarNum);
@@ -729,6 +729,20 @@
 
 		growStack(ft);
 	}
+	
+	/**
+	 * Set the field but don't duplicate its value so
+	 * nothing is left on the stack after this call.
+	 */
+	public void setField(LocalField field) {
+		BCLocalField lf = (BCLocalField) field;
+		Type lt = lf.type;
+
+		putField(lf.type, lf.cpi, false);
+
+		if (stackDepth == 0)
+			overflowMethodCheck();
+	}
 
 	/**
 		Upon entry the top word(s) on the stack is
@@ -753,7 +767,7 @@
 		BCLocalField lf = (BCLocalField) field;
 		Type lt = lf.type;
 
-		putField(lf.type, lf.cpi);
+		putField(lf.type, lf.cpi, true);
 	}
 
 	/**
@@ -764,50 +778,38 @@
 		Type ft = cb.factory.type(fieldType);
 		int cpi = modClass.addFieldReference(cb.classType.vmNameSimple, fieldName, ft.vmName());
 
-		putField(ft, cpi);
+		putField(ft, cpi, true);
 	}
 
-	private void putField(Type fieldType, int cpi) {
+	private void putField(Type fieldType, int cpi, boolean dup) {
 
 		// now have ...,value
-		myCode.addInstr(fieldType.width() == 2  ? VMOpcode.DUP2 : VMOpcode.DUP);
-		growStack(fieldType);
+		if (dup)
+		{
+			myCode.addInstr(fieldType.width() == 2  ? VMOpcode.DUP2 : VMOpcode.DUP);
+			growStack(fieldType);
+		}
+		// now have
+		// dup true:  ...,value,value
+		// dup false: ...,value,
 
-		// now have ...,value,value
 		pushThis();
-		// now have ...,value,value,this
-		swap();
-		/*
-		if (fieldType.width() == 1) {
-			myCode.addInstr(VMOpcode.SWAP);
-			Type t1 = popStack();
-			Type t2 = popStack();
-			growStack(t1);
-			growStack(t2);
-
-			// now have ...,word,this,word
-
-		} else {
+		// now have
+		// dup true:  ...,value,value,this
+		// dup false: ...,value,this
 
-			// now have wA,wB,wA,wB,this
-			myCode.addInstr(VMOpcode.DUP_X2);
-
-			Type t1 = popStack();
-			Type t2 = popStack();
-			growStack(t1);
-			growStack(t2);
-			growStack(t1);
-
-			// now have wA,wB,this,wA,wB,this
-			myCode.addInstr(VMOpcode.POP);
-			popStack();
+		swap();
+		// now have
+		// dup true:  ...,value,this,value
+		// dup false: ...,this,value
 
-			// now have wA,wB,this,wA,wB
-		}
-*/
 		myCode.addInstrU2(VMOpcode.PUTFIELD, cpi);
 		popStack(); // the value
 		popStack(); // this
+
+		// now have
+		// dup true:  ...,value
+		// dup false: ...
 	}
 	/**
 		Pop the top stack value and store it in the field.

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
Mon Apr 11 11:36:20 2005
@@ -913,9 +913,7 @@
 		*/
 
 		acb.generateNull(acbConstructor, getTypeCompiler(destCTI));
-		acbConstructor.putField(field);
-		acbConstructor.endStatement();
-
+		acbConstructor.setField(field);
 
 
 		/*

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
Mon Apr 11 11:36:20 2005
@@ -205,8 +205,7 @@
 		/* Assign the initializer to the DataValueDescriptor[] field */
 		MethodBuilder cb = acb.getConstructor();
 		cb.pushNewArray(ClassName.DataValueDescriptor, argumentsListSize);
-		cb.putField(arrayField);
-		cb.endStatement();
+		cb.setField(arrayField);
 
 		/* Set the array elements that are constant */
 		int numConstants = 0;

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
Mon Apr 11 11:36:20 2005
@@ -578,8 +578,7 @@
 			LocalField arrayField =
 				acb.newFieldDeclaration(Modifier.PRIVATE, resultSetArrayType);
 			mb.pushNewArray(ClassName.ResultSet, dependentNodes.length);  // new ResultSet[size]
-			mb.putField(arrayField);
-			mb.endStatement();
+			mb.setField(arrayField);
 
 			argCount = 4;
 			for(int index=0 ; index <  dependentNodes.length ; index++)

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ExpressionClassBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ExpressionClassBuilder.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ExpressionClassBuilder.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ExpressionClassBuilder.java
Mon Apr 11 11:36:20 2005
@@ -845,8 +845,7 @@
 
 		constructor.pushNewStart(ClassName.CurrentDatetime);
 		constructor.pushNewComplete(0);
-		constructor.putField(cdtField);
-		constructor.endStatement();
+		constructor.setField(cdtField);
 
 		return cdtField;
 	}

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java
Mon Apr 11 11:36:20 2005
@@ -410,8 +410,7 @@
 		/* Assign the initializer to the DataValueDescriptor[] field */
 		MethodBuilder cb = acb.getConstructor();
 		cb.pushNewArray(ClassName.DataValueDescriptor, listSize);
-		cb.putField(arrayField);
-		cb.endStatement();
+		cb.setField(arrayField);
 
 		/* Set the array elements that are constant */
 		int numConstants = 0;

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java
Mon Apr 11 11:36:20 2005
@@ -2756,8 +2756,7 @@
 			/* Assign the initializer to the Qualifier[] field */
 			consMB.pushNewArray(
                 ClassName.Qualifier + "[]", (int) num_of_or_conjunctions + 1);
-			consMB.putField(qualField);
-			consMB.endStatement();
+			consMB.setField(qualField);
 
             // Allocate qualifiers[0] which is an entry for each of the leading
             // AND clauses.
@@ -3150,8 +3149,7 @@
 		LocalField field =
 			acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.ExecIndexRow);
 		
-		mb.putField(field);
-		mb.endStatement();
+		mb.setField(field);
 
 		return field;
 	}

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
Mon Apr 11 11:36:20 2005
@@ -1395,8 +1395,7 @@
 		cb.push(numCols);
 		cb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null,
 							rowAllocatorMethod, rowAllocatorType, 1);
-		cb.putField(field);
-		cb.endStatement();
+		cb.setField(field);
 		/* Increase the statement counter in constructor.  Code size in
 		 * constructor can become too big (more than 64K) for Java compiler
 		 * to handle (beetle 4293).  We set constant columns in other

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SQLToJavaValueNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SQLToJavaValueNode.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SQLToJavaValueNode.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SQLToJavaValueNode.java
Mon Apr 11 11:36:20 2005
@@ -451,8 +451,7 @@
 		  mb.getField(returnsNullOnNullState);
 		mb.completeConditional();
 		
-		mb.putField(returnsNullOnNullState);
-		mb.endStatement();
+		mb.setField(returnsNullOnNullState);
 	}
 
 

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
Mon Apr 11 11:36:20 2005
@@ -698,8 +698,7 @@
 		// reset the parameters are null indicator.
 		if (returnsNullOnNullState != null) {
 			mb.push(false);
-			mb.putField(returnsNullOnNullState);
-			mb.endStatement();
+			mb.setField(returnsNullOnNullState);
 
 			// for the call to the generated method below.
 			mb.pushThis();
@@ -772,8 +771,7 @@
 				functionEntrySQLAllowed = acb.newFieldDeclaration(Modifier.PRIVATE, "short");
 				mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
 									"getSQLAllowed", "short", 0);
-				mb.putField(functionEntrySQLAllowed);
-				mb.endStatement();
+				mb.setField(functionEntrySQLAllowed);
 
 			}
 			
@@ -819,8 +817,7 @@
 
 					// create the holder of all the ResultSet arrays, new java.sql.ResultSet[][compiledResultSets]
 					cons.pushNewArray("java.sql.ResultSet[]", compiledResultSets);
-					cons.putField(procedureResultSetsHolder);
-					cons.endStatement();
+					cons.setField(procedureResultSetsHolder);
 
 
 					// arguments for the dynamic result sets

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java?view=diff&r1=160931&r2=160932
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java
Mon Apr 11 11:36:20 2005
@@ -1843,18 +1843,15 @@
 				mb.getField(subRS);
 				mb.completeConditional();
 		
-				mb.putField(subRS);
-				mb.endStatement();
+				mb.setField(subRS);
 
                 executeMB.pushNull( ClassName.NoPutResultSet);
-                executeMB.putField(subRS);
-                executeMB.endStatement();
+                executeMB.setField(subRS);
 			}
 
             executeMB.pushNull( ClassName.NoPutResultSet);
-            executeMB.putField(rsFieldLF);
-            executeMB.endStatement();
-
+            executeMB.setField(rsFieldLF);
+ 
 			// now we fill in the body of the conditional
 			mb.getField(rsFieldLF);
 			mb.conditionalIfNull();
@@ -1990,8 +1987,7 @@
 			mb.completeConditional();
 		}
 		
-		mb.putField(rsFieldLF);
-		mb.endStatement();
+		mb.setField(rsFieldLF);
 
 		/* rs.openCore() */
 		mb.getField(rsFieldLF);
@@ -2089,8 +2085,7 @@
 		mb.callMethod(VMOpcode.INVOKEVIRTUAL, (String) null, mbsq.getName(), type, 0);
 
 		// generate: field = value (value is on stack)
-		mb.putField(field);
-		mb.endStatement();
+		mb.setField(field);
 
 		return field;
 	}



Mime
View raw message