hotspot/test/compiler/intrinsics/unsafe/UnsafeGetAddressTest.java
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 42307 cefc81dc1d52
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23495
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 23495
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
23495
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
     4
 *
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
     8
 *
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    13
 * accompanied this code).
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    14
 *
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    18
 *
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    21
 * questions.
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    22
 */
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    23
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    24
/*
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    25
 * @test
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    26
 * @bug 6653795
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    27
 * @summary C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40059
diff changeset
    28
 * @modules java.base/jdk.internal.misc:+open
23495
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    29
 *
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    30
 * @run main compiler.intrinsics.unsafe.UnsafeGetAddressTest
23495
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    31
 */
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    32
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    33
package compiler.intrinsics.unsafe;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    34
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36851
diff changeset
    35
import jdk.internal.misc.Unsafe;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    36
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    37
import java.lang.reflect.Field;
23495
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    38
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    39
public class UnsafeGetAddressTest {
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    40
    private static Unsafe unsafe;
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    41
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36851
diff changeset
    43
        Class c = UnsafeGetAddressTest.class.getClassLoader().loadClass("jdk.internal.misc.Unsafe");
23495
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    44
        Field f = c.getDeclaredField("theUnsafe");
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    45
        f.setAccessible(true);
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    46
        unsafe = (Unsafe)f.get(c);
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    47
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    48
        long address = unsafe.allocateMemory(unsafe.addressSize());
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    49
        unsafe.putAddress(address, 0x0000000080000000L);
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36851
diff changeset
    50
        // from jdk.internal.misc.Unsafe.getAddress' documentation:
23495
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    51
        // "If the native pointer is less than 64 bits wide, it is
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    52
        // extended as an unsigned number to a Java long."
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    53
        result = unsafe.getAddress(address);
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    54
        System.out.printf("1: was 0x%x, expected 0x%x\n", result,
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    55
                0x0000000080000000L);
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    56
        for (int i = 0; i < 1000000; i++) {
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    57
            result = unsafe.getAddress(address);
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    58
        }
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    59
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    60
        // The code has got compiled, check the result now
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    61
        System.out.printf("2: was 0x%x, expected 0x%x\n", result,
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    62
                0x0000000080000000L);
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    63
        if (result != 0x0000000080000000L) {
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    64
            System.out.println("Test Failed");
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    65
            System.exit(97);
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    66
        } else {
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    67
            System.out.println("Test Passed");
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    68
        }
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    69
    }
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    70
    static volatile long result;
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    71
}
f222fac90da2 6653795: C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems
poonam
parents:
diff changeset
    72