hotspot/test/compiler/escapeAnalysis/TestEscapeThroughInvoke.java
author bharadwaj
Tue, 05 Apr 2016 20:32:54 +0000
changeset 37295 e00dfcc21fa1
parent 29355 6a13ec66ba95
child 40059 c2304140ed64
permissions -rw-r--r--
Merge
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.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    28
 * @run main/othervm -XX:CompileCommand=dontinline,TestEscapeThroughInvoke::create TestEscapeThroughInvoke
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    29
 */
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    30
public class TestEscapeThroughInvoke {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    31
    private A a;
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    32
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    33
    public static void main(String[] args) {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    34
        TestEscapeThroughInvoke test = new TestEscapeThroughInvoke();
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    35
        test.a = new A(42);
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    36
        // Make sure run gets compiled by C2
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    37
        for (int i = 0; i < 100_000; ++i) {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    38
            test.run();
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    39
        }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    40
    }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    41
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    42
    private void run() {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    43
        // Allocate something to trigger EA
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    44
        new Object();
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    45
        // Create a new escaping instance of A and
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    46
        // verify that it is always equal to 'a.saved'.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    47
        A escapingA = create(42);
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    48
        a.check(escapingA);
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    49
    }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    50
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    51
    // Create and return a new instance of A that escaped through 'A::saveInto'.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    52
    // The 'dummy' parameters are needed to avoid EA skipping the methods.
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    53
    private A create(Integer dummy) {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    54
        A result = new A(dummy);
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    55
        result.saveInto(a, dummy); // result escapes into 'a' here
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    56
        return result;
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    57
    }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    58
}
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    59
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    60
class A {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    61
    private A saved;
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    62
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    63
    public A(Integer dummy) { }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    64
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    65
    public void saveInto(A other, Integer dummy) {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    66
        other.saved = this;
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    67
    }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    68
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    69
    public void check(A other) {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    70
        if (this.saved != other) {
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    71
            throw new RuntimeException("TEST FAILED: Objects not equal.");
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    72
        }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    73
    }
6a13ec66ba95 8006960: hotspot, "impossible" assertion failure
thartmann
parents:
diff changeset
    74
}