Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4052870

initialization of classes is performed incorrectly

    XMLWordPrintable

    Details

      Description



      Name: laC46010 Date: 05/19/97



      According to JLS (12.4.1 When Initialization Occurs, p.223-225)
      "A class or interface type T will be initialized at its first active use".
      However JIT 210.046 for JDK 1.1.2 initializes classes on more early stage
      - before their first use. This leads to failures of the following JCK tests:

      lang/CLSS/clss092/clss09201
      lang/EXEC/exec007/exec00704
      lang/STMT/stmt107/stmt10701
      lang/STMT/stmt107/stmt10702
      lang/STMT/stmt107/stmt10705

      along with the example from spec (p.225) below:

      [H:/ld12/java/leo/java/bug/jit/init/ex3] ja -verify Test
      Symantec Java! JustInTime Compiler Version 210.046 for JDK 1.1.2
      Copyright (C) 1996-97 Symantec Corporation
      ii=2
      j=3
      jj=4
      1
      3

      JLS says it should print

      1
      j=3
      jj=4
      3


      Another modified example from the spec
      shows that JIT illegaly initializes classes "Super" and "Two".
      They should not be initialized because statements
                       One o = null;
                       Two t = new Two();
      are not executed so there is not "active use" of the classes here.

      [H:/ld12/java/leo/java/bug/jit/init/ex1] jc -d . Test.java
      Symantec Java! JustInTime Compiler Version 210.046 for JDK 1.1.2
      Copyright (C) 1996-97 Symantec Corporation
      [H:/ld12/java/leo/java/bug/jit/init/ex1] ja -verify Test
      Symantec Java! JustInTime Compiler Version 210.046 for JDK 1.1.2
      Copyright (C) 1996-97 Symantec Corporation
      Super
      Two

      --------------------------Test.java-------------------------------
      class Super {
              static { System.out.print("Super\n"); }
      }

      class One {
              static { System.out.print("One\n"); }
      }

      class Two extends Super {
              static { System.out.print("Two\n"); }
      }

      class Test {
              public static void main(String[] args) {
      int i = 1;
      int j = 2;
      if (i==j) {
                       One o = null;
                       Two t = new Two();
                       System.out.println((Object)o == (Object)t);
      } else {
      j++;
      }
              }
      }
      ---------------------------------------------------------

      ======================================================================

      Same bug report from the customer:

      The following code demonstrates a bug in
      static intialization. The static
      initialization block is never called,
      causing a run time error. Notice that bogus
      error that Cafe gives.


      E:>cat DSC.java
      class YCount
      {
        YCount(int j) {
          i = j;
        }

        int i;
      }


       public final class DSC {

         private static DSC s_c =
           new DSC ( ) ;

       public static DSC controller ( ) {
           return s_c;
       }

       private DSC ( )
       {
          System.out.println("IN: DSC.DSC");
          x_fun(1);
        }



      private static YCount[] x_yCount;
      static {
      System.out.println("Static block
      initialized");
      x_yCount = new YCount[2];
      x_yCount[0] = new YCount(0);
      x_yCount[2] = new YCount(1);
      }

      static void x_fun(int yNb){
          System.out.println("IN DSC.x_fun(" + yNb
      + ")");
          System.out.println(x_yCount);
          if (x_yCount == null) {
            System.out.println("failure");
          }
          YCount y = x_yCount[1];
          if (y == null) {
            System.out.println("failure");
          }
          System.out.println(y);
          System.out.println("y recovered");
          System.out.println("OUT DSC.x_fun(" + yNb
      + ")");
      }


      public static void main(String[] args)
      {
        DSC.controller();
      }

      }


      E:>d:\jdk\bin\javac DSC.java

      E:> d:\jdk\bin\java.exe DSC
      IN: DSC.DSC
      IN DSC.x_fun(1)
      null
      failure

      E:>d:\cafe\java\bin\javac.exe DSC.java
      Symantec Java! JustInTime Compiler Version
      210.050 for JDK 1.1
      Copyright (C) 1996-97 Symantec Corporation
        compiling: DSC.java

      E:>d:\cafe\java\bin\java.exe -classpath
      .;%CLASSPATH% DSC
      Symantec Java! JustInTime Compiler Version
      210.050 for JDK 1.1
      Copyright (C) 1996-97 Symantec Corporation
      IN: DSC.DSC
      IN DSC.x_fun(1)
      null
      failure
      Can't find class DSC

      If you have any questions or require
      additional information, please feel free to
      contact me at any time. I can be reached at
      (613) 728-0826 ext.1581 or via e-mail at
      ###@###.###.

        Attachments

          Activity

            People

            Assignee:
            dviswanasunw Deepa Viswanathan (Inactive)
            Reporter:
            leosunw Leo Leo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: