News for hackers. Stuff that matters.
Re:Updating the Go Memory Model by uluyol on Monday July 12, 2021 @10:06PM (#27817026)
Is Java really memory safe in the face of races? The case I'm thinking about is this:

Shared state:

ArrayList A with intial buffer B and length L

Thread 1:

Grows A and replaces B with buffer C, length with M

Thread 2:

(Earlier loaded B into a register)

Code says write to A[M-1]. JVM checks M-1 against M but uses B as it was already stored in a register. Now you have a buffer overflow.

Except, people on this thread seem to think this is impossible. How does Java prevent this?

Re:Updating the Go Memory Model by lmm on Monday July 12, 2021 @10:30PM (#27817126)
The buffer itself, being a Java array, is checked. You'll get an exception but you won't get undefined behaviour.
Re:Updating the Go Memory Model by uluyol on Tuesday July 13, 2021 @08:04AM (#27819925)
Of course. That makes sense. Thanks!