RFR: 8342540: InterfaceCalls micro-benchmark gives misleading results [v2]

Aleksey Shipilev shade at openjdk.org
Mon Oct 21 13:18:33 UTC 2024


On Mon, 21 Oct 2024 11:16:51 GMT, Andrew Haley <aph at openjdk.org> wrote:

> I don't think we assume it: the analysis is in Marsaglia's _Xorshift RNGs_ paper. The full period (except 0) is proven there.

Yeah, all right. Seeing is believing, and indeed the distributions look okay:


public class XorShiftHisto {

    static int l;

    static int step(int range) {
        l = scramble(l);
        return (l & Integer.MAX_VALUE) % range;
    }

    static int scramble(int n) {
        int x = n;
        x ^= x << 13;
        x ^= x >>> 17;
        x ^= x << 5;
        return x == 0 ? 1 : x;
    }

    public static void main(String... args) {
        for (int range = 1; range <= 10; range++) {
            l = 0;
            int[] histo = new int[range];
            for (int c = 0; c < 1000000; c++) {
                histo[step(range)]++;
            }
            System.out.println("Histo " + range + ": " + Arrays.toString(histo));
        }
    }
}

$ java XorShiftHisto.java
Histo 1: [1000000]
Histo 2: [500093, 499907]
Histo 3: [333036, 333888, 333076]
Histo 4: [250116, 249824, 249977, 250083]
Histo 5: [200577, 199994, 199940, 199945, 199544]
Histo 6: [166273, 166493, 166425, 166763, 167395, 166651]
Histo 7: [142746, 142358, 142815, 143556, 143004, 142908, 142613]
Histo 8: [124841, 124510, 125431, 124673, 125275, 125314, 124546, 125410]
Histo 9: [110846, 111088, 110885, 110834, 111145, 111201, 111356, 111655, 110990]
Histo 10: [100197, 100061, 99901, 99953, 100070, 100380, 99933, 100039, 99992, 99474]

-------------

PR Comment: https://git.openjdk.org/jdk/pull/21581#issuecomment-2426651581


More information about the hotspot-compiler-dev mailing list