Re: Are there real use cases with the Java access modes?

Nathan Reynolds via Concurrency-interest <[email protected]> Mon, 19 Jul 2021 10:55:35 -0600
Newsgroups gmane.comp.java.jsr.166-concurrency
Message-ID <CALMUwcoP1WRG20r6q=7a=eTq+iJFfrtmNXkFa1PTO9873LteSw@mail.gmail.com>
Program Mistake Detector (PMD) is an awesome tool for finding many
mistakes.  It can be easily improved with new rules.  There are other
similar tools out there as well but I am not sure of their capabilities.

Consider this simple case...

private boolean m_quit;   // not volatile

while (!m_quit)
{
   // do some things
}

If the loop body does not modify m_quit, then we can write a PMD rule to
flag this as an unintended infinite loop (i.e. a mistake).  If the while
loop has no method calls, then this simple case can be done with a very
simple PMD rule.  If the while loop calls other methods, then the PMD rule
will need to explore the call tree to see if m_quit is modified.  This will
be more complex to write.

With such a rule in place, when a programmer writes an unintended infinite
loop, then PMD will flag the problem.  The programmer can then fix the
problem and the bug will only exist for a few minutes on the programmer's
machine.

With such a simple solution (e.g. create a PMD rule), I would rather
improve linters to catch programmer's mistakes than make a change to Java
that could hurt performance.

On Mon, Jul 19, 2021 at 8:26 AM Andrew Haley via Concurrency-interest <
[email protected]> wrote:

> On 7/19/21 3:06 PM, Gregg Wonderly via Concurrency-interest wrote:
> > I am specifically against the single optimization I illustrated that
> rewrites code to be non-logically executed, without the user being aware of
> this happening and not being warned that an optimization has potentially
> made the logic of the application not work as expected.
>
> That single optimization is no more than hoisting a memory load. It's
> one of the most common optimizations there is. It probably happens
> many times in every moderately complex method. It's not some kind of
> weird "let's turn this into an infinite loop" optimization.
>
> For every non-volatile field load, in the absence of synchronization
> actions, it is entirely correct and proper to hoist the result of that
> load into a register, or propagate its value some other way. This is
> common in many programming language implementations, and is not going
> to change. It is a very important optimization.
>
> --
> Andrew Haley  (he/him)
> Java Platform Lead Engineer
> Red Hat UK Ltd. <https://www.redhat.com>
> https://keybase.io/andrewhaley
> EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
>
> _______________________________________________
> Concurrency-interest mailing list
> [email protected]
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>

_______________________________________________
Concurrency-interest mailing list
[email protected]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest