A baffling bug...

Andrew Haley aph at redhat.com
Fri Nov 11 18:38:12 UTC 2016

I've been having some problems with my tests, which include one
failure I can't explain.

What happens is that Graal-generated code tries to re-lock an object
which is already locked in this method using a stack slot for the
displaced header which is already in use for the same object.  This
should not be possible if locks are correctly nested.

The code roughly looks like this:

    public final int readUnsignedShort() throws IOException {
        int ch1 = in.read();
        int ch2 = in.read();

where read is():

    public synchronized int read() throws IOException {
        if (pos >= count) {
            if (pos >= count)
                return -1;
        return getBufIfOpen()[pos++] & 0xff;

It's extremely hard to tell exactly what is going on because the
generated code has very convoluted control flow.  However, my guess is
that Graal has tried to coalesce two monitor regions into one but got
it wrong.  (These two monitor regions are for the two synchronized
calls to in.read().)

So, my questions:

Does Graal try to coalesce monitor regions?  If so, is there some way
to turn that off?

Does anyone have any other suggestions?

Or want to look at the generated code?  ;-)


More information about the graal-dev mailing list