1 /*
   2  * Copyright (c) 2015, 2016, 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  * @test
  26  * @requires (vm.simpleArch == "x64" | vm.simpleArch == "sparcv9") & os.arch != "aarch64"
  27  * @library /
  28  * @modules jdk.vm.ci/jdk.vm.ci.hotspot
  29  *          jdk.vm.ci/jdk.vm.ci.meta
  30  *          jdk.vm.ci/jdk.vm.ci.code
  31  *          jdk.vm.ci/jdk.vm.ci.code.site
  32  *          jdk.vm.ci/jdk.vm.ci.runtime
  33  *          jdk.vm.ci/jdk.vm.ci.amd64
  34  *          jdk.vm.ci/jdk.vm.ci.sparc
  35  * @compile CodeInstallationTest.java DebugInfoTest.java TestAssembler.java TestHotSpotVMConfig.java amd64/AMD64TestAssembler.java sparc/SPARCTestAssembler.java
  36  * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI jdk.vm.ci.code.test.SimpleDebugInfoTest
  37  */
  38 
  39 package jdk.vm.ci.code.test;
  40 
  41 import org.junit.Assume;
  42 import org.junit.Test;
  43 
  44 import jdk.vm.ci.code.Register;
  45 import jdk.vm.ci.hotspot.HotSpotConstant;
  46 import jdk.vm.ci.meta.JavaConstant;
  47 import jdk.vm.ci.meta.JavaKind;
  48 import jdk.vm.ci.meta.ResolvedJavaType;
  49 import jdk.vm.ci.meta.Value;
  50 
  51 public class SimpleDebugInfoTest extends DebugInfoTest {
  52 
  53     public static int intOnStack() {
  54         return 42;
  55     }
  56 
  57     private void testIntOnStack(DebugInfoCompiler compiler) {
  58         test(compiler, getMethod("intOnStack"), 2, JavaKind.Int);
  59     }
  60 
  61     public static int intInLocal() {
  62         int local = 42;
  63         return local;
  64     }
  65 
  66     public void testIntInLocal(DebugInfoCompiler compiler) {
  67         test(compiler, getMethod("intInLocal"), 3, JavaKind.Int);
  68     }
  69 
  70     @Test
  71     public void testConstInt() {
  72         DebugInfoCompiler compiler = (asm, values) -> {
  73             values[0] = JavaConstant.forInt(42);
  74             return null;
  75         };
  76         testIntOnStack(compiler);
  77         testIntInLocal(compiler);
  78     }
  79 
  80     @Test
  81     public void testRegInt() {
  82         DebugInfoCompiler compiler = (asm, values) -> {
  83             Register reg = asm.emitLoadInt(42);
  84             values[0] = reg.asValue(asm.getValueKind(JavaKind.Int));
  85             return null;
  86         };
  87         testIntOnStack(compiler);
  88         testIntInLocal(compiler);
  89     }
  90 
  91     @Test
  92     public void testStackInt() {
  93         DebugInfoCompiler compiler = (asm, values) -> {
  94             Register reg = asm.emitLoadInt(42);
  95             values[0] = asm.emitIntToStack(reg);
  96             return null;
  97         };
  98         testIntOnStack(compiler);
  99         testIntInLocal(compiler);
 100     }
 101 
 102     public static float floatOnStack() {
 103         return 42.0f;
 104     }
 105 
 106     private void testFloatOnStack(DebugInfoCompiler compiler) {
 107         test(compiler, getMethod("floatOnStack"), 2, JavaKind.Float);
 108     }
 109 
 110     public static float floatInLocal() {
 111         float local = 42.0f;
 112         return local;
 113     }
 114 
 115     private void testFloatInLocal(DebugInfoCompiler compiler) {
 116         test(compiler, getMethod("floatInLocal"), 3, JavaKind.Float);
 117     }
 118 
 119     @Test
 120     public void testConstFloat() {
 121         DebugInfoCompiler compiler = (asm, values) -> {
 122             values[0] = JavaConstant.forFloat(42.0f);
 123             return null;
 124         };
 125         testFloatOnStack(compiler);
 126         testFloatInLocal(compiler);
 127     }
 128 
 129     @Test
 130     public void testRegFloat() {
 131         DebugInfoCompiler compiler = (asm, values) -> {
 132             Register reg = asm.emitLoadFloat(42.0f);
 133             values[0] = reg.asValue(asm.getValueKind(JavaKind.Float));
 134             return null;
 135         };
 136         testFloatOnStack(compiler);
 137         testFloatInLocal(compiler);
 138     }
 139 
 140     @Test
 141     public void testStackFloat() {
 142         DebugInfoCompiler compiler = (asm, values) -> {
 143             Register reg = asm.emitLoadFloat(42.0f);
 144             values[0] = asm.emitFloatToStack(reg);
 145             return null;
 146         };
 147         testFloatOnStack(compiler);
 148         testFloatInLocal(compiler);
 149     }
 150 
 151     public static long longOnStack() {
 152         return 42;
 153     }
 154 
 155     private void testLongOnStack(DebugInfoCompiler compiler) {
 156         test(compiler, getMethod("longOnStack"), 3, JavaKind.Long, JavaKind.Illegal);
 157     }
 158 
 159     public static long longInLocal() {
 160         long local = 42;
 161         return local;
 162     }
 163 
 164     private void testLongInLocal(DebugInfoCompiler compiler) {
 165         test(compiler, getMethod("longInLocal"), 4, JavaKind.Long, JavaKind.Illegal);
 166     }
 167 
 168     @Test
 169     public void testConstLong() {
 170         DebugInfoCompiler compiler = (asm, values) -> {
 171             values[0] = JavaConstant.forLong(42);
 172             values[1] = Value.ILLEGAL;
 173             return null;
 174         };
 175         testLongOnStack(compiler);
 176         testLongInLocal(compiler);
 177     }
 178 
 179     @Test
 180     public void testRegLong() {
 181         DebugInfoCompiler compiler = (asm, values) -> {
 182             Register reg = asm.emitLoadLong(42);
 183             values[0] = reg.asValue(asm.getValueKind(JavaKind.Long));
 184             values[1] = Value.ILLEGAL;
 185             return null;
 186         };
 187         testLongOnStack(compiler);
 188         testLongInLocal(compiler);
 189     }
 190 
 191     @Test
 192     public void testStackLong() {
 193         DebugInfoCompiler compiler = (asm, values) -> {
 194             Register reg = asm.emitLoadLong(42);
 195             values[0] = asm.emitLongToStack(reg);
 196             values[1] = Value.ILLEGAL;
 197             return null;
 198         };
 199         testLongOnStack(compiler);
 200         testLongInLocal(compiler);
 201     }
 202 
 203     public static Class<?> objectOnStack() {
 204         return SimpleDebugInfoTest.class;
 205     }
 206 
 207     private void testObjectOnStack(DebugInfoCompiler compiler) {
 208         test(compiler, getMethod("objectOnStack"), 2, JavaKind.Object);
 209     }
 210 
 211     public static Class<?> objectInLocal() {
 212         Class<?> local = SimpleDebugInfoTest.class;
 213         return local;
 214     }
 215 
 216     private void testObjectInLocal(DebugInfoCompiler compiler) {
 217         test(compiler, getMethod("objectInLocal"), 3, JavaKind.Object);
 218     }
 219 
 220     @Test
 221     public void testConstObject() {
 222         ResolvedJavaType type = metaAccess.lookupJavaType(objectOnStack());
 223         DebugInfoCompiler compiler = (asm, values) -> {
 224             values[0] = constantReflection.asJavaClass(type);
 225             return null;
 226         };
 227         testObjectOnStack(compiler);
 228         testObjectInLocal(compiler);
 229     }
 230 
 231     @Test
 232     public void testRegObject() {
 233         ResolvedJavaType type = metaAccess.lookupJavaType(objectOnStack());
 234         DebugInfoCompiler compiler = (asm, values) -> {
 235             Register reg = asm.emitLoadPointer((HotSpotConstant) constantReflection.asJavaClass(type));
 236             values[0] = reg.asValue(asm.getValueKind(JavaKind.Object));
 237             return null;
 238         };
 239         testObjectOnStack(compiler);
 240         testObjectInLocal(compiler);
 241     }
 242 
 243     @Test
 244     public void testStackObject() {
 245         ResolvedJavaType type = metaAccess.lookupJavaType(objectOnStack());
 246         DebugInfoCompiler compiler = (asm, values) -> {
 247             Register reg = asm.emitLoadPointer((HotSpotConstant) constantReflection.asJavaClass(type));
 248             values[0] = asm.emitPointerToStack(reg);
 249             return null;
 250         };
 251         testObjectOnStack(compiler);
 252         testObjectInLocal(compiler);
 253     }
 254 
 255     @Test
 256     public void testRegNarrowObject() {
 257         Assume.assumeTrue(config.useCompressedOops);
 258         ResolvedJavaType type = metaAccess.lookupJavaType(objectOnStack());
 259         DebugInfoCompiler compiler = (asm, values) -> {
 260             HotSpotConstant wide = (HotSpotConstant) constantReflection.asJavaClass(type);
 261             Register reg = asm.emitLoadPointer((HotSpotConstant) wide.compress());
 262             values[0] = reg.asValue(asm.narrowOopKind);
 263             return null;
 264         };
 265         testObjectOnStack(compiler);
 266         testObjectInLocal(compiler);
 267     }
 268 
 269     @Test
 270     public void testStackNarrowObject() {
 271         Assume.assumeTrue(config.useCompressedOops);
 272         ResolvedJavaType type = metaAccess.lookupJavaType(objectOnStack());
 273         DebugInfoCompiler compiler = (asm, values) -> {
 274             HotSpotConstant wide = (HotSpotConstant) constantReflection.asJavaClass(type);
 275             Register reg = asm.emitLoadPointer((HotSpotConstant) wide.compress());
 276             values[0] = asm.emitNarrowPointerToStack(reg);
 277             return null;
 278         };
 279         testObjectOnStack(compiler);
 280         testObjectInLocal(compiler);
 281     }
 282 }