hotspot/test/compiler/intrinsics/unsafe/UnsafeTwoCASLong.java
author psandoz
Mon, 05 Jun 2017 15:52:09 -0700
changeset 45514 0fc9cc73ce45
parent 42307 cefc81dc1d52
permissions -rw-r--r--
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9 Reviewed-by: psandoz, dholmes, thartmann, kvn Contributed-by: ron.pressler@oracle.com, claes.redestad@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35094
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
     1
/*
45514
0fc9cc73ce45 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 42307
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
35094
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
     4
 *
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
     8
 *
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    13
 * accompanied this code).
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    14
 *
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    18
 *
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    21
 * questions.
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    22
 */
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    23
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    24
/*
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    25
 * @test
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    26
 * @bug 8143930
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    27
 * @summary C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41705
diff changeset
    28
 * @modules java.base/jdk.internal.misc:+open
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35094
diff changeset
    29
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35094
diff changeset
    30
 * @run testng/othervm -Diters=200000 -XX:TieredStopAtLevel=1
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35094
diff changeset
    31
 *      compiler.intrinsics.unsafe.UnsafeTwoCASLong
35094
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    32
 */
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    33
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35094
diff changeset
    34
package compiler.intrinsics.unsafe;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35094
diff changeset
    35
35094
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    36
import org.testng.annotations.Test;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    37
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    38
import java.lang.reflect.Field;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    39
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    40
import static org.testng.Assert.*;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    41
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    42
public class UnsafeTwoCASLong {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    43
    static final int ITERS = Integer.getInteger("iters", 1);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    44
    static final jdk.internal.misc.Unsafe UNSAFE;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    45
    static final long V_OFFSET;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    46
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    47
    static {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    48
        try {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    49
            Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    50
            f.setAccessible(true);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    51
            UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    52
        } catch (Exception e) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    53
            throw new RuntimeException("Unable to get Unsafe instance.", e);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    54
        }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    55
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    56
        try {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    57
            Field vField = UnsafeTwoCASLong.class.getDeclaredField("v");
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    58
            V_OFFSET = UNSAFE.objectFieldOffset(vField);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    59
        } catch (Exception e) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    60
            throw new RuntimeException(e);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    61
        }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    62
    }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    63
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    64
    long v;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    65
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    66
    @Test
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    67
    public void testFieldInstance() {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    68
        UnsafeTwoCASLong t = new UnsafeTwoCASLong();
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    69
        for (int c = 0; c < ITERS; c++) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    70
            testAccess(t, V_OFFSET);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    71
        }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    72
    }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    73
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    74
    static void testAccess(Object base, long offset) {
45514
0fc9cc73ce45 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 42307
diff changeset
    75
        UNSAFE.compareAndSetLong(base, offset, 1L, 2L);
0fc9cc73ce45 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 42307
diff changeset
    76
        UNSAFE.compareAndSetLong(base, offset, 2L, 1L);
35094
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    77
    }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    78
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    79
}