Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-3755

[drlvm][verifier] VM allows to use jsr instruction to call subroutine recursively

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • None
    • None
    • DRLVM
    • None
    • Windows and Linux

    Description

      According to J2SE VM specification
      no jsr and jsr_w instruction may be used recursively to call subroutine.

      But VM does not reject class which calls subroutine recursively.
      To reproduce this bug run the following test. It uses synthetic classes subroutineTest and finallyTest created from jasmin source code
      ------------jsrTest.java-----------------------
      public class jsrTest {
      public static void main(String[] args) {
      try

      { Class.forName("finallyTest"); System.out.println("finallyTest failed: expected VerifyError was not thrown"); }

      catch (VerifyError e)

      { System.out.println("finallyTest passed: " + e); }

      catch (Throwable e)

      { System.out.println("finallyTest failed: unexpected error " + e); }

      try

      { Class.forName("subroutineTest"); System.out.println("subroutineTest failed: expected VerifyError was not thrown"); }

      catch (VerifyError e)

      { System.out.println("subroutineTest passed: " + e); }

      catch (Throwable e)

      { System.out.println("subroutineTest failed: unexpected error " + e); }

      }
      }
      -----------finallyTest.jj------------------
      .class public finallyTest
      .super java/lang/Object
      ;
      ; standard initializer
      .method public <init>()V
      aload_0
      invokespecial java/lang/Object/<init>()V
      return
      .end method
      ;
      ; test method
      .method public static test()V
      .limit stack 2
      .limit locals 2
      jsr First
      return
      First:
      astore_1
      sipush 111
      sipush 111
      if_icmpeq Second
      ret 1
      Second:
      jsr First ; recursively call a subroutine
      return
      .end method
      -----------------subroutineTest.jj-------------------
      .class public subroutineTest
      .super java/lang/Object
      ;
      ; standard initializer
      .method public <init>()V
      aload_0
      invokespecial java/lang/Object/<init>()V
      return
      .end method
      ;
      ; test method
      .method test()V
      .limit locals 3
      .limit stack 2

      jsr First
      return
      First:
      astore_2
      jsr First ; recursively call a subroutine
      ret 2
      .end method
      --------------------------------------------------------------
      Create subroutineTest and finallyTest classes using jasmin.jar or use classes from attachment
      java -jar jasmin.jar finallyTest.jj
      java -jar jasmin.jar subroutineTest.jj

      Run jsrTest
      Java
      Output on RI is:
      ----------------------
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

      finallyTest passed: java.lang.VerifyError: (class: finallyTest, method: test signature: ()V) Recursive call to jsr entry
      subroutineTest passed: java.lang.VerifyError: (class: subroutineTest, method: test signature: ()V) Recursive call to jsr entry

      Output on Harmony is:
      --------------------------------
      Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors, as applicable.
      java version "1.5.0"
      pre-alpha : not complete or compatible
      svn = r531681, (Apr 24 2007), Windows/ia32/msvc 1310, release build
      http://incubator.apache.org/harmony
      finallyTest failed: expected VerifyError was not thrown
      subroutineTest failed: expected VerifyError was not thrown

      Attachments

        1. jsrTest.zip
          2 kB
          Vera Petrashkova

        Activity

          People

            Unassigned Unassigned
            vpetrash Vera Petrashkova
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: