test/hotspot/jtreg/compiler/escapeAnalysis/TestEscapeThroughInvoke.java
author jiangli
Fri, 02 Nov 2018 19:30:31 -0400
changeset 52397 1322829d1501
parent 47216 71c04702a3d5
permissions -rw-r--r--
8209564: runtime/appcds/CDSandJFR.java timeout on tier6 on sparc Summary: Set timeout 500 in CDSandJFR.java Reviewed-by: dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29355
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
     1
/*
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
     4
 *
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
     8
 *
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    13
 * accompanied this code).
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    14
 *
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    18
 *
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    21
 * questions.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    22
 */
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    23
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    24
/**
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    25
 * @test
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    26
 * @bug 8073956
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    27
 * @summary Tests C2 EA with allocated object escaping through a call.
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    28
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    29
 * @run main/othervm
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    30
 *      -XX:CompileCommand=dontinline,compiler.escapeAnalysis.TestEscapeThroughInvoke::create
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    31
 *      compiler.escapeAnalysis.TestEscapeThroughInvoke
29355
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    32
 */
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    33
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    34
package compiler.escapeAnalysis;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    35
29355
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    36
public class TestEscapeThroughInvoke {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    37
    private A a;
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    38
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    39
    public static void main(String[] args) {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    40
        TestEscapeThroughInvoke test = new TestEscapeThroughInvoke();
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    41
        test.a = new A(42);
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    42
        // Make sure run gets compiled by C2
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    43
        for (int i = 0; i < 100_000; ++i) {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    44
            test.run();
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    45
        }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    46
    }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    47
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    48
    private void run() {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    49
        // Allocate something to trigger EA
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    50
        new Object();
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    51
        // Create a new escaping instance of A and
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    52
        // verify that it is always equal to 'a.saved'.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    53
        A escapingA = create(42);
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    54
        a.check(escapingA);
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    55
    }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    56
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    57
    // Create and return a new instance of A that escaped through 'A::saveInto'.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    58
    // The 'dummy' parameters are needed to avoid EA skipping the methods.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    59
    private A create(Integer dummy) {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    60
        A result = new A(dummy);
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    61
        result.saveInto(a, dummy); // result escapes into 'a' here
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    62
        return result;
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    63
    }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    64
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    65
    static class A {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    66
        private A saved;
29355
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    67
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    68
        public A(Integer dummy) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    69
        }
29355
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    70
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    71
        public void saveInto(A other, Integer dummy) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    72
            other.saved = this;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    73
        }
29355
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    74
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    75
        public void check(A other) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    76
            if (this.saved != other) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    77
                throw new RuntimeException("TEST FAILED: Objects not equal.");
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29355
diff changeset
    78
            }
29355
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    79
        }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    80
    }
40067
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    81
}