hotspot/test/compiler/jvmci/code/SimpleDebugInfoTest.java
changeset 38057 1eba14626850
parent 38014 8731fa11f766
parent 38056 033ebbb3746e
child 38058 17294a77a970
equal deleted inserted replaced
38014:8731fa11f766 38057:1eba14626850
     1 /*
       
     2  * Copyright (c) 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  * @test
       
    26  * @requires (os.simpleArch == "x64" | os.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  * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI compiler.jvmci.code.SimpleDebugInfoTest
       
    36  */
       
    37 
       
    38 package compiler.jvmci.code;
       
    39 
       
    40 import jdk.vm.ci.code.Register;
       
    41 import jdk.vm.ci.hotspot.HotSpotConstant;
       
    42 import jdk.vm.ci.hotspot.HotSpotVMConfig;
       
    43 import jdk.vm.ci.meta.JavaConstant;
       
    44 import jdk.vm.ci.meta.JavaKind;
       
    45 import jdk.vm.ci.meta.ResolvedJavaType;
       
    46 import jdk.vm.ci.meta.Value;
       
    47 
       
    48 import org.junit.Assume;
       
    49 import org.junit.Test;
       
    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(target.getLIRKind(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 
       
   103     public static float floatOnStack() {
       
   104         return 42.0f;
       
   105     }
       
   106 
       
   107     private void testFloatOnStack(DebugInfoCompiler compiler) {
       
   108         test(compiler, getMethod("floatOnStack"), 2, JavaKind.Float);
       
   109     }
       
   110 
       
   111     public static float floatInLocal() {
       
   112         float local = 42.0f;
       
   113         return local;
       
   114     }
       
   115 
       
   116     private void testFloatInLocal(DebugInfoCompiler compiler) {
       
   117         test(compiler, getMethod("floatInLocal"), 3, JavaKind.Float);
       
   118     }
       
   119 
       
   120     @Test
       
   121     public void testConstFloat() {
       
   122         DebugInfoCompiler compiler = (asm, values) -> {
       
   123             values[0] = JavaConstant.forFloat(42.0f);
       
   124             return null;
       
   125         };
       
   126         testFloatOnStack(compiler);
       
   127         testFloatInLocal(compiler);
       
   128     }
       
   129 
       
   130     @Test
       
   131     public void testRegFloat() {
       
   132         DebugInfoCompiler compiler = (asm, values) -> {
       
   133             Register reg = asm.emitLoadFloat(42.0f);
       
   134             values[0] = reg.asValue(target.getLIRKind(JavaKind.Float));
       
   135             return null;
       
   136         };
       
   137         testFloatOnStack(compiler);
       
   138         testFloatInLocal(compiler);
       
   139     }
       
   140 
       
   141     @Test
       
   142     public void testStackFloat() {
       
   143         DebugInfoCompiler compiler = (asm, values) -> {
       
   144             Register reg = asm.emitLoadFloat(42.0f);
       
   145             values[0] = asm.emitFloatToStack(reg);
       
   146             return null;
       
   147         };
       
   148         testFloatOnStack(compiler);
       
   149         testFloatInLocal(compiler);
       
   150     }
       
   151 
       
   152 
       
   153     public static long longOnStack() {
       
   154         return 42;
       
   155     }
       
   156 
       
   157     private void testLongOnStack(DebugInfoCompiler compiler) {
       
   158         test(compiler, getMethod("longOnStack"), 3, JavaKind.Long, JavaKind.Illegal);
       
   159     }
       
   160 
       
   161     public static long longInLocal() {
       
   162         long local = 42;
       
   163         return local;
       
   164     }
       
   165 
       
   166     private void testLongInLocal(DebugInfoCompiler compiler) {
       
   167         test(compiler, getMethod("longInLocal"), 4, JavaKind.Long, JavaKind.Illegal);
       
   168     }
       
   169 
       
   170     @Test
       
   171     public void testConstLong() {
       
   172         DebugInfoCompiler compiler = (asm, values) -> {
       
   173             values[0] = JavaConstant.forLong(42);
       
   174             values[1] = Value.ILLEGAL;
       
   175             return null;
       
   176         };
       
   177         testLongOnStack(compiler);
       
   178         testLongInLocal(compiler);
       
   179     }
       
   180 
       
   181     @Test
       
   182     public void testRegLong() {
       
   183         DebugInfoCompiler compiler = (asm, values) -> {
       
   184             Register reg = asm.emitLoadLong(42);
       
   185             values[0] = reg.asValue(target.getLIRKind(JavaKind.Long));
       
   186             values[1] = Value.ILLEGAL;
       
   187             return null;
       
   188         };
       
   189         testLongOnStack(compiler);
       
   190         testLongInLocal(compiler);
       
   191     }
       
   192 
       
   193     @Test
       
   194     public void testStackLong() {
       
   195         DebugInfoCompiler compiler = (asm, values) -> {
       
   196             Register reg = asm.emitLoadLong(42);
       
   197             values[0] = asm.emitLongToStack(reg);
       
   198             values[1] = Value.ILLEGAL;
       
   199             return null;
       
   200         };
       
   201         testLongOnStack(compiler);
       
   202         testLongInLocal(compiler);
       
   203     }
       
   204 
       
   205 
       
   206     public static Class<?> objectOnStack() {
       
   207         return SimpleDebugInfoTest.class;
       
   208     }
       
   209 
       
   210     private void testObjectOnStack(DebugInfoCompiler compiler) {
       
   211         test(compiler, getMethod("objectOnStack"), 2, JavaKind.Object);
       
   212     }
       
   213 
       
   214     public static Class<?> objectInLocal() {
       
   215         Class<?> local = SimpleDebugInfoTest.class;
       
   216         return local;
       
   217     }
       
   218 
       
   219     private void testObjectInLocal(DebugInfoCompiler compiler) {
       
   220         test(compiler, getMethod("objectInLocal"), 3, JavaKind.Object);
       
   221     }
       
   222 
       
   223     @Test
       
   224     public void testConstObject() {
       
   225         ResolvedJavaType type = metaAccess.lookupJavaType(objectOnStack());
       
   226         DebugInfoCompiler compiler = (asm, values) -> {
       
   227             values[0] = constantReflection.asJavaClass(type);
       
   228             return null;
       
   229         };
       
   230         testObjectOnStack(compiler);
       
   231         testObjectInLocal(compiler);
       
   232     }
       
   233 
       
   234     @Test
       
   235     public void testRegObject() {
       
   236         ResolvedJavaType type = metaAccess.lookupJavaType(objectOnStack());
       
   237         DebugInfoCompiler compiler = (asm, values) -> {
       
   238             Register reg = asm.emitLoadPointer((HotSpotConstant) constantReflection.asJavaClass(type));
       
   239             values[0] = reg.asValue(target.getLIRKind(JavaKind.Object));
       
   240             return null;
       
   241         };
       
   242         testObjectOnStack(compiler);
       
   243         testObjectInLocal(compiler);
       
   244     }
       
   245 
       
   246     @Test
       
   247     public void testStackObject() {
       
   248         ResolvedJavaType type = metaAccess.lookupJavaType(objectOnStack());
       
   249         DebugInfoCompiler compiler = (asm, values) -> {
       
   250             Register reg = asm.emitLoadPointer((HotSpotConstant) constantReflection.asJavaClass(type));
       
   251             values[0] = asm.emitPointerToStack(reg);
       
   252             return null;
       
   253         };
       
   254         testObjectOnStack(compiler);
       
   255         testObjectInLocal(compiler);
       
   256     }
       
   257 
       
   258     @Test
       
   259     public void testRegNarrowObject() {
       
   260         Assume.assumeTrue(HotSpotVMConfig.config().useCompressedOops);
       
   261         ResolvedJavaType type = metaAccess.lookupJavaType(objectOnStack());
       
   262         DebugInfoCompiler compiler = (asm, values) -> {
       
   263             HotSpotConstant wide = (HotSpotConstant) constantReflection.asJavaClass(type);
       
   264             Register reg = asm.emitLoadPointer((HotSpotConstant) wide.compress());
       
   265             values[0] = reg.asValue(asm.narrowOopKind);
       
   266             return null;
       
   267         };
       
   268         testObjectOnStack(compiler);
       
   269         testObjectInLocal(compiler);
       
   270     }
       
   271 
       
   272     @Test
       
   273     public void testStackNarrowObject() {
       
   274         Assume.assumeTrue(HotSpotVMConfig.config().useCompressedOops);
       
   275         ResolvedJavaType type = metaAccess.lookupJavaType(objectOnStack());
       
   276         DebugInfoCompiler compiler = (asm, values) -> {
       
   277             HotSpotConstant wide = (HotSpotConstant) constantReflection.asJavaClass(type);
       
   278             Register reg = asm.emitLoadPointer((HotSpotConstant) wide.compress());
       
   279             values[0] = asm.emitNarrowPointerToStack(reg);
       
   280             return null;
       
   281         };
       
   282         testObjectOnStack(compiler);
       
   283         testObjectInLocal(compiler);
       
   284     }
       
   285 }