test/hotspot/jtreg/compiler/stable/TestStableMemoryBarrier.java
author rwestberg
Mon, 04 Jun 2018 16:21:08 +0200
changeset 50391 2bea53d7a27b
parent 47216 71c04702a3d5
child 51016 a926b7737d3b
permissions -rw-r--r--
8202095: JFR TestBiasedLockRevocationEvents should cope with multiple events during a single safepoint Reviewed-by: mgronlun, egahlin
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
/*
37773
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36508
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
34183
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
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    30
 * @modules java.base/jdk.internal.vm.annotation
34183
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    31
 *
38188
e76af590ea2f 8155751: Some tests miss othervm for main/bootclasspath mode
vlivanov
parents: 38152
diff changeset
    32
 * @run main/bootclasspath/othervm -Xcomp -XX:CompileOnly=::testCompile
e76af590ea2f 8155751: Some tests miss othervm for main/bootclasspath mode
vlivanov
parents: 38152
diff changeset
    33
 *                                 compiler.stable.TestStableMemoryBarrier
34183
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
 */
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    37
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    38
package compiler.stable;
34183
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    39
35099
982950884444 8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents: 34183
diff changeset
    40
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
    41
34183
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    42
public class TestStableMemoryBarrier {
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    44
        for (int i = 0; i < 1000000; i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    45
            NotDominate.testCompile(i);
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    46
        }
34183
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
     * 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
    50
     * 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
    51
     */
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    52
    private static class NotDominate {
34183
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    53
        public @Stable int v;
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    54
        public static int[] array = new int[100];
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    55
34183
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    56
        public static NotDominate testCompile(int n) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    57
            if ((n % 2) == 0) return null;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    58
            // add a loop here, trigger PhaseIdealLoop::verify_dominance
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    59
            for (int i = 0; i < 100; i++) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    60
                array[i] = n;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    61
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    62
            NotDominate nm = new NotDominate();
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    63
            nm.v = n;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    64
            return nm;
34183
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    65
        }
8b683720a3e4 8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff changeset
    66
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
}
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35753
diff changeset
    70