1 /* 2 * Copyright (c) 2019, Red Hat, Inc. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8219335 27 * @summary "failed: unexpected type" assert failure in ConnectionGraph::split_unique_types() with unsafe accesses 28 * 29 * @modules java.base/jdk.internal.misc 30 * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:-TieredCompilation -Xcomp -XX:CompileOnly=MaybeOffHeapUnsafeAccessToNewObject::test1 -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline MaybeOffHeapUnsafeAccessToNewObject 31 */ 32 33 import java.lang.reflect.Field; 34 import jdk.internal.misc.Unsafe; 35 36 public class MaybeOffHeapUnsafeAccessToNewObject { 37 public volatile int f_int = -1; 38 39 40 public static Unsafe unsafe = Unsafe.getUnsafe(); 41 public static final long f_int_off; 42 43 static { 44 Field f_int_field = null; 45 try { 46 f_int_field = MaybeOffHeapUnsafeAccessToNewObject.class.getField("f_int"); 47 } catch (Exception e) { 48 System.out.println("reflection failed " + e); 49 e.printStackTrace(); 50 } 51 f_int_off = unsafe.objectFieldOffset(f_int_field); 52 } 53 main(String[] args)54 static public void main(String[] args) { 55 MaybeOffHeapUnsafeAccessToNewObject o = new MaybeOffHeapUnsafeAccessToNewObject(); 56 test1(); 57 } 58 test1_helper1(Object t)59 static Object test1_helper1(Object t) { 60 return t; 61 } 62 test1_helper2(long off)63 static long test1_helper2(long off) { 64 return off; 65 } 66 test1()67 static int test1() { 68 MaybeOffHeapUnsafeAccessToNewObject t = new MaybeOffHeapUnsafeAccessToNewObject(); 69 Object o = test1_helper1(t); 70 long off = test1_helper2(f_int_off); 71 return unsafe.getInt(o, off); 72 } 73 74 } 75