hotspot/test/compiler/intrinsics/hashcode/TestHashCode.java
author chegar
Tue, 22 Mar 2016 15:26:07 +0000
changeset 36694 182a5e7a519e
parent 24916 bcf892f54aba
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24916
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
     1
/*
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
     4
 *
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
     8
 *
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    13
 * accompanied this code).
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    14
 *
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    18
 *
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    21
 * questions.
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    22
 */
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    23
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    24
/*
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    25
 * @test
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    26
 * @bug 8011646
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    27
 * @summary SEGV in compiled code with loop predication
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    28
 * @run main/othervm  -XX:-TieredCompilation -XX:CompileOnly=TestHashCode.m1,Object.hashCode TestHashCode
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    29
 *
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    30
 */
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    31
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    32
public class TestHashCode {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    33
    static class A {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    34
        int i;
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    35
    }
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    36
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    37
    static class B extends A {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    38
    }
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    39
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    40
    static boolean crash = false;
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    41
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    42
    static A m2() {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    43
        if (crash) {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    44
            return null;
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    45
        }
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    46
        return new A();
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    47
    }
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    48
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    49
    static int m1(A aa) {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    50
        int res = 0;
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    51
        for (int i = 0; i < 10; i++) {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    52
            A a = m2();
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    53
            int j = a.i;
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    54
            if (aa instanceof B) {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    55
            }
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    56
            res += a.hashCode();
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    57
        }
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    58
        return res;
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    59
    }
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    60
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    61
    public static void main(String[] args) {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    62
        A a = new A();
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    63
        for (int i = 0; i < 20000; i++) {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    64
            m1(a);
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    65
        }
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    66
        crash = true;
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    67
        try {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    68
          m1(a);
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    69
        } catch (NullPointerException e) {
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    70
            System.out.println("Test passed");
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    71
        }
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    72
    }
bcf892f54aba 8011646: SEGV in compiled code with loop predication
anoll
parents:
diff changeset
    73
}