Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/shenandoah/compiler/TestMaybeNullUnsafeAccess.java
32285 views
/*1* Copyright (c) 2017, 2018, Red Hat, Inc. 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* @test TestMaybeNullUnsafeAccess25* @summary cast on before unsafe access moved in dominating null check null path causes crash26* @key gc27* @library /testlibrary28*29* @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:-TieredCompilation30* TestMaybeNullUnsafeAccess31*32* @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:-TieredCompilation33* -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC34* TestMaybeNullUnsafeAccess35*36*/3738import sun.misc.Unsafe;3940import java.lang.reflect.Field;4142import com.oracle.java.testlibrary.*;4344public class TestMaybeNullUnsafeAccess {4546static final sun.misc.Unsafe UNSAFE = Utils.getUnsafe();47static final long F_OFFSET;4849static class A {50int f;51}5253static {54try {55Field fField = A.class.getDeclaredField("f");56F_OFFSET = UNSAFE.objectFieldOffset(fField);57} catch (Exception e) {58throw new RuntimeException(e);59}60}6162static A test_helper(Object o) {63return (A) o;64}6566static int test(Object o) {67int f = 0;68for (int i = 0; i < 100; i++) {69A a = test_helper(o);70f = UNSAFE.getInt(a, F_OFFSET);71}72return f;73}7475static public void main(String[] args) {76A a = new A();77for (int i = 0; i < 20000; i++) {78test_helper(null);79test_helper(a);80test(a);81}82}8384}858687