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 (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
  27  * @compile CodeInstallerTest.java
  28  * @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI compiler.jvmci.errors.TestInvalidDebugInfo
  29  */
  30 
  31 package compiler.jvmci.errors;
  32 
  33 import jdk.vm.ci.code.BytecodeFrame;
  34 import jdk.vm.ci.code.DebugInfo;
  35 import jdk.vm.ci.code.Location;
  36 import jdk.vm.ci.code.Register;
  37 import jdk.vm.ci.code.StackSlot;
  38 import jdk.vm.ci.code.VirtualObject;
  39 import jdk.vm.ci.code.site.DataPatch;
  40 import jdk.vm.ci.code.site.Infopoint;
  41 import jdk.vm.ci.code.site.InfopointReason;
  42 import jdk.vm.ci.code.site.Site;
  43 import jdk.vm.ci.common.JVMCIError;
  44 import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
  45 import jdk.vm.ci.hotspot.HotSpotReferenceMap;
  46 import jdk.vm.ci.meta.Assumptions.Assumption;
  47 import jdk.vm.ci.meta.JavaConstant;
  48 import jdk.vm.ci.meta.JavaKind;
  49 import jdk.vm.ci.meta.JavaValue;
  50 import jdk.vm.ci.meta.LIRKind;
  51 import jdk.vm.ci.meta.ResolvedJavaType;
  52 import jdk.vm.ci.meta.Value;
  53 
  54 import org.junit.Test;
  55 
  56 /**
  57  * Tests for errors in debug info.
  58  */
  59 public class TestInvalidDebugInfo extends CodeInstallerTest {
  60 
  61     private static class UnknownJavaValue implements JavaValue {
  62     }
  63 
  64     private void test(JavaValue[] values, JavaKind[] slotKinds, int locals, int stack, int locks) {
  65         test(null, values, slotKinds, locals, stack, locks);
  66     }
  67 
  68     private void test(VirtualObject[] vobj, JavaValue[] values, JavaKind[] slotKinds, int locals, int stack, int locks) {
  69         test(vobj, values, slotKinds, locals, stack, locks, StackSlot.get(null, 0, true));
  70     }
  71 
  72     private void test(VirtualObject[] vobj, JavaValue[] values, JavaKind[] slotKinds, int locals, int stack, int locks, StackSlot deoptRescueSlot) {
  73         BytecodeFrame frame = new BytecodeFrame(null, dummyMethod, 0, false, false, values, slotKinds, locals, stack, locks);
  74         DebugInfo info = new DebugInfo(frame, vobj);
  75         info.setReferenceMap(new HotSpotReferenceMap(new Location[0], new Location[0], new int[0], 8));
  76         installEmptyCode(new Site[]{new Infopoint(0, info, InfopointReason.SAFEPOINT)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], deoptRescueSlot);
  77     }
  78 
  79     @Test(expected = NullPointerException.class)
  80     public void testNullValues() {
  81         test(null, new JavaKind[0], 0, 0, 0);
  82     }
  83 
  84     @Test(expected = NullPointerException.class)
  85     public void testNullSlotKinds() {
  86         test(new JavaValue[0], null, 0, 0, 0);
  87     }
  88 
  89     @Test(expected = JVMCIError.class)
  90     public void testMissingDeoptRescueSlot() {
  91         test(null, new JavaValue[0], new JavaKind[0], 0, 0, 0, null);
  92     }
  93 
  94     @Test(expected = JVMCIError.class)
  95     public void testUnexpectedScopeValuesLength() {
  96         test(new JavaValue[]{JavaConstant.FALSE}, new JavaKind[0], 0, 0, 0);
  97     }
  98 
  99     @Test(expected = JVMCIError.class)
 100     public void testUnexpectedScopeSlotKindsLength() {
 101         test(new JavaValue[0], new JavaKind[]{JavaKind.Boolean}, 0, 0, 0);
 102     }
 103 
 104     @Test(expected = NullPointerException.class)
 105     public void testNullValue() {
 106         test(new JavaValue[]{null}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);
 107     }
 108 
 109     @Test(expected = NullPointerException.class)
 110     public void testNullSlotKind() {
 111         test(new JavaValue[]{JavaConstant.INT_0}, new JavaKind[]{null}, 1, 0, 0);
 112     }
 113 
 114     @Test(expected = NullPointerException.class)
 115     public void testNullMonitor() {
 116         test(new JavaValue[]{null}, new JavaKind[0], 0, 0, 1);
 117     }
 118 
 119     @Test(expected = JVMCIError.class)
 120     public void testWrongMonitorType() {
 121         test(new JavaValue[]{JavaConstant.INT_0}, new JavaKind[0], 0, 0, 1);
 122     }
 123 
 124     @Test(expected = JVMCIError.class)
 125     public void testUnexpectedIllegalValue() {
 126         test(new JavaValue[]{Value.ILLEGAL}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);
 127     }
 128 
 129     @Test(expected = JVMCIError.class)
 130     public void testUnexpectedTypeInCPURegister() {
 131         Register reg = getRegister(arch.getPlatformKind(JavaKind.Int), 0);
 132         test(new JavaValue[]{reg.asValue()}, new JavaKind[]{JavaKind.Illegal}, 1, 0, 0);
 133     }
 134 
 135     @Test(expected = JVMCIError.class)
 136     public void testUnexpectedTypeInFloatRegister() {
 137         Register reg = getRegister(arch.getPlatformKind(JavaKind.Float), 0);
 138         test(new JavaValue[]{reg.asValue()}, new JavaKind[]{JavaKind.Illegal}, 1, 0, 0);
 139     }
 140 
 141     @Test(expected = JVMCIError.class)
 142     public void testUnexpectedTypeOnStack() {
 143         LIRKind kind = codeCache.getTarget().getLIRKind(JavaKind.Int);
 144         StackSlot value = StackSlot.get(kind, 8, false);
 145         test(new JavaValue[]{value}, new JavaKind[]{JavaKind.Illegal}, 1, 0, 0);
 146     }
 147 
 148     @Test(expected = JVMCIError.class)
 149     public void testWrongConstantType() {
 150         test(new JavaValue[]{JavaConstant.INT_0}, new JavaKind[]{JavaKind.Object}, 1, 0, 0);
 151     }
 152 
 153     @Test(expected = JVMCIError.class)
 154     public void testUnsupportedConstantType() {
 155         test(new JavaValue[]{JavaConstant.forShort((short) 0)}, new JavaKind[]{JavaKind.Short}, 1, 0, 0);
 156     }
 157 
 158     @Test(expected = JVMCIError.class)
 159     public void testUnexpectedNull() {
 160         test(new JavaValue[]{JavaConstant.NULL_POINTER}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);
 161     }
 162 
 163     @Test(expected = JVMCIError.class)
 164     public void testUnexpectedObject() {
 165         JavaValue wrapped = constantReflection.forObject(this);
 166         test(new JavaValue[]{wrapped}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);
 167     }
 168 
 169     @Test(expected = JVMCIError.class)
 170     public void testUnknownJavaValue() {
 171         test(new JavaValue[]{new UnknownJavaValue()}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);
 172     }
 173 
 174     @Test(expected = JVMCIError.class)
 175     public void testMissingIllegalAfterDouble() {
 176         test(new JavaValue[]{JavaConstant.DOUBLE_0, JavaConstant.INT_0}, new JavaKind[]{JavaKind.Double, JavaKind.Int}, 2, 0, 0);
 177     }
 178 
 179     @Test(expected = JVMCIError.class)
 180     public void testInvalidVirtualObjectId() {
 181         ResolvedJavaType obj = metaAccess.lookupJavaType(Object.class);
 182         VirtualObject o = VirtualObject.get(obj, 5);
 183         o.setValues(new JavaValue[0], new JavaKind[0]);
 184 
 185         test(new VirtualObject[]{o}, new JavaValue[0], new JavaKind[0], 0, 0, 0);
 186     }
 187 
 188     @Test(expected = JVMCIError.class)
 189     public void testDuplicateVirtualObject() {
 190         ResolvedJavaType obj = metaAccess.lookupJavaType(Object.class);
 191         VirtualObject o1 = VirtualObject.get(obj, 0);
 192         o1.setValues(new JavaValue[0], new JavaKind[0]);
 193 
 194         VirtualObject o2 = VirtualObject.get(obj, 0);
 195         o2.setValues(new JavaValue[0], new JavaKind[0]);
 196 
 197         test(new VirtualObject[]{o1, o2}, new JavaValue[0], new JavaKind[0], 0, 0, 0);
 198     }
 199 
 200     @Test(expected = JVMCIError.class)
 201     public void testUnexpectedVirtualObject() {
 202         ResolvedJavaType obj = metaAccess.lookupJavaType(Object.class);
 203         VirtualObject o = VirtualObject.get(obj, 0);
 204         o.setValues(new JavaValue[0], new JavaKind[0]);
 205 
 206         test(new VirtualObject[]{o}, new JavaValue[]{o}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);
 207     }
 208 
 209     @Test(expected = JVMCIError.class)
 210     public void testUndefinedVirtualObject() {
 211         ResolvedJavaType obj = metaAccess.lookupJavaType(Object.class);
 212         VirtualObject o0 = VirtualObject.get(obj, 0);
 213         o0.setValues(new JavaValue[0], new JavaKind[0]);
 214 
 215         VirtualObject o1 = VirtualObject.get(obj, 1);
 216         o1.setValues(new JavaValue[0], new JavaKind[0]);
 217 
 218         test(new VirtualObject[]{o0}, new JavaValue[]{o1}, new JavaKind[]{JavaKind.Object}, 1, 0, 0);
 219     }
 220 }