program order: hard to understand definition

Discussion in 'Java' started by pvbemmel-at-xs4all-nl, Nov 29, 2010.

  1. I find it hard to match my intuition of program order, as being
    the order given by lines in the source code,
    to definition of "program order" in the Java Language Specification.
    The definition given by wikipedia, seems much clearer.
    Both are reproduced below.

    Why is the JLS definition so hard to understand?

    Can anybody explain?

    Paul van Bemmelen.

    The Java Language Specification, Third Edition, section 17.4.3 "Programs
    and Program Order" , states:
    ----------------------------------------------
    Among all the inter-thread actions performed by each thread t, the
    program order of t is a total order that reflects the order in which
    these actions would be performed according to the intra-thread semantics
    of t.
    ----------------------------------------------

    The introduction to section 17.4 "Memory Model" , states about
    "intra-thread semantics" :
    ----------------------------------------------
    The memory model determines what values can be read at every point in
    the program. The actions of each thread in isolation must behave as
    governed by the semantics of that thread, with the exception that the
    values seen by each read are determined by the memory model. When we
    refer to this, we say that the program obeys intra-thread semantics.
    Intra-thread semantics are the semantics for single threaded programs,
    and allow the complete prediction of the behavior of a thread based on
    the values seen by read actions within the thread.
    ----------------------------------------------

    In www.wikipedia.org , the entry for "java memory model" states
    -----------------------------------------------
    For execution of a single thread, the rules are simple. The Java
    Language Specification requires a Java Virtual Machine to observe
    within-thread as-if-serial semantics. The runtime (which, in this case,
    usually refers to the dynamic compiler, the processor and the memory
    subsystem) is free to introduce any useful execution optimizations as
    long as the result of the thread in isolation is guaranteed to be
    exactly the same it would have been had all the statements been executed
    in the order the statements occurred in the program (also called program
    order).
    -----------------------------------------------
    pvbemmel-at-xs4all-nl, Nov 29, 2010
    #1
    1. Advertising

  2. pvbemmel-at-xs4all-nl

    Arne Vajhøj Guest

    On 29-11-2010 15:34, pvbemmel-at-xs4all-nl wrote:
    > I find it hard to match my intuition of program order, as being
    > the order given by lines in the source code,
    > to definition of "program order" in the Java Language Specification.
    > The definition given by wikipedia, seems much clearer.
    > Both are reproduced below.
    >
    > Why is the JLS definition so hard to understand?
    >
    > Can anybody explain?


    Language specifications are written by language
    specialists for language specialist.

    Wikipedia is written by ordinary users for
    ordinary users.

    Different context => different result.

    And it is not really IT specific.

    Imagine two engine engineers from Ford and GM discussing
    fuel injection and an ordinary car owner listening to
    the discussion.

    Arne
    Arne Vajhøj, Nov 30, 2010
    #2
    1. Advertising

  3. On 11/29/2010 03:34 PM, pvbemmel-at-xs4all-nl wrote:
    > Why is the JLS definition so hard to understand?


    Specifications, by their nature, have to be a lot more precise than
    general overviews. I would note that I don't find it hard to understand,
    then again, I use language specifications as my refresher on basic
    syntax questions, so...

    > Among all the inter-thread actions performed by each thread t, the
    > program order of t is a total order that reflects the order in which
    > these actions would be performed according to the intra-thread semantics
    > of t.


    Basically, this means that the program order is a valid ordering that
    obeys all of the law of §17--in other words, this is the ordering that
    is actually done by the program at runtime.

    I would also like to take the time to point out that the memory model
    only stipulates a partial ordering that must be performed, so there is
    some scope for program orders to be different.

    > The introduction to section 17.4 "Memory Model" , states about
    > "intra-thread semantics" :


    The memory model is perhaps the most complicated part of the JLS, even
    more so than, say, generics type inference during method invocation
    (which is imposing, to say the least). You won't get much out of it if
    you just read snippets of text; you have to carefully read it in its
    entirety to digest it.

    The memory model is pretty much about one thing:
    "The memory model determines what values can be read at every point in
    the program." (§17.4, ¶3)

    If you're not interested in interthread memory consistency semantics,
    this section of the JLS is completely useless for you. What you would
    rather want is execution order, defined in §15.

    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
    Joshua Cranmer, Nov 30, 2010
    #3
  4. pvbemmel-at-xs4all-nl

    Eric Sosman Guest

    On 11/29/2010 3:34 PM, pvbemmel-at-xs4all-nl wrote:
    >
    > I find it hard to match my intuition of program order, as being
    > the order given by lines in the source code,
    > to definition of "program order" in the Java Language Specification.
    > The definition given by wikipedia, seems much clearer.
    > Both are reproduced below.
    >
    > Why is the JLS definition so hard to understand?
    >
    > Can anybody explain?


    The JLS does not have the freedom to indulge in imprecise phrases
    like "as-if-serial semantics." You'll note that Wikipedia does not
    even attempt to define what it means by "as-if-serial," but that the
    JLS language tries to nail down precisely what it means.

    Challenge: Define "sweet" without using words that appeal to the
    reader's pre-existing notions of sweetness: Define it without saying
    "sugar" or "honey" or "molasses" or any such, just define it from the
    ground up. Then pour it on your pancakes and see how it tastes. ;-)

    --
    Eric Sosman
    lid
    Eric Sosman, Nov 30, 2010
    #4
  5. On 11/29/2010 09:28 PM, Eric Sosman wrote:
    > Challenge: Define "sweet" without using words that appeal to the
    > reader's pre-existing notions of sweetness: Define it without saying
    > "sugar" or "honey" or "molasses" or any such, just define it from the
    > ground up. Then pour it on your pancakes and see how it tastes. ;-)


    A substance is "sweet" if it contains, in relatively large amounts, a
    set of chemicals whose stereochemistry places certain functional groups
    in specific relevant positions that allow chemical conformational
    changes in specialized receptors on the human tongue, specifically those
    found most predominantly in the forward portion of the tongue. Examples
    of chemicals which activate these receptors include
    (2R,3R,4S,5S,6R)-2-[(2S,3S,4S,5R)-3,4-dihydroxy-2,5-bis(hydroxymethyl)oxolan-2-yl]oxy-6-(hydroxymethyl)oxane-3,4,5-triol,
    N-(L-α-Aspartyl)-L-phenylalanine, 1,1-Dioxo-1,2-benzothiazol-3-one, and
    (2R,3S,4R,5R)-2,3,5,4,6-Pentahydroxyhexanal.

    And no, do not ask me to diagram those molecules.
    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
    Joshua Cranmer, Nov 30, 2010
    #5
  6. On 11/29/2010 10:46 PM, Joshua Cranmer wrote:
    > (2R,3S,4R,5R)-2,3,5,4,6-Pentahydroxyhexanal.


    My bad. In my haste to respond, I neglected to remember that this is
    actually not the stereochemical form detected. The aldehyde would
    actually tautomerize into a cyclic hemiacetal for this. I leave the ways
    in which this happens as an exercise for the reader.

    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
    Joshua Cranmer, Nov 30, 2010
    #6
  7. pvbemmel-at-xs4all-nl

    Eric Sosman Guest

    On 11/29/2010 10:46 PM, Joshua Cranmer wrote:
    > On 11/29/2010 09:28 PM, Eric Sosman wrote:
    >> Challenge: Define "sweet" without using words that appeal to the
    >> reader's pre-existing notions of sweetness: Define it without saying
    >> "sugar" or "honey" or "molasses" or any such, just define it from the
    >> ground up. Then pour it on your pancakes and see how it tastes. ;-)

    >
    > A substance is "sweet" if it contains, in relatively large amounts, a
    > set of chemicals whose stereochemistry places certain functional groups
    > in specific relevant positions that allow chemical conformational
    > changes in specialized receptors on the human tongue, specifically those
    > found most predominantly in the forward portion of the tongue. Examples
    > of chemicals which activate these receptors include
    > (2R,3R,4S,5S,6R)-2-[(2S,3S,4S,5R)-3,4-dihydroxy-2,5-bis(hydroxymethyl)oxolan-2-yl]oxy-6-(hydroxymethyl)oxane-3,4,5-triol,
    > N-(L-α-Aspartyl)-L-phenylalanine, 1,1-Dioxo-1,2-benzothiazol-3-one, and
    > (2R,3S,4R,5R)-2,3,5,4,6-Pentahydroxyhexanal.


    You forgot the part about pouring it on your pancakes ...

    "Unnngggh! Urrrrggh! Honey, can you hand me the pliers? The lid
    on this jar of N-(L-α-Aspartyl)-L-phenylalanine is stuck solid."

    --
    Eric Sosman
    lid
    Eric Sosman, Nov 30, 2010
    #7
  8. pvbemmel-at-xs4all-nl

    Tom Anderson Guest

    On Mon, 29 Nov 2010, Eric Sosman wrote:

    > On 11/29/2010 3:34 PM, pvbemmel-at-xs4all-nl wrote:
    >>
    >> I find it hard to match my intuition of program order, as being the
    >> order given by lines in the source code, to definition of "program
    >> order" in the Java Language Specification. The definition given by
    >> wikipedia, seems much clearer. Both are reproduced below.
    >>
    >> Why is the JLS definition so hard to understand?
    >>
    >> Can anybody explain?

    >
    > The JLS does not have the freedom to indulge in imprecise phrases
    > like "as-if-serial semantics." You'll note that Wikipedia does not
    > even attempt to define what it means by "as-if-serial," but that the
    > JLS language tries to nail down precisely what it means.
    >
    > Challenge: Define "sweet" without using words that appeal to the
    > reader's pre-existing notions of sweetness: Define it without saying
    > "sugar" or "honey" or "molasses" or any such, just define it from the
    > ground up. Then pour it on your pancakes and see how it tastes. ;-)


    That's not fair. Sweet is a quale - it can't be described without
    reference to subjective experience. Not even by the JLS authors.

    tom

    --
    Understand the world we're living in
    Tom Anderson, Nov 30, 2010
    #8
  9. On 30-11-2010 2:41, Joshua Cranmer wrote:
    > On 11/29/2010 03:34 PM, pvbemmel-at-xs4all-nl wrote:
    >> Why is the JLS definition so hard to understand?

    >
    > Specifications, by their nature, have to be a lot more precise than
    > general overviews. I would note that I don't find it hard to understand,
    > then again, I use language specifications as my refresher on basic
    > syntax questions, so...
    >
    >> Among all the inter-thread actions performed by each thread t, the
    >> program order of t is a total order that reflects the order in which
    >> these actions would be performed according to the intra-thread semantics
    >> of t.

    >
    > Basically, this means that the program order is a valid ordering that
    > obeys all of the law of §17--in other words, this is the ordering that
    > is actually done by the program at runtime.
    >
    > I would also like to take the time to point out that the memory model
    > only stipulates a partial ordering that must be performed, so there is
    > some scope for program orders to be different.
    >
    >> The introduction to section 17.4 "Memory Model" , states about
    >> "intra-thread semantics" :

    >
    > The memory model is perhaps the most complicated part of the JLS, even
    > more so than, say, generics type inference during method invocation
    > (which is imposing, to say the least). You won't get much out of it if
    > you just read snippets of text; you have to carefully read it in its
    > entirety to digest it.
    >
    > The memory model is pretty much about one thing:
    > "The memory model determines what values can be read at every point in
    > the program." (§17.4, ¶3)
    >
    > If you're not interested in interthread memory consistency semantics,
    > this section of the JLS is completely useless for you. What you would
    > rather want is execution order, defined in §15.
    >


    I AM interested in interthread memory consistency semantics.
    And I DO appreciate a precise definition.

    I don't find the line
    >> program order of t is a total order that reflects the order in which

    very precise: what is meant by "reflects" ?

    Also, the line

    >The actions of each thread in isolation must behave as governed by the
    >semantics of that thread, with the exception that the values seen by
    >each read are determined by the memory model.


    is like a forward reference: in the process of defining the behaviour of
    a thread, you refer to the "semantics of that thread". And even
    stranger, it says that there is an exception to those semantics.
    Surely, with "the semantics of that thread", something specific is
    meant, but what can that be?

    Paul van Bemmelen.
    pvbemmel-at-xs4all-nl, Nov 30, 2010
    #9
  10. On 11/30/2010 09:03 AM, pvbemmel-at-xs4all-nl wrote:
    > I don't find the line
    > >> program order of t is a total order that reflects the order in which

    > very precise: what is meant by "reflects" ?


    Think of it as saying that the two are isomorphic.

    > Also, the line
    >
    > >The actions of each thread in isolation must behave as governed by the
    > >semantics of that thread, with the exception that the values seen by
    > >each read are determined by the memory model.

    >
    > is like a forward reference: in the process of defining the behaviour of
    > a thread, you refer to the "semantics of that thread". And even
    > stranger, it says that there is an exception to those semantics.
    > Surely, with "the semantics of that thread", something specific is
    > meant, but what can that be?


    You have to read the entire section carefully, but it clearly states
    that, in the absence of multiple threads, the semantics of a single
    thread follow the execution order for that thread, which is a specific
    order given in a subsection of §15, §15.4 I believe.


    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
    Joshua Cranmer, Nov 30, 2010
    #10
  11. pvbemmel-at-xs4all-nl

    Roedy Green Guest

    On Mon, 29 Nov 2010 21:34:28 +0100, pvbemmel-at-xs4all-nl
    <> wrote, quoted or indirectly quoted someone who
    said :

    >Why is the JLS definition so hard to understand?


    the JLS is aimed at compiler writers. It is a lawyerly document about
    corner cases. To learn the language you need a text book crammed full
    of examples. Even a free out-of-date book will do. You can then learn
    the latest stuff online.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    If you give your kitchen floor a quick steam mop every few days, you will find you never have to get out buckets and brushes for deep cleaning. Similary, if you keep your code tidy, refactoring as you go, you probably won't need major rewrites.
    Roedy Green, Nov 30, 2010
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. torhu
    Replies:
    5
    Views:
    356
  2. Jianli Shen
    Replies:
    1
    Views:
    587
    Victor Bazarov
    Mar 13, 2005
  3. TheSaint

    Hard to understand 'eval'

    TheSaint, Jun 14, 2008, in forum: Python
    Replies:
    10
    Views:
    453
    Bruno Desthuilliers
    Jun 16, 2008
  4. fl
    Replies:
    4
    Views:
    507
  5. Xiaoshen Li
    Replies:
    32
    Views:
    320
    John W. Kennedy
    Nov 12, 2005
Loading...

Share This Page