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

Mustang b85: global statics variable is accessible before <clinit> finished.

XMLWordPrintable

    • b85
    • 6
    • b92
    • generic
    • generic
    • Verified

      JCK: 6.0 b23
      Test:
        vm/concepts/execution/execution081/execution08120m1 failed.
      ( The test checks that the global statics variable is unaccessible before the method <clinit> finishes )
      FAILED: mustang b85 ( only on client vm - "-client" option )
      PASSED: mustang b84 ( all ), tiger ( JDK5.0u7 )
      Also PASSED on mustang b85 with -server OR with "-client -Xcomp" options.

      PLATFORM: seems to be platform indeprndent failure
      ----------------------------------------------------------
      Test src ( several printlns added ):
      import java.io.PrintStream;

      class X extends Thread {
          public static final boolean _P; // TRUE after clinit

          static {
              // _P is FALSE here
              // Run fiddle_with_X in a loop until it compiles
             for (int i=0; i < 15000; i++) {
                 Y.fiddle_with_X();
             }

              // Stall for a long time to allow adverse thread to get in
              try {
                  sleep(3000);
              } catch (InterruptedException ix) {
              }

              _P = true; // set to TRUE here
              System.out.println("P:" + _P);
          }
      }

      class Y extends Thread {

          public static boolean fiddle_with_X() {
          
              boolean xp = X._P; // Capture locally X._P
              return xp;
          }

          // What happens when we kick off a new Y?
          public void run() {
              // Sleep until X's <clinit> is underway
              try {
                  sleep(1000);
              } catch (InterruptedException ix) {
              }

              boolean xp = Y.fiddle_with_X();
              if (xp == false) {
                  System.out.println("Y.fiddle_with_X() returned false");
                  execution08120m1.retCode = 2; //STATUS_FAILED
              } else {
                  System.out.println("OK");
                  execution08120m1.retCode = 0; //STATUS_PASSED
              }
          }
      }

      class execution08120m1 {
          static volatile int retCode = 0;

          static public void main(String[] argv) {
              System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
          }

          public static int run(String argv[], PrintStream out) {

              // Make an adverse Y thread.
              // It sleeps a little to let X::<clinit> get underway

             Y y = new Y();
             y.start();

              // Invoke X.<clinit> It will sleep for 3000.
              // Meanwhile Y should wake-up and access X's statics.
              boolean b = X._P;
              System.out.println("P: " + b);

              if (b != true) {
                  System.out.println("FAILED: Expected X._P to be true after <clinit> ");
                  return 2; //STATUS_FAILED
              }
              return retCode;
          }
      }

      ------------------------------------
      ------------------------------------
      Test output in case of failure:
      java version "1.6.0-beta2"
      Java(TM) SE Runtime Environment (build 1.6.0-beta2-b85)
      Java HotSpot(TM) Client VM (build 1.6.0-beta2-b85, mixed mode, sharing)

      Y.fiddle_with_X() returned false
      P:true
      P: true
      97
      -----------------------------------

      If we comment lines in test ( that caused JIT compilation ? ):
              // Run fiddle_with_X in a loop until it compiles
         for (int i=0; i < 15000; i++) {
              Y.fiddle_with_X();
         }
      test passes.

            never Tom Rodriguez
            dgubkin Dmitriy Gubkin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: