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

DOC*: JS: step debug in&out synchronized method, deadlocks

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.6
    • core-svc
    • x86
    • windows_nt



      Name: mf23781 Date: 08/24/98


      *Test case:

      J17_13a_MyThread.java
      =========================

      class J17_13a_MyThread extends Thread {
        J17_13a_SharedResource r;



        public J17_13a_MyThread(J17_13a_SharedResource r) {this.r = r;}

        public void run() { //LOC:TC0003.01
      for (int i=0; i<3; i++) {
      try {
      r.Increment(); //LOC:TC0002.01
      Thread.sleep(100);
      }
      catch (InterruptedException e) {}
      }
        }

      }


      J17_13a_SharedResource.java
      =============================


      class J17_13a_SharedResource {
        private int x=0; //observe the value of x;



      //it should be changing 1..2..3
        
        public synchronized void Increment () {
      x++;
      System.out.println(x);
        }

      }


      J17_13a_ThreadsAndLocks.java
      =============================


      //Author: Henry Chiu
      //Date: 19980219
      //17.13
      //The synchronized statement (§14.17) computes
      //a reference to an object; it then attempts to
      //perform a lock action on that object and does
      //not proceed further until the lock action has successfully
      // completed. (A lock action may be delayed because
      //the rules about locks can prevent the main memory
      //from participating until some other thread is ready
      //to perform one or more unlock actions.) After the lock
      //action has been performed, the body of the synchronized
      //statement is executed. If execution of the body is ever
      //completed, either normally or abruptly, an unlock action
      //is automatically performed on that same lock.
      //A synchronized method (§8.4.3.5) automatically
      //performs a lock action when it is invoked; its body
      //is not executed until the lock action has successfully
      //completed. If the method is an instance method, it locks
      //the lock associated with the instance for which it was
      //invoked (that is, the object that will be known as this
      //during execution of the body of the method).
      //Cross Reference: 17.2, 17.5


      public class J17_13a_ThreadsAndLocks
      {
        public int x;

        public static void main(String args[]) {
      J17_13a_SharedResource r = new J17_13a_SharedResource();
      Thread t1 = new J17_13a_MyThread(r);
      Thread t2 = new J17_13a_MyThread(r);
      t1.start();
      t2.start();
        }

      }


      *Steps to reproduce the defect:

      jdb J17_13a_ThreadsAndLocks
      stop at J17_13a_SharedResource:10
      run
      run
      thread 2 (to switch to the thread that is suspended)
      next




      *Outputs:

      1.1.6
      ===========

      P:\defects\6433>jdb J17_13a_ThreadsAndLocks
      Initializing jdb...
      Warning: JIT compiler "symcjit" not found. Will use interpreter.
      Warning: JIT compiler "symcjit" not found. Will use interpreter.
      0xf8fa20:class(J17_13a_ThreadsAndLocks)
      > stop at J17_13a_SharedResource:10
      Breakpoint set at J17_13a_SharedResource:10
      > run
      run J17_13a_ThreadsAndLocks
      running ...
      main[1]
      Breakpoint hit: J17_13a_SharedResource.Increment (J17_13a_SharedResource:10)
      Thread-96[1] run
      run J17_13a_ThreadsAndLocks
      running ...
      main[1]
      Breakpoint hit: J17_13a_SharedResource.Increment (J17_13a_SharedResource:10)
      Thread-99[1] thread 2
      Thread-100[1] next
      Thread-100[1]
      Fatal exception: java.net.SocketException: Connection reset by peer
      java.net.SocketException: Connection reset by peer
              at java.net.SocketInputStream.read(Compiled Code)
              at java.io.BufferedInputStream.fill(Compiled Code)
              at java.io.BufferedInputStream.read(Compiled Code)
              at java.io.FilterInputStream.read(FilterInputStream.java:81)
              at sun.tools.debug.AgentIn.run(Compiled Code)
              at java.lang.Thread.run(Thread.java:474)

      J17_13a_ThreadsAndLocks exited


      1.1.7H
      =========


      P:\defects\6433>jdb J17_13a_ThreadsAndLocks
      Initializing jdb...
      0xf8ff78:class(J17_13a_ThreadsAndLocks)
      > stop at J17_13a_SharedResource:10
      Breakpoint set at J17_13a_SharedResource:10
      > run
      run J17_13a_ThreadsAndLocks
      running ...
      main[1]
      Breakpoint hit: J17_13a_SharedResource.Increment (J17_13a_SharedResource:10)
      Thread-95[1] run
      run J17_13a_ThreadsAndLocks
      running ...
      main[1]
      Breakpoint hit: J17_13a_SharedResource.Increment (J17_13a_SharedResource:10)
      Thread-98[1] thread 2
      Thread-99[1] next
      Thread-99[1]
      Fatal exception: java.net.SocketException: Connection reset by peer
      java.net.SocketException: Connection reset by peer
              at java.net.SocketInputStream.read(Compiled Code)
              at java.io.BufferedInputStream.fill(Compiled Code)
              at java.io.BufferedInputStream.read(Compiled Code)
              at java.io.FilterInputStream.read(FilterInputStream.java:73)
              at sun.tools.debug.AgentIn.run(Compiled Code)
              at java.lang.Thread.run(Thread.java:466)

      J17_13a_ThreadsAndLocks exited


      1.2fcs-E(First run)
      ===================

      P:\defects\6433>jdb J17_13a_ThreadsAndLocks
      Initializing jdb...
      0xa9:class(J17_13a_ThreadsAndLocks)
      > stop at J17_13a_SharedResource:10
      Breakpoint set at J17_13a_SharedResource:10
      > run
      run J17_13a_ThreadsAndLocks
      running ...
      Thread-0[1]
      Breakpoint hit: J17_13a_SharedResource.Increment (J17_13a_SharedResource:10)
      Thread-0[1] run
      run J17_13a_ThreadsAndLocks
      running ...
      main[1]
      Current thread "main" died. Execution continuing...
      >
      Breakpoint hit: J17_13a_SharedResource.Increment (J17_13a_SharedResource:10)
      Thread-3[1] thread 2
      Thread-4[1] next
      java.lang.InternalError: JVMDI_ERROR_NO_MORE_FRAMESThread-4[1]
              at sun.tools.agent.StackFrame.frameCount(Native Method)
              at sun.tools.agent.StackFrame.getStackFrames(StackFrame.java:47)
              at sun.tools.agent.StepHandler.getCurrentStackTrace(StepHandler.java:407)
              at sun.tools.agent.StepHandler.stepLine(StepHandler.java:731)
              at sun.tools.agent.StepHandler.run(StepHandler.java:156)


      1.2fcs-E(Second run)
      ====================

      P:\defects\6433>jdb J17_13a_ThreadsAndLocks
      Initializing jdb...
      0xa9:class(J17_13a_ThreadsAndLocks)
      > stop at J17_13a_SharedResource:10
      Breakpoint set at J17_13a_SharedResource:10
      > run
      run J17_13a_ThreadsAndLocks
      running ...
      main[1]
      Current thread "main" died. Execution continuing...
      >
      Breakpoint hit: J17_13a_SharedResource.Increment (J17_13a_SharedResource:10)
      Thread-0[1] run
      run J17_13a_ThreadsAndLocks
      running ...
      main[1]
      Breakpoint hit:
      Fatal exception: java.lang.Exception: java.lang.InternalError: JVMDI_ERROR_INVALID_TH
      READ
      java.lang.Exception: java.lang.InternalError: JVMDI_ERROR_INVALID_THREAD
              at sun.tools.debug.RemoteAgent.getReply(Compiled Code)
              at sun.tools.debug.RemoteAgent.dumpStack(Compiled Code)
              at sun.tools.debug.RemoteThread.getStack(RemoteThread.java:278)
              at sun.tools.debug.RemoteThread.dumpStack(RemoteThread.java:129)
              at sun.tools.ttydebug.TTY.breakpointEvent(TTY.java:80)
              at sun.tools.debug.AgentIn.run(Compiled Code)
              at java.lang.Thread.run(Thread.java:475)

      J17_13a_ThreadsAndLocks exited

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

            Unassigned Unassigned
            miflemi Mick Fleming
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: