harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r546915 [1/5] - in /harmony/enhanced/drlvm/trunk: src/test/regression/H3225/ vm/vmcore/include/ vm/vmcore/src/class_support/ vm/vmcore/src/verifier/
Date Wed, 13 Jun 2007 15:17:11 GMT
Author: gshimansky
Date: Wed Jun 13 08:17:09 2007
New Revision: 546915

URL: http://svn.apache.org/viewvc?view=rev&rev=546915
Log:
Applied patches for tests and verifier from HARMONY-3910
[drlvm][verifier] VerifyError is reported for class in mpowerplayer application


Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H3225/J9CompatibleJsrTest.j   (with props)
Modified:
    harmony/enhanced/drlvm/trunk/src/test/regression/H3225/NegativeJsrTest.java
    harmony/enhanced/drlvm/trunk/src/test/regression/H3225/PositiveJsrTest.j
    harmony/enhanced/drlvm/trunk/src/test/regression/H3225/run.test.xml
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/verifier.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Verifier_stub.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/Graph.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/Verifier.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/ver_dataflow.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/ver_graph.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/ver_real.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/ver_subroutine.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/ver_subroutine.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/ver_utils.cpp

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3225/J9CompatibleJsrTest.j
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3225/J9CompatibleJsrTest.j?view=auto&rev=546915
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3225/J9CompatibleJsrTest.j (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3225/J9CompatibleJsrTest.j Wed Jun 13 08:17:09 2007
@@ -0,0 +1,137 @@
+.class public org/apache/harmony/drlvm/tests/regression/h3225/J9CompatibleJsrTest
+.super junit/framework/TestCase
+.method public <init>()V
+    aload_0
+    invokespecial junit/framework/TestCase/<init>()V
+    return
+.end method
+
+;
+; Launches testcases which check subroutine verification.
+;
+.method public static main([Ljava/lang/String;)V
+    .limit stack 1
+    .limit locals 1
+
+    ldc "org.apache.harmony.drlvm.tests.regression.h3225.J9CompatibleJsrTest"
+    invokestatic java/lang/Class/forName(Ljava/lang/String;)Ljava/lang.Class;
+    invokestatic junit/textui/TestRunner/run(Ljava/lang/Class;)V
+
+    return
+.end method
+
+;
+; A subroutine is called from two different subroutines. RI produce
+; a shameful error message in this case.
+;
+.method public testNestedSubs()V
+    .limit stack 3
+    .limit locals 2
+
+    jsr LabelSub1
+    jsr LabelSub2
+    return
+
+LabelSub1:
+    astore 1
+    jsr LabelSub
+    ret 1
+
+LabelSub2:
+    astore 1
+    jsr LabelSub
+    ret 1
+
+LabelSub:
+    astore 0
+    ret 0
+
+.end method
+
+;
+; A subroutine splits execution and calls another subroutine from
+; different branches.
+;
+.method public testSubSplit()V
+    .limit stack 1
+    .limit locals 2
+
+    jsr LabelSub
+    return
+
+LabelSub:
+    astore 1
+    aconst_null
+    ifnull Label1
+    jsr LabelSub1
+Label1:
+    jsr LabelSub1
+Label2:
+    jsr LabelSub2
+    aconst_null
+    ifnonnull Label2
+    jsr LabelSub2
+    goto Label4
+Label3:
+    jsr LabelSub3
+    ret 1
+Label4:
+    aconst_null
+    ifnull Label3
+    jsr LabelSub3
+    aconst_null
+    ifnull Label3
+    return
+
+LabelSub1:
+    astore 0
+    ret 0
+
+LabelSub2:
+    astore 0
+    ret 0
+
+LabelSub3:
+    astore 0
+    ret 0
+
+.end method
+
+;
+; A nested subroutine is preceded with two calls to another subroutine.
+;
+.method public testNestedPreceded()V
+    .limit stack 4
+    .limit locals 1
+
+    iconst_0
+    jsr LabelSub
+    return
+
+LabelSub:
+    swap
+    jsr LabelSub1
+    jsr LabelSub1
+    jsr LabelSub2
+    swap
+    astore 0
+    ret 0
+
+LabelSub1:
+    swap
+    iconst_1
+    iadd
+    swap
+    astore 0
+    ret 0
+
+LabelSub2:
+    swap
+    iconst_1
+    iadd
+    swap
+    astore 0
+    ret 0
+
+.end method
+

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H3225/J9CompatibleJsrTest.j
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/H3225/NegativeJsrTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3225/NegativeJsrTest.java?view=diff&rev=546915&r1=546914&r2=546915
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3225/NegativeJsrTest.java (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3225/NegativeJsrTest.java Wed Jun 13 08:17:09 2007
@@ -6,11 +6,7 @@
  */
 public class NegativeJsrTest extends junit.framework.TestCase {
     public static void main(String args[]) {
-        NegativeJsrTest t = new NegativeJsrTest();
-        t.testMergeExecution();
-        t.testMergeEmptyStack();
-        t.testMergeIntFloat();
-        t.testMergeStack();
+        junit.textui.TestRunner.run(org.apache.harmony.drlvm.tests.regression.h3225.NegativeJsrTest.class);
     }
 
     public void testMergeExecution() {

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/H3225/PositiveJsrTest.j
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3225/PositiveJsrTest.j?view=diff&rev=546915&r1=546914&r2=546915
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3225/PositiveJsrTest.j (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3225/PositiveJsrTest.j Wed Jun 13 08:17:09 2007
@@ -10,34 +10,12 @@
 ; Launches testcases which check subroutine verification.
 ;
 .method public static main([Ljava/lang/String;)V
-    .limit stack 2
+    .limit stack 1
     .limit locals 1
 
-    new org/apache/harmony/drlvm/tests/regression/h3225/PositiveJsrTest
-    dup
-    invokespecial org/apache/harmony/drlvm/tests/regression/h3225/PositiveJsrTest/<init>()V
-    astore_0
-
-    aload_0
-    invokevirtual org/apache/harmony/drlvm/tests/regression/h3225/PositiveJsrTest/testMinimalLimits()V
-
-    aload_0
-    invokevirtual org/apache/harmony/drlvm/tests/regression/h3225/PositiveJsrTest/testLastJsr()V
-
-    aload_0
-    invokevirtual org/apache/harmony/drlvm/tests/regression/h3225/PositiveJsrTest/testCommonReturn()V
-
-    aload_0
-    invokevirtual org/apache/harmony/drlvm/tests/regression/h3225/PositiveJsrTest/testMultipleCalls()V
-
-    aload_0
-    invokevirtual org/apache/harmony/drlvm/tests/regression/h3225/PositiveJsrTest/testNestedSubs()V
-
-    aload_0
-    invokevirtual org/apache/harmony/drlvm/tests/regression/h3225/PositiveJsrTest/testCallFromHandler()V
-
-    aload_0
-    invokevirtual org/apache/harmony/drlvm/tests/regression/h3225/PositiveJsrTest/testBranches()V
+    ldc "org.apache.harmony.drlvm.tests.regression.h3225.PositiveJsrTest"
+    invokestatic java/lang/Class/forName(Ljava/lang/String;)Ljava/lang.Class;
+    invokestatic junit/textui/TestRunner/run(Ljava/lang/Class;)V
 
     return
 .end method
@@ -201,4 +179,98 @@
     ret 1
 
 .end method
+
+
+;
+; A subroutine graph contains several unreachable nodes.
+;
+.method public testUnreachableNodes()V
+    .limit stack 1
+    .limit locals 1
+
+    return
+LabelBackward:
+    aconst_null
+    ifnull LabelForward
+    aconst_null
+    ifnull LabelBackward
+LabelForward:
+    aconst_null
+    ifnull LabelBackward
+    jsr LabelBackward
+.end method
+
+;
+; A subroutine is called from another subroutine nine times.
+;
+.method public testNineNestedSubs()V
+    .limit stack 3
+    .limit locals 1
+
+    iconst_0
+    jsr LabelSub
+    jsr LabelSub
+    jsr LabelSub
+    jsr LabelSub
+    jsr LabelSub
+    jsr LabelSub
+    jsr LabelSub
+    jsr LabelSub
+    jsr LabelSub
+    bipush 81
+    swap
+    invokestatic org/apache/harmony/drlvm/tests/regression/h3225/PositiveJsrTest/assertEquals(II)V
+    return
+
+LabelSub:
+    swap
+    jsr LabelSubSub
+    jsr LabelSubSub
+    jsr LabelSubSub
+    jsr LabelSubSub
+    jsr LabelSubSub
+    jsr LabelSubSub
+    jsr LabelSubSub
+    jsr LabelSubSub
+    jsr LabelSubSub
+    swap
+    astore 0
+    ret 0
+
+LabelSubSub:
+    astore 0
+    iconst_1
+    iadd
+    ret 0
+
+.end method
+
+;
+; Calls one subroutine after another in the subroutine context.
+;
+.method public testSubAfterSub()V
+    .limit stack 1
+    .limit locals 2
+
+    jsr LabelSub1
+    return
+
+LabelSub1:
+    astore 0
+    jsr LabelSub2
+    jsr LabelSub2
+    jsr LabelSub3
+    jsr LabelSub3
+    ret 0
+
+LabelSub2:
+    astore 1
+    ret 1
+
+LabelSub3:
+    astore 1
+    ret 1
+
+.end method
+
 

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/H3225/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3225/run.test.xml?view=diff&rev=546915&r1=546914&r2=546915
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3225/run.test.xml (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3225/run.test.xml Wed Jun 13 08:17:09 2007
@@ -6,6 +6,9 @@
         <run-junit-test 
              test="org.apache.harmony.drlvm.tests.regression.h3225.NegativeJsrTest"
              vmarg="-Xint" />
+        <run-junit-test 
+             test="org.apache.harmony.drlvm.tests.regression.h3225.J9CompatibleJsrTest"
+             vmarg="-Xint" />
     </target>
 </project>
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/verifier.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/verifier.h?view=diff&rev=546915&r1=546914&r2=546915
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/verifier.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/verifier.h Wed Jun 13 08:17:09 2007
@@ -17,37 +17,37 @@
 /** 
  * @author Pavel Rebriy
  * @version $Revision: 1.1.2.1.4.3 $
- */  
+ */
 #ifndef _VERIFIER_H_
 #define _VERIFIER_H_
 
 #include "class_interface.h"
 
-enum Verifier_Result
+enum vf_Result
 {
-    VER_OK,
-    VER_ErrorUnknown,               // unknown error occured
-    VER_ErrorInstruction,           // instruction coding error
-    VER_ErrorConstantPool,          // bad constant pool format
-    VER_ErrorLocals,                // incorrect usage of local variables
-    VER_ErrorBranch,                // incorrect local branch offset
-    VER_ErrorStackOverflow,         // stack overflow
-    VER_ErrorStackUnderflow,        // stack underflow
-    VER_ErrorStackDepth,            // inconstant stack deep to basic block
-    VER_ErrorCodeEnd,               // falling off the end of the code
-    VER_ErrorHandler,               // error in method handler
-    VER_ErrorDataFlow,              // data flow error
-    VER_ErrorIncompatibleArgument,  // incompatible argument to function
-    VER_ErrorLoadClass,             // error load class
-    VER_ErrorResolve,               // error resolve field/method
-    VER_ErrorJsrRecursive,          // found a recursive subroutine call sequence
-    VER_ErrorJsrMultipleRet,        // subroutine splits execution into several
-                                    // <code>ret</code> instructions
-    VER_ErrorJsrLoadRetAddr,        // loaded return address from local variable
-    VER_ErrorJsrOther,              // invalid subroutine
-    VER_ClassNotLoaded,             // verified class not loaded yet
-    VER_ErrorInternal,              // error in verification process
-    VER_Continue                    // intermediate status, continue analysis
+    VF_OK,
+    VF_ErrorUnknown,            // unknown error occured
+    VF_ErrorInstruction,        // instruction coding error
+    VF_ErrorConstantPool,       // bad constant pool format
+    VF_ErrorLocals,             // incorrect usage of local variables
+    VF_ErrorBranch,             // incorrect local branch offset
+    VF_ErrorStackOverflow,      // stack overflow
+    VF_ErrorStackUnderflow,     // stack underflow
+    VF_ErrorStackDepth,         // inconstant stack deep to basic block
+    VF_ErrorCodeEnd,            // falling off the end of the code
+    VF_ErrorHandler,            // error in method handler
+    VF_ErrorDataFlow,           // data flow error
+    VF_ErrorIncompatibleArgument,       // incompatible argument to function
+    VF_ErrorLoadClass,          // error load class
+    VF_ErrorResolve,            // error resolve field/method
+    VF_ErrorJsrRecursive,       // found a recursive subroutine call sequence
+    VF_ErrorJsrMultipleRet,     // subroutine splits execution into several
+    // <code>ret</code> instructions
+    VF_ErrorJsrLoadRetAddr,     // loaded return address from local variable
+    VF_ErrorJsrOther,           // invalid subroutine
+    VF_ClassNotLoaded,          // verified class not loaded yet
+    VF_ErrorInternal,           // error in verification process
+    VF_Continue                 // intermediate status, continue analysis
 };
 
 /**
@@ -58,8 +58,8 @@
  * @return Class verification result.
  * @note Assertion is raised if klass is equal to null.
  */
-Verifier_Result
-vf_verify_class( class_handler klass, unsigned verifyAll, char **error );
+vf_Result
+vf_verify_class(class_handler klass, unsigned verifyAll, char **error);
 
 /**
  * Function provides final constraint checks for a given class.
@@ -69,23 +69,22 @@
  * @return Class verification result.
  * @note Assertion is raised if klass or error_message are equal to null.
  */
-Verifier_Result
-vf_verify_class_constraints( class_handler klass, unsigned verifyAll, char **error );
+vf_Result
+vf_verify_class_constraints(class_handler klass, unsigned verifyAll,
+                            char **error);
 
 /**
  * Function provides final constraint checks for a given class.
  * @param error - error message of verifier
  * @note Assertion is raised if error_message is equal to null.
  */
-void
-vf_release_error_message( void *error );
+void vf_release_error_message(void *error);
 
 /**
  * Function releases verify data in class loader.
  * @param data - verify data
  * @note Assertion is raised if data is equal to null.
  */
-void
-vf_release_verify_data( void *data );
+void vf_release_verify_data(void *data);
 
 #endif // _VERIFIER_H_

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Verifier_stub.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Verifier_stub.cpp?view=diff&rev=546915&r1=546914&r2=546915
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Verifier_stub.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/Verifier_stub.cpp Wed Jun 13 08:17:09 2007
@@ -17,7 +17,7 @@
 /** 
  * @author Pavel Pervov
  * @version $Revision: 1.1.2.2.4.4 $
- */  
+ */
 
 
 #define LOG_DOMAIN "verifier"
@@ -30,18 +30,17 @@
 #include "open/vm.h"
 #include "lock_manager.h"
 
-bool
-Class::verify(const Global_Env* env)
+bool Class::verify(const Global_Env * env)
 {
     // fast path
-    if(m_state >= ST_BytecodesVerified)
+    if (m_state >= ST_BytecodesVerified)
         return true;
 
     LMAutoUnlock aulock(m_lock);
-    if(m_state >= ST_BytecodesVerified)
+    if (m_state >= ST_BytecodesVerified)
         return true;
 
-    if(is_array()) {
+    if (is_array()) {
         // no need do bytecode verification for arrays
         m_state = ST_BytecodesVerified;
         return true;
@@ -58,31 +57,28 @@
     /**
      * Verify class
      */
-    if(is_enabled == TRUE
-        && !is_interface()
-        && (is_bootstrap == FALSE || is_forced == TRUE))
-    {
+    if (is_enabled == TRUE && !is_interface()
+        && (is_bootstrap == FALSE || is_forced == TRUE)) {
         char *error;
-        Verifier_Result result = vf_verify_class((class_handler)this, is_strict, &error);
-        if( result != VER_OK ) {
+        vf_Result result =
+            vf_verify_class((class_handler) this, is_strict, &error);
+        if (VF_OK != result) {
             aulock.ForceUnlock();
             REPORT_FAILED_CLASS_CLASS(m_class_loader, this,
-                "java/lang/VerifyError", error);
+                                      "java/lang/VerifyError", error);
             return false;
         }
     }
     m_state = ST_BytecodesVerified;
 
     return true;
-} // Class::verify
+}                               // Class::verify
 
 
-bool
-Class::verify_constraints(const Global_Env* env)
+bool Class::verify_constraints(const Global_Env * env)
 {
     // fast path
-    switch(m_state)
-    {
+    switch (m_state) {
     case ST_ConstraintsVerified:
     case ST_Initializing:
     case ST_Initialized:
@@ -94,8 +90,7 @@
     lock();
 
     // check verification stage again
-    switch(m_state)
-    {
+    switch (m_state) {
     case ST_ConstraintsVerified:
     case ST_Initializing:
     case ST_Initialized:
@@ -105,13 +100,12 @@
     }
     assert(m_state == ST_Prepared);
 
-    if(is_array()) {
+    if (is_array()) {
         // no need do constraint verification for arrays
         m_state = ST_ConstraintsVerified;
         unlock();
         return true;
     }
-
     // get verifier enable status
     Boolean is_strict = env->verify_strict;
 
@@ -120,13 +114,12 @@
 
     // check method constraints
     char *error;
-    Verifier_Result result =
-        vf_verify_class_constraints((class_handler)this, is_strict, &error);
+    vf_Result result =
+        vf_verify_class_constraints((class_handler) this, is_strict, &error);
 
     // lock class and check result
     lock();
-    switch(m_state)
-    {
+    switch (m_state) {
     case ST_ConstraintsVerified:
     case ST_Initializing:
     case ST_Initialized:
@@ -134,15 +127,15 @@
         unlock();
         return true;
     }
-    if( result != VER_OK ) {
+    if (VF_OK != result) {
         unlock();
-        if( result == VER_ErrorLoadClass ) {
+        if (result == VF_ErrorLoadClass) {
             // Exception is raised by class loading
             // and passed through verifier unchanged
             assert(exn_raised());
         } else {
             REPORT_FAILED_CLASS_CLASS(m_class_loader, this,
-                "java/lang/VerifyError", error);
+                                      "java/lang/VerifyError", error);
         }
         return false;
     }
@@ -152,4 +145,4 @@
     unlock();
 
     return true;
-} // class_verify_method_constraints
+}                               // class_verify_method_constraints

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/Graph.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/Graph.cpp?view=diff&rev=546915&r1=546914&r2=546915
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/Graph.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/verifier/Graph.cpp Wed Jun 13 08:17:09 2007
@@ -29,16 +29,15 @@
 /**
  * Prints graph structure in stderr.
  */
-void
-vf_Graph::DumpGraph()
+void vf_Graph::DumpGraph()
 {
 #if _VF_DEBUG
-    VF_DEBUG( "Method: " << class_get_name( m_ctx->m_class ) << "::"
-              << m_ctx->m_name << m_ctx->m_descriptor << endl );
-    VF_DEBUG( "-- start --" );
+    VF_DEBUG("Method: " << class_get_name(m_ctx->m_class) << "::"
+             << m_ctx->m_name << m_ctx->m_descriptor << endl);
+    VF_DEBUG("-- start --");
     ResetNodeIterator();
-    while( HasMoreElements() ) {
-        DumpNode( GetNextNode() );
+    while (HasMoreElements()) {
+        DumpNode(GetNextNode());
     }
 #endif // _VF_DEBUG
 }                               // vf_Graph::DumpGraph
@@ -46,59 +45,57 @@
 /**
  * Prints graph node in stderr.
  */
-void
-vf_Graph::DumpNode( vf_NodeHandle node )        // a graph node
+void vf_Graph::DumpNode(vf_NodeHandle node)     // a graph node
 {
 #if _VF_DEBUG
     // print node incoming edges
     vf_EdgeHandle edge;
-    for( edge = node->m_inedge; edge; edge = edge->m_innext ) {
-        VF_DEBUG( " [" << GetNodeNum( edge->m_start ) << "] -->" );
+    for (edge = node->m_inedge; edge; edge = edge->m_innext) {
+        VF_DEBUG(" [" << GetNodeNum(edge->m_start) << "] -->");
     }
 
-    switch ( node->m_type ) {
+    switch (node->m_type) {
     case VF_NODE_START_ENTRY:
-        VF_DEBUG( "node[" << GetNodeNum( node ) << "]: start node" );
+        VF_DEBUG("node[" << GetNodeNum(node) << "]: start node");
         break;
     case VF_NODE_END_ENTRY:
-        VF_DEBUG( "node[" << GetNodeNum( node ) << "]: end node" );
+        VF_DEBUG("node[" << GetNodeNum(node) << "]: end node");
         break;
     case VF_NODE_HANDLER:
-        VF_DEBUG( "node[" << GetNodeNum( node ) << "]: exception handler" );
+        VF_DEBUG("node[" << GetNodeNum(node) << "]: exception handler");
         break;
     default:
-        DumpNodeInternal( node );
+        DumpNodeInternal(node);
     }
 
     // print node outcoming edges
-    for( edge = node->m_outedge; edge; edge = edge->m_outnext ) {
-        VF_DEBUG( " --> [" << GetNodeNum( edge->m_end ) << "]" );
+    for (edge = node->m_outedge; edge; edge = edge->m_outnext) {
+        VF_DEBUG(" --> [" << GetNodeNum(edge->m_end) << "]");
     }
-    VF_DEBUG( "" );
+    VF_DEBUG("");
 #endif // _VF_DEBUG
 }                               // vf_Graph::DumpNode
 
 /**
  * Prints graph node instruction in stream.
  */
-void
-vf_Graph::DumpNodeInternal( vf_NodeHandle node )        // graph node number
+void vf_Graph::DumpNodeInternal(vf_NodeHandle node)     // graph node number
 {
 #if _VF_DEBUG
     // print node header
-    VF_DEBUG( "Node #" << GetNodeNum( node ) );
-    VF_DEBUG( "Stack mod: " << node->m_stack );
-    DumpSub( node->m_sub );
+    VF_DEBUG("Node #" << GetNodeNum(node));
+    VF_DEBUG("Stack mod: " << node->m_stack);
+    DumpSub(node->m_sub);
 
     // get code instructions
     unsigned count = node->m_end - node->m_start + 1;
     vf_InstrHandle instr = node->m_start;
 
     // print node instructions
-    for( unsigned index = 0; index < count; index++, instr++ ) {
-        VF_DEBUG( index << ": " << ( ( instr->m_stack < 0 ) ? "[" : "[ " )
-                  << instr->m_stack << "| " << instr->m_minstack << "] "
-                  << vf_opcode_names[*( instr->m_addr )] );
+    for (unsigned index = 0; index < count; index++, instr++) {
+        VF_DEBUG(index << ": " << ((instr->m_stack < 0) ? "[" : "[ ")
+                 << instr->m_stack << "| " << instr->m_minstack << "] "
+                 << vf_opcode_names[*(instr->m_addr)]);
     }
 #endif // _VF_DEBUG
 }                               // vf_Graph::DumpNodeInternal
@@ -107,8 +104,7 @@
 /**
  * Dumps graph node in file in DOT format.
  */
-void
-vf_Graph::DumpDotGraph()
+void vf_Graph::DumpDotGraph()
 {
 #if _VF_DEBUG
     /**
@@ -118,23 +114,23 @@
     const int MAX_LABEL_LENGTH = 80;
 
     // get class and method name
-    const char *class_name = class_get_name( m_ctx->m_class );
+    const char *class_name = class_get_name(m_ctx->m_class);
 
     // create file name
-    size_t len = strlen( class_name ) + strlen( m_ctx->m_name )
-        + strlen( m_ctx->m_descriptor ) + 6;
-    char *fname = (char*)STD_ALLOCA( len );
-    sprintf( fname, "%s_%s%s", class_name, m_ctx->m_name, m_ctx->m_descriptor );
+    size_t len = strlen(class_name) + strlen(m_ctx->m_name)
+        + strlen(m_ctx->m_descriptor) + 6;
+    char *fname = (char *) STD_ALLOCA(len);
+    sprintf(fname, "%s_%s%s", class_name, m_ctx->m_name, m_ctx->m_descriptor);
 
     char *f_start;
     char *pointer;
-    if( len > MAX_LABEL_LENGTH ) {
+    if (len > MAX_LABEL_LENGTH) {
         f_start = fname + len - MAX_LABEL_LENGTH;
         // shift to the start of the nearest lexem
-        for( pointer = f_start;; pointer++ ) {
-            if( isalnum( *pointer ) ) {
+        for (pointer = f_start;; pointer++) {
+            if (isalnum(*pointer)) {
                 continue;
-            } else if( !*pointer ) {    // end of the string
+            } else if (!*pointer) {     // end of the string
                 break;
             } else {
                 // record the first matching position
@@ -146,34 +142,34 @@
         f_start = fname;
     }
 
-    for( pointer = f_start;; pointer++ ) {
-        if( isalnum( *pointer ) ) {
+    for (pointer = f_start;; pointer++) {
+        if (isalnum(*pointer)) {
             continue;
-        } else if( !*pointer ) {        // end of the string
+        } else if (!*pointer) { // end of the string
             break;
         } else {
             *pointer = '_';
         }
     }
     // pointer currently points to the end of the string
-    sprintf( pointer, ".dot" );
+    sprintf(pointer, ".dot");
 
     // create .dot file
-    ofstream fout( f_start );
-    if( fout.fail() ) {
-        VF_DEBUG( "vf_Graph::DumpDotGraph: error opening file: " << f_start );
+    ofstream fout(f_start);
+    if (fout.fail()) {
+        VF_DEBUG("vf_Graph::DumpDotGraph: error opening file: " << f_start);
         return;
     }
     // create name of graph
-    sprintf( fname, "%s.%s%s", class_name, m_ctx->m_name, m_ctx->m_descriptor );
+    sprintf(fname, "%s.%s%s", class_name, m_ctx->m_name, m_ctx->m_descriptor);
 
     // print graph to file
-    DumpDotHeader( f_start, fout );
+    DumpDotHeader(f_start, fout);
     ResetNodeIterator();
-    while( HasMoreElements() ) {
-        DumpDotNode( GetNextNode(), fout );
+    while (HasMoreElements()) {
+        DumpDotNode(GetNextNode(), fout);
     }
-    DumpDotEnd( fout );
+    DumpDotEnd(fout);
 
     // close file
     fout.flush();
@@ -184,9 +180,8 @@
 /**
  * Dumps graph header in file in DOT format.
  */
-void
-vf_Graph::DumpDotHeader( const char *graph_name,        // graph name
-                         ofstream &out )        // output file stream
+void vf_Graph::DumpDotHeader(const char *graph_name,    // graph name
+                             ofstream &out)     // output file stream
 {
 #if _VF_DEBUG
     out << "digraph dotgraph {" << endl
@@ -206,39 +201,37 @@
 /**
  * Dumps graph node in file in DOT format.
  */
-void
-vf_Graph::DumpDotNode( vf_NodeHandle node,      // graph node number
-                       ofstream &out )  // output file stream
+void vf_Graph::DumpDotNode(vf_NodeHandle node,  // graph node number
+                           ofstream &out)       // output file stream
 {
 #if _VF_DEBUG
     // print node to dot file
-    out << "node" << GetNodeNum( node );
-    if( VF_NODE_START_ENTRY == node->m_type ) { // start node
+    out << "node" << GetNodeNum(node);
+    if (VF_NODE_START_ENTRY == node->m_type) {  // start node
         out << " [label=\"START\", color=limegreen]" << endl;
-    } else if( VF_NODE_END_ENTRY == node->m_type ) {    // end node
+    } else if (VF_NODE_END_ENTRY == node->m_type) {     // end node
         out << " [label=\"END\", color=orangered]" << endl;
-    } else if( VF_NODE_HANDLER == node->m_type ) {      // handler node
+    } else if (VF_NODE_HANDLER == node->m_type) {       // handler node
         out << " [label=\"Handler #"
-            << GetNodeNum( node ) << "\", shape=ellipse, color=";
-        if( node->m_sub ) {
+            << GetNodeNum(node) << "\", shape=ellipse, color=";
+        if (node->m_sub) {
             out << "\"#B7FFE" << hex
-                << ( vf_get_sub_num( node->m_sub, m_ctx ) %
-                     16 ) << dec << "\"";
+                << (vf_get_sub_num(node->m_sub, m_ctx) % 16) << dec << "\"";
         } else {
             out << "aquamarine";
         }
         out << "]" << endl;
     } else {                    // other nodes
-        DumpDotNodeInternal( node, "\\n---------\\n", "\\l", out );
+        DumpDotNodeInternal(node, "\\n---------\\n", "\\l", out);
     }
 
     // print node outcoming edges to dot file
-    for( vf_EdgeHandle edge = node->m_outedge; edge; edge = edge->m_outnext ) {
-        out << "node" << GetNodeNum( node ) << " -> "
-            << "node" << GetNodeNum( edge->m_end );
-        if( VF_NODE_HANDLER == edge->m_end->m_type ) {
+    for (vf_EdgeHandle edge = node->m_outedge; edge; edge = edge->m_outnext) {
+        out << "node" << GetNodeNum(node) << " -> "
+            << "node" << GetNodeNum(edge->m_end);
+        if (VF_NODE_HANDLER == edge->m_end->m_type) {
             out << "[color=red]" << endl;
-        } else if( vf_is_jsr_branch( edge, m_ctx ) ) {
+        } else if (vf_is_jsr_branch(edge, m_ctx)) {
             out << "[color=blue]" << endl;
         }
         out << ";" << endl;
@@ -249,16 +242,15 @@
 /**
  * Dumps graph node instruction in file stream in DOT format.
  */
-void
-vf_Graph::DumpDotNodeInternal( vf_NodeHandle node,      // graph node number
-                               char *next_node, // separator between nodes in stream
-                               char *next_instr,        // separator between instructions in stream
-                               ofstream &out )  // output file stream
+void vf_Graph::DumpDotNodeInternal(vf_NodeHandle node,  // graph node number
+                                   char *next_node,     // separator between nodes in stream
+                                   char *next_instr,    // separator between instructions in stream
+                                   ofstream &out)       // output file stream
 {
 #if _VF_DEBUG
     // print node header
     out << " [label=\"";
-    out << "Node " << GetNodeNum( node ) << next_node
+    out << "Node " << GetNodeNum(node) << next_node
         << "Stack mod: " << node->m_stack << next_node;
 
     // get code instructions
@@ -266,16 +258,16 @@
     vf_InstrHandle instr = node->m_start;
 
     // print node instructions
-    for( unsigned index = 0; index < count; index++, instr++ ) {
-        out << index << ": " << ( ( instr->m_stack < 0 ) ? "[" : "[ " )
+    for (unsigned index = 0; index < count; index++, instr++) {
+        out << index << ": " << ((instr->m_stack < 0) ? "[" : "[ ")
             << instr->m_stack << "\\| " << instr->m_minstack << "] "
-            << vf_opcode_names[*( instr->m_addr )] << next_instr;
+            << vf_opcode_names[*(instr->m_addr)] << next_instr;
     }
     out << "\"" << endl;
 
-    if( node->m_sub ) {
+    if (node->m_sub) {
         out << ", color=\"#B2F" << hex
-            << ( vf_get_sub_num( node->m_sub, m_ctx ) % 16 ) << dec << "EE\"";
+            << (vf_get_sub_num(node->m_sub, m_ctx) % 16) << dec << "EE\"";
     }
     out << "]" << endl;
 #endif // _VF_DEBUG
@@ -284,8 +276,7 @@
 /**
  * Dumps graph end in file in DOT format.
  */
-void
-vf_Graph::DumpDotEnd( ofstream &out )   // output file stream
+void vf_Graph::DumpDotEnd(ofstream &out)        // output file stream
 {
 #if _VF_DEBUG
     out << "}" << endl;
@@ -299,8 +290,7 @@
 /**
  * Creates bytecode control flow graph.
  */
-vf_Result
-vf_create_graph( vf_Context *ctx )      // verification context
+vf_Result vf_create_graph(vf_Context *ctx)      // verification context
 {
     vf_BCode *bc = ctx->m_bc;
 
@@ -310,17 +300,17 @@
      */
     unsigned edges = 0;
     unsigned short handler_count = ctx->m_handlers;
-    for( unsigned short handler_index = 0; handler_index < handler_count;
-         handler_index++ ) {
+    for (unsigned short handler_index = 0; handler_index < handler_count;
+         handler_index++) {
         unsigned short start_pc, end_pc, handler_pc, handler_cp_index, count;
-        method_get_exc_handler_info( ctx->m_method, handler_index,
-                                     &start_pc, &end_pc, &handler_pc,
-                                     &handler_cp_index );
+        method_get_exc_handler_info(ctx->m_method, handler_index,
+                                    &start_pc, &end_pc, &handler_pc,
+                                    &handler_cp_index);
 
         // number of basic blocks in the exception range
         unsigned handler_edges = 0;
-        for( count = start_pc; count < end_pc; count++ ) {
-            if( bc[count].m_is_bb_start ) {
+        for (count = start_pc; count < end_pc; count++) {
+            if (bc[count].m_is_bb_start) {
                 handler_edges++;
             }
         }
@@ -337,23 +327,23 @@
     /**
      * Check instruction offsets, count basic blocks and edges.
      */
-    for( unsigned index = 0; index < ctx->m_len; index++ ) {
+    for (unsigned index = 0; index < ctx->m_len; index++) {
         vf_InstrHandle instr = bc[index].m_instr;
-        if( NULL == instr ) {
-            if( bc[index].m_is_bb_start ) {
-                VF_REPORT( ctx, "Illegal target of jump or branch" );
-                return VER_ErrorBranch;
+        if (NULL == instr) {
+            if (bc[index].m_is_bb_start) {
+                VF_REPORT(ctx, "Illegal target of jump or branch");
+                return VF_ErrorBranch;
             } else {
                 continue;
             }
         }
 
-        if( bc[index].m_is_bb_start ) {
-            ( (vf_Instr*)instr )->m_is_bb_start = true;
+        if (bc[index].m_is_bb_start) {
+            ((vf_Instr *) instr)->m_is_bb_start = true;
             nodes++;
         }
 
-        if( instr->m_offcount ) {
+        if (instr->m_offcount) {
             // basic block should start next, so we will
             // count one branch anyway
             edges += instr->m_offcount - 1;
@@ -367,107 +357,106 @@
     edges += nodes - 1 - ctx->m_retnum;
 
     // allocate memory for graph structure
-    void *mem_graph = vf_palloc( ctx->m_pool, sizeof( vf_Graph ) );
+    void *mem_graph = vf_palloc(ctx->m_pool, sizeof(vf_Graph));
     // for graph creation use pre-calculated numbers
-    vf_Graph *graph = new( mem_graph ) vf_Graph( nodes, edges, ctx );
+    vf_Graph *graph = new(mem_graph) vf_Graph(nodes, edges, ctx);
     ctx->m_graph = graph;
 
     /**
      * Create nodes.
      */
-    graph->NewNode( VF_NODE_START_ENTRY );
+    graph->NewNode(VF_NODE_START_ENTRY);
 
     // create handler nodes
     unsigned node_index;
-    for( node_index = 1; node_index <= ( unsigned )handler_count;
-         node_index++ ) {
-        graph->NewNode( VF_NODE_HANDLER );
+    for (node_index = 1; node_index <= (unsigned) handler_count; node_index++) {
+        graph->NewNode(VF_NODE_HANDLER);
     }
 
     // create code range nodes right after the last handler node
     // a new node correspond to a subsequent basic block of instructions
-    for( vf_InstrHandle bb_start = ctx->m_instr;
-         bb_start < ctx->m_last_instr; node_index++ ) {
+    for (vf_InstrHandle bb_start = ctx->m_instr;
+         bb_start < ctx->m_last_instr; node_index++) {
         // find a basic block end
         vf_InstrHandle next_bb_start = bb_start + 1;
-        while( ( next_bb_start < ctx->m_last_instr )
-               && ( !next_bb_start->m_is_bb_start ) ) {
+        while ((next_bb_start < ctx->m_last_instr)
+               && (!next_bb_start->m_is_bb_start)) {
             next_bb_start++;
         }
 
-        ( (vf_Instr*)bb_start )->m_node =
-            graph->NewNode( bb_start, next_bb_start - 1 );
+        ((vf_Instr *) bb_start)->m_node =
+            graph->NewNode(bb_start, next_bb_start - 1);
         bb_start = next_bb_start;
     }
 
     // create exit-entry node
     graph->AddEndNode();
     unsigned node_num = node_index + 1;
-    assert( 0 == graph->HasMoreNodeSpace() );
+    assert(0 == graph->HasMoreNodeSpace());
 
     /**
      * Create edges.
      */
-    vf_Node *node = (vf_Node*)graph->GetNode( handler_count + 1 );
+    vf_Node *node = (vf_Node *) graph->GetNode(handler_count + 1);
 
     // from start-entry node to the first code range node
-    graph->NewEdge( (vf_Node*)graph->GetStartNode(), node );
+    graph->NewEdge((vf_Node *) graph->GetStartNode(), node);
 
     // create code range edges
-    for( ; VF_NODE_CODE_RANGE == node->m_type; node++ ) {
+    for (; VF_NODE_CODE_RANGE == node->m_type; node++) {
         vf_InstrHandle instr = node->m_end;
 
         // set control flow edges
-        if( instr->m_offcount ) {
-            for( unsigned count = 0; count < instr->m_offcount; count++ ) {
-                int offset = vf_get_instr_branch( instr, count );
+        if (instr->m_offcount) {
+            for (unsigned count = 0; count < instr->m_offcount; count++) {
+                int offset = vf_get_instr_branch(instr, count);
                 vf_Node *next_node =
-                    (vf_Node*)graph->GetNodeFromBytecodeIndex( offset );
-                assert( node );
+                    (vf_Node *) graph->GetNodeFromBytecodeIndex(offset);
+                assert(node);
 
-                graph->NewEdge( node, next_node );
-                if( next_node < node ) {
+                graph->NewEdge(node, next_node);
+                if (next_node < node) {
                     // node has a backward branch, thus any
                     // object on the stack should be initialized
                     node->m_initialized = true;
                 }
             }
-        } else if( VF_INSTR_RETURN == instr->m_type
-                   || VF_INSTR_THROW == instr->m_type ) {
-            graph->NewEdge( node, (vf_Node*)graph->GetEndNode() );
-        } else if( VF_INSTR_RET == instr->m_type ) {
+        } else if (VF_INSTR_RETURN == instr->m_type
+                   || VF_INSTR_THROW == instr->m_type) {
+            graph->NewEdge(node, (vf_Node *) graph->GetEndNode());
+        } else if (VF_INSTR_RET == instr->m_type) {
             // no edges from ret
-        } else if( VF_NODE_CODE_RANGE == ( node + 1 )->m_type ) {
-            graph->NewEdge( node, node + 1 );
+        } else if (VF_NODE_CODE_RANGE == (node + 1)->m_type) {
+            graph->NewEdge(node, node + 1);
         } else {
-            VF_REPORT( ctx, "Falling off the end of the code" );
-            return VER_ErrorBranch;
+            VF_REPORT(ctx, "Falling off the end of the code");
+            return VF_ErrorBranch;
         }
 
     }
-    assert( VF_NODE_END_ENTRY == node->m_type );
+    assert(VF_NODE_END_ENTRY == node->m_type);
 
     // create OUT map vectors for handler nodes
-    unsigned char *start_bc = method_get_bytecode( ctx->m_method );
-    for( unsigned short handler_index = 0;
-         handler_index < handler_count; handler_index++ ) {
+    unsigned char *start_bc = method_get_bytecode(ctx->m_method);
+    for (unsigned short handler_index = 0;
+         handler_index < handler_count; handler_index++) {
         unsigned short start_pc, end_pc, handler_pc, handler_cp_index;
-        method_get_exc_handler_info( ctx->m_method,
-                                     handler_index, &start_pc, &end_pc,
-                                     &handler_pc, &handler_cp_index );
+        method_get_exc_handler_info(ctx->m_method,
+                                    handler_index, &start_pc, &end_pc,
+                                    &handler_pc, &handler_cp_index);
 
         vf_ValidType *type = NULL;
-        if( handler_cp_index ) {
-            const char *name = vf_get_cp_class_name( ctx->m_class,
-                                                     handler_cp_index );
-            assert( name );
-            type = vf_create_class_valid_type( name, ctx );
+        if (handler_cp_index) {
+            const char *name = vf_get_cp_class_name(ctx->m_class,
+                                                    handler_cp_index);
+            assert(name);
+            type = vf_create_class_valid_type(name, ctx);
 
             // set restriction for handler class
-            if( ctx->m_vtype.m_throwable->string[0] != type->string[0] ) {
-                ctx->m_type->SetRestriction( ctx->m_vtype.m_throwable->
-                                             string[0], type->string[0], 0,
-                                             VF_CHECK_SUPER );
+            if (ctx->m_vtype.m_throwable->string[0] != type->string[0]) {
+                ctx->m_type->SetRestriction(ctx->m_vtype.m_throwable->
+                                            string[0], type->string[0], 0,
+                                            VF_CHECK_SUPER);
             }
         }
 
@@ -478,42 +467,41 @@
          *    incoming map vector, local variables map vector will be
          *    created with during the process of merge.
          */
-        vf_MapVector *p_outvector = (vf_MapVector*)
-            &graph->GetNode( handler_index + 1 )->m_outmap;
+        vf_MapVector *p_outvector = (vf_MapVector *)
+            &graph->GetNode(handler_index + 1)->m_outmap;
         p_outvector->m_stack =
-            (vf_MapEntry*)graph->AllocMemory( sizeof( vf_MapEntry ) *
-                                                 ctx->m_maxstack );
+            (vf_MapEntry *) graph->AllocMemory(sizeof(vf_MapEntry) *
+                                               ctx->m_maxstack);
         p_outvector->m_depth = 1;
-        vf_set_vector_stack_entry_ref( p_outvector->m_stack, 0, type );
+        vf_set_vector_stack_entry_ref(p_outvector->m_stack, 0, type);
 
         // outcoming handler edge
-        vf_Node *handler_node =
-            (vf_Node*)graph->GetNode( handler_index + 1 );
-        graph->NewEdge( handler_node,
-                        (vf_Node*)graph->
-                        GetNodeFromBytecodeIndex( handler_pc ) );
+        vf_Node *handler_node = (vf_Node *) graph->GetNode(handler_index + 1);
+        graph->NewEdge(handler_node,
+                       (vf_Node *) graph->
+                       GetNodeFromBytecodeIndex(handler_pc));
 
         // node range start
-        node = (vf_Node*)graph->GetNodeFromBytecodeIndex( start_pc );
+        node = (vf_Node *) graph->GetNodeFromBytecodeIndex(start_pc);
 
-        vf_NodeHandle last_node = ( end_pc == ctx->m_len )
+        vf_NodeHandle last_node = (end_pc == ctx->m_len)
             ? graph->GetEndNode()
-            : graph->GetNodeFromBytecodeIndex( end_pc );
+            : graph->GetNodeFromBytecodeIndex(end_pc);
 
-        for( ; node < last_node; node++ ) {
+        for (; node < last_node; node++) {
             // node is protected by exception handler, thus the 
             // reference in local variables have to be initialized
             node->m_initialized = true;
-            graph->NewEdge( node, handler_node );
+            graph->NewEdge(node, handler_node);
         }
     }
     // one edge is reserved
-    assert( 0 == graph->HasMoreEdgeSpace() );
+    assert(0 == graph->HasMoreEdgeSpace());
 
-    VF_DUMP( DUMP_GRAPH, graph->DumpGraph() );
-    VF_DUMP( DUMP_DOT, graph->DumpDotGraph() );
+    VF_DUMP(DUMP_GRAPH, graph->DumpGraph());
+    VF_DUMP(DUMP_DOT, graph->DumpDotGraph());
 
-    return VER_OK;
+    return VF_OK;
 }                               // vf_create_graph
 
 /************************************************************
@@ -522,21 +510,20 @@
 /**
  * Checks stack depth of a node.
  */
-vf_Result
-vf_check_node_stack_depth( vf_Node *node,       // a graph node
-                           unsigned &depth,     // initial stack depth
-                           vf_Context *ctx )    // verification context
-{
-    if( node->m_mark ) {
-        if( ( depth == node->m_inmap.m_depth )
-            || ( VF_NODE_CODE_RANGE != node->m_type ) ) {
+vf_Result vf_check_node_stack_depth(vf_Node *node,      // a graph node
+                                    unsigned &depth,    // initial stack depth
+                                    vf_Context *ctx)    // verification context
+{
+    if (node->m_mark) {
+        if ((depth == node->m_inmap.m_depth)
+            || (VF_NODE_CODE_RANGE != node->m_type)) {
             // consistent stack depth in the node
-            return VER_OK;
+            return VF_OK;
         } else {
             // inconsistent stack depth
-            VF_REPORT( ctx, "Inconsistent stack depth: "
-                       << node->m_inmap.m_depth << " != " << depth );
-            return VER_ErrorStackDepth;
+            VF_REPORT(ctx, "Inconsistent stack depth: "
+                      << node->m_inmap.m_depth << " != " << depth);
+            return VF_ErrorStackDepth;
         }
     }
     // mark the node
@@ -546,111 +533,122 @@
     vf_Graph *graph = ctx->m_graph;
     graph->IncrementReachableCount();
     node->m_inmap.m_depth = depth;
+    VF_TRACE("node", "node[" << ctx->m_graph->GetNodeNum(node)
+             << "].in.depth := " << node->m_inmap.m_depth);
 
-    if( VF_NODE_CODE_RANGE != node->m_type ) {
-        if( VF_NODE_HANDLER == node->m_type ) {
+    if (VF_NODE_CODE_RANGE != node->m_type) {
+        if (VF_NODE_HANDLER == node->m_type) {
             depth = 1;
             node->m_stack = 1;
             node->m_outmap.m_depth = 1;
-        } else if( VF_NODE_END_ENTRY == node->m_type ) {
-            return VER_OK;
+        } else if (VF_NODE_END_ENTRY == node->m_type) {
+            return VF_OK;
         }
-        return VER_Continue;
+        return VF_Continue;
     }
     // calculate a stack depth after the last node instruction
     int stack_depth = 0;
-    for( vf_InstrHandle instr = node->m_start; instr <= node->m_end; instr++ ) {
-        if( instr->m_minstack > depth ) {
-            VF_REPORT( ctx,
-                       "Unable to pop operands needed for an instruction" );
-            return VER_ErrorStackUnderflow;
+    for (vf_InstrHandle instr = node->m_start; instr <= node->m_end; instr++) {
+        if (instr->m_minstack > depth) {
+            VF_REPORT(ctx,
+                      "Unable to pop operands needed for an instruction");
+            return VF_ErrorStackUnderflow;
         }
         stack_depth += instr->m_stack;
         depth += instr->m_stack;
-        assert( depth >= 0 );
-        if( depth > ctx->m_maxstack ) {
-            VF_REPORT( ctx, "Instruction stack overflow" );
-            return VER_ErrorStackOverflow;
+        assert(depth >= 0);
+        if (depth > ctx->m_maxstack) {
+            VF_REPORT(ctx, "Instruction stack overflow");
+            return VF_ErrorStackOverflow;
         }
     }
 
     node->m_stack = stack_depth;
     node->m_outmap.m_depth = depth;
-    return VER_Continue;
+    VF_TRACE("node", "node[" << ctx->m_graph->GetNodeNum(node)
+             << "].out.depth := " << node->m_outmap.m_depth);
+    return VF_Continue;
 }                               // vf_check_node_stack_depth
 
 /**
  * Checks graph nodes stack depth consistency recursively.
  * Returns result of a check.
  */
-static vf_Result
-vf_check_stack_depth( vf_Node *node,    // a graph node
-                      unsigned stack_depth,     // initial stack depth of node
-                      vf_Context *ctx ) // verification context
+static vf_Result vf_check_stack_depth(vf_Node *node,    // a graph node
+                                      unsigned stack_depth,     // initial stack depth of node
+                                      vf_Context *ctx)  // verification context
 {
     // check for node stack overflow
-    vf_Result result = vf_check_node_stack_depth( node, stack_depth, ctx );
-    if( result != VER_Continue ) {
+    vf_Result result = vf_check_node_stack_depth(node, stack_depth, ctx);
+    if (VF_Continue != result) {
         return result;
     }
     // iterate over out edges and set stack depth for out nodes
-    for( vf_EdgeHandle outedge = node->m_outedge;
-         outedge; outedge = outedge->m_outnext ) {
+    for (vf_EdgeHandle outedge = node->m_outedge;
+         outedge; outedge = outedge->m_outnext) {
         // get out node
-        vf_Node *outnode = (vf_Node*)outedge->m_end;
+        vf_Node *outnode = (vf_Node *) outedge->m_end;
         // mark out node with its out nodes
-        result = vf_check_stack_depth( outnode, stack_depth, ctx );
-        if( VER_OK != result ) {
+        result = vf_check_stack_depth(outnode, stack_depth, ctx);
+        if (VF_OK != result) {
             return result;
         }
     }
-    return VER_OK;
+    return VF_OK;
 }                               // vf_check_stack_depth
 
 /**
  * Removes <i>in</i> edge from the list of the corresponding end node.
  */
-static void
-vf_remove_inedge( vf_EdgeHandle edge )  // verification context
+static void vf_remove_inedge(vf_EdgeHandle edge)        // verification context
 {
-    vf_EdgeHandle *p_next_edge = (vf_EdgeHandle*) & edge->m_end->m_inedge;
-    vf_Edge *inedge = (vf_Edge*) edge->m_end->m_inedge;
-    while( inedge ) {
-        if( inedge == edge ) {
+    vf_EdgeHandle *p_next_edge = (vf_EdgeHandle *) & edge->m_end->m_inedge;
+    vf_Edge *inedge = (vf_Edge *) edge->m_end->m_inedge;
+    while (inedge) {
+        if (inedge == edge) {
             // remove the edge from the list
             *p_next_edge = inedge->m_innext;
             return;
         }
         p_next_edge = &inedge->m_innext;
-        inedge = (vf_Edge*) inedge->m_innext;
+        inedge = (vf_Edge *) inedge->m_innext;
     }
-    VF_DIE( "vf_remove_inedge: Cannot find an IN edge " << edge
-            << " from the list of the node " << edge->m_end );
+    VF_DIE("vf_remove_inedge: Cannot find an IN edge " << edge
+           << " from the list of the node " << edge->m_end);
 }
 
 /**
  * Scans dead nodes, removes obsolete edges and fills corresponding bytecode by nop
  * instruction.
  */
-static void
-vf_nullify_unreachable_bytecode( vf_ContextHandle ctx ) // verification context
+static void vf_nullify_unreachable_bytecode(vf_ContextHandle ctx)       // verification context
 {
     vf_Node *node =
-        (vf_Node*)ctx->m_graph->GetStartNode()->m_outedge->m_end;
-    for( ; node->m_type != VF_NODE_END_ENTRY; node++ ) {
-        assert( VF_NODE_CODE_RANGE == node->m_type );
-        if( !node->m_mark ) {
+        (vf_Node *) ctx->m_graph->GetStartNode()->m_outedge->m_end;
+    for (; node->m_type != VF_NODE_END_ENTRY; node++) {
+        assert(VF_NODE_CODE_RANGE == node->m_type);
+        if (!node->m_mark) {
+            VF_TRACE("node",
+                     "Cleaning unreachable node #" << ctx->m_graph->
+                     GetNodeNum(node));
             unsigned char *instr = node->m_start->m_addr;
-            const unsigned char *end = vf_get_instr_end( node->m_end, ctx );
-            while( instr < end ) {
-                *( instr++ ) = OPCODE_NOP;
+            const unsigned char *end = vf_get_instr_end(node->m_end, ctx);
+            while (instr < end) {
+                *(instr++) = OPCODE_NOP;
             }
             node->m_stack = 0;
             // we assume that java compiler generally doesn't generate a dead code,
             // so we rarely remove edges here is rare
-            for( vf_EdgeHandle edge = node->m_outedge; edge;
-                 edge = edge->m_outnext ) {
-                vf_remove_inedge( edge );
+            for (vf_EdgeHandle edge = node->m_outedge; edge;
+                 edge = edge->m_outnext) {
+                assert(edge->m_start == node);
+                VF_TRACE("edge", "Cleaning unreachable edge #"
+                         << ctx->m_graph->GetNodeNum(node) << " -> #"
+                         << ctx->m_graph->GetNodeNum(edge->m_end));
+                if (edge->m_end->m_mark) {
+                    // remove edges to reachable nodes
+                    vf_remove_inedge(edge);
+                }
             }
             node->m_inedge = node->m_outedge = NULL;
             node->m_sub = NULL;
@@ -662,8 +660,7 @@
 /**
  * Provides checks of control flow and data flow structures of graph.
  */
-vf_Result
-vf_check_graph( vf_Context *ctx )       // verification context
+vf_Result vf_check_graph(vf_Context *ctx)       // verification context
 {
     vf_Graph *graph = ctx->m_graph;
     vf_InstrHandle instr = ctx->m_instr;
@@ -671,70 +668,67 @@
     vf_Result result;
 
     // allocate a current stack map vector
-    ctx->m_map =    (vf_MapVector*)vf_palloc( ctx->m_pool,
-                                              sizeof( vf_MapVector ) );
-    ctx->m_graph->AllocVector( ctx->m_map );
+    ctx->m_map = (vf_MapVector *) vf_palloc(ctx->m_pool,
+                                            sizeof(vf_MapVector));
+    ctx->m_graph->AllocVector(ctx->m_map);
 
     // create a buf stack map vector (max 4 entries)
-    ctx->m_buf =    (vf_MapEntry*)vf_palloc( ctx->m_pool,
-                                             sizeof( vf_MapEntry )
-                                             * ctx->m_maxstack );
+    ctx->m_buf = (vf_MapEntry *) vf_palloc(ctx->m_pool, sizeof(vf_MapEntry)
+                                           * ctx->m_maxstack);
 
-    if( ctx->m_retnum ) {
-        result = vf_mark_subroutines( ctx );
+    if (ctx->m_retnum) {
+        result = vf_mark_subroutines(ctx);
     } else {
         result =
-            vf_check_stack_depth( (vf_Node*)graph->GetStartNode(), 0,
-                                  ctx );
+            vf_check_stack_depth((vf_Node *) graph->GetStartNode(), 0, ctx);
     }
-    if( VER_OK != result ) {
+    if (VF_OK != result) {
         return result;
     }
     // there could be only <code>nop</code> opcodes in the bytecode, in this case 
     // the code is already checked during previous step
-    if( ctx->m_maxstack == 0 ) {
-        return VER_OK;
+    if (ctx->m_maxstack == 0) {
+        return VF_OK;
     }
     // override all dead nodes
-    assert( graph->GetReachableNodeCount() <= graph->GetNodeCount() );
-    if( graph->GetReachableNodeCount() < graph->GetNodeCount() ) {
-        vf_nullify_unreachable_bytecode( ctx );
+    assert(graph->GetReachableNodeCount() <= graph->GetNodeCount());
+    if (graph->GetReachableNodeCount() < graph->GetNodeCount()) {
+        vf_nullify_unreachable_bytecode(ctx);
     }
 
-    if( ctx->m_retnum ) {
-        result = vf_inline_subroutines( ctx );
-        if( VER_OK != result ) {
+    if (ctx->m_retnum) {
+        result = vf_inline_subroutines(ctx);
+        if (VF_OK != result) {
             return result;
         }
     }
 
-    VF_DUMP( DUMP_MOD, graph->DumpGraph() );
-    VF_DUMP( DUMP_DOT_MOD, graph->DumpDotGraph() );
+    VF_DUMP(DUMP_MOD, graph->DumpGraph());
+    VF_DUMP(DUMP_DOT_MOD, graph->DumpDotGraph());
 
     /** 
      * Check that execution flow terminates with
      * return or athrow bytecodes.
      * Override all incoming edges to the end-entry node.
      */
-    for( vf_EdgeHandle inedge =
-         graph->GetEndNode()->m_inedge; inedge;
-         inedge = inedge->m_innext ) {
+    for (vf_EdgeHandle inedge =
+         graph->GetEndNode()->m_inedge; inedge; inedge = inedge->m_innext) {
         // get incoming node
         vf_NodeHandle innode = inedge->m_start;
         // get node last instruction
         vf_InstrType type = innode->m_end->m_type;
 
-        if( ( VF_INSTR_RETURN != type ) && ( VF_INSTR_THROW != type ) ) {
+        if ((VF_INSTR_RETURN != type) && (VF_INSTR_THROW != type)) {
             // illegal instruction
-            VF_REPORT( ctx, "Falling off the end of the code" );
-            return VER_ErrorCodeEnd;
+            VF_REPORT(ctx, "Falling off the end of the code");
+            return VF_ErrorCodeEnd;
         }
     }
 
     /**
      * Make data flow analysis
      */
-    result = vf_check_graph_data_flow( ctx );
+    result = vf_check_graph_data_flow(ctx);
 
     return result;
 }                               // vf_check_graph
@@ -742,13 +736,12 @@
 /**
  * Frees memory allocated for graph, if any.
  */
-void
-vf_free_graph( vf_Context *ctx )        // verification context
+void vf_free_graph(vf_Context *ctx)     // verification context
 {
-    if( ctx->m_graph ) {
-        VF_TRACE( "method", VF_REPORT_CTX( ctx ) << "method graph: "
-                  << " nodes: " << ctx->m_graph->GetNodeCount()
-                  << ", edges: " << ctx->m_graph->GetEdgeCount() );
+    if (ctx->m_graph) {
+        VF_TRACE("method", VF_REPORT_CTX(ctx) << "method graph: "
+                 << " nodes: " << ctx->m_graph->GetNodeCount()
+                 << ", edges: " << ctx->m_graph->GetEdgeCount());
         ctx->m_graph->~vf_Graph();
         ctx->m_graph = NULL;
     }



Mime
View raw message