Re.: CHA ignores default methods during analysis leading to incorrect code generation

Yann Le Tallec ylt at letallec.org
Fri Feb 28 12:27:40 PST 2014


Original message:
http://mail.openjdk.java.net/pipermail/hotspot-dev/2014-January/012252.html

The test (DefaultAndConcreteMethodsCHA.java) passes as expected on b129.

However a post on Stackoverflow reports a very similar bug that can still
be reproduced on b129: http://stackoverflow.com/q/22096052/829571

Code copied below for reference - I get the erroneous output for i ~ 260,
i.e. after approximately 25 seconds.

Yann

public class IsolatedBug {
    static int i = 0;
    private final Box box;

    private final List<Drawable> drawables;

    public IsolatedBug() {
        this.box = new Box();
        this.drawables = new ArrayList<>();

        drawables.add(box);
        drawables.forEach(drawable -> System.out.println(++i + " " +
drawable + " C=" + drawable.isShadowCaster() + "/R=" +
drawable.isShadowReceiver()));
    }

    private void init() throws InterruptedException {
        while (true) {
            drawables.forEach(drawable -> System.out.println(++i + " " +
drawable + " C=" + drawable.isShadowCaster() + "/R=" +
drawable.isShadowReceiver()));
            Thread.sleep(100);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        new IsolatedBug().init();
    }
}

abstract class Drawable implements DrawableInterface {}

interface DrawableInterface {
    default public boolean isShadowReceiver() { return false; }
    default public boolean isShadowCaster() { return false; }
}

interface ShadowDrawable extends DrawableInterface {
    @Override default public boolean isShadowReceiver() { return true; }
    @Override default public boolean isShadowCaster() { return true; }
}

class Box extends Drawable implements ShadowDrawable {}


More information about the hotspot-dev mailing list