Path: blob/master/test/hotspot/jtreg/compiler/jvmci/errors/TestInvalidDebugInfo.java
41152 views
/*1* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @requires vm.jvmci26* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot27* jdk.internal.vm.ci/jdk.vm.ci.code28* jdk.internal.vm.ci/jdk.vm.ci.code.site29* jdk.internal.vm.ci/jdk.vm.ci.meta30* jdk.internal.vm.ci/jdk.vm.ci.runtime31* jdk.internal.vm.ci/jdk.vm.ci.common32* @compile CodeInstallerTest.java33* @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI34* -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidDebugInfo35*/3637package compiler.jvmci.errors;3839import jdk.vm.ci.code.Architecture;40import jdk.vm.ci.code.BytecodeFrame;41import jdk.vm.ci.code.DebugInfo;42import jdk.vm.ci.code.Location;43import jdk.vm.ci.code.Register;44import jdk.vm.ci.code.StackSlot;45import jdk.vm.ci.code.VirtualObject;46import jdk.vm.ci.code.site.DataPatch;47import jdk.vm.ci.code.site.Infopoint;48import jdk.vm.ci.code.site.InfopointReason;49import jdk.vm.ci.code.site.Site;50import jdk.vm.ci.common.JVMCIError;51import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;52import jdk.vm.ci.hotspot.HotSpotReferenceMap;53import jdk.vm.ci.meta.Assumptions.Assumption;54import jdk.vm.ci.meta.JavaConstant;55import jdk.vm.ci.meta.JavaKind;56import jdk.vm.ci.meta.JavaValue;57import jdk.vm.ci.meta.PlatformKind;58import jdk.vm.ci.meta.ResolvedJavaType;59import jdk.vm.ci.meta.Value;60import jdk.vm.ci.meta.ValueKind;61import org.junit.Test;6263/**64* Tests for errors in debug info.65*/66public class TestInvalidDebugInfo extends CodeInstallerTest {6768private static class UnknownJavaValue implements JavaValue {69}7071private static class TestValueKind extends ValueKind<TestValueKind> {7273TestValueKind(Architecture arch, JavaKind kind) {74this(arch.getPlatformKind(kind));75}7677TestValueKind(PlatformKind kind) {78super(kind);79}8081@Override82public TestValueKind changeType(PlatformKind kind) {83return new TestValueKind(kind);84}85}8687private void test(JavaValue[] values, JavaKind[] slotKinds, int locals, int stack, int locks) {88test(null, values, slotKinds, locals, stack, locks);89}9091private void test(VirtualObject[] vobj, JavaValue[] values, JavaKind[] slotKinds, int locals, int stack, int locks) {92test(vobj, values, slotKinds, locals, stack, locks, StackSlot.get(null, 0, true));93}9495private void test(VirtualObject[] vobj, JavaValue[] values, JavaKind[] slotKinds, int locals, int stack, int locks, StackSlot deoptRescueSlot) {96BytecodeFrame frame = new BytecodeFrame(null, dummyMethod, 0, false, false, values, slotKinds, locals, stack, locks);97DebugInfo info = new DebugInfo(frame, vobj);98info.setReferenceMap(new HotSpotReferenceMap(new Location[0], new Location[0], new int[0], 8));99installEmptyCode(new Site[]{new Infopoint(0, info, InfopointReason.SAFEPOINT)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], deoptRescueSlot);100}101102@Test(expected = NullPointerException.class)103public void testNullValues() {104test(null, new JavaKind[0], 0, 0, 0);105}106107@Test(expected = NullPointerException.class)108public void testNullSlotKinds() {109test(new JavaValue[0], null, 0, 0, 0);110}111112@Test(expected = JVMCIError.class)113public void testMissingDeoptRescueSlot() {114test(null, new JavaValue[0], new JavaKind[0], 0, 0, 0, null);115}116117@Test(expected = JVMCIError.class)118public void testUnexpectedScopeValuesLength() {119test(new JavaValue[]{JavaConstant.FALSE}, new JavaKind[0], 0, 0, 0);120}121122@Test(expected = JVMCIError.class)123public void testUnexpectedScopeSlotKindsLength() {124test(new JavaValue[0], new JavaKind[]{JavaKind.Boolean}, 0, 0, 0);125}126127@Test(expected = NullPointerException.class)128public void testNullValue() {129test(new JavaValue[]{null}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);130}131132@Test(expected = NullPointerException.class)133public void testNullSlotKind() {134test(new JavaValue[]{JavaConstant.INT_0}, new JavaKind[]{null}, 1, 0, 0);135}136137@Test(expected = NullPointerException.class)138public void testNullMonitor() {139test(new JavaValue[]{null}, new JavaKind[0], 0, 0, 1);140}141142@Test(expected = JVMCIError.class)143public void testWrongMonitorType() {144test(new JavaValue[]{JavaConstant.INT_0}, new JavaKind[0], 0, 0, 1);145}146147@Test(expected = JVMCIError.class)148public void testUnexpectedIllegalValue() {149test(new JavaValue[]{Value.ILLEGAL}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);150}151152@Test(expected = JVMCIError.class)153public void testUnexpectedTypeInCPURegister() {154Register reg = getRegister(arch.getPlatformKind(JavaKind.Int), 0);155test(new JavaValue[]{reg.asValue()}, new JavaKind[]{JavaKind.Illegal}, 1, 0, 0);156}157158@Test(expected = JVMCIError.class)159public void testUnexpectedTypeInFloatRegister() {160Register reg = getRegister(arch.getPlatformKind(JavaKind.Float), 0);161test(new JavaValue[]{reg.asValue()}, new JavaKind[]{JavaKind.Illegal}, 1, 0, 0);162}163164@Test(expected = JVMCIError.class)165public void testUnexpectedTypeOnStack() {166ValueKind<?> kind = new TestValueKind(codeCache.getTarget().arch, JavaKind.Int);167StackSlot value = StackSlot.get(kind, 8, false);168test(new JavaValue[]{value}, new JavaKind[]{JavaKind.Illegal}, 1, 0, 0);169}170171@Test(expected = JVMCIError.class)172public void testWrongConstantType() {173test(new JavaValue[]{JavaConstant.INT_0}, new JavaKind[]{JavaKind.Object}, 1, 0, 0);174}175176@Test(expected = JVMCIError.class)177public void testUnsupportedConstantType() {178test(new JavaValue[]{JavaConstant.forShort((short) 0)}, new JavaKind[]{JavaKind.Short}, 1, 0, 0);179}180181@Test(expected = JVMCIError.class)182public void testUnexpectedNull() {183test(new JavaValue[]{JavaConstant.NULL_POINTER}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);184}185186@Test(expected = JVMCIError.class)187public void testUnexpectedObject() {188JavaValue wrapped = constantReflection.forObject(this);189test(new JavaValue[]{wrapped}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);190}191192@Test(expected = JVMCIError.class)193public void testUnknownJavaValue() {194test(new JavaValue[]{new UnknownJavaValue()}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);195}196197@Test(expected = JVMCIError.class)198public void testMissingIllegalAfterDouble() {199test(new JavaValue[]{JavaConstant.DOUBLE_0, JavaConstant.INT_0}, new JavaKind[]{JavaKind.Double, JavaKind.Int}, 2, 0, 0);200}201202@Test(expected = JVMCIError.class)203public void testInvalidVirtualObjectId() {204ResolvedJavaType obj = metaAccess.lookupJavaType(Object.class);205VirtualObject o = VirtualObject.get(obj, 5);206o.setValues(new JavaValue[0], new JavaKind[0]);207208test(new VirtualObject[]{o}, new JavaValue[0], new JavaKind[0], 0, 0, 0);209}210211@Test(expected = JVMCIError.class)212public void testDuplicateVirtualObject() {213ResolvedJavaType obj = metaAccess.lookupJavaType(Object.class);214VirtualObject o1 = VirtualObject.get(obj, 0);215o1.setValues(new JavaValue[0], new JavaKind[0]);216217VirtualObject o2 = VirtualObject.get(obj, 0);218o2.setValues(new JavaValue[0], new JavaKind[0]);219220test(new VirtualObject[]{o1, o2}, new JavaValue[0], new JavaKind[0], 0, 0, 0);221}222223@Test(expected = JVMCIError.class)224public void testUnexpectedVirtualObject() {225ResolvedJavaType obj = metaAccess.lookupJavaType(Object.class);226VirtualObject o = VirtualObject.get(obj, 0);227o.setValues(new JavaValue[0], new JavaKind[0]);228229test(new VirtualObject[]{o}, new JavaValue[]{o}, new JavaKind[]{JavaKind.Int}, 1, 0, 0);230}231232@Test(expected = JVMCIError.class)233public void testUndefinedVirtualObject() {234ResolvedJavaType obj = metaAccess.lookupJavaType(Object.class);235VirtualObject o0 = VirtualObject.get(obj, 0);236o0.setValues(new JavaValue[0], new JavaKind[0]);237238VirtualObject o1 = VirtualObject.get(obj, 1);239o1.setValues(new JavaValue[0], new JavaKind[0]);240241test(new VirtualObject[]{o0}, new JavaValue[]{o1}, new JavaKind[]{JavaKind.Object}, 1, 0, 0);242}243}244245246