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