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

JVM treats non-static <clinit> as class initialization method

    XMLWordPrintable

Details

    • sparc
    • solaris_7

    Description



      Name: vsR10008 Date: 05/30/2000




      JVMS 2nd ed. (CHAPTER 3 "The Structure of the Java Virtual Machine", section 3.9
      "Specially Named Initialization Methods") reads:

      "A class or interface has at most one class or interface initialization method.
      ...
      The initialization method of a class or interface is static and takes no arguments.
      It has the special name <clinit>"

      The following test shows that JVM implicitly invokes non-static <clinit> treating it
      as class initialization method.

      ------------------------------------------------------------------ c.jasm -----

      super public class c
      {

      public static Field a:I;

      public Method "<init>":"()V"
      stack 1 locals 1
      {
      aload_0;
      invokespecial Method java/lang/Object."<init>":"()V";
      return;
      }

      Method "<clinit>":"()V"
      stack 1 locals 1
      {
      iconst_1;
      putstatic Field a:"I";
      return;
      }

      }

      ------------------------------------------------------------------ t.java -----

      public class t {
          public static void main(String[] argv) {
              try {
                  if ( c.a == 0 ) {
                      System.out.println("PASSED!");
                      System.exit(0);
                  } else {
                      System.out.println("FAILED, a=" +c.a);
                  }
              } catch (Throwable t) {
                  System.out.println("FAILED: Exception "+t);
              }
          }
      }

      --------------------------------------------------------------------------------

      $ java -version
      java version "1.3.0rc3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
      Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, interpreted mode)

      $ uname -a
      SunOS novo12 5.7 Generic_Patch sun4u sparc SUNW,Ultra-2

      $ jasm c.jasm

      $ javac -d . t.java

      $ java t

      FAILED, a=1

      This bug is reproduced in all available builds of JDK (1.0-1.4beta)
      and affects Classic and HotSpot both.

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

      Attachments

        Issue Links

          Activity

            People

              hhuangsunw Hui Huang (Inactive)
              atwosunw A2 A2 (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: