hotspot/test/compiler/stable/TestStableMemoryBarrier.java
author iignatyev
Fri, 29 Jan 2016 03:11:16 +0300
changeset 35753 ee7921f045d2
parent 35099 982950884444
child 36508 5f9eee6b383b
permissions -rw-r--r--
8148012: get rid of slash-dot-dot in @library directives Reviewed-by: dholmes, dfazunen, cjplummer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34183
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
     1
/*
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
     4
 *
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    10
 *
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    15
 * accompanied this code).
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    16
 *
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    20
 *
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    23
 * questions.
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    24
 */
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    25
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    26
/*
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    27
 * @test TestStableMemoryBarrier
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    28
 * @bug 8139758
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    29
 * @summary tests memory barrier correctly inserted for stable fields
35753
ee7921f045d2 8148012: get rid of slash-dot-dot in @library directives
iignatyev
parents: 35099
diff changeset
    30
 * @library /testlibrary /test/lib
34183
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    31
 *
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    32
 * @run main/bootclasspath -Xcomp -XX:CompileOnly=::testCompile
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    33
 *                   java.lang.invoke.TestStableMemoryBarrier
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    34
 *
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    35
 * @author hui.shi@linaro.org
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    36
 */
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    37
package java.lang.invoke;
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    38
35099
982950884444 8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents: 34183
diff changeset
    39
import jdk.internal.vm.annotation.Stable;
982950884444 8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents: 34183
diff changeset
    40
34183
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    41
import java.lang.reflect.InvocationTargetException;
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    42
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    43
public class TestStableMemoryBarrier {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    44
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    46
        run(NotDominate.class);
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    47
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    48
    }
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    49
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    50
    /* ====================================================
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    51
     * Stable field initialized in method, but its allocation
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    52
     * doesn't dominate MemBar Release at the end of method.
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    53
     */
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    54
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    55
    static class NotDominate{
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    56
        public @Stable int v;
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    57
        public static int[] array = new int[100];
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    58
        public static NotDominate testCompile(int n) {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    59
           if ((n % 2) == 0) return null;
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    60
           // add a loop here, trigger PhaseIdealLoop::verify_dominance
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    61
           for (int i = 0; i < 100; i++) {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    62
              array[i] = n;
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    63
           }
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    64
           NotDominate nm = new NotDominate();
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    65
           nm.v = n;
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    66
           return nm;
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    67
        }
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    68
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    69
        public static void test() throws Exception {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    70
           for (int i = 0; i < 1000000; i++)
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    71
               testCompile(i);
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    72
        }
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    73
    }
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    74
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    75
    public static void run(Class<?> test) {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    76
        Throwable ex = null;
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    77
        System.out.print(test.getName()+": ");
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    78
        try {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    79
            test.getMethod("test").invoke(null);
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    80
        } catch (InvocationTargetException e) {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    81
            ex = e.getCause();
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    82
        } catch (Throwable e) {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    83
            ex = e;
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    84
        } finally {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    85
            if (ex == null) {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    86
                System.out.println("PASSED");
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    87
            } else {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    88
                System.out.println("FAILED");
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    89
                ex.printStackTrace(System.out);
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    90
            }
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    91
        }
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    92
    }
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    93
}