aoqi@0: /* aoqi@0: * Copyright 2014 SAP AG. All Rights Reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /** aoqi@0: * @test aoqi@0: * @bug 8038048 aoqi@0: * @summary assert(null_obj->escape_state() == PointsToNode::NoEscape,etc) aoqi@0: * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+DoEscapeAnalysis -XX:-TieredCompilation -Xbatch TestUnsafePutAddressNullObjMustNotEscape aoqi@0: * @author Richard Reingruber richard DOT reingruber AT sap DOT com aoqi@0: */ aoqi@0: aoqi@0: import java.lang.reflect.Field; aoqi@0: import sun.misc.Unsafe; aoqi@0: aoqi@0: public class TestUnsafePutAddressNullObjMustNotEscape { aoqi@0: aoqi@0: public static Unsafe usafe; aoqi@0: public static long mem; aoqi@0: public static long checksum; aoqi@0: aoqi@0: public static void main(String[] args) throws Exception { aoqi@0: System.out.println("EXECUTING test."); aoqi@0: aoqi@0: { aoqi@0: System.out.println("Acquiring sun.misc.Unsafe.theUnsafe using reflection."); aoqi@0: getUnsafe(); aoqi@0: System.out.println("Allocating raw memory."); aoqi@0: mem = (usafe.allocateMemory(1024) + 8L) & ~7L; aoqi@0: System.out.println("Triggering JIT compilation of the test method"); aoqi@0: triggerJitCompilationOfTestMethod(); aoqi@0: } aoqi@0: aoqi@0: System.out.println("SUCCESSFULLY passed test."); aoqi@0: } aoqi@0: aoqi@0: public static void triggerJitCompilationOfTestMethod() { aoqi@0: long sum = 0; aoqi@0: for (int ii = 50000; ii >= 0; ii--) { aoqi@0: sum = testMethod(); aoqi@0: } aoqi@0: checksum = sum; aoqi@0: } aoqi@0: aoqi@0: public static class IDGen { aoqi@0: private static long id; aoqi@0: public long nextId() { aoqi@0: return id++; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static long testMethod() { aoqi@0: // dummy alloc to trigger escape analysis aoqi@0: IDGen gen = new IDGen(); aoqi@0: // StoreP of null_obj to raw mem triggers assertion in escape analysis aoqi@0: usafe.putAddress(mem, 0L); aoqi@0: return gen.nextId(); aoqi@0: } aoqi@0: aoqi@0: private static void getUnsafe() throws Exception { aoqi@0: Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe"); aoqi@0: field.setAccessible(true); aoqi@0: usafe = (sun.misc.Unsafe) field.get(null); aoqi@0: } aoqi@0: }