hotspot/test/compiler/unsafe/JdkInternalMiscUnsafeAccessTestObject.java
author psandoz
Wed, 09 Dec 2015 14:54:40 +0100
changeset 35103 d19354bcbfa6
child 36316 7a83de7aabca
permissions -rw-r--r--
8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables Reviewed-by: shade, dholmes, alanb, chegar, mchung, roland
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
        // Lazy
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   131
        {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   132
            UNSAFE.putOrderedObject(base, offset, "foo");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   133
            Object x = UNSAFE.getObjectVolatile(base, offset);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   134
            assertEquals(x, "foo", "putRelease Object value");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   135
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   136
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   137
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   138
        UNSAFE.putObject(base, offset, "foo");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   139
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   140
        // Compare
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   141
        {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   142
            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
   143
            assertEquals(r, true, "success compareAndSwap Object");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   144
            Object x = UNSAFE.getObject(base, offset);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   145
            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
   146
        }
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
        {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   149
            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
   150
            assertEquals(r, false, "failing compareAndSwap Object");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   151
            Object x = UNSAFE.getObject(base, offset);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   152
            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
   153
        }
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
        // Compare set and get
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
            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
   158
            assertEquals(o, "bar", "getAndSet 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, "foo", "getAndSet 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
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   163
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   164
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   165
}