Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/unsafe/UnsafeGetAddressTest.java
41153 views
/*1* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 665379526* @summary C2 intrinsic for Unsafe.getAddress performs pointer sign extension on 32-bit systems27* @modules java.base/jdk.internal.misc:+open28*29* @run main compiler.intrinsics.unsafe.UnsafeGetAddressTest30*/3132package compiler.intrinsics.unsafe;3334import jdk.internal.misc.Unsafe;3536import java.lang.reflect.Field;3738public class UnsafeGetAddressTest {39private static Unsafe unsafe;4041public static void main(String[] args) throws Exception {42Class c = UnsafeGetAddressTest.class.getClassLoader().loadClass("jdk.internal.misc.Unsafe");43Field f = c.getDeclaredField("theUnsafe");44f.setAccessible(true);45unsafe = (Unsafe)f.get(c);4647long address = unsafe.allocateMemory(unsafe.addressSize());48unsafe.putAddress(address, 0x0000000080000000L);49// from jdk.internal.misc.Unsafe.getAddress' documentation:50// "If the native pointer is less than 64 bits wide, it is51// extended as an unsigned number to a Java long."52result = unsafe.getAddress(address);53System.out.printf("1: was 0x%x, expected 0x%x\n", result,540x0000000080000000L);55for (int i = 0; i < 1000000; i++) {56result = unsafe.getAddress(address);57}5859// The code has got compiled, check the result now60System.out.printf("2: was 0x%x, expected 0x%x\n", result,610x0000000080000000L);62if (result != 0x0000000080000000L) {63System.out.println("Test Failed");64System.exit(97);65} else {66System.out.println("Test Passed");67}68}69static volatile long result;70}71727374