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