1/* 2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. 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 */ 23package org.graalvm.compiler.hotspot.amd64.test; 24 25import static org.graalvm.compiler.core.common.GraalOptions.OptImplicitNullChecks; 26 27import org.graalvm.compiler.hotspot.test.HotSpotGraalCompilerTest; 28import org.graalvm.compiler.options.OptionValues; 29import org.junit.Assume; 30import org.junit.Test; 31 32import jdk.vm.ci.meta.ResolvedJavaMethod; 33 34/** 35 * Ensures that frame omission works in cases where it is expected to. 36 */ 37public class CompressedNullCheckTest extends HotSpotGraalCompilerTest { 38 39 private static final class Container { 40 Integer i; 41 } 42 43 public static void testSnippet(Container c) { 44 c.i.intValue(); 45 } 46 47 @SuppressWarnings("try") 48 private void testImplicit(Integer i) { 49 Assume.assumeTrue(runtime().getVMConfig().useCompressedOops); 50 51 Container c = new Container(); 52 c.i = i; 53 54 ResolvedJavaMethod method = getResolvedJavaMethod("testSnippet"); 55 Result expect = executeExpected(method, null, c); 56 57 // make sure we don't get a profile that removes the implicit null check 58 method.reprofile(); 59 60 OptionValues options = new OptionValues(getInitialOptions(), OptImplicitNullChecks, true); 61 Result actual = executeActual(options, method, null, c); 62 assertEquals(expect, actual); 63 } 64 65 @SuppressWarnings("try") 66 private void testExplicit(Integer i) { 67 Assume.assumeTrue(runtime().getVMConfig().useCompressedOops); 68 69 Container c = new Container(); 70 c.i = i; 71 72 test(new OptionValues(getInitialOptions(), OptImplicitNullChecks, false), "testSnippet", c); 73 } 74 75 @Test 76 public void implicit() { 77 testImplicit(new Integer(1)); 78 } 79 80 @Test 81 public void implicitNull() { 82 testImplicit(null); 83 } 84 85 @Test 86 public void explicit() { 87 testExplicit(new Integer(1)); 88 } 89 90 @Test 91 public void explicitNull() { 92 testExplicit(null); 93 } 94} 95