1 /*
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.core.test.ea;
26
27 import java.util.List;
28
29 import org.graalvm.compiler.graph.Node;
30 import org.graalvm.compiler.graph.iterators.NodeIterable;
31 import org.graalvm.compiler.loop.DefaultLoopPolicies;
32 import org.graalvm.compiler.loop.phases.LoopFullUnrollPhase;
33 import org.graalvm.compiler.loop.phases.LoopPeelingPhase;
34 import org.graalvm.compiler.nodes.ConstantNode;
35 import org.graalvm.compiler.nodes.ReturnNode;
36 import org.graalvm.compiler.nodes.extended.BoxNode;
37 import org.graalvm.compiler.nodes.extended.ValueAnchorNode;
38 import org.graalvm.compiler.nodes.java.LoadFieldNode;
39 import org.graalvm.compiler.nodes.virtual.AllocatedObjectNode;
40 import org.graalvm.compiler.nodes.virtual.CommitAllocationNode;
41 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
42 import org.graalvm.compiler.phases.schedule.SchedulePhase;
43 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
44 import org.junit.Assert;
45 import org.junit.Assume;
46 import org.junit.Test;
47
48 import jdk.vm.ci.meta.JavaConstant;
49
50 /**
51 * The PartialEscapeAnalysisPhase is expected to remove all allocations and return the correct
52 * values.
53 */
54 public class EscapeAnalysisTest extends EATestBase {
55
56 @Test
57 public void test1() {
58 testEscapeAnalysis("test1Snippet", JavaConstant.forInt(101), false);
59 }
60
61 @SuppressWarnings("deprecation")
62 public static int test1Snippet() {
396 testEscapeAnalysis("testInstanceOfSnippet", JavaConstant.forInt(1), false);
397 }
398
399 public boolean testInstanceOfSnippet() {
400 TestClassObject obj = new TestClassObject(TestClassObject.class);
401 TestClassObject obj2 = new TestClassObject(obj);
402 return obj2.x instanceof TestClassObject;
403 }
404
405 @SuppressWarnings("unused")
406 public static void testNewNodeSnippet() {
407 new ValueAnchorNode(null);
408 }
409
410 /**
411 * This test makes sure that the allocation of a {@link Node} can be removed. It therefore also
412 * tests the intrinsification of {@link Object#getClass()}.
413 */
414 @Test
415 public void testNewNode() {
416 // Trackking of creation interferes with escape analysis
417 Assume.assumeFalse(Node.TRACK_CREATION_POSITION);
418 testEscapeAnalysis("testNewNodeSnippet", null, false);
419 }
420
421 private static final TestClassObject staticObj = new TestClassObject();
422
423 public static Object testFullyUnrolledLoopSnippet() {
424 /*
425 * This tests a case that can appear if PEA is performed both before and after loop
426 * unrolling/peeling: If the VirtualInstanceNode is not duplicated correctly with the loop,
427 * the resulting object will reference itself, and not a second (different) object.
428 */
429 TestClassObject obj = staticObj;
430 for (int i = 0; i < 2; i++) {
431 obj = new TestClassObject(obj);
432 }
433 return obj.x;
434 }
435
436 @Test
437 public void testFullyUnrolledLoop() {
|
1 /*
2 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.core.test.ea;
26
27 import java.util.List;
28
29 import org.graalvm.compiler.graph.Node;
30 import org.graalvm.compiler.graph.iterators.NodeIterable;
31 import org.graalvm.compiler.loop.DefaultLoopPolicies;
32 import org.graalvm.compiler.loop.phases.LoopFullUnrollPhase;
33 import org.graalvm.compiler.loop.phases.LoopPeelingPhase;
34 import org.graalvm.compiler.nodes.ConstantNode;
35 import org.graalvm.compiler.nodes.ReturnNode;
36 import org.graalvm.compiler.nodes.extended.BoxNode;
37 import org.graalvm.compiler.nodes.extended.ValueAnchorNode;
38 import org.graalvm.compiler.nodes.java.LoadFieldNode;
39 import org.graalvm.compiler.nodes.virtual.AllocatedObjectNode;
40 import org.graalvm.compiler.nodes.virtual.CommitAllocationNode;
41 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
42 import org.graalvm.compiler.phases.schedule.SchedulePhase;
43 import org.graalvm.compiler.test.SubprocessUtil;
44 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
45 import org.junit.Assert;
46 import org.junit.Assume;
47 import org.junit.Test;
48
49 import jdk.vm.ci.meta.JavaConstant;
50
51 /**
52 * The PartialEscapeAnalysisPhase is expected to remove all allocations and return the correct
53 * values.
54 */
55 public class EscapeAnalysisTest extends EATestBase {
56
57 @Test
58 public void test1() {
59 testEscapeAnalysis("test1Snippet", JavaConstant.forInt(101), false);
60 }
61
62 @SuppressWarnings("deprecation")
63 public static int test1Snippet() {
397 testEscapeAnalysis("testInstanceOfSnippet", JavaConstant.forInt(1), false);
398 }
399
400 public boolean testInstanceOfSnippet() {
401 TestClassObject obj = new TestClassObject(TestClassObject.class);
402 TestClassObject obj2 = new TestClassObject(obj);
403 return obj2.x instanceof TestClassObject;
404 }
405
406 @SuppressWarnings("unused")
407 public static void testNewNodeSnippet() {
408 new ValueAnchorNode(null);
409 }
410
411 /**
412 * This test makes sure that the allocation of a {@link Node} can be removed. It therefore also
413 * tests the intrinsification of {@link Object#getClass()}.
414 */
415 @Test
416 public void testNewNode() {
417 // Tracking of creation interferes with escape analysis
418 Assume.assumeFalse(Node.TRACK_CREATION_POSITION);
419 // JaCoco can add escaping allocations (e.g. allocation of coverage recording data
420 // structures)
421 Assume.assumeFalse("JaCoCo found -> skipping", SubprocessUtil.isJaCoCoAttached());
422 testEscapeAnalysis("testNewNodeSnippet", null, false);
423 }
424
425 private static final TestClassObject staticObj = new TestClassObject();
426
427 public static Object testFullyUnrolledLoopSnippet() {
428 /*
429 * This tests a case that can appear if PEA is performed both before and after loop
430 * unrolling/peeling: If the VirtualInstanceNode is not duplicated correctly with the loop,
431 * the resulting object will reference itself, and not a second (different) object.
432 */
433 TestClassObject obj = staticObj;
434 for (int i = 0; i < 2; i++) {
435 obj = new TestClassObject(obj);
436 }
437 return obj.x;
438 }
439
440 @Test
441 public void testFullyUnrolledLoop() {
|