hotspot/test/compiler/intrinsics/unsafe/UnsafeTwoCASLong.java
author chegar
Tue, 22 Mar 2016 15:26:07 +0000
changeset 36694 182a5e7a519e
parent 35094 1e623555b98d
child 40059 c2304140ed64
permissions -rw-r--r--
Merge
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
/*
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
/*
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    26
 * @test
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    27
 * @bug 8143930
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    28
 * @summary C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    29
 * @modules java.base/jdk.internal.misc
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    30
 * @run testng/othervm -Diters=200000 -XX:TieredStopAtLevel=1 UnsafeTwoCASLong
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    31
 */
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
import org.testng.annotations.Test;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    34
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    35
import java.lang.reflect.Field;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    36
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    37
import static org.testng.Assert.*;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    38
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    39
public class UnsafeTwoCASLong {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    40
    static final int ITERS = Integer.getInteger("iters", 1);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    41
    static final jdk.internal.misc.Unsafe UNSAFE;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    42
    static final long V_OFFSET;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    43
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    44
    static {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    45
        try {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    46
            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
    47
            f.setAccessible(true);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    48
            UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    49
        } catch (Exception e) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    50
            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
    51
        }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    52
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    53
        try {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    54
            Field vField = UnsafeTwoCASLong.class.getDeclaredField("v");
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    55
            V_OFFSET = UNSAFE.objectFieldOffset(vField);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    56
        } catch (Exception e) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    57
            throw new RuntimeException(e);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    58
        }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    59
    }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    60
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    61
    long v;
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
    @Test
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    64
    public void testFieldInstance() {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    65
        UnsafeTwoCASLong t = new UnsafeTwoCASLong();
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    66
        for (int c = 0; c < ITERS; c++) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    67
            testAccess(t, V_OFFSET);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    68
        }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    69
    }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    70
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    71
    static void testAccess(Object base, long offset) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    72
        UNSAFE.compareAndSwapLong(base, offset, 1L, 2L);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    73
        UNSAFE.compareAndSwapLong(base, offset, 2L, 1L);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    74
    }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    75
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    76
}
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    77