You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-dev@jakarta.apache.org by tc...@apache.org on 2007/04/06 19:41:13 UTC

svn commit: r526235 - in /jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals: Pass3bVerifier.java Subroutines.java

Author: tcurdt
Date: Fri Apr  6 10:41:12 2007
New Revision: 526235

URL: http://svn.apache.org/viewvc?view=rev&rev=526235
Log:
http://issues.apache.org/bugzilla/show_bug.cgi?id=40577


Modified:
    jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java
    jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java

Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java
URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java?view=diff&rev=526235&r1=526234&r2=526235
==============================================================================
--- jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java (original)
+++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java Fri Apr  6 10:41:12 2007
@@ -23,13 +23,17 @@
 import java.util.List;
 import java.util.Random;
 import java.util.Vector;
+
 import org.apache.bcel.Constants;
 import org.apache.bcel.Repository;
 import org.apache.bcel.classfile.JavaClass;
 import org.apache.bcel.classfile.Method;
 import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GETFIELD;
 import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InvokeInstruction;
 import org.apache.bcel.generic.JsrInstruction;
+import org.apache.bcel.generic.LoadInstruction;
 import org.apache.bcel.generic.MethodGen;
 import org.apache.bcel.generic.ObjectType;
 import org.apache.bcel.generic.RET;
@@ -40,6 +44,7 @@
 import org.apache.bcel.verifier.VerificationResult;
 import org.apache.bcel.verifier.Verifier;
 import org.apache.bcel.verifier.exc.AssertionViolatedException;
+import org.apache.bcel.verifier.exc.StructuralCodeConstraintException;
 import org.apache.bcel.verifier.exc.VerifierConstraintViolatedException;
 
 /**
@@ -126,7 +131,7 @@
    * The proof of termination is about the existence of a
    * fix point of frame merging.
 	 */
-	private void circulationPump(ControlFlowGraph cfg, InstructionContext start, Frame vanillaFrame, InstConstraintVisitor icv, ExecutionVisitor ev){
+	private void circulationPump(MethodGen m,ControlFlowGraph cfg, InstructionContext start, Frame vanillaFrame, InstConstraintVisitor icv, ExecutionVisitor ev){
 		final Random random = new Random();
 		InstructionContextQueue icq = new InstructionContextQueue();
 		
@@ -246,6 +251,44 @@
 						this.addMessage("Warning: ReturnInstruction '"+ic+"' may leave method with an uninitialized object on the operand stack '"+os+"'.");
 					}
 				}
+                //see JVM $4.8.2
+                //TODO implement all based on stack 
+                Type returnedType = null;
+                if( ih.getPrev().getInstruction() instanceof InvokeInstruction )
+                {
+                    returnedType = ((InvokeInstruction)ih.getPrev().getInstruction()).getType(m.getConstantPool());
+                }
+                if( ih.getPrev().getInstruction() instanceof LoadInstruction )
+                {
+                    int index = ((LoadInstruction)ih.getPrev().getInstruction()).getIndex();
+                    returnedType = lvs.get(index);
+                }
+                if( ih.getPrev().getInstruction() instanceof GETFIELD )
+                {
+                    returnedType = ((GETFIELD)ih.getPrev().getInstruction()).getType(m.getConstantPool());
+                }
+                if( returnedType != null )
+                {
+                    if( returnedType instanceof ObjectType )
+                    {
+                        try
+                        {
+                            if( !((ObjectType)returnedType).isAssignmentCompatibleWith(m.getReturnType()) )
+                            {
+                                throw new StructuralCodeConstraintException("Returned type "+returnedType+" does not match Method's return type "+m.getReturnType());
+                            }
+                        }
+                        catch (ClassNotFoundException e)
+                        {
+                            //dont know what do do now, so raise RuntimeException
+                            throw new RuntimeException(e);
+                        }
+                    }
+                    else if( !returnedType.equals(m.getReturnType()) )
+                    {
+                        throw new StructuralCodeConstraintException("Returned type "+returnedType+" does not match Method's return type "+m.getReturnType());
+                    }
+                }
 			}
 		}while ((ih = ih.getNext()) != null);
 		
@@ -321,7 +364,7 @@
 						f.getLocals().set(twoslotoffset + j + (mg.isStatic()?0:1), Type.UNKNOWN);
 					}
 				}
-				circulationPump(cfg, cfg.contextOf(mg.getInstructionList().getStart()), f, icv, ev);
+				circulationPump(mg,cfg, cfg.contextOf(mg.getInstructionList().getStart()), f, icv, ev);
 			}
 		}
 		catch (VerifierConstraintViolatedException ce){

Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java?view=diff&rev=526235&r1=526234&r2=526235
==============================================================================
--- jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java (original)
+++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java Fri Apr  6 10:41:12 2007
@@ -565,7 +565,7 @@
                 return s;
             }
 		}
-System.err.println("DEBUG: Please verify '"+any+"' lies in dead code.");
+System.err.println("DEBUG: Please verify '"+any.toString(true)+"' lies in dead code.");
 		return null;
 		//throw new AssertionViolatedException("No subroutine for InstructionHandle found (DEAD CODE?).");
 	}



---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-dev-help@jakarta.apache.org