hotspot/test/compiler/5091921/Test6890943.java
author duke
Wed, 05 Jul 2017 20:03:14 +0200
changeset 26896 4e78978073f6
parent 25732 e2c1d053a55f
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     1
/*
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
     2
 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     4
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     8
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    13
 * accompanied this code).
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    14
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    18
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    21
 * questions.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    22
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    23
 */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    24
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    25
/**
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    26
 * @test
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    27
 * @bug 6890943
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    28
 * @summary JVM mysteriously gives wrong result on 64-bit 1.6 VMs in hotspot mode.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    29
 *
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    30
 * @run main/othervm/timeout=240 Test6890943
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    31
 */
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    32
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    33
import java.io.*;
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    34
import java.nio.file.Path;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    35
import java.nio.file.Paths;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    36
import java.util.HashMap;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    37
import java.util.Map;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    38
import java.util.Scanner;
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    39
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    40
public class Test6890943 {
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    41
    public static final boolean AIR = true, ROCK = false;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    42
    private static final Path PATH = Paths.get(System.getProperty("test.src", "."));
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    43
    private static final Path INPUT_FILE = PATH.resolve("input6890943.txt");
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    44
    private static final Path GOLDEN_FILE = PATH.resolve("output6890943.txt");
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    45
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    46
    public static void main(String[] args) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    47
        new Test6890943().go();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    48
    }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    49
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    50
    int r, c, f, t;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    51
    boolean[][] grid;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    52
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    53
    public void go() {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    54
        Scanner in, golden;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    55
        try {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    56
            in = new Scanner(new FileInputStream(INPUT_FILE.toFile()));
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    57
            golden = new Scanner(new FileInputStream(GOLDEN_FILE.toFile()));
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    58
        } catch (FileNotFoundException e) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    59
            throw new RuntimeException("TEST failure: can't open test file", e);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    60
        }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    61
        in.useDelimiter("\\s+");
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    62
        golden.useDelimiter("\\s+");
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    63
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    64
        int T = in.nextInt();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    65
        for (t = 0; t < T; t++) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    66
            r = in.nextInt();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    67
            c = in.nextInt();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    68
            f = in.nextInt();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    69
            grid = new boolean[r][c];
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    70
            for (int x = 0; x < r; x++) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    71
                String line = in.next();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    72
                for (int y = 0; y < c; y++) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    73
                    grid[x][y] = line.charAt(y) == '.';
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    74
                }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    75
            }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    76
            int digs = solve();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    77
            String result = "Case #" + (t + 1) + ": " + (digs == -1 ? "No" : "Yes " + digs);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    78
            System.out.println(result);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    79
            // Compare with golden string from the file
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    80
            String goldenStr = golden.nextLine();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    81
            if (!result.equals(goldenStr)) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    82
                System.err.println("FAIL: strings are not equal\n"
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    83
                        + "-- Result: " + result + "\n"
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    84
                        + "-- Golden: " + goldenStr);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    85
                throw new RuntimeException("FAIL: Result string is not equal to the golden");
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    86
            }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    87
        }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    88
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    89
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    90
    Map<Integer, Integer> M = new HashMap<Integer, Integer>();
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    91
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    92
    private int solve() {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    93
        M = new HashMap<Integer, Integer>();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    94
        M.put(calcWalkingRange(0, 0), 0);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    95
        for (int digDown = 0; digDown < r; digDown++) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    96
            Map<Integer, Integer> tries = new HashMap<Integer, Integer>();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    97
            for (Map.Entry<Integer, Integer> m : M.entrySet()) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    98
                int q = m.getKey();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
    99
                if (depth(q) != (digDown)) continue;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   100
                if (stuck(q)) continue;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   101
                tries.put(q, m.getValue());
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   102
            }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   103
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   104
            for (Map.Entry<Integer, Integer> m : tries.entrySet()) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   105
                int q = m.getKey();
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   106
                int fallLeftDelta = 0, fallRightDelta = 0;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   107
                //fall left
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   108
                int fallLeft = fall(digDown, start(q));
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   109
                if (fallLeft > 0) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   110
                    fallLeftDelta = 1;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   111
                    if (fallLeft <= f) addToM(calcWalkingRange(digDown + fallLeft, start(q)), m.getValue());
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   112
                }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   113
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   114
                //fall right
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   115
                int fallRight = fall(digDown, end(q));
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   116
                if (fallRight > 0) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   117
                    fallRightDelta = 1;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   118
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   119
                    if (fallRight <= f) addToM(calcWalkingRange(digDown + fallRight, end(q)), m.getValue());
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   120
                }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   121
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   122
                for (int p = start(q) + fallLeftDelta; p <= end(q) - fallRightDelta; p++) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   123
                    //goLeft
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   124
                    for (int digSpot = p; digSpot > start(q) + fallLeftDelta; digSpot--) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   125
                        int fallDown = 1 + fall(digDown + 1, digSpot);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   126
                        if (fallDown <= f) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   127
                            if (fallDown == 1) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   128
                                addToM(calcWalkingRange(digDown + 1, digSpot, digSpot, p),
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   129
                                        m.getValue() + Math.abs(digSpot - p) + 1);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   130
                            } else {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   131
                                addToM(calcWalkingRange(digDown + fallDown, digSpot),
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   132
                                        m.getValue() + Math.abs(digSpot - p) + 1);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   133
                            }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   134
                        }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   135
                    }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   136
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   137
                    //goRight
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   138
                    for (int digSpot = p; digSpot < end(q) - fallRightDelta; digSpot++) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   139
                        int fallDown = 1 + fall(digDown + 1, digSpot);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   140
                        if (fallDown <= f) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   141
                            if (fallDown == 1) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   142
                                addToM(calcWalkingRange(digDown + 1, digSpot, p, digSpot),
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   143
                                        m.getValue() + Math.abs(digSpot - p) + 1);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   144
                            } else {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   145
                                addToM(calcWalkingRange(digDown + fallDown, digSpot),
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   146
                                        m.getValue() + Math.abs(digSpot - p) + 1);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   147
                            }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   148
                        }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   149
                    }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   150
                }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   151
            }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   152
        }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   153
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   154
        int result = Integer.MAX_VALUE;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   155
        for (Map.Entry<Integer, Integer> m : M.entrySet()) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   156
            if (depth(m.getKey()) == r - 1) result = Math.min(m.getValue(), result);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   157
        }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   158
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   159
        if (result == Integer.MAX_VALUE) return -1;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   160
        return result;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   161
    }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   162
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   163
    private void addToM(int q, int i) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   164
        Integer original = M.get(q);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   165
        if (original == null) M.put(q, i);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   166
        else M.put(q, Math.min(original, i));
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   167
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   168
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   169
    private int fall(int row, int column) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   170
        int res = 0;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   171
        for (int p = row + 1; p < r; p++) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   172
            if (grid[p][column] == AIR) res++;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   173
            else break;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   174
        }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   175
        return res;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   176
    }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   177
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   178
    private boolean stuck(int q) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   179
        return start(q) == end(q);
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   180
    }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   181
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   182
    private int depth(int q) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   183
        return q % 50;
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   184
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   185
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   186
    private int start(int q) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   187
        return q / (50 * 50);
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   188
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   189
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   190
    private int end(int q) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   191
        return (q / 50) % 50;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   192
    }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   193
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   194
    private int calcWalkingRange(int depth, int pos) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   195
        return calcWalkingRange(depth, pos, Integer.MAX_VALUE, Integer.MIN_VALUE);
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   196
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   197
25732
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   198
    private int calcWalkingRange(int depth, int pos, int airOverrideStart, int airOverrideEnd) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   199
        int left = pos, right = pos;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   200
        if (depth >= r) return (c - 1) * 50 + depth;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   201
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   202
        while (left > 0) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   203
            if (grid[depth][left - 1] == ROCK && (left - 1 < airOverrideStart || left - 1 > airOverrideEnd)) break;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   204
            if (depth < r - 1 && grid[depth + 1][left - 1] == AIR) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   205
                left--;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   206
                break;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   207
            }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   208
            left--;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   209
        }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   210
        while (right < c - 1) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   211
            if (grid[depth][right + 1] == ROCK && (right + 1 < airOverrideStart || right + 1 > airOverrideEnd)) break;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   212
            if (depth < r - 1 && grid[depth + 1][right + 1] == AIR) {
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   213
                right++;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   214
                break;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   215
            }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   216
            right++;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   217
        }
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   218
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   219
        return left * 50 * 50 + right * 50 + depth;
e2c1d053a55f 8048882: Some regression tests are not robust with VM output
ppunegov
parents: 15753
diff changeset
   220
    }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   221
}