hotspot/test/compiler/unsafe/JdkInternalMiscUnsafeAccessTestByte.java
author bharadwaj
Tue, 05 Apr 2016 20:32:54 +0000
changeset 37295 e00dfcc21fa1
parent 36827 53d2d43551d2
child 36851 03e2f4d0a421
permissions -rw-r--r--
Merge
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 byte
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                   JdkInternalMiscUnsafeAccessTestByte
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 JdkInternalMiscUnsafeAccessTestByte
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  JdkInternalMiscUnsafeAccessTestByte
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    32
 * @run testng/othervm -Diters=20000                         JdkInternalMiscUnsafeAccessTestByte
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 JdkInternalMiscUnsafeAccessTestByte {
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 = JdkInternalMiscUnsafeAccessTestByte.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 = JdkInternalMiscUnsafeAccessTestByte.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(byte[].class);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    81
        int ascale = UNSAFE.arrayIndexScale(byte[].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 byte 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
    byte 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
        JdkInternalMiscUnsafeAccessTestByte t = new JdkInternalMiscUnsafeAccessTestByte();
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
        byte[] array = new byte[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
    @Test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   115
    public void testArrayOffHeap() {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   116
        int size = 10;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   117
        long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   118
        try {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   119
            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
   120
                for (int i = 0; i < size; i++) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   121
                    testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
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
            }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   124
        } finally {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   125
            UNSAFE.freeMemory(address);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   126
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   127
    }
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
    @Test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   130
    public void testArrayOffHeapDirect() {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   131
        int size = 10;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   132
        long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   133
        try {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   134
            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
   135
                for (int i = 0; i < size; i++) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   136
                    testAccess((((long) i) << ARRAY_SHIFT) + address);
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
            }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   139
        } finally {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   140
            UNSAFE.freeMemory(address);
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
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   143
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   144
    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
   145
        // Plain
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
            UNSAFE.putByte(base, offset, (byte)1);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   148
            byte x = UNSAFE.getByte(base, offset);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   149
            assertEquals(x, (byte)1, "set byte value");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   150
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   151
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   152
        // Volatile
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
            UNSAFE.putByteVolatile(base, offset, (byte)2);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   155
            byte x = UNSAFE.getByteVolatile(base, offset);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   156
            assertEquals(x, (byte)2, "putVolatile byte value");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   157
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   158
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   159
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   160
        // Lazy
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   161
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   162
            UNSAFE.putByteRelease(base, offset, (byte)1);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   163
            byte x = UNSAFE.getByteAcquire(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   164
            assertEquals(x, (byte)1, "putRelease byte value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   165
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   166
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   167
        // Opaque
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   168
        {
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   169
            UNSAFE.putByteOpaque(base, offset, (byte)2);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   170
            byte x = UNSAFE.getByteOpaque(base, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   171
            assertEquals(x, (byte)2, "putOpaque byte value");
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   172
        }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 35103
diff changeset
   173
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   174
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   175
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   176
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   177
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   178
    static void testAccess(long address) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   179
        // Plain
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   180
        {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   181
            UNSAFE.putByte(address, (byte)1);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   182
            byte x = UNSAFE.getByte(address);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   183
            assertEquals(x, (byte)1, "set byte value");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   184
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   185
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   186
}
36827
53d2d43551d2 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36316
diff changeset
   187