hotspot/test/compiler/intrinsics/unsafe/UnsafeTwoCASLong.java
author gtriantafill
Wed, 14 Sep 2016 08:17:50 -0400
changeset 41092 c388d897472d
parent 40059 c2304140ed64
child 41705 332239c052cc
permissions -rw-r--r--
8165889: Remove jdk.test.lib.unsafe.UnsafeHelper Summary: Remove use of setAccessible() to get Unsafe. Reviewed-by: shade, lfoltan
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
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35094
diff changeset
    30
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35094
diff changeset
    31
 * @run testng/othervm -Diters=200000 -XX:TieredStopAtLevel=1
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35094
diff changeset
    32
 *      compiler.intrinsics.unsafe.UnsafeTwoCASLong
35094
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    33
 */
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    34
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35094
diff changeset
    35
package compiler.intrinsics.unsafe;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35094
diff changeset
    36
35094
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    37
import org.testng.annotations.Test;
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
import java.lang.reflect.Field;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    40
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    41
import static org.testng.Assert.*;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    42
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    43
public class UnsafeTwoCASLong {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    44
    static final int ITERS = Integer.getInteger("iters", 1);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    45
    static final jdk.internal.misc.Unsafe UNSAFE;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    46
    static final long V_OFFSET;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    47
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    48
    static {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    49
        try {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    50
            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
    51
            f.setAccessible(true);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    52
            UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    53
        } catch (Exception e) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    54
            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
    55
        }
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    56
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    57
        try {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    58
            Field vField = UnsafeTwoCASLong.class.getDeclaredField("v");
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    59
            V_OFFSET = UNSAFE.objectFieldOffset(vField);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    60
        } catch (Exception e) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    61
            throw new RuntimeException(e);
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
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    65
    long v;
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    66
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    67
    @Test
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    68
    public void testFieldInstance() {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    69
        UnsafeTwoCASLong t = new UnsafeTwoCASLong();
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    70
        for (int c = 0; c < ITERS; c++) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    71
            testAccess(t, V_OFFSET);
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
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    75
    static void testAccess(Object base, long offset) {
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    76
        UNSAFE.compareAndSwapLong(base, offset, 1L, 2L);
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    77
        UNSAFE.compareAndSwapLong(base, offset, 2L, 1L);
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
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    80
}
1e623555b98d 8143930: C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs
roland
parents:
diff changeset
    81