Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/unsafe/UnsafeTwoCASLong.java
41153 views
/*1* Copyright (c) 2015, 2017, 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 814393026* @summary C1 LinearScan asserts when compiling two back-to-back CompareAndSwapLongs27* @modules java.base/jdk.internal.misc:+open28*29* @run testng/othervm -Diters=200000 -XX:TieredStopAtLevel=130* compiler.intrinsics.unsafe.UnsafeTwoCASLong31*/3233package compiler.intrinsics.unsafe;3435import org.testng.annotations.Test;3637import java.lang.reflect.Field;3839import static org.testng.Assert.*;4041public class UnsafeTwoCASLong {42static final int ITERS = Integer.getInteger("iters", 1);43static final jdk.internal.misc.Unsafe UNSAFE;44static final long V_OFFSET;4546static {47try {48Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");49f.setAccessible(true);50UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);51} catch (Exception e) {52throw new RuntimeException("Unable to get Unsafe instance.", e);53}5455try {56Field vField = UnsafeTwoCASLong.class.getDeclaredField("v");57V_OFFSET = UNSAFE.objectFieldOffset(vField);58} catch (Exception e) {59throw new RuntimeException(e);60}61}6263long v;6465@Test66public void testFieldInstance() {67UnsafeTwoCASLong t = new UnsafeTwoCASLong();68for (int c = 0; c < ITERS; c++) {69testAccess(t, V_OFFSET);70}71}7273static void testAccess(Object base, long offset) {74UNSAFE.compareAndSetLong(base, offset, 1L, 2L);75UNSAFE.compareAndSetLong(base, offset, 2L, 1L);76}7778}798081