Path: blob/master/test/hotspot/jtreg/compiler/escapeAnalysis/TestUnsafePutAddressNullObjMustNotEscape.java
41152 views
/*1* Copyright (c) 2014 SAP SE. 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 803804826* @summary assert(null_obj->escape_state() == PointsToNode::NoEscape,etc)27* @modules java.base/jdk.internal.misc:+open28*29* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+DoEscapeAnalysis30* -XX:-TieredCompilation -Xbatch31* compiler.escapeAnalysis.TestUnsafePutAddressNullObjMustNotEscape32*33* @author Richard Reingruber richard DOT reingruber AT sap DOT com34*/3536package compiler.escapeAnalysis;3738import jdk.internal.misc.Unsafe;3940import java.lang.reflect.Field;4142public class TestUnsafePutAddressNullObjMustNotEscape {4344public static Unsafe usafe;45public static long mem;46public static long checksum;4748public static void main(String[] args) throws Exception {49System.out.println("EXECUTING test.");5051{52System.out.println("Acquiring jdk.internal.misc.Unsafe.theUnsafe using reflection.");53getUnsafe();54System.out.println("Allocating raw memory.");55mem = (usafe.allocateMemory(1024) + 8L) & ~7L;56System.out.println("Triggering JIT compilation of the test method");57triggerJitCompilationOfTestMethod();58}5960System.out.println("SUCCESSFULLY passed test.");61}6263public static void triggerJitCompilationOfTestMethod() {64long sum = 0;65for (int ii = 50000; ii >= 0; ii--) {66sum = testMethod();67}68checksum = sum;69}7071public static class IDGen {72private static long id;73public long nextId() {74return id++;75}76}7778public static long testMethod() {79// dummy alloc to trigger escape analysis80IDGen gen = new IDGen();81// StoreP of null_obj to raw mem triggers assertion in escape analysis82usafe.putAddress(mem, 0L);83return gen.nextId();84}8586private static void getUnsafe() throws Exception {87Field field = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");88field.setAccessible(true);89usafe = (jdk.internal.misc.Unsafe) field.get(null);90}91}929394