|
| 1 | +/* |
| 2 | + * Copyright (c) 2011, 2016, 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. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. |
| 10 | + * |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | + * accompanied this code). |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License version |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + * |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | + * or visit www.oracle.com if you need additional information or have any |
| 23 | + * questions. |
| 24 | + */ |
| 25 | +package org.graalvm.compiler.core.test.ea; |
| 26 | + |
| 27 | +import java.util.concurrent.atomic.AtomicReference; |
| 28 | + |
| 29 | +import org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode; |
| 30 | +import org.junit.Test; |
| 31 | + |
| 32 | +import jdk.vm.ci.meta.JavaConstant; |
| 33 | + |
| 34 | +public class UnsafeCompareAndSwapVirtualizationTest extends EATestBase { |
| 35 | + |
| 36 | + private static Object obj1 = new Object(); |
| 37 | + private static Object obj2 = new Object(); |
| 38 | + |
| 39 | + public static boolean bothVirtualNoMatch() { |
| 40 | + AtomicReference<Object> a = new AtomicReference<>(); |
| 41 | + return a.compareAndSet(new Object(), new Object()); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void bothVirtualNoMatchTest() { |
| 46 | + testEscapeAnalysis("bothVirtualNoMatch", JavaConstant.INT_0, true); |
| 47 | + assertTrue(graph.getNodes(LogicCompareAndSwapNode.TYPE).isEmpty()); |
| 48 | + } |
| 49 | + |
| 50 | + public static boolean bothVirtualMatch() { |
| 51 | + Object expect = new Object(); |
| 52 | + AtomicReference<Object> a = new AtomicReference<>(expect); |
| 53 | + return a.compareAndSet(expect, new Object()); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void bothVirtualMatchTest() { |
| 58 | + testEscapeAnalysis("bothVirtualMatch", JavaConstant.INT_1, true); |
| 59 | + assertTrue(graph.getNodes(LogicCompareAndSwapNode.TYPE).isEmpty()); |
| 60 | + } |
| 61 | + |
| 62 | + public static boolean expectedVirtualMatch() { |
| 63 | + Object o = new Object(); |
| 64 | + AtomicReference<Object> a = new AtomicReference<>(o); |
| 65 | + return a.compareAndSet(o, obj1); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void expectedVirtualMatchTest() { |
| 70 | + testEscapeAnalysis("expectedVirtualMatch", null, true); |
| 71 | + assertTrue(graph.getNodes(LogicCompareAndSwapNode.TYPE).isEmpty()); |
| 72 | + } |
| 73 | + |
| 74 | + public static boolean expectedVirtualNoMatch() { |
| 75 | + Object o = new Object(); |
| 76 | + AtomicReference<Object> a = new AtomicReference<>(); |
| 77 | + return a.compareAndSet(o, obj1); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void expectedVirtualNoMatchTest() { |
| 82 | + testEscapeAnalysis("expectedVirtualNoMatch", null, true); |
| 83 | + assertTrue(graph.getNodes(LogicCompareAndSwapNode.TYPE).isEmpty()); |
| 84 | + } |
| 85 | + |
| 86 | + public static boolean bothNonVirtualNoMatch() { |
| 87 | + AtomicReference<Object> a = new AtomicReference<>(); |
| 88 | + return a.compareAndSet(obj1, obj2); |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + public void bothNonVirtualNoMatchTest() { |
| 93 | + testEscapeAnalysis("bothNonVirtualNoMatch", null, true); |
| 94 | + assertTrue(graph.getNodes(LogicCompareAndSwapNode.TYPE).isEmpty()); |
| 95 | + } |
| 96 | + |
| 97 | + public static boolean bothNonVirtualMatch() { |
| 98 | + AtomicReference<Object> a = new AtomicReference<>(obj1); |
| 99 | + return a.compareAndSet(obj1, obj2); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void bothNonVirtualMatchTest() { |
| 104 | + testEscapeAnalysis("bothNonVirtualMatch", null, true); |
| 105 | + assertTrue(graph.getNodes(LogicCompareAndSwapNode.TYPE).isEmpty()); |
| 106 | + } |
| 107 | + |
| 108 | + public static boolean onlyInitialValueVirtualMatch() { |
| 109 | + AtomicReference<Object> a = new AtomicReference<>(new Object()); |
| 110 | + return a.compareAndSet(obj1, obj2); |
| 111 | + } |
| 112 | +} |
0 commit comments