Path: blob/master/test/hotspot/jtreg/compiler/escapeAnalysis/TestEscapeThroughInvoke.java
41149 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 807395626* @summary Tests C2 EA with allocated object escaping through a call.27*28* @run main/othervm29* -XX:CompileCommand=dontinline,compiler.escapeAnalysis.TestEscapeThroughInvoke::create30* compiler.escapeAnalysis.TestEscapeThroughInvoke31*/3233package compiler.escapeAnalysis;3435public class TestEscapeThroughInvoke {36private A a;3738public static void main(String[] args) {39TestEscapeThroughInvoke test = new TestEscapeThroughInvoke();40test.a = new A(42);41// Make sure run gets compiled by C242for (int i = 0; i < 100_000; ++i) {43test.run();44}45}4647private void run() {48// Allocate something to trigger EA49new Object();50// Create a new escaping instance of A and51// verify that it is always equal to 'a.saved'.52A escapingA = create(42);53a.check(escapingA);54}5556// Create and return a new instance of A that escaped through 'A::saveInto'.57// The 'dummy' parameters are needed to avoid EA skipping the methods.58private A create(Integer dummy) {59A result = new A(dummy);60result.saveInto(a, dummy); // result escapes into 'a' here61return result;62}6364static class A {65private A saved;6667public A(Integer dummy) {68}6970public void saveInto(A other, Integer dummy) {71other.saved = this;72}7374public void check(A other) {75if (this.saved != other) {76throw new RuntimeException("TEST FAILED: Objects not equal.");77}78}79}80}818283