db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r430522 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode: BCMethod.java CodeChunk.java
Date Thu, 10 Aug 2006 20:41:02 GMT
Author: djd
Date: Thu Aug 10 13:41:02 2006
New Revision: 430522

URL: http://svn.apache.org/viewvc?rev=430522&view=rev
Log:
DERBY-766 (partial) Clean up the existing split methods to avoid confusion over a code
length passed in. Now length of the method's code is determined inside the methods rather
than being passed around.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/CodeChunk.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java?rev=430522&r1=430521&r2=430522&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
Thu Aug 10 13:41:02 2006
@@ -281,7 +281,7 @@
                 optimalMinLength = lengthToCheck;
 
             split_pc = myCode.splitZeroStack(this, modClass, split_pc,
-                    lengthToCheck, optimalMinLength);
+                    optimalMinLength);
 
             // Negative split point returned means that no split
             // was possible. Give up on this approach and goto

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/CodeChunk.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/CodeChunk.java?rev=430522&r1=430521&r2=430522&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/CodeChunk.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/CodeChunk.java
Thu Aug 10 13:41:02 2006
@@ -834,7 +834,7 @@
 		byte[] codeBytes = cout.getData();
 		
 		int u2p = CODE_OFFSET + pc + 1;
-		
+        		
 		return ((codeBytes[u2p] & 0xff) << 8) | (codeBytes[u2p+1] & 0xff);
 	}
 
@@ -942,7 +942,7 @@
      */
     private int findMaxStack(ClassHolder ch, int pc, int codeLength) {
 
-        int endPc = pc + codeLength;
+        final int endPc = pc + codeLength;
         int stack = 0;
         int maxStack = 0;
 
@@ -958,7 +958,7 @@
                 maxStack = stack;
  
             int[] cond_pcs = findConditionalPCs(pc, opcode);
-            if (cond_pcs != null) {
+            if (cond_pcs != null) {                 
                 // an else block exists.
                 if (cond_pcs[3] != -1) {
                     int blockMaxStack = findMaxStack(ch, cond_pcs[1],
@@ -1281,11 +1281,10 @@
      * 
      * @param mb Method for this chunk.
      * @param ch Class definition
-     * @param codeLength codeLength to check
      * @param optimalMinLength minimum length required for split
      */
     final int splitZeroStack(BCMethod mb, ClassHolder ch, final int split_pc,
-            final int codeLength, final int optimalMinLength) {
+            final int optimalMinLength) {
         int stack = 0;
 
         // maximum possible split seen that is less than
@@ -1297,7 +1296,7 @@
         // a conditional.
         int outerConditionalEnd_pc = -1;
 
-        int end_pc = split_pc + codeLength;
+        int end_pc = getPC(); // pc will be positioned at the end.
         for (int pc = split_pc; pc < end_pc;) {
 
             short opcode = getOpcode(pc);
@@ -1392,8 +1391,8 @@
             BCMethod subMethod = startSubMethod(mb, "void", split_pc,
                     splitLength);
 
-            return splitCodeIntoSubMethod(mb, ch, subMethod, split_pc, splitLength,
-                    codeLength);
+            return splitCodeIntoSubMethod(mb, ch, subMethod,
+                    split_pc, splitLength);
         }
         return -1;
     }
@@ -1492,10 +1491,9 @@
      * @param subMethod Sub-method code was pushed into
      * @param split_pc Program counter the split started at
      * @param splitLength Length of code split
-     * @param codeLength Length of code before split
      */
     private int splitCodeIntoSubMethod(BCMethod mb, ClassHolder ch,
-            BCMethod subMethod, int split_pc, int splitLength, int codeLength) {
+            BCMethod subMethod, final int split_pc, final int splitLength) {
         CodeChunk subChunk = subMethod.myCode;
 
         byte[] codeBytes = cout.getData();
@@ -1515,8 +1513,7 @@
         subMethod.maxStack = subChunk.findMaxStack(ch, 0, subChunk.getPC());
         subMethod.complete();
 
-        return removePushedCode(mb, ch, subMethod, split_pc, splitLength,
-                codeLength);
+        return removePushedCode(mb, ch, subMethod, split_pc, splitLength);
     }
 
     /**
@@ -1535,20 +1532,22 @@
      *            Program counter the split started at
      * @param splitLength
      *            Length of code split
-     * @param codeLength
-     *            Length of code before split
      */
     private int removePushedCode(BCMethod mb, ClassHolder ch,
-            BCMethod subMethod, int split_pc, int splitLength, int codeLength) {
+            BCMethod subMethod, final int split_pc, final int splitLength) {
         // now need to fix up this method, create
         // a new CodeChunk just to be clearer than
         // trying to modify this chunk directly.
+        
+        // total length of the code for this method before split
+        final int codeLength = getPC();
+        
         CodeChunk replaceChunk = new CodeChunk(mb.cb);
         mb.myCode = replaceChunk;
         mb.maxStack = 0;
 
         byte[] codeBytes = cout.getData();
-
+        
         // write any existing code before the split point
         // into the replacement chunk.
         if (split_pc != 0) {
@@ -1566,10 +1565,12 @@
 
         // Write the code remaining in this method into the replacement chunk
 
-        int remainingCodeLength = codeLength - splitLength;
-        try {
-            replaceChunk.cout.write(codeBytes, CODE_OFFSET + split_pc
-                    + splitLength, remainingCodeLength);
+        int remainingCodePC = split_pc + splitLength;
+        int remainingCodeLength = codeLength - splitLength - split_pc;
+        
+       try {
+            replaceChunk.cout.write(codeBytes, CODE_OFFSET + remainingCodePC,
+                    remainingCodeLength);
         } catch (IOException ioe) {
             limitHit(ioe);
         }
@@ -1580,7 +1581,7 @@
         // into the constant pool in the code stream are valid.
         if (cb.limitMsg != null)
             return -1;
-                
+        
         mb.maxStack = replaceChunk.findMaxStack(ch, 0, replaceChunk.getPC());
 
         return postSplit_pc;



Mime
View raw message