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

JCK spec section 14.17, paragraph 5 is violated by JDK 1.1.

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      solaris_2.5.1

      Description

      allan.jacobs@Eng 1997-02-27
      The test is flawed. The yield statement should be inside the loop.
      Please close this bug.


      allan.jacobs@Eng 1997-02-26
      JCK spec section 14.17, paragraph 5 is violated by JDK 1.1.

      A lock on an object should not prevent other threads from manipulating
      fields of that object in unsynchronized sections of code.

      The test code is adapted from Modena test c1417501. It hangs when
      executed (with the JIT disabled and using green threads).

      /**
       ** JAVATEST : The Modena JAVA Test Suite, Version 2.0, November 1996
       ** Copyright (c) 1996 Modena Software (I) Pvt. Ltd., All Rights Reserved
       **/

      /*
       * Section: 14.17
       *
       * Filename: c1417501.java
       *
       * Purpose: Positive test for section 14.17, para 5:
       *
       * "Acquiring the lock associated with an object does not
       * itself prevent other threads from accessing fields of
       * the object or invoking unsynchronised methods on the
       * object.Other threads can use the synchronised method
       * or the synchronized statement in a conventional manner
       * to achieve mutual exclusion."
       *
       * Language Specification: October, 1996
       */

      //import cpack.Chk;

      class X extends Thread{
         static volatile int i;
         X(String s) { super(s);}
         
         public void run()
          {
           if(this.getName().equals("X2"))
           check_Access();
           else
            {
             yield();
             synchronized(this)
              {
      while(true)
      {
      if( i==3) break;
      }
      }
            }
          }
          
          static void check_Access()
           {
             for(int j=0;j <1000;j++) {}
             i = 3; // Accessing fields of a synchronized object
           }
             
          static void check_synchronized() throws Throwable
           {
             Thread t1 = new X("X1");
             Thread t2 = new X("X2");
             
             t1.start();
             sleep(100);
             t2.start();
             
             t1.join();
             t2.join();
             t1.stop();
             t2.stop();
            }
            
          public static void main(String[] arg) throws Throwable
           {
             check_synchronized();
      System.out.println(i==3);
             //Chk.chkIntVal("err_1", "i", i, 3);
             
             //Chk.endTest("c1417501");
           }
      }
             

      allan.jacobs@Eng 1997-02-27
      The test is flawed. The yield statement should be inside the loop.
      Please close this bug.

        Attachments

          Activity

            People

            • Assignee:
              tlindholsunw Timothy Lindholm (Inactive)
              Reporter:
              ajacobssunw Allan Jacobs (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: