hotspot/test/compiler/unsafe/JdkInternalMiscUnsafeAccessTestObject.java
author chegar
Sat, 09 Apr 2016 23:03:39 +0100
changeset 36851 03e2f4d0a421
parent 36827 53d2d43551d2
child 38234 06263a71233c
permissions -rw-r--r--
8153737: Unsupported Module Reviewed-by: alanb, mchung, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
     1
/*
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
     4
 *
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
     8
 *
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    13
 * accompanied this code).
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    14
 *
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    18
 *
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    21
 * questions.
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    22
 */
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    23
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    24
/*
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    25
 * @test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    26
 * @bug 8143628
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    27
 * @summary Test unsafe access for Object
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.misc
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    29
 * @run testng/othervm -Diters=100   -Xint                   JdkInternalMiscUnsafeAccessTestObject
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    30
 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestObject
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    31
 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  JdkInternalMiscUnsafeAccessTestObject
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    32
 * @run testng/othervm -Diters=20000                         JdkInternalMiscUnsafeAccessTestObject
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    33
 */
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    34
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    35
import org.testng.annotations.Test;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    36
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    37
import java.lang.reflect.Field;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    38
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    39
import static org.testng.Assert.*;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    40
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    41
public class JdkInternalMiscUnsafeAccessTestObject {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    42
    static final int ITERS = Integer.getInteger("iters", 1);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    43
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    44
    static final jdk.internal.misc.Unsafe UNSAFE;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    45
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    46
    static final long V_OFFSET;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    47
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    48
    static final Object STATIC_V_BASE;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    49
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    50
    static final long STATIC_V_OFFSET;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    51
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    52
    static int ARRAY_OFFSET;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    53
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    54
    static int ARRAY_SHIFT;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    55
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    56
    static {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    57
        try {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    58
            Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    59
            f.setAccessible(true);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    60
            UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    61
        } catch (Exception e) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    62
            throw new RuntimeException("Unable to get Unsafe instance.", e);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    63
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    64
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    65
        try {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    66
            Field staticVField = JdkInternalMiscUnsafeAccessTestObject.class.getDeclaredField("static_v");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    67
            STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    68
            STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    69
        } catch (Exception e) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    70
            throw new RuntimeException(e);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    71
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    72
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    73
        try {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    74
            Field vField = JdkInternalMiscUnsafeAccessTestObject.class.getDeclaredField("v");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    75
            V_OFFSET = UNSAFE.objectFieldOffset(vField);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    76
        } catch (Exception e) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    77
            throw new RuntimeException(e);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    78
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    79
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    80
        ARRAY_OFFSET = UNSAFE.arrayBaseOffset(Object[].class);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    81
        int ascale = UNSAFE.arrayIndexScale(Object[].class);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    82
        ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    83
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    84
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    85
    static Object static_v;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    86
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    87
    Object v;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    88
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    89
    @Test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    90
    public void testFieldInstance() {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    91
        JdkInternalMiscUnsafeAccessTestObject t = new JdkInternalMiscUnsafeAccessTestObject();
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    92
        for (int c = 0; c < ITERS; c++) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    93
            testAccess(t, V_OFFSET);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    94
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    95
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    96
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    97
    @Test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    98
    public void testFieldStatic() {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    99
        for (int c = 0; c < ITERS; c++) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   100
            testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   101
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   102
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   104
    @Test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   105
    public void testArray() {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   106
        Object[] array = new Object[10];
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   107
        for (int c = 0; c < ITERS; c++) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   108
            for (int i = 0; i < array.length; i++) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   109
                testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   110
            }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   111
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   112
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   113
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   114
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   115
    static void testAccess(Object base, long offset) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   116
        // Plain
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   117
        {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   118
            UNSAFE.putObject(base, offset, "foo");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   119
            Object x = UNSAFE.getObject(base, offset);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   120
            assertEquals(x, "foo", "set Object value");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   121
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   122
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   123
        // Volatile
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   124
        {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   125
            UNSAFE.putObjectVolatile(base, offset, "bar");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   126
            Object x = UNSAFE.getObjectVolatile(base, offset);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   127
            assertEquals(x, "bar", "putVolatile Object value");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   128
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   129
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   130
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   131
        // Lazy
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   132
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   133
            UNSAFE.putObjectRelease(base, offset, "foo");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   134
            Object x = UNSAFE.getObjectAcquire(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   135
            assertEquals(x, "foo", "putRelease Object value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   136
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   137
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   138
        // Opaque
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   139
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   140
            UNSAFE.putObjectOpaque(base, offset, "bar");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   141
            Object x = UNSAFE.getObjectOpaque(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   142
            assertEquals(x, "bar", "putOpaque Object value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   143
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   144
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   145
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   146
        UNSAFE.putObject(base, offset, "foo");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   147
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   148
        // Compare
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   149
        {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   150
            boolean r = UNSAFE.compareAndSwapObject(base, offset, "foo", "bar");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   151
            assertEquals(r, true, "success compareAndSwap Object");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   152
            Object x = UNSAFE.getObject(base, offset);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   153
            assertEquals(x, "bar", "success compareAndSwap Object value");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   154
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   155
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   156
        {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   157
            boolean r = UNSAFE.compareAndSwapObject(base, offset, "foo", "baz");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   158
            assertEquals(r, false, "failing compareAndSwap Object");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   159
            Object x = UNSAFE.getObject(base, offset);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   160
            assertEquals(x, "bar", "failing compareAndSwap Object value");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   161
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   162
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   163
        // Advanced compare
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   164
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   165
            Object r = UNSAFE.compareAndExchangeObjectVolatile(base, offset, "bar", "foo");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   166
            assertEquals(r, "bar", "success compareAndExchangeVolatile Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   167
            Object x = UNSAFE.getObject(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   168
            assertEquals(x, "foo", "success compareAndExchangeVolatile Object value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   169
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   170
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   171
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   172
            Object r = UNSAFE.compareAndExchangeObjectVolatile(base, offset, "bar", "baz");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   173
            assertEquals(r, "foo", "failing compareAndExchangeVolatile Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   174
            Object x = UNSAFE.getObject(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   175
            assertEquals(x, "foo", "failing compareAndExchangeVolatile Object value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   176
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   177
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   178
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   179
            Object r = UNSAFE.compareAndExchangeObjectAcquire(base, offset, "foo", "bar");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   180
            assertEquals(r, "foo", "success compareAndExchangeAcquire Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   181
            Object x = UNSAFE.getObject(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   182
            assertEquals(x, "bar", "success compareAndExchangeAcquire Object value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   183
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   184
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   185
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   186
            Object r = UNSAFE.compareAndExchangeObjectAcquire(base, offset, "foo", "baz");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   187
            assertEquals(r, "bar", "failing compareAndExchangeAcquire Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   188
            Object x = UNSAFE.getObject(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   189
            assertEquals(x, "bar", "failing compareAndExchangeAcquire Object value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   190
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   191
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   192
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   193
            Object r = UNSAFE.compareAndExchangeObjectRelease(base, offset, "bar", "foo");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   194
            assertEquals(r, "bar", "success compareAndExchangeRelease Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   195
            Object x = UNSAFE.getObject(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   196
            assertEquals(x, "foo", "success compareAndExchangeRelease Object value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   197
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   198
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   199
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   200
            Object r = UNSAFE.compareAndExchangeObjectRelease(base, offset, "bar", "baz");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   201
            assertEquals(r, "foo", "failing compareAndExchangeRelease Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   202
            Object x = UNSAFE.getObject(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   203
            assertEquals(x, "foo", "failing compareAndExchangeRelease Object value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   204
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   205
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   206
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   207
            boolean r = UNSAFE.weakCompareAndSwapObject(base, offset, "foo", "bar");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   208
            assertEquals(r, true, "weakCompareAndSwap Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   209
            Object x = UNSAFE.getObject(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   210
            assertEquals(x, "bar", "weakCompareAndSwap Object value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   211
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   212
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   213
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   214
            boolean r = UNSAFE.weakCompareAndSwapObjectAcquire(base, offset, "bar", "foo");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   215
            assertEquals(r, true, "weakCompareAndSwapAcquire Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   216
            Object x = UNSAFE.getObject(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   217
            assertEquals(x, "foo", "weakCompareAndSwapAcquire Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   218
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   219
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   220
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   221
            boolean r = UNSAFE.weakCompareAndSwapObjectRelease(base, offset, "foo", "bar");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   222
            assertEquals(r, true, "weakCompareAndSwapRelease Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   223
            Object x = UNSAFE.getObject(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   224
            assertEquals(x, "bar", "weakCompareAndSwapRelease Object");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   225
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   226
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   227
        // Compare set and get
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   228
        {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   229
            Object o = UNSAFE.getAndSetObject(base, offset, "foo");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   230
            assertEquals(o, "bar", "getAndSet Object");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   231
            Object x = UNSAFE.getObject(base, offset);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   232
            assertEquals(x, "foo", "getAndSet Object value");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   233
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   234
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   235
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   236
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   237
}
36827
53d2d43551d2 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36316
diff changeset
   238
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 36827
diff changeset
   239