Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native-image leads to wrong execution / code #2011

Closed
ptrd opened this issue Dec 20, 2019 · 6 comments
Closed

native-image leads to wrong execution / code #2011

ptrd opened this issue Dec 20, 2019 · 6 comments
Assignees

Comments

@ptrd
Copy link

ptrd commented Dec 20, 2019

Given this simple sample

package sample;

public class Simple {

    public static void main(String[] args) {
        byte ca = (byte) 0xca;
        System.out.println("Result: " + checkType(ca));
    }

    static boolean checkType(byte type) {
        byte masked = (byte) (type & 0xf0);
        boolean result = (masked == (byte) 0xc0);
        return result;
    }
}

When compiled and run with java, it returns true (which it obviously should).

When compiled with native-image however, it returns false.

GraalVM Version 19.3.0 CE
MacOS Catalina 10.15.2
Using -H:Optimize=0 doesn't make any difference.

@olpaw
Copy link
Member

olpaw commented Dec 20, 2019

@dougxc this looks like a compiler bug. If I run checkType in a hot loop if get to the point where it returns false. On Stock JDK I do not ever get to that point.

@olpaw
Copy link
Member

olpaw commented Dec 20, 2019

public class Simple {

    public static void main(String[] args) {
        byte ca = (byte) 0xca;
        int x = 0;
        while(x++ < 2 << 20) {
            boolean res = checkType(ca);
            assert res : "Fails after " + x + " iterations.";
            System.out.print(res ? "X" : "x");
        }
    }

    static boolean checkType(byte type) {
        byte masked = (byte) (type & 0xf0);
        boolean result = (masked == (byte) 0xc0);
        return result;
    }

}

Passes java -ea Simple with stock JDK but not when run on GraalVM 19.3.0.

@olpaw
Copy link
Member

olpaw commented Dec 20, 2019

@ptrd thanks a lot for this bug report!

@ptrd
Copy link
Author

ptrd commented Dec 20, 2019

You're welcome. Can't wait to experiment with kwik.tech compiled to native....

@dougxc
Copy link
Member

dougxc commented Dec 20, 2019

Hi @ptrd , thanks for reporting. This is related to #1995 and is fixed in master (276ff2b). It will be in GraalVM CE 19.3.1.

@dougxc dougxc closed this as completed Dec 20, 2019
@ptrd
Copy link
Author

ptrd commented Dec 20, 2019

Ok, cool. Made a note in my agenda for Jan 14. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants