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.vm.ci/jdk.vm.ci.hotspot 28 * jdk.vm.ci/jdk.vm.ci.code 29 * jdk.vm.ci/jdk.vm.ci.code.site 30 * jdk.vm.ci/jdk.vm.ci.meta 31 * jdk.vm.ci/jdk.vm.ci.runtime 32 * jdk.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.TestInvalidCompilationResult 35 */ 36 37 package compiler.jvmci.errors; 38 39 import jdk.vm.ci.code.StackSlot; 40 import jdk.vm.ci.code.site.ConstantReference; 41 import jdk.vm.ci.code.site.DataPatch; 42 import jdk.vm.ci.code.site.DataSectionReference; 43 import jdk.vm.ci.code.site.Infopoint; 44 import jdk.vm.ci.code.site.InfopointReason; 45 import jdk.vm.ci.code.site.Mark; 46 import jdk.vm.ci.code.site.Reference; 47 import jdk.vm.ci.code.site.Site; 48 import jdk.vm.ci.common.JVMCIError; 49 import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment; 50 import jdk.vm.ci.hotspot.HotSpotConstant; 51 import jdk.vm.ci.meta.Assumptions.Assumption; 52 import jdk.vm.ci.meta.VMConstant; 53 import org.junit.Test; 54 55 /** 56 * Tests for errors in the code installer. 57 */ 58 public class TestInvalidCompilationResult extends CodeInstallerTest { 59 60 private static class InvalidAssumption extends Assumption { 61 } 62 63 private static class InvalidVMConstant implements VMConstant { 64 65 public boolean isDefaultForKind() { 66 return false; 67 } 68 69 public String toValueString() { 70 return null; 71 } 72 } 73 74 private static class InvalidReference extends Reference { 75 76 @Override 77 public int hashCode() { 78 return 0; 79 } 80 81 @Override 82 public boolean equals(Object obj) { 83 return false; 84 } 85 } 86 87 @Test(expected = JVMCIError.class) 88 public void testInvalidAssumption() { 89 installEmptyCode(new Site[0], new Assumption[]{new InvalidAssumption()}, new Comment[0], 16, new DataPatch[0], null); 90 } 91 92 @Test(expected = JVMCIError.class) 93 public void testInvalidAlignment() { 94 installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 7, new DataPatch[0], null); 95 } 96 97 @Test(expected = NullPointerException.class) 98 public void testNullDataPatchInDataSection() { 99 installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{null}, null); 100 } 101 102 @Test(expected = NullPointerException.class) 103 public void testNullReferenceInDataSection() { 104 installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, null)}, null); 105 } 106 107 @Test(expected = JVMCIError.class) 108 public void testInvalidDataSectionReference() { 109 DataSectionReference ref = new DataSectionReference(); 110 ref.setOffset(0); 111 installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null); 112 } 113 114 @Test(expected = JVMCIError.class) 115 public void testInvalidNarrowMethodInDataSection() { 116 HotSpotConstant c = (HotSpotConstant) dummyMethod.getEncoding(); 117 ConstantReference ref = new ConstantReference((VMConstant) c.compress()); 118 installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null); 119 } 120 121 @Test(expected = NullPointerException.class) 122 public void testNullConstantInDataSection() { 123 ConstantReference ref = new ConstantReference(null); 124 installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null); 125 } 126 127 @Test(expected = JVMCIError.class) 128 public void testInvalidConstantInDataSection() { 129 ConstantReference ref = new ConstantReference(new InvalidVMConstant()); 130 installEmptyCode(new Site[0], new Assumption[0], new Comment[0], 16, new DataPatch[]{new DataPatch(0, ref)}, null); 131 } 132 133 @Test(expected = NullPointerException.class) 134 public void testNullReferenceInCode() { 135 installEmptyCode(new Site[]{new DataPatch(0, null)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null); 136 } 137 138 @Test(expected = NullPointerException.class) 139 public void testNullConstantInCode() { 140 ConstantReference ref = new ConstantReference(null); 141 installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null); 142 } 143 144 @Test(expected = JVMCIError.class) 145 public void testInvalidConstantInCode() { 146 ConstantReference ref = new ConstantReference(new InvalidVMConstant()); 147 installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null); 148 } 149 150 @Test(expected = JVMCIError.class) 151 public void testInvalidReference() { 152 InvalidReference ref = new InvalidReference(); 153 installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null); 154 } 155 156 @Test(expected = JVMCIError.class) 157 public void testOutOfBoundsDataSectionReference() { 158 DataSectionReference ref = new DataSectionReference(); 159 ref.setOffset(0x1000); 160 installEmptyCode(new Site[]{new DataPatch(0, ref)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null); 161 } 162 163 @Test(expected = JVMCIError.class) 164 public void testInvalidMark() { 165 installEmptyCode(new Site[]{new Mark(0, new Object())}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null); 166 } 167 168 @Test(expected = JVMCIError.class) 169 public void testInvalidMarkInt() { 170 installEmptyCode(new Site[]{new Mark(0, -1)}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null); 171 } 172 173 @Test(expected = NullPointerException.class) 174 public void testNullSite() { 175 installEmptyCode(new Site[]{null}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null); 176 } 177 178 @Test(expected = JVMCIError.class) 179 public void testInfopointMissingDebugInfo() { 180 Infopoint info = new Infopoint(0, null, InfopointReason.METHOD_START); 181 installEmptyCode(new Site[]{info}, new Assumption[0], new Comment[0], 16, new DataPatch[0], null); 182 } 183 184 @Test(expected = JVMCIError.class) 185 public void testSafepointMissingDebugInfo() { 186 Infopoint info = new Infopoint(0, null, InfopointReason.SAFEPOINT); 187 StackSlot deoptRescueSlot = StackSlot.get(null, 0, true); 188 installEmptyCode(new Site[]{info}, new Assumption[0], new Comment[0], 16, new DataPatch[0], deoptRescueSlot); 189 } 190 191 @Test(expected = JVMCIError.class) 192 public void testInvalidDeoptRescueSlot() { 193 StackSlot deoptRescueSlot = StackSlot.get(null, -1, false); 194 installEmptyCode(new Site[]{}, new Assumption[0], new Comment[0], 16, new DataPatch[0], deoptRescueSlot); 195 } 196 }