hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestChar.java
author rfield
Mon, 06 Mar 2017 15:44:37 -0800
changeset 44066 336ca6c49e10
parent 40059 c2304140ed64
child 45514 0fc9cc73ce45
permissions -rw-r--r--
8176241: JShell tests: on full builds CompletionSuggestionTest.testImportStart() fails Reviewed-by: darcy
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 char
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39419
diff changeset
    28
 *
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 36827
diff changeset
    29
 * @modules jdk.unsupported/sun.misc
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39419
diff changeset
    30
 * @run testng/othervm -Diters=100   -Xint                   compiler.unsafe.SunMiscUnsafeAccessTestChar
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39419
diff changeset
    31
 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 compiler.unsafe.SunMiscUnsafeAccessTestChar
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39419
diff changeset
    32
 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  compiler.unsafe.SunMiscUnsafeAccessTestChar
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39419
diff changeset
    33
 * @run testng/othervm -Diters=20000                         compiler.unsafe.SunMiscUnsafeAccessTestChar
35103
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
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39419
diff changeset
    36
package compiler.unsafe;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39419
diff changeset
    37
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    38
import org.testng.annotations.Test;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    39
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    40
import java.lang.reflect.Field;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    41
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    42
import static org.testng.Assert.*;
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
public class SunMiscUnsafeAccessTestChar {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    45
    static final int ITERS = Integer.getInteger("iters", 1);
38234
06263a71233c 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 36851
diff changeset
    46
    static final int WEAK_ATTEMPTS = Integer.getInteger("weakAttempts", 10);
35103
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 sun.misc.Unsafe UNSAFE;
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 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 final Object STATIC_V_BASE;
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 final long STATIC_V_OFFSET;
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 int ARRAY_OFFSET;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    57
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    58
    static int ARRAY_SHIFT;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    59
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    60
    static {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    61
        try {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    62
            Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    63
            f.setAccessible(true);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    64
            UNSAFE = (sun.misc.Unsafe) f.get(null);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    65
        } catch (Exception e) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    66
            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
    67
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    68
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    69
        try {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    70
            Field staticVField = SunMiscUnsafeAccessTestChar.class.getDeclaredField("static_v");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    71
            STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    72
            STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    73
        } catch (Exception e) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    74
            throw new RuntimeException(e);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    75
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    76
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    77
        try {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    78
            Field vField = SunMiscUnsafeAccessTestChar.class.getDeclaredField("v");
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    79
            V_OFFSET = UNSAFE.objectFieldOffset(vField);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    80
        } catch (Exception e) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    81
            throw new RuntimeException(e);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    82
        }
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
        ARRAY_OFFSET = UNSAFE.arrayBaseOffset(char[].class);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    85
        int ascale = UNSAFE.arrayIndexScale(char[].class);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    86
        ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    87
    }
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
    static char static_v;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    90
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    91
    char v;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    92
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    93
    @Test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    94
    public void testFieldInstance() {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    95
        SunMiscUnsafeAccessTestChar t = new SunMiscUnsafeAccessTestChar();
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    96
        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
    97
            testAccess(t, V_OFFSET);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    98
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
    99
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   100
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   101
    @Test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   102
    public void testFieldStatic() {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   103
        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
   104
            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
   105
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   106
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   107
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   108
    @Test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   109
    public void testArray() {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   110
        char[] array = new char[10];
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   111
        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
   112
            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
   113
                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
   114
            }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   115
        }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   116
    }
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
    @Test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   119
    public void testArrayOffHeap() {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   120
        int size = 10;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   121
        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
   122
        try {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   123
            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
   124
                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
   125
                    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
   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
        } finally {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   129
            UNSAFE.freeMemory(address);
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   130
        }
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
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   133
    @Test
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   134
    public void testArrayOffHeapDirect() {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   135
        int size = 10;
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   136
        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
   137
        try {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   138
            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
   139
                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
   140
                    testAccess((((long) i) << ARRAY_SHIFT) + 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
        } finally {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   144
            UNSAFE.freeMemory(address);
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
    }
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
    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
   149
        // Plain
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   150
        {
39419
cc993a4ab581 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38234
diff changeset
   151
            UNSAFE.putChar(base, offset, '\u0123');
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   152
            char x = UNSAFE.getChar(base, offset);
39419
cc993a4ab581 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38234
diff changeset
   153
            assertEquals(x, '\u0123', "set char value");
35103
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
        // Volatile
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   157
        {
39419
cc993a4ab581 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38234
diff changeset
   158
            UNSAFE.putCharVolatile(base, offset, '\u4567');
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   159
            char x = UNSAFE.getCharVolatile(base, offset);
39419
cc993a4ab581 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38234
diff changeset
   160
            assertEquals(x, '\u4567', "putVolatile char value");
35103
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
36827
53d2d43551d2 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 35103
diff changeset
   166
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   167
    }
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   168
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   169
    static void testAccess(long address) {
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   170
        // Plain
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   171
        {
39419
cc993a4ab581 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38234
diff changeset
   172
            UNSAFE.putChar(address, '\u0123');
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
diff changeset
   173
            char x = UNSAFE.getChar(address);
39419
cc993a4ab581 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38234
diff changeset
   174
            assertEquals(x, '\u0123', "set char value");
35103
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
}
36827
53d2d43551d2 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 35103
diff changeset
   178