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

JLS has a bug in the chapter of Java Memory Model.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 13.0.2
    • specification
    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      The effect of the interruption in the context of the memory model is incorrectly described in the JLS Ch17.
      We cannot confidently guess what is actually true.

      First, 17.4.2 has a list that defines synchronization actions, but this does not contain interruptions and its observations. Later, 17.4.4 states that these actions can have synchronize-with relations. If these are not synchronization actions but still be able to have sw relations, it is a bit strange because 17.4.4 also says synchronize-with relations are induced by synchronization actions. (But I cannot conclude that it is a contradiction, because there is no 'all the' before the word 'synchronize-with relation', technically.)
      Second, there is a crucial misstatement. The last of the list in 17.4.4 says that [[an interruption synchronizes-with "any" point where any other thread determines that it has been interrupted]]. Any!? If ever so, as you can easily imagine, happens-before relation couldn't be an order any more. Would have loops. If ever doubtful, see the example code below. I imagine that the correct statement would be "an interruption happens before the SUBSEQUENT (
      </div>
      </div>
      <br /> <br /> <br /> <br /> <br /> <br />
      <div class="form-group">
      <label for="system_os_info" class="col-sm-2 control-label">System
      / OS / Java Runtime Information </label>
      <div class="col-sm-8">

      <textarea id="system_os_info" name="system_os_info" style="resize: none;" placeholder="Additional system configuration information here." class="form-control" rows="4">



      ---------- BEGIN SOURCE ----------
      //thread0 can do whatever. just keep living.
      Thread thread0 = new Thread(()->{while(true);});
      thread0.setDaemon(true);
      thread0.start();

      //interruption[A]
      thread0.interrupt();

      //no doubt I can observe thread0's interrupted state.
      if (thread0.isInterrupted()) {
      //the printing.
      System.out.println("""
      after reading JLS 17.4.4 carefully, we cannot avoid the stupid conclusion
      that interruption[B] (coded below) happens-before this printing action.
      """);
      }

      //thread1 starts.
      new Thread(()->{
      //interruption[B], which obviously is happened-before by the printing.
      thread0.interrupt();
      }).start();
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: