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

TEST_BUG: Race conditions in PingPong.java

    Details

    • Subcomponent:
    • Resolved In Build:
      tiger
    • CPU:
      x86
    • OS:
      solaris_10
    • Verification:
      Verified

      Description



      Name: vsR10238 Date: 09/03/2003


      Filed By : J2SE-SQA [###@###.###
      JDK : JDK1.5.0
      Testbase : Regression-cte
      Platform[s] : Solaris 10 (x86) (CDE)
      Falling test[s]:
               CTE_REGTEST/Generic/4514097/PingPong.java

      Regression-CTE test CTE_REGTEST/Generic/4514097/PingPong.java from the test suite for JDK1.5.0
      fails with JDK1.5.0, JDK1.4.2 due to races in the test.

      Below is an excerpt from the PingPong.main method (PingPong.java):

                   PingPong[] rest = new PingPong[count];
                   for (int i = 0; i < count; i++)
                   {
                       rest[i] = new PingPong("" + i, 0);
                   }

                   System.out.println(" Main sleeping for 1 second..");

                   try {
                                     sleep(1000);
                   }
                   catch (InterruptedException e)
                   {
                   }
                   for (int i = 0; i < count; i++)
                   {
                       rest[i].start();
                   }
                    PingPong one = new PingPong("FirstOne", 0); // Code modified so that it can notify all waiting threads..
                   one.start();

      There is no delay between starting the waiting threads and the notifying one.
      It seems like sleep(1000) was placed a little bit higher than was intended. It should be placed
      after the loop with rest[i].start.

      As a result the PingPong thread named "one" notified the "rest" threads before they had even started,
      which caused the failure and the following output in test.out from the test and the JVM profiler:

      ------------------------------------------------------------------
        Main sleeping for 1 second..
      Sleeping for 1 Second ....

      Notifying all ....

      FirstOne
      It is not "FirstOne" ... Hence waiting on Integer ...

      It is not "FirstOne" ... Hence waiting on Integer ...

      It is not "FirstOne" ... Hence waiting on Integer ...

      Event ID : 80fbdb8: THREAD_START: Thread Name: Finalizer
      Event ID : 80fb3a8: THREAD_START: Thread Name: Reference Handler
      Event ID : 806b0a8: THREAD_START: Thread Name: main
      Event ID : 81044b0: THREAD_START: Thread Name: Signal Dispatcher
      Event ID : 811d120: THREAD_START: Thread Name: Thread-3
      Event ID : 811c6e0: THREAD_START: Thread Name: Thread-2
      Event ID : 811bca0: THREAD_START: Thread Name: Thread-1
      Event ID : 811bb08: THREAD_START: Thread Name: Thread-0
      Event ID : 811bb08: MONITOR_WAIT: Object : d041dd30, Timeout : 0
      Event ID : 811bca0: MONITOR_WAIT: Object : d041dd30, Timeout : 0
      Event ID : 811c6e0: MONITOR_WAIT: Object : d041dd30, Timeout : 0

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

      After I modified the code as follows the test passed.

                   for (int i = 0; i < count; i++)
                   {
                       rest[i].start();
                   }

                   System.out.println(" Main sleeping for 1 second..");

                   try {
                                     sleep(1000);
                   }
                   catch (InterruptedException e)
                   {
                   }


                    PingPong one = new PingPong("FirstOne", 0); // Code modified so that it can notify all waiting threads..
                   one.start();


      It is not so easy to reproduce the failure.
      For example, the test stable fails only on our Solaris 10 (x86) computer
      when I run it using JavaTest on its display.
      But the test always passes when I run it via rsh on the same computer.


      Test source location:
      =====================
      /net/jdk/export/jpse04/Regression/1.5.0/test/CTE_REGTEST/Generic/4514097/PingPong.java

      jtr file location:
      ==================
      /net/jtgb4u4c.sfbay/export/sail15/results.2/tiger/b17/regtest/x86/sol10_x86_gnome_linux-18/workDir/cte/CTE_REGTEST/Generic/4514097/PingPong.jtr

      How to reproduce:
      =================
      Run the following script (you may need to change its variables)

      --- script start ---
      #!/bin/sh
      RESULT_DIR=`pwd`
      WORK_DIR=$RESULT_DIR/workDir/test
      REPORT_DIR=$RESULT_DIR/reportDir
      JT_HOME="/net/linux-15/export/home/java/jct"
      JAVA_HOME="/net/linux-15/export/home/java/jdk1.5.0/x86"
      TEST_BASE_PATH="/net/linux-15/export/home/java/regtest.tiger/cte"
      TESTVMOPTS="-client"
      CLASSPATH="$JT_HOME/classes:$JT_HOME/lib/javatest.jar:$JT_HOME/lib/jtreg.jar"

      TEST="CTE_REGTEST/Generic/4514097/PingPong.java"

      mkdir -p $WORK_DIR/scratch 2>&1
      mkdir -p $WORK_DIR/jtData 2>&1
      mkdir -p $REPORT_DIR 2>&1

      #rm $WORK_DIR/jtData/ResultCache.jtw 2>&1

      cd $WORK_DIR/scratch

      $JAVA_HOME/bin/java -server -cp $CLASSPATH -DenvVars=TESTJAVAHOME=$JAVA_HOME,TESTVMOPTS=$TESTVMOPTS,DISPLAY=:0,HOME=$HOME/.regtest,PATH=/bin:/usr/bin,CPAPPEND=$JT_HOME/jemmy/jemmy.jar,TZ=,LC_ALL=en_US,LC_CTYPE=en_US,LANG=en_US,LPDEST= -DDISPLAY=:0 -DlocalHost="linux-18" -Dprogram=jtreg com.sun.javatest.regtest.Main -a -v default -batch -params -w "$WORK_DIR" -r "$REPORT_DIR" -t "$TEST_BASE_PATH" "$TEST_BASE_PATH/$TEST"

      --- script end ---

      Script output:
      ==============

      Test output (jtr part):
      =======================
      ----------System.out:(5/129)----------
        inflated: i386-libdev1.so
        inflated: Linux-libdev1.so
        inflated: sparc-libdev1.so
        inflated: dev1.dll
      Invalid output, check it.
      ----------System.err:(1/35)----------
      java full version "1.5.0-beta-b17"
      result: Failed. Execution failed: exit code 1


      test result: Failed. Execution failed: exit code 1


      Specific machine info:
      ======================
      Hostname: linux-18
      OS: Solaris 10 (x86) (CDE)



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

        Attachments

          Activity

            People

            • Assignee:
              asaha Abhijit Saha
              Reporter:
              vshsunw Vsh Vsh (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: